Exemplo n.º 1
0
def HighOrderMeshLine(C,
                      mesh,
                      Decimals=10,
                      equally_spaced=False,
                      check_duplicates=True,
                      Parallel=False,
                      nCPU=1):

    from Florence.FunctionSpace import Line
    from Florence.QuadratureRules import GaussLobattoPoints1D
    from Florence.QuadratureRules.EquallySpacedPoints import EquallySpacedPoints
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementLine

    # ARRANGE NODES FOR LINES HERE (DONE ONLY FOR LINES) - IMPORTANT
    node_aranger = NodeArrangementLine(C)

    if not equally_spaced:
        eps = GaussLobattoPoints1D(C).ravel()
        eps = eps[node_aranger]
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((2, eps.shape[0]), dtype=np.float64)
        for i in range(0, eps.shape[0]):
            Neval[:, i] = Line.LagrangeGaussLobatto(0, eps[i])[0]
    else:
        eps = EquallySpacedPoints(2, C).ravel()
        eps = eps[node_aranger]
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((2, eps.shape[0]), dtype=np.float64)
        for i in range(0, eps.shape[0]):
            Neval[:, i] = Line.Lagrange(0, eps[i])[0]
    makezero(Neval)

    nodeperelem = mesh.elements.shape[1]
    renodeperelem = int(C + 2)
    left_over_nodes = renodeperelem - nodeperelem

    reelements = -1 * np.ones(
        (mesh.elements.shape[0], renodeperelem), dtype=np.int64)
    reelements[:, :2] = mesh.elements
    iesize = int(C)
    repoints = np.zeros(
        (mesh.points.shape[0] + iesize * mesh.elements.shape[0],
         mesh.points.shape[1]),
        dtype=np.float64)
    repoints[:mesh.points.shape[0], :] = mesh.points

    #--------------------------------------------------------------------------------------
    telements = time()

    xycoord_higher = []
    ParallelTuple1 = []
    if Parallel:
        # GET HIGHER ORDER COORDINATES - PARALLEL
        ParallelTuple1 = parmap.map(ElementLoopTri,
                                    np.arange(0, mesh.elements.shape[0]),
                                    mesh.elements,
                                    mesh.points,
                                    'line',
                                    eps,
                                    Neval,
                                    pool=MP.Pool(processes=nCPU))

    # LOOP OVER ELEMENTS
    maxNode = np.max(reelements)
    for elem in range(0, mesh.elements.shape[0]):

        # GET HIGHER ORDER COORDINATES
        if Parallel:
            xycoord_higher = ParallelTuple1[elem]
        else:
            xycoord_higher = GetInteriorNodesCoordinates(
                mesh.points[mesh.elements[elem, :], :], 'line', elem, eps,
                Neval)

        # EXPAND THE ELEMENT CONNECTIVITY
        newElements = np.arange(maxNode + 1, maxNode + 1 + left_over_nodes)
        # reelements[elem,3:] = np.arange(maxNode+1,maxNode+1+left_over_nodes)
        reelements[elem, 2:] = newElements
        maxNode = newElements[-1]

        repoints[mesh.points.shape[0] + elem * iesize:mesh.points.shape[0] +
                 (elem + 1) * iesize] = xycoord_higher[2:, :]

    telements = time() - telements

    #--------------------------------------------------------------------------------------
    # NOW REMOVE DUPLICATED POINTS
    tnodes = time()
    nnode_linear = mesh.points.shape[0]
    # KEEP ZEROFY ON, OTHERWISE YOU GET STRANGE BEHVAIOUR
    rounded_repoints = repoints[nnode_linear:, :].copy()
    makezero(rounded_repoints)
    rounded_repoints = np.round(rounded_repoints, decimals=Decimals)
    _, idx_repoints, inv_repoints = unique2d(rounded_repoints,
                                             order=False,
                                             consider_sort=False,
                                             return_index=True,
                                             return_inverse=True)
    del rounded_repoints

    idx_repoints = np.concatenate(
        (np.arange(nnode_linear), idx_repoints + nnode_linear))
    repoints = repoints[idx_repoints, :]

    unique_reelements, inv_reelements = np.unique(reelements[:, 2:],
                                                  return_inverse=True)
    unique_reelements = unique_reelements[inv_repoints]
    reelements = unique_reelements[inv_reelements]
    reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem - 2)
    reelements = np.concatenate((mesh.elements, reelements), axis=1)

    # SANITY CHECK FOR DUPLICATES
    #---------------------------------------------------------------------#
    # NOTE THAT THIS REMAPS THE ELEMENT CONNECTIVITY FOR THE WHOLE MESH
    # AND AS A RESULT THE FIRST FEW COLUMNS WOULD NO LONGER CORRESPOND TO
    # LINEAR CONNECTIVITY
    if check_duplicates:
        last_shape = repoints.shape[0]
        deci = int(Decimals) - 2
        if Decimals < 6:
            deci = Decimals
        repoints, idx_repoints, inv_repoints = remove_duplicates_2D(
            repoints, decimals=deci)
        unique_reelements, inv_reelements = np.unique(reelements,
                                                      return_inverse=True)
        unique_reelements = unique_reelements[inv_repoints]
        reelements = unique_reelements[inv_reelements]
        reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem)
        if last_shape != repoints.shape[0]:
            warn(
                'Duplicated points generated in high order mesh. Lower the "Decimals". I have fixed it for now'
            )
    #---------------------------------------------------------------------#

    tnodes = time() - tnodes

    #------------------------------------------------------------------------------------------

    class nmesh(object):
        points = repoints
        elements = reelements
        edges = []
        faces = []
        nnode = repoints.shape[0]
        nelem = reelements.shape[0]
        info = 'line'

    # MESH CORNERS REMAIN THE SAME FOR ALL POLYNOMIAL DEGREES
    if isinstance(mesh.corners, np.ndarray):
        nmesh.corners = mesh.corners

    return nmesh
