How to use the underworld.function.branching.map 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
idx = material.index
            if material.viscosity and material.plasticity:
                EffViscosityMap[idx] = fn.misc.min(PlasticityMap[idx], ViscosityMap[idx])
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.viscosity:
                EffViscosityMap[idx] = ViscosityMap[idx]
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.plasticity:
                EffViscosityMap[idx] = PlasticityMap[idx]
                BGViscosityMap[idx] = PlasticityMap[idx]
                PlasticMap[idx] = 1.0

        viscosityFn = fn.branching.map(fn_key=self.materialField, mapping=EffViscosityMap)
        backgroundViscosityFn = fn.branching.map(fn_key=self.materialField,mapping=BGViscosityMap)

        isPlastic = fn.branching.map(fn_key=self.materialField, mapping=PlasticMap)
        yieldConditions = [(viscosityFn < backgroundViscosityFn, 1.0),
                           (isPlastic > 0.5, 1.0),
                           (True, 0.0)]

        self.isYielding = fn.branching.conditional(yieldConditions) * self.strainRate_2ndInvariant
        
        return viscosityFn
github underworldcode / underworld2 / docs / development / models_broken / LemialeEtAl2008 / data_comp / Lemiale-Parallel.py View on Github external
# In[15]:

# iterative over 
viscIterate = viscosityFn * (3.0 * alpha * pressureField + kFn) * fn.exception.SafeMaths( 
                                                        fn.misc.max(0.0, 1./(yieldStressFn+1.0e-14) ))

# apply criterion and calculate viscosity everywhere
conditions = [ ( yieldStressFn > 3.0 * alpha * pressureField + kFn , viscIterate ),     # plastic
               (                                              True , etaV        ) ]    # viscous

# 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.
viscPlastic = fn.branching.conditional( conditions )

viscosityMap = { materialA:etaA, materialV:viscPlastic, materialW:etaW }
viscosityFn  = fn.branching.map( fn_key = materialVariable, mapping = viscosityMap )


# Buoyancy forces
# ----
# 
# Densites of materials are different, so gravity does play a role.
# 

# In[16]:

# Define our vertical unit vector using a python tuple (this will be automatically converted to a function).
z_hat = ( 0.0, 1.0 )

# Now create a buoyancy force vector using the density (FEvariable) and the vertical unit vector. 
buoyancyFn = -densityFn*z_hat
github underworldcode / underworld2 / docs / examples / 1_10_BucklingBeamCompression.py View on Github external
# DeviatoricStress

devStressFn = 2.0 * viscosityFn * strainRateFn


# ### Buoyancy forces
# 
# In this example, no buoyancy forces are considered. However, to establish an appropriate pressure gradient in the material, it would normally be useful to map density from material properties and create a buoyancy force.

# In[16]:

densityMap = { materialA: 0.0, materialV:1.0, materialU:10.0 }

densityFn = fn.branching.map( fn_key=materialVariable, mapping=densityMap )

# And the final buoyancy force function.
z_hat = ( 0.0, 1.0 )
buoyancyFn = -densityFn * z_hat


# System setup
# -----
# 
# Setup a Stokes equation system and connect a solver up to it.  
# 
# In this example, no buoyancy forces are considered. However, to establish an appropriate pressure gradient in the material, it would normally be useful to map density from material properties and create a buoyancy force.

# In[17]:

