def test_hex_contact_3D_order2_onFace(self): file="hex_contact_3D_order2_onFace.msh" ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True) ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True) ms2.setX(ms2.getX()+[0,0,0.5]) my_dom=JoinFaces([ms1,ms2],optimize=False) self.checker(my_dom,file)
def test_brickconstr(self): self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0)]) self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40]) self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40]) self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"]) self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0)], diracTags=["test"]) z=Brick(4,4, diracPoints=[(0,0,0), (0.25,0.25, 0.25)], diracTags=[40,51]) z=Brick(4,4, diracPoints=[(0.125,0.625,0), (0.5,1,0), (0.75, 0.25, 0.51), (0.89, 0.875,1)], 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, 0.0), (0.75, 0.25, 1), (1.0, 0.75, 1.0)]) 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,-500)) if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) self.assertEqual(inf(v[2]),-500) 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(z.showTagNames(), 'A, B, C, back, bottom, front, left, right, top') self.assertEqual(z.getTag("C"), 42)
def test_data_dump_to_NetCDF_brick(self): mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False) d1=Data(mydomain1.getMPIRank(), Function(mydomain1)) d1.expand() dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc") d1.dump(dumpfile) d2=load(dumpfile, mydomain1) self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
def setUp(self): self.order = 2 d1 = Brick(n0=NE // 2, n1=NE, n2=NE, l0=0.5, order=2, useElementsOnFace=True) d2 = Brick(n0=NE // 2 + 1, n1=NE, n2=NE, l0=0.5, order=2, useElementsOnFace=True) d2.setX(d2.getX() + [0.5, 0.0, 0.0]) if getMPISizeWorld() > 1: with self.assertRaises(NotImplementedError) as pkg: self.domain = JoinFaces([d1, d2], optimize=False) e = pkg.exception if FINLEY_MERGE_ERROR not in str(e): raise e raise unittest.SkipTest(FINLEY_MERGE_ERROR) else: self.domain = JoinFaces([d1, d2], optimize=False)
def test_hex_3D_order2(self): file = "hex_3D_order1_macro.msh" my_dom = Brick(1, 1, 1, -1, useElementsOnFace=0) self.checker(my_dom, file)
def test_hex3D_order1_integorder10(self): NE = getMPIRankWorld() my_dom = Brick(NE, NE, NE, integrationOrder=10) self.__test_3DQ(my_dom, 10)
def setUp(self): self.order = 1 self.domain = Brick(n0=NE, n1=NE, n2=NE, order=-1, useElementsOnFace=0)
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.BICGSTAB self.preconditioner = SolverOptions.JACOBI
def getDomain(): """ this defines a dom as a brick of length and width l and hight h """ global netotal v_p = {} for tag in sorted(rho_tab.keys()): v_p[tag] = sqrt((2 * mu_tab[tag] + lmbd_tab[tag]) / rho_tab[tag]) v_p_ref = min(v_p.values()) print( "velocities: bedrock = %s, sand = %s, water =%s, absorber =%s, reference =%s" % (v_p[bedrock], v_p[sand], v_p[water], v_p[absorber], v_p_ref)) sections = {} sections["x"] = [ d_absorber, x_sand, l_sand, l_x_water, l_sand, l - x_sand - 2 * l_sand - l_x_water, d_absorber ] sections["y"] = [ d_absorber, y_sand, l_sand, l_y_water, l_sand, l - y_sand - 2 * l_sand - l_y_water, d_absorber ] sections["z"] = [d_absorber, h - h_water - h_sand, h_sand, h_water] if output: print("sections x = ", sections["x"]) print("sections y = ", sections["y"]) print("sections z = ", sections["z"]) mats = [[ [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ], [[ absorber, absorber, absorber, absorber, absorber, absorber, absorber ], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [ absorber, absorber, absorber, absorber, absorber, absorber, absorber ]], [[ absorber, absorber, absorber, absorber, absorber, absorber, absorber ], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, sand, sand, sand, bedrock, absorber], [absorber, bedrock, sand, sand, sand, bedrock, absorber], [absorber, bedrock, sand, sand, sand, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [ absorber, absorber, absorber, absorber, absorber, absorber, absorber ]], [[ absorber, absorber, absorber, absorber, absorber, absorber, absorber ], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [absorber, bedrock, sand, sand, sand, bedrock, absorber], [absorber, bedrock, sand, water, sand, bedrock, absorber], [absorber, bedrock, sand, sand, sand, bedrock, absorber], [absorber, bedrock, bedrock, bedrock, bedrock, bedrock, absorber], [ absorber, absorber, absorber, absorber, absorber, absorber, absorber ]]] num_elem = {} for d in sections: num_elem[d] = [] for i in range(len(sections[d])): if d == "x": v_p_min = v_p[mats[0][0][i]] for q in range(len(sections["y"])): for r in range(len(sections["z"])): v_p_min = min(v_p[mats[r][q][i]], v_p_min) elif d == "y": v_p_min = v_p[mats[0][i][0]] for q in range(len(sections["x"])): for r in range(len(sections["z"])): v_p_min = min(v_p[mats[r][i][q]], v_p_min) elif d == "z": v_p_min = v_p[mats[i][0][0]] for q in range(len(sections["x"])): for r in range(len(sections["y"])): v_p_min = min(v_p[mats[i][r][q]], v_p_min) num_elem[d].append( max(1, int(sections[d][i] * v_p_ref / v_p_min / resolution + 0.5))) ne_x = sum(num_elem["x"]) ne_y = sum(num_elem["y"]) ne_z = sum(num_elem["z"]) netotal = ne_x * ne_y * ne_z if output: print("grid : %s x %s x %s (%s elements)" % (ne_x, ne_y, ne_z, netotal)) dom = Brick(ne_x, ne_y, ne_z, l0=o * ne_x, l1=o * ne_y, l2=o * ne_z, order=o) x_old = dom.getX() x_new = 0 for d in sections: if d == "x": i = 0 f = [1, 0, 0] if d == "y": i = 1 f = [0, 1, 0] if d == "z": i = 2 f = [0, 0, 1] x = x_old[i] p = origin[d] ne = 0 s = 0. for i in range(len(sections[d]) - 1): msk = whereNonPositive(x - o * ne + 0.5) s = s * msk + (sections[d][i] / (o * num_elem[d][i]) * (x - o * ne) + p) * (1. - msk) ne += num_elem[d][i] p += sections[d][i] x_new = x_new + s * f dom.setX(x_new) fs = Function(dom) x = Function(dom).getX() x0 = x[0] x1 = x[1] x2 = x[2] p_z = origin["z"] for i in range(len(mats)): f_z = wherePositive(x2 - p_z) * wherePositive(x2 - p_z + sections["z"][i]) p_y = origin["y"] for j in range(len(mats[i])): f_y = wherePositive(x1 - p_y) * wherePositive(x1 - p_z + sections["y"][j]) p_x = origin["x"] for k in range(len(mats[i][j])): f_x = wherePositive(x0 - p_x) * wherePositive(x0 - p_x + sections["x"][k]) fs.setTags(mats[i][j][k], f_x * f_y * f_z) p_x += sections["x"][k] p_y += sections["y"][j] p_z += sections["z"][i] return dom
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 1, optimize=OPTIMIZE) self.package = SolverOptions.TRILINOS self.method = SolverOptions.MINRES self.preconditioner = SolverOptions.JACOBI
except ImportError: print("Finley module required but not available") HAVE_FINLEY = False if HAVE_FINLEY: #... set some parameters ... lam=1. mu=0.1 alpha=1.e-6 xc=[0.3,0.3,1.] beta=8. T_ref=0. T_0=1. #... generate domain ... mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10) x=mydomain.getX() #... set temperature ... T=T_0*exp(-beta*length(x-xc)) #... open symmetric PDE ... mypde=LinearPDE(mydomain) mypde.setSymmetryOn() #... set coefficients ... C=Tensor4(0.,Function(mydomain)) for i in range(mydomain.getDim()): for j in range(mydomain.getDim()): C[i,i,j,j]+=lam C[i,j,i,j]+=mu C[i,j,j,i]+=mu msk=whereZero(x[0])*[1.,0.,0.] \ +whereZero(x[1])*[0.,1.,0.] \
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))
def test_mesh_dump_to_NetCDF_brick(self): mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False) dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc") mydomain1.dump(dumpfile) mydomain2=LoadMesh(dumpfile) self.domainsEqual(mydomain1, mydomain2)
def generate(self): (numGridPts1, numGridPts2) = self.getGridPointsPerDim() periodic0 = True if (self.getDim() == 2): mesh1 = \ Rectangle( numGridPts1[0], numGridPts1[1], order=1, l0=self.bBox1.getSize()[0], l1=self.bBox1.getSize()[1], periodic0=periodic0 ) mesh2 = \ Rectangle( numGridPts2[0], numGridPts2[1], order=1, l0=self.bBox2.getSize()[0], l1=self.bBox2.getSize()[1], periodic0=periodic0 ) else: mesh1 = \ Brick( numGridPts1[0], numGridPts1[1], numGridPts1[2], order=1, l0=self.bBox1.getSize()[0], l1=self.bBox1.getSize()[1], l2=self.bBox1.getSize()[2], periodic0=periodic0 ) mesh2 = \ Brick( numGridPts2[0], numGridPts2[1], numGridPts2[2], order=1, l0=self.bBox2.getSize()[0], l1=self.bBox2.getSize()[1], l2=self.bBox2.getSize()[2], periodic0=periodic0 ) x1 = mesh1.getX() x2 = mesh2.getX() # # To get the same identical tags on the particle boundary elements # of both meshes, reflect about the y-axis. # x2[1] = -x2[1] x2[1] += abs(inf(x2[1])) # # Now translate the meshes so they correspond to the # specified bounding boxes. # for d in range(0, self.getDim()): x1[d] += self.bBox1.getMinPt()[d] x2[d] += self.bBox2.getMinPt()[d] mesh1.setX(x1) mesh2.setX(x2) self.mesh = Merge([mesh1, mesh2])
ndx = 15 # mesh steps in x direction ndy = 15 # mesh steps in y direction - one dimension means one element ndz = 10 #PDE related rho=100.0 rholoc=[0,0,-0] 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 = Brick(l0=mx,l1=my,n0=ndx, n1=ndy,l2=mz,n2=ndz) x=Solution(domain).getX() x=x-[mx/2,my/2,mz/2] domain.setX(interpolate(x, ContinuousFunction(domain))) mask=wherePositive(100-length(x-rholoc)) rho=rho*mask kro=kronecker(domain) mass=rho*vol(domain) ipot=FunctionOnBoundary(domain) xb=ipot.getX() q=whereZero(x[2]-inf(x[2])) ###############################################ESCRIPT PDE CONSTRUCTION mypde=LinearPDE(domain)
NEz = 200 # number of nodes in the z direction H0 = 600 # height [m] of transect above bottom of domain (will be locked to grid) b_hx = 45000.0 # background magnetic field in nT x direction b_hz = 0.0 # background magnetic field in nT y direction b_hy = 0.0 # background magnetic field in nT z direction ksi = 0.015 # assumed susceptibility Lx = dx*NEx Ly = dx*NEy Lz = dx*NEz print("domain dimensions = [%dm x %dm x %dm]"%(Lx,Ly,Lz)) print("grid = [%d x %d x %d]"%(NEx, NEy, NEz)) # Create domain domain=Brick(n0=NEx, n1=NEy, n2=NEz, l0=Lx, l1=Ly, l2=Lz) # Define model using class MagneticModel3D # Assumes zero Dirichlet BC at bottom left front corner model=MagneticModel3D(domain) # Define susceptibility Z0=100 # vertical position of circle below transect [m] c=[Lx/2.,Ly/2., H0-Z0] # circle center R=20. # radius x=domain.getX() d=length(x-c) kC=ksi*whereNegative(d-R) # 0 for d>R and 1 for d<R model.setSusceptibility(kC)
print("file ", filename, " is generated") if d == 2: m = [[11., 12.], [21., 22.]] else: m = [[11., 12., 13.], [21., 22., 23.], [31., 32., 33.]] try: eval("(x*m).save%s(\"%s\")" % (format.upper(), filename)) except Exception as msg: print("%% failed because of ", msg) for format in ["vtk", "dx"]: for d in [2, 3]: for order in [1, 2]: if (d == 2): mesh = Rectangle(ne, ne, order, l0=order * ne, l1=order * ne) elif (d == 3): mesh = Brick(ne, ne, ne, order, l0=order * ne, l1=order * ne, l2=order * ne) for fs in [ "ContinuousFunction", "Function", "FunctionOnBoundary", "Solution", "ReducedSolution", "FunctionOnContact" ]: filetype = "%s.o%d.d%d" % (fs, order, d) writeInFormat(eval("%s(mesh)" % fs), format, filetype)
def setUp(self): self.domain = Brick(NE,NE,NE,-1,useElementsOnFace=0) self.order = 1
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.0001; confining=-1.e5; lx = 0.05; ly = 0.05; lz = 0.1; # sample dimension nx = 8; ny = 8; nz = 16; # discretization mydomain = Brick(l0=lx,l1=ly,l2=lz,n0=nx,n1=ny,n2=nz,order=2,integrationOrder=2) # 20-noded,8-Gauss hexahedral element dim = 3; k = kronecker(mydomain) numg = 8*nx*ny*nz; # number of Gauss points packNo=list(range(0,numg,8)) prob = MultiScale(domain=mydomain,ng=numg,useMPI=True,rtol=1e-2) # mpi is activated 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()) # traction on boundary x = mydomain.getX()
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.TRILINOS self.method = SolverOptions.DIRECT
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.TRILINOS self.method = SolverOptions.PCG self.preconditioner = SolverOptions.ILUT
def setUp(self): NE = 29 # warning: smaller NE may case a failure for VarioF tests due to discretization errors. self.dom = Brick(NE, NE, NE) self.rescaleDomain()
T_END = 0.05 # set T_END=(2*pi)/OMEGA to run a full simulation n = 0 if DIM == 2: mydomain = Rectangle(int(ceil(L * NE / H)), NE, l0=L, l1=H, order=1, useFullElementOrder=True, optimize=True) else: mydomain = Brick(int(ceil(L * NE / H)), int(ceil(L * NE / H)), NE, l0=L, l1=L, l2=H, order=1, useFullElementOrder=True, optimize=True) x = mydomain.getX() v = Vector(0.0, Solution(mydomain)) if DIM == 2: a0 = 1 n0 = 1 n1 = 0.5 a1 = -(a0 * n0) / n1 v[0] = a0 * sin(pi * n0 * x[0]) * cos(pi * n1 * x[1]) v[1] = a1 * cos(pi * n0 * x[0]) * sin(pi * n1 * x[1]) else:
c = integrate(u_h, Function(dom)) - 1. x0 = getCenter(t) x0h = integrate(x * u_h, Function(dom)) d = length(x0 - x0h) sigma_h2 = sqrt(integrate(length(x - x0h)**2 * u_h, Function(dom))) if DIM == 3: sigma_h2 *= sqrt(2. / 3.) e = sigma_h2 / sqrt(4 * E * t) - 1 # return a,b,c,e,1./(4*pi*E*t)**(DIM/2.) return d, e # return a,b,c,d,e if DIM == 2: dom = Rectangle(NE, NE) else: dom = Brick(NE, NE, NE) dom.setX(2 * dom.getX() - 1) # set initial value x = dom.getX() u0 = 1 / (4. * pi * E * T0)**(DIM / 2.) * exp( -length(dom.getX() - getCenter(T0))**2 / (4. * E * T0)) print("QUALITY ", QUALITY(T0, u0)) x = Function(dom).getX() if DIM == 2: V = OMEGA0 * (x[0] * [0, -1] + x[1] * [1, 0]) else: V = OMEGA0 * (x[0] * [0, cos(ALPHA), 0] + x[1] * [-cos(ALPHA), 0, sin(ALPHA)] + x[2] * [0., -sin(ALPHA), 0.])
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.TFQMR self.preconditioner = SolverOptions.GAUSS_SEIDEL
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.TRILINOS self.method = SolverOptions.BICGSTAB self.preconditioner = SolverOptions.GAUSS_SEIDEL
def getMesh(NE_X, NE_Y, t, d, o, fullOrder, r, l_X): if t == "Hex": if d == 2: dom = Rectangle(n0=NE_X, n1=NE_Y, l0=l_X, order=o, useFullElementOrder=fullOrder, useElementsOnFace=r, optimize=True) else: Brick() dom = Brick(n0=NE_X, n1=NE_Y, n2=NE_Y, l0=l_X, order=o, useFullElementOrder=fullOrder, useElementsOnFace=r, optimize=True) else: des = Design(dim=d, order=o, element_size=min(l_X / max(3, NE_X), 1. / max(3, NE_Y)), keep_files=True) des.setScriptFileName("tester.geo") if d == 2: p0 = Point(0., 0.) p1 = Point(l_X, 0.) p2 = Point(l_X, 1.) p3 = Point(0., 1.) l01 = Line(p0, p1) l12 = Line(p1, p2) l23 = Line(p2, p3) l30 = Line(p3, p0) s = PlaneSurface(CurveLoop(l01, l12, l23, l30)) des.addItems(s, l01, l12, l23, l30) else: p000 = Point(0., 0., 0.) p100 = Point(l_X, 0., 0.) p010 = Point(0., 1., 0.) p110 = Point(l_X, 1., 0.) p001 = Point(0., 0., 1.) p101 = Point(l_X, 0., 1.) p011 = Point(0., 1., 1.) p111 = Point(l_X, 1., 1.) l10 = Line(p000, p100) l20 = Line(p100, p110) l30 = Line(p110, p010) l40 = Line(p010, p000) l11 = Line(p000, p001) l21 = Line(p100, p101) l31 = Line(p110, p111) l41 = Line(p010, p011) l12 = Line(p001, p101) l22 = Line(p101, p111) l32 = Line(p111, p011) l42 = Line(p011, p001) bottom = PlaneSurface(-CurveLoop(l10, l20, l30, l40)) top = PlaneSurface(CurveLoop(l12, l22, l32, l42)) front = PlaneSurface(CurveLoop(l10, l21, -l12, -l11)) back = PlaneSurface(CurveLoop(l30, l41, -l32, -l31)) left = PlaneSurface(CurveLoop(l11, -l42, -l41, l40)) right = PlaneSurface(CurveLoop(-l21, l20, l31, -l22)) vol = Volume(SurfaceLoop(bottom, top, front, back, left, right)) des.addItems(vol) dom = MakeDomain(des) return dom
import time vel = -0.0001 confining = -1.e5 lx = 0.05 ly = 0.05 lz = 0.1 # sample dimension nx = 8 ny = 8 nz = 16 # discretization mydomain = Brick(l0=lx, l1=ly, l2=lz, n0=nx, n1=ny, n2=nz, order=2, integrationOrder=2) # 20-noded,8-Gauss hexahedral element dim = 3 k = kronecker(mydomain) numg = 8 * nx * ny * nz # number of Gauss points packNo = range(0, numg, 8) prob = MultiScale(domain=mydomain, ng=numg, useMPI=True, rtol=1e-2) # mpi is activated disp = Vector(0., Solution(mydomain)) t = 0
def setUp(self): self.domain = Brick(NE, NE, NE, 2) self.order = 2
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 1, optimize=OPTIMIZE) self.package = SolverOptions.UMFPACK self.method = SolverOptions.DIRECT
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.MINRES self.preconditioner = SolverOptions.RILU
#diagnostics_file=FileWriter(DIAGNOSTICS_FN,append=True) print(("<%s> Restart at time step %d (t=%e) completed." % (time.asctime(), n, t))) else: if DIM == 2: dom = Rectangle(int(ceil(L * NE / H)), NE, l0=L / H, l1=1, order=-1, optimize=True) else: dom = Brick(int(ceil(L * NE / H)), int(ceil(L * NE / H)), NE, l0=L / H, l1=L / H, l2=1, order=-1, optimize=True) x = dom.getX() T = Scalar(1, Solution(dom)) for d in range(DIM): if d == DIM - 1: T *= sin(x[d] / H * pi) else: T *= cos(x[d] / L * pi) T = (1. - x[DIM - 1]) + PERT * T v = Vector(0, Solution(dom)) stress = Tensor(0, Function(dom)) x2 = ReducedSolution(dom).getX()
def test_hex_3D_order2(self): file = "hex_3D_order2.msh" my_dom = Brick(1, 1, 1, 2) self.checker(my_dom, file)
def XXX(dim, tend, dt, s, h, b, c, d, c_dir="x", d_dir="x", a=1., CN=True): """ dim - sparial dimension s - width of initial profile h - mesh size """ v_c = c / a * getDirection(dim, c_dir) v_d = d / a * getDirection(dim, d_dir) v = (v_c + v_d) E = b / a if VERBOSITY: print("=" * 100) print( "XX Start test dim = %d , h=%e, b=%e, c=%e, d=%e, c_dir=%s, d_dir=%s, a=%e, s=%e" % (dim, h, b, c, d, c_dir, d_dir, a, s)) print("=" * 100) print("initial width s = ", s) print("diffusion = ", E) print("total velocity = ", v) print("tend = ", tend) print("tolerance = ", TOL) print("number of elements over s =", s / h) b0 = sqrt(-log(TAU) * 4 * (s**2 + E * tend)) b1 = sqrt(-log(TAU)) * 2 * s X0_0 = max(b1, -v[0] * tend + b0) X0_1 = max(b1, -v[1] * tend + b0) l_0 = X0_0 + max(v[0] * tend + b0, b1) l_1 = X0_1 + max(v[1] * tend + b0, b1) NE_0 = max(int(l_0 / h + 0.5), 1) NE_1 = max(int(l_1 / h + 0.5), 1) if dim == 2: if VERBOSITY: print("%d x %d grid over %e x %e with element size %e." % (NE_0, NE_1, l_0, l_1, h)) if NE_0 * NE_1 > NE_MAX: raise ValueError("too many elements %s." % (NE_0 * NE_1, )) dom = Rectangle(n0=NE_0, n1=NE_1, l0=l_0, l1=l_1) x0 = [X0_0, X0_1] else: X0_2 = max(b1, -v[2] * tend + b0) l_2 = X0_2 + max(v[2] * tend + b0, b1) NE_2 = max(int(l_2 / h + 0.5), 1) if VERBOSITY: print( "%d x %d x %d grid over %e x %e x %e with element size %e." % (NE_0, NE_1, NE_2, l_0, l_1, l_2, h)) if NE_0 * NE_1 * NE_2 > NE_MAX: raise ValueError("too many elements %s." % (NE_0 * NE_1 * NE_2, )) dom = Brick(n0=NE_0, n1=NE_1, ne2=NE_2, l0=l_0, l1=l_1, l2=l_2) x0 = [X0_0, X0_1, X0_2] if VERBOSITY: print("initial location = ", x0) print("XX", interpolate(uRef(dom, 0., E, s, v, x0), FunctionOnBoundary(dom))) fc_BE = TransportPDE(dom, numEquations=1) fc_BE.setValue(M=a, A=-b * kronecker(dom), B=-v_d * a, C=-v_c * a) fc_BE.getSolverOptions().setVerbosity(VERBOSITY) fc_BE.getSolverOptions().setTolerance(TOL) # fc_BE.getSolverOptions().setPreconditioner( fc_BE.getSolverOptions().GAUSS_SEIDEL) fc_BE.getSolverOptions().setNumSweeps(5) if VERBOSITY: print("Backward Euler Transport created") fc_CN = TransportPDE(dom, numEquations=1) fc_CN.setValue(M=a, A=-b * kronecker(dom), B=-v_d * a, C=-v_c * a) fc_CN.getSolverOptions().setVerbosity(VERBOSITY) fc_CN.getSolverOptions().setTolerance(TOL) #fc_CN.getSolverOptions().setPreconditioner(fc_CN.getSolverOptions().GAUSS_SEIDEL) fc_CN.getSolverOptions().setNumSweeps(2) if VERBOSITY: print("Crank Nicolson Transport created") dt_CN = fc_CN.getSafeTimeStepSize() if VERBOSITY: print("time step size by Crank Nicolson=", dt_CN) U0 = uRef(dom, 0, E, s, v, x0) U0_e = uRef(dom, 0, E, s, v, x0, True) fc_CN.setInitialSolution(U0) fc_BE.setInitialSolution(U0) initial_error_L2 = sqrt(integrate((U0 - U0_e)**2)) if VERBOSITY: print("initial Lsup = ", Lsup(U0), Lsup(U0_e)) print("initial integral = ", integrate(U0_e)) print("initial error = ", initial_error_L2) print("used time step size =", dt) if not CN: n = int(ceil(tend / dt)) if VERBOSITY: print("Solve Backward Euler:") print("substeps : ", n) t0 = clock() for i in range(n): u = fc_BE.getSolution(dt) t0 = clock() - t0 else: if VERBOSITY: print("Solve Crank Nicolson:") dt = dt_CN t0 = clock() u = fc_CN.getSolution(tend) t0 = clock() - t0 out = QUALITY(u, uRef(dom, tend, E, s, v, x0, True)) print("XX", interpolate(uRef(dom, tend, E, s, v, x0), FunctionOnBoundary(dom))) out['time'] = t0 out['tend'] = tend out['dt'] = dt out['dx'] = h if abs(b) > 0: out["peclet"] = length(v) * s / b else: out["peclet"] = 9999999. # saveVTK("bb.vtu",u0=U0,u_CN=u_CN, uRef=uRef(dom,dt2,E,s,v,X0) ) return out
def test_hex_3D_order2_onFace(self): file = "hex_3D_order2_onFace.msh" my_dom = Brick(1, 1, 1, 2, useElementsOnFace=1) self.checker(my_dom, file)
def setUp(self): self.domain = Brick(NE0, NE1, NE2, 2, optimize=OPTIMIZE) self.package = SolverOptions.TRILINOS self.method = SolverOptions.BICGSTAB self.preconditioner = SolverOptions.JACOBI self.REL_TOL = 5.e-6
def test_hex3D_order2_integorder6(self): NE = getMPIRankWorld() my_dom = Brick(NE, NE, NE, order=2, integrationOrder=6) self.__test_3DQ(my_dom, 6)
def getDomain(): """ this defines a dom as a brick of length and width l and hight h """ global netotal v_p={} for tag in sorted(rho_tab.keys()): v_p[tag]=sqrt((2*mu_tab[tag]+lmbd_tab[tag])/rho_tab[tag]) v_p_ref=min(v_p.values()) print("velocities: bedrock = %s, sand = %s, water =%s, absorber =%s, reference =%s"%(v_p[bedrock],v_p[sand],v_p[water],v_p[absorber],v_p_ref)) sections={} sections["x"]=[d_absorber, x_sand, l_sand, l_x_water, l_sand, l-x_sand-2*l_sand-l_x_water, d_absorber] sections["y"]=[d_absorber, y_sand, l_sand, l_y_water, l_sand, l-y_sand-2*l_sand-l_y_water, d_absorber] sections["z"]=[d_absorber,h-h_water-h_sand,h_sand,h_water] if output: print("sections x = ",sections["x"]) print("sections y = ",sections["y"]) print("sections z = ",sections["z"]) mats= [ [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ], [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ], [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , sand , sand , sand , bedrock , absorber], [absorber, bedrock , sand , sand , sand , bedrock , absorber], [absorber, bedrock , sand , sand , sand , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ], [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, bedrock , sand , sand , sand , bedrock , absorber], [absorber, bedrock , sand , water , sand , bedrock , absorber], [absorber, bedrock , sand , sand , sand , bedrock , absorber], [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber], [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ] ] num_elem={} for d in sections: num_elem[d]=[] for i in range(len(sections[d])): if d=="x": v_p_min=v_p[mats[0][0][i]] for q in range(len(sections["y"])): for r in range(len(sections["z"])): v_p_min=min(v_p[mats[r][q][i]],v_p_min) elif d=="y": v_p_min=v_p[mats[0][i][0]] for q in range(len(sections["x"])): for r in range(len(sections["z"])): v_p_min=min(v_p[mats[r][i][q]],v_p_min) elif d=="z": v_p_min=v_p[mats[i][0][0]] for q in range(len(sections["x"])): for r in range(len(sections["y"])): v_p_min=min(v_p[mats[i][r][q]],v_p_min) num_elem[d].append(max(1,int(sections[d][i] * v_p_ref/v_p_min /resolution+0.5))) ne_x=sum(num_elem["x"]) ne_y=sum(num_elem["y"]) ne_z=sum(num_elem["z"]) netotal=ne_x*ne_y*ne_z if output: print("grid : %s x %s x %s (%s elements)"%(ne_x,ne_y,ne_z,netotal)) dom=Brick(ne_x,ne_y,ne_z,l0=o*ne_x,l1=o*ne_y,l2=o*ne_z,order=o) x_old=dom.getX() x_new=0 for d in sections: if d=="x": i=0 f=[1,0,0] if d=="y": i=1 f=[0,1,0] if d=="z": i=2 f=[0,0,1] x=x_old[i] p=origin[d] ne=0 s=0. for i in range(len(sections[d])-1): msk=whereNonPositive(x-o*ne+0.5) s=s*msk + (sections[d][i]/(o*num_elem[d][i])*(x-o*ne)+p)*(1.-msk) ne+=num_elem[d][i] p+=sections[d][i] x_new=x_new + s * f dom.setX(x_new) fs=Function(dom) x=Function(dom).getX() x0=x[0] x1=x[1] x2=x[2] p_z=origin["z"] for i in range(len(mats)): f_z=wherePositive(x2-p_z)*wherePositive(x2-p_z+sections["z"][i]) p_y=origin["y"] for j in range(len(mats[i])): f_y=wherePositive(x1-p_y)*wherePositive(x1-p_z+sections["y"][j]) p_x=origin["x"] for k in range(len(mats[i][j])): f_x=wherePositive(x0-p_x)*wherePositive(x0-p_x+sections["x"][k]) fs.setTags(mats[i][j][k],f_x*f_y*f_z) p_x+=sections["x"][k] p_y+=sections["y"][j] p_z+=sections["z"][i] return dom