Exemplo n.º 2
0
def HighOrderMeshQuad(C,
                      mesh,
                      Decimals=10,
                      equally_spaced=False,
                      check_duplicates=True,
                      parallelise=False,
                      nCPU=1,
                      compute_boundary_info=True):

    from Florence.FunctionSpace import Quad, QuadES
    from Florence.QuadratureRules import GaussLobattoPointsQuad
    from Florence.QuadratureRules.EquallySpacedPoints import EquallySpacedPoints
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementQuad

    Parallel = parallelise

    if not equally_spaced:
        eps = GaussLobattoPointsQuad(C)
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((4, eps.shape[0]), dtype=np.float64)
        for i in range(0, eps.shape[0]):
            Neval[:, i] = Quad.LagrangeGaussLobatto(0,
                                                    eps[i, 0],
                                                    eps[i, 1],
                                                    arrange=1)[:, 0]
    else:
        eps = EquallySpacedPoints(3, C)
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((4, eps.shape[0]), dtype=np.float64)
        for i in range(0, eps.shape[0]):
            Neval[:, i] = QuadES.Lagrange(0, eps[i, 0], eps[i, 1],
                                          arrange=1)[:, 0]
    makezero(Neval)

    nodeperelem = mesh.elements.shape[1]
    renodeperelem = int((C + 2)**2)
    left_over_nodes = renodeperelem - nodeperelem

    reelements = -1 * np.ones(
        (mesh.elements.shape[0], renodeperelem), dtype=np.int64)
    reelements[:, :4] = mesh.elements
    iesize = int(4 * C + C**2)
    repoints = np.zeros(
        (mesh.points.shape[0] + iesize * mesh.elements.shape[0],
         mesh.points.shape[1]),
        dtype=np.float64)
    repoints[:mesh.points.shape[0], :] = mesh.points

    #--------------------------------------------------------------------------------------
    telements = time()

    xycoord_higher = []
    ParallelTuple1 = []
    if Parallel:
        # GET HIGHER ORDER COORDINATES - PARALLEL
        ParallelTuple1 = parmap.map(ElementLoopTri,
                                    np.arange(0, mesh.elements.shape[0]),
                                    mesh.elements,
                                    mesh.points,
                                    'quad',
                                    eps,
                                    Neval,
                                    pool=MP.Pool(processes=nCPU))

    # LOOP OVER ELEMENTS
    maxNode = np.max(reelements)
    for elem in range(0, mesh.elements.shape[0]):

        # GET HIGHER ORDER COORDINATES
        if Parallel:
            xycoord_higher = ParallelTuple1[elem]
        else:
            xycoord_higher = GetInteriorNodesCoordinates(
                mesh.points[mesh.elements[elem, :], :], 'quad', elem, eps,
                Neval)

        # EXPAND THE ELEMENT CONNECTIVITY
        newElements = np.arange(maxNode + 1, maxNode + 1 + left_over_nodes)
        # reelements[elem,3:] = np.arange(maxNode+1,maxNode+1+left_over_nodes)
        reelements[elem, 4:] = newElements
        maxNode = newElements[-1]

        repoints[mesh.points.shape[0] + elem * iesize:mesh.points.shape[0] +
                 (elem + 1) * iesize] = xycoord_higher[4:, :]

    telements = time() - telements

    #--------------------------------------------------------------------------------------
    # NOW REMOVE DUPLICATED POINTS
    tnodes = time()
    nnode_linear = mesh.points.shape[0]
    # KEEP ZEROFY ON, OTHERWISE YOU GET STRANGE BEHVAIOUR
    rounded_repoints = repoints[nnode_linear:, :].copy()
    makezero(rounded_repoints)
    rounded_repoints = np.round(rounded_repoints, decimals=Decimals)
    _, idx_repoints, inv_repoints = unique2d(rounded_repoints,
                                             order=False,
                                             consider_sort=False,
                                             return_index=True,
                                             return_inverse=True)
    del rounded_repoints

    idx_repoints = np.concatenate(
        (np.arange(nnode_linear), idx_repoints + nnode_linear))
    repoints = repoints[idx_repoints, :]

    unique_reelements, inv_reelements = np.unique(reelements[:, 4:],
                                                  return_inverse=True)
    unique_reelements = unique_reelements[inv_repoints]
    reelements = unique_reelements[inv_reelements]
    reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem - 4)
    reelements = np.concatenate((mesh.elements, reelements), axis=1)

    # SANITY CHECK FOR DUPLICATES
    #---------------------------------------------------------------------#
    # NOTE THAT THIS REMAPS THE ELEMENT CONNECTIVITY FOR THE WHOLE MESH
    # AND AS A RESULT THE FIRST FEW COLUMNS WOULD NO LONGER CORRESPOND TO
    # LINEAR CONNECTIVITY
    if check_duplicates:
        last_shape = repoints.shape[0]
        deci = int(Decimals) - 2
        if Decimals < 6:
            deci = Decimals
        repoints, idx_repoints, inv_repoints = remove_duplicates_2D(
            repoints, decimals=deci)
        unique_reelements, inv_reelements = np.unique(reelements,
                                                      return_inverse=True)
        unique_reelements = unique_reelements[inv_repoints]
        reelements = unique_reelements[inv_reelements]
        reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem)
        if last_shape != repoints.shape[0]:
            warn(
                'Duplicated points generated in high order mesh. Lower the "Decimals". I have fixed it for now'
            )
    #---------------------------------------------------------------------#

    tnodes = time() - tnodes
    #------------------------------------------------------------------------------------------

    #------------------------------------------------------------------------------------------
    reedges = np.array([])
    if compute_boundary_info:
        # BUILD EDGES NOW
        tedges = time()

        edge_to_elements = mesh.GetElementsWithBoundaryEdgesQuad()
        node_arranger = NodeArrangementQuad(C)[0]
        reedges = np.zeros((mesh.edges.shape[0], C + 2), dtype=np.int64)
        reedges = reelements[edge_to_elements[:, 0][:, None],
                             node_arranger[edge_to_elements[:, 1], :]]

        tedges = time() - tedges
    #------------------------------------------------------------------------------------------

    class nmesh(object):
        points = repoints
        elements = reelements
        edges = reedges
        faces = []
        nnode = repoints.shape[0]
        nelem = reelements.shape[0]
        info = 'quad'

    # print('\npMeshing timing:\n\t\tElement loop 1:\t '+str(telements)+' seconds\n\t\tNode loop:\t\t '+str(tnodes)+\
    #  ' seconds'+'\n\t\tElement loop 2:\t '+str(telements_2)+' seconds\n\t\tEdge loop:\t\t '+str(tedges)+' seconds\n')

    return nmesh
