예제 #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
파일: mathfunctions.py 프로젝트: FEniCS/ufl
 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
파일: tensors.py 프로젝트: unifem/UFL-Plus
    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
파일: mathfunctions.py 프로젝트: FEniCS/ufl
    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
파일: tensors.py 프로젝트: unifem/UFL-Plus
    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
파일: mathfunctions.py 프로젝트: FEniCS/ufl
 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,))