How to use the underworld.conditions function in underworld

To help you get started, we’ve selected a few underworld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github underworldcode / underworld2 / underworld / systems / sle / _assemblyterm.py View on Github external
def __init__(self, nbc, integrationSwarm=None, surfaceGaussPoints=2, **kwargs):
        if not isinstance(nbc, uw.conditions.NeumannCondition):
            raise ValueError( "Provided 'nbc' must be a NeumannCondition class." )
        self._nbc = nbc
        # use the nbc variable's mesh
        mesh = self._nbc.variable.mesh

        if integrationSwarm != None:
            if not isinstance( integrationSwarm, uw.swarm.GaussBorderIntegrationSwarm):
                raise ValueError("Provided 'borderSwarm' must be of type uw.swarm.GaussBorderIntegrationSwarm")
        else: # no swarm provide, so we build one
            if not isinstance(surfaceGaussPoints, int):
                raise TypeError( "Provided 'surfaceGaussPoints' must be a positive integer")
            if surfaceGaussPoints < 1:
                raise ValueError( "Provided 'surfaceGaussPoints' must be a positive integer")
            integrationSwarm = uw.swarm.GaussBorderIntegrationSwarm( mesh=mesh,
                                                                     particleCount=surfaceGaussPoints )
github underworldcode / underworld2 / docs / development / models_broken / LemialeEtAl2008 / data_comp / Lemiale-Parallel.py View on Github external
# ### Boundary conditions
# 
# Pure shear with moving  walls — all boundaries are zero traction with 

# In[6]:

iWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
jWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]
base   = mesh.specialSets["MinJ_VertexSet"]
top    = mesh.specialSets["MaxJ_VertexSet"]

allWalls = iWalls + jWalls

velocityBCs = uw.conditions.DirichletCondition( variable        = velocityField, 
                                                indexSetsPerDof = (iWalls, base) )

for index in mesh.specialSets["MinI_VertexSet"]:
    velocityField.data[index] = [minXv, 0.]
for index in mesh.specialSets["MaxI_VertexSet"]:
    velocityField.data[index] = [maxXv, 0.]
    


# ### Setup the material swarm
# 
# This is used for tracking deformation and history dependence of the rheology

# In[7]:

swarm         = uw.swarm.Swarm( mesh=mesh )
github underworldcode / underworld2 / docs / publications / TosiEtAl-2015 / TosiParallel.py View on Github external
temperatureField.data[index] = TB
for index in mesh.specialSets["MaxJ_VertexSet"]:
    temperatureField.data[index] = TS


# **Conditions on the boundaries**
# 
# Construct sets for the both horizontal and vertical walls. Combine the sets of vertices to make the I (left and right side walls) and J (top and bottom walls) sets. Note that both sets contain the corners of the box.

# In[ ]:

iWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
jWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]
freeslipBC = uw.conditions.DirichletCondition( variable      = velocityField, 
                                               indexSetsPerDof = (iWalls, jWalls) )
tempBC     = uw.conditions.DirichletCondition( variable      = temperatureField, 
                                               indexSetsPerDof = (jWalls,) )


# Set up material parameters and functions
# -----
# 

