Changeset 9131


Ignore:
Timestamp:
Jun 5, 2014, 12:49:11 PM (11 years ago)
Author:
davies
Message:

Change to parallel_boyd_box smoothing timescale implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga_parallel/parallel_boyd_box_operator.py

    r9130 r9131  
    11import anuga
    22import math
     3import numpy
    34
    45from anuga.structures.boyd_box_operator import boyd_box_function
     
    100101        # May/June 2014 -- allow 'smoothing ' of driving_energy, delta total energy, and outflow_enq_depth
    101102        self.smoothing_timescale=0.
    102         self.smooth_driving_energy=0.
    103103        self.smooth_delta_total_energy=0.
    104         self.smooth_outflow_enq_depth=0.
     104        self.smooth_Q=0.
    105105        # Set them based on a call to the discharge routine with smoothing_timescale=0.
    106106        # [values of self.smooth_* are required in discharge_routine, hence dummy values above]
    107107        Qvd=self.discharge_routine()
    108         self.smooth_driving_energy=1.0*self.driving_energy
    109108        self.smooth_delta_total_energy=1.0*self.delta_total_energy
    110         self.smooth_outflow_enq_depth=Qvd[2]
     109        self.smooth_Q=Qvd[0]
    111110        # Finally, set the smoothing timescale we actually want
    112111        self.smoothing_timescale=smoothing_timescale
     
    170169        # master proc orders reversal if applicable
    171170        if self.myid == self.master_proc:
    172 
     171            # May/June 2014 -- change the driving forces gradually, with forward euler timestepping
     172            ts=self.domain.timestep/max(self.domain.timestep, self.smoothing_timescale,1.0e-06)
     173            self.smooth_delta_total_energy=self.smooth_delta_total_energy+\
     174                                    ts*(self.delta_total_energy-self.smooth_delta_total_energy)
    173175
    174176            # Reverse the inflow and outflow direction?
    175             if self.delta_total_energy < 0:
     177            if self.smooth_delta_total_energy < 0:
    176178                self.inflow_index = 1
    177179                self.outflow_index = 0
    178180
    179                 self.delta_total_energy = -self.delta_total_energy
     181                #self.delta_total_energy = -self.delta_total_energy
     182                self.delta_total_energy = -self.smooth_delta_total_energy
    180183
    181184                for i in self.procs:
     
    183186                    pypar.send(True, i)
    184187            else:
     188                self.delta_total_energy = self.smooth_delta_total_energy
    185189                for i in self.procs:
    186190                    if i == self.master_proc: continue
     
    251255                    self.driving_energy = inflow_enq_depth
    252256                   
    253                 # May/June 2014 -- change the driving forces gradually, with forward euler timestepping
    254                 ts=self.domain.timestep/max(self.domain.timestep, self.smoothing_timescale,1.0e-06)
    255                 self.smooth_driving_energy=self.smooth_driving_energy+\
    256                                         ts*(self.driving_energy-self.smooth_driving_energy)
    257                 self.smooth_delta_total_energy=self.smooth_delta_total_energy+\
    258                                         ts*(self.delta_total_energy-self.smooth_delta_total_energy)
    259                 self.smooth_outflow_enq_depth=self.smooth_outflow_enq_depth+\
    260                                         ts*(outflow_enq_depth-self.smooth_outflow_enq_depth)
    261 
    262257           
    263258                Q, barrel_velocity, outlet_culvert_depth, flow_area, case = \
     
    266261                                                flow_width          =self.culvert_width,
    267262                                                length              =self.culvert_length,
    268                                                 #driving_energy      =self.driving_energy,
    269                                                 #delta_total_energy  =self.delta_total_energy,
    270                                                 #outlet_enquiry_depth=outflow_enq_depth,
    271                                                 # Allow smoothing of the driving energies
    272                                                 driving_energy      =self.smooth_driving_energy,
    273                                                 delta_total_energy  =self.smooth_delta_total_energy,
    274                                                 outlet_enquiry_depth=self.smooth_outflow_enq_depth,
     263                                                driving_energy      =self.driving_energy,
     264                                                delta_total_energy  =self.delta_total_energy,
     265                                                outlet_enquiry_depth=outflow_enq_depth,
    275266                                                sum_loss            =self.sum_loss,
    276267                                                manning             =self.manning)
    277268
    278                
     269                ################################################
     270                # Smooth discharge. This can reduce oscillations
     271                #
     272                # NOTE: The sign of smooth_Q assumes that
     273                #   self.inflow_index=0 and self.outflow_index=1
     274                #   , whereas the sign of Q is always positive
     275                Qsign=(self.outflow_index-self.inflow_index) # To adjust sign of Q
     276                self.smooth_Q = self.smooth_Q +ts*(Q*Qsign-self.smooth_Q)
     277                if numpy.sign(self.smooth_Q)!=Qsign:
     278                    # The flow direction of the 'instantaneous Q' based on the
     279                    # 'smoothed delta_total_energy' is not the same as the
     280                    # direction of smooth_Q. To prevent 'jumping around', let's
     281                    # set Q to zero
     282                    Q=0.
     283                else:
     284                    Q = abs(self.smooth_Q)
     285                barrel_velocity=Q/flow_area
    279286            # END CODE BLOCK for DEPTH  > Required depth for CULVERT Flow
    280287
Note: See TracChangeset for help on using the changeset viewer.