Esempio n. 1
0
    def _visit_LogicalValueNode(self, expr, **kwargs):
        mapping = self.mapping
        expr = expr.expr
        if isinstance(expr, SymbolicDeterminant):
            return SymbolicExpr(mapping.det_jacobian)

        elif isinstance(expr, SymbolicInverseDeterminant):
            return SymbolicExpr(1. / SymbolicDeterminant(mapping))

        elif isinstance(expr, WeightedVolumeQuadrature):
            l_quad = TensorQuadrature()
            l_quad = self._visit(l_quad, **kwargs)

            points, weights = list(zip(*l_quad))
            wvol = Mul(*weights)
            return wvol

        elif isinstance(expr, SymbolicWeightedVolume):
            wvol = self._visit(expr, **kwargs)
            det_jac = SymbolicDeterminant(mapping)
            det_jac = SymbolicExpr(det_jac)
            return wvol * Abs(det_jac)

        else:
            raise TypeError('{} not available'.format(type(expr)))
Esempio n. 2
0
    def _visit_PhysicalValueNode(self, expr, **kwargs):
        mapping = self.mapping
        expr = LogicalExpr(mapping, expr.expr)
        expr = SymbolicExpr(expr)

        inv_jac = SymbolicInverseDeterminant(mapping)
        jac = SymbolicExpr(mapping.det_jacobian)
        expr = expr.subs(1 / jac, inv_jac)

        return expr
Esempio n. 3
0
def test_derivatives_2d_with_mapping():

    dim = 2
    M = Mapping('M', dim=dim)
    O = M(Domain('Omega', dim=dim))
    V = ScalarFunctionSpace('V', O, kind='h1')
    u = element_of(V, 'u')

    det_jac = Jacobian(M).det()
    J = Symbol('J')

    expr = M
    assert SymbolicExpr(expr) == Symbol('M')

    expr = M[0]
    assert SymbolicExpr(expr) == Symbol('x')

    expr = M[1]
    assert SymbolicExpr(expr) == Symbol('y')

    expr = dx2(M[0])
    assert SymbolicExpr(expr) == Symbol('x_x2')

    expr = dx1(M[1])
    assert SymbolicExpr(expr) == Symbol('y_x1')

    expr = LogicalExpr(dx(u), O).subs(det_jac, J)
    expected = '(u_x1 * y_x2 - u_x2 * y_x1)/J'
    difference = SymbolicExpr(expr) - sympify(expected)
    assert difference.simplify() == 0
Esempio n. 4
0
def test_derivatives_2d_without_mapping():

    O = Domain('Omega', dim=2)
    V = ScalarFunctionSpace('V', O)
    u = element_of(V, 'u')

    expr = u
    assert SymbolicExpr(expr) == Symbol('u')

    expr = dx(u)
    assert SymbolicExpr(expr) == Symbol('u_x')

    expr = dx(dx(u))
    assert SymbolicExpr(expr) == Symbol('u_xx')

    expr = dx(dy(u))
    assert SymbolicExpr(expr) == Symbol('u_xy')

    expr = dy(dx(u))
    assert SymbolicExpr(expr) == Symbol('u_xy')

    expr = dy(dx(dz(u)))
    assert SymbolicExpr(expr) == Symbol('u_xyz')

    expr = dy(dy(dx(u)))
    assert SymbolicExpr(expr) == Symbol('u_xyy')

    expr = dy(dz(dy(u)))
    assert SymbolicExpr(expr) == Symbol('u_yyz')
Esempio n. 5
0
    def _visit_MatrixLocalBasis(self, expr, **kwargs):
        dim = self.dim
        rank = self._visit(expr.rank)
        target = SymbolicExpr(expr.target)

        name = 'arr_{}'.format(target.name)
        return IndexedVariable(name, dtype='real', rank=rank)
Esempio n. 6
0
    def _visit_AtomicNode(self, expr, **kwargs):
        if isinstance(expr.expr, WeightedVolumeQuadrature):
            mapping = self.mapping
            expr = SymbolicWeightedVolume(mapping)
            return self._visit(expr, **kwargs)

        else:
            return SymbolicExpr(expr.expr)