# **Viscosity field**
# 
# The viscosity is a function of temperature ($T$), the vertical coordinate ($z$) and the strain rate ($\dot{\epsilon}$) and is given by
# 
# $$
#     \eta(T, z, \dot{\epsilon}) = 2 \left( \frac{1}{\eta_{lin}(T,z)} + \frac{1}{\eta_{plast}(\dot{\epsilon})} \right)^{-1}
# $$
# 
# where the linear part is
github underworldcode / underworld2 / underworld / systems / _stokes.py View on Github external
self._swarm = voronoi_swarm
        if voronoi_swarm and velocityField.mesh.elementType=='Q2':
            import warnings
            warnings.warn("Voronoi integration may yield unsatisfactory results for Q2 mesh.")

        mesh = velocityField.mesh

        if not isinstance(conditions,(list,tuple)):
            conditionslist = []
            conditionslist.append(conditions)
            conditions = conditionslist
        for cond in conditions:
            # set the bcs on here
            if not isinstance( cond, uw.conditions.SystemCondition ):
                raise TypeError( "Provided 'conditions' must be 'SystemCondition' objects." )
            elif type(cond) == uw.conditions.DirichletCondition:
                if cond.variable == self._velocityField:
                    libUnderworld.StgFEM.FeVariable_SetBC( self._velocityField._cself, cond._cself )
                elif cond.variable == self._pressureField:
                    libUnderworld.StgFEM.FeVariable_SetBC( self._pressureField._cself, cond._cself )
                else:
                    raise ValueError("Provided condition does not appear to correspond to the system unknowns.")

        self._conditions = conditions

        self._eqNums = dict()
        self._eqNums[velocityField] = sle.EqNumber( self._velocityField, self._removeBCs )
        self._eqNums[pressureField] = sle.EqNumber( self._pressureField, self._removeBCs )

        # create solutions vectors and load fevariable values onto them for best first guess
        self._velocitySol = sle.SolutionVector(velocityField, self._eqNums[velocityField])
        self._pressureSol = sle.SolutionVector(pressureField, self._eqNums[pressureField])
github underworldcode / underworld2 / unsupported / annulus / wrappers.py View on Github external
inner = self.meshSets['innerNodes'] = annulus.specialSets["MinI_VertexSet"]
        self.meshSets['boundaryNodes'] = self.meshSets['outerNodes']+self.meshSets['innerNodes']

        # create the dirichet boundary condtions
        self.dirichletBCs=dict()
        # the three types of conditions available
        self.dirichletBCs['temperature'] = uw.conditions.DirichletCondition(
                                                    variable=tField,
                                                    indexSetsPerDof=(inner+outer) )

        self.dirichletBCs['velocity_freeSlip'] =  uw.conditions.RotatedDirichletCondition(
                                    variable        = vField,
                                    indexSetsPerDof = (inner+outer, None),
                                    basis_vectors   = (annulus.bnd_vec_normal, annulus.bnd_vec_tangent))

        self.dirichletBCs['velocity_noSlip']   =  uw.conditions.RotatedDirichletCondition(
                                    variable        = vField,
                                    indexSetsPerDof = (inner+outer, None),
                                    basis_vectors   = (annulus.bnd_vec_normal, annulus.bnd_vec_tangent))

        # set up analytics logging
        self.f     = radialLengths[0]/radialLengths[1]
        self.dT_dr = fn.math.dot( tField.fn_gradient, annulus._fn_unitvec_radial() )

        self.dT_dr_outer_integral  = uw.utils.Integral( mesh=annulus, fn=self.dT_dr,
                                                   integrationType="surface", surfaceIndexSet=outer )

        self.dT_dr_inner_integral  = uw.utils.Integral( mesh=annulus, fn=self.dT_dr,
                                                   integrationType="surface", surfaceIndexSet=inner )

        # start the log file
        self.log_titles += ['','Nu_u','Nu_b']
