def test_brickReadMesh(self): fname=os.path.join(FINLEY_TEST_MESH_PATH,'brick_4x4x4.fly') self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0)]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0)]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"]) z=ReadMesh(fname, diracPoints=[(0,0,1), (0.25,0.25, 0.25)], diracTags=[40,51]) z=ReadMesh(fname, diracPoints=[(0.125,0.625,0), (0.5,1,1), (0.75, 0.25,0), (0.89, 0.875, 0.5)], diracTags=["A", "B", "A", "C"]) v=interpolate(z.getX(), DiracDeltaFunctions(z)) if mpisize==1: self.assertEqual(v.toListOfTuples(),[(0.0, 0.5, 0.0), (0.5, 1.0, 1.0), (0.75, 0.25, 0.0), (1.0, 0.75, 0.5)]) self.assertEqual(v.getNumberOfDataPoints(), 4) self.assertEqual(inf(v[0]), 0) self.assertEqual(inf(v[1]), 0.25) self.assertEqual(Lsup(v[0]), 1) self.assertEqual(Lsup(v[1]), 1) v.setTaggedValue("A",(-10,0.5,-0.5)) if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) self.assertEqual(inf(v[2]), -0.5) v.setTaggedValue(500,(-100,-100, -100)) # non-existant tag if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) self.assertEqual(inf(v[2]), -0.5) self.assertEqual(z.showTagNames(), 'A, B, C, back, bottom, front, left, right, top') self.assertEqual(z.getTag("C"), 203)
def test_brickReadMesh(self): fname=os.path.join(FINLEY_TEST_MESH_PATH,'brick_4x4x4.fly') self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0)]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0)]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40]) self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"]) z=ReadMesh(fname, diracPoints=[(0,0,1), (0.25,0.25, 0.25)], diracTags=[40,51]) z=ReadMesh(fname, diracPoints=[(0.125,0.625,0), (0.5,1,1), (0.75, 0.25,0), (0.89, 0.875, 0.5)], diracTags=["A", "B", "A", "C"]) v=interpolate(z.getX(), DiracDeltaFunctions(z)) if mpisize==1: self.assertEqual(v.toListOfTuples(),[(0.0, 0.5, 0.0), (0.5, 1.0, 1.0), (0.75, 0.25, 0.0), (1.0, 0.75, 0.5)]) self.assertEqual(v.getNumberOfDataPoints(), 4) self.assertEqual(inf(v[0]), 0) self.assertEqual(inf(v[1]), 0.25) self.assertEqual(Lsup(v[0]), 1) self.assertEqual(Lsup(v[1]), 1) v.setTaggedValue("A",(-10,0.5,-0.5)) if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) self.assertEqual(inf(v[2]), -0.5) v.setTaggedValue(500,(-100,-100, -100)) # non-existant tag if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) self.assertEqual(inf(v[2]), -0.5) self.assertEqual(z.showTagNames(), 'A, B, C, back, bottom, front, left, right, top') self.assertEqual(z.getTag("C"), 203)
def test_mesh_read_rectangle_from_finley_file(self): mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False) mydomain2 = ReadMesh( os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly")) self.domainsEqual(mydomain1, mydomain2)
def test_flyTags(self): dom = ReadMesh( os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly")) tags = sorted(dom.showTagNames().split(', ')) self.assertEqual(tags, sorted(['top', 'bottom', 'left', 'right'])) self.assertEqual(dom.getTag('top'), 20, 'error with top') self.assertEqual(dom.getTag('bottom'), 10, 'error with bottom,') self.assertEqual(dom.getTag('left'), 1, 'error with left') self.assertEqual(dom.getTag('right'), 2, 'error with reight') self.assertRaises(ValueError, dom.getTag, 'tag4')
def test_mesh_read_brick_from_finley_file(self): mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False) mydomain2 = ReadMesh( os.path.join(FINLEY_TEST_MESH_PATH, "brick_8x10x12.fly")) self.domainsEqual(mydomain1, mydomain2)
def test_flyTags(self): dom=ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly")) tags=sorted(dom.showTagNames().split(', ')) self.assertEqual(tags,sorted(['top', 'bottom', 'left', 'right'])) self.assertEqual(dom.getTag('top'),20,'error with top') self.assertEqual(dom.getTag('bottom'),10,'error with bottom,') self.assertEqual(dom.getTag('left'),1,'error with left') self.assertEqual(dom.getTag('right'),2,'error with reight') self.assertRaises(ValueError, dom.getTag, 'tag4')
def test_ReadWriteTagNames(self): file = "hex_2D_order2.msh" test = os.path.join(FINLEY_WORKDIR, "test.fly") dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, file), 3, optimize=False) insertTagNames(dom, A=1, B=2) dom.write(test) dom2 = ReadMesh(test, 3, optimize=False) t = getTagNames(dom) self.assertTrue(len(t) == 6) self.assertTrue("A" in t) self.assertTrue("B" in t) self.assertTrue(dom2.getTag("A") == 1) self.assertTrue(dom2.getTag("B") == 2) self.assertTrue(dom2.isValidTagName("A")) self.assertTrue(dom2.isValidTagName("B"))
def test_ReadWriteTagNames(self): file="hex_2D_order2.msh" test = os.path.join(FINLEY_WORKDIR,"test.fly") dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,file),3,optimize=False) insertTagNames(dom,A=1,B=2) dom.write(test) dom2 = ReadMesh(test,3,optimize=False) t=getTagNames(dom) self.assertTrue(len(t)==6) self.assertTrue("A" in t) self.assertTrue("B" in t) self.assertTrue(dom2.getTag("A") == 1) self.assertTrue(dom2.getTag("B") == 2) self.assertTrue(dom2.isValidTagName("A")) self.assertTrue(dom2.isValidTagName("B"))
# Parameter # DIM = 2 MESHFILE = "sub.fly" ETA = 1.e22 * U.Pa * U.sec V_MAX = 1. * U.cm / U.yr ALPHA = 30 * U.DEG STRIKE = 10 * U.DEG DIP = 30 * U.DEG N = 1 # boudary layer control g = 9.81 * U.m / U.sec**2 # # derived values # dom = ReadMesh(MESHFILE) DIM = dom.getDim() bb = boundingBox(dom) LX = bb[0][1] - bb[0][0] if DIM == 3: LY = bb[1][1] - bb[1][0] DEPTH = bb[DIM - 1][1] - bb[DIM - 1][0] sc = StokesProblemCartesian(dom) x = dom.getX() # v = Vector(0., Solution(dom)) mask = Vector(0., Solution(dom)) # # in subduction zone: #
#PDE related res1 = 500.0 res2 = 10.0 res3 = 1000.0 res4 = 10000.0 #con=1/res cur = 1000. ################################################ESTABLISHING PARAMETERS #the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example11") #ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION domain = ReadMesh(os.path.join(save_path, 'example11lc.fly')) # create the domain res = Scalar(0, Function(domain)) res.setTaggedValue("volume_0", res1) res.setTaggedValue("volume_1", res2) res.setTaggedValue("volume_2", res3) res.setTaggedValue("volume_3", res4) con = 1 / res x = Solution(domain).getX() kro = kronecker(domain) source1 = [3. * mx / 8., my / 2, 0] source2 = [5. * mx / 8., my / 2, 0] c1 = length(exp(-length(x - source1) / (10.))) c1 = c1 / integrate(c1)
# DIM=2 MESHFILE="sub.fly" ETA=1.e22*U.Pa*U.sec V_MAX=1.*U.cm/U.yr ALPHA=30*U.DEG STRIKE=10*U.DEG DIP=30*U.DEG N=1 # boudary layer control g=9.81*U.m/U.sec**2 # # derived values # dom=ReadMesh(MESHFILE) DIM=dom.getDim() bb=boundingBox(dom) LX=bb[0][1]-bb[0][0] if DIM == 3: LY=bb[1][1]-bb[1][0] DEPTH=bb[DIM-1][1]-bb[DIM-1][0] sc=StokesProblemCartesian(dom) x = dom.getX() # v=Vector(0.,Solution(dom)) mask=Vector(0.,Solution(dom)) # # in subduction zone: #
def setUp(self): self.domain = ReadMesh( os.path.join(FINLEY_TEST_MESH_PATH, "mesh_3Do2_Contact.fly"))
This script can run under MPI. """ MESH_DIRECTORY = "./tmp_meshes" from esys.escript import * from esys.finley import ReadMesh import os for root, dirs, files in os.walk(MESH_DIRECTORY, topdown=False): for name in files: f = name.split(".") if f[0].startswith("mesh_") and f[-1] == "fly": print("Reading " + os.path.join(MESH_DIRECTORY, name)) dom = ReadMesh(os.path.join(MESH_DIRECTORY, name), optimize=True) for fs_name in [ "ContinuousFunction", "Solution", "Function", "FunctionOnBoundary", "FunctionOnContactZero", "FunctionOnContactOne", "ReducedContinuousFunction", "ReducedSolution", "ReducedFunction", "ReducedFunctionOnBoundary", "ReducedFunctionOnContactZero", "ReducedFunctionOnContactOne" ]: if fs_name == "ContinuousFunction": fs = ContinuousFunction(dom) if fs_name == "Solution": fs = Solution(dom) if fs_name == "Function": fs = Function(dom)
def run(self): # material parameter lam = self.prms.lameLambda mu = self.prms.lameMu rho = self.prms.density nu = self.prms.viscosity # set up boundary conditions pres = self.prms.pressure shear = self.prms.shearForce getLogger().info("Reading mesh from " + self.getMeshFileName()) domain = ReadMesh(self.getMeshFileName()) impact_forces = escript.Vector(0, FunctionOnBoundary(domain)) impact_forces.expand() getLogger().info("Shape = " + str(impact_forces.getShape())) x = FunctionOnBoundary(domain).getX() getLogger().info( "Initialising pressure and shearing boundary conditions...") snapDist = 0.001 external_forces = \ (abs(x[1]-sup(x[1]))-snapDist).whereNegative()*[-shear,-pres] \ + \ (abs(x[1]-inf(x[1]))-snapDist).whereNegative()*[shear,pres] getLogger().info("Setting up PDE...") mypde = LinearPDE(domain) mypde.setLumpingOn() mypde.setValue(D=rho * identity(mypde.getDim())) getLogger().info("Initialising solution at t=0...") u = Vector(0, ContinuousFunction(domain)) u_last = Vector(0, ContinuousFunction(domain)) v = Vector(0, ContinuousFunction(domain)) v_last = Vector(0, ContinuousFunction(domain)) a = Vector(0, ContinuousFunction(domain)) a_last = Vector(0, ContinuousFunction(domain)) # initialise iteration prms tend = self.prms.maxTime dt = self.prms.timeStepSize # dt=1./5.*sqrt(rho/(lam+2*mu))*Lsup(domain.getSize()) getLogger().info("time step size = " + str(dt)) n = 0 t = 0 getLogger().info("Beginning iteration...") while (t < tend): getLogger().info("Running LSM time step...") self.lsm.runTimeStep() getLogger().info("Updating impact forces from LSM...") self.updateImpactStresses(impact_forces) getLogger().info( "(inf(impactForces), sup(impact_forces)) = (" + \ str(inf(impact_forces)) + ", " + str(sup(impact_forces)) + ")" ) # ... update FEM ... getLogger().info("Initialising PDE coefficients...") g = grad(u) stress = (lam * trace(g)) * identity( mypde.getDim()) + mu * (g + transpose(g)) mypde.setValue(X=-(1.0 / (1.0 + (nu * dt / 2.0))) * stress, Y=-nu * v_last - (nu * dt / 2.0) * a_last, y=external_forces + impact_forces) getLogger().info("Solving PDE...") a = mypde.getSolution() getLogger().info("Updating displacements...") # u_new=2*u-u_last+dt**2*a # u_last=u # u=u_new v_new = v_last + (dt / 2.0) * (a + a_last) v_last = v v = v_new u_new = u_last + dt * v + ((dt**2) / 2.0) * a u_last = u u = u_new a_last = a getLogger().info("Updating LSM mesh node positions...") displacement = u - u_last self.updateLsmMeshPosn(displacement) t += dt n += 1 getLogger().info(str(n) + "-th time step, t=" + str(t)) getLogger().info("a=" + str(inf(a)) + ", " + str(sup(a))) getLogger().info("u=" + str(inf(u)) + ", " + str(sup(u))) getLogger().info("inf(u-u_last) = " + str(inf(displacement))) getLogger().info("sup(u-u_last) = " + str(sup(displacement))) # ... save current acceleration and displacement if ((self.prms.saveDxIncr > 0) and ((n % self.prms.saveDxIncr) == 0)): u.saveDX( os.path.join( self.prms.outputDir, "displ.{0:d}.dx".format(n // self.prms.saveDxIncr)))
def setUp(self): self.domain = ReadMesh( os.path.join(FINLEY_TEST_MESH_PATH, "mesh_3Do2_Contact_withElementsOnFace.fly"))
# print "p:",inf(p),sup(p) # print "u:",inf(u),sup(u) self.__pde_u.setValue(y_contact=-p) return self.__pde_u.getSolution() def solve_g(self,u,tol=1.e-8): dp=Vector(0.,FunctionOnContactZero(self.domain)) h=FunctionOnContactZero(self.domain).getSize() # print jump(u)-self.slip dp[0]=(self.slip[0]-jump(u[0]))*lam_mu/h dp[1]=(self.slip[1]-jump(u[1]))*lam_mu/h dp[2]=(self.slip[2]-jump(u[2]))*lam_mu/h return dp dom=ReadMesh("meshfault3D.fly",integrationOrder=-1) prop=SlippingFault(dom) d=dom.getDim() x=dom.getX()[0] # x=dom.getX()[d-1] mask=whereZero(x-inf(x))*numpy.ones((d,)) x=FunctionOnContactZero(dom).getX() s=numpy.array([-100000.,1.,1.]) for i in range(3): d=fend[i]-fstart[i] if d>0: q=(x[i]-fstart[i])/d s=q*(1-q)*4*s elif d<0: q=(x[i]-fend[i])/d s=q*(1-q)*4*s
def test_Tet3D_order1_integorder4(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tet4.fly"), optimize=False, integrationOrder=4) self.__test_3DT(my_dom, 4)
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: if isinstance(config.sigma0, dict): sigma0=Scalar(config.sigma_background,Function(domain)) for k in config.sigma0: sigma0.setTaggedValue(k, config.sigma0[k])
def test_Tet3D_macro_integorder5(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tet10_macro.fly"), optimize=False, integrationOrder=5) self.__test_3DT(my_dom, 5)
if getMPISizeWorld() > 1: print("This example will not run in an MPI world.") sys.exit(0) if HAVE_FINLEY: #################################################ESTABLISHING VARIABLES G = 6.67300 * 10E-11 ################################################ESTABLISHING PARAMETERS #the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example10") #ensure the dir exists mkDir(save_path) ####################################################DOMAIN CONSTRUCTION domain = ReadMesh(os.path.join(save_path, 'fault.fly')) # create the domain x = Solution(domain).getX() rho = Scalar(0, Function(domain)) rho.setTaggedValue("xx", 500.) rho.setTaggedValue("limestone", 0.0) rho.setTaggedValue("fault", 1200.) kro = kronecker(domain) q = whereZero(x[2]) #-sup(x[2])) ###############################################ESCRIPT PDE CONSTRUCTION mypde = LinearPDE(domain) mypde.setValue(A=kro, Y=4. * 3.1415 * G * rho, q=q, r=0) sol = mypde.getSolution() saveVTK(os.path.join(save_path,"ex10c.vtu"),\
# print "p:",inf(p),sup(p) # print "u:",inf(u),sup(u) self.__pde_u.setValue(y_contact=-p) return self.__pde_u.getSolution() def solve_g(self, u, tol=1.e-8): dp = Vector(0., FunctionOnContactZero(self.domain)) h = FunctionOnContactZero(self.domain).getSize() # print jump(u)-self.slip dp[0] = (self.slip[0] - jump(u[0])) * lam_mu / h dp[1] = (self.slip[1] - jump(u[1])) * lam_mu / h dp[2] = (self.slip[2] - jump(u[2])) * lam_mu / h return dp dom = ReadMesh("meshfault3D.fly", integrationOrder=-1) prop = SlippingFault(dom) d = dom.getDim() x = dom.getX()[0] # x=dom.getX()[d-1] mask = whereZero(x - inf(x)) * numpy.ones((d, )) x = FunctionOnContactZero(dom).getX() s = numpy.array([-100000., 1., 1.]) for i in range(3): d = fend[i] - fstart[i] if d > 0: q = (x[i] - fstart[i]) / d s = q * (1 - q) * 4 * s elif d < 0: q = (x[i] - fend[i]) / d s = q * (1 - q) * 4 * s
print("Finley module not available") HAVE_FINLEY = False ########################################################MPI WORLD CHECK if getMPISizeWorld() > 1: import sys print("This example will not run in an MPI world.") sys.exit(0) if HAVE_FINLEY: #################################################ESTABLISHING VARIABLES # where to save output data savepath = "data/example09c" meshpath = "data/example09n" mkDir(savepath) #Geometric and material property related variables. domain=ReadMesh(os.path.join(savepath,'example09n.fly')) # create the domain x=Solution(domain).getX() #parameters layers 1,2,3,4 and fault prho=np.array([2200.,2500.,3200.,4500.,5500.]) #density pvel=np.array([1500.,2200.,3000.,3200.,5000.]) #velocity pmu=pvel**2.*prho/4. #bulk modulus plam=pvel**2.*prho/2. #lames constant nlayers=4 width=300.0 rho=Scalar(0,Function(domain)) vel=Scalar(0,Function(domain)) mu=Scalar(0,Function(domain)) lam=Scalar(0,Function(domain)) print(0.5*np.sqrt(prho/(plam+2*pmu))*0.5)
def setUp(self): self.order = 1 self.domain = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tet_3D_macro.fly"), optimize=False)
def setUp(self): self.domain = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"tet_3D_order2.fly"),optimize=True) self.order = 2
ampmax = 0 for it in range(0, ls): t = it * h tt = t - t0 dum1 = np.exp(-a * tt * tt) source[it] = -2. * a * tt * dum1 if (abs(source[it]) > ampmax): ampmax = abs(source[it]) time[it] = t * h # will introduce a spherical source at middle left of bottom face xc = [mx / 2, my / 2, 0] ####################################################DOMAIN CONSTRUCTION domain = ReadMesh(os.path.join(meshpath, 'example09lc.fly')) # create the domain x = domain.getX() # get the locations of the nodes in the domain lam = Scalar(0, Function(domain)) mu = Scalar(0, Function(domain)) rho = Scalar(0, Function(domain)) #Setting parameters for each layer in the model. for i in range(0, nlayers): rho.setTaggedValue("volume_%d" % i, rhoc + i * 100.) lamc = (vel + i * 100.)**2. * (rhoc + i * 100.) / 2. muc = (vel + i * 100.)**2. * (rhoc + i * 100.) / 4. lam.setTaggedValue("volume_%d" % i, lamc) mu.setTaggedValue("volume_%d" % i, muc) ##########################################################ESTABLISH PDE
def test_Tet2D_order2_integorder8(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tri6.fly"), optimize=False, integrationOrder=8) self.__test_2DT(my_dom, 8, 1. / sqrt(EPSILON))
def test_Tet3D_order2_integorder9(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tet10.fly"), optimize=False, integrationOrder=9) self.__test_3DT(my_dom, 9, 1. / sqrt(EPSILON))
def test_Tet2D_macro_integorder10(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tri6_macro.fly"), optimize=False, integrationOrder=10) self.__test_2DT(my_dom, 10)
def test_Tet3D_macro_integorder10(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tet10_macro.fly"), optimize=False, integrationOrder=10) self.__test_3DT(my_dom, 10, 1. / sqrt(EPSILON))
ampmax=0 for it in range(0,ls): t = it*h tt = t-t0 dum1 = np.exp(-a * tt * tt) source[it] = -2. * a * tt * dum1 if (abs(source[it]) > ampmax): ampmax = abs(source[it]) time[it]=t*h # will introduce a spherical source at middle left of bottom face xc=[mx/2,my/2,0] ####################################################DOMAIN CONSTRUCTION domain=ReadMesh(os.path.join(meshpath,'example09lc.fly')) # create the domain x=domain.getX() # get the locations of the nodes in the domain lam=Scalar(0,Function(domain)) mu=Scalar(0,Function(domain)) rho=Scalar(0,Function(domain)) #Setting parameters for each layer in the model. for i in range(0,nlayers): rho.setTaggedValue("volume_%d"%i,rhoc+i*100.) lamc=(vel+i*100.)**2.*(rhoc+i*100.)/2. muc=(vel+i*100.)**2.*(rhoc+i*100.)/4. lam.setTaggedValue("volume_%d"%i,lamc) mu.setTaggedValue("volume_%d"%i,muc) ##########################################################ESTABLISH PDE
def test_Tet2D_order1_integorder7(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tri3.fly"), optimize=False, integrationOrder=7) self.__test_2DT(my_dom, 7)
import argparse from fingal import makeTagField parser = argparse.ArgumentParser( description='creates a silo/vtk file from fly.') parser.add_argument(dest='meshfile', metavar='meshfile', type=str, help='fly file') parser.add_argument('--silo', '-s', dest='silo', metavar='SILO', help="silo file to write.") parser.add_argument('--vtk', '-v', dest='vtk', metavar='SILO', help="vtk file to write.") args = parser.parse_args() domain = ReadMesh(args.meshfile) print("mesh read from " + args.meshfile) if args.silo is not None: saveSilo(args.silo, tag=makeTagField(ReducedFunction(domain))) print(args.silo + ".silo with tags has been generate") if args.vtk is not None: saveSilo(args.vtk, tag=makeTagField(ReducedFunction(domain))) print(args.vtk + ".vtk with tags has been generated.")
def test_Tet2D_macro_integorder9(self): my_dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "tri6_macro.fly"), optimize=False, integrationOrder=9) self.__test_2DT(my_dom, 9, 1. / sqrt(EPSILON))
useFields = False if any([s.find("ERR") >= 0 for s in config.datacolumns]): assert args.noise, 'Noise level must be positive.' addError = True else: addError = args.noise > 0 if getMPIRankWorld() == 0: print("configuration " + args.config + " imported.") print(f"Data columns to be generated: {config.datacolumns}") if usePotentials: print("Potential based data are generated.") if useFields: print("Electric field based data are generated.") if addError: print(f"Error of {args.noise}% is added to data.") domain = ReadMesh(config.meshfile) if getMPIRankWorld() == 0: print("mesh read from " + config.meshfile) elocations = readElectrodeLocations(config.stationfile, delimiter=config.stationdelimiter) if getMPIRankWorld() == 0: print("%s electrode locations read from %s." % (len(elocations), config.stationfile)) survey = readSurveyData(config.schedulefile, stations=elocations, usesStationCoordinates=config.usesStationCoordinates, columns=[], dipoleInjections=config.dipoleInjections, dipoleMeasurements=config.dipoleMeasurements, delimiter=config.datadelimiter,
fly.write("Tags\n") fly.close() mph.close() print("escript file %s generated." % (args.fly)) if args.points: nodes = diracpoints['nodes'] tags = diracpoints['tags'] f = open(args.points, 'w') for k in range(len(tags)): idx = nodes[k][0] x = nodesX[idx, :] if sdim == 2: f.write("%d %g %g %g\n" % (tags[k], x[0], x[1], 0.)) else: f.write("%d %g %g %g\n" % (tags[k], x[0], x[1], x[2])) f.close() print("source points have been written to " + args.points) if args.silofile is not None: mesh = ReadMesh(args.fly) saveSilo(args.silofile, tags=makeTagField(ReducedFunction(mesh))) print(args.silofile + ".silo with tags has been generated.") if args.points: print( "***WARNING: in COMSOL tags/ids for geometrical node IDs for sources are shown with an offset by 1 to the qIDs in the file. " )
parser.add_argument('--debug', '-d', dest='debug', action='store_true', default=False, help="shows more information.") args = parser.parse_args() logger=logging.getLogger('inv') if args.debug: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) config = importlib.import_module(args.config) if getMPIRankWorld() == 0: print("** This is an ERT/IP inversion using field intensity data @ %s **"%datetime.now().strftime("%d.%m.%Y %H:%M")) print("configuration "+args.config+" imported.") domain=ReadMesh(config.meshfile) if getMPIRankWorld() == 0: print("mesh read from "+config.meshfile) elocations=readElectrodeLocations(config.stationfile, delimiter=config.stationdelimiter) if getMPIRankWorld() == 0: print("%s electrode locations read from %s."%(len(elocations), config.stationfile)) survey=readSurveyData(config.datafile, stations=elocations, usesStationCoordinates=config.usesStationCoordinates, columns=config.datacolumns, dipoleInjections=config.dipoleInjections, dipoleMeasurements=False, delimiter=config.datadelimiter, commend='#', printInfo=args.debug) assert survey.getNumObservations()>0, "no data found." # define region with fixed conductivity: if isinstance(config.region_fixed , list): fixedm=MaskFromTag(domain, *tuple(config.region_fixed)) if len(config.region_fixed)> 0 and getMPIRankWorld() == 0: