return Min(nu_out, 2e15) # would introduce a viscosity limit nu = visc(u) epsilon = sym(grad(u)) F = (2*nu*inner(epsilon, grad(v)) - div(u)*q - div(v)*p)*dx - inner(v, f)*dx dF = derivative(F, w) pde = NonlinearVariationalProblem(F, w, bcs, dF) solver = NonlinearVariationalSolver(pde) solver.parameters["symmetric"] = True solver.parameters["newton_solver"]["maximum_iterations"] = 80 solver.parameters["newton_solver"]["error_on_nonconvergence"] = False solver.parameters["newton_solver"]["relaxation_parameter"] = 0.6 solver.parameters["newton_solver"]["relative_tolerance"] = 1E-4 solver.parameters["newton_solver"]["linear_solver"] = 'superlu_dist' solver.solve() (u, p) = w.split(deepcopy=True) # Save the final solution ufilename = "velocity_%s" % (fname) fu = HDF5File(mesh.mpi_comm(),os.path.join(data_dir, ufilename+".hdf5"), 'w') fu.write(u, "/velocity") # Save the final solution for visualisation save_pvd("3D_velocity_%s" % (fname), u) print "end of ice dynamics"
mb_func = set_mb(s_new, Q3, dofsQ3, dofsQ3_x) # if constant value shall be set #mb_func = Function(Q3) #mb_func.assign(Constant(0.0)) # Set velocity on the computational mesh v_new = set_velocity(velocity, s_new, s_new_bed_ini, Q3, V3, dofV3_x, dofsV3, bed_diff1) v_vert = set_verticalvelocity(velocity, s_new, s_new_bed_ini, Q3, dofsQ3, dofsQ3_x, bed_diff1) # Compute exptected mass change due to mass balance rate field [mb_start, mb0_start] = mb_change(mb_func, hice_start, dt_ADV, Q3) mb_mass0 = hice_t0 - assemble(mb0_start * dx) # Save fields for visualisation # save_pvd("rmesh_hicestart", hice_start, pvd_number=tna) save_pvd("rmesh_ft0", mb_func) # save_pvd("rmesh_snew", s_new, pvd_number=tna) save_pvd("rmesh_vnew", v_new, pvd_number=tna) save_pvd("rmesh_vert", v_vert, pvd_number=tna) # save_pvd("rmesh_ice", h_ice1, pvd_number=tna) # save_pvd("rmesh_bed", s_new_bed, pvd_number=tna) # Compute surface gradient DG = VectorFunctionSpace(Rmesh, 'DG', 0) grad2 = project(grad(s_new), DG) save_pvd("rmesh_grad2", grad2, pvd_number=tna) # -------------------- START of SURFACE EVOLUTION ------------------------- # Perform computation on 2D computational mesh # Required in SUPG stabilisation h = CellSize(Rmesh)
[mb_start, mb0_start] = mb_change(mb_func, hice_start, dt_ADV, Q3) mb_mass0 = hice_t0 - assemble(mb0_start * dx) # Save fields for visualisation # save_pvd("rmesh_hicestart", hice_start, pvd_number=tna) # save_pvd("rmesh_ft0", mb_func) # save_pvd("rmesh_snew", s_new, pvd_number=tna) # save_pvd("rmesh_vnew", v_new, pvd_number=tna) # save_pvd("rmesh_vert", v_vert, pvd_number=tna) # save_pvd("rmesh_ice", h_ice1, pvd_number=tna) # save_pvd("rmesh_bed", s_new_bed, pvd_number=tna) # Compute surface gradient DG = VectorFunctionSpace(Rmesh, 'DG', 0) grad2 = project(grad(s_new), DG) save_pvd("rmesh_grad2", grad2, pvd_number=tna) # Interpolate all parameters into DG FunctionSpace Q_dg = FunctionSpace(Rmesh, "DG", 1) V_dg = VectorFunctionSpace(Rmesh, "DG", 1) snew_dg = interpolate(s_new, Q_dg) snewbed_dg = interpolate(s_new_bed, Q_dg) mbfunc_dg = interpolate(mb_func, Q_dg) vnew_dg = interpolate(v_new, V_dg) vvert_dg = interpolate(v_vert, Q_dg) # -------------------- START of SURFACE EVOLUTION ------------------------- # Perform computation on 2D computational mesh # Required in SUPG stabilisation h = CellSize(Rmesh) n = FacetNormal(Rmesh)
class BoundaryEast(SubDomain): def inside(self, x, on_boundary): return on_boundary and (near(x[0], nx2)) north = BoundaryNorth() south = BoundarySouth() west = BoundaryWest() east = BoundaryEast() # Mark boundaries north.mark(boundaries, 106) south.mark(boundaries, 104) west.mark(boundaries, 105) east.mark(boundaries, 103) # Save mesh to hdf5 m3filename = fname fu10 = HDF5File(mesh.mpi_comm(), os.path.join(data_dir, m3filename + ".hdf5"), 'w') fu10.write(mesh, "/mesh") #fu10.write(subdomains, "/subdomains") fu10.write(boundaries, "/boundaries") # Save for visualisation save_pvd("3D_mesh_%s" % (fname), mesh) #save_pvd("3D_boundaries_%s" % (fname), boundaries) print "read mesh done - t1: ", t1, mesh.hmin()