Exemple #1
0
def test_2DmultiRegion(verbose=0):
    """Test for loading gmsh mesh through PUMI with multiple-regions"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/TwoQuads.dmg'
    Mesh = testDir + '/TwoQuads.smb'
    domain = Domain.PUMIDomain(
        dim=2, manager=MeshAdapt.AdaptManager())  #initialize the domain

    domain.AdaptManager.reconstructedFlag = 0  #this is used to indicate that no mesh reconstruction is being done.
    domain.AdaptManager.PUMIAdapter.loadModelAndMesh(bytes(Model, 'utf-8'),
                                                     bytes(Mesh, 'utf-8'))
    domain.faceList = [[14], [12], [11], [13], [15], [16]]
    domain.boundaryLabels = [1, 2, 3, 4, 5, 6]
    domain.regList = [[41], [42]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()
    mesh.convertFromPUMI(domain,
                         domain.AdaptManager.PUMIAdapter,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    ok(mesh.elementMaterialTypes[0] == 1)
    ok(mesh.elementMaterialTypes[-1] == 2)
def init_mpi_petsc(opts):
    log("Initializing MPI")
    if opts.petscOptions != None:
        petsc_argv = sys.argv[:1]+opts.petscOptions.split()
        log("PETSc options from commandline")
        log(str(petsc_argv))
    else:
        petsc_argv=sys.argv[:1]
    if opts.petscOptionsFile != None:
        petsc_argv=[sys.argv[0]]
        petsc_argv += open(opts.petscOptionsFile).read().split()
        log("PETSc options from commandline")
        log(str(petsc_argv))
    return Comm.init(argv=petsc_argv)
Exemple #3
0
def init_mpi_petsc(opts, log):
    log("Initializing MPI")
    if opts.petscOptions != None:
        petsc_argv = sys.argv[:1]+opts.petscOptions.split()
        log("PETSc options from commandline")
        log(str(petsc_argv))
    else:
        petsc_argv=sys.argv[:1]
    if opts.petscOptionsFile != None:
        petsc_argv=[sys.argv[0]]
        petsc_argv += open(opts.petscOptionsFile).read().split()
        log("PETSc options from commandline")
        log(str(petsc_argv))
    return Comm.init(argv=petsc_argv)
Exemple #4
0
def test_parallelLoadPUMI(verbose=0):
    """Test to load parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(),2)
    testDir=os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain()
    Model=testDir+ '/Prism.dmg'
    Mesh=testDir + '/Prism.smb'
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList, parallel = comm.size() > 1, dim = domain.nd)
    eq(mesh.nElements_global,8148)
    eq(mesh.nNodes_global,1880)
    eq(mesh.nEdges_global,11001)
    eq(mesh.nElementBoundaries_global,17270)
def test_3DparallelLoadPUMI(verbose=0):
    """Test to load 3D parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(),2)
    testDir=os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain()
    Model=testDir+ '/Prism.dmg'
    Mesh=testDir + '/Prism.smb'
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList, domain.regList,parallel = comm.size() > 1, dim = domain.nd)
    eq(mesh.nElements_global,8148)
    eq(mesh.nNodes_global,1880)
    eq(mesh.nEdges_global,11001)
    eq(mesh.nElementBoundaries_global,17270)
def test_2DparallelLoadPUMI(verbose=0):
    """Test to load 2D parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(),2)
    testDir=os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain(dim=2)
    Model=testDir+ '/Rectangle.dmg'
    Mesh=testDir + '/Rectangle.smb'
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList, domain.regList,parallel = comm.size() > 1, dim = domain.nd)
    eq(mesh.nElements_global,8)
    eq(mesh.nNodes_global,10)
    eq(mesh.nEdges_global,17)
    eq(mesh.nElementBoundaries_global,17)
