def test_Tet10_macro(self): file="tet10_gmsh.msh" ref="tet10_macro.fly" test = os.path.join(FINLEY_WORKDIR,"tet10_macro_test.fly") dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3,useMacroElements=True,optimize=False) dom.write(test) self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
def test_Tet4(self): file="tet4_gmsh.msh" ref="tet4.fly" test = os.path.join(FINLEY_WORKDIR,"tet4_test.fly") dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3,optimize=False) dom.write(test) self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
def test_readgmsh_format_4_1(self): mydomain1 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "testcube.2.2.msh"), numDim=3) mydomain2 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "testcube.4.1.msh"), numDim=3) self.domainsEqual(mydomain1, mydomain2)
def test_gmshTags(self): dom=ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "tagtest.msh"),2) tags=dom.showTagNames().split(', ') self.assertEqual(tags,['tag1', 'tag2', 'tag3'],'error with tags') self.assertEqual(dom.getTag('tag1'),1,'error with tag1') self.assertEqual(dom.getTag('tag2'),2,'error with tag2') self.assertEqual(dom.getTag('tag3'),3,'error with tag3') self.assertRaises(ValueError, dom.getTag, 'tag4')
def test_gmshTags(self): dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "tagtest.msh"), 2) tags = dom.showTagNames().split(', ') self.assertEqual(tags, ['tag1', 'tag2', 'tag3'], 'error with tags') self.assertEqual(dom.getTag('tag1'), 1, 'error with tag1') self.assertEqual(dom.getTag('tag2'), 2, 'error with tag2') self.assertEqual(dom.getTag('tag3'), 3, 'error with tag3') self.assertRaises(ValueError, dom.getTag, 'tag4')
def test_Tet10(self): file = "tet10_gmsh.msh" ref = "tet10.fly" test = os.path.join(FINLEY_WORKDIR, "tet10_test.fly") dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, file), 3, optimize=False) dom.write(test) self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH, ref))
def test_Tri6_macro(self): file = "tri6_gmsh.msh" ref = "tri6_macro.fly" test = os.path.join(FINLEY_WORKDIR, "tri6_macro_test.fly") dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, file), 2, useMacroElements=True, optimize=False) dom.write(test) self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH, ref))
def test_getPotential3dSchlumberger(self): numElectrodes = 12 directionVector = [1., 0.] midPoint = [] totalApparentResVal = 130. current = 0.5 interval_a = 5 interval_n = 5 if not HAVE_GMSH: raise unittest.SkipTest("gmsh required for test") lc = 10.0 bufferThickness = 100 extents = [200, 200, 200] midPoint = [0, 0] lcDiv = 10.0 electrodes = [] start = [] start.append(midPoint[0] - (( (numElectrodes - 1) * interval_a) / 2. * directionVector[0])) start.append(midPoint[1] - (( (numElectrodes - 1) * interval_a) / 2. * directionVector[1])) electrodeTags = [] electrodeLst = [] for i in range(numElectrodes): electrodes.append([ start[0] + (directionVector[0] * i * interval_a), start[1] + (directionVector[1] * i * interval_a), 0 ]) electrodeTags.append("e%d" % i) runName = os.path.join(WORKDIR, "dcResSchlum%d-%d" % (lc, lc / lcDiv)) filename = os.path.join(TEST_DATA_ROOT, "schlum.geo") meshname = os.path.join(TEST_DATA_ROOT, "dcResSchlum10-1.msh") verbosity = 3 gmshGeo2Msh(filename, meshname, 3, 1, verbosity) dom = ReadGmsh(meshname, 3, diracTags=electrodeTags, diracPoints=electrodes) if mpirank == 0: os.unlink(meshname) primaryConductivity = Scalar(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Scalar(1 / 130., ContinuousFunction(dom)) schs = SchlumbergerSurvey(dom, primaryConductivity, secondaryConductivity, current, interval_a, interval_n, midPoint, directionVector, numElectrodes) potentials = schs.getPotentialAnalytic() totalApparentRes = schs.getApparentResistivity(potentials[2]) for i in totalApparentRes: for j in i: res_a = abs(j - totalApparentResVal) res_b = 0.1 * totalApparentResVal self.assertLess( res_a, res_b, "result of %g greater than tolerance of %g" % (res_a, res_b))
def test_rectReadGmsh(self): fname=os.path.join(FINLEY_TEST_MESH_PATH, 'rect_test.msh') self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0)]) self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40]) self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=["cows"]) z=ReadGmsh(fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40,51]) z=ReadGmsh(fname, 2, diracPoints=[(0,0),(0,1),(1,0),(1,1)], diracTags=["A", "B", "A", "C"]) v=interpolate(z.getX(), DiracDeltaFunctions(z)) if mpisize==1: self.assertEqual(v.toListOfTuples(),[(0,0), (0,1), (1,0), (1,1)]) self.assertEqual(v.getNumberOfDataPoints(), 4) v.setTaggedValue("A",(-10,99)) self.assertEqual(inf(v[0]), -10) self.assertEqual(Lsup(v[1]), 99) v.setTaggedValue(500,(-100,-100)) # non-existant tag self.assertEqual(inf(v[0]), -10) self.assertEqual(Lsup(v[1]), 99) self.assertEqual(z.showTagNames(), 'A, B, C') self.assertEqual(z.getTag("C"), 42)
def test_readgmsh_format(self): print("\n reading format 2..... ") mydomain1 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "Kalgoorlie.2.msh"), numDim=3) print(" reading format 2.2..... ") mydomain2 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "Kalgoorlie.22.msh"), numDim=3) print(" reading format 4.0..... ") mydomain3 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "Kalgoorlie.40.msh"), numDim=3) print(" reading format 4.1..... ") mydomain4 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "Kalgoorlie.41.msh"), numDim=3) print(" comparing ..... ") self.assertTrue(self.domainsEqual(mydomain1, mydomain2), "Failed to read MSH format 2 or 22") self.assertTrue(self.domainsEqual(mydomain1, mydomain3), "Failed to read MSH format 4.0") self.assertTrue(self.domainsEqual(mydomain1, mydomain4), "Failed to read MSH format 4.1")
def test_getpotential3dPolePole(self): structured = False if structured: extents = [1000, 1000, 1000] dom = Brick(50, 50, 50, l0=extents[0], l1=extents[1], l2=-extents[2]) else: extents = [1000, 2000, 2000] tags = [] points = [] tags.append("e1") tags.append("e2") tags.append("e3") tags.append("e4") points.append([-0.4 * extents[0], 0, 0]) points.append([-0.2 * extents[0], 0, 0]) points.append([0.2 * extents[0], 0, 0]) points.append([0.4 * extents[0], 0, 0]) verbosity = 3 filename = os.path.join(TEST_DATA_ROOT, "pole.geo") meshname = os.path.join(TEST_DATA_ROOT, "dcResPolePole50-5.msh") gmshGeo2Msh(filename, meshname, 3, 1, verbosity) dom = ReadGmsh(meshname, 3, diracTags=tags, diracPoints=points) totalApparentRes = 130. primaryConductivity = Scalar(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Scalar(1 / 130., ContinuousFunction(dom)) current = 1000. a = 4 * 0.05 * extents[0] midPoint = [0.5 * extents[0], 0.5 * extents[1]] directionVector = [1., 0.] numElectrodes = 4 pps = PolePoleSurvey(dom, primaryConductivity, secondaryConductivity, current, a, midPoint, directionVector, numElectrodes) delPhi = pps.getPotential() totalApparentResList = pps.getApparentResistivityTotal() for i in totalApparentResList: res_a = abs(i - totalApparentRes) res_b = 0.05 * totalApparentRes self.assertLess( res_a, res_b, "result of %g greater than tolerance of %g" % (res_a, res_b))
def gzpot(p, y, x, *args): #rho, rhox, rhoy, R = p rhox = args[0] / 2. rhoy = args[1] / 2. rho, R, z = p #Domain related. mx = args[0] my = args[1] #PDE related G = 6.67300 * 10E-11 #DOMAIN CONSTRUCTION domain = ReadGmsh('data/example10m/example10m.msh', 2) domx = Solution(domain).getX() mask = wherePositive(R - length(domx - rholoc)) rhoe = rho * mask kro = kronecker(domain) q = whereZero(domx[1] - my) + whereZero(domx[1]) + whereZero( domx[0]) + whereZero(domx[0] - mx) #ESCRIPT PDE CONSTRUCTION mypde = LinearPDE(domain) mypde.setValue(A=kro, Y=4. * np.pi * G * rhoe, q=q, r=0.0) mypde.setSymmetryOn() sol = mypde.getSolution() g_field = grad(sol) #The graviational accelleration g. g_fieldz = g_field * [0, 1] #The vertical component of the g field. gz = length(g_fieldz) #The magnitude of the vertical component. #MODEL SIZE SAMPLING sol_escgz = [] sol_escx = [] for i in range(0, len(x)): sol_escgz.append([x[i], rhoy + z]) sample = [] # array to hold values rec = Locator(gz.getFunctionSpace(), sol_escgz) #location to record psol = rec.getValue(gz) err = np.sum((np.array(y) - np.array(psol))**2.) print("Lsup= ", Lsup(np.array(psol) - np.array(sol_angz)) / Lsup(np.array(psol))) return err
if HAVE_FINLEY: #################################################ESTABLISHING VARIABLES # PDE related rho = 200.0 # the density contrast of the source G = 6.67300 * 10e-11 # gravitational constant R = 100.0 # radius of the source body ################################################ESTABLISHING PARAMETERS # the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example10") mesh_path = "data/example10m" # ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION # Geometric and material property related variables. domain = ReadGmsh(os.path.join(mesh_path, "example10m.msh"), 2) # create the domain x = domain.getX() # Domain related dimensions from the imported file. mx = Lsup(x) * m # meters - model length my = Lsup(x) * m # meters - model width rholoc = [mx / 2, my / 2] mask = wherePositive(R - length(x - rholoc)) rhoe = rho * mask kro = kronecker(domain) # Define the analytic solution. def analytic_gz(x, z, R, drho): G = 6.67300 * 10e-11 return G * 2 * np.pi * R * R * drho * (z / (x * x + z * z))
import os import errno try: os.mkdir('./result/') os.mkdir('./result/gauss') os.mkdir('./result/vtk') os.mkdir('./result/packing') except OSError as exc: if exc.errno != errno.EEXIST: raise pass vel = -0.00025; surcharge=-20.e3; # surcharge equals to the initial vertical stress of the RVE packing dim = 2; B = 0.05; L = 0.6; H = 0.4; mydomain = ReadGmsh('footing.msh',numDim=dim,integrationOrder=2) # read Gmsh mesh with 6-node triangle element (2500 tri6); each element has 3 Gauss points k = kronecker(mydomain) numg = 3*2500; # number of Gauss points nump = 16; # number of processes in multiprocessing packNo=list(range(0,numg,50)) prob = MultiScale(domain=mydomain,ng=numg,np=nump,random=False,rtol=1e-2,usePert=False,pert=-2.e-5,verbose=False) disp = Vector(0.,Solution(mydomain)) t=0 stress = prob.getCurrentStress() proj = Projector(mydomain) sig = proj(stress) sig_bounda = interpolate(sig,FunctionOnBoundary(mydomain)) traction = matrix_mult(sig_bounda,mydomain.getNormal())
else: znew = float(z) fout.write("%s %g %g %g\n" % (i, float(x), float(y), znew)) cc += 1 else: fout.write(line) line = fin.readline() fin.close() fout.close() print("topography added to file %s and written to file %s." % (MSHN1, MSHN2)) # now we are ready to generate the 3D mesh: rp = subprocess.run( ["gmsh", "-3", "-algo", "frontal", "-o", MSHN3, GEOFN2]) rp.check_returncode() print(">> GMSH mesh file %s generated." % MSHN3) if not args.flyno and not args.mshno: dts = [] dps = [] for s in elocations: if config.stationsFMT: dts.append(config.stationsFMT % s) else: dts.append(s) dps.append(elocations[s]) domain = ReadGmsh(MSHN3, 3, diracPoints=dps, diracTags=dts, optimize=True) domain.write(config.meshfile) print("Mesh written to file %s" % (config.meshfile))
if HAVE_FINLEY: #################################################ESTABLISHING VARIABLES #PDE related rho = 200.0 #the density contrast of the source G = 6.67300 * 10E-11 #gravitational constant R = 100. #radius of the source body ################################################ESTABLISHING PARAMETERS #the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example10") mesh_path = "data/example10m" #ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION #Geometric and material property related variables. domain = ReadGmsh(os.path.join(mesh_path, 'example10m.msh'), 2) # create the domain x = domain.getX() #Domain related dimensions from the imported file. mx = Lsup(x) * m #meters - model length my = Lsup(x) * m #meters - model width rholoc = [mx / 2, my / 2] mask = wherePositive(R - length(x - rholoc)) rhoe = rho * mask kro = kronecker(domain) #Define the analytic solution. def analytic_gz(x, z, R, drho): G = 6.67300 * 10E-11 return G * 2 * np.pi * R * R * drho * (z / (x * x + z * z))
print("** This is an ERT inversion @ %s **"%datetime.now().strftime("%d.%m.%Y %H:%M")) print("configuration "+args.config+" imported.") elocations=readElectrodeLocations(config.stationfile, delimiter=config.stationdelimiter) if getMPIRankWorld() == 0: print("%s electrode locations read from %s."%(len(elocations), config.stationfile)) if config.stationsFMT: dts=[ config.stationsFMT%s for s in elocations] else: dts=[ s for s in elocations] if os.path.splitext(config.meshfile)[1] == ".msh" : domain=ReadGmsh(config.meshfile, 3, diracPoints=[ elocations[s] for s in elocations], diracTags=dts, optimize=True ) else: if args.addStations: domain=ReadMesh(config.meshfile, diracPoints=[ elocations[s] for s in elocations], diracTags=dts, optimize=True ) else: domain=ReadMesh(config.meshfile) if getMPIRankWorld() == 0: print("Mesh read from "+config.meshfile) survey=readSurveyData(config.datafile, stations=elocations, usesStationCoordinates=config.usesStationCoordinates, columns=config.datacolumns, dipoleInjections=config.dipoleInjections, dipoleMeasurements=config.dipoleMeasurements, delimiter=config.datadelimiter, commend='#', printInfo=args.debug) assert survey.getNumObservations()>0, "no data found." # set the reference conductivity:
def test_getPotentialPolDip(self): structured = False totalApparentRes = 130. if structured: extents = [100, 100, 100] dom = Brick(25, 25, 25, l0=extents[0], l1=extents[1], l2=-extents[2]) else: if not HAVE_GMSH: raise unittest.SkipTest("gmsh required for test") extents = [100, 100, 100] electrodes = [] tags = [] tags.append("e0") tags.append("e1") tags.append("e2") tags.append("e3") tags.append("e4") tags.append("e5") tags.append("e6") tags.append("e7") tags.append("e8") tags.append("e9") tags.append("e10") tags.append("e11") electrodes.append([-22.0, 0.0, 0]) electrodes.append([-18.0, 0.0, 0]) electrodes.append([-14.0, 0.0, 0]) electrodes.append([-10.0, 0.0, 0]) electrodes.append([-6.0, 0.0, 0]) electrodes.append([-2.0, 0.0, 0]) electrodes.append([2.0, 0.0, 0]) electrodes.append([6.0, 0.0, 0]) electrodes.append([10.0, 0.0, 0]) electrodes.append([14.0, 0.0, 0]) electrodes.append([18.0, 0.0, 0]) electrodes.append([22.0, 0.0, 0]) filename = os.path.join(TEST_DATA_ROOT, "dip.geo") meshname = os.path.join(TEST_DATA_ROOT, "dcRespoldip10-1.msh") verbosity = 3 gmshGeo2Msh(filename, meshname, 3, 1, verbosity) dom = ReadGmsh(meshname, 3, diracTags=tags, diracPoints=electrodes) if mpirank == 0: os.unlink(meshname) n = 5 totalApparentResVal = 130. primaryConductivity = Scalar(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Scalar(1 / 130., ContinuousFunction(dom)) current = 1000. numElectrodes = 12 # a=(.8*extents[0])/numElectrodes a = 4 midPoint = [0, 0] directionVector = [1., 0.] poldips = PoleDipoleSurvey(dom, primaryConductivity, secondaryConductivity, current, a, n, midPoint, directionVector, numElectrodes) poldips.getPotential() primaryApparentRes = poldips.getApparentResistivityPrimary() SecondaryApparentRes = poldips.getApparentResistivitySecondary() totalApparentRes = poldips.getApparentResistivityTotal() for i in totalApparentRes: for j in i: res_a = abs(j - totalApparentResVal) res_b = 0.1 * totalApparentResVal self.assertLess( res_a, res_b, "result of %g greater than tolerance of %g" % (res_a, res_b))
# import FE-DE mapping of boundary node IDs FEDENodeMap = numpy.load(sceneExt+'FEDENodeMap'+mshName+'.npy').item() # state filename of initial membrane DE elements DE_ext = './DE_exts/Test2/DE_ext_'+mshName+'.yade.gz' # surcharnge pressure on FE top boundary surcharge=-2.e4 # file to write force on the bottom graphDir = './result/graphs/msTest2_Explicit/gp'+str(gp)+'/' fout=file(graphDir+'safe_%1.1f_'%safe+'t_%1.1f_'%duration+mshName+'_quasi.dat','w') ################### ## model setup ## ################### # multiscale model description dom = ReadGmsh(mshName[:8]+'.msh',numDim=dim,integrationOrder=2) prob = MultiScale(domain=dom,dim=dim,ng=numg,np=nump,rho=rho,\ mIds=mIds,FEDENodeMap=FEDENodeMap,DE_ext=DE_ext) # nodal coordinate dom = prob.getDomain() x = dom.getX() bx = FunctionOnBoundary(dom).getX() # Dirichlet BC positions, smooth lateral boundary Dbc = whereZero(x[0])*[1,0] + whereZero(x[0]-lx)*[1,0] \ #~ +whereZero(x[0]-lx)*whereZero(x[1])*[0,1] # Dirichlet BC values Dbc_val = whereZero(x[0])*[0,0] + whereZero(x[0]-lx)*[0,0] \ #~ +whereZero(x[0]-lx)*whereZero(x[1])*[0,0]
from esys.escript import * from esys.weipa import saveVTK, saveSilo from esys.escript.linearPDEs import LinearSinglePDE, SolverOptions from esys.finley import ReadGmsh from esys.escript.pdetools import Locator print("read in mesh") domain = ReadGmsh("simplemesh.msh", 3, optimize=True) pde = LinearSinglePDE(domain, isComplex=False) pde.setSymmetryOn() x = domain.getX() pde.setValue(A=kronecker(3), Y=1, q=whereZero(x[0] - inf(x[0]))) options = pde.getSolverOptions() options.setPackage(SolverOptions.TRILINOS) options.setSolverMethod(SolverOptions.PCG) options.setPreconditioner(SolverOptions.AMG) options.setTrilinosParameter("multigrid algorithm", "sa") options.setTrilinosParameter("sa: damping factor", 1.3) options.setTrilinosParameter("max levels", 10) options.setTrilinosParameter("coarse: max size", 2000) options.setTrilinosParameter("coarse: type", "SuperLU") options.setTrilinosParameter("verbosity", "low") print("solve pde") u = pde.getSolution() saveSilo("asimple", u=u) print("finished")
def test_gmshNamedTags(self): dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "test_Add.msh"), 3) sigma = Scalar(0, Function(dom)) sigma.expand() sigma.setTaggedValue("v5", 10) self.assertEqual(Lsup(sigma), 10.0, "Named value not set properly")