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_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_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
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: #
else: # end of simulation time t_end=0.1 # time step size: dt=0.01 # dimensions: L0=1.;L1=1. # location, size and value of heat source xc=[0.3,0.4]; r=0.1; Qc=3000 # material parameter k=1; rhocp=100; # bottom temperature: T_bot=100 # generate domain: mydomain=Rectangle(l0=L0,l1=L1,n0=20,n1=20) x=mydomain.getX() # set boundray temperature: T_D=T_bot/L1*(L1-x[1]) # set heat source: Q=Qc*whereNegative(length(x-xc)-r) # generate domain: mypde=LinearPDE(mydomain) mypde.setSymmetryOn() # set PDE coefficients: mypde.setValue(A=dt*k*kronecker(mydomain), D=dt*rhocp, r=T_D, q=whereZero(x[1])+whereZero(x[1]-L1)) # initial temperature T=T_D # step counter and time marker: N=0; t=0 # stop when t_end is reached:
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 TEST_SUPG = False or True if DIM == 2: dom = Rectangle(NE, NE) else: dom = Brick(NE, NE, NE) u0 = dom.getX()[0] # saveVTK("u.%s.vtu"%0,u=u0) # print "XX"*80 dom.setX(2 * dom.getX() - 1) # set initial value 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.])
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) if CREATE_TOPO: topography=Scalar(0.,Solution(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.]) #=================== fc=TransportPDE(dom,num_equations=1,theta=THETA) x=Function(dom).getX()
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.]) #===================
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 b_c = whereZero(x[0]) * [1.0, 0.0] + whereZero(x[1]) * [1.0, 1.0] + whereZero( x[0] - l0) * [1.0, 0.0] + whereZero(x[1] - l1) * [1.0, 1.0] velocity = Vector(0.0, ContinuousFunction(mesh)) pressure = Scalar(0.0, ContinuousFunction(mesh)) Y = Vector(0.0, Function(mesh)) #define initial interface between fluids xx = mesh.getX()[0] yy = mesh.getX()[1] func = Scalar(0.0, ContinuousFunction(mesh)) h_interface = Scalar(0.0, ContinuousFunction(mesh)) h_interface = h_interface + (0.02 * cos(math.pi * xx / l0) + 0.2) func = yy - h_interface
L0 = 1. L1 = 1. # height of k interface: H = L1 * 0.75 # bottom temperature: T_bot = 100 # location, size and value of heat source xc = [0.3, 0.4] r = 0.1 Qc = 3000 # two values for k k0 = 1 k1 = 10 # create domain: mydomain = Rectangle(l0=L0, l1=L1, n0=20, n1=20) x = mydomain.getX() # set variable k k = k0 + (k1 - k0) * wherePositive(x[1] - H) # boundary temperature T_D = T_bot / L1 * (L1 - x[1]) # heat source Q = Qc * whereNegative(length(x - xc) - r) # create PDE and set coefficients: mypde = LinearPDE(mydomain) mypde.setSymmetryOn() # set PDE coefficients: mypde.setValue(A=k*kronecker(mydomain),Y=Q, r=T_D, \ q=whereZero(x[1])+whereZero(x[1]-L1)) # get temperature: T = mypde.getSolution() # save as VTK for visualisation:
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 b_c = whereZero(x[0])*[1.0,0.0] + whereZero(x[1])*[1.0,1.0] + whereZero(x[0]-l0)*[1.0,0.0] + whereZero(x[1]-l1)*[1.0,1.0] velocity = Vector(0.0, ContinuousFunction(mesh)) pressure = Scalar(0.0, ContinuousFunction(mesh)) Y = Vector(0.0,Function(mesh)) #define initial interface between fluids xx = mesh.getX()[0] yy = mesh.getX()[1] func = Scalar(0.0, ContinuousFunction(mesh)) h_interface = Scalar(0.0, ContinuousFunction(mesh)) h_interface = h_interface + (0.02*cos(math.pi*xx/l0) + 0.2) func = yy - h_interface func_new = func.interpolate(ReducedSolution(mesh))
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 TEST_SUPG=False or True if DIM==2: dom=Rectangle(NE,NE) else: dom=Brick(NE,NE,NE) u0=dom.getX()[0] # saveVTK("u.%s.vtu"%0,u=u0) # print "XX"*80 dom.setX(2*dom.getX()-1) # set initial value 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.]) #===================