Exemplo n.º 3
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"
    )
Exemplo n.º 4
0
def HighOrderMeshHex(C,
                     mesh,
                     Decimals=10,
                     equally_spaced=False,
                     check_duplicates=True,
                     Zerofy=True,
                     Parallel=False,
                     nCPU=1,
                     ComputeAll=True):

    from Florence.FunctionSpace import Hex, HexES
    from Florence.QuadratureRules import GaussLobattoPointsHex
    from Florence.QuadratureRules.EquallySpacedPoints import EquallySpacedPoints
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementHex

    # SWITCH OFF MULTI-PROCESSING FOR SMALLER PROBLEMS WITHOUT GIVING A MESSAGE
    if (mesh.elements.shape[0] < 500) and (C < 5):
        Parallel = False
        nCPU = 1

    if not equally_spaced:
        eps = GaussLobattoPointsHex(C)
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((8, eps.shape[0]), dtype=np.float64)
        hpBases = Hex.LagrangeGaussLobatto
        for i in range(8, eps.shape[0]):
            Neval[:, i] = hpBases(0, eps[i, 0], eps[i, 1], eps[i, 2])[:, 0]
    else:
        eps = EquallySpacedPoints(4, C)
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((8, eps.shape[0]), dtype=np.float64)
        hpBases = HexES.Lagrange
        for i in range(8, eps.shape[0]):
            Neval[:, i] = hpBases(0, eps[i, 0], eps[i, 1], eps[i, 2])[:, 0]

    # THIS IS NECESSARY FOR REMOVING DUPLICATES
    makezero(Neval, tol=1e-12)

    nodeperelem = mesh.elements.shape[1]
    renodeperelem = int((C + 2)**3)
    left_over_nodes = renodeperelem - nodeperelem

    reelements = -1 * np.ones(
        (mesh.elements.shape[0], renodeperelem), dtype=np.int64)
    reelements[:, :8] = mesh.elements
    # TOTAL NUMBER OF (INTERIOR+EDGE+FACE) NODES
    iesize = renodeperelem - 8
    repoints = np.zeros(
        (mesh.points.shape[0] + iesize * mesh.elements.shape[0], 3),
        dtype=np.float64)
    repoints[:mesh.points.shape[0], :] = mesh.points

    telements = time()

    xycoord_higher = []
    ParallelTuple1 = []
    if Parallel:
        # GET HIGHER ORDER COORDINATES - PARALLEL
        ParallelTuple1 = parmap.map(ElementLoopTet,
                                    np.arange(0, mesh.elements.shape[0]),
                                    mesh.elements,
                                    mesh.points,
                                    'hex',
                                    eps,
                                    Neval,
                                    pool=MP.Pool(processes=nCPU))

    maxNode = np.max(reelements)
    for elem in range(0, mesh.elements.shape[0]):
        # maxNode = np.max(reelements) # BIG BOTTLENECK
        if Parallel:
            xycoord_higher = ParallelTuple1[elem]
        else:
            xycoord = mesh.points[mesh.elements[elem, :], :]
            # GET HIGHER ORDER COORDINATES
            xycoord_higher = GetInteriorNodesCoordinates(
                xycoord, 'hex', elem, eps, Neval)

        # EXPAND THE ELEMENT CONNECTIVITY
        newElements = np.arange(maxNode + 1, maxNode + 1 + left_over_nodes)
        reelements[elem, 8:] = newElements
        # INSTEAD COMPUTE maxNode BY INDEXING
        maxNode = newElements[-1]

        repoints[mesh.points.shape[0] + elem * iesize:mesh.points.shape[0] +
                 (elem + 1) * iesize] = xycoord_higher[8:, :]

    if Parallel:
        del ParallelTuple1

    telements = time() - telements
    #--------------------------------------------------------------------------------------
    # NOW REMOVE DUPLICATED POINTS
    tnodes = time()

    nnode_linear = mesh.points.shape[0]
    # KEEP ZEROFY ON, OTHERWISE YOU GET STRANGE BEHVAIOUR
    # rounded_repoints = makezero(repoints[nnode_linear:,:].copy())
    rounded_repoints = repoints[nnode_linear:, :].copy()
    makezero(rounded_repoints)
    rounded_repoints = np.round(rounded_repoints, decimals=Decimals)

    _, idx_repoints, inv_repoints = unique2d(rounded_repoints,
                                             order=False,
                                             consider_sort=False,
                                             return_index=True,
                                             return_inverse=True)
    # idx_repoints.sort()
    del rounded_repoints  #, flattened_repoints

    idx_repoints = np.concatenate(
        (np.arange(nnode_linear), idx_repoints + nnode_linear))
    repoints = repoints[idx_repoints, :]

    unique_reelements, inv_reelements = np.unique(reelements[:, 8:],
                                                  return_inverse=True)
    unique_reelements = unique_reelements[inv_repoints]
    reelements = unique_reelements[inv_reelements]
    reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem - 8)
    reelements = np.concatenate((mesh.elements, reelements), axis=1)

    # SANITY CHECK fOR DUPLICATES
    #---------------------------------------------------------------------#
    # NOTE THAT THIS REMAPS THE ELEMENT CONNECTIVITY FOR THE WHOLE MESH
    # AND AS A RESULT THE FIRST FEW COLUMNS WOULD NO LONGER CORRESPOND TO
    # LINEAR CONNECTIVITY
    if check_duplicates:
        last_shape = repoints.shape[0]
        deci = int(Decimals) - 2
        if Decimals < 6:
            deci = Decimals
        repoints, idx_repoints, inv_repoints = remove_duplicates_2D(
            repoints, decimals=deci)
        unique_reelements, inv_reelements = np.unique(reelements,
                                                      return_inverse=True)
        unique_reelements = unique_reelements[inv_repoints]
        reelements = unique_reelements[inv_reelements]
        reelements = reelements.reshape(mesh.elements.shape[0], renodeperelem)
        if last_shape != repoints.shape[0]:
            warn(
                'Duplicated points generated in high order mesh. Lower the "Decimals". I have fixed it for now'
            )
    #---------------------------------------------------------------------#

    tnodes = time() - tnodes
    #------------------------------------------------------------------------------------------

    # USE ALTERNATIVE APPROACH TO GET MESH EDGES AND FACES
    reedges = np.zeros((mesh.edges.shape[0], C + 2))
    fsize = int((C + 2.) * (C + 3.) / 2.)
    refaces = np.zeros((mesh.faces.shape[0], fsize), dtype=mesh.faces.dtype)

    if ComputeAll == True:
        #------------------------------------------------------------------------------------------
        # BUILD FACES NOW
        tfaces = time()

        refaces = np.zeros((mesh.faces.shape[0], fsize))
        # DO NOT CHANGE THE FACES, BY RECOMPUTING THEM, AS THE LINEAR FACES CAN COME FROM
        # AN EXTERNAL MESH GENERATOR, WHOSE ORDERING MAY NOT BE THE SAME, SO JUST FIND WHICH
        # ELEMENTS CONTAIN THESE FACES
        face_to_elements = mesh.GetElementsWithBoundaryFacesHex()
        node_arranger = NodeArrangementHex(C)[0]

        refaces = reelements[face_to_elements[:, 0][:, None],
                             node_arranger[face_to_elements[:, 1], :]].astype(
                                 mesh.faces.dtype)

        tfaces = time() - tfaces
        #------------------------------------------------------------------------------------------

        #------------------------------------------------------------------------------------------
        # BUILD EDGES NOW
        tedges = time()

        # BUILD A 2D MESH
        from Florence import Mesh
        tmesh = Mesh()
        tmesh.element_type = "quad"
        tmesh.elements = refaces
        tmesh.nelem = tmesh.elements.shape[0]
        # GET BOUNDARY EDGES
        reedges = tmesh.GetEdgesQuad()
        del tmesh

        tedges = time() - tedges
        #------------------------------------------------------------------------------------------

    class nmesh(object):
        # """Construct pMesh"""
        points = repoints
        elements = reelements
        edges = np.array([[], []])
        faces = np.array([[], []])
        nnode = repoints.shape[0]
        nelem = reelements.shape[0]
        info = 'hex'

    if ComputeAll is True:
        nmesh.edges = reedges
        nmesh.faces = refaces

    gc.collect()

    # print '\nHigh order meshing timing:\n\t\tElement loop:\t '+str(telements)+' seconds\n\t\tNode loop:\t\t '+str(tnodes)+\
    #  ' seconds'+'\n\t\tEdge loop:\t\t '+str(tedges)+' seconds'+\
    #  '\n\t\tFace loop:\t\t '+str(tfaces)+' seconds\n'

    return nmesh
