def __init__(self, *expressions): Operator.__init__(self, expressions) # Checks indexset = set(self.ufl_operands[0].ufl_free_indices) if not all(not (indexset ^ set(e.ufl_free_indices)) for e in self.ufl_operands): error("Can't combine subtensor expressions with different sets of free indices.")
def __init__(self, arg1, arg2): Operator.__init__(self, (arg1, arg2)) if isinstance(arg1, (ComplexValue, complex)) or isinstance(arg2, (ComplexValue, complex)): raise TypeError("Atan2 does not support complex numbers.") if not is_true_ufl_scalar(arg1): error("Expecting scalar argument 1.") if not is_true_ufl_scalar(arg2): error("Expecting scalar argument 2.")
def __init__(self, arg1, arg2): Operator.__init__(self, (arg1, arg2)) if isinstance(arg1, (ComplexValue, complex)) or isinstance( arg2, (ComplexValue, complex)): raise TypeError("Atan2 does not support complex numbers.") if not is_true_ufl_scalar(arg1): error("Expecting scalar argument 1.") if not is_true_ufl_scalar(arg2): error("Expecting scalar argument 2.")
def __init__(self, summand, index): j, = index fi = summand.ufl_free_indices fid = summand.ufl_index_dimensions pos = fi.index(j.count()) self._dimension = fid[pos] self.ufl_free_indices = fi[:pos] + fi[pos + 1:] self.ufl_index_dimensions = fid[:pos] + fid[pos + 1:] Operator.__init__(self, (summand, index))
def __init__(self, summand, index): j, = index fi = summand.ufl_free_indices fid = summand.ufl_index_dimensions pos = fi.index(j.count()) self._dimension = fid[pos] self.ufl_free_indices = fi[:pos] + fi[pos+1:] self.ufl_index_dimensions = fid[:pos] + fid[pos+1:] Operator.__init__(self, (summand, index))
def __init__(self, *expressions): Operator.__init__(self, expressions) # Checks indexset = set(self.ufl_operands[0].ufl_free_indices) if not all(not (indexset ^ set(e.ufl_free_indices)) for e in self.ufl_operands): error( "Can't combine subtensor expressions with different sets of free indices." )
def __init__(self, expression, multiindex): # Store operands Operator.__init__(self, (expression, multiindex)) # Error checking if not isinstance(expression, Expr): error("Expecting Expr instance, not %s." % ufl_err_str(expression)) if not isinstance(multiindex, MultiIndex): error("Expecting MultiIndex instance, not %s." % ufl_err_str(multiindex)) shape = expression.ufl_shape # Error checking if len(shape) != len(multiindex): error("Invalid number of indices (%d) for tensor " "expression of rank %d:\n\t%s\n" % (len(multiindex), len( expression.ufl_shape), ufl_err_str(expression))) if any( int(di) >= int(si) or int(di) < 0 for si, di in zip(shape, multiindex) if isinstance(di, FixedIndex)): error("Fixed index out of range!") # Build tuples of free index ids and dimensions if 1: efi = expression.ufl_free_indices efid = expression.ufl_index_dimensions fi = list(zip(efi, efid)) for pos, ind in enumerate(multiindex._indices): if isinstance(ind, Index): fi.append((ind.count(), shape[pos])) fi = unique_sorted_indices(sorted(fi)) if fi: fi, fid = zip(*fi) else: fi, fid = (), () else: mfiid = [(ind.count(), shape[pos]) for pos, ind in enumerate(multiindex._indices) if isinstance(ind, Index)] mfi, mfid = zip(*mfiid) if mfiid else ((), ()) fi, fid = merge_unique_indices(expression.ufl_free_indices, expression.ufl_index_dimensions, mfi, mfid) # Cache free index and dimensions self.ufl_free_indices = fi self.ufl_index_dimensions = fid
def __init__(self, expression, label=None): # Conversion expression = as_ufl(expression) if label is None: label = Label() # Checks if not isinstance(expression, Expr): error("Expecting Expr.") if not isinstance(label, Label): error("Expecting a Label.") if expression.ufl_free_indices: error("Variable cannot wrap an expression with free indices.") Operator.__init__(self, (expression, label))
def __init__(self, expression, label=None): # Conversion expression = as_ufl(expression) if label is None: label = Label() # Checks if not isinstance(expression, Expr): error("Expecting Expr.") if not isinstance(label, Label): error("Expecting a Label.") if expression.ufl_free_indices: error("Variable cannot wrap an expression with free indices.") Operator.__init__(self, (expression, label))
def __init__(self, expression, multiindex): # Store operands Operator.__init__(self, (expression, multiindex)) # Error checking if not isinstance(expression, Expr): error("Expecting Expr instance, not %s." % ufl_err_str(expression)) if not isinstance(multiindex, MultiIndex): error("Expecting MultiIndex instance, not %s." % ufl_err_str(multiindex)) shape = expression.ufl_shape # Error checking if len(shape) != len(multiindex): error("Invalid number of indices (%d) for tensor " "expression of rank %d:\n\t%s\n" % (len(multiindex), len(expression.ufl_shape), ufl_err_str(expression))) if any(int(di) >= int(si) for si, di in zip(shape, multiindex) if isinstance(di, FixedIndex)): error("Fixed index out of range!") # Build tuples of free index ids and dimensions if 1: efi = expression.ufl_free_indices efid = expression.ufl_index_dimensions fi = list(zip(efi, efid)) for pos, ind in enumerate(multiindex._indices): if isinstance(ind, Index): fi.append((ind.count(), shape[pos])) fi = unique_sorted_indices(sorted(fi)) if fi: fi, fid = zip(*fi) else: fi, fid = (), () else: mfiid = [(ind.count(), shape[pos]) for pos, ind in enumerate(multiindex._indices) if isinstance(ind, Index)] mfi, mfid = zip(*mfiid) if mfiid else ((), ()) fi, fid = merge_unique_indices(expression.ufl_free_indices, expression.ufl_index_dimensions, mfi, mfid) # Cache free index and dimensions self.ufl_free_indices = fi self.ufl_index_dimensions = fid
def __init__(self, name, classname, nu, argument): if not is_true_ufl_scalar(nu): error("Expecting scalar nu.") if not is_true_ufl_scalar(argument): error("Expecting scalar argument.") # Use integer representation if suitable fnu = float(nu) inu = int(nu) if fnu == inu: nu = as_ufl(inu) else: nu = as_ufl(fnu) Operator.__init__(self, (nu, argument)) self._classname = classname self._name = name
def __init__(self, name, classname, nu, argument): if not is_true_ufl_scalar(nu): error("Expecting scalar nu.") if not is_true_ufl_scalar(argument): error("Expecting scalar argument.") # Use integer representation if suitable fnu = float(nu) inu = int(nu) if fnu == inu: nu = as_ufl(inu) else: nu = as_ufl(fnu) Operator.__init__(self, (nu, argument)) self._classname = classname self._name = name
def __init__(self, expression, indices): if not isinstance(expression, Expr): error("Expecting ufl expression.") if expression.ufl_shape != (): error("Expecting scalar valued expression.") if not isinstance(indices, MultiIndex): error("Expecting a MultiIndex.") if not all(isinstance(i, Index) for i in indices): error("Expecting sequence of Index objects, not %s." % indices._ufl_err_str_()) Operator.__init__(self, (expression, indices)) fi, fid, sh = remove_indices(expression.ufl_free_indices, expression.ufl_index_dimensions, [ind.count() for ind in indices]) self.ufl_free_indices = fi self.ufl_index_dimensions = fid self.ufl_shape = sh
def __init__(self, expression, indices): if not isinstance(expression, Expr): error("Expecting ufl expression.") if expression.ufl_shape != (): error("Expecting scalar valued expression.") if not isinstance(indices, MultiIndex): error("Expecting a MultiIndex.") if not all(isinstance(i, Index) for i in indices): error("Expecting sequence of Index objects, not %s." % indices._ufl_err_str_()) Operator.__init__(self, (expression, indices)) fi, fid, sh = remove_indices(expression.ufl_free_indices, expression.ufl_index_dimensions, [ind.count() for ind in indices]) self.ufl_free_indices = fi self.ufl_index_dimensions = fid self.ufl_shape = sh
def __init__(self, condition, true_value, false_value): if not isinstance(condition, Condition): error("Expectiong condition as first argument.") true_value = as_ufl(true_value) false_value = as_ufl(false_value) tsh = true_value.ufl_shape fsh = false_value.ufl_shape if tsh != fsh: error("Shape mismatch between conditional branches.") tfi = true_value.ufl_free_indices ffi = false_value.ufl_free_indices if tfi != ffi: error("Free index mismatch between conditional branches.") if isinstance(condition, (EQ, NE)): if not all((condition.ufl_operands[0].ufl_shape == (), condition.ufl_operands[0].ufl_free_indices == (), condition.ufl_operands[1].ufl_shape == (), condition.ufl_operands[1].ufl_free_indices == ())): error("Non-scalar == or != is not allowed.") Operator.__init__(self, (condition, true_value, false_value))
def __init__(self, condition, true_value, false_value): if not isinstance(condition, Condition): error("Expectiong condition as first argument.") true_value = as_ufl(true_value) false_value = as_ufl(false_value) tsh = true_value.ufl_shape fsh = false_value.ufl_shape if tsh != fsh: error("Shape mismatch between conditional branches.") tfi = true_value.ufl_free_indices ffi = false_value.ufl_free_indices if tfi != ffi: error("Free index mismatch between conditional branches.") if isinstance(condition, (EQ, NE)): if not all((condition.ufl_operands[0].ufl_shape == (), condition.ufl_operands[0].ufl_free_indices == (), condition.ufl_operands[1].ufl_shape == (), condition.ufl_operands[1].ufl_free_indices == ())): error("Non-scalar == or != is not allowed.") Operator.__init__(self, (condition, true_value, false_value))
def __init__(self, *operands): Operator.__init__(self, operands) if not all(isinstance(i, Expr) for i in operands): error("Expecting Expr in ExprList.")
def __init__(self, f): Operator.__init__(self, (f, ))
def __init__(self, *operands): Operator.__init__(self, operands) if not all(isinstance(e, Expr) for e in operands): error("Expecting Expr in ExprMapping.")
def __init__(self, a): Operator.__init__(self, (a, )) if not isinstance(a, Expr): error("Expecting Expr instance, not %s." % ufl_err_str(a))
def __init__(self, arg1, arg2): Operator.__init__(self, (arg1, arg2)) if not is_true_ufl_scalar(arg1): error("Expecting scalar argument 1.") if not is_true_ufl_scalar(arg2): error("Expecting scalar argument 2.")
def __init__(self, name, argument): Operator.__init__(self, (argument,)) if not is_true_ufl_scalar(argument): error("Expecting scalar argument.") self._name = name
def __init__(self, a, b): Operator.__init__(self)
def __init__(self, a): Operator.__init__(self, (a, ))
def __init__(self, name, argument): Operator.__init__(self, (argument, )) if not is_true_ufl_scalar(argument): error("Expecting scalar argument.") self._name = name
def __init__(self, f): if not isinstance(f, FormArgument): error("Can only take reference value of form arguments.") Operator.__init__(self, (f, ))
def __init__(self, *operands): Operator.__init__(self, operands) if not all(isinstance(i, Expr) for i in operands): error("Expecting Expr in ExprList.")
def __init__(self, left, right): Operator.__init__(self, (left, right)) if not (is_true_ufl_scalar(left) and is_true_ufl_scalar(right)): error("Expecting scalar arguments.")
def __init__(self, left, right): Operator.__init__(self, (left, right)) if not (is_true_ufl_scalar(left) and is_true_ufl_scalar(right)): error("Expecting scalar arguments.")
def __init__(self, f): Operator.__init__(self, (f,))
def __init__(self, *operands): Operator.__init__(self, operands) if not all(isinstance(e, Expr) for e in operands): error("Expecting Expr in ExprMapping.")
def __init__(self, operands): Operator.__init__(self, operands)
def __init__(self, f): if not isinstance(f, FormArgument): error("Can only take reference value of form arguments.") Operator.__init__(self, (f,))