def test_hex_contact_2D_order2_onFace(self): file="hex_contact_2D_order2_onFace.msh" ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True) ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True) ms2.setX(ms2.getX()+[0,0.5]) my_dom=JoinFaces([ms1,ms2],optimize=False) self.checker(my_dom,file)
class Test_OtherInterpolationOnFinley(unittest.TestCase): def setUp(self): self.r=Rectangle(4,1).getX()[0]+2 self.z=Data(2) def tearDown(self): del self.z del self.r def test_nonuniformint(self): self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [0,1], [5,6], True) self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [3,4], [5,6], True) self.assertTrue(Lsup(self.z.nonuniformInterpolate([0,1], [5,6], False)-6)<0.00001, "RHS edge not fitted") self.assertTrue(Lsup(self.z.nonuniformInterpolate([3,4], [5,6], False)-5)<0.00001, "LHS edge not fitted") tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 2.8], [1, -1, 2, 4], False) self.assertTrue(Lsup(sup(tmp)-4)<0.0001, "RHS edge not fitted for Rect") self.assertTrue(Lsup(inf(tmp)-0.090909)<0.00001, "Internal interpolate failed") tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False) self.assertTrue(Lsup(sup(tmp)-3.42857)<0.00001, "Internal interpolate failed") def test_nonuniformSlope(self): self.assertRaises(RuntimeError, self.z.nonuniformSlope, [0,1], [5,6], True) self.assertRaises(RuntimeError, self.z.nonuniformSlope, [3,4], [5,6], True) self.assertTrue(Lsup(self.z.nonuniformSlope([0,1], [5,6], False))<0.00001, "RHS edge not fitted") self.assertTrue(Lsup(self.z.nonuniformSlope([3,4], [5,6], False))<0.00001, "LHS edge not fitted") tmp=self.r.nonuniformSlope([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False) self.assertTrue(Lsup(sup(tmp)-30)<0.00001, "Internal interpolate failed") self.assertTrue(Lsup(inf(tmp)+7.27273)<0.00001, "Internal interpolate failed")
def test_rectconstr(self): self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0)]) self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40]) self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40]) self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=["cows"]) self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,)], diracTags=["test"]) z=Rectangle(4,4, diracPoints=[(0,0), (0.25,0.25)], diracTags=[40,51]) z=Rectangle(4,4, diracPoints=[(0.125,0.625), (0.5,1), (0.75, 0.25), (0.89, 0.875)], diracTags=["A", "B", "A", "C"]) v=interpolate(z.getX(), DiracDeltaFunctions(z)) if mpisize==1: self.assertEqual(v.toListOfTuples(),[(0.0, 0.5), (0.5, 1.0), (0.75, 0.25), (1.0, 0.75)]) 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)) if mpisize==1: self.assertEqual(inf(v[0]), -10) self.assertEqual(inf(v[1]), 0.5) v.setTaggedValue(500,(-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, bottom, left, right, top') self.assertEqual(z.getTag("C"), 42)
def test_data_dump_to_NetCDF_rectangle(self): mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0) 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 test_setXError(self): domain=Rectangle(NE,NE) x=domain.getX() z=interpolate(x, Function(domain)) self.assertRaises(ValueError, domain.setX, z) del x del z del domain
def test_mesh_dump_to_NetCDF_rectangle(self): mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False) dumpfile = os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc") mydomain1.dump(dumpfile) mydomain2 = LoadMesh(dumpfile) self.domainsEqual(mydomain1, mydomain2)
def test_connectivity_info(self): if hasFeature("boostnumpy"): domain = Rectangle(n0=3, n1=4) testvalues = domain.getConnectivityInfo() correctvalues = [[0., 1., 5., 4.], [1., 2., 6., 5.], [2., 3., 7., 6.], [4., 5., 9., 8.], [5., 6., 10., 9.], [6., 7., 11., 10.], [8., 9., 13., 12.], [9., 10., 14., 13.], [10., 11., 15., 14.], [12., 13., 17., 16.], [13., 14., 18., 17.], [14., 15., 19., 18.]] for i in range(0, testvalues.shape[0]): for j in range(0, 4): self.assertEqual(testvalues[i][j], correctvalues[i][j])
def setUp(self): self.order = 2 d1 = Rectangle(n0=NE // 2 + 1, n1=NE, l0=0.5, order=2, useElementsOnFace=True) d2 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=True) d2.setX(d2.getX() + [0.5, 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_data_dump_to_NetCDF_rectangle(self): mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False, useElementsOnFace=0) 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): try: self.workdir=os.environ['FINLEY_WORKDIR'] except KeyError: self.workdir='.' NE0=NE NE1=NE+1 self.domain = Rectangle(NE0, NE1, order=2) self.functionspaces = [ ContinuousFunction ] # number of total data points for each function space self.linecounts=[ (2*NE0+1)*(2*NE1+1)-NE0*NE1+1 ] # number of masked points, i.e. where X[0] is non-zero self.linecounts_masked=[ (2*NE0+1)*(2*NE1+1)-(2+NE0)*NE1 ] # expected values in first line of masked data = [ X[:], X[0] ] self.firstline=[ [1./(2*NE0), 0., 1./(2*NE0)] ] if getMPISizeWorld() == 1: self.functionspaces += [ ReducedContinuousFunction, Function, ReducedFunction, FunctionOnBoundary, ReducedFunctionOnBoundary ] self.linecounts += [ 31, 181, 81, 55, 37 ] self.linecounts_masked += [ 25, 181, 81, 40, 27 ] self.firstline += [ [.25, 0., .25], [.02817541634481463,.02254033307585171,.02817541634481463], [.05283121635129676,.04226497308103741,.05283121635129676], [.02817541634481463,0.,.02817541634481463], [.05283121635129676,0.,.05283121635129676] ] else: print("Skipping some CSV tests on finley since MPI size > 1")
def test_Rectangle_optimize_order1(self): mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False, useElementsOnFace=0) mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True, useElementsOnFace=0) self.domainsEqual(mydomain1, mydomain2)
def setUp(self): Stations = [(0., 0.), (1., 0), (0, 1), (1, 1)] StationsTags = ["A1", "A2", "A3", "A4"] self.domain = Rectangle(n0=5, n1=5, diracPoints=Stations, diracTags=StationsTags)
def test_hex2D_macro_integorder10(self): NE = getMPIRankWorld() my_dom = Rectangle(NE, NE, order=-1, useElementsOnFace=0, integrationOrder=10) self.__test_2DQ(my_dom, 10)
def setUp(self): try: self.workdir = os.environ['FINLEY_WORKDIR'] except KeyError: self.workdir = '.' self.domain = Rectangle(NE, NE + 1, 2) self.functionspace = FunctionOnBoundary( self.domain ) # due to a bug in escript python needs to hold a reference to the domain
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_hex_contact_2D_order2_onFace(self): file = "hex_contact_2D_order2_onFace.msh" ms1 = Rectangle(1, 1, 2, l1=0.5, useElementsOnFace=True) ms2 = Rectangle(1, 1, 2, l1=0.5, useElementsOnFace=True) ms2.setX(ms2.getX() + [0, 0.5]) my_dom = JoinFaces([ms1, ms2], optimize=False) self.checker(my_dom, file)
def test_getPotential2d(self): dom = Rectangle(20, 20, l0=1000, l1=-1000, d1=mpisize) extents = [1000, 1000] primaryConductivity = Data(1 / 100., ContinuousFunction(dom)) secondaryConductivity = Data(1 / 130., ContinuousFunction(dom)) current = 1000. a = 0.05 * extents[0] start = [0.25 * extents[0]] directionVector = [1] numElectrodes = 10 self.assertRaises( NotImplementedError, lambda: PolePoleSurvey( dom, primaryConductivity, secondaryConductivity, current, a, start, directionVector, numElectrodes))
def setUp(self): Width = self.DX * self.NEx Center = self.NEx // 2 * self.DX self.domain = Rectangle(self.NEx, self.NEx, l0=Width, l1=Width, diracPoints=[(Center, Center)], diracTags=["src"], order=self.Order, fullOrder=True) numStation = (self.NEx // 2 - 3 - self.NE_STATION0 - 1) stations = [((self.NE_STATION0 + i) * self.DX, Center) for i in range(numStation)] self.loc = Locator(Solution(self.domain), stations) self.source = Scalar(0j, DiracDeltaFunctions(self.domain)) self.source.setTaggedValue("src", self.Amplitude) self.sourceX = (Center, Center)
def setUp(self): self.order = 2 d1 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0) d2 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0) d2.setX(d2.getX() + [0.5, 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_2D_order2(self): file = "hex_2D_order2.msh" my_dom = Rectangle(1, 1, 2, useElementsOnFace=0) self.checker(my_dom, file)
def setUp(self): self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.MINRES self.preconditioner = SolverOptions.RILU
################################################ESTABLISHING PARAMETERS t = 0 * day # our start time, usually zero tend = 0.5 * day # - time to end simulation outputs = 200 # number of time steps required. h = (tend - t) / outputs #size of time step #user warning statement print("Expected Number of time outputs is: ", (tend - t) / h) i = 0 #loop counter #the folder to put our outputs in, leave blank "" for script path save_path = os.path.join("data", "example02") #ensure the dir exists mkDir(save_path, os.path.join(save_path, "tempT")) ####################################################DOMAIN CONSTRUCTION rod = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy) x = Solution(rod).getX() ###############################################ESCRIPT PDE CONSTRUCTION mypde = LinearPDE(rod) A = zeros((2, 2)) A[0, 0] = kappa q = whereZero(x[0]) mypde.setValue(A=A, D=rhocp / h, q=q, r=T0) # ... set initial temperature .... T = T0 * whereZero(x[0]) + Tref * (1 - whereZero(x[0])) # ... open a collector for the time marks and corresponding total energy t_list = [] E_list = [] # ... convert solution points for plotting plx = x.toListOfTuples()
else: tend = 1.5 # end time h = 0.001 # time step # data recording times rtime = 0.0 # first time to record rtime_inc = tend / 20.0 # time increment to record #Check to make sure number of time steps is not too large. print("Time step size= ", h, "Expected number of outputs= ", tend / h) U0 = 0.005 # amplitude of point source # want a spherical source in the middle of area xc = [500, 500] # with reference to mx,my this is the source location ####################################################DOMAIN CONSTRUCTION mydomain = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy) # create the domain x = mydomain.getX() # get the node locations of the domain ##########################################################ESTABLISH PDE mypde = LinearPDE(mydomain) # create pde mypde.setSymmetryOn() # turn symmetry on mypde.setValue(D=1.) # set the value of D in the general form to 1. ############################################FIRST TIME STEPS AND SOURCE # define small radius around point xc src_radius = 30 print("src_radius = ", src_radius) # set initial values for first two time steps with source terms u = U0 * (cos(length(x - xc) * 3.1415 / src_radius) + 1) * whereNegative(length(x - xc) - src_radius) u_m1 = u
if HAVE_FINLEY: NE = 16 DIM = 3 H = 1. L = 2 * H OMEGA = 10 EPS = 0.01 t = 0 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()
os.mkdir('./result/gauss') os.mkdir('./result/vtk') os.mkdir('./result/packing') except OSError as exc: if exc.errno != errno.EEXIST: raise pass confining = -2.e5; pore = 1.e5 # initial pore pressure perm = 0.001**2/(180.*8.9e-4); # unscaled permeability, using KC equation kf = 2.2e9 # fluid bulk modulus dt = .1; vel = -0.0001 # time step and loading speed lx = 0.05; ly = 0.1 # sample dimension nx = 8; ny = 16 # discretization mydomain = Rectangle(l0=lx,l1=ly,n0=nx,n1=ny,order=2,integrationOrder=2) k = kronecker(mydomain); dim = 2. numg = 4*nx*ny; # no. of Gauss points mpi = True # use MPI prob = MultiScale(domain=mydomain,pore0=pore,perm=perm,kf=kf,dt=dt,ng=numg,useMPI=mpi,rtol=1.e-2) disp = Vector(0.,Solution(mydomain)) t = 0 ux = mydomain.getX() # disp. node coordinate px = ReducedSolution(mydomain).getX() # press. node coordinate bx = FunctionOnBoundary(mydomain).getX() topSurf = whereZero(bx[1]-ly) uDbc = whereZero(ux[1])*[0,1]+whereZero(ux[0]-lx/2.)*whereZero(ux[1])*[1,1]+whereZero(ux[1]-ly)*[0,1] # disp. Dirichlet BC mask vDbc = whereZero(ux[1])*[0,0]+whereZero(ux[0]-lx/2.)*whereZero(ux[1])*[0,0]+whereZero(ux[1]-ly)*[0,vel*dt] # disp. Dirichlet BC value uNbc = whereZero(bx[0])*[-confining,0]+whereZero(bx[0]-lx)*[confining,0] # disp. Neumann BC
def test_mesh_dump_to_NetCDF_rectangle(self): mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False) dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc") mydomain1.dump(dumpfile) mydomain2=LoadMesh(dumpfile) self.domainsEqual(mydomain1, mydomain2)
__copyright__="""Copyright (c) 2003-2016 by The University of Queensland http://www.uq.edu.au Primary Business: Queensland, Australia""" __license__="""Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" from esys.escript import * from esys.escript.linearPDEs import LinearPDE, TransportPDE from esys.finley import Rectangle from esys.weipa import saveVTK # dom=Rectangle(12,8,l0=1.5) # dom=Rectangle(24,16,l0=1.5) dom=Rectangle(48,32,l0=1.5) saveDataCSV("t.csv",x=dom.getX(), rho=length(dom.getX())) 1/0 # dom=Rectangle(8*48,8*32,l0=1.5) # dom=Rectangle(120,80,l0=1.5) V=Scalar(1.,Function(dom))*[-1.,0] THETA=0. fc=TransportPDE(dom,num_equations=1,theta=THETA) fc.setTolerance(1.e-12) fc.setValue(M=Scalar(1.,Function(dom)),C=V) x=dom.getX() x_0=[0.5,0.5] sigma=0.075 u0=1. for i in range(dom.getDim()): u0=u0*exp(-(x[i]-x_0[i])**2/sigma**2)
#from esys.ripley import Rectangle, Brick from esys.weipa import saveVTK from math import pi, ceil NE=128 #NE=4 DIM=2 THETA=0.5 OMEGA0=1. ALPHA=pi/4 T0=0 T_END=2.*pi dt=1e-3*10*10 E=1.e-3 dom=Rectangle(NE,NE) u0=dom.getX()[0] # saveVTK("u.%s.vtu"%0,u=u0) # print "XX"*80 # set initial value #dom.setX(2*dom.getX()-1) #x=dom.getX() #r=sqrt(x[0]**2+(x[1]-1./3.)**2) #u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5)) #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.])
else: tend = 1.0 # end time h = 0.0005 # time step # data recording times rtime = 0.0 # first time to record rtime_inc = tend / 20.0 # time increment to record # Check to make sure number of time steps is not too large. print("Time step size= ", h, "Expected number of outputs= ", tend / h) U0 = 0.005 # amplitude of point source # want a spherical source in the middle of area xc = [500, 500] # with reference to mx,my this is the source location ####################################################DOMAIN CONSTRUCTION mydomain = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy) # create the domain x = mydomain.getX() # get the node locations of the domain ##########################################################ESTABLISH PDE mypde = LinearPDE(mydomain) # create pde # turn lumping on for more efficient solving mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING) mypde.setSymmetryOn() # turn symmetry on mypde.setValue(D=1.0) # set the value of D in the general form to 1. ############################################FIRST TIME STEPS AND SOURCE # define small radius around point xc src_radius = 25.0 print("src_radius = ", src_radius) # set initial values for first two time steps with source terms u = U0 * (cos(length(x - xc) * 3.1415 / src_radius) + 1) * whereNegative(length(x - xc) - src_radius)
#solver settings dt = 0.001 t_step = 0 t_step_end = 2000 TOL = 1.0e-5 max_iter=400 verbose=True useUzawa=True #define mesh l0=0.9142 l1=1.0 n0=200 n1=200 mesh=Rectangle(l0=l0, l1=l1, order=2, n0=n0, n1=n1) #get mesh dimensions numDim = mesh.getDim() #get element size h = Lsup(mesh.getSize()) #level set parameters tolerance = 1.0e-6 reinit_max = 30 reinit_each = 3 alpha = 1 smooth = alpha*h #boundary conditions x = mesh.getX() #left + bottom + right + top
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.1; # sample size, 50mm by 100mm nx = 8; ny = 16; # sample discretization, 8 by 16 quadrilateral elements mydomain = Rectangle(l0=lx,l1=ly,n0=nx,n1=ny,order=2,integrationOrder=2) dim = mydomain.getDim() k = kronecker(mydomain) numg = 4*nx*ny; # number of Gauss points, 4 GP each element (reduced integration) nump = 16; # number of processes for multiprocessing prob = MultiScale(domain=mydomain,ng=numg,np=nump,random=False,rtol=1e-2,usePert=False,pert=-2.e-5,verbose=True) disp = Vector(0.,Solution(mydomain)) t=0 stress = prob.getCurrentStress() # initial stress proj = Projector(mydomain) sig = proj(stress) # project Gauss point value to nodal value sig_bounda = interpolate(sig,FunctionOnBoundary(mydomain)) # interpolate
def setUp(self): self.r=Rectangle(4,1).getX()[0]+2 self.z=Data(2)
def test_hex2D_order2_integorder10(self): NE = getMPIRankWorld() my_dom = Rectangle(NE, NE, order=2, integrationOrder=10) self.__test_2DQ(my_dom, 10)
def test_hex_2D_order1_onFace(self): file = "hex_2D_order1_onFace.msh" my_dom = Rectangle(1, 1, 1, useElementsOnFace=1) self.checker(my_dom, file)
alpha_w = 1.00 alpha = 1.00*1000000. Pen=0. B=100. nstep = 3000 dt = 1. small = EPSILON w_step=max(int(nstep/50),1)*0+1 toler = 0.001 teta1 = 0.5 teta2 = 0.5 teta3 = 1 # =0 split A; =1 split B # create domain: dom=Rectangle(int(nel*L/min(L,H)),int(nel*H/min(L,H)),order=1, l0=L, l1=H) x=dom.getX() momentumStep1=LinearPDESystem(dom) momentumStep1.setValue(q=whereZero(x[0])*[1.,0.]+whereZero(x[1])*[0.,1.]) # fix x0=0 and x1=0 face_mask=whereZero(FunctionOnBoundary(dom).getX()[1]) pressureStep2=LinearSinglePDE(dom) pressureStep2.setReducedOrderOn() pressureStep2.setValue(q=whereZero(x[0]-L)+whereZero(x[1]-H)) momentumStep3=LinearPDESystem(dom) momentumStep3.setValue(q=whereZero(x[0])*[1.,0.]+whereZero(x[1])*[0.,1.]) # # initial values:
""" Author: Ning Guo <*****@*****.**> run `mv retainingSmooth.yade.gz 0.yade.gz` to generate initial RVE packing """ from esys.escript import * from esys.finley import Rectangle from esys.weipa import saveVTK from esys.escript.pdetools import Projector from msFEM2D import MultiScale from saveGauss import saveGauss2D import time vel = -0.00017; surcharge=-2.e4; # surcharge equals to the initial vertical stress of the RVE packing; vel<0 passive failure; vel>0 active failure B = 0.4; H = 0.2; wallH = 0.17; baseH = H-wallH; # setup dimensions nx = 40; ny = 20 # discretization with 40x20 quads mydomain = Rectangle(l0=B,l1=H,n0=nx,n1=ny,order=2,integrationOrder=2) dim = mydomain.getDim() k = kronecker(mydomain) numg = 4*nx*ny; nump = 16; packNo=range(0,numg,16) disp = Vector(0.,Solution(mydomain)) prob = MultiScale(domain=mydomain,ng=numg,np=nump,random=False,rtol=1e-2,usePert=False,pert=-2.e-5,verbose=True) t=0 time_start = time.time() x = mydomain.getX() bx = FunctionOnBoundary(mydomain).getX() left = whereZero(x[0])
#decay1[t]=np.exp(g*t) #decay2[t]=(np.exp(-.1*g*t)-1) time[it]=t*h #tdecay=decay1*decay2*U0 #decay1=decay1*U0; decay2=decay2*U0 pl.clf(); pl.plot(source) #pl.plot(time,decay1);pl.plot(time,decay2); #pl.plot(time,tdecay) pl.savefig(os.path.join(savepath,'source.png')) # will introduce a spherical source at middle left of bottom face xc=[mx/2,0] ####################################################DOMAIN CONSTRUCTION domain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy,order=2) # create the domain x=domain.getX() # get the locations of the nodes in the domani ##########################################################ESTABLISH PDE mypde=LinearPDE(domain) # create pde mypde.setSymmetryOn() # turn symmetry on # turn lumping on for more efficient solving mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING) kmat = kronecker(domain) # create the kronecker delta function of the domain mypde.setValue(D=kmat*rho) #set the general form value D ##########################################################ESTABLISH ABC # Define where the boundary decay will be applied. bn=50. bleft=xstep*bn; bright=mx-(xstep*bn); bbot=my-(ystep*bn) # btop=ystep*bn # don't apply to force boundary!!!
# ====================== t = 0 # time stamp n = 0 # time step counter dt = DT # current time step size t_vis = 0 n_vis = 0 counter_vis = 0 mkDir(VIS_DIR) # ========================= # # set up domain # if DIM == 2: dom = Rectangle(NE_L, NE_H, l0=L, l1=H, order=1, optimize=True) else: dom = Brick(NE_L, NE_L, NE_H, l0=L, l1=L, l2=H, order=1, optimize=True) BBOX = boundingBox(dom) DIM = dom.getDim() x = dom.getX() # # initial values: # sigma = Tensor(0.0, Function(dom)) eps_e = Tensor(0.0, Function(dom)) if CASE == 2 or CASE == 3: alpha = ALPHA_0 * exp(-length(Function(dom).getX() - xc) ** 2 / WWW ** 2) else: alpha = Scalar(ALPHA_0, Function(dom))
t=dataMgr.getValue('t') t_vis=dataMgr.getValue('t_vis') n=dataMgr.getValue('n') dt=dataMgr.getValue('dt') stress=dataMgr.getValue('stress') v=dataMgr.getValue('v') p=dataMgr.getValue('p') T=dataMgr.getValue('T') if CREATE_TOPO: topography=dataMgr.getValue('topography') #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() p=Ra*(x2[DIM-1]-0.5*x2[DIM-1]**2-0.5)
http://www.uq.edu.au Primary Business: Queensland, Australia""" __license__="""Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" from esys.escript import * from esys.escript.linearPDEs import Poisson try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.weipa import saveVTK if not HAVE_FINLEY: print("Finley module not available") else: # generate domain: mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20) # define characteristic function of Gamma^D x = mydomain.getX() gammaD = whereZero(x[0])+whereZero(x[1]) # define PDE and get its solution u mypde = Poisson(domain=mydomain) mypde.setValue(f=1,q=gammaD) u = mypde.getSolution() # write u to an external file saveVTK("u.vtu",sol=u)
wellspecs = { 'P1' : { "X0" :[ (N_X/2+0.5)*CELL_X, (N_Y/2+0.5)*CELL_Y, 0.5*CELL_Z], "r" : 0.8333 * U.ft, "s" : 0, "Q" : [0., 2000*U.Barrel/U.day ], "BHP" : 75*U.psi, "schedule" : [0.*U.yr, 2*U.yr] } } # print input print(("<%s> Execution started."%time.asctime())) DIM=2 domain=Rectangle(N_X, N_Y, l0=L_X, l1=L_Y) N=1000 for I in wellspecs: domain.setTagMap(I, N) N+=1 domain.addDiracPoint(wellspecs[I]["X0"][:DIM], I) print(("<%s> Well %s introduced to domain."%(time.asctime(), I))) #domain=Brick(N_X, N_Y,N_Z,l0=L_X, l1=L_Y,l2=L_Z) print(("<%s> Domain has been generated."%time.asctime())) print("length x-direction = %f km"%(sup(domain.getX()[0])/U.km)) print("cell size in x direction = %f m"%(CELL_X/U.m)) print("length y-direction = %f km"%(sup(domain.getX()[1])/U.km))
def setUp(self): self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.TFQMR self.preconditioner = SolverOptions.GAUSS_SEIDEL
# This example demonstrates both interpolation and saving data in CSV format from esys.escript import saveDataCSV, sup, interpolateTable import numpy try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False if not HAVE_FINLEY: print("Finley module not available") else: n=4 #Change this to whatever you like r=Rectangle(n,n) x=r.getX() x0=x[0] x1=x[1] #we'll use this later toobig=100 #An exception will be thrown if interpolation produces a value larger than this #First one dimensional interpolation #In this example we will interpolate a sine curve #The values we take from the domain will range from 0 to 1 (inclusive) sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0, -0.70710678118654746, -1, -0.70710678118654746, 0] numslices=len(sine_table)-1 minval=0
def setUp(self): self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE) self.package = SolverOptions.PASO self.method = SolverOptions.BICGSTAB self.preconditioner = SolverOptions.JACOBI
from esys.escript.linearPDEs import LinearPDE try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.weipa import saveVTK if not HAVE_FINLEY: print("Finley module not available") else: #... set some parameters ... kappa=1. omega=0.1 eta=10. #... generate domain ... mydomain = Rectangle(l0=5.,l1=1.,n0=50, n1=10) #... open PDE and set coefficients ... mypde=LinearPDE(mydomain) mypde.setSymmetryOn() n=mydomain.getNormal() x=mydomain.getX() mypde.setValue(A=kappa*kronecker(mydomain),D=omega,Y=omega*x[0], \ d=eta,y=kappa*n[0]+eta*x[0]) #... calculate error of the PDE solution ... u=mypde.getSolution() print("error is ",Lsup(u-x[0])) # output should be similar to "error is 1.e-7" saveVTK("x0.vtu",sol=u)
def test_hex_2D_order1_macro(self): file = "hex_2D_order1_macro.msh" my_dom = Rectangle(1, 1, -1, useElementsOnFace=0) self.checker(my_dom, file)
from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.weipa import saveVTK from esys.escript.unitsSI import DEG if not HAVE_FINLEY: print("Finley module not available") else: #... set some parameters ... lam=1. mu=1 slip_max=1. mydomain = Rectangle(l0=1.,l1=1.,n0=16, n1=16) # n1 need to be multiple of 4!!! # .. create the fault system fs=FaultSystem(dim=2) fs.addFault(V0=[0.5,0.25], strikes=90*DEG, ls=0.5, tag=1) # ... create a slip distribution on the fault: p, m=fs.getParametrization(mydomain.getX(),tag=1) p0,p1= fs.getW0Range(tag=1) s=m*(p-p0)*(p1-p)/((p1-p0)/2)**2*slip_max*[0.,1.] # ... calculate stress according to slip: D=symmetric(grad(s)) chi, d=fs.getSideAndDistance(D.getFunctionSpace().getX(),tag=1) sigma_s=(mu*D+lam*trace(D)*kronecker(mydomain))*chi #... open symmetric PDE ... mypde=LinearPDE(mydomain) mypde.setSymmetryOn() #... set coefficients ...
def test_hex2D_order1_integorder9(self): NE = getMPIRankWorld() my_dom = Rectangle(NE, NE, integrationOrder=9) self.__test_2DQ(my_dom, 9)
from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.weipa import saveVTK from esys.escript.unitsSI import DEG if not HAVE_FINLEY: print("Finley module not available") else: #... set some parameters ... lam = 1. mu = 1 slip_max = 1. mydomain = Rectangle(l0=1., l1=1., n0=16, n1=16) # n1 need to be multiple of 4!!! # .. create the fault system fs = FaultSystem(dim=2) fs.addFault(V0=[0.5, 0.25], strikes=90 * DEG, ls=0.5, tag=1) # ... create a slip distribution on the fault: p, m = fs.getParametrization(mydomain.getX(), tag=1) p0, p1 = fs.getW0Range(tag=1) s = m * (p - p0) * (p1 - p) / ((p1 - p0) / 2)**2 * slip_max * [0., 1.] # ... calculate stress according to slip: D = symmetric(grad(s)) chi, d = fs.getSideAndDistance(D.getFunctionSpace().getX(), tag=1) sigma_s = (mu * D + lam * trace(D) * kronecker(mydomain)) * chi #... open symmetric PDE ... mypde = LinearPDE(mydomain) mypde.setSymmetryOn() #... set coefficients ...
b = sup(u_h) * (4 * pi * E * t) ** (DIM / 2.0) - 1.0 c = integrate(u_h, Function(dom)) - 1.0 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.0 / 3.0) 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.0 * pi * E * T0) ** (DIM / 2.0) * exp(-length(dom.getX() - getCenter(T0)) ** 2 / (4.0 * 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.0, -sin(ALPHA), 0.0])
# This example demonstrates both interpolation and saving data in CSV format from esys.escript import saveDataCSV, sup, interpolateTable import numpy try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False if not HAVE_FINLEY: print("Finley module not available") else: n = 4 #Change this to whatever you like r = Rectangle(n, n) x = r.getX() x0 = x[0] x1 = x[1] #we'll use this later toobig = 100 #An exception will be thrown if interpolation produces a value larger than this #First one dimensional interpolation #In this example we will interpolate a sine curve #The values we take from the domain will range from 0 to 1 (inclusive) sine_table = [ 0, 0.70710678118654746, 1, 0.70710678118654746, 0, -0.70710678118654746, -1, -0.70710678118654746, 0 ]
my = -5000 * m #meters - model width ndx = 100 # mesh steps in x direction ndy = 100 # mesh steps in y direction - one dimension means one element #PDE related rho = 200.0 rholoc = [2500, -2500] 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 = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy) x = Solution(domain).getX() mask = wherePositive(10 - length(x - rholoc)) rho = rho * mask kro = kronecker(domain) q = whereZero(x[1] - my) + whereZero(x[1]) + whereZero( x[0]) + whereZero(x[0] - mx) ###############################################ESCRIPT PDE CONSTRUCTION mypde = LinearPDE(domain) mypde.setValue(A=kro, Y=4. * 3.1415 * G * rho) mypde.setValue(q=q, r=0) mypde.setSymmetryOn() sol = mypde.getSolution()
from esys.escript import * from esys.escript.linearPDEs import Poisson from esys.finley import Rectangle #Testing whether we have a late enough version of matplotlib try: matplotlib.mlab.griddata # TO keep the version distributed by openSuse happy interp='nn' try: from mpl_toolkits.natgrid import _natgrid except ImportError: interp='linear' # generate domain: mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20) # define characteristic function of Gamma^D x = mydomain.getX() gammaD = whereZero(x[0])+whereZero(x[1]) # define PDE and get its solution u mypde = Poisson(domain=mydomain) mypde.setValue(f=1,q=gammaD) u = mypde.getSolution() # interpolate u to a matplotlib grid: x_grid = numpy.linspace(0.,1.,50) y_grid = numpy.linspace(0.,1.,50) x=mydomain.getX()[0].toListOfTuples() y=mydomain.getX()[1].toListOfTuples() z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples() z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid,interp=interp )