Exemple #7
0
def test_2DmultiRegion(verbose=0):
    """Test for loading gmsh mesh through PUMI with multiple-regions"""
    testDir=os.path.dirname(os.path.abspath(__file__))
    Model=testDir + '/TwoQuads.dmg'
    Mesh=testDir + '/TwoQuads.smb'
    domain = Domain.PUMIDomain(dim=2) #initialize the domain
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList=[[14],[12],[11],[13],[15],[16]]
    domain.regList=[[41],[42]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList,domain.regList, parallel = comm.size() > 1, dim = domain.nd)
    ok(mesh.elementMaterialTypes[0]==1)
    ok(mesh.elementMaterialTypes[-1]==2)
Exemple #8
0
def test_wdot():
    """
    test_wdot

    Verifies that the proteus.LinearAlgebraTools.wdot computes dot product correctly.
    """
    import numpy as np
    import numpy.testing as npt
    from proteus.LinearAlgebraTools import wDot
    from proteus import Comm
    comm = Comm.init()
    x = np.array([-1, 2, 3])
    y = np.array([5, 6, 10])
    h = np.array([0.5, 1.2, 6.0])
    t1 = 191.9
    t2 = wDot(x, y, h)
    test = npt.assert_almost_equal
    test.description = 'test_wdot'
    assert t1 == approx(t2)
Exemple #9
0
def test_wdot():
    """
    test_wdot

    Verifies that the proteus.LinearAlgebraTools.wdot computes dot product correctly.
    """
    import numpy as np
    import numpy.testing as npt
    from proteus.LinearAlgebraTools import wDot
    from proteus import Comm
    comm = Comm.init()
    x = np.array([-1, 2, 3])
    y = np.array([5, 6, 10])
    h = np.array([0.5, 1.2, 6.0])
    t1 = 191.9        
    t2 = wDot(x, y, h)
    test = npt.assert_almost_equal
    test.description = 'test_wdot'
    assert t1 == approx(t2)
