def transport_concentrations(self, t, ts_manager, Cold, srcF): Nc = Cold.shape[0] Cnew = np.zeros_like(Cold) compute_all_concentrations = True newton = Newton( self.simulation, 1e-5, 30, LinearSolver(1e-6, 150) ) # self.simulation.default_Newton() context = SimulationContext() # self.plot_pressure() # while loop to find suitable dt (other strategies are possible...) while compute_all_concentrations: for i in range(Nc): print("espece ========> ", i) # print ("ts_manager.current_step ========> ", ts_manager.current_step) self.set_source_term(srcF[i, :] / ts_manager.current_step) self.set_concentrations(Cold[i, :]) self.set_states_inj( self.simulation.dirichlet_node_states(), self.simulation.vertices()[:, 0], self.simulation.vertices()[:, 1], i, ) deltat = timestep.make_one_timestep( newton, ts_manager.steps(), simulation_context=context ) Cnew[i, :] = self.retrieve_concentrations() else: compute_all_concentrations = ( False # job is done all concentrations have been computed with dt ) # self.plot_1D_concentrations(t, Cnew) return Cnew
state.S[:] = [1, 0] state.C[:] = [[1.0, 0.0], [0.0, 1.0]] def set_variable_initial_bc_values(): set_states(simulation.node_states(), Topz - simulation.vertices()[:, 2]) set_states(simulation.cell_states(), Topz - simulation.compute_cell_centers()[:, 2]) set_FreeFlow_state(simulation.node_states()) set_Dirichlet_state(simulation.dirichlet_node_states()) master_print("set initial and BC") set_variable_initial_bc_values() # set linear solver properties newton = Newton(simulation, 1e-7, 15, LinearSolver(1e-6, 50)) context = SimulationContext() context.abort_on_ksp_failure = False context.dump_system_on_ksp_failure = False context.abort_on_newton_failure = False timestep = TimeStepManager( initial_timestep=100.0, minimum_timestep=1e-3, maximum_timestep=10.0 * year, increase_factor=1.2, decrease_factor=0.2, ) final_time = 100.0 * year
X0 = simulation.build_state(p=p0, T=T0) simulation.all_states().set(X0) simulation.dirichlet_node_states().set(X0) def set_boundary_heat_flux(): Neumann = ComPASS.NeumannBC() Neumann.heat_flux = bottom_heat_flux face_centers = simulation.face_centers() simulation.set_Neumann_faces(face_centers[:, 2] <= -H, Neumann) set_boundary_heat_flux() newton = Newton(simulation, 1e-5, 3, LinearSolver(1e-6, 150)) context = SimulationContext() context.abort_on_ksp_failure = False context.dump_system_on_ksp_failure = False context.abort_on_newton_failure = False final_time = 2e6 * year # ComPASS.set_maximum_timestep(0.1*final_time) current_time = standard_loop( simulation, final_time=final_time, nitermax=140, time_step_manager=TimeStepManager( 1 * day, # initial time steps increase_factor=1.2,
states.C[:] = 1.0 for states in [ComPASS.node_states(), ComPASS.cell_states()]: set_initial_states(states) def set_dirichlet_states(): states = ComPASS.dirichlet_node_states() set_initial_states(states) states.T[:] = u(ComPASS.vertices()) set_dirichlet_states() newton = Newton(1e-5, 3, LinearSolver(1e-8, 150)) context = SimulationContext() context.abort_on_ksp_failure = False context.dump_system_on_ksp_failure = False context.abort_on_newton_failure = False final_time = 10.0 standard_loop( fixed_timestep=1.0, final_time=final_time, output_period=0.1 * final_time, # nitermax=1, context=context, newton=newton, )
Neumann.molar_flux[:] = liq_molar_fraction_qbin[:] * qbin Neumann.heat_flux = qbin * simulation.liquid_molar_enthalpy( pbot, Tbot_input, liq_molar_fraction_qbin) simulation.set_Neumann_faces(neumann_heat_faces, Neumann) # master_print('set initial and BC') sys.stdout.write("set initial and BC" + "\n") set_variable_initial_bc_values() # master_print('set Neumann BC') sys.stdout.write("set Neumann BC" + "\n") set_variable_boundary_heat_flux() sys.stdout.flush() # set linear solver properties newton = Newton(simulation, 1e-5, 10, LinearSolver(1e-6, 50)) context = SimulationContext() context.abort_on_ksp_failure = False context.dump_system_on_ksp_failure = False context.abort_on_newton_failure = False timestep = TimeStepManager( initial_timestep=1000.0, minimum_timestep=1e-8, maximum_timestep=10.0 * year, increase_factor=1.2, decrease_factor=0.2, ) final_time = 300.0 * year
# np.savetxt("save_Tp_OP123.txt", save_Tp_OP123) # # print('time==', t) # ########################## # ## Plot Results # ########################## # #plt.clf() # # cmap = plt.get_cmap("tab10") # # plt.figure(1) # # plt.plot(xcoord, T, color='red', label='Simulated '+ str(round(t,0)) +'s' ) # # plt.legend() ############################################################## ### set linear solver properties ############################################################## # save_Tp_OP123 = [] newton = Newton(1e-7, 15, LinearSolver(1e-6, 50)) context = SimulationContext() context.abort_on_ksp_failure = False context.dump_system_on_ksp_failure = False context.abort_on_newton_failure = False timestep = TimeStepManager( initial_timestep=1, minimum_timestep=1e-7, maximum_timestep=10.0 * year, increase_factor=1.2, decrease_factor=0.2, ) final_time = 100 * hour