stokesPIC = uw.systems.Stokes( velocityField = velocityField,
github underworldcode / underworld2 / unsupported / geodynamics / Model.py View on Github external
for material in self.materials:
            idx = material.index
            if material.viscosity and material.plasticity:
                EffViscosityMap[idx] = fn.misc.min(PlasticityMap[idx], ViscosityMap[idx])
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.viscosity:
                EffViscosityMap[idx] = ViscosityMap[idx]
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.plasticity:
                EffViscosityMap[idx] = PlasticityMap[idx]
                BGViscosityMap[idx] = PlasticityMap[idx]
                PlasticMap[idx] = 1.0

        viscosityFn = fn.branching.map(fn_key=self.materialField, mapping=EffViscosityMap)
        backgroundViscosityFn = fn.branching.map(fn_key=self.materialField,mapping=BGViscosityMap)

        isPlastic = fn.branching.map(fn_key=self.materialField, mapping=PlasticMap)
        yieldConditions = [(viscosityFn < backgroundViscosityFn, 1.0),
                           (isPlastic > 0.5, 1.0),
                           (True, 0.0)]

        self.isYielding = fn.branching.conditional(yieldConditions) * self.strainRate_2ndInvariant
        
        return viscosityFn
github underworldcode / underworld2 / unsupported / geodynamics / Model.py View on Github external
EffViscosityMap[idx] = fn.misc.min(PlasticityMap[idx], ViscosityMap[idx])
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.viscosity:
                EffViscosityMap[idx] = ViscosityMap[idx]
                BGViscosityMap[idx] = ViscosityMap[idx]
                PlasticMap[idx] = 0.
            elif material.plasticity:
                EffViscosityMap[idx] = PlasticityMap[idx]
                BGViscosityMap[idx] = PlasticityMap[idx]
                PlasticMap[idx] = 1.0

        viscosityFn = fn.branching.map(fn_key=self.materialField, mapping=EffViscosityMap)
        backgroundViscosityFn = fn.branching.map(fn_key=self.materialField,mapping=BGViscosityMap)

        isPlastic = fn.branching.map(fn_key=self.materialField, mapping=PlasticMap)
        yieldConditions = [(viscosityFn < backgroundViscosityFn, 1.0),
                           (isPlastic > 0.5, 1.0),
                           (True, 0.0)]

        self.isYielding = fn.branching.conditional(yieldConditions) * self.strainRate_2ndInvariant
        
        return viscosityFn
github underworldcode / underworld2 / docs / examples / 1_05_StokesSinker.py View on Github external
# Here the functions for density and viscosity are set using the ``map`` function. This function evaluates a key function (here the material index), and the result (i.e. the key) is used to determine which function to evaluate to obtain the actual result (such as the particle density). 
# 
# For example if the material index of a particle is the light index number then the viscosity for that particle will be set to 1. If it had the heavy index number then it will be set to ``visc_sphere``, which can be either a function (say depending on temperature) or a constant as it is below.
# 
# The same approach is taken when setting up the density function for each particle in the swarm.

# In[12]:

# Set constants for the viscosity and density of the sinker.
viscSphere = 10.0
densitySphere = 10.0

# Here we set a viscosity value of '1.' for both materials 
mappingDictViscosity = { materialLightIndex:1., materialHeavyIndex:viscSphere }
# Create the viscosity map function.
viscosityMapFn = fn.branching.map( fn_key=materialIndex, mapping=mappingDictViscosity )
# Here we set a density of '0.' for the lightMaterial, and '1.' for the heavymaterial.
mappingDictDensity = { materialLightIndex:0., materialHeavyIndex:densitySphere }
# Create the density map function.
densityFn = fn.branching.map( fn_key=materialIndex, mapping=mappingDictDensity )

# And the final buoyancy force function.
z_hat = ( 0.0, 1.0 )
buoyancyFn = -densityFn * z_hat


# System setup
# -----
# 
# **Setup a Stokes system**

# In[13]:
github underworldcode / underworld2 / underworld / function / branching.py View on Github external
raise ValueError("You must specify a key function via the 'fn_key' parameter.")
        fn_key = _Function.convert(fn_key)

        self.fn_default = _Function.convert(fn_default)
        if self.fn_default == None:
            fn_defaultCself = None
        else:
            fn_defaultCself = self.fn_default._fncself
        # create instance
        self._fncself = _cfn.Map( fn_key._fncself, fn_defaultCself )

        self._fn_key  = fn_key
        self._mapping = mapping

        # build parent
        super(map,self).__init__(argument_fns=[fn_key,self.fn_default],**kwargs)
        
        self._map = {}

        for key, value in mapping.items():
            if not isinstance(key, int) or key < 0:
                raise ValueError("Key '{}' not valid. Mapping keys must be unsigned integers.".format(key))
            funcVal = _Function.convert(value)
            if funcVal == None:
                raise ValueError("'None' is not valid for mapped functions.")
            
            self._underlyingDataItems.update(funcVal._underlyingDataItems) # update dictionary
            # insert mapping and keep handles in py dict
            self._map[key] = funcVal
            self._fncself.insert( key, funcVal._fncself )
github underworldcode / underworld2 / unsupported / geodynamics / Model.py View on Github external
def init_advection_diffusion(self):
        DiffusivityMap = {}
        for material in self.materials:
            DiffusivityMap[material.index] = nd(material.diffusivity)
        
        self.DiffusivityFn = fn.branching.map(fn_key=self.materialField,
                                              mapping=DiffusivityMap)
       
        HeatProdMap = {}
        for material in self.materials:
            HeatProdMap[material.index] = (nd(material.radiogenicHeatProd) /
                                           (nd(material.density) *
                                            nd(material.capacity)))
        
        self.HeatProdFn = fn.branching.map(fn_key=self.materialField,
                                           mapping=HeatProdMap)
        
        self.advdiffSystem = uw.systems.AdvectionDiffusion(
                self.temperature,
                self._temperatureDot,
                velocityField=self.velocityField,
                fn_diffusivity=self.DiffusivityFn,
github underworldcode / underworld2 / docs / development / models_broken / LemialeEtAl2008 / data_comp / Lemiale-Parallel.py View on Github external
( ((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.
# 
# **Define first iteration of first timestep**
# 
# Set all viscosities to the constant values. For the plastic region this is used to calculate the effective viscosity by iterating later.
# 

# In[13]:

viscosityMap = { materialA:etaA, materialV:etaV, materialW:etaW }
viscosityFn  = fn.branching.map( fn_key = materialVariable, mapping = viscosityMap )