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: a0 = 1 a1 = 1 n0 = 2 n1 = 2 n2 = 0.5 a2 = -(a0 * n0 + a1 * n1) / n2 v[0] = a0 * sin(pi * n0 * x[0]) * cos(pi * n1 * x[1]) * cos( pi * n2 * x[2]) v[1] = a1 * cos(pi * n0 * x[0]) * sin(pi * n1 * x[1]) * cos( pi * n2 * x[2]) v[2] = a2 * cos(pi * n0 * x[0]) * cos(pi * n1 * x[1]) * sin( pi * n2 * x[2]) mts = Mountains(mydomain, eps=EPS) while t < T_END: print("STEP ", t) mts.setVelocity(v * cos(OMEGA * t)) Z = mts.update() saveVTK("state.%d.vtu" % n, sol=Z, v=mts.getVelocity()) print("Integral(Z)=", integrate(Z), Lsup(mts.getVelocity()[DIM - 1])) n += 1 t += mts.getSafeTimeStepSize()
flow.setExternals(F=Ra*T*unitVector(DIM-1,DIM)) # if dt<=0 or not CREATE_TOPO: if not CREATE_TOPO: flow.update(dt, iter_max=100, verbose=False) else: topography_last=topography Topo_norm, error_Topo=1,1 i=0 while error_Topo > TOPO_TOL * Topo_norm: flow.setStatus(t, v_old, p_old, stress_old) flow.setExternals(f=-SURFACE_LOAD*(topography-dt*v)*unitVector(DIM-1,DIM)*top_boundary_mask, restoration_factor=SURFACE_LOAD*dt*top_boundary_mask) flow.update(dt, iter_max=100, verbose=False) v=flow.getVelocity() mts.setTopography(topography_old) mts.setVelocity(v) topography_last, topography=topography, mts.update(dt, allow_substeps=True) error_Topo=sqrt(integrate(((topography-topography_last)*top_boundary_mask)**2)) Topo_norm=sqrt(integrate((topography*top_boundary_mask)**2)) #print("topography update step %d error = %e, norm = %e."%(i, error_Topo, Topo_norm), Lsup(v)) i+=1 if i > TOPO_ITER_MAX: raise RuntimeError("topography did not converge after %d steps."%TOPO_ITER_MAX) v=flow.getVelocity() #for d in range(DIM): #print("range %d-velocity "%d,inf(v[d]),sup(v[d])) #print("Courant = ",inf(dom.getSize()/(length(v)+1e-19)), inf(dom.getSize()**2)) print("<%s> flow solver completed."%time.asctime()) n+=1 t+=dt #print("influx= ",integrate(inner(v,dom.getNormal())), sqrt(integrate(length(v)**2,FunctionOnBoundary(dom))), integrate(1., FunctionOnBoundary(dom))) print("<%s> Time step %d (t=%e) completed."%(time.asctime(),n,t))
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: a0=1 a1=1 n0=2 n1=2 n2=0.5 a2=-(a0*n0+a1*n1)/n2 v[0]=a0*sin(pi*n0*x[0])* cos(pi*n1*x[1])* cos(pi*n2*x[2]) v[1]=a1*cos(pi*n0*x[0])* sin(pi*n1*x[1])* cos(pi*n2*x[2]) v[2]=a2*cos(pi*n0*x[0])* cos(pi*n1*x[1])* sin(pi*n2*x[2]) mts=Mountains(mydomain,eps=EPS) while t<T_END: print("STEP ", t) mts.setVelocity(v*cos(OMEGA*t)) Z=mts.update() saveVTK("state.%d.vtu"%n,sol=Z, v=mts.getVelocity()) print("Integral(Z)=",integrate(Z),Lsup(mts.getVelocity()[DIM-1])) n+=1 t+=mts.getSafeTimeStepSize()
flow.update(dt, iter_max=100, verbose=False) else: topography_last = topography Topo_norm, error_Topo = 1, 1 i = 0 while error_Topo > TOPO_TOL * Topo_norm: flow.setStatus(t, v_old, p_old, stress_old) flow.setExternals(f=-SURFACE_LOAD * (topography - dt * v) * unitVector(DIM - 1, DIM) * top_boundary_mask, restoration_factor=SURFACE_LOAD * dt * top_boundary_mask) flow.update(dt, iter_max=100, verbose=False) v = flow.getVelocity() mts.setTopography(topography_old) mts.setVelocity(v) topography_last, topography = topography, mts.update( dt, allow_substeps=True) error_Topo = sqrt( integrate( ((topography - topography_last) * top_boundary_mask)**2)) Topo_norm = sqrt(integrate((topography * top_boundary_mask)**2)) #print("topography update step %d error = %e, norm = %e."%(i, error_Topo, Topo_norm), Lsup(v)) i += 1 if i > TOPO_ITER_MAX: raise RuntimeError( "topography did not converge after %d steps." % TOPO_ITER_MAX) v = flow.getVelocity() #for d in range(DIM): #print("range %d-velocity "%d,inf(v[d]),sup(v[d])) #print("Courant = ",inf(dom.getSize()/(length(v)+1e-19)), inf(dom.getSize()**2)) print("<%s> flow solver completed." % time.asctime())