Ignore:
Timestamp:
Jun 17, 2014, 9:46:06 PM (11 years ago)
Author:
steve
Message:

Commiting all the validation tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/shallow_water/boundaries.py

    r8920 r9174  
    346346        q[1] = q[2] = 0.0
    347347        return q
     348
     349class Characteristic_stage_boundary(Boundary):
     350    """Sets the stage via a function and the momentum is determined
     351    via assumption of simple incoming wave (uses Riemann invariant)
     352
     353
     354    Example:
     355
     356    def waveform(t):
     357        return sea_level + normalized_amplitude/cosh(t-25)**2
     358
     359    Bcs = Characteristic_stage_boundary(domain, waveform)
     360
     361    Underlying domain must be specified when boundary is instantiated
     362    """
     363
     364    def __init__(self, domain=None, function=None, default_stage = 0.0):
     365        """ Instantiate a
     366            Characteristic_stage_boundary.
     367            domain is the domain containing the boundary
     368            function is the function to apply the wave
     369            default_stage is the assumed stage pre the application of wave
     370        """
     371
     372        Boundary.__init__(self)
     373
     374        if domain is None:
     375            msg = 'Domain must be specified for this type boundary'
     376            raise Exception, msg
     377
     378        if function is None:
     379            msg = 'Function must be specified for this type boundary'
     380            raise Exception, msg
     381
     382        self.domain = domain
     383        self.function = function
     384        self.default_stage = default_stage
     385
     386        self.Elev  = domain.quantitis['elevation']
     387        self.Stage = domain.quantitis['stage']
     388        self.Height = domain.quantitis['height']
     389
     390    def __repr__(self):
     391        """ Return a representation of this instance. """
     392        msg = 'Characteristic_stage_boundary '
     393        msg += '(%s) ' % self.domain
     394        msg += '(%s) ' % self.default_stage
     395        return msg
     396
     397
     398    def evaluate(self, vol_id, edge_id):
     399        """Calculate reflections (reverse outward momentum).
     400
     401        vol_id   
     402        edge_id 
     403        """
     404       
     405        t = self.domain.get_time()
     406
     407
     408        value = self.function(t)
     409        try:
     410            stage = float(value)
     411        except:
     412            stage = float(value[0])
     413
     414
     415
     416        q = self.conserved_quantities
     417        #q[0] = self.stage[vol_id, edge_id]
     418        q[0] = stage
     419        q[1] = self.xmom[vol_id, edge_id]
     420        q[2] = self.ymom[vol_id, edge_id]
     421
     422        normal = self.normals[vol_id, 2*edge_id:2*edge_id+2]
     423
     424        r = rotate(q, normal, direction = 1)
     425        r[1] = -r[1]
     426        q = rotate(r, normal, direction = -1)
     427
     428
     429        return q
     430
     431
     432
     433
     434
     435
     436    def evaluate_segment(self, domain, segment_edges):
     437        """Apply reflective BC on the boundary edges defined by
     438        segment_edges
     439        """
     440
     441        if segment_edges is None:
     442            return
     443        if domain is None:
     444            return
     445
     446        t = self.domain.get_time()
     447
     448
     449        value = self.function(t)
     450        try:
     451            stage = float(value)
     452        except:
     453            stage = float(value[0])
     454                       
     455
     456        ids = segment_edges
     457        vol_ids  = domain.boundary_cells[ids]
     458        edge_ids = domain.boundary_edges[ids]
     459
     460        Stage = domain.quantities['stage']
     461        Elev  = domain.quantities['elevation']
     462        Height= domain.quantities['height']
     463        Xmom  = domain.quantities['xmomentum']
     464        Ymom  = domain.quantities['ymomentum']
     465        Xvel  = domain.quantities['xvelocity']
     466        Yvel  = domain.quantities['yvelocity']
     467
     468        Normals = domain.normals
     469
     470        #print vol_ids
     471        #print edge_ids
     472        #Normals.reshape((4,3,2))
     473        #print Normals.shape
     474        #print Normals[vol_ids, 2*edge_ids]
     475        #print Normals[vol_ids, 2*edge_ids+1]
     476       
     477        n1  = Normals[vol_ids,2*edge_ids]
     478        n2  = Normals[vol_ids,2*edge_ids+1]
     479
     480        # Transfer these quantities to the boundary array
     481        Stage.boundary_values[ids]  = Stage.edge_values[vol_ids,edge_ids]
     482        Elev.boundary_values[ids]   = Elev.edge_values[vol_ids,edge_ids]
     483        Height.boundary_values[ids] = Height.edge_values[vol_ids,edge_ids]
     484
     485        # Rotate and negate Momemtum
     486        q1 = Xmom.edge_values[vol_ids,edge_ids]
     487        q2 = Ymom.edge_values[vol_ids,edge_ids]
     488
     489        r1 = -q1*n1 - q2*n2
     490        r2 = -q1*n2 + q2*n1
     491
     492        Xmom.boundary_values[ids] = n1*r1 - n2*r2
     493        Ymom.boundary_values[ids] = n2*r1 + n1*r2
     494
     495        # Rotate and negate Velocity
     496        q1 = Xvel.edge_values[vol_ids,edge_ids]
     497        q2 = Yvel.edge_values[vol_ids,edge_ids]
     498
     499        r1 = q1*n1 + q2*n2
     500        r2 = q1*n2 - q2*n1
     501
     502        Xvel.boundary_values[ids] = n1*r1 - n2*r2
     503        Yvel.boundary_values[ids] = n2*r1 + n1*r2
     504
     505       
     506
    348507
    349508class Dirichlet_discharge_boundary(Boundary):
Note: See TracChangeset for help on using the changeset viewer.