def test_gmsh_generation_3D(self): domain = Domain.PiecewiseLinearComplexDomain() cube = st.Cuboid(domain, dim=[2.,2.,2.]) st.assembleDomain(domain) domain.writeGeo('gmsh_mesh_test_3D', he_max=0.1) gmsh_cmd = "gmsh {0:s} -v 10 -3 -o {1:s} -format msh".format(domain.geofile+".geo", domain.geofile+".msh") check_call(gmsh_cmd, shell=True) MeshTools.msh2simplex(domain.geofile, nd=3) # cek disabling exact tests due to cross-platform non-reproducibility # with open('gmsh_mesh_test_3D.node', 'r') as nodefile: # npt.assert_equal(nodefile.readline(), '7674 3 0 1\n') # with open('gmsh_mesh_test_3D.edge', 'r') as edgefile: # npt.assert_equal(edgefile.readline(), '9384 1\n') # with open('gmsh_mesh_test_3D.face', 'r') as facefile: # npt.assert_equal(facefile.readline(), '6256 3 1\n') # with open('gmsh_mesh_test_3D.ele', 'r') as elefile: # npt.assert_equal(elefile.readline(), '37473 4 1\n') with open('gmsh_mesh_test_3D.node', 'r') as nodefile: assert(abs(int(nodefile.readline().split()[0]) - 7674)/7674.0 < .02) with open('gmsh_mesh_test_3D.edge', 'r') as edgefile: assert(abs(int(edgefile.readline().split()[0]) - 9384)/9384.0 < .02) with open('gmsh_mesh_test_3D.face', 'r') as facefile: assert(abs(int(facefile.readline().split()[0]) - 6256)/6256.0 < .02) with open('gmsh_mesh_test_3D.ele', 'r') as elefile: assert(abs(int(elefile.readline().split()[0]) - 37473)/37473.0 < .02)
def test_adaptIBM_adaptMesh(self): currentPath = os.path.dirname(os.path.abspath(__file__)) runCommand = "cd " + currentPath + "; parun -l5 cylinder_so.py -C 'T=0.01 onlySaveFinalSolution=True genMesh=False usePUMI=True';" subprocess.check_call(runCommand, shell=True) #load initial mesh and extract element count domain = Domain.PUMIDomain( manager=MeshAdapt.AdaptManager()) #initialize the domain filePath = bytes(currentPath + '/', 'utf-8') domain.AdaptManager.PUMIAdapter.loadModelAndMesh( filePath + b"Reconstructed.dmg", filePath + b"Reconstructed.smb") mesh = MeshTools.TetrahedralMesh() mesh.convertFromPUMI(domain, domain.AdaptManager.PUMIAdapter, [1], [1], parallel=comm.size() > 1, dim=2) nElements_initial = mesh.nElements_global #load final mesh and extract element count domain.AdaptManager.PUMIAdapter.loadModelAndMesh( filePath + b"Reconstructed.dmg", filePath + b"finalMesh.smb") mesh2 = MeshTools.TetrahedralMesh() mesh2.convertFromPUMI(domain, domain.AdaptManager.PUMIAdapter, [1], [1], parallel=comm.size() > 1, dim=2) nElements_final = mesh2.nElements_global #adapted mesh should have less elements assert (nElements_final < nElements_initial)
def test_gmsh_generation_3D(self): domain = Domain.PiecewiseLinearComplexDomain() cube = st.Cuboid(domain, dim=[2., 2., 2.]) st.assembleDomain(domain) domain.writeGeo('gmsh_mesh_test_3D', he_max=0.1) gmsh_cmd = "gmsh {0:s} -v 10 -3 -o {1:s} -format msh".format( domain.geofile + ".geo", domain.geofile + ".msh") check_call(gmsh_cmd, shell=True) MeshTools.msh2simplex(domain.geofile, nd=3) # cek disabling exact tests due to cross-platform non-reproducibility # with open('gmsh_mesh_test_3D.node', 'r') as nodefile: # npt.assert_equal(nodefile.readline(), '7674 3 0 1\n') # with open('gmsh_mesh_test_3D.edge', 'r') as edgefile: # npt.assert_equal(edgefile.readline(), '9384 1\n') # with open('gmsh_mesh_test_3D.face', 'r') as facefile: # npt.assert_equal(facefile.readline(), '6256 3 1\n') # with open('gmsh_mesh_test_3D.ele', 'r') as elefile: # npt.assert_equal(elefile.readline(), '37473 4 1\n') with open('gmsh_mesh_test_3D.node', 'r') as nodefile: assert (abs(int(nodefile.readline().split()[0]) - 7674) / 7674.0 < .02) with open('gmsh_mesh_test_3D.edge', 'r') as edgefile: assert (abs(int(edgefile.readline().split()[0]) - 9384) / 9384.0 < .02) with open('gmsh_mesh_test_3D.face', 'r') as facefile: assert (abs(int(facefile.readline().split()[0]) - 6256) / 6256.0 < .02) with open('gmsh_mesh_test_3D.ele', 'r') as elefile: assert (abs(int(elefile.readline().split()[0]) - 37473) / 37473.0 < .02)
def PUMI_adaptMesh(self,inputString=b""): """ Uses a computed error field to construct a size field and adapts the mesh using SCOREC tools (a.k.a. MeshAdapt) """ ## domain = self.domain if(hasattr(self,"nSolveSteps")): logEvent("h-adapt mesh by calling AdaptAdaptManager.PUMIAdapter at step %s" % self.nSolveSteps) if(b"pseudo" in self.domain.AdaptManager.sizeInputs): logEvent("Testing solution transfer and restart feature of adaptation. No actual mesh adaptation!") else: domain.AdaptManager.PUMIAdapter.adaptPUMIMesh(inputString) logEvent("Converting PUMI mesh to Proteus") #ibaned: PUMI conversion #2 #TODO: this code is nearly identical to #PUMI conversion #1, they should be merged #into a function if domain.nd == 3: mesh = MeshTools.TetrahedralMesh() else: mesh = MeshTools.TriangularMesh() mesh.convertFromPUMI(domain, domain.AdaptManager.PUMIAdapter, domain.faceList, domain.regList, parallel = self.comm.size() > 1, dim = domain.nd) self.PUMI_reallocate(mesh) self.PUMI2Proteus(domain)
def PUMI_reallocate(self, mesh): p0 = self.pList[0] n0 = self.nList[0] if self.TwoPhaseFlow: nLevels = p0.myTpFlowProblem.general['nLevels'] nLayersOfOverlapForParallel = p0.myTpFlowProblem.general[ 'nLayersOfOverlapForParallel'] parallelPartitioningType = MeshTools.MeshParallelPartitioningTypes.element domain = p0.myTpFlowProblem.domain domain.MeshOptions.setParallelPartitioningType('element') else: nLevels = n0.nLevels nLayersOfOverlapForParallel = n0.nLayersOfOverlapForParallel parallelPartitioningType = n0.parallelPartitioningType domain = p0.domain logEvent("Generating %i-level mesh from PUMI mesh" % (nLevels, )) if domain.nd == 3: mlMesh = MeshTools.MultilevelTetrahedralMesh( 0, 0, 0, skipInit=True, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) if domain.nd == 2: mlMesh = MeshTools.MultilevelTriangularMesh( 0, 0, 0, skipInit=True, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) if self.comm.size() == 1: mlMesh.generateFromExistingCoarseMesh( mesh, nLevels, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) else: mlMesh.generatePartitionedMeshFromPUMI( mesh, nLevels, nLayersOfOverlap=nLayersOfOverlapForParallel) self.mlMesh_nList = [] for p in self.pList: self.mlMesh_nList.append(mlMesh) if (domain.PUMIMesh.size_field_config() == "isotropicProteus"): mlMesh.meshList[0].subdomainMesh.size_field = numpy.ones( (mlMesh.meshList[0].subdomainMesh.nNodes_global, 1), 'd') * 1.0e-1 if (domain.PUMIMesh.size_field_config() == 'anisotropicProteus'): mlMesh.meshList[0].subdomainMesh.size_scale = numpy.ones( (mlMesh.meshList[0].subdomainMesh.nNodes_global, 3), 'd') mlMesh.meshList[0].subdomainMesh.size_frame = numpy.ones( (mlMesh.meshList[0].subdomainMesh.nNodes_global, 9), 'd') #may want to trigger garbage collection here self.modelListOld = self.modelList logEvent("Allocating models on new mesh") self.allocateModels()
def test_c0q1_hex_mesh(): from proteus import MeshTools xmf_archive_base=os.path.join(os.path.dirname(os.path.abspath(__file__)), '..','hex_cube_3x3') heavy_file_base = xmf_archive_base mesh_info = MeshTools.readMeshXdmf(xmf_archive_base,heavy_file_base) hex_meshfile_base = 'hexmesh_3x3' MeshTools.writeHexMesh(mesh_info,hex_meshfile_base,index_base=1) check_c0q1(test_hexMesh_3x3=True,use_petsc=True, name="_hexMesh_")
def test_c0q1_hex_mesh(): from proteus import MeshTools xmf_archive_base = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'hex_cube_3x3') heavy_file_base = xmf_archive_base mesh_info = MeshTools.readMeshXdmf(xmf_archive_base, heavy_file_base) hex_meshfile_base = 'hexmesh_3x3' MeshTools.writeHexMesh(mesh_info, hex_meshfile_base, index_base=1) check_c0q1(test_hexMesh_3x3=True, use_petsc=True, name="_hexMesh_")
def build3DMesh(p, nnx, nny, nnz): return MeshTools.MultilevelTetrahedralMesh(nnx,nny,nnz, p.domain.x[0], p.domain.x[1], p.domain.x[2], p.domain.L[0], p.domain.L[1], p.domain.L[2], refinementLevels=1, nLayersOfOverlap=0, parallelPartitioningType=MeshTools.MeshParallelPartitioningTypes.node)
def build1DMesh(p, nnx): return MeshTools.MultilevelEdgeMesh(nnx, 1, 1, p.domain.x[0], 0.0, 0.0, p.domain.L[0], 1.0, 1.0, refinementLevels=1, nLayersOfOverlap=0, parallelPartitioningType=MeshTools.MeshParallelPartitioningTypes.node)
def build2DMesh(p, nnx, nny): return MeshTools.MultilevelTriangularMesh(nnx,nny,1, p.domain.x[0], p.domain.x[1], 1.0, p.domain.L[0], p.domain.L[1], 1.0, refinementLevels=1, nLayersOfOverlap=0, parallelPartitioningType=MeshTools.MeshParallelPartitioningTypes.node)
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 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 test_gmsh_generation_2D(self): domain = Domain.PlanarStraightLineGraphDomain() domain.vertices = [[0., 0., 0.], [5., 0., 0.], [5., 5., 0.], [0., 5., 0.]] domain.segments = [[0, 1], [1, 2], [2, 3], [3, 0]] domain.facets = [[[0, 1, 2, 3]]] domain.writeGeo('gmsh_mesh_test_2D', he_max=0.1) gmsh_cmd = "gmsh {0:s} -v 10 -2 -o {1:s} -format msh".format( domain.geofile + ".geo", domain.geofile + ".msh") check_call(gmsh_cmd, shell=True) MeshTools.msh2simplex(domain.geofile, nd=2) with open('gmsh_mesh_test_2D.node', 'r') as nodefile: npt.assert_equal(nodefile.readline(), '3425 2 0 1\n') with open('gmsh_mesh_test_2D.edge', 'r') as edgefile: npt.assert_equal(edgefile.readline(), '10072 1\n') with open('gmsh_mesh_test_2D.ele', 'r') as elefile: npt.assert_equal(elefile.readline(), '6648 3 1\n')
def PUMI_reallocate(self,mesh): p0 = self.pList[0] n0 = self.nList[0] nLevels = n0.nLevels nLayersOfOverlapForParallel = n0.nLayersOfOverlapForParallel parallelPartitioningType = MeshTools.MeshParallelPartitioningTypes.element domain = p0.domain domain.MeshOptions.setParallelPartitioningType('element') logEvent("Generating %i-level mesh from PUMI mesh" % (nLevels,)) if domain.nd == 3: mlMesh = MeshTools.MultilevelTetrahedralMesh( 0,0,0,skipInit=True, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) if domain.nd == 2: mlMesh = MeshTools.MultilevelTriangularMesh( 0,0,0,skipInit=True, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) if self.comm.size()==1: mlMesh.generateFromExistingCoarseMesh( mesh,nLevels, nLayersOfOverlap=nLayersOfOverlapForParallel, parallelPartitioningType=parallelPartitioningType) else: mlMesh.generatePartitionedMeshFromPUMI( mesh,nLevels, nLayersOfOverlap=nLayersOfOverlapForParallel) #need to remove old mlMesh references to ensure the number of mesh entities is properly updated self.mlMesh_nList.clear() for p in self.pList: self.mlMesh_nList.append(mlMesh) if (b"isotropicProteus" in self.domain.AdaptManager.sizeInputs): mlMesh.meshList[0].subdomainMesh.size_field = numpy.ones((mlMesh.meshList[0].subdomainMesh.nNodes_global,1),'d')*1.0e-1 if (b'anisotropicProteus' in self.domain.AdaptManager.sizeInputs): mlMesh.meshList[0].subdomainMesh.size_scale = numpy.ones((mlMesh.meshList[0].subdomainMesh.nNodes_global,3),'d') mlMesh.meshList[0].subdomainMesh.size_frame = numpy.ones((mlMesh.meshList[0].subdomainMesh.nNodes_global,9),'d') #may want to trigger garbage collection here self.modelListOld = self.modelList logEvent("Allocating models on new mesh") self.allocateModels()
def test_gmsh_generation_2D(self): domain = Domain.PlanarStraightLineGraphDomain() domain.vertices = [[0., 0., 0.], [5., 0., 0.], [5., 5., 0.], [0., 5., 0.]] domain.segments = [[0, 1], [1, 2], [2, 3], [3, 0]] domain.facets = [[[0, 1, 2, 3]]] domain.writeGeo('gmsh_mesh_test_2D', he_max=0.1) gmsh_cmd = "gmsh {0:s} -v 10 -2 -o {1:s} -format msh".format(domain.geofile+".geo", domain.geofile+".msh") check_call(gmsh_cmd, shell=True) MeshTools.msh2simplex(domain.geofile, nd=2) with open('gmsh_mesh_test_2D.node', 'r') as nodefile: npt.assert_equal(nodefile.readline(), '3425 2 0 1\n') with open('gmsh_mesh_test_2D.edge', 'r') as edgefile: npt.assert_equal(edgefile.readline(), '10072 1\n') with open('gmsh_mesh_test_2D.ele', 'r') as elefile: npt.assert_equal(elefile.readline(), '6648 3 1\n')
def hotstartWithPUMI(self): #Call restart functions logEvent("Converting PUMI mesh to Proteus") if self.pList[0].domain.nd == 3: mesh = MeshTools.TetrahedralMesh() else: mesh = MeshTools.TriangularMesh() mesh.convertFromPUMI(self.pList[0].domain.AdaptManager.PUMIAdapter, self.pList[0].domain.faceList, self.pList[0].domain.regList, parallel = self.comm.size() > 1, dim = self.pList[0].domain.nd) if(self.pList[0].domain.checkpointInfo==None): sys.exit("Need to specify checkpointInfo file in inputs") else: self.PUMIcheckpointer.DecodeModel(self.pList[0].domain.checkpointInfo) self.PUMI_reallocate(mesh) #need to double check if this call is necessaryor if it can be simplified to a shorter call PUMI2Proteus(self,self.pList[0].domain)
def test_meshLoadPUMI(verbose=0): """Test to load serial PUMI model and mesh""" testDir=os.path.dirname(os.path.abspath(__file__)) cubeMdl=testDir + '/cube.dmg' cube670p1=testDir + '/cube.smb' meshAdaptInstance = MeshAdaptPUMI.MeshAdaptPUMI() meshAdaptInstance.loadModelAndMesh(cubeMdl, cube670p1) mesh = MeshTools.TetrahedralMesh() mesh.cmesh = cmeshTools.CMesh() meshAdaptInstance.constructFromSerialPUMIMesh(mesh.cmesh) mesh.buildFromC(mesh.cmesh) eq(mesh.nElements_global,670) eq(mesh.nNodes_global,190) eq(mesh.nEdges_global,977) eq(mesh.nElementBoundaries_global,1458)
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_meshLoadPUMI(verbose=0): """Test to load serial PUMI model and mesh""" testDir = os.path.dirname(os.path.abspath(__file__)) cubeMdl = testDir + '/cube.dmg' cube670p1 = testDir + '/cube.smb' PUMIAdapter = MeshAdaptPUMI.MeshAdapt() PUMIAdapter.loadModelAndMesh(bytes(cubeMdl, 'utf-8'), bytes(cube670p1, 'utf-8')) mesh = MeshTools.TetrahedralMesh() mesh.cmesh = cmeshTools.CMesh() PUMIAdapter.constructFromSerialPUMIMesh(mesh.cmesh) cmeshTools.allocateGeometricInfo_tetrahedron(mesh.cmesh) cmeshTools.computeGeometricInfo_tetrahedron(mesh.cmesh) mesh.buildFromC(mesh.cmesh) eq(mesh.nElements_global, 670) eq(mesh.nNodes_global, 190) eq(mesh.nEdges_global, 977) eq(mesh.nElementBoundaries_global, 1458)
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 __init__(self, nd, name="defaultDomain", units="m"): """ Set dimensions (nd), name string, and units string """ if nd not in [1, 2, 3]: raise RuntimeError("Domain object must have dimension 1,2, or 3") self.nd = nd self.name = name self.units = units # make default empty list for parameters self.vertices = [] self.vertexFlags = [] self.segments = [] self.segmentFlags = [] self.facets = [] # necessary in 2D for gmsh self.facetFlags = [] self.holes = [] self.holes_ind = [] # for gmsh: index of hole (2D: facet; 3D: volume) self.regions = [] self.regionFlags = [] self.volumes = [] # only for gmsh: loop of facets # for bounding box self.x = [] self.L = [] # list of shape instances (from proteus.SpatialTools.py) self.shape_list = [] # list of boundary conditions self.bc = [] # list of auxiliaryVariables self.auxiliaryVariables = [] # needed for gmsh self.volumes = [] self.boundaryTags = {} self.BC = {} self.BCbyFlag = {} # use_gmsh hack self.use_gmsh = False self.MeshOptions = MeshTools.MeshOptions(self)
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)
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)
facetFlags=facetFlags) #regions = regions, #regionFlags = regionFlags, #holes=holes) domain.MeshOptions.setParallelPartitioningType('node') #domain.MeshOptions.use_gmsh=True domain.boundaryTags = boundaryTags domain.writePoly("mesh") domain.writeGeo("mesh",he_max=he) #domain.writeGeo("mesh",he_max=he) #domain.writePLY("mesh") #domain.writeAsymptote("mesh") #domain.MeshOptions.triangleOptions="VApq1.25q12feena%e" % ((he**3)/6.0,) gmsh_cmd = "gmsh {0:s} -v 10 -3 -o {1:s} -format msh2".format(domain.geofile+".geo", domain.geofile+".msh") check_call(gmsh_cmd, shell=True) mt.msh2simplex("mesh",nd=3) domain.MeshOptions.genMesh=False # ****************************** # # ***** INITIAL CONDITIONS ***** # # ****************************** # class zero(object): def uOfXT(self,x,t): return 0. disc_ICs=True class clsvof_init_cond(object): def uOfXT(self,x,t): waterLine_x = 1.22 waterLine_z = 0.55 phi_x = x[0]-waterLine_x phi_z = x[2]-waterLine_z
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)
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)
midpoint_z_index = (nPoints_z + 1) // 2 assert (nPoints_x + 1) % 2 == 0 assert (nPoints_y + 1) % 2 == 0 assert (nPoints_z + 1) % 2 == 0 dx = 1.0 / (nPoints_x - 1.0) dy = 1.0 / (nPoints_y - 1.0) dz = 1.0 / (nPoints_z - 1.0) x = np.zeros((nPoints_x, nPoints_y, nPoints_z, 3), 'd') for i in range(nPoints_x): for j in range(nPoints_y): for k in range(nPoints_z): x[i, j, k, 0] = i * dx x[i, j, k, 1] = j * dy x[i, j, k, 2] = k * dz grid = MeshTools.RectangularGrid(500, 1, 1, Lx=1.0) X = np.array([n.p for n in grid.nodeList]) Xx = np.array([n.p[0] for n in grid.nodeList]) def test_PlaneCouetteFlow(): iwork = np.zeros((1, ), 'i') rwork = np.zeros((5, ), 'd') t = 0.0 rwork[0] = 0.1 rwork[1] = dy * (nPoints_y - 1.0) rwork[2] = 0.0 rwork[3] = 0.0 rwork[4] = 0.0 ux = np.zeros(x.shape[:-1], 'd') uy = np.zeros(x.shape[:-1], 'd')