def _mesh2domain(mesh): "Deprecation mechanism for symbolic geometry." if isinstance(mesh, ufl.Cell): raise TypeError( "Cannot construct geometry from a Cell. Pass the mesh instead, for example use FacetNormal(mesh) instead of FacetNormal(triangle) or triangle.n" ) return ufl.as_domain(mesh)
def get_common_domain(mesh, common_cell): if mesh is not None: if common_cell is not None: raise RuntimeError("Please provide only mesh, common_cell is deprecated.") return mesh.ufl_domain() else: if common_cell is None: return None else: # TODO: Enable deprecation warning, later remove common_cell argument #deprecation_warning("Please provide only mesh, common_cell is deprecated.") return ufl.as_domain(common_cell)
def get_common_domain(mesh, common_cell): if mesh is not None: if common_cell is not None: raise RuntimeError( "Please provide only mesh, common_cell is deprecated.") return mesh.ufl_domain() else: if common_cell is None: return None else: # TODO: Enable deprecation warning, later remove common_cell argument #deprecation_warning("Please provide only mesh, common_cell is deprecated.") return ufl.as_domain(common_cell)
def CellSize(mesh): """ Return cell size function for given mesh. *Arguments* mesh a :py:class:`Mesh <dolfin.cpp.Mesh>`. *Example of usage* .. code-block:: python mesh = UnitSquare(4,4) h = CellSize(mesh) """ return 2.0*ufl.Circumradius(ufl.as_domain(mesh))
def CellVolume(mesh): # TODO: Remove this when we can pass mesh directly to ufl.CellVolume """ Return cell volume function for given mesh. *Arguments* mesh a :py:class:`Mesh <dolfin.cpp.Mesh>`. *Example of usage* .. code-block:: python mesh = UnitSquare(4,4) vol = CellVolume(mesh) """ return ufl.CellVolume(ufl.as_domain(mesh))
def FacetNormal(mesh): """ Return facet normal function for given mesh. *Arguments* mesh a :py:class:`Mesh <dolfin.cpp.Mesh>`. *Example of usage* .. code-block:: python mesh = UnitSquare(4,4) n = FacetNormal(mesh) """ return ufl.FacetNormal(ufl.as_domain(mesh))
def __init__(self, value, domain=None): # Init also called in mesh constructor, but constant can be built without mesh utils._init() self.dat, rank, shape = _globalify(value) cell = None if domain is not None: domain = ufl.as_domain(domain) cell = domain.ufl_cell() if rank == 0: e = ufl.FiniteElement("Real", cell, 0) elif rank == 1: e = ufl.VectorElement("Real", cell, 0, shape[0]) elif rank == 2: e = ufl.TensorElement("Real", cell, 0, shape=shape) fs = ufl.FunctionSpace(domain, e) super(Constant, self).__init__(fs) self._repr = 'Constant(%r, %r)' % (self.ufl_element(), self.count())
def __init__(self, value, cell=None, name=None): """ Create constant-valued function with given value. *Arguments* value The value may be either a single scalar value, or a tuple/list of values for vector-valued functions, or nested lists or a numpy array for tensor-valued functions. cell Optional argument. A :py:class:`Cell <ufl.Cell>` which defines the geometrical dimensions the Constant is defined for. name Optional argument. A str which overrules the default name of the Constant. The data type Constant represents a constant value that is unknown at compile-time. Its values can thus be changed without requiring re-generation and re-compilation of C++ code. *Examples of usage* .. code-block:: python p = Constant(pi/4) # scalar C = Constant((0.0, -1.0, 0.0)) # constant vector """ if cell is None: domain = None else: #deprecation_warning("The cell argument is no longer necessary.") domain = ufl.as_domain(cell) if not isinstance(domain, (ufl.Domain,)): raise TypeError("Expected an ufl.Domain as the second argument") array = numpy.array(value) rank = len(array.shape) floats = map(float, array.flat) # Create UFL element and initialize constant if rank == 0: self._ufl_element = ufl.FiniteElement("Real", domain, 0) cpp.Constant.__init__(self, floats[0]) elif rank == 1: self._ufl_element = ufl.VectorElement("Real", domain, 0, len(floats)) cpp.Constant.__init__(self, floats) else: self._ufl_element = ufl.TensorElement("Real", domain, 0, shape=array.shape) cpp.Constant.__init__(self, list(array.shape), floats) # Initialize base classes ufl.Coefficient.__init__(self, self._ufl_element, count=self.id()) # Set name as given or automatic name = name or "f_%d" % self.count() self.rename(name, "a Constant")
def __init__(self, value, cell=None, name=None): """ Create constant-valued function with given value. *Arguments* value The value may be either a single scalar value, or a tuple/list of values for vector-valued functions, or nested lists or a numpy array for tensor-valued functions. cell Optional argument. A :py:class:`Cell <ufl.Cell>` which defines the geometrical dimensions the Constant is defined for. name Optional argument. A str which overrules the default name of the Constant. The data type Constant represents a constant value that is unknown at compile-time. Its values can thus be changed without requiring re-generation and re-compilation of C++ code. *Examples of usage* .. code-block:: python p = Constant(pi/4) # scalar C = Constant((0.0, -1.0, 0.0)) # constant vector """ if cell is None: domain = None else: #deprecation_warning("The cell argument is no longer necessary.") domain = ufl.as_domain(cell) if not isinstance(domain, ufl.Domain): raise TypeError( "Expected an ufl.Domain as the second argument") array = numpy.array(value) rank = len(array.shape) floats = list(map(float, array.flat)) # Create UFL element and initialize constant if rank == 0: self._ufl_element = ufl.FiniteElement("Real", domain, 0) cpp.Constant.__init__(self, floats[0]) elif rank == 1: self._ufl_element = ufl.VectorElement("Real", domain, 0, len(floats)) cpp.Constant.__init__(self, floats) else: self._ufl_element = ufl.TensorElement("Real", domain, 0, shape=array.shape) cpp.Constant.__init__(self, list(array.shape), floats) # Initialize base classes ufl.Coefficient.__init__(self, self._ufl_element, count=self.id()) # Set name as given or automatic name = name or "f_%d" % self.count() self.rename(name, "a Constant")
def _mesh2domain(mesh): "Deprecation mechanism for symbolic geometry." if isinstance(mesh, ufl.Cell): cpp.deprecation("Constructing geometry from a Cell", "1.4", "1.5", "Pass mesh instead, for example use FacetNormal(mesh) instead of FacetNormal(triangle) or triangle.n") return ufl.as_domain(mesh)
def _mesh2domain(mesh): "Deprecation mechanism for symbolic geometry." if isinstance(mesh, ufl.Cell): raise TypeError("Cannot construct geometry from a Cell. Pass the mesh instead, for example use FacetNormal(mesh) instead of FacetNormal(triangle) or triangle.n") return ufl.as_domain(mesh)