Exemplo n.º 5
0
=======
            raise ImportError("PostMesh is not installed. Please install using 'pip install PostMeshPy'")
>>>>>>> upstream/master

        from Florence.FunctionSpace import Tri

        C = mesh.InferPolynomialDegree() - 1

        if formulation.ndim == 2:

            # CHOOSE TYPE OF BOUNDARY SPACING
            boundary_fekete = np.array([[]])
            if self.nodal_spacing_for_cad == 'fekete':
                boundary_fekete = GaussLobattoQuadrature(C+2)[0]
            else:
                boundary_fekete = EquallySpacedPoints(formulation.ndim,C)
            # IT IS IMPORTANT TO ENSURE THAT THE DATA IS C-CONITGUOUS
            boundary_fekete = boundary_fekete.copy(order="c")

            curvilinear_mesh = PostMeshCurve(mesh.element_type,dimension=formulation.ndim)
            curvilinear_mesh.SetMeshElements(mesh.elements)
            curvilinear_mesh.SetMeshPoints(mesh.points)
            curvilinear_mesh.SetMeshEdges(mesh.edges)
            curvilinear_mesh.SetMeshFaces(np.zeros((1,4),dtype=np.uint64))
            curvilinear_mesh.SetScale(self.scale_value_on_projection)
            curvilinear_mesh.SetCondition(self.condition_for_projection)
            curvilinear_mesh.SetProjectionPrecision(1.0e-04)
            curvilinear_mesh.SetProjectionCriteria(self.projection_flags)
            curvilinear_mesh.ScaleMesh()
            # curvilinear_mesh.InferInterpolationPolynomialDegree()
            curvilinear_mesh.SetNodalSpacing(boundary_fekete)
