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(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.PUMIMesh, domain.faceList, domain.regList, parallel=comm.size() > 1, dim=domain.nd) ok(mesh.elementMaterialTypes[0] == 1) ok(mesh.elementMaterialTypes[-1] == 2)
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_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_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)
nny = 2 * refinement domain = Domain.RectangularDomain(tank_dim) boundaryTags = domain.boundaryTags elif usePUMI and not genMesh: from proteus.MeshAdaptPUMI import MeshAdaptPUMI domain = Domain.PUMIDomain(dim=nd) #initialize the domain #boundaryTags=baseDomain.boundaryFlags he = 0.06 adaptMeshFlag = opts.adapt#1 adaptMesh_nSteps =3#5 adaptMesh_numIter = 5 hmax = he; hmin = he/4.0; hPhi = he/2.0;#/4.0 domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=hmax, hmin=hmin, hPhi = hPhi, adaptMesh=adaptMeshFlag, numIter=adaptMesh_numIter, numAdaptSteps=adaptMesh_nSteps, sfConfig="pseudo",logType="off",reconstructedFlag=2,gradingFact=1.2) domain.PUMIMesh.loadModelAndMesh("Reconstructed.dmg", "Reconstructed.smb") else: domain = Domain.PlanarStraightLineGraphDomain() if genMesh and usePUMI: from proteus.MeshAdaptPUMI import MeshAdaptPUMI domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI() # ----- TANK ----- # tank = Tank2D(domain, tank_dim) # ----- EXTRA BOUNDARY CONDITIONS ----- #
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)
nd = 2 #number of dimensions in the problem parallelPartitioningType = proteus.MeshTools.MeshParallelPartitioningTypes.element #type of partitioning if parallel nLayersOfOverlapForParallel = 0 #amount of ghosting if parallel boundaries = ['left', 'right', 'bottom', 'top'] #boundary tag dictionary boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)]) domain = Domain.PUMIDomain(dim=nd) #initialize the domain domain.faceList = [[11], [13], [14], [12]] #model entities associated wtih boundary tags adaptMesh = True #adapt the mesh? adaptMesh_nSteps = 5 #amount of time steps before checking error? hMax = 0.08 hMin = 0.00625 adaptMesh_numIter = 2 #number of iterations for mesh adaptation errorType = "ERM" #only just ERM at the moment logSwitch = "off" #on or off target_error = 10.0 target_element_count = 8000 domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI( hmax=hMax, hmin=hMin, numIter=adaptMesh_numIter, sfConfig=errorType, logType=logSwitch, targetError=target_error, targetElementCount=target_element_count) domain.PUMIMesh.loadModelAndMesh("Dambreak.null", "Dambreak.msh")
domain = Domain.PUMIDomain() #initialize the domain #domain.numBC=6 #set number of BCs # domain.numAdaptSteps=1 #set number of adapt steps (loops) #Following sets list of face tags of geometric model as mapped from boundary Tags, #meaning if faceList=[[2,4],[1]] and boundaries=['left','right'], then faces with geometry tags 2 and 4 are set as 'left' #and face with geometric tag 4 is set as 'right' #The order of boundaries list is important because the last ones take precendence over the first ones, #which means that the geometric edge or vertex which lies on 2 or more geometric faces will be set with the boundaries tag of #the geomtric face which is latter in the order (email: [email protected] for any questions) domain.faceList=[[41],[46],[42],[44],[45],[43]] #set max edge length, min edge length, number of meshadapt iterations and initialize the MeshAdaptPUMI object he =0.5 adaptMesh = True adaptMesh_nSteps = 10 adaptMesh_numIter = 2 domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig='ERM',maType='isotropic',targetError=0.1,targetElementCount=1000) #domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig='isotropic') #read the geometry and mesh testDir=os.path.dirname(os.path.abspath(__file__)) Model = testDir + '/../Couette.null' Mesh = testDir + '/../Couette.msh' domain.PUMIMesh.loadModelAndMesh(Model,Mesh) # Time stepping T=1.0 dt_fixed = 0.2 dt_init = min(0.1*dt_fixed,0.001) runCFL=0.33 nDTout = int(round(old_div(T,dt_fixed))) # Numerical parameters
faceList = [] for boundary in boundaries: if boundary in faceMap: faceList.append(faceMap[boundary]) else: faceList.append([]) domain = Domain.PUMIDomain(dim=3) domain.faceList = faceList adaptMesh = True adaptMesh_nSteps = 10 adaptMesh_numIter = 3 domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI(hmax=he, hmin=he, numIter=adaptMesh_numIter, sfConfig="farhad") domain.PUMIMesh.loadModelAndMesh("floating_bar_3d.dmg", "floating_bar_3d.smb") restrictFineSolutionToAllMeshes = False parallelPartitioningType = MeshTools.MeshParallelPartitioningTypes.element nLayersOfOverlapForParallel = 0 quad_order = 3 #---------------------------------------------------- # Boundary conditions and other flags #---------------------------------------------------- openTop = False openSides = False openEnd = True