当前位置: 首页>>代码示例>>Python>>正文


Python constantvalue.as_ufl函数代码示例

本文整理汇总了Python中ufl.constantvalue.as_ufl函数的典型用法代码示例。如果您正苦于以下问题:Python as_ufl函数的具体用法?Python as_ufl怎么用?Python as_ufl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了as_ufl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dot

def dot(a, b):
    "UFL operator: Take the dot product of *a* and *b*. The complex conjugate of the second argument is taken."
    a = as_ufl(a)
    b = as_ufl(b)
    if a.ufl_shape == () and b.ufl_shape == ():
        return a * b
    return Dot(a, b)
开发者ID:firedrakeproject,项目名称:ufl,代码行数:7,代码来源:operators.py

示例2: dot

def dot(a, b):
    "UFL operator: Take the dot product of a and b."
    a = as_ufl(a)
    b = as_ufl(b)
    if a.shape() == () and b.shape() == ():
        return a*b
    return Dot(a, b)
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:7,代码来源:operators.py

示例3: cross

def cross(a, b):
    "UFL operator: Take the cross product of a and b."
    a = as_ufl(a)
    b = as_ufl(b)
    #ufl_assert(a.shape() == (3,) and b.shape() == (3,),
    #           "Expecting 3D vectors in cross product.")
    return Cross(a, b)
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:7,代码来源:operators.py

示例4: inner

def inner(a, b):
    "UFL operator: Take the inner product of *a* and *b*. The complex conjugate of the second argument is taken."
    a = as_ufl(a)
    b = as_ufl(b)
    if a.ufl_shape == () and b.ufl_shape == ():
        return a * Conj(b)
    return Inner(a, b)
开发者ID:firedrakeproject,项目名称:ufl,代码行数:7,代码来源:operators.py

示例5: __init__

    def __init__(self, name, left, right):
        left = as_ufl(left)
        right = as_ufl(right)

        Condition.__init__(self, (left, right))

        self._name = name

        if name in ('!=', '=='):
            # Since equals and not-equals are used for comparing
            # representations, we have to allow any shape here. The
            # scalar properties must be checked when used in
            # conditional instead!
            pass
        elif name in ('&&', '||'):
            # Binary operators acting on boolean expressions allow
            # only conditions
            for arg in (left, right):
                if not isinstance(arg, Condition):
                    error("Expecting a Condition, not %s." % ufl_err_str(arg))
        else:
            # Binary operators acting on non-boolean expressions allow
            # only scalars
            if left.ufl_shape != () or right.ufl_shape != ():
                error("Expecting scalar arguments.")
            if left.ufl_free_indices != () or right.ufl_free_indices != ():
                error("Expecting scalar arguments.")
开发者ID:FEniCS,项目名称:ufl,代码行数:27,代码来源:conditional.py

示例6: __new__

    def __new__(cls, a, b):
        a = as_ufl(a)
        b = as_ufl(b)

        # Assertions
        # TODO: Enabled workaround for nonscalar division in __div__,
        # so maybe we can keep this assertion. Some algorithms may need updating.
        if not is_ufl_scalar(a):
            error("Expecting scalar nominator in Division.")
        if not is_true_ufl_scalar(b):
            error("Division by non-scalar is undefined.")
        if isinstance(b, Zero):
            error("Division by zero!")

        # Simplification a/b -> a
        if isinstance(a, Zero) or b == 1:
            return a
        # Simplification "literal a / literal b" -> "literal value of a/b"
        # Avoiding integer division by casting to float
        if isinstance(a, ScalarValue) and isinstance(b, ScalarValue):
            return as_ufl(float(a._value) / float(b._value))
        # Simplification "a / a" -> "1"
        if not a.free_indices() and not a.shape() and a == b:
            return as_ufl(1)

        # construct and initialize a new Division object
        self = AlgebraOperator.__new__(cls)
        self._init(a, b)
        return self
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:29,代码来源:algebra.py

示例7: inner

def inner(a, b):
    "UFL operator: Take the inner product of a and b."
    a = as_ufl(a)
    b = as_ufl(b)
    if a.shape() == () and b.shape() == ():
        return a*b
    return Inner(a, b)
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:7,代码来源:operators.py

示例8: atan_2

def atan_2(f1,f2):
    "UFL operator: Take the inverse tangent of f."
    f1 = as_ufl(f1)
    f2 = as_ufl(f2)
    r = Atan2(f1, f2)
    if isinstance(r, (ScalarValue, Zero, int, float)):
        return float(r)
    return r
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:8,代码来源:operators.py

示例9: derivative

