Esempio n. 1
0
def make_data(switch):
    u = sympy.Matrix(
        sympy.sympify("""
        (sin(pi*x)*cos(pi*z),
         cos(pi*x)*sin(pi*y),
         cos(pi*y)*sin(pi*z))
        """))
    if switch[0] == "T":
        l1 = sympy.Matrix(
            sympy.sympify("""
            ((sin(pi*y)*sin(pi*z), sin(pi*z), sin(pi*y)),
             (sin(pi*z), sin(pi*x)*sin(pi*z), sin(pi*x)),
             (sin(pi*y), sin(pi*x), sin(pi*x)*sin(pi*y)))
            """))
    else:
        l1 = sympy.zeros(3, 3)
    if switch[1] == "T":
        l2 = sympy.Matrix(sympy.sympify("(2, 0, 1)"))
    else:
        l2 = sympy.zeros(3, 1)
    if switch[2] == "T":
        l3 = sympy.Matrix(sympy.sympify("(3, 2, -1)"))
    else:
        l3 = sympy.zeros(3, 1)
    if switch[3] == "T":
        l4 = sympy.Matrix(
            sympy.sympify("""
            (( 1,  2, -1),
             ( 3, -3, -3),
             ( 1,  3,  1))
            """))
    else:
        l4 = sympy.zeros(3, 3)
    if switch[4] == "T":
        # l5 = sympy.Matrix(sympy.sympify(
        #     """
        #     (( 10, 0,  0),
        #      ( 0,  10, 0),
        #      ( 0,  0,  0))
        #     """))
        l5 = sympy.Matrix(
            sympy.sympify("""
            ((10,  0,  0),
             ( 0, 10,  0),
             ( 0,  0, 10))
            """))
    else:
        l5 = sympy.zeros(3, 3)
    # compute data in sympy
    du = S.curl(u)
    sigma = -S.div(u) + l2.dot(u)
    dsigma = S.grad(sigma)
    f = dsigma + l3 * sigma + S.curl(du) + l4 * du + S.curl(l1 * u) + l5 * u
    # convert to FEniCS
    f = Expression(S.sympy2exp(f))
    ext_sols = map(Expression, map(S.sympy2exp, (sigma, dsigma, u, du)))
    lots = map(Expression, map(S.sympy2exp, (l1, l2, l3, l4, l5)))
    return (f, lots, ext_sols)
Esempio n. 2
0
def make_data(switch):
    u = sympy.Matrix(sympy.sympify(
        """
        (sin(pi*x)*cos(pi*z),
         cos(pi*x)*sin(pi*y),
         cos(pi*y)*sin(pi*z))
        """))
    if switch[0] == "T":
        l1 = sympy.Matrix(sympy.sympify(
            """
            ((sin(pi*y)*sin(pi*z), sin(pi*z), sin(pi*y)),
             (sin(pi*z), sin(pi*x)*sin(pi*z), sin(pi*x)),
             (sin(pi*y), sin(pi*x), sin(pi*x)*sin(pi*y)))
            """))
    else:
        l1 = sympy.zeros(3, 3)
    if switch[1] == "T":
        l2 = sympy.Matrix(sympy.sympify("(2, 0, 1)"))
    else:
        l2 = sympy.zeros(3, 1)
    if switch[2] == "T":
        l3 = sympy.Matrix(sympy.sympify("(3, 2, -1)"))
    else:
        l3 = sympy.zeros(3, 1)
    if switch[3] == "T":
        l4 = sympy.Matrix(sympy.sympify(
            """
            (( 1,  2, -1),
             ( 3, -3, -3),
             ( 1,  3,  1))
            """))
    else:
        l4 = sympy.zeros(3, 3)
    if switch[4] == "T":
        # l5 = sympy.Matrix(sympy.sympify(
        #     """
        #     (( 10, 0,  0),
        #      ( 0,  10, 0),
        #      ( 0,  0,  0))
        #     """))
        l5 = sympy.Matrix(sympy.sympify(
            """
            ((10,  0,  0),
             ( 0, 10,  0),
             ( 0,  0, 10))
            """))        
    else:
        l5 = sympy.zeros(3, 3)
    # compute data in sympy
    du = S.curl(u)
    sigma = -S.div(u) + l2.dot(u)
    dsigma = S.grad(sigma)
    f = dsigma + l3 * sigma + S.curl(du) + l4 * du + S.curl(l1 * u) + l5 * u
    # convert to FEniCS
    f = Expression(S.sympy2exp(f))
    ext_sols = map(Expression, map(S.sympy2exp, (sigma, dsigma, u, du)))
    lots = map(Expression, map(S.sympy2exp, (l1, l2, l3, l4, l5)))
    return (f, lots, ext_sols)
