def CladdingR_solver(FC_mesh, FC_facets, FC_fs, FC_info, D_post, R_path): FC_fi, FC_fo = FC_fs h, Tfc_inner, Tb, FC_Tave = FC_info # Reading mesh data stored in .xdmf files. mesh = Mesh() with XDMFFile(FC_mesh) as infile: infile.read(mesh) mvc = MeshValueCollection("size_t", mesh, 1) with XDMFFile(FC_facets) as infile: infile.read(mvc, "name_to_read") mf = cpp.mesh.MeshFunctionSizet(mesh, mvc) #File("Circle_facet.pvd").write(mf) # Mesh data print('CladdingRod_mesh data\n', 'Number of cells: ', mesh.num_cells(), '\n Number of nodes: ', mesh.num_vertices()) # Define variational problem V = FunctionSpace(mesh, 'P', 1) u = Function(V) v = TestFunction(V) # Define boundary conditions base on pygmsh mesh mark bc = DirichletBC(V, Constant(Tfc_inner), mf, FC_fi) ds = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=FC_fo) # Variational formulation # Klbda_ZrO2 = 18/1000 # W/(m K) --> Nuclear reactor original source # Klbda_ZrO2 = Constant(K_ZrO2(FC_Tave)) F = K_ZrO2(u) * dot(grad(u), grad(v)) * dx + h * (u - Tb) * v * ds # Compute solution du = TrialFunction(V) Gain = derivative(F, u, du) solve(F==0, u, bc, J=Gain, \ solver_parameters={"newton_solver": {"linear_solver": "lu", "relative_tolerance": 1e-9}}, \ form_compiler_parameters={"cpp_optimize": True, "representation": "uflacs", "quadrature_degree" : 2} ) # mumps # Save solution if D_post: fU_out = XDMFFile(os.path.join(R_path, 'FuelCladding', 'u.xdmf')) fU_out.write_checkpoint(u, "T", 0, XDMFFile.Encoding.HDF5, False) fU_out.close()
def FuelR_solver(FR_mesh, FR_facets, FR_f, FRod_info, D_post, R_path): Qv, Tfr_outer, FR_Tave = FRod_info # Reading mesh data stored in .xdmf files. mesh = Mesh() with XDMFFile(FR_mesh) as infile: infile.read(mesh) mvc = MeshValueCollection("size_t", mesh, 1) with XDMFFile(FR_facets) as infile: infile.read(mvc, "name_to_read") mf = cpp.mesh.MeshFunctionSizet(mesh, mvc) #File("Circle_facet.pvd").write(mf) # Mesh data print('FuelRod_mesh data\n', 'Number of cells: ', mesh.num_cells(), '\n Number of nodes: ', mesh.num_vertices()) # Define variational problem V = FunctionSpace(mesh, 'P', 1) u = Function(V) v = TestFunction(V) f = Constant(Qv) # Define boundary conditions base on pygmsh mesh mark bc = DirichletBC(V, Constant(Tfr_outer), mf, FR_f) # Variational formulation # Klbda_UO2 = Constant(K_UO2(FR_Tave)) F = K_UO2(u) * dot(grad(u), grad(v)) * dx - f * v * dx # Compute solution du = TrialFunction(V) Gain = derivative(F, u, du) solve(F==0, u, bc, J=Gain, \ solver_parameters={"newton_solver": {"linear_solver": "lu", "relative_tolerance": 1e-9}}, \ form_compiler_parameters={"cpp_optimize": True, "representation": "uflacs", "quadrature_degree" : 2} ) # mumps # Save solution if D_post: fU_out = XDMFFile(os.path.join(R_path, 'FuelRod', 'u.xdmf')) fU_out.write_checkpoint(u, "T", 0, XDMFFile.Encoding.HDF5, False) fU_out.close()
class XDMFWriter(object): def __init__(self, directory, file): self.outputFile = XDMFFile("{}/{}.xdmf".format(directory, file)) self.outputFile.parameters["rewrite_function_mesh"] = False self.outputFile.parameters["functions_share_mesh"] = True def writeSingle(self, solution, time=0.0): self.outputFile.write(solution, time) def writeMultiple(self, solutionList, time=0.0): for solution in solutionList: self.outputFile.write(solution, time) def close(self): self.outputFile.close()
p.increment(Udiv, ustar, np.array([2, 3], dtype=np.uintp), theta_p, step) del (t1) if step == 2: theta_L.assign(1.0) if step % store_step == 0: t1 = Timer("[P] Storing xdmf fields, just output!") # Set output, also throw out particle output xdmf_rho.write_checkpoint(rho, "rho", t, append=True) xdmf_u.write(Uh.sub(0), t) xdmf_p.write(Uh.sub(1), t) # Save particle data p.dump2file(mesh, fname_list, property_list, 'ab', False) comm.barrier() del (t1) timer.stop() xdmf_u.close() xdmf_rho.close() xdmf_p.close() time_table = timings(TimingClear.keep, [TimingType.wall]) with open(outdir_base + "timings" + str(nx) + ".log", "w") as out: out.write(time_table.str(True)) if comm.rank == 0: sht.copy2('./LockExchange.py', outdir_base)
# Compute solution solver.solve(S.vector(), b) (u, U) = S.split(True) # Update previous time step update(u, u0, v0, a0, beta, gamma, dt) update(U, U0, V0, A0, beta, gamma, dt) # time_array_x, time_array_y = time_to_pml_border(u_s_0, u0, time_array_x,time_array_y, t, Lx, Ly, n) # Save solution to XDMF file format xdmf_file.write(u, t) if record and rec_counter % 2 == 0: pvd << (u0,t) rec_counter += 1 #s = p.linspace(0,Lx+2*Ly, n) #file_time = open('filename_time_to_pml.obj', 'w') #pickle.dump([s,time_array_x,time_array_y], file_time) #plt.plot(s, time_array_x) #plt.plot(s, time_array_y) #plt.show() # Close file xdmf_file.close()
ap.do_step(float(dt)) lstsq_psi.project(psi_h, lb, ub) psi_h_min = min(psi_h_min, psi_h.vector().min()) psi_h_max = max(psi_h_max, psi_h.vector().max()) if comm.rank == 0: print("Min max phi {} {}".format(psi_h_min, psi_h_max)) if step % store_step == 0: outfile.write_checkpoint(psi_h, function_name="psi", time_step=t, append=True) # Dump particles to file p.dump2file(mesh, fname_list, property_list, "ab") timer.stop() area_end = assemble(psi_h * dx) num_part = p.number_of_particles() l2_error = np.sqrt(abs(assemble((psi_h0 - psi_h) * (psi_h0 - psi_h) * dx))) if comm.Get_rank() == 0: print("Num cells " + str(mesh.num_entities_global(2))) print("Num particles " + str(num_part)) print("Elapsed time " + str(timer.elapsed()[0])) print("Area error " + str(abs(area_end - area_0))) print("Error " + str(l2_error)) print("Min max phi {} {}".format(psi_h_min, psi_h_max)) outfile.close()
output_field.write_checkpoint(psi_h, function_name="psi", time_step=step * float(dt), append=True) # Write conservation data if comm.rank == 0: area_error = abs(np.float64((area_n - area_0))) with open(conservation_data, "a") as write_file: data = [step * float(dt), area_n, area_error] writer = csv.writer(write_file) writer.writerow( ["{:10.7g}".format(val) for val in data]) del t1 timer.stop() output_field.close() # Particle output p.dump2file(mesh, fname_list, property_list, "wb") # Compute error (we should accurately recover initial condition) l2_error = sqrt( abs( assemble( dot(psi_h - psi0_expression, psi_h - psi0_expression) * dx))) num_part = p.number_of_particles() if comm.Get_rank() == 0: print("l2 error " + str(l2_error))
Uvector = 3 * as_backend_type(u_n.vector()).get_local() _3u_n.vector().set_local(Uvector) _3u_A, _3u_B, _3u_C, _3u_T = _3u_n.split() _u_D = _3u_C if Data_postprocessing: fA_out.write_checkpoint(_u_A, "A", t, XDMFFile.Encoding.HDF5, True) fB_out.write_checkpoint(_u_B, "B", t, XDMFFile.Encoding.HDF5, True) fC_out.write_checkpoint(_u_C, "C", t, XDMFFile.Encoding.HDF5, True) fD_out.write_checkpoint(_u_D, "D", t, XDMFFile.Encoding.HDF5, True) fT_out.write_checkpoint(_u_T, "T", t, XDMFFile.Encoding.HDF5, True) Twall_n = Twall ufl_integral = assemble(_u_T * ds_wall) Numer = (roW * Vw * Cpw) / dt * Twall_n + fw * Cpw * Tcool_in + hw * A * ufl_integral Twall_new = Numer / Denom print('Wall temperature {} K'.format(np.around(float(Twall_new), 4))) Twall.assign(Twall_new) u_n.assign(u) fA_out.close() fB_out.close() fC_out.close() fD_out.close() fT_out.close() End_St = dtm.datetime.now() # The end time of execution---------------------- Execution_time(Start_St, End_St, 'Reports', 'PhtAnh_PBR', True) # _______________END_______________ #