def derivative(form, coefficient, argument=None, coefficient_derivatives=None):
    """UFL form operator:
    Compute the Gateaux derivative of *form* w.r.t. *coefficient* in direction
    of *argument*.

    If the argument is omitted, a new ``Argument`` is created
    in the same space as the coefficient, with argument number
    one higher than the highest one in the form.

    The resulting form has one additional ``Argument``
    in the same finite element space as the coefficient.

    A tuple of ``Coefficient`` s may be provided in place of
    a single ``Coefficient``, in which case the new ``Argument``
    argument is based on a ``MixedElement`` created from this tuple.

    An indexed ``Coefficient`` from a mixed space may be provided,
    in which case the argument should be in the corresponding
    subspace of the coefficient space.

    If provided, *coefficient_derivatives* should be a mapping from
    ``Coefficient`` instances to their derivatives w.r.t. *coefficient*.
    """

    coefficients, arguments = _handle_derivative_arguments(form, coefficient,
                                                           argument)

    if coefficient_derivatives is None:
        coefficient_derivatives = ExprMapping()
    else:
        cd = []
        for k in sorted_expr(coefficient_derivatives.keys()):
            cd += [as_ufl(k), as_ufl(coefficient_derivatives[k])]
        coefficient_derivatives = ExprMapping(*cd)

    # Got a form? Apply derivatives to the integrands in turn.
    if isinstance(form, Form):
        integrals = []
        for itg in form.integrals():
            if not isinstance(coefficient, SpatialCoordinate):
                fd = CoefficientDerivative(itg.integrand(), coefficients,
                                           arguments, coefficient_derivatives)
            else:
                fd = CoordinateDerivative(itg.integrand(), coefficients,
                                          arguments, coefficient_derivatives)
            integrals.append(itg.reconstruct(fd))
        return Form(integrals)

    elif isinstance(form, Expr):
        # What we got was in fact an integrand
        if not isinstance(coefficient, SpatialCoordinate):
            return CoefficientDerivative(form, coefficients,
                                         arguments, coefficient_derivatives)
        else:
            return CoordinateDerivative(form, coefficients,
                                        arguments, coefficient_derivatives)

    error("Invalid argument type %s." % str(type(form)))
开发者ID:firedrakeproject,项目名称:ufl,代码行数:58,代码来源:formoperators.py

示例10: atan_2

def atan_2(f1, f2):
    "UFL operator: Take the inverse tangent with two the arguments *f1* and *f2*."
    f1 = as_ufl(f1)
    f2 = as_ufl(f2)
    if isinstance(f1, (ComplexValue, complex)) or isinstance(f2, (ComplexValue, complex)):
        raise TypeError('atan_2 is incompatible with complex numbers.')
    r = Atan2(f1, f2)
    if isinstance(r, (RealValue, Zero, int, float)):
        return float(r)
    if isinstance(r, (ComplexValue, complex)):
        return complex(r)
    return r
开发者ID:firedrakeproject,项目名称:ufl,代码行数:12,代码来源:operators.py

示例11: test_float

def test_float(self):
    f1 = as_ufl(1)
    f2 = as_ufl(1.0)
    f3 = FloatValue(1)
    f4 = FloatValue(1.0)
    f5 = 3 - FloatValue(1) - 1
    f6 = 3 * FloatValue(2) / 6

    assert f1 == f1
    self.assertNotEqual(f1, f2)  # IntValue vs FloatValue, == compares representations!
    assert f2 == f3
    assert f2 == f4
    assert f2 == f5
    assert f2 == f6
开发者ID:FEniCS,项目名称:ufl,代码行数:14,代码来源:test_literals.py

示例12: __init__

 def __init__(self, name, classname, nu, argument):
     Operator.__init__(self)
     ufl_assert(is_true_ufl_scalar(nu), "Expecting scalar nu.")
     ufl_assert(is_true_ufl_scalar(argument), "Expecting scalar argument.")
     fnu = float(nu)
     inu = int(nu)
     if fnu == inu:
         nu = as_ufl(inu)
     else:
         nu = as_ufl(fnu)
     self._classname = classname
     self._name     = name
     self._nu       = nu
     self._argument = argument
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:14,代码来源:mathfunctions.py

示例13: test_int

def test_int(self):
    f1 = as_ufl(1)
    f2 = as_ufl(1.0)
    f3 = IntValue(1)
    f4 = IntValue(1.0)
    f5 = 3 - IntValue(1) - 1
    f6 = 3 * IntValue(2) / 6

    assert f1 == f1
    self.assertNotEqual(f1, f2)  # IntValue vs FloatValue, == compares representations!
    assert f1 == f3
    assert f1 == f4
    assert f1 == f5
    assert f2 == f6  # Division produces a FloatValue
开发者ID:FEniCS,项目名称:ufl,代码行数:14,代码来源:test_literals.py

示例14: outer

def outer(*operands):
    "UFL operator: Take the outer product of two or more operands. The complex conjugate of the first argument is taken."
    n = len(operands)
    if n == 1:
        return operands[0]
    elif n == 2:
        a, b = operands
    else:
        a = outer(*operands[:-1])
        b = operands[-1]
    a = as_ufl(a)
    b = as_ufl(b)
    if a.ufl_shape == () and b.ufl_shape == ():
        return Conj(a) * b
    return Outer(a, b)
开发者ID:firedrakeproject,项目名称:ufl,代码行数:15,代码来源:operators.py

示例15: outer

def outer(*operands):
    "UFL operator: Take the outer product of two or more operands."
    n = len(operands)
    if n == 1:
        return operands[0]
    elif n == 2:
        a, b = operands
    else:
        a = outer(*operands[:-1])
        b = operands[-1]
    a = as_ufl(a)
    b = as_ufl(b)
    if a.shape() == () and b.shape() == ():
        return a*b
    return Outer(a, b)
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:15,代码来源:operators.py


注:本文中的ufl.constantvalue.as_ufl函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。