示例#1
0
def prism( p2 ):
    
    mesh = g.Mesh( 3 )
    n0 = mesh.createNode( 0.0, 0.0, 0.0 )
    n1 = mesh.createNode( 1.0, 0.0, 0.0 )
    n2 = mesh.createNode( 0.0, 1.0, 0.0 )
    n4 = mesh.createNode( 0.0, 0.0, 1.0 )
    n5 = mesh.createNode( 1.0, 0.0, 1.0 )
    n6 = mesh.createNode( 0.0, 1.0, 1.4 )
        
    ns = g.stdVectorNodes()
    for n in mesh.nodes():
        ns.append( n )
    
    mesh.createCell( ns, 0 )
    mesh.rotate( g.RVector3( 10.0, 34.0, 45 ) )
    mesh.scale( g.RVector3( 0.9, 0.8, 0.7 ) )
    
    if p2: 
        mesh = mesh.createP2()
        mesh.exportVTK( "prism15" )
    else:
        mesh.exportVTK( "prism6" )
   
    show( mesh )
示例#2
0
def appendTetrahedronBoundary(mesh, xbound=100, ybound=100, zbound=100,
                              marker=1, quality=2, isSubSurface=False,
                              verbose=False):
    """
    Return new mesh surrounded by tetrahedron boundary box.

    Creates a tetrahedral box around a given mesh
    suitable for geo-simulation (surface boundary at top).

    Parameters
    ----------
    mesh : mesh object
        Mesh to which the tetrahedron boundary should be appended.
    xbound : float, optional
        Horizontal prolongation distance in x-direction.
    ybound : float, optional
        Horizonal prolongation distance in y-direction.
    zbound : float, optional
        Vertical prolongation distance.
    marker : int, optional
        Marker of new cells.
    quality : float, optional
        Triangle quality.
    isSubSurface : boolean, optional
        Apply boundary conditions suitable for geo-simulaion and prolongate
        mesh to the surface if necessary.
    verbose : boolean, optional
        Be verbose.

    See Also
    --------
    appendTriangleBoundary

    Notes
    -----
    Boundaries of mesh need marker 1.
    """
    # create boundary for mesh from boundary marker == 1

    if isSubSurface:
        raise Exception('Implement me')

    meshBoundary = pg.Mesh()
    meshBoundary.createH2()

    bounds = []
    for b in meshBoundary.boundaries():
        if b.marker() == 1:
            bounds.append(b)

    meshBoundaryPoly = pg.Mesh()
    meshBoundaryPoly.createMeshByBoundaries(
        meshBoundary, meshBoundary.findBoundaryByMarker(1))

    meshBoundaryPoly.exportAsTetgenPolyFile("paraBoundary.poly")
    # system( 'polyConvert -V paraBoundary' )

    # create worldSurface.poly including boundary mesh for a nice surface mesh
    # it will be later the tetgen input with preserve boundary
    polyCreateWorld('worldSurface', x=xbound, y=ybound, depth=zbound, marker=1,
                    verbose=verbose)
    os.system('polyMerge -N worldSurface paraBoundary worldSurface')
    polyAddVIP('worldSurface', mesh.cell(0).center(), isHoleMarker=True,
               verbose=verbose)
    worldBoundary = tetgen('worldSurface', quality=1.12, verbose=verbose)
    # worldBoundary.exportBoundaryVTU('worldSurface')

    worldPoly = pg.Mesh()
    worldPoly.createMeshByBoundaries(worldBoundary,
                                     worldBoundary.findBoundaryByMarker(-2, 0))
    worldPoly.exportAsTetgenPolyFile("worldSurface.poly")

    os.system('polyMerge -N worldSurface paraBoundary boundaryWorld')

    # mesh should have to be a hole
    polyAddVIP('boundaryWorld', mesh.cell(0).center(), isHoleMarker=True,
               verbose=verbose)
    # system( 'polyConvert -o world-poly -V boundaryWorld' )

    boundMesh = tetgen('boundaryWorld', quality=quality, preserveBoundary=True,
                       verbose=verbose)
    # boundMesh.exportVTK( 'boundaryWorld' )

    # merge mesh and worldBoundary
    for c in boundMesh.cells():
        c.setMarker(marker)

    if verbose:
        print("merge grid and boundary")

    swatch = pg.Stopwatch(True)
    for c in meshBoundary.cells():
        nodes = pg.stdVectorNodes()
        for n in c.nodes():
            nodes.append(boundMesh.createNodeWithCheck(n.pos()))

        boundMesh.createCell(nodes, c.marker())
    if verbose:
        print(" done.", swatch.duration(True))

    try:
        os.remove('boundaryWorld.bms')
        os.remove('worldSurface.bms')
        os.remove('boundaryWorld.poly')
        os.remove('paraBoundary.poly')
        os.remove('worldSurface.poly')
    except BaseException as e:
        print(e)

    return boundMesh
示例#3
0
    #axes.set_xlim( mesh.xmin(), mesh.xmax() );


fig = P.figure()

mesh1 = g.Mesh()
n1 = mesh1.createNode(0.0, 0.0, 0.0)
n2 = mesh1.createNode(1.0, 0.0, 0.0)
edge1 = g.EdgeCell(n1, n2)
u1 = g.RVector(mesh1.nodeCount())

mesh2 = g.Mesh()
n1 = mesh2.createNode(0.0, 0.0, 0.0)
n2 = mesh2.createNode(1.0, 0.0, 0.0)
n3 = mesh2.createNode(0.5, 0.0, 0.0)
nodes = g.stdVectorNodes()
nodes.append(n1)
nodes.append(n2)
nodes.append(n3)
edge2 = g.Edge3Cell(nodes)

