• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python constantvalue.as_ufl函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_scalar_sums

def test_scalar_sums(self):
    n = 10
    s = [as_ufl(i) for i in range(n)]

    for i in range(n):
        self.assertNotEqual(s[i], i+1)

    for i in range(n):
        assert s[i] == i

    for i in range(n):
        assert 0 + s[i] == i

    for i in range(n):
        assert s[i] + 0 == i

    for i in range(n):
        assert 0 + s[i] + 0 == i

    for i in range(n):
        assert 1 + s[i] - 1 == i

    assert s[1] + s[1] == 2
    assert s[1] + s[2] == 3
    assert s[1] + s[2] + s[3] == s[6]
    assert s[5] - s[2] == 3
    assert 1*s[5] == 5
    assert 2*s[5] == 10
    assert s[6]/3 == 2
开发者ID:FEniCS,项目名称:ufl,代码行数:29,代码来源:test_literals.py


示例17: Dn

def Dn(f):
    """UFL operator: Take the directional derivative of *f* in the
    facet normal direction, Dn(f) := dot(grad(f), n)."""
    f = as_ufl(f)
    if is_cellwise_constant(f):
        return Zero(f.ufl_shape, f.ufl_free_indices, f.ufl_index_dimensions)
    return dot(grad(f), FacetNormal(f.ufl_domain()))
开发者ID:firedrakeproject,项目名称:ufl,代码行数:7,代码来源:operators.py


示例18: _mathfunction

def _mathfunction(f, cls):
    f = as_ufl(f)
    r = cls(f)
    if isinstance(r, (RealValue, Zero, int, float)):
        return float(r)
    if isinstance(r, (ComplexValue, complex)):
        return complex(r)
    return r
开发者ID:firedrakeproject,项目名称:ufl,代码行数:8,代码来源:operators.py


示例19: Dn

def Dn(f):
    """UFL operator: Take the directional derivative of f in the
    facet normal direction, Dn(f) := dot(grad(f), n)."""
    f = as_ufl(f)
    cell = f.cell()
    if cell is None: # FIXME: Rather if f.is_cellwise_constant()?
        return Zero(f.shape(), f.free_indices(), f.index_dimensions())
    return dot(grad(f), cell.n)
开发者ID:maciekswat,项目名称:dolfin_python_deps,代码行数:8,代码来源:operators.py


示例20: test_complex

def test_complex(self):
    f1 = as_ufl(1 + 1j)
    f2 = as_ufl(1)
    f3 = as_ufl(1j)
    f4 = ComplexValue(1 + 1j)
    f5 = ComplexValue(1.0 + 1.0j)
    f6 = as_ufl(1.0)
    f7 = as_ufl(1.0j)

    assert f1 == f1
    assert f1 == f4
    assert f1 == f5  # ComplexValue uses floats
    assert f1 == f2 + f3  # Type promotion of IntValue to ComplexValue with arithmetic
    assert f4 == f2 + f3
    assert f5 == f2 + f3
    assert f4 == f5
    assert f6 + f7 == f2 + f3
开发者ID:FEniCS,项目名称:ufl,代码行数:17,代码来源:test_literals.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.error函数代码示例发布时间:2022-05-27
下一篇:
Python assertions.ufl_assert函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap