示例#1
0
    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.")
示例#2
0
 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.")
示例#3
0
 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.")
示例#4
0
 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))
示例#5
0
文件: indexsum.py 项目: FEniCS/ufl
 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))
示例#6
0
    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."
            )
示例#7
0
    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
示例#8
0
    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))
示例#9
0
文件: variable.py 项目: FEniCS/ufl
    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))
示例#10
0
文件: indexed.py 项目: FEniCS/ufl
    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
示例#11
0
    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
示例#12
0
    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
示例#13
0
    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
示例#14
0
    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
示例#15
0
    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))
示例#16
0
文件: conditional.py 项目: FEniCS/ufl
    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))
示例#17
0
 def __init__(self, *operands):
     Operator.__init__(self, operands)
     if not all(isinstance(i, Expr) for i in operands):
         error("Expecting Expr in ExprList.")
示例#18
0
 def __init__(self, f):
     Operator.__init__(self, (f, ))
示例#19
0
 def __init__(self, *operands):
     Operator.__init__(self, operands)
     if not all(isinstance(e, Expr) for e in operands):
         error("Expecting Expr in ExprMapping.")
示例#20
0
 def __init__(self, a):
     Operator.__init__(self, (a, ))
     if not isinstance(a, Expr):
         error("Expecting Expr instance, not %s." % ufl_err_str(a))
示例#21
0
 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.")
示例#22
0
 def __init__(self, name, argument):
     Operator.__init__(self, (argument,))
     if not is_true_ufl_scalar(argument):
         error("Expecting scalar argument.")
     self._name = name
示例#23
0
 def __init__(self, a, b):
     Operator.__init__(self)
示例#24
0
 def __init__(self, a):
     Operator.__init__(self, (a, ))
示例#25
0
 def __init__(self, name, argument):
     Operator.__init__(self, (argument, ))
     if not is_true_ufl_scalar(argument):
         error("Expecting scalar argument.")
     self._name = name
示例#26
0
 def __init__(self, f):
     if not isinstance(f, FormArgument):
         error("Can only take reference value of form arguments.")
     Operator.__init__(self, (f, ))
示例#27
0
 def __init__(self, *operands):
     Operator.__init__(self, operands)
     if not all(isinstance(i, Expr) for i in operands):
         error("Expecting Expr in ExprList.")
示例#28
0
文件: conditional.py 项目: FEniCS/ufl
 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.")
示例#29
0
 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.")
示例#30
0
文件: restriction.py 项目: FEniCS/ufl
 def __init__(self, f):
     Operator.__init__(self, (f,))
示例#31
0
 def __init__(self, *operands):
     Operator.__init__(self, operands)
     if not all(isinstance(e, Expr) for e in operands):
         error("Expecting Expr in ExprMapping.")
示例#32
0
 def __init__(self, operands):
     Operator.__init__(self, operands)
示例#33
0
 def __init__(self, f):
     if not isinstance(f, FormArgument):
         error("Can only take reference value of form arguments.")
     Operator.__init__(self, (f,))