Exemple #10
0
def test_2DparallelLoadPUMI(verbose=0):
    """Test to load 2D parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(), 2)
    testDir = os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain(dim=2)
    Model = testDir + '/Rectangle.dmg'
    Mesh = testDir + '/Rectangle.smb'
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    eq(mesh.nElements_global, 8)
    eq(mesh.nNodes_global, 10)
    eq(mesh.nEdges_global, 17)
    eq(mesh.nElementBoundaries_global, 17)
def test_2DmultiRegion(verbose=0):
    """Test for loading gmsh mesh through PUMI with multiple-regions"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/TwoQuads.dmg'
    Mesh = testDir + '/TwoQuads.smb'
    domain = Domain.PUMIDomain(dim=2)  #initialize the domain
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList = [[14], [12], [11], [13], [15], [16]]
    domain.regList = [[41], [42]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    ok(mesh.elementMaterialTypes[0] == 1)
    ok(mesh.elementMaterialTypes[-1] == 2)
def test_poiseuilleError(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error for 
    a Poiseuille flow case. The estimated error should be larger than the
    exact error in the seminorm"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/Couette.null'
    Mesh = testDir + '/Couette.msh'

    domain = Domain.PUMIDomain()  #initialize the domain
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01,
                                                  hmin=0.008,
                                                  numIter=1,
                                                  sfConfig='ERM',
                                                  maType='isotropic',
                                                  logType='off')
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList = [[80], [76], [42], [24], [82], [78]]

    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)

    domain.PUMIMesh.transferFieldToPUMI("coordinates", mesh.nodeArray)

    rho = numpy.array([998.2, 998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0, 0.0, 0.0])
    deltaT = 1.0  #dummy number
    domain.PUMIMesh.transferPropertiesToPUMI(rho, nu, g, deltaT)

    #Poiseuille Flow
    Ly = 0.2
    Lz = 0.05
    Re = 100
    Umax = Re * nu[0] / Lz

    def vOfX(x):
        return 4 * Umax / (Lz**2) * (x[2]) * (Lz - x[2])

    def dvOfXdz(x):
        return 4 * Umax / (Lz**2) * (Lz - 2 * x[2])

    #hard code solution
    vector = numpy.zeros((mesh.nNodes_global, 3), 'd')
    dummy = numpy.zeros(mesh.nNodes_global)

    vector[:, 0] = dummy
    vector[:, 1] = 4 * Umax / (Lz**2) * (mesh.nodeArray[:, 2]) * (
        Lz - mesh.nodeArray[:, 2])  #v-velocity
    vector[:, 2] = dummy
    domain.PUMIMesh.transferFieldToPUMI("velocity", vector)

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd')
    domain.PUMIMesh.transferFieldToPUMI("p", scalar)

    scalar[:, 0] = mesh.nodeArray[:, 2]
    domain.PUMIMesh.transferFieldToPUMI("phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd') + 1.0
    domain.PUMIMesh.transferFieldToPUMI("vof", scalar)

    errorTotal = domain.PUMIMesh.get_local_error()

    # load the femspace with linear basis and get the quadrature points on a reference element
    elementQuadrature = Quadrature.SimplexGaussQuadrature(domain.nd, 3)

    ok(mesh.nNodes_element == 4)  #confirm all of the elements have 4 nodes

    #hard code computation for H1 seminorm; ideally will be reformatted using the classes within proteus
    derivativeArrayRef = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [-1, -1, -1]]
    error = 0
    for eID in range(mesh.nElements_global):
        nodes = mesh.elementNodesArray[eID]
        coords = []
        for i in range(mesh.nNodes_element):
            coords.append(mesh.nodeArray[nodes[i]])
        J = numpy.matrix([[
            coords[0][0] - coords[3][0], coords[1][0] - coords[3][0],
            coords[2][0] - coords[3][0]
        ],
                          [
                              coords[0][1] - coords[3][1],
                              coords[1][1] - coords[3][1],
                              coords[2][1] - coords[3][1]
                          ],
                          [
                              coords[0][2] - coords[3][2],
                              coords[1][2] - coords[3][2],
                              coords[2][2] - coords[3][2]
                          ]])
        invJ = J.I
        detJ = numpy.linalg.det(J)
        gradPhi_h = 0
        for k in range(len(elementQuadrature.points)):
            tempQpt = 0
            zCoord = elementQuadrature.points[k][0]*coords[0][2] \
                +elementQuadrature.points[k][1]*coords[1][2] \
                +elementQuadrature.points[k][2]*coords[2][2] \
                +(1-elementQuadrature.points[k][0]-elementQuadrature.points[k][1]-elementQuadrature.points[k][2])*coords[3][2]
            for i in range(mesh.nNodes_element):
                temp = 0
                for j in range(domain.nd):
                    temp = temp + derivativeArrayRef[i][j] * invJ[j, 2]
                tempQpt = tempQpt + vector[nodes[i]][1] * temp
            exactgradPhi = dvOfXdz([0, 0, zCoord])
            gradPhi_h = gradPhi_h + tempQpt
            error = error + (exactgradPhi - gradPhi_h
                             )**2 * elementQuadrature.weights[k] * abs(detJ)

    error = sqrt(error)
    ok(error < errorTotal)
        
    ns = NumericalSolution.NS_base(so,pList,nList,so.sList,opts)
    ns.calculateSolution('poisson_2d_c0p1')
    
    #test load vector calculation in a crude way
    #see if sum over test functions of residual is same as the sum over the test functions of the load vector
    #should be if have strong bc's and no other terms in residual besides stiffness and load 
    #transport model on the final grid
    finest_model = ns.modelList[0].levelModelList[-1]
    #cheating a little bit to get the global test space dimension from the global trial space
    nr = finest_model.u[0].femSpace.dim
    import numpy as np
    r = np.zeros((nr,),'d')
    f = np.zeros((nr,),'d')
    utmp = np.zeros((nr,),'d')
    finest_model.getResidual(utmp,r)
    finest_model.getLoadVector(f)
    return r,f
