Esempio n. 1
0
def hpBases(C, xi, eta, zeta, Transform=0, EvalOpt=0, equally_spaced=False):
    """
        Transform:                  transform to from degenrate quad
        EvalOpt:                    evaluate 1 as an approximation 0.9999999
    """

    eps = FeketePointsTet(C)
    if equally_spaced:
        eps = EquallySpacedPointsTet(C)

    N = eps.shape[0]
    # Make the Vandermonde matrix
    V = np.zeros((N, N))

    for i in range(0, N):
        x = eps[i, :]
        p = NormalisedJacobiTet(C, x)
        V[i, :] = p

    nsize = int((C + 2.) * (C + 3.) * (C + 4.) / 6.)

    Bases = np.zeros((nsize, 1))
    gBases = np.zeros((nsize, 3))

    # GradNormalisedJacobiTet IS ALWAYS CALLED WITH (HEX) R,S,T COORDINATE
    if Transform:
        # IF A TRANSFORMATION TO HEX COORDINATE IS NEEDED
        r, s, t = MapXiEtaZeta2RST(xi, eta, zeta)
        p, dp_dxi, dp_deta, dp_dzeta = GradNormalisedJacobiTet(
            C, np.array([r, s, t]), EvalOpt)
    else:
        # IF XI,ETA,ZETA ARE DIRECTLY GIVEN IN HEX FORMAT
        p, dp_dxi, dp_deta, dp_dzeta = GradNormalisedJacobiTet(
            C, np.array([xi, eta, zeta]), EvalOpt)

    # ACTUAL WAY
    # Bases = np.linalg.solve(V.T,p)
    # gBases[:,0] = np.linalg.solve(V.T,dp_dxi)
    # gBases[:,1] = np.linalg.solve(V.T,dp_deta)
    # gBases[:,2] = np.linalg.solve(V.T,dp_dzeta)

    # SOLVE FOR MULTIPLE RIGHT HAND SIDES
    # ps = np.concatenate((p[:,None],dp_dxi[:,None],dp_deta[:,None],dp_dzeta[:,None]),axis=1)
    ps = np.concatenate((p, dp_dxi, dp_deta, dp_dzeta)).reshape(4,
                                                                p.shape[0]).T
    tup = np.linalg.solve(V.T, ps)
    Bases = tup[:, 0]
    gBases[:, 0] = tup[:, 1]
    gBases[:, 1] = tup[:, 2]
    gBases[:, 2] = tup[:, 3]

    return Bases, gBases
