本文整理汇总了Python中proteus.Comm.init方法的典型用法代码示例。如果您正苦于以下问题:Python Comm.init方法的具体用法?Python Comm.init怎么用?Python Comm.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类proteus.Comm
的用法示例。
在下文中一共展示了Comm.init方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_mpi_petsc
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例2: test_2DparallelLoadPUMI
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例3: test_3DparallelLoadPUMI
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例4: test_2DmultiRegion
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例5: test_wdot
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例6: test_load_vector
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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()
示例7: log
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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 = []
示例8: test_2DgmshLoadAndAdapt
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例9: test_poiseuilleError
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
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)
示例10:
# 需要导入模块: from proteus import Comm [as 别名]
# 或者: from proteus.Comm import init [as 别名]
#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()