本文整理汇总了Python中ufl.assertions.ufl_assert函数的典型用法代码示例。如果您正苦于以下问题:Python ufl_assert函数的具体用法?Python ufl_assert怎么用?Python ufl_assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ufl_assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *cells):
"Create a ProductCell from a given list of cells."
self._cells = cells
ufl_assert(len(self._cells) > 0, "Expecting at least one cell")
self._cellname = self._cells[0].cellname()#" x ".join([c.cellname() for c in cells])
self._topological_dimension = sum(c.topological_dimension() for c in cells)
self._geometric_dimension = sum(c.geometric_dimension() for c in cells)
self._repr = "ProductCell(*%r)" % list(self._cells)
self._n = None
self._x = SpatialCoordinate(self) # For now
self._xi = None # ?
self._J = None # ?
self._Jinv = None # ?
self._detJ = None # ?
self._volume = None
self._circumradius = None
self._cellsurfacearea = None
self._facetarea = None # Not defined
self._facetdiameter = None # Not defined
示例2: list_tensor
def list_tensor(self, f): # TODO: Is this right? Fix for higher order tensors too.
"d/dx_i [x_0, ..., x_n-1] = e_i (unit vector)"
ops = f.operands()
n = len(ops)
s = ops[0].shape()
ufl_assert(s == (), "TODO: Assuming a vector, i.e. scalar operands.")
return unit_vectors(n) # TODO: Non-scalars
示例3: __init__
def __init__(self, arg1, arg2):
Operator.__init__(self)
ufl_assert(is_true_ufl_scalar(arg1), "Expecting scalar argument 1.")
ufl_assert(is_true_ufl_scalar(arg2), "Expecting scalar argument 2.")
self._name = "atan_2"
self._arg1 = arg1
self._arg2 = arg2
示例4: diag
def diag(A):
"""UFL operator: Take the diagonal part of rank 2 tensor A _or_
make a diagonal rank 2 tensor from a rank 1 tensor.
Always returns a rank 2 tensor. See also diag_vector."""
# TODO: Make a compound type or two for this operator
# Get and check dimensions
r = A.rank()
if r == 1:
n, = A.shape()
elif r == 2:
m, n = A.shape()
ufl_assert(m == n, "Can only take diagonal of square tensors.")
else:
error("Expecting rank 1 or 2 tensor.")
# Build matrix row by row
rows = []
for i in range(n):
row = [0]*n
row[i] = A[i] if r == 1 else A[i,i]
rows.append(row)
return as_matrix(rows)
示例5: _square_matrix_shape
def _square_matrix_shape(self, A):
sh = A.shape()
if self._dim is not None:
sh = complete_shape(sh, self._dim) # FIXME: Does this ever happen? Pretty sure other places assume shapes are always "complete".
ufl_assert(sh[0] == sh[1], "Expecting square matrix.")
ufl_assert(sh[0] is not None, "Unknown dimension.")
return sh
示例6: _variable_derivative
def _variable_derivative(self, o, f, v):
f, fp = f
v, vp = v
ufl_assert(isinstance(vp, Zero), "TODO: What happens if vp != 0, i.e. v depends the differentiation variable?")
# Are there any issues with indices here? Not sure, think through it...
oprime = o.reconstruct(fp, v)
return (o, oprime)
示例7: restricted
def restricted(self, o):
ufl_assert(self.current_restriction is None,
"Not expecting twice restricted expression.")
self.current_restriction = o._side
e, = o.operands()
self.visit(e)
self.current_restriction = None
示例8: component_tensor
def component_tensor(self, f):
x, i = f.operands()
s = f.shape()
ufl_assert(len(s) == 1, "TODO: Assuming a vector, i.e. scalar operands.")
n, = s
d = ListTensor([1]*n) # TODO: Non-scalars
return (d, None)
示例9: __init__
def __init__(self, *elements):
"Create TensorProductElement from a given list of elements."
self._sub_elements = list(elements)
ufl_assert(len(self._sub_elements) > 0,
"Cannot create TensorProductElement from empty list.")
self._repr = "TensorProductElement(*%r)" % self._sub_elements
family = "TensorProductElement"
# Define cell as the product of each subcell
cell = ProductCell(*[e.cell() for e in self._sub_elements])
domain = as_domain(cell) # FIXME: figure out what this is supposed to mean :)
# Define polynomial degree as the maximal of each subelement
degree = max(e.degree() for e in self._sub_elements)
# No quadrature scheme defined
quad_scheme = None
# For now, check that all subelements have the same value
# shape, and use this.
# TODO: Not sure if this makes sense, what kind of product is used to build the basis?
value_shape = self._sub_elements[0].value_shape()
ufl_assert(all(e.value_shape() == value_shape
for e in self._sub_elements),
"All subelements in must have same value shape")
super(TensorProductElement, self).__init__(family, domain, degree,
quad_scheme, value_shape)
示例10: extract_subelement_component
def extract_subelement_component(self, i):
"""Extract direct subelement index and subelement relative
component index for a given component index"""
if isinstance(i, int):
i = (i,)
self._check_component(i)
# Select between indexing modes
if len(self.value_shape()) == 1:
# Indexing into a long vector of flattened subelement shapes
j, = i
# Find subelement for this index
for k, e in enumerate(self._sub_elements):
sh = e.value_shape()
si = product(sh)
if j < si:
break
j -= si
ufl_assert(j >= 0, "Moved past last value component!")
# Convert index into a shape tuple
j = index_to_component(j, sh)
else:
# Indexing into a multidimensional tensor
# where subelement index is first axis
k = i[0]
ufl_assert(k < len(self._sub_elements),
"Illegal component index (dimension %d)." % k)
j = i[1:]
return (k, j)
示例11: __add__
def __add__(self, other):
"Add two elements, creating an enriched element"
ufl_assert(isinstance(other, FiniteElementBase),
"Can't add element and %s." % other.__class__)
warning_blue("WARNING: Creating an EnrichedElement,\n " +\
"if you intended to create a MixedElement use '*' instead of '+'.")
from ufl.finiteelement import EnrichedElement
return EnrichedElement(self, other)
示例12: __init__
def __init__(self, spatial_dim, coefficients, arguments, coefficient_derivatives, cache=None):
ForwardAD.__init__(self, spatial_dim, var_shape=(), var_free_indices=(),
var_index_dimensions={}, cache=cache)
self._v = arguments
self._w = coefficients
self._cd = coefficient_derivatives
ufl_assert(isinstance(self._w, Tuple), "Expecting a Tuple.")
ufl_assert(isinstance(self._v, Tuple), "Expecting a Tuple.")
示例13: d
def d(self):
"""The dimension of the cell.
Only valid if the geometric and topological dimensions are the same."""
ufl_assert(self._topological_dimension == self._geometric_dimension,
"Cell.d is undefined when geometric and"+\
"topological dimensions are not the same.")
return self._geometric_dimension
示例14: __init__
def __init__(self, integrals):
self._dintegrals = integral_sequence_to_dict(integrals)
ufl_assert(all(isinstance(itg, Integral) for itg in integrals),
"Expecting list of integrals.")
self._signature = None
self._hash = None
self._form_data = None
self._is_preprocessed = False
示例15: reconstruct
def reconstruct(self, **kwargs):
kwargs["family"] = kwargs.get("family", self.family())
kwargs["domain"] = kwargs.get("domain", self.domain())
kwargs["degree"] = kwargs.get("degree", self.degree())
ufl_assert("dim" not in kwargs, "Cannot change dim in reconstruct.")
kwargs["dim"] = len(self._sub_elements)
kwargs["quad_scheme"] = kwargs.get("quad_scheme", self.quadrature_scheme())
return VectorElement(**kwargs)