Esempio n. 2
0
def test_quadrature_functionspace():

    print("Running tests on QuadratureRule and FunctionSpace modules")

    mesh = Mesh()
    etypes = ["line", "tri", "quad", "tet", "hex"]
    for etype in etypes:

        if etype == "line":
            mesh.Line()
        elif etype == "tri":
            mesh.Circle(element_type="tri")
        elif etype == "quad":
            mesh.Circle(element_type="quad")
        elif etype == "tet":
            mesh.Cube(element_type="tet", nx=1, ny=1, nz=1)
        elif etype == "hex":
            mesh.Cube(element_type="hex", nx=1, ny=1, nz=1)

        for p in range(2, 7):
            mesh.GetHighOrderMesh(p=p, check_duplicates=False)

            q = QuadratureRule(mesh_type=etype, norder=p + 2, flatten=False)
            FunctionSpace(mesh, q, p=p, equally_spaced=False)
            FunctionSpace(mesh, q, p=p, equally_spaced=True)

            q = QuadratureRule(mesh_type=etype, norder=p + 2, flatten=True)
            FunctionSpace(mesh, q, p=p, equally_spaced=False)
            FunctionSpace(mesh, q, p=p, equally_spaced=True)

    # now test all Fekete/ES point creation
    from Florence.QuadratureRules import FeketePointsTri
    from Florence.QuadratureRules.QuadraturePointsWeightsTri import QuadraturePointsWeightsTri
    from Florence.QuadratureRules import FeketePointsTet
    from Florence.QuadratureRules.QuadraturePointsWeightsTet import QuadraturePointsWeightsTet
    from Florence.QuadratureRules import GaussLobattoPoints1D, GaussLobattoPointsQuad, GaussLobattoPointsHex
    from Florence.QuadratureRules.QuadraturePointsWeightsTri import QuadraturePointsWeightsTri
    from Florence.QuadratureRules.WVQuadraturePointsWeightsQuad import WVQuadraturePointsWeightsQuad
    from Florence.QuadratureRules.WVQuadraturePointsWeightsHex import WVQuadraturePointsWeightsHex
    from Florence.QuadratureRules.EquallySpacedPoints import EquallySpacedPoints, EquallySpacedPointsTri, EquallySpacedPointsTet
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementLine, NodeArrangementTri, NodeArrangementQuad
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementTet, NodeArrangementHex, NodeArrangementQuadToTri
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementHexToTet, NodeArrangementLayeredToHex

    for i in range(21):
        FeketePointsTri(i)
        QuadraturePointsWeightsTri(i, 3)
        QuadraturePointsWeightsTet(i)
        EquallySpacedPoints(2, i)
        EquallySpacedPoints(3, i)
        EquallySpacedPoints(4, i)
        EquallySpacedPointsTri(i)
        EquallySpacedPointsTet(i)

        NodeArrangementLine(i)
        NodeArrangementTri(i)
        NodeArrangementQuad(i)
        NodeArrangementHex(i)
        NodeArrangementLayeredToHex(i)

        if i < 6:
            NodeArrangementQuadToTri(i)

        if i < 2:
            NodeArrangementHexToTet(i)

        if i < 18:
            FeketePointsTet(i)
            NodeArrangementTet(i)
        WVQuadraturePointsWeightsQuad(i)
        if i <= 16:
            WVQuadraturePointsWeightsHex(i)

    print(
        "Successfully finished running tests on QuadratureRule and FunctionSpace modules\n"
    )
