mesh_mover = MeshMover(tp.meshes[0], monitor, method='monge_ampere', op=op) mesh_mover.adapt() tp.__init__(op, meshes=[Mesh(mesh_mover.x)]) # --- Solve the tracer transport problem # Note: # * Pure Lagrangian leads to tangled elements after only a few iterations # * This motivates applying monitor based methods throughout the simulation tp.set_initial_condition() init_vol = assemble(Constant(1.0) * dx(domain=tp.mesh)) init_l1_norm = norm(tp.fwd_solutions_tracer[0], norm_type='L1') init_l2_norm = norm(tp.fwd_solutions_tracer[0], norm_type='L2') init_sol = tp.fwd_solutions_tracer[0].copy(deepcopy=True) tp.solve_forward() # Compare initial and final tracer concentrations final_vol = assemble(Constant(1.0) * dx(domain=tp.mesh)) final_l1_norm = norm(tp.fwd_solutions_tracer[0], norm_type='L1') final_l2_norm = norm(tp.fwd_solutions_tracer[0], norm_type='L2') final_sol = tp.fwd_solutions_tracer[0].copy(deepcopy=True) abs_l2_error = errornorm(init_sol, final_sol, norm_type='L2') print_output("Volume error: {:.2f}%".format( 100 * abs(init_vol - final_vol) / init_vol)) print_output("Conservation error: {:.2f}%".format( 100 * abs(init_l1_norm - final_l1_norm) / init_l1_norm)) print_output("Relative L2 error: {:.2f}%".format(100 * abs_l2_error / init_l2_norm)) init_sol = init_sol.dat.data final_sol = final_sol.dat.data
mon_init = project(Constant(1.0) + comp_new2, P1) H = Function(P1) tau = TestFunction(P1) a = (inner(tau, H) * dx) + (K * inner(tau.dx(1), H.dx(1)) * dx) - inner(tau, mon_init) * dx solve(a == 0, H) return H swp.set_monitor_functions(gradient_interface_monitor) t1 = time.time() swp.solve_forward() t2 = time.time() print(t2 - t1) print(fac_x) print(alpha) print(beta) print(gamma) new_mesh = RectangleMesh(880, 20, 220, 10) bath = Function(FunctionSpace(new_mesh, "CG", 1)).project(swp.fwd_solutions_bathymetry[0]) fpath = "hydrodynamics_beach_bath_mov_{:d}_{:d}_{:d}_{:d}_{:d}"
# Misc 'debug': bool(args.debug or False), } # --- Create solver and copy initial solution ep = AdaptiveProblem(CosinePrescribedVelocityOptions(**kwargs)) ep.set_initial_condition() init_sol = ep.fwd_solutions_tracer[0].copy(deepcopy=True) init_norm = norm(init_sol) # --- Eulerian interpretation ep.solve_forward() final_sol_eulerian = ep.fwd_solutions_tracer[-1] relative_error_eulerian = abs(errornorm(init_sol, final_sol_eulerian)/init_norm) print_output("Relative error in Eulerian case: {:.2f}%".format(100*relative_error_eulerian)) # --- Lagrangian interpretation kwargs['approach'] = 'lagrangian' lp = AdaptiveProblem(CosinePrescribedVelocityOptions(**kwargs)) lp.set_initial_condition() init_sol = lp.fwd_solutions_tracer[0].copy(deepcopy=True) init_coords = lp.meshes[0].coordinates.dat.data.copy() lp.solve_forward() final_sol_lagrangian = lp.fwd_solutions_tracer[-1]