Esempio n. 3
0
def make_data(switch):
    u = sympy.Matrix(sympy.sympify(
        """
        ((cos(pi*x)+3)*sin(pi*y)*sin(pi*z),
         sin(pi*x)*(cos(pi*y)+2)*sin(pi*z),
         sin(pi*x)*sin(pi*y)*(cos(pi*z)+2))
        """))
    if switch[0] == "T":
        l1 = sympy.Matrix(sympy.sympify("(sin(pi*x), -sin(pi*y), 0)"))
    else:
        l1 = sympy.zeros(3, 1)        
    if switch[1] == "T":
        l2 = sympy.Matrix(sympy.sympify(
            """
            (( 1,  2, -1),
             ( 2, -2,  0),
             ( 1,  3,  1))
            """))
    else:
        l2 = sympy.zeros(3, 3)
    if switch[2] == "T":
        l3 = sympy.Matrix(sympy.sympify(
            """
            (( 1,  0, -1),
             ( 0, -1,  0),
             ( 1,  2,  1))
            """))
    else:
        l3 = sympy.zeros(3, 3)
    if switch[3] == "T":
        l4 = sympy.Matrix(sympy.sympify("(1, 2, -1)"))
    else:
        l4 = sympy.zeros(3, 1)
    if switch[4] == "T":
        l5 = sympy.Matrix(sympy.sympify(
            """
            (( 10, 0,  0),
             ( 0, 10,  0),
             ( 0,  0,  0))
            """))
    else:
        l5 = sympy.zeros(3, 3)
    # compute data in sympy
    du = S.div(u)
    sigma = S.curl(u) + l2 * u
    dsigma = S.curl(sigma)
    f = dsigma + l3 * sigma - S.grad(du) - S.grad(l1.dot(u)) + l4 * du + l5 * u
    # convert to FEniCS
    f = Expression(S.sympy2exp(f))
    ext_sols = map(Expression, map(S.sympy2exp, (sigma, dsigma, u, du)))
    lots = map(Expression, map(S.sympy2exp, (l1, l2, l3, l4, l5)))
    return (f, lots, ext_sols)
Esempio n. 4
0
def make_data(switch):
    u = sympy.Matrix(
        sympy.sympify("""
        ((cos(pi*x)+3)*sin(pi*y)*sin(pi*z),
         sin(pi*x)*(cos(pi*y)+2)*sin(pi*z),
         sin(pi*x)*sin(pi*y)*(cos(pi*z)+2))
        """))
    if switch[0] == "T":
        l1 = sympy.Matrix(sympy.sympify("(sin(pi*x), -sin(pi*y), 0)"))
    else:
        l1 = sympy.zeros(3, 1)
    if switch[1] == "T":
        l2 = sympy.Matrix(
            sympy.sympify("""
            (( 1,  2, -1),
             ( 2, -2,  0),
             ( 1,  3,  1))
            """))
    else:
        l2 = sympy.zeros(3, 3)
    if switch[2] == "T":
        l3 = sympy.Matrix(
            sympy.sympify("""
            (( 1,  0, -1),
             ( 0, -1,  0),
             ( 1,  2,  1))
            """))
    else:
        l3 = sympy.zeros(3, 3)
    if switch[3] == "T":
        l4 = sympy.Matrix(sympy.sympify("(1, 2, -1)"))
    else:
        l4 = sympy.zeros(3, 1)
    if switch[4] == "T":
        l5 = sympy.Matrix(
            sympy.sympify("""
            (( 10, 0,  0),
             ( 0, 10,  0),
             ( 0,  0,  0))
            """))
    else:
        l5 = sympy.zeros(3, 3)
    # compute data in sympy
    du = S.div(u)
    sigma = S.curl(u) + l2 * u
    dsigma = S.curl(sigma)
    f = dsigma + l3 * sigma - S.grad(du) - S.grad(l1.dot(u)) + l4 * du + l5 * u
    # convert to FEniCS
    f = Expression(S.sympy2exp(f))
    ext_sols = map(Expression, map(S.sympy2exp, (sigma, dsigma, u, du)))
    lots = map(Expression, map(S.sympy2exp, (l1, l2, l3, l4, l5)))
    return (f, lots, ext_sols)