How to use the underworld.function.branching.conditional 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 / unsupported / geodynamics / Model.py View on Github external
def _fill_model(self):

        conditions = [(obj.shape.fn, obj.index)
                      for obj in self.materials if obj.shape is not None]

        conditions.append((True, self._defaultMaterial))
        self.materialField.data[:] = fn.branching.conditional(conditions).evaluate(self.swarm)
github underworldcode / underworld2 / underworld / mesh / _spherical_mesh.py View on Github external
1. If on the domain boundary - rotated to (r,n,t) and
         2. If not on the domain boundary - rotated by identity matrix i.e. (NO rotation).
        """

        # initialiase bases vectors as meshVariables
        self._e1 = self.add_variable(nodeDofCount=3)
        self._e2 = self.add_variable(nodeDofCount=3)
        self._e3 = self.add_variable(nodeDofCount=3)

        posFn = fn.coord()
        radiusFn =  fn.math.sqrt(posFn[1]**2 + posFn[2]**2)


        self._fn_x_or_rotated  = fn.misc.constant(1.0)*(1.,0.,0.)

        self._fn_y_or_rotated  = fn.branching.conditional(
                                    [ ( self.bndMeshVariable != 0.0, self._get_tangential_Fn() ),
                                      (                       True, fn.misc.constant(1.0)*(0.,1.,0.) ) ] )
        self._fn_z_or_rotated  = fn.branching.conditional(
                                    [ ( self.bndMeshVariable != 0.0 , self._get_normal_Fn() ),
                                      (                       True, fn.misc.constant(1.0)*(0.,0.,1.) ) ] )

        # evaluate the new bases

        self._e1.data[:] = self._fn_x_or_rotated.evaluate(self) # should be unchanged in this mesh
        self._e2.data[:] = self._fn_y_or_rotated.evaluate(self) #
        self._e3.data[:] = self._fn_z_or_rotated.evaluate(self) #
        #
        # self._e1.data[:] = (1.,0.,0.)
        # self._e2.data[:] = self._get_tangential_Fn().evaluate(self)
        # self._e3.data[:] = self._get_normal_Fn().evaluate(self)
github underworldcode / underworld2 / underworld / utils / _utils.py View on Github external
raise ValueError("Mesh does not appear to provide a 'AllWalls_VertexSet' special set. This is required for surface integration.")
                for guy in surfaceIndexSet:
                    inSet = int(guy) in allBoundaryNodes
                    if not inSet:
                        raise ValueError("Your surfaceIndexSet appears to contain node(s) which do not belong to the mesh boundary. Surface integration across internal nodes is not currently supported.")
                # create MeshVariable
                deltaMeshVariable = mesh.add_variable(1)
                # init to zero
                deltaMeshVariable.data[:] = 0.
                # set to 1 on provided vertices
                deltaMeshVariable.data[surfaceIndexSet.data] = 1.
                # replace fn with delta*fn
                # note that we need to use this condition so that we only capture border swarm particles
                # on the surface itself. for those directly adjacent, the deltaMeshVariable will evaluate
                # to non-zero (but less than 1.), so we need to remove those from the integration as well.
                self._maskFn = underworld.function.branching.conditional(
                                                  [  ( deltaMeshVariable > 0.999, 1. ),
                                                     (                      True, 0. )   ] )
                integrationSwarm = uw.swarm.GaussBorderIntegrationSwarm(mesh)
        else:
            if not isinstance(integrationSwarm, uw.swarm.IntegrationSwarm):
                raise TypeError("'integrationSwarm' object passed in must be of type 'IntegrationSwarm'")

        self._integrationSwarm = integrationSwarm
        self._cself.integrationSwarm = integrationSwarm._cself
        self._cself.dim = mesh.dim

        self.fn = fn

        super(Integral,self).__init__(**kwargs)
github underworldcode / underworld2 / docs / development / models_broken / LemialeEtAl2008 / data_comp / Lemiale-Parallel.py View on Github external
materialW = 1 # weak
materialA = 2 # accommodation layer a.k.a. Sticky Air

# The particle coordinates will be the input to the function evaluate (see final line in this cell).
# We get proxy for this now using the input() function.
coord = fn.input()

# Setup the conditions list for the following conditional function. Where the
# z coordinate (coordinate[1]) is less than the perturbation, set to lightIndex.
conditions = [ (                                  coord[1] > thicknessV , materialA ),
               ( ((coord[1] < dWeak) & (coord[0]**2. < (dWeak**2.)/4.)) , materialW ),
               (                                                   True , materialV ) ]

# The actual function evaluation. Here the conditional function is evaluated at the location
# of each swarm particle. The results are then written to the materialVariable swarm variable.
materialVariable.data[:] = fn.branching.conditional( conditions ).evaluate(swarm)


# Define the density function
# ---

# In[12]:

# Here we set a density for each material - constants defined at the top
densityMap   = { materialA:rhoA, materialV:rhoV, materialW:rhoV }
densityFn    = fn.branching.map( fn_key = materialVariable, mapping = densityMap )


# Define the viscosity function
# ----
# 
# In this case, the viscosity of material which has not reached the yield criterion is simply going to be a constant. Nevertheless, it is useful to define it here as a function and write the remaining code such that it is not changed if we introduce additional materials or a dependence on another set of equations.
github underworldcode / underworld2 / unsupported / geodynamics / rheologyDatabase / yielding_criteria.py View on Github external
def linearFrictionWeakening(cumulativeTotalStrain, FrictionCoef, FrictionCoefSw, epsilon1=0.5, epsilon2=1.5, **kwargs):

    frictionVal = [(cumulativeTotalStrain < epsilon1, fn.misc.constant(FrictionCoef)),
                   (cumulativeTotalStrain > epsilon2, fn.misc.constant(FrictionCoefSw)),
                   (True, FrictionCoef + ((FrictionCoef - FrictionCoefSw)/(epsilon1 - epsilon2)) * (cumulativeTotalStrain - epsilon1))]

    frictionVal = fn.branching.conditional(frictionVal)
 
    return fn.math.atan(frictionVal)
github underworldcode / underworld2 / unsupported / geodynamics / rheology.py View on Github external
def _get_second_invariant(self):
        FirstIterCondition = [(self.firstIter,nd(self.defaultStrainRateInvariant)),
                              (True, self.strainRateInvariantField)]
        return fn.branching.conditional(FirstIterCondition)
github underworldcode / underworld2 / unsupported / geodynamics / surfaceProcesses.py View on Github external
self.swarm = swarm
        self.threshold = nd(threshold)

        materialMap = {}
        for material in air:
            materialMap[material.index] = 1.0

        isAirMaterial = fn.branching.map(fn_key=materialIndexField, mapping=materialMap, fn_default=0.0)

        sedimentation = [(((isAirMaterial > 0.5) & (fn.input()[1] < nd(threshold))), sediment[0].index),
                         (True, materialIndexField)]
        erosion = [(((isAirMaterial < 0.5) & (fn.input()[1] > nd(threshold))), sediment[0].index),
                         (True, materialIndexField)]

        self._fn1 = fn.branching.conditional(belowthreshold)
        self._fn2 = fn.branching.conditional(belowthreshold)
github underworldcode / underworld2 / docs / development / models_inprogress / uw3 / poisson3D.py View on Github external
model = uw.systems.pl_PoissonModel()

# these following 2 fn are made available by the model
temperature  = model.fn_temperature

'''
PI = fn.misc.constant(3.14159265359)
my_k = fn.math.sin( PI * ( fn_r / 5. - 1. ) )
'''

someFn = fn.misc.constant(-1)
fn_r = fn.math.sqrt( fn.math.dot( fn.coord(), fn.coord() ) )
fn_r2 = (10.*temperature+1.)*fn_r

benFn = fn.branching.conditional( [ (fn.coord()[2] > 0.0, fn_r),
                                    (True               , fn_r2) ] )

model.Solve(fn_k=fn_r, fn_f=1., fn_dBC_inner=2., fn_dBC_outer=0.)