db2.data['S'] = db2.data['B'] + db2.data['H'] H = db2.get_nearest_expression("H") S = db2.get_nearest_expression("S") B = db2.get_nearest_expression("B") M = db2.get_nearest_expression("mask") T_s = db1.get_nearest_expression("srfTemp") q_geo = db1.get_nearest_expression("q_geo") adot = db1.get_nearest_expression("adot") U_ob = dm.get_projection("U_ob", near=True) u = dm.get_nearest_expression("vx") v = dm.get_nearest_expression("vy") model = model.Model() model.set_mesh(mesh) model.set_geometry(S, B, deform=True) model.calculate_boundaries(mask=M, adot=adot) model.set_parameters(pc.IceParameters()) model.initialize_variables() # constraints on optimization for beta : class Bounds_max(Expression): def eval(self, values, x): if M(x[0], x[1], x[2]) > 0: values[0] = 2 * DOLFIN_EPS else: values[0] = 100000.0 # initial friction coef :
class UExpression(Expression): def eval(self, values, x): values[0] = u(x) class VExpression(Expression): def eval(self, values, x): values[0] = v(x) class WExpression(Expression): def eval(self, values, x): values[0] = w(x) # Setup the model model = model.Model() model.set_mesh(mesh) model.set_geometry(S, B, deform=True) # Output the two meshes for comparison print("Writing meshes") File(out_dir + "full_mesh.pvd") << mesh_model.mesh File(out_dir + "part_mesh.pvd") << model.mesh # Apparently the smb is only used in the transient solver with free-surface # so adot isn't projected onto the mesh otherwise by the steady solver. # In order to view adot in paraview, I'll just output it manually adot_out = project(adot,model.Q) File(out_dir + '/adot.pvd') << adot_out print("Doing some stuff") u_out = project(UExpression(),model.Q) v_out = project(VExpression(),model.Q)
# Now deform the refined mesh to match the surface and bed velocity refined_mesh = Mesh(mesh_name + ".xml") # Expression for the bed elevation class BedExpression(Expression): def eval(self, values, x): # Get the z coordinate for this x value values[0] = bed(x[0],x[1]) # Expression for the surface elevation class SurfaceExpression(Expression): def eval(self, values, x): # Get the surface value at a point #values[0] = surface(x[0],x[1]) values[0] = surface(x[0],x[1]) model = model.Model() # Set the mesh to the non-deformed anisotropic mesh model.set_mesh(refined_mesh) # Deform it to match the surface and bed geometry model.set_geometry(SurfaceExpression(element = model.Q.ufl_element()), BedExpression(element = model.Q.ufl_element()), deform = False) model.deform_mesh_to_geometry() plot(model.mesh, interactive = True) # Save the mesh File(mesh_name + '_deformed.xml') << model.mesh File(mesh_name + '_deformed.pvd') << model.mesh print(len(model.mesh.coordinates()[:]))
adot = d1.get_expression("acca", near=True) T_s = d1.get_interpolation("temp", near=True) q_geo = d1.get_interpolation("ghfsr", near=True) u = dm.get_interpolation("vx", near=True) v = dm.get_interpolation("vy", near=True) U_ob = dm.get_interpolation("U_ob", near=True) config = default_config() config['output_path'] = out_dir config['model_order'] = 'SSA' model = model.Model() model.set_mesh(mesh) #model.calculate_boundaries(mask=M, adot=adot) #model.set_geometry(S, B, deform=True) model.set_geometry(S, B, deform=False) adot = interpolate(adot, model.Q) mask = interpolate(M, model.Q) # do not need this in 3D (not deformed) : #XDMFFile(mesh.mpi_comm(), out_dir + 'mesh.xdmf') << model.mesh # save the state of the model : f = HDF5File(mesh.mpi_comm(), out_dir + 'vars.h5', 'w') #f.write(model.ff, 'ff') #f.write(model.cf, 'cf') #f.write(model.ff_acc, 'ff_acc') f.write(model.S, 'S') f.write(model.B, 'B') f.write(T_s, 'T_s')
nx = 20 ny = 20 nz = 10 model = model.Model() model.generate_uniform_mesh(nx, ny, nz, xmin=0, xmax=L, ymin=0, ymax=L) surface = Expression('1300 - x[0] * tan(alpha)', alpha=alpha, element=model.Q.ufl_element()) bed = Expression( '1300 - x[0] * tan(alpha) - 1000.0 + 500.0 * ' \ + ' sin(2*pi*x[0]/L) * sin(2*pi*x[1]/L)', alpha=alpha, L=L, element=model.Q.ufl_element()) beta = Expression( '10 + 10 * sin(2*pi*x[0]/L) * sin(2*pi*x[1]/L)', alpha=alpha, L=L, element=model.Q.ufl_element()) model.set_geometry(surface, bed, deform=True) model.set_parameters(pc.IceParameters()) model.calculate_boundaries() model.initialize_variables() File('output/beta.pvd') << interpolate(beta, model.Q) # specifify non-linear solver parameters : nonlin_solver_params = default_nonlin_solver_params() nonlin_solver_params['newton_solver']['relaxation_parameter'] = 0.9 nonlin_solver_params['newton_solver']['relative_tolerance'] = 1e-14 nonlin_solver_params['newton_solver']['maximum_iterations'] = 25 nonlin_solver_params['newton_solver']['error_on_nonconvergence'] = False nonlin_solver_params['newton_solver']['linear_solver'] = 'mumps' nonlin_solver_params['newton_solver']['preconditioner'] = 'default' parameters['form_compiler']['quadrature_degree'] = 2