# p+=dp U=U_new print("U:",inf(U),sup(U)) print("P:",inf(p),sup(p)) p_pos=clip(p,small) gg=grad(U) vol=gg[0,0]+gg[1,1]+U[0]/r gamma=sqrt(2*((gg[0,0]-vol/3)**2+(gg[1,1]-vol/3)**2+(U[0]/r-vol/3)**2+(gg[1,0]+gg[0,1])**2/2)) m=whereNegative(eta*gamma-alpha*p_pos) eta_d=m*eta+(1.-m)*alpha*p_pos/(gamma+small) print("viscosity =",inf(eta_d),sup(eta_d)) dev_stress=eta_d*(symmetric(gg)-2./3.*vol*kronecker(dom)) # # step size control: # len=inf(dom.getSize()) dt1=inf(dom.getSize()/(length(U)+small)) dt2=inf(0.5*ro*(len**2)/eta_d) dt=dt1*dt2/(dt1+dt2) print("new step size = ",dt) # # update geometry # dom.setX(dom.getX()+U*dt) t=t+dt if (istep-1)%w_step==0:saveVTK("u.%d.vtu"%((istep-1)/w_step),p=p,eta=eta_d,U=U_star,U_star=U_star,gamma=gamma) if istep == 3: 1/0
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() fc.setValue(M=Scalar(1., Function(dom)), C=V) #============== if TEST_SUPG: supg = LinearSinglePDE(dom) supg.setValue(D=1.) supg.setSolverMethod(supg.LUMPING) dt_supg = inf(dom.getSize() / length(V)) u_supg = u0 * 1. c = 0 # saveVTK("u.%s.vtu"%c,u=u0) fc.setInitialSolution(u0) t = T0 print("QUALITY FCT: time = %s pi" % (t / pi), inf(u0), sup(u0), integrate(u0)) while t < T_END: print("time step t=", t + dt) u = fc.solve(dt, verbose=True) print("QUALITY FCT: time = %s pi" % (t + dt / pi), inf(u), sup(u), integrate(u)) if TEST_SUPG: #========== supg tests ================ nn = max(ceil(dt / dt_supg), 1.)
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() fc.setValue(M=Scalar(1., Function(dom)), C=V, A=-Scalar(E, Function(dom)) * kronecker(dom)) #============== if TEST_SUPG: supg = LinearSinglePDE(dom) supg.setValue(D=1.) supg.setSolverMethod(supg.LUMPING) dt_supg = 1. / (1. / inf(dom.getSize() / length(V)) + 1. / inf(dom.getSize()**2 / E)) * 0.3 u_supg = u0 * 1. c = 0 saveVTK("u.%s.vtu" % c, u=u0) fc.setInitialSolution(u0) t = T0 while t < T_END: print("time step t=", t + dt) u = fc.solve(dt) if TEST_SUPG: #========== supg tests ================ nn = max(ceil(dt / dt_supg), 1.) dt2 = dt / nn nnn = 0
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() fc.setValue(M=Scalar(1.,Function(dom)),C=V,A=-Scalar(E,Function(dom))*kronecker(dom)) #============== if TEST_SUPG: supg=LinearSinglePDE(dom) supg.setValue(D=1.) supg.setSolverMethod(supg.LUMPING) dt_supg=1./(1./inf(dom.getSize()/length(V))+1./inf(dom.getSize()**2/E))*0.3 u_supg=u0*1. c=0 saveVTK("u.%s.vtu"%c,u=u0) fc.setInitialSolution(u0) t=T0 while t<T_END: print("time step t=",t+dt) u=fc.solve(dt) if TEST_SUPG: #========== supg tests ================ nn=max(ceil(dt/dt_supg),1.) dt2=dt/nn nnn=0 while nnn<nn :
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 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))
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 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))
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() fc.setValue(M=Scalar(1.,Function(dom)),C=V) #============== if TEST_SUPG: supg=LinearSinglePDE(dom) supg.setValue(D=1.) supg.setSolverMethod(supg.LUMPING) dt_supg=inf(dom.getSize()/length(V)) u_supg=u0*1. c=0 # saveVTK("u.%s.vtu"%c,u=u0) fc.setInitialSolution(u0) t=T0 print("QUALITY FCT: time = %s pi"%(t/pi),inf(u0),sup(u0),integrate(u0)) while t<T_END: print("time step t=",t+dt) u=fc.solve(dt, verbose=True) print("QUALITY FCT: time = %s pi"%(t+dt/pi),inf(u),sup(u),integrate(u)) if TEST_SUPG: #========== supg tests ================ nn=max(ceil(dt/dt_supg),1.) dt2=dt/nn