Exemplo n.º 6
0
=======
    from Florence.MeshGeneration.NodeArrangement import NodeArrangementLine

    # ARRANGE NODES FOR LINES HERE (DONE ONLY FOR LINES) - IMPORTANT
    node_aranger = NodeArrangementLine(C)

    if not equally_spaced:
        eps = GaussLobattoPoints1D(C).ravel()
        eps = eps[node_aranger]
>>>>>>> upstream/master
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((2,eps.shape[0]),dtype=np.float64)
        for i in range(0,eps.shape[0]):
            Neval[:,i] = Line.LagrangeGaussLobatto(0,eps[i])[0]
    else:
        eps = EquallySpacedPoints(2,C).ravel()
<<<<<<< HEAD
=======
        eps = eps[node_aranger]
>>>>>>> upstream/master
        # COMPUTE BASES FUNCTIONS AT ALL NODAL POINTS
        Neval = np.zeros((2,eps.shape[0]),dtype=np.float64)
        for i in range(0,eps.shape[0]):
            Neval[:,i] = Line.Lagrange(0,eps[i])[0]
    makezero(Neval)

<<<<<<< HEAD
=======

>>>>>>> upstream/master
    nodeperelem = mesh.elements.shape[1]
    def GetIdealElement(self, elem, fem_solver, function_space,
                        LagrangeElemCoords):
        """Retrieves ideal element/domain
        """

        from Florence.Tensor import makezero
        from Florence.FunctionSpace import Tri, Tet, Quad, Hex
        from Florence.QuadratureRules.EquallySpacedPoints import EquallySpacedPoints, EquallySpacedPointsTri, EquallySpacedPointsTet
        sqrt = np.sqrt
        if function_space.element_type == "tri":
            nodeperlinearelem = 3
            eps = EquallySpacedPointsTri(function_space.degree - 1)
            hpBases = Tri.hpNodal.hpBases
            Neval = np.zeros((nodeperlinearelem, eps.shape[0]),
                             dtype=np.float64)
            for i in range(0, eps.shape[0]):
                Neval[:, i] = hpBases(0,
                                      eps[i, 0],
                                      eps[i, 1],
                                      Transform=1,
                                      EvalOpt=1,
                                      equally_spaced=True)[0]
            xycoord = LagrangeElemCoords[:nodeperlinearelem, :]
            xycoord = np.array([[-0.5, 0], [0.5, 0], [0., np.sqrt(3.) / 2.]])
            # xycoord = eps[:nodeperlinearelem,:]
            # xycoord = fem_solver.imesh.points[elem,:]

        elif function_space.element_type == "quad":
            nodeperlinearelem = 4
            eps = EquallySpacedPoints(3, function_space.degree - 1)
            hpBases = Quad.LagrangeGaussLobatto
            Neval = np.zeros((nodeperlinearelem, eps.shape[0]),
                             dtype=np.float64)
            for i in range(0, eps.shape[0]):
                Neval[:, i] = hpBases(0, eps[i, 0], eps[i, 1], arrange=1)[:, 0]
            xycoord = LagrangeElemCoords[:nodeperlinearelem, :]
            xycoord = np.array([[0., 0], [1., 0], [1., 1.], [0., 1.]])
            xycoord = eps[:nodeperlinearelem, :]

        elif function_space.element_type == "tet":
            nodeperlinearelem = 4
            eps = EquallySpacedPointsTet(function_space.degree - 1)
            hpBases = Tet.hpNodal.hpBases
            Neval = np.zeros((nodeperlinearelem, eps.shape[0]),
                             dtype=np.float64)
            for i in range(0, eps.shape[0]):
                Neval[:, i] = hpBases(0,
                                      eps[i, 0],
                                      eps[i, 1],
                                      eps[i, 2],
                                      Transform=1,
                                      EvalOpt=1,
                                      equally_spaced=True)[0]
            xycoord = LagrangeElemCoords[:nodeperlinearelem, :]
            xycoord = np.array([[sqrt(8. / 9.), 0, -1 / 3.],
                                [-sqrt(2. / 9.),
                                 sqrt(2. / 3.), -1 / 3.],
                                [-sqrt(2. / 9.), -sqrt(2. / 3.), -1 / 3.],
                                [0., 0, 1.]])

        elif function_space.element_type == "hex":
            nodeperlinearelem = 8
            eps = EquallySpacedPoints(4, function_space.degree - 1)
            hpBases = Hex.LagrangeGaussLobatto
            Neval = np.zeros((nodeperlinearelem, eps.shape[0]),
                             dtype=np.float64)
            for i in range(0, eps.shape[0]):
                Neval[:, i] = hpBases(0,
                                      eps[i, 0],
                                      eps[i, 1],
                                      eps[i, 2],
                                      arrange=1)[:, 0]
            xycoord = LagrangeElemCoords[:nodeperlinearelem, :]
            xycoord = eps[:nodeperlinearelem, :]

        makezero(Neval)
        xycoord_higher = np.copy(LagrangeElemCoords)
        xycoord_higher[:nodeperlinearelem, :] = xycoord
        if function_space.degree > 1:
            xycoord_higher[nodeperlinearelem:, :] = np.dot(
                Neval[:, nodeperlinearelem:].T, xycoord)
        LagrangeElemCoords = xycoord_higher

        return LagrangeElemCoords