github underworldcode / underworld2 / underworld / function / analytic.py View on Github external
Returns
        -------
        underworld.conditions.SystemCondition
            The BC object. It should be passed in to the system being constructed.

        '''
        mesh = velVar.mesh

        bcverts = []
        bcverts.append( mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"] )
        bcverts.append( mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"] )
        if self.dim == 3:
            bcverts.append( mesh.specialSets["MinK_VertexSet"] + mesh.specialSets["MaxK_VertexSet"] )
        import underworld as uw
        return uw.conditions.DirichletCondition(velVar, bcverts)
github underworldcode / underworld2 / underworld / systems / _darcyflow.py View on Github external
self._kMatTerm = sle.MatrixAssemblyTerm_NA_i__NB_i__Fn(  integrationSwarm=intswarm,
                                                                 assembledObject=self._kmatrix,
                                                                 fn=_fn_diffusivity)

        self._forceVecTerm = sle.VectorAssemblyTerm_NA_i__Fn_i(   integrationSwarm=intswarm,
                                                              assembledObject=self._fvector,
                                                              fn=fn_bodyforce*fn_diffusivity)

        # search for neumann conditions
        for cond in conditions:
            if isinstance( cond, uw.conditions.NeumannCondition ):
                #NOTE many NeumannConditions can be used but the _sufaceFluxTerm only records the last

                ### -VE flux because of Energy_SLE_Solver ###
                negativeCond = uw.conditions.NeumannCondition( fn_flux=-1.0*cond.fn_flux,
                                                               variable=cond.variable,
                                                               indexSetsPerDof=cond.indexSet )

                self._surfaceFluxTerm = sle.VectorSurfaceAssemblyTerm_NA__Fn__ni(
                                                                assembledObject  = self._fvector,
                                                                surfaceGaussPoints = 2,
                                                                nbc         = negativeCond )
        super(SteadyStateDarcyFlow, self).__init__(**kwargs)
github underworldcode / underworld2 / docs / examples / 1_10_BucklingBeamCompression.py View on Github external
# ### Boundary conditions
# 
# Pure shear with moving  side walls — all boundaries are zero traction with outflow top and bottom
# to accommodate changing volume

# In[4]:

iWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
jWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]
base   = mesh.specialSets["MinJ_VertexSet"]
top    = mesh.specialSets["MaxJ_VertexSet"]
allWalls = iWalls + jWalls

velocityBCs = uw.conditions.DirichletCondition( variable        = velocityField, 
                                                indexSetsPerDof = (iWalls, iWalls) )

for index in mesh.specialSets["MinI_VertexSet"]:
    velocityField.data[index] = [minXv, 0.]
for index in mesh.specialSets["MaxI_VertexSet"]:
    velocityField.data[index] = [maxXv, 0.]
    


# ### Setup the material swarm and passive tracers
# 
# The material swarm is used for tracking deformation and history dependence of the rheology
# 
# Passive swarms can track all sorts of things but lack all the machinery for integration and re-population

# In[5]:
github underworldcode / underworld2 / docs / tutorials / ConvectionTutorial / Notebooks / 058-RayleighBenardConvection-setup.py View on Github external
for index in Tmesh.specialSets["MaxJ_VertexSet"]:
    temperatureField.data[index] = tempMin


# Velocity and Temperature boundary conditions

# In[15]:

iWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
jWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]

# 2D velocity vector can have two Dirichlet conditions on each vertex, 
# v_x is fixed on the iWalls (vertical), v_y is fixed on the jWalls (horizontal)

freeslipBC = uw.conditions.DirichletCondition( variable        = velocityField, 
                                               indexSetsPerDof = (iWalls, jWalls) )

# Temperature is held constant on the jWalls

jTWalls = Tmesh.specialSets["MinJ_VertexSet"] + Tmesh.specialSets["MaxJ_VertexSet"]


tempBC     = uw.conditions.DirichletCondition( variable        = temperatureField, 
                                               indexSetsPerDof = (jTWalls,) )

# figtemp = glucifer.Figure( figsize=(800,400) )
# figtemp.append( glucifer.objects.Surface(mesh, temperatureField, colours="blue white red") )
# figtemp.append( glucifer.objects.Mesh(mesh) )
# figtemp.show()
github underworldcode / underworld2 / underworld / systems / _curvilinear_stokes.py View on Github external
assembledObject  = self._mmatrix,
                                                                        mesh             =  mesh,
                                                                        fn               = self._fn_minus_one_on_lambda )

        if fn_stresshistory != None:
            self._NA_j__Fn_ijTerm    = sle.VectorAssemblyTerm_NA_j__Fn_ij( integrationSwarm = intswarm, 
                                                                           assembledObject  = self._fvector, 
                                                                           fn               = fn_stresshistory )
        # objects used for analysis, dictionary for organisation
        self._aObjects = dict()
        self._aObjects['vdotv_fn'] = uw.function.math.dot(self._velocityField, self._velocityField)

        super(Curvilinear_Stokes, self).__init__(**kwargs)

        for cond in self._conditions:
            if type(cond) in [uw.conditions.RotatedDirichletCondition, uw.conditions.CurvilinearDirichletCondition]:
                self.redefineVelocityDirichletBC(cond.basis_vectors)