Esempio n. 7
0
    def _visit_ComputeKernelExpr(self, expr, op=None, lhs=None, **kwargs):
        expr = expr.expr
        if lhs is None:
            if not isinstance(expr, (Add, Mul)):
                lhs = self._visit(BasisAtom(expr), **kwargs)
            else:
                lhs = random_string(6)
                lhs = Symbol('tmp_{}'.format(lhs))

        weight = SymbolicWeightedVolume(self.mapping)
        weight = SymbolicExpr(weight)

        rhs = self._visit(expr, **kwargs)
        rhs *= weight

        if op is None:
            stmt = Assign(lhs, rhs)

        else:
            stmt = AugAssign(lhs, op, rhs)

        return self._visit(stmt, **kwargs)
Esempio n. 8
0
    def _visit_LogicalBasisValue(self, expr, **kwargs):
        # ...
        dim = self.dim
        coords = ['x1', 'x2', 'x3'][:dim]

        expr = expr.expr
        atom = BasisAtom(expr).atom
        atoms = _split_test_function(atom)

        ops = [dx1, dx2, dx3][:dim]
        d_atoms = dict(zip(coords, atoms))
        d_ops = dict(zip(coords, ops))
        d_indices = get_index_logical_derivatives(expr)
        args = []
        for k, u in d_atoms.items():
            d = d_ops[k]
            n = d_indices[k]
            for i in range(n):
                u = d(u)
            args.append(u)
        # ...

        expr = Mul(*args)
        return SymbolicExpr(expr)
Esempio n. 9
0
def test_symbolic_expr_1d_1():
    rdim = 1

    M = Mapping('M', rdim)
    domain = M(Domain('Omega', dim=rdim))

    alpha = Constant('alpha')

    V = ScalarFunctionSpace('V', domain, kind='h1')

    u = element_of(V, name='u')

    det_M = Jacobian(M).det()
    det_M = SymbolicExpr(det_M)
    #print('>>> ', det_M)
    det = Symbol('det')

    # ...
    expr = u
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(u)
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(M[0])
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx(u)
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expr)
    # ...

    # ...
    expr = dx(Jacobian(M).det())
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(u))
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(dx(u)))
    expr = LogicalExpr(expr, mapping=M, dim=rdim)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
Esempio n. 10
0
def test_symbolic_expr_3d_1():
    dim = 3
    M = Mapping('M', dim=dim)
    domain = M(Domain('Omega', dim=dim))

    V = ScalarFunctionSpace('V', domain, kind='h1')
    u = element_of(V, 'u')

    det_M = Jacobian(M).det()
    det_M = SymbolicExpr(det_M)
    #print('>>> ', det_M)
    det = Symbol('det')

    # ...
    expr = u
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(u)
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(dx2(u))
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(M[0])
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx(u)
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expr)
    # ...

    # ...
    expr = dx(Jacobian(M).det())
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(u))
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(dx(u)))
    expr = LogicalExpr(expr, domain)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
Esempio n. 11
0
def test_symbolic_expr_3d_1():
    rdim = 3

    M = Mapping('M', rdim)
    domain = Domain('Omega', dim=rdim)

    alpha = Constant('alpha')

    V = ScalarFunctionSpace('V', domain)
    u = element_of(V, 'u')

    det_M = DetJacobian(M)
    det_M = SymbolicExpr(det_M)
    #print('>>> ', det_M)
    det = Symbol('det')

    # ...
    expr = u
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(u)
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(dx2(u))
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx1(M[0])
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    #print(expr)
    # ...

    # ...
    expr = dx(u)
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expr)
    # ...

    # ...
    expr = dx(DetJacobian(M))
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(u))
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
    #print(expand(expr))
    # ...

    # ...
    expr = dx(dx(dx(u)))
    expr = LogicalExpr(M, expr)
    expr = SymbolicExpr(expr)
    expr = expr.subs(det_M, det)
Esempio n. 12
0
 def _visit_Expr(self, expr, **kwargs):
     return SymbolicExpr(expr)
Esempio n. 13
0
    def _visit_PhysicalGeometryValue(self, expr, **kwargs):
        mapping = self.mapping
        expr = LogicalExpr(mapping, expr.expr)

        return SymbolicExpr(expr)
Esempio n. 14
0
 def _visit_BasisAtom(self, expr, **kwargs):
     symbol = SymbolicExpr(expr.expr)
     return symbol
Esempio n. 15
0
 def _visit_CoefficientBasis(self, expr, **kwargs):
     target = SymbolicExpr(expr.target)
     name = 'coeff_{}'.format(target.name)
     return Variable('real', name)