for i in range(2):
    u = g.RVector(mesh1.nodeCount())
    u[i] = 1.0
    at = fig.add_subplot(2, 3, 1 + i)
    drawShapes(at, edge1, u)

for i in range(3):
    u = g.RVector(mesh2.nodeCount())
    u[i] = 1.0
    at = fig.add_subplot(2, 3, 4 + i)
示例#4
0
def appendTetrahedronBoundary(
    mesh, xbound=100, ybound=100, zbound=100, marker=1, quality=2, isSubSurface=False, verbose=False
):
    """
    Returns a new mesh that contains a tetrahedral box around a given mesh
    suitable for geo-simulation (surface boundary at top).

    Parameters
    ----------
    mesh : mesh object
        Mesh to which the tetrahedron boundary should be appended.
    xbound : float, optional
        Horizontal prolongation distance in x-direction.
    ybound : float, optional
        Horizonal prolongation distance in y-direction.
    zbound : float, optional
        Vertical prolongation distance.
    marker : int, optional
        Marker of new cells.
    quality : float, optional
        Triangle quality.
    isSubSurface : boolean, optional
        Apply boundary conditions suitable for geo-simulaion and prolongate
        mesh to the surface if necessary.
    verbose : boolean, optional
        Be verbose.

    See Also
    --------
    appendTriangleBoundary

    Notes
    -----
    Boundaries of mesh need marker 1.
    """
    # create boundary for mesh from boundary marker == 1
    meshBoundary = pg.Mesh()
    meshBoundary.createH2()

    bounds = []
    for b in meshBoundary.boundaries():
        if b.marker() == 1:
            bounds.append(b)

    meshBoundaryPoly = pg.Mesh()
    meshBoundaryPoly.createMeshByBoundaries(meshBoundary, meshBoundary.findBoundaryByMarker(1))

    meshBoundaryPoly.exportAsTetgenPolyFile("paraBoundary.poly")
    # system( 'polyConvert -V paraBoundary' )

    # create worldSurface.poly including boundary mesh for a nice surface mesh
    # it will be later the tetgen input with preserve boundary
    polyCreateWorld("worldSurface", x=xbound, y=ybound, depth=zbound, marker=1, verbose=verbose)
    system("polyMerge -N worldSurface paraBoundary worldSurface")
    polyAddVIP("worldSurface", mesh.cell(0).center(), isHoleMarker=True, verbose=verbose)
    worldBoundary = tetgen("worldSurface", quality=1.12, verbose=verbose)
    # worldBoundary.exportBoundaryVTU('worldSurface')

    worldPoly = pg.Mesh()
    worldPoly.createMeshByBoundaries(worldBoundary, worldBoundary.findBoundaryByMarker(-2, 0))
    worldPoly.exportAsTetgenPolyFile("worldSurface.poly")

    system("polyMerge -N worldSurface paraBoundary boundaryWorld")

    # mesh should have to be a hole
    polyAddVIP("boundaryWorld", mesh.cell(0).center(), isHoleMarker=True, verbose=verbose)
    # system( 'polyConvert -o world-poly -V boundaryWorld' )

    boundMesh = tetgen("boundaryWorld", quality=quality, preserveBoundary=True, verbose=verbose)
    # boundMesh.exportVTK( 'boundaryWorld' )

    # merge mesh and worldBoundary
    for c in boundMesh.cells():
        c.setMarker(marker)

    if verbose:
        print("merge grid and boundary")

    swatch = pg.Stopwatch(True)
    for c in meshBoundary.cells():
        nodes = pg.stdVectorNodes()
        for i, n in enumerate(c.nodes()):
            nodes.append(boundMesh.createNodeWithCheck(n.pos()))

        boundMesh.createCell(nodes, c.marker())
    if verbose:
        print(" done.", swatch.duration(True))

    try:
        os.remove("boundaryWorld.bms")
        os.remove("worldSurface.bms")
        os.remove("boundaryWorld.poly")
        os.remove("paraBoundary.poly")
        os.remove("worldSurface.poly")
    except:
        None

    return boundMesh
    ax.set_aspect('equal')
    #axes.set_xlim( mesh.xmin(), mesh.xmax() );

fig = P.figure()

mesh1 = g.Mesh( )
n1 = mesh1.createNode( 0.0, 0.0, 0.0 )
n2 = mesh1.createNode( 1.0, 0.0, 0.0 )
edge1 = g.EdgeCell( n1, n2 )
u1 = g.RVector( mesh1.nodeCount() )

mesh2 = g.Mesh( )
n1 = mesh2.createNode( 0.0, 0.0, 0.0 )
n2 = mesh2.createNode( 1.0, 0.0, 0.0 )
n3 = mesh2.createNode( 0.5, 0.0, 0.0 )
nodes = g.stdVectorNodes()
nodes.append(n1); nodes.append(n2); nodes.append(n3)
edge2 = g.Edge3Cell( nodes )

for i in range( 2 ):
    u = g.RVector( mesh1.nodeCount() )
    u[ i ] = 1.0;
    at = fig.add_subplot(2,3,1+i)
    drawShapes( at, edge1, u )

for i in range( 3 ):
    u = g.RVector( mesh2.nodeCount() )
    u[ i ] = 1.0;
    at = fig.add_subplot(2,3,4+i)
    drawShapes( at, edge2, u )