Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if _fn_viscosity2:
_fn_viscosity2 = uw.function.Function.convert(_fn_viscosity2)
if not isinstance( _fn_viscosity2, uw.function.Function):
raise TypeError( "Provided 'fn_viscosity2' must be of or convertible to 'Function' class." )
if not isinstance( _removeBCs, bool):
raise TypeError( "Provided '_removeBCs' must be of type bool." )
self._removeBCs = _removeBCs
if _fn_director:
_fn_director = uw.function.Function.convert(_fn_director)
if not isinstance( _fn_director, uw.function.Function):
raise TypeError( "Provided 'fn_director' must be of or convertible to 'Function' class." )
if fn_stresshistory:
fn_stresshistory = uw.function.Function.convert(fn_stresshistory)
if not isinstance( fn_stresshistory, uw.function.Function):
raise TypeError( "Provided 'fn_stresshistory' must be of or convertible to 'Function' class." )
self._fn_minus_one_on_lambda = None
if fn_one_on_lambda != None:
self._fn_minus_one_on_lambda = uw.function.Function.convert(-1.0 * fn_one_on_lambda)
if not isinstance(self._fn_minus_one_on_lambda, uw.function.Function):
raise ValueError("Provided 'fn_minus_one_on_lambda' must be of, or convertible to, the 'Function' class.")
if fn_source != None:
self._fn_source = uw.function.Function.convert(fn_source)
if not isinstance(self._fn_source, uw.function.Function):
raise ValueError("Provided 'fn_source' must be of, or convertible to, the 'Function' class.")
if not fn_bodyforce:
if velocityField.mesh.dim == 2:
def fn_flux(self, fn):
""" Set the underworld.Function that defines the flux """
_fn = uw.function.Function.convert(fn)
if not isinstance( _fn, uw.function.Function):
raise ValueError( "Provided '_fn' must be of or convertible to 'Function' class." )
self._fn_flux = _fn
def __init__(self, mesh, fn, crossSection="", resolution=[100,100,1],
colourBar=True,
offsetEdges=None, onMesh=False,
*args, **kwargs):
self._onMesh = onMesh
#Check the mesh has a valid vertGridId, if not then we can't use onMesh
#(Invalid should be -1, but is read as unsigned (4294967295) from python for some reason
# valid value should be small, so just treat any large integer as invalid)
if mesh._mesh.vertGridId > 1000 or mesh._mesh.vertGridId < 0:
self._onMesh = False
self._fn = _underworld.function.Function.convert(fn)
if not isinstance(mesh,_uwmesh.FeMesh):
raise TypeError("'mesh' object passed in must be of type 'FeMesh'")
self._mesh = mesh
if not isinstance(crossSection,str):
raise ValueError("'crossSection' parameter must be of python type 'str'")
self._crossSection = crossSection
self._offsetEdges = offsetEdges
if not isinstance( resolution, (list,tuple)):
if isinstance(resolution,int):
resolution = [resolution,resolution,1]
else:
raise TypeError("'resolution' passed in must be of type 'int', 'list' or 'tuple'")
for el in resolution:
def __init__(self, swarm, fn_colour=None, fn_mask=None, fn_size=None, colourVariable=None,
colourBar=True, *args, **kwargs):
if not isinstance(swarm,_swarmMod.Swarm):
raise TypeError("'swarm' object passed in must be of type 'Swarm'")
self._swarm = swarm
self._fn_colour = None
if fn_colour != None:
self._fn_colour = _underworld.function.Function.convert(fn_colour)
else:
colourBar = False
self._fn_mask = None
if fn_mask != None:
self._fn_mask = _underworld.function.Function.convert(fn_mask)
self._fn_size = None
if fn_size != None:
self._fn_size = _underworld.function.Function.convert(fn_size)
# build parent
super(Points,self).__init__(colourBar=colourBar, *args, **kwargs)
def __init__(self, variable, indexSetsPerDof=None, fn_flux=None ):
# call parent
super(NeumannCondition,self).__init__(variable, indexSetsPerDof)
_fn_flux = uw.function.Function.convert(fn_flux)
if not isinstance( _fn_flux, uw.function.Function):
raise TypeError( "Provided 'fn_flux' must be of or convertible to 'Function' class." )
self.fn_flux=_fn_flux
if not isinstance( velocityField, uw.mesh.MeshVariable):
raise TypeError( "Provided 'velocityField' must be of 'MeshVariable' class." )
if velocityField.nodeDofCount != velocityField.mesh.dim:
raise ValueError( "Provided 'velocityField' must be a vector field of same dimensionality as its mesh." )
self._velocityField = velocityField
if not isinstance( pressureField, uw.mesh.MeshVariable):
raise TypeError( "Provided 'pressureField' must be of 'MeshVariable' class." )
if pressureField.nodeDofCount != 1:
raise ValueError( "Provided 'pressureField' must be a scalar field (ie pressureField.nodeDofCount==1)." )
self._pressureField = pressureField
_fn_viscosity = uw.function.Function.convert(fn_viscosity)
if not isinstance( _fn_viscosity, uw.function.Function):
raise TypeError( "Provided 'fn_viscosity' must be of or convertible to 'Function' class." )
if _fn_viscosity2:
_fn_viscosity2 = uw.function.Function.convert(_fn_viscosity2)
if not isinstance( _fn_viscosity2, uw.function.Function):
raise TypeError( "Provided 'fn_viscosity2' must be of or convertible to 'Function' class." )
if not isinstance( _removeBCs, bool):
raise TypeError( "Provided '_removeBCs' must be of type bool." )
self._removeBCs = _removeBCs
if _fn_director:
_fn_director = uw.function.Function.convert(_fn_director)
if not isinstance( _fn_director, uw.function.Function):
raise TypeError( "Provided 'fn_director' must be of or convertible to 'Function' class." )
if fn_stresshistory:
fn_stresshistory = uw.function.Function.convert(fn_stresshistory)
if not isinstance( fn_stresshistory, uw.function.Function):
raise TypeError( "Provided 'fn_stresshistory' must be of or convertible to 'Function' class." )
def __init__(self, phiField, velocityField, fn_diffusivity, fn_sourceTerm=None, conditions=[]):
"""Implements the Spiegelman / Katz Semi-lagrangian Advection / Crank Nicholson Diffusion algorithm"""
mesh = velocityField.mesh
# unknown field and velocity field
self.phiField = phiField
self.vField = velocityField
# uw.functions for diffusivity and a source term
self.fn_diffusivity = uw.function.Function.convert(fn_diffusivity)
self.fn_sourceTerm = uw.function.Function.convert(fn_sourceTerm)
self.fn_dt = uw.function.misc.constant(1.0) # dummy value
# build a grid field, phiStar, for the information at departure points
self._phiStar = phiField.copy()
# placeholder for swarm-based _mesh_interpolator_stripy
self._mswarm = None
self._mswarm_advector = None
# check input 'conditions' list is valid
if not isinstance(conditions, (list, tuple)):
conditionslist = []
conditionslist.append(conditions)
conditions = conditionslist
def validateFn(_fn, name="N/A"):
fn = uw.function.Function.convert(_fn)
if not isinstance( fn, uw.function.Function):
raise TypeError( "Provided object '"+name+"' must be of or convertible to 'Function' class." )
return fn
def fn_one_on_lambda(self, newFn):
if hasattr(self, '_compressibleTerm'):
self._fn_minus_one_on_lambda = uw.function.Function.convert(-1.0*newFn)
self._compressibleTerm._fn = self._fn_minus_one_on_lambda
self._compressibleTerm._set_fn_function(self._compressibleTerm._cself, self._fn_minus_one_on_lambda._fncself)
else:
import warnings
warnings.warn("Cannot add fn_minus_one_on_lambda to existing stokes object. Instead you should build a new object with fn_minus_one_on_lambda defined", RuntimeWarning)
def __init__(self, temperatureField, fn_diffusivity, fn_heating=0., voronoi_swarm=None, conditions=[], _removeBCs=True, **kwargs):
if not isinstance( temperatureField, uw.mesh.MeshVariable):
raise TypeError( "Provided 'temperatureField' must be of 'MeshVariable' class." )
self._temperatureField = temperatureField
try:
_fn_diffusivity = uw.function.Function.convert(fn_diffusivity)
except Exception as e:
raise uw._prepend_message_to_exception(e, "Exception encountered. Note that provided 'fn_diffusivity' must be of or convertible to 'Function' class.\nEncountered exception message:\n")
try:
_fn_heating = uw.function.Function.convert(fn_heating)
except Exception as e:
raise uw._prepend_message_to_exception(e, "Exception encountered. Note that provided 'fn_heating' must be of or convertible to 'Function' class.\nEncountered exception message:\n")
if voronoi_swarm and not isinstance(voronoi_swarm, uw.swarm.Swarm):
raise TypeError( "Provided 'swarm' must be of 'Swarm' class." )
self._swarm = voronoi_swarm
if voronoi_swarm and temperatureField.mesh.elementType=='Q2':
import warnings
warnings.warn("Voronoi integration may yield unsatisfactory results for Q2 element types.")
if not isinstance( _removeBCs, bool):