def test_load_vector():
    for name,use_num_flux in zip(['Strong_Dir','Weak_Dir'],[False,True]):
        r,f = compute_load_vector(use_num_flux)
        test = npt.assert_almost_equal
        test.descrption = 'test_load_vector_{}'.format(name)
        yield test,r,f
if __name__ == '__main__':
    from proteus import Comm
    comm = Comm.init()
    import nose
    nose.main()

Exemple #14
0
def test_2DgmshLoadAndAdapt(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error and adapting for 
    a 2D Couette flow case"""
    testDir=os.path.dirname(os.path.abspath(__file__))
    Model=testDir + '/Couette2D.null'
    Mesh=testDir + '/Couette2D.msh'
    domain = Domain.PUMIDomain(dim=2) #initialize the domain
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig=b'ERM',maType=b'isotropic',targetError=1)
    domain.PUMIMesh.loadModelAndMesh(bytes(Model,'utf-8'), bytes(Mesh,'utf-8'))
    domain.faceList=[[14],[12],[11],[13]]
    domain.boundaryLabels=[1,2,3,4]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain,domain.PUMIMesh, domain.faceList,domain.regList, parallel = comm.size() > 1, dim = domain.nd)

    domain.PUMIMesh.transferFieldToPUMI(b"coordinates",mesh.nodeArray)

    rho = numpy.array([998.2,998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0,0.0])
    deltaT = 1.0 #dummy number
    epsFact = 1.0 #dummy number
    domain.PUMIMesh.transferPropertiesToPUMI(rho,nu,g,deltaT,epsFact)

    #Couette Flow
    Lz = 0.05
    Uinf = 2e-3
    #hard code solution
    vector=numpy.zeros((mesh.nNodes_global,3),'d')
    dummy = numpy.zeros(mesh.nNodes_global); 
    vector[:,0] = Uinf*mesh.nodeArray[:,1]/Lz #v-velocity
    vector[:,1] = dummy
    vector[:,2] = dummy
    domain.PUMIMesh.transferFieldToPUMI(b"velocity", vector)
    del vector
    del dummy

    scalar=numpy.zeros((mesh.nNodes_global,1),'d')
    domain.PUMIMesh.transferFieldToPUMI(b"p", scalar)

    scalar[:,0] = mesh.nodeArray[:,1]
    domain.PUMIMesh.transferFieldToPUMI(b"phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global,1),'d')+1.0
    domain.PUMIMesh.transferFieldToPUMI(b"vof", scalar)

    errorTotal=domain.PUMIMesh.get_local_error()
    ok(errorTotal<1e-14)

    #ok(domain.PUMIMesh.willAdapt(),1)

    domain.PUMIMesh.adaptPUMIMesh()
    
    mesh = MeshTools.TriangularMesh()
    mesh.convertFromPUMI(domain,domain.PUMIMesh,
                     domain.faceList,
                     domain.regList,
                     parallel = comm.size() > 1,
                     dim = domain.nd)
    nElements_final = mesh.nElements_global
    ok(nElements_final>nElements_initial)
Exemple #15
0
    petsc_argv = [sys.argv[0]]
    with open(opts.petscOptionsFile) as petsc_file:
        data = petsc_file.readlines()

    def strip_comments(line):
        if '#' in line:
            line = line[:line.index('#')]
        return line

    stripped_data = [strip_comments(line) for line in data]
    petsc_argv += '\n'.join(stripped_data).split()
    log("PETSc options from commandline")
    log(str(petsc_argv))

Comm.argv = petsc_argv
comm = Comm.init()
Profiling.procID = comm.rank()
if opts.logLevel > 0:
    #mwf looks like just gets .py.log if no sso file given
    #Profiling.openLog(args[0][-3:]+".log",opts.logLevel)
    if len(args) == 0:
        Profiling.openLog("proteus.log", opts.logLevel)
    elif len(args[0].split(' ')) == 1:
        Profiling.openLog(args[0].split('.')[0] + ".log", opts.logLevel)
    else:
        Profiling.openLog(args[0][-3:] + ".log", opts.logLevel)
if opts.logAllProcesses:
    Profiling.logAllProcesses = True

#blanket import statements can go below here now that petsc4py should be initialized
from proteus import *
Exemple #16
0
def test_gmshLoadAndAdapt(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error and adapting for 
    a Couette flow case"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/Couette.null'
    Mesh = testDir + '/Couette.msh'

    domain = Domain.PUMIDomain()  #initialize the domain
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01,
                                                  hmin=0.008,
                                                  numIter=1,
                                                  sfConfig='ERM',
                                                  maType='isotropic')
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList = [[80], [76], [42], [24], [82], [78]]

    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)

    domain.PUMIMesh.transferFieldToPUMI("coordinates", mesh.nodeArray)

    rho = numpy.array([998.2, 998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0, 0.0, 0.0])
    domain.PUMIMesh.transferPropertiesToPUMI(rho, nu, g)

    #Couette Flow
    Lz = 0.05
    Uinf = 2e-3
    #hard code solution
    vector = numpy.zeros((mesh.nNodes_global, 3), 'd')
    dummy = numpy.zeros(mesh.nNodes_global)
    vector[:, 0] = dummy
    vector[:, 1] = Uinf * mesh.nodeArray[:, 2] / Lz  #v-velocity
    vector[:, 2] = dummy
    domain.PUMIMesh.transferFieldToPUMI("velocity", vector)
    del vector
    del dummy

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd')
    domain.PUMIMesh.transferFieldToPUMI("p", scalar)

    scalar[:, 0] = mesh.nodeArray[:, 2]
    domain.PUMIMesh.transferFieldToPUMI("phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd') + 1.0
    domain.PUMIMesh.transferFieldToPUMI("vof", scalar)

    errorTotal = domain.PUMIMesh.get_local_error()
    ok(errorTotal < 1e-14)

    ok(domain.PUMIMesh.willAdapt(), 1)

    domain.PUMIMesh.adaptPUMIMesh()

    mesh = MeshTools.TetrahedralMesh()
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    nElements_final = mesh.nElements_global
    ok(nElements_final > nElements_initial)
"""
convenience script to generate xdmf and vtk output from tetgen files
"""
from proteus import Comm
Comm.init()
comm = Comm.get()
def refine_uniform_from_tetgen(filebase,refinementLevels,index_base=0,EB=False):
    from proteus import MeshTools,Archiver
    mesh = MeshTools.TetrahedralMesh()
    mesh.generateFromTetgenFiles(filebase,index_base,skipGeometricInit=False)

    MLMesh = MeshTools.MultilevelTetrahedralMesh(0,0,0,skipInit=True)

    MLMesh.generateFromExistingCoarseMesh(mesh,refinementLevels)

    MLMesh.meshList[-1].writeTetgenFiles(filebase+'_out',index_base)

    ar = Archiver.XdmfArchive('.',filebase+'_out')
    import xml.etree.ElementTree as ElementTree
    ar.domain = ElementTree.SubElement(ar.tree.getroot(),"Domain")
    mesh.writeMeshXdmf(ar,'mesh_coarse'+'_out',init=True,EB=EB,tCount=0)
    MLMesh.meshList[-1].writeMeshXdmf(ar,'mesh_fine'+'_out',init=True,EB=EB,tCount=1)
    ar.close()
    
def refine_uniform_from_triangle(filebase,refinementLevels,index_base=0,EB=False):
    from proteus import MeshTools,Archiver
    mesh = MeshTools.TriangularMesh()
    mesh.generateFromTriangleFiles(filebase,index_base)

    MLMesh = MeshTools.MultilevelTriangularMesh(0,0,0,skipInit=True)
Exemple #18
0
def test_gmshLoadAndAdapt(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error and adapting for 
    a Couette flow case"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/Couette.null'
    Mesh = testDir + '/Couette.msh'

    domain = Domain.PUMIDomain(
        manager=MeshAdapt.AdaptManager())  #initialize the domain

    domain.AdaptManager.modelDict = {'flow': 0}
    domain.AdaptManager.sizeInputs = [b'error_erm']
    domain.AdaptManager.adapt = 1
    domain.AdaptManager.hmax = 0.01
    domain.AdaptManager.hmin = 0.008
    domain.AdaptManager.hphi = 0.008
    domain.AdaptManager.numIterations = 1
    domain.AdaptManager.targetError = 1

    domain.AdaptManager.PUMIAdapter.loadModelAndMesh(bytes(Model, 'utf-8'),
                                                     bytes(Mesh, 'utf-8'))
    domain.AdaptManager.PUMIAdapter.setAdaptProperties(domain.AdaptManager)

    domain.faceList = [[80], [76], [42], [24], [82], [78]]
    domain.boundaryLabels = [1, 2, 3, 4, 5, 6]

    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain,
                         domain.AdaptManager.PUMIAdapter,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)

    domain.AdaptManager.PUMIAdapter.transferFieldToPUMI(
        b"coordinates", mesh.nodeArray)

    rho = numpy.array([998.2, 998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0, 0.0, 0.0])
    deltaT = 1.0  #dummy number
    epsFact = 1.0  #dummy number
    domain.AdaptManager.PUMIAdapter.transferPropertiesToPUMI(
        rho, nu, g, deltaT, deltaT, deltaT, epsFact)

    #Couette Flow
    Lz = 0.05
    Uinf = 2e-3
    #hard code solution
    vector = numpy.zeros((mesh.nNodes_global, 3), 'd')
    dummy = numpy.zeros(mesh.nNodes_global)
    vector[:, 0] = dummy
    vector[:, 1] = Uinf * mesh.nodeArray[:, 2] / Lz  #v-velocity
    vector[:, 2] = dummy
    domain.AdaptManager.PUMIAdapter.transferFieldToPUMI(b"velocity", vector)
    del vector
    del dummy

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd')
    domain.AdaptManager.PUMIAdapter.transferFieldToPUMI(b"p", scalar)

    scalar[:, 0] = mesh.nodeArray[:, 2]
    domain.AdaptManager.PUMIAdapter.transferFieldToPUMI(b"phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd') + 1.0
    domain.AdaptManager.PUMIAdapter.transferFieldToPUMI(b"vof", scalar)

    errorTotal = domain.AdaptManager.PUMIAdapter.get_local_error()
    ok(errorTotal < 1e-14)

    #ok(domain.AdaptManager.willAdapt(),1)
    domain.AdaptManager.PUMIAdapter.adaptPUMIMesh(b"")

    mesh = MeshTools.TetrahedralMesh()
    mesh.convertFromPUMI(domain,
                         domain.AdaptManager.PUMIAdapter,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    nElements_final = mesh.nElements_global
    ok(nElements_final > nElements_initial)
Exemple #19
0
log = Profiling.logEvent

log("Initializing MPI")#this won't show up unless logAllProcesses=True because we don't know our procID yet
if opts.petscOptions != None:
    petsc_argv = sys.argv[:1]+opts.petscOptions.split()
    log("PETSc options from commandline")
    log(str(petsc_argv))
else:
    petsc_argv=sys.argv[:1]
if opts.petscOptionsFile != None:
    petsc_argv=[sys.argv[0]]
    petsc_argv += open(opts.petscOptionsFile).read().split()
    log("PETSc options from commandline")
    log(str(petsc_argv))

comm = Comm.init(argv=petsc_argv)
#blanket import statements can go below here now that petsc4py should be initialized
Profiling.procID=comm.rank()
log("Initialized MPI")
if opts.viewer is not False:
    from proteusGraphical import *
from proteus import *

log("Adding "+str(opts.probDir)+" to path for loading modules")
probDir = str(opts.probDir)
if probDir not in sys.path:
    sys.path.insert(0,probDir)

pList = []
nList = []
sList = []
Exemple #20
0
def test_2DgmshLoadAndAdapt(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error and adapting for 
    a 2D Couette flow case"""
    testDir=os.path.dirname(os.path.abspath(__file__))
    Model=testDir + '/Couette2D.null'
    Mesh=testDir + '/Couette2D.msh'
    domain = Domain.PUMIDomain(dim=2) #initialize the domain
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig='ERM',maType='isotropic',targetError=1)
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList=[[14],[12],[11],[13]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList,domain.regList, parallel = comm.size() > 1, dim = domain.nd)

    domain.PUMIMesh.transferFieldToPUMI("coordinates",mesh.nodeArray)

    rho = numpy.array([998.2,998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0,0.0])
    deltaT = 1.0 #dummy number
    domain.PUMIMesh.transferPropertiesToPUMI(rho,nu,g,deltaT)

    #Couette Flow
    Lz = 0.05
    Uinf = 2e-3
    #hard code solution
    vector=numpy.zeros((mesh.nNodes_global,3),'d')
    dummy = numpy.zeros(mesh.nNodes_global); 
    vector[:,0] = Uinf*mesh.nodeArray[:,1]/Lz #v-velocity
    vector[:,1] = dummy
    vector[:,2] = dummy
    domain.PUMIMesh.transferFieldToPUMI("velocity", vector)
    del vector
    del dummy

    scalar=numpy.zeros((mesh.nNodes_global,1),'d')
    domain.PUMIMesh.transferFieldToPUMI("p", scalar)

    scalar[:,0] = mesh.nodeArray[:,1]
    domain.PUMIMesh.transferFieldToPUMI("phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global,1),'d')+1.0
    domain.PUMIMesh.transferFieldToPUMI("vof", scalar)

    errorTotal=domain.PUMIMesh.get_local_error()
    ok(errorTotal<1e-14)

    ok(domain.PUMIMesh.willAdapt(),1)

    domain.PUMIMesh.adaptPUMIMesh()
    
    mesh = MeshTools.TriangularMesh()
    mesh.convertFromPUMI(domain.PUMIMesh,
                     domain.faceList,
                     domain.regList,
                     parallel = comm.size() > 1,
                     dim = domain.nd)
    nElements_final = mesh.nElements_global
    ok(nElements_final>nElements_initial)
Exemple #21
0
#import sys
#from proteus import Comm
import os
import sys
import socket
import cPickle
import numpy
import proteus
#remove blankent import statements until after Comm initialized for petsc4py
# from proteus import *
from proteus import Profiling,Comm
from warnings import *
import optparse
import sys
import pstats
import pdb
import petsc4py
Profiling.openLog("proteus.log",7)
print sys.argv[:1]
comm = Comm.init(argv=sys.argv[:1])
comm = Comm.init(argv=sys.argv[:1])
#petsc4py.init(sys.argv[:1])
print comm.rank(),comm.size()
print "Hellow World from",comm.rank()
from proteus import *
Profiling.procID=comm.rank()
def test_poiseuilleError(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error for 
    a Poiseuille flow case. The estimated error should be larger than the
    exact error in the seminorm"""
    testDir=os.path.dirname(os.path.abspath(__file__))
    Model=testDir + '/Couette.null'
    Mesh=testDir + '/Couette.msh'

    domain = Domain.PUMIDomain() #initialize the domain
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig='ERM',maType='isotropic',logType='off')
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList=[[80],[76],[42],[24],[82],[78]]

    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList, domain.regList,parallel = comm.size() > 1, dim = domain.nd)

    domain.PUMIMesh.transferFieldToPUMI("coordinates",mesh.nodeArray)


    rho = numpy.array([998.2,998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0,0.0,0.0])
    deltaT = 1.0 #dummy number 
    domain.PUMIMesh.transferPropertiesToPUMI(rho,nu,g,deltaT)

    #Poiseuille Flow
    Ly=0.2
    Lz = 0.05
    Re = 100
    Umax = Re*nu[0]/Lz

    def vOfX(x):
        return 4*Umax/(Lz**2)*(x[2])*(Lz-x[2])
    def dvOfXdz(x):
        return 4*Umax/(Lz**2)*(Lz-2*x[2])

    #hard code solution
    vector=numpy.zeros((mesh.nNodes_global,3),'d')
    dummy = numpy.zeros(mesh.nNodes_global); 

    vector[:,0] = dummy
    vector[:,1] = 4*Umax/(Lz**2)*(mesh.nodeArray[:,2])*(Lz-mesh.nodeArray[:,2]) #v-velocity
    vector[:,2] = dummy
    domain.PUMIMesh.transferFieldToPUMI("velocity", vector)

    scalar=numpy.zeros((mesh.nNodes_global,1),'d')
    domain.PUMIMesh.transferFieldToPUMI("p", scalar)

    scalar[:,0] = mesh.nodeArray[:,2]
    domain.PUMIMesh.transferFieldToPUMI("phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global,1),'d')+1.0
    domain.PUMIMesh.transferFieldToPUMI("vof", scalar)

    errorTotal=domain.PUMIMesh.get_local_error()


    # load the femspace with linear basis and get the quadrature points on a reference element
    elementQuadrature = Quadrature.SimplexGaussQuadrature(domain.nd,3)

    ok(mesh.nNodes_element==4) #confirm all of the elements have 4 nodes

    #hard code computation for H1 seminorm; ideally will be reformatted using the classes within proteus
    derivativeArrayRef = [[1,0,0],[0,1,0],[0,0,1],[-1,-1,-1]]
    error = 0
    for eID in range(mesh.nElements_global):
        nodes=mesh.elementNodesArray[eID]
        coords=[];
        for i in range(mesh.nNodes_element):
            coords.append(mesh.nodeArray[nodes[i]])
        J = numpy.matrix([[coords[0][0]-coords[3][0],coords[1][0]-coords[3][0],coords[2][0]-coords[3][0]],
                          [coords[0][1]-coords[3][1],coords[1][1]-coords[3][1],coords[2][1]-coords[3][1]],
                          [coords[0][2]-coords[3][2],coords[1][2]-coords[3][2],coords[2][2]-coords[3][2]]])
        invJ = J.I
        detJ = numpy.linalg.det(J)
        gradPhi_h = 0
        for k in range(len(elementQuadrature.points)):
            tempQpt = 0 
            zCoord = elementQuadrature.points[k][0]*coords[0][2] \
                +elementQuadrature.points[k][1]*coords[1][2] \
                +elementQuadrature.points[k][2]*coords[2][2] \
                +(1-elementQuadrature.points[k][0]-elementQuadrature.points[k][1]-elementQuadrature.points[k][2])*coords[3][2]
            for i in range(mesh.nNodes_element):
                temp = 0
                for j in range(domain.nd):
                    temp = temp + derivativeArrayRef[i][j]*invJ[j,2]
                tempQpt = tempQpt + vector[nodes[i]][1]*temp
            exactgradPhi = dvOfXdz([0,0,zCoord])
            gradPhi_h = gradPhi_h + tempQpt
            error = error + (exactgradPhi-gradPhi_h)**2*elementQuadrature.weights[k]*abs(detJ)

    error = sqrt(error)
    ok(error<errorTotal)