S = numpy.array([0.0, 0.0]) X0 = [bb[0][0], bb[1][1]] dd = [-cos(ALPHA), -sin(ALPHA)] else: S = numpy.array([sin(STRIKE), cos(STRIKE), 0.0]) X0 = [bb[0][0], bb[1][0], bb[2][1]] dd = [-cos(ALPHA), 0.0, -sin(ALPHA)] r = sqrt(length(x - X0) ** 2 - inner(X0 - x, S) ** 2) v = V_MAX * r * dd mask = MaskFromBoundaryTag(dom, "subduction") * [1.0 for i in range(DIM)] # # back of the domain # v = v * (1.0 - whereZero(x[0] - bb[0][1]) * kronecker(DIM)[0]) mask += whereZero(x[0] - bb[0][1]) * kronecker(DIM)[0] # # bottom of the domain # v = v * (1.0 - ((bb[DIM - 1][1] - x[DIM - 1]) / DEPTH) ** N * kronecker(DIM)[DIM - 1]) mask += whereZero(x[DIM - 1] - bb[DIM - 1][0]) * kronecker(DIM)[DIM - 1] # # faces of the domain: # if DIM == 3: v = v * (1.0 - (((x[1] - bb[1][0]) * (bb[1][1] - x[1]) / (0.5 * LY) ** 2) ** N * kronecker(DIM)[1])) mask += (whereZero(x[1] - bb[1][0]) + whereZero(x[1] - bb[1][1])) * kronecker(DIM)[1] sc.initialize(eta=ETA, fixed_u_mask=mask) p = Scalar(0.0, ReducedSolution(dom)) v, p = sc.solve(v, p, verbose=True) saveVTK("u.vtu", velocity=v, pressure=p, m=mask)
else: S = numpy.array([sin(STRIKE), cos(STRIKE), 0.]) X0 = [bb[0][0], bb[1][0], bb[2][1]] dd = [-cos(ALPHA), 0., -sin(ALPHA)] r = sqrt(length(x - X0)**2 - inner(X0 - x, S)**2) v = V_MAX * r * dd mask = MaskFromBoundaryTag(dom, "subduction") * [1. for i in range(DIM)] # # back of the domain # v = v * (1. - whereZero(x[0] - bb[0][1]) * kronecker(DIM)[0]) mask += whereZero(x[0] - bb[0][1]) * kronecker(DIM)[0] # # bottom of the domain # v = v * (1. - ((bb[DIM - 1][1] - x[DIM - 1]) / DEPTH)**N * kronecker(DIM)[DIM - 1]) mask += whereZero(x[DIM - 1] - bb[DIM - 1][0]) * kronecker(DIM)[DIM - 1] # # faces of the domain: # if DIM == 3: v = v * (1. - (((x[1] - bb[1][0]) * (bb[1][1] - x[1]) / (0.5 * LY)**2)**N * kronecker(DIM)[1])) mask += (whereZero(x[1] - bb[1][0]) + whereZero(x[1] - bb[1][1])) * kronecker(DIM)[1] sc.initialize(eta=ETA, fixed_u_mask=mask) p = Scalar(0., ReducedSolution(dom)) v, p = sc.solve(v, p, verbose=True) saveVTK("u.vtu", velocity=v, pressure=p, m=mask)
http://www.apache.org/licenses/LICENSE-2.0""" __url__ = "https://launchpad.net/escript-finley" # $Id:$ from esys.escript import * from esys.weipa import saveVTK from esys.escript.models import StokesProblemCartesian try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError as e: print("Finley module required but not available") HAVE_FINLEY = False if HAVE_FINLEY: NE = 25 dom = Rectangle(NE, NE, order=-1, useElementsOnFace=0) # use macro elements for pressure x = dom.getX() sc = StokesProblemCartesian(dom) mask = (whereZero(x[0]) * [1., 0] + whereZero(x[0] - 1)) * [1., 0] + ( whereZero(x[1]) * [0., 1.] + whereZero(x[1] - 1)) * [1., 1] sc.initialize(eta=.01, fixed_u_mask=mask) v = Vector(0., Solution(dom)) v[0] += whereZero(x[1] - 1.) p = Scalar(0., ReducedSolution(dom)) v, p = sc.solve(v, p, verbose=True) saveVTK("u.vtu", velocity=v, pressure=p)
coordinates[0]) * [1.0, 0.0] #velocity and pressure vectors velocity = Vector(0.0, Solution(mesh)) pressure = Scalar(0.0, ReducedSolution(mesh)) #Stokes Cartesian solution = StokesProblemCartesian(mesh) solution.setTolerance(tolerance) while t <= t_end: print(" ----- Time step = %s -----" % (t)) print("Time = %s seconds" % (time)) solution.initialize(fixed_u_mask=boundary_cond, eta=eta, f=Y) velocity, pressure = solution.solve(velocity, pressure, max_iter=max_iter, verbose=verbose, usePCG=True) print("Max velocity =", Lsup(velocity), "m/s") #Courant condition dt = 0.4 * h / (Lsup(velocity)) print("dt", dt) #displace the mesh displacement = velocity * dt coordinates = mesh.getX()
#Stokes Cartesian solution=StokesProblemCartesian(mesh,debug=True) solution.setTolerance(TOL) #level set levelset = LevelSet(mesh, func_new, reinit_max, reinit_each, tolerance, smooth) while t_step <= t_step_end: #update density and viscosity rho = levelset.update_parameter(rho1, rho2) eta = levelset.update_parameter(eta1, eta2) #get velocity and pressure of fluid Y[1] = -rho*g solution.initialize(fixed_u_mask=b_c,eta=eta,f=Y) velocity,pressure=solution.solve(velocity,pressure,max_iter=max_iter,verbose=verbose,useUzawa=useUzawa) #update the interface func = levelset.update_phi(velocity, dt, t_step) print("##########################################################") print("time step:", t_step, " completed with dt:", dt) print("Velocity: min =", inf(velocity), "max =", Lsup(velocity)) print("##########################################################") #save interface, velocity and pressure saveVTK("phi2D.%2.4i.vtu"%t_step,interface=func,velocity=velocity,pressure=pressure) #courant condition dt = 0.4*Lsup(mesh.getSize())/Lsup(velocity) t_step += 1
http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" # $Id:$ from esys.escript import * from esys.weipa import saveVTK from esys.escript.models import StokesProblemCartesian try: from esys.finley import Rectangle HAVE_FINLEY = True except ImportError as e: print("Finley module required but not available") HAVE_FINLEY = False if HAVE_FINLEY: NE=25 dom = Rectangle(NE,NE,order=-1, useElementsOnFace=0) # use macro elements for pressure x = dom.getX() sc=StokesProblemCartesian(dom) mask= (whereZero(x[0])*[1.,0]+whereZero(x[0]-1))*[1.,0] + (whereZero(x[1])*[0.,1.]+whereZero(x[1]-1))*[1.,1] sc.initialize(eta=.01, fixed_u_mask= mask) v=Vector(0.,Solution(dom)) v[0]+=whereZero(x[1]-1.) p=Scalar(0.,ReducedSolution(dom)) v,p=sc.solve(v,p, verbose=True) saveVTK("u.vtu",velocity=v,pressure=p)
#Stokes Cartesian solution = StokesProblemCartesian(mesh, debug=True) solution.setTolerance(TOL) #level set levelset = LevelSet(mesh, func_new, reinit_max, reinit_each, tolerance, smooth) while t_step <= t_step_end: #update density and viscosity rho = levelset.update_parameter(rho1, rho2) eta = levelset.update_parameter(eta1, eta2) #get velocity and pressure of fluid Y[1] = -rho * g solution.initialize(fixed_u_mask=b_c, eta=eta, f=Y) velocity, pressure = solution.solve(velocity, pressure, max_iter=max_iter, verbose=verbose, useUzawa=useUzawa) #update the interface func = levelset.update_phi(velocity, dt, t_step) print("##########################################################") print("time step:", t_step, " completed with dt:", dt) print("Velocity: min =", inf(velocity), "max =", Lsup(velocity)) print("##########################################################") #save interface, velocity and pressure
while n<1: print("========= Time step %d ======="%( n+1,)) m=0 dtau_lsup =1. while dtau_lsup > TOL * tau_lsup: print("--- iteration step %d ---- "%m) if n==0 and m==0: eta_top=ETA_TOP else: tau_Y=clip(c*cos(friction_angle)+p*sin(friction_angle), minval=0.) eta_top=clip(safeDiv(tau_Y,gamma_dot),maxval=ETA_TOP) print("eta_top=",eta_top) eta_eff=eta_top*(1-mask_visc) + ETA_BOTTOM*mask_visc print("eta_eff=",eta_eff) flow.initialize(fixed_u_mask=fixed_v_mask,eta=eta_eff,f=-RHO*G*unitVector(DIM-1,DIM)) v,p=flow.solve(v,-3.*p,max_iter=MAX_ITER,verbose=VERBOSE,usePCG=True) print("p=",p) p*=-(1./3.) gamma_dot=sqrt(2.)*length(deviatoric(symmetric(grad(v)))) tau, tau_old = eta_eff*gamma_dot, tau dtau_lsup=Lsup(tau-tau_old) tau_lsup=Lsup(tau) print("increment tau = ",dtau_lsup,tau_lsup, dtau_lsup > TOL * tau_lsup, TOL) print("flux balance = ",integrate(inner(v,dom.getNormal()))) m+=1 if m>MAX_ITER: raise ValueError("no convergence.") print("iteration complted after %d steps"%(m,)) print(p) saveVTK("test.vtu",v=v, p=p, eta=eta_eff, tau=tau);
print("========= Time step %d =======" % (n + 1, )) m = 0 dtau_lsup = 1. while dtau_lsup > TOL * tau_lsup: print("--- iteration step %d ---- " % m) if n == 0 and m == 0: eta_top = ETA_TOP else: tau_Y = clip(c * cos(friction_angle) + p * sin(friction_angle), minval=0.) eta_top = clip(safeDiv(tau_Y, gamma_dot), maxval=ETA_TOP) print("eta_top=", eta_top) eta_eff = eta_top * (1 - mask_visc) + ETA_BOTTOM * mask_visc print("eta_eff=", eta_eff) flow.initialize(fixed_u_mask=fixed_v_mask, eta=eta_eff, f=-RHO * G * unitVector(DIM - 1, DIM)) v, p = flow.solve(v, -3. * p, max_iter=MAX_ITER, verbose=VERBOSE, usePCG=True) print("p=", p) p *= -(1. / 3.) gamma_dot = sqrt(2.) * length(deviatoric(symmetric(grad(v)))) tau, tau_old = eta_eff * gamma_dot, tau dtau_lsup = Lsup(tau - tau_old) tau_lsup = Lsup(tau) print("increment tau = ", dtau_lsup, tau_lsup, dtau_lsup > TOL * tau_lsup, TOL) print("flux balance = ", integrate(inner(v, dom.getNormal())))