Esempio n. 3
0
def GetBasesAtNodes(C,
                    Quadrature,
                    info,
                    bases_type="nodal",
                    equally_spaced=False):

    ns = []
    Basis = []
    gBasisx = []
    gBasisy = []
    gBasisz = []
    if info == 'hex' or info == "quad":
        w = 2
        if info == "quad": ndim = 2
        elif info == "hex": ndim = 3
        ns = int((C + 2)**ndim)
        # GET THE BASES AT NODES INSTEAD OF GAUSS POINTS
        Basis = np.zeros((ns, ns))
        gBasisx = np.zeros((ns, ns))
        gBasisy = np.zeros((ns, ns))
        gBasisz = np.zeros((ns, ns))
    elif info == 'tet':
        p = C + 1
        ns = int((p + 1) * (p + 2) * (p + 3) / 6)
        # GET BASES AT NODES INSTEAD OF GAUSS POINTS
        Basis = np.zeros((ns, ns))
        gBasisx = np.zeros((ns, ns))
        gBasisy = np.zeros((ns, ns))
        gBasisz = np.zeros((ns, ns))
    elif info == 'tri':
        p = C + 1
        ns = int((p + 1) * (p + 2) / 2)
        # GET BASES AT NODES INSTEAD OF GAUSS POINTS
        Basis = np.zeros((ns, ns))
        gBasisx = np.zeros((ns, ns))
        gBasisy = np.zeros((ns, ns))
    elif info == 'line':
        ns = int(C + 2)
        # GET THE BASES AT NODES INSTEAD OF GAUSS POINTS
        Basis = np.zeros((ns, ns))
        gBasisx = np.zeros((ns, ns))

    eps = []
    if info == 'hex':
        counter = 0
        if not equally_spaced:
            eps = GaussLobattoPointsHex(C)
            hpBases = Hex.LagrangeGaussLobatto
            GradhpBases = Hex.GradLagrangeGaussLobatto
        else:
            eps = EquallySpacedPoints(4, C)
            hpBases = HexES.Lagrange
            GradhpBases = HexES.GradLagrange

        for i in range(0, eps.shape[0]):
            ndummy = hpBases(C, eps[i, 0], eps[i, 1], eps[i, 2], arrange=1)
            Basis[:, counter] = ndummy[:, 0]
            dummy = GradhpBases(C, eps[i, 0], eps[i, 1], eps[i, 2], arrange=1)
            gBasisx[:, counter] = dummy[:, 0]
            gBasisy[:, counter] = dummy[:, 1]
            gBasisz[:, counter] = dummy[:, 2]
            counter += 1

    elif info == 'quad':
        if not equally_spaced:
            eps = GaussLobattoPointsQuad(C)
            hpBases = Quad.LagrangeGaussLobatto
            GradhpBases = Quad.GradLagrangeGaussLobatto
        else:
            eps = EquallySpacedPoints(3, C)
            hpBases = QuadES.Lagrange
            GradhpBases = QuadES.GradLagrange

        counter = 0
        for i in range(0, eps.shape[0]):
            ndummy = hpBases(C, eps[i, 0], eps[i, 1], arrange=1)
            Basis[:, counter] = ndummy[:, 0]
            dummy = GradhpBases(C, eps[i, 0], eps[i, 1], arrange=1)
            gBasisx[:, counter] = dummy[:, 0]
            gBasisy[:, counter] = dummy[:, 1]
            counter += 1

    elif info == 'tet':
        if not equally_spaced:
            eps = FeketePointsTet(C)
        else:
            eps = EquallySpacedPointsTet(C)
        hpBases = Tet.hpNodal.hpBases

        counter = 0
        for i in range(0, eps.shape[0]):
            ndummy, dummy = hpBases(C,
                                    eps[i, 0],
                                    eps[i, 1],
                                    eps[i, 2],
                                    1,
                                    1,
                                    equally_spaced=equally_spaced)
            ndummy = ndummy.reshape(ndummy.shape[0], 1)
            Basis[:, counter] = ndummy[:, 0]
            gBasisx[:, counter] = dummy[:, 0]
            gBasisy[:, counter] = dummy[:, 1]
            gBasisz[:, counter] = dummy[:, 2]
            counter += 1

    elif info == 'tri':
        if not equally_spaced:
            eps = FeketePointsTri(C)
        else:
            eps = EquallySpacedPointsTri(C)
        hpBases = Tri.hpNodal.hpBases

        for i in range(0, eps.shape[0]):
            ndummy, dummy = hpBases(C,
                                    eps[i, 0],
                                    eps[i, 1],
                                    1,
                                    1,
                                    equally_spaced=equally_spaced)
            ndummy = ndummy.reshape(ndummy.shape[0], 1)
            Basis[:, i] = ndummy[:, 0]
            gBasisx[:, i] = dummy[:, 0]
            gBasisy[:, i] = dummy[:, 1]

    elif info == 'line':
        if not equally_spaced:
            eps = GaussLobattoQuadrature(C + 2)[0]
            hpBases = Line.LagrangeGaussLobatto
        else:
            eps = EquallySpacedPoints(2, C)
            hpBases = Line.Lagrange

        # We probably need node arrangment for lines
        counter = 0
        for i in range(0, eps.shape[0]):
            ndummy = hpBases(C, eps[i, 0])
            Basis[:, counter] = ndummy[0][i]
            gBasisx[:, counter] = ndummy[1][i]
            counter += 1

    class Domain(object):
        Bases = Basis
        gBasesx = gBasisx
        gBasesy = gBasisy
        w = np.ones(eps.shape[0])

    if info == "hex" or info == "tet":
        Domain.gBasesz = gBasisz
    elif info == "tri" or info == "quad":
        Domain.gBasesz = np.zeros_like(gBasisx)
    elif info == "line":
        Domain.gBasesy = np.zeros_like(gBasisx)
        Domain.gBasesz = np.zeros_like(gBasisx)

    if info == "hex" or info == "quad":
        Domain.w = np.ones(C + 2)

    return Domain