def mult(self, mat, x, y, inc=False): with self.cfn.dat.vec as v: x.copy(v) firedrake.prolong(self.cfn, self.ffn) for bc in self.fbcs: bc.zero(self.ffn) with self.ffn.dat.vec_ro as v: if inc: y.axpy(1.0, v) else: v.copy(y)
def prolong(c, f): return firedrake.prolong(c, f)
def interpolate(self, vector, out): Tc = vector.fun for Tinter in self.intermediate_Ts: fd.prolong(Tc, Tinter) Tc = Tinter fd.prolong(Tc, out)
u_in = firedrake.Function(V_in) input_name = os.path.splitext(args.input)[0] with firedrake.DumbCheckpoint(input_name, mode=firedrake.FILE_READ) as chk: timesteps, indices = chk.get_timesteps() chk.set_timestep(timesteps[-1], idx=indices[-1]) chk.load(h_in, name='h') chk.load(u_in, name='u') if args.input_level < args.output_level: # Prolong the input data to the output function space h0 = firedrake.Function(Q) u0 = firedrake.Function(V) firedrake.prolong(h_in, h0) firedrake.prolong(u_in, u0) else: h0 = h_in u0 = u_in # Otherwise create some rough initial data else: h0 = interpolate(Constant(100), Q) s0 = icepack.compute_surface(h=h0, b=z_b) u0 = solver.diagnostic_solve(velocity=interpolate( as_vector((35 * x / Lx, 0)), V), thickness=h0, surface=s0, fluidity=A, friction=C)
# increase dt until error > error_threshold while error < error_threshold: # error < error_threshold so increase dt by small amount dt = dt + step # NB: prolong does not copy so we must re-assign ref sol. fine = Function(V_fine).assign(ref) # Run the simulation with this dt try: sol = solver_CG(mesh, el=cell_type, space=space, deg=degree, T=0.50, dt=dt) error = errornorm(ref, prolong(sol, fine)) except Exception: # numerical instability occurred, exit with last stable dt dt = dt - step error = 1e10 print( "For degree {}, the error is {} using a {} s timestep".format( degree, error, dt)) # error > error_threshold, print( "Highest stable dt is {} s for a degree {} for a an error threshold of {}" .format(dt, degree, error_threshold)) dts[i, j] = dt print("------FINISHED------") print(dts)