def test__extrems__no_gravity(T_injection_degC=33.0, flow_velocity_m_s=1.0e-6): T_injection = degC2K(T_injection_degC) p0 = 1.0 * bar T0_degC = 5.0 T0 = degC2K(T0_degC) p_outlet = p0 permeability = 1e-12 # m^2 porosity = 0.2 final_time = 1e8 # s rhow = 1000 # kg/m3 Cw = 4200.0 # J/K/kg Kw = 0.6 # W/m/K rhor = 2600.0 # kg/m3 Cr = 800.0 # J/K/kg Kr = 2.0 # W/m/K Keq = (1 - porosity) * Kr + porosity * Kw # grid specifications extent = Lx, Ly, Lz = 1000, 10, 10 shape = nx, ny, nz = 100, 1, 1 origin = (0, -0.5 * Ly, -0.5 * Lz) simulation = ComPASS.load_eos("linear_water") ComPASS.set_output_directory_and_logfile(__file__) simulation.set_gravity(0) simulation.set_rock_volumetric_heat_capacity(rhor * Cr) p = simulation.get_fluid_properties() p.compressibility = 1e-8 grid = ComPASS.Grid(shape=shape, extent=extent, origin=origin) def outlet_nodes(): return simulation.global_vertices()[:, 0] >= Lx simulation.init( grid=grid, cell_permeability=permeability, cell_porosity=porosity, cell_thermal_conductivity=Keq, set_dirichlet_nodes=outlet_nodes, ) def set_initial_states(states): states.context[:] = 1 # liquid states.p[:] = p0 states.T[:] = T0 states.S[:] = 1 states.C[:] = 1.0 # component fraction... here only one component for states in [ simulation.dirichlet_node_states(), simulation.node_states(), simulation.cell_states(), ]: set_initial_states(states) def set_boundary_flux(): Neumann = ComPASS.NeumannBC() specific_massflux = (flow_velocity_m_s * simulation.molar_density(p0, T_injection) / (Ly * Lz)) Neumann.molar_flux[:] = specific_massflux # energy inflow is approximated using p0 Neumann.heat_flux = specific_massflux * simulation.molar_enthalpy( p0, T_injection) simulation.set_Neumann_faces(simulation.face_centers()[:, 0] <= 0, Neumann) set_boundary_flux() output_period = 0.1 * final_time # On teste a chaque pas de temps si les valeurs extremes sont bien sur les bords (boundary_idx, ) = np.where((simulation.vertices()[:, 0] >= Lx) | (simulation.vertices()[:, 0] <= 0)) def valid(arr, atol=1e-3): arr_boundary = arr[boundary_idx] r_min = arr_boundary.min(0) - atol r_max = arr_boundary.max(0) + atol g_min, g_max = arr.min(0), arr.max(0) return np.all((r_min <= g_min) & (g_min <= r_max) & (r_min <= g_max) & (g_max <= r_max)) def valid_current(iteration, time): X = simulation.node_states() assert valid(X.T) assert valid(X.p) assert valid(X.C) ##assert valid(X.S) # NON pas la saturation car la bulle se developpe avant la sortie standard_loop( simulation, final_time=final_time, time_step_manager=TimeStepManager(1 * hour, 0.2 * output_period), output_period=output_period, output_callbacks=[valid_current], )
p=p_origin, T=Ttop) simulation.all_states().set(initial_state) dirichlet = simulation.dirichlet_node_states() dirichlet.set(initial_state) # will init all variables: context, states... def set_pT_distribution(states, xyz): x, y, z = [xyz[:, j] for j in range(3)] states.p[:] = pressure_gradient(x, y) + hp(z) states.T[:] = geotherm(z) set_pT_distribution(simulation.node_states(), simulation.vertices()) set_pT_distribution(simulation.cell_states(), simulation.compute_cell_centers()) set_pT_distribution(dirichlet, simulation.vertices()) # Close all wells for wid in range(nb_random_wells): simulation.close_well(wid) final_time = 500 * year output_period = 0.1 * final_time standard_loop( simulation, final_time=final_time, time_step_manager=TimeStepManager(1 * year, output_period), output_period=output_period, )
def collect_node_temperature(iteration, t): if ComPASS.mpi.communicator().size > 1: if ComPASS.mpi.is_on_master_proc: print("WARNING - No output in parallel mode") return print("Collecting temperature at iteration", iteration) print(" and time", t / year, "years") states = simulation.cell_states() cell_temperatures.append((t, np.copy(states.T))) standard_loop( simulation, final_time=final_time, output_period=final_time / 50, time_step_manager=TimeStepManager(final_time / 1e3, 1.0), output_callbacks=(collect_node_temperature,), ) if ComPASS.mpi.communicator().size == 1: assert ComPASS.mpi.is_on_master_proc xy = simulation.compute_cell_centers()[:, 0:2] XX = xy[:, 0].reshape(ny, nx) YY = xy[:, 1].reshape(ny, nx) import ComPASS.utils.mpl_backends as mpl_backends plt = mpl_backends.import_pyplot(False) if plt: plt.clf() for tT in cell_temperatures: t, T = tT
def set_pT_distribution(states, z): states.p[:] = hp(z) states.T[:] = geotherm(z) set_pT_distribution(simulation.node_states(), simulation.vertices()[:, 2]) set_pT_distribution(simulation.cell_states(), simulation.compute_cell_centers()[:, 2]) set_pT_distribution(dirichlet, simulation.vertices()[:, 2]) # We set an *eager* timestep strategy to quickly increase timestep after closing/opening events tsmger = TimeStepManager( initial_timestep=dt_ref, maximum_timestep=day, increase_factor=2.0, decrease_factor=0.5, ) # Build well histories well_operations = [] # wells_history in colums: t(week), Q1, Q2, T1, T2 histories = np.loadtxt("wells_history.txt", usecols=(0, 1, 2, 3, 4)) t = histories[:, 0] * week if with_wells: rho_ref = simulation.liquid_molar_density(ptop, Ttop) def mass_flowrate(Qv): # m3/h to kg/s /2. => Halfdomain
state.context[node_flags == freeflow_flag] = diphasic_with_liq_outflow state.p[node_flags == freeflow_flag] = p0 state.T[node_flags == freeflow_flag] = T0 state.S[node_flags == freeflow_flag] = [0.0, 1.0] state.C[node_flags == freeflow_flag] = [[1.0, 0.0], [0.0, 1.0]] state.FreeFlow_phase_flowrate[node_flags == freeflow_flag] = 0.0 set_FreeFlow_state(simulation.node_states()) # set linear solver properties newton = Newton(simulation, 1e-6, 35, LinearSolver(1e-6, 50)) final_time = 300 * year output_period = 0.05 * final_time timestep = TimeStepManager( initial_timestep=1.0 * day, minimum_timestep=1e-3, maximum_timestep=output_period, increase_factor=1.3, decrease_factor=0.2, ) standard_loop( simulation, final_time=final_time, time_step_manager=timestep, output_period=output_period, newton=newton, )
############################################################## ### 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 output_period = final_time * 0.1 end_of_simu = standard_loop( final_time=final_time, output_period=output_period, context=context, newton=newton, time_step_manager=timestep, # iteration_callbacks = [graph_frac] # output_callbacks=[graph_frac]
states.T[:] = T0 states.S[:] = 1.0 states.C[:] = 1.0 for states in [ simulation.dirichlet_node_states(), simulation.node_states(), simulation.cell_states(), ]: set_initial_states(states) 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() final_time = 1e4 * year output_period = 1e3 * year standard_loop( simulation, final_time=final_time, time_step_manager=TimeStepManager(30 * day, output_period), output_period=output_period, )
ComPASS.cell_states(), ]: set_initial_states(states) def set_boundary_heat_flux(): Neumann = ComPASS.NeumannBC() Neumann.heat_flux = bottom_heat_flux face_centers = ComPASS.face_centers() ComPASS.set_Neumann_faces(face_centers[:, 2] <= -H, Neumann) set_boundary_heat_flux() newton = Newton(1e-5, 10, LinearSolver(1e-8, 150)) context = SimulationContext() context.abort_on_ksp_failure = True context.dump_system_on_ksp_failure = True context.abort_on_newton_failure = False final_time = 1e4 * year output_period = 1e3 * year standard_loop( final_time=final_time, output_period=output_period, time_step_manager=TimeStepManager(1 * day, 1000 * year), context=context, newton=newton, )
fracture_porosity=phi_fracture, fracture_thermal_conductivity=thermal_cond, set_dirichlet_nodes=top_nodes, ) X0 = simulation.build_state(simulation.Context.liquid, p=p0, T=T0) simulation.all_states().set(X0) simulation.dirichlet_node_states().set(X0) def set_boundary_fluxes(): Neumann = ComPASS.NeumannBC() Neumann.molar_flux[:] = qmass Neumann.heat_flux = qmass * hbottom face_centers = simulation.face_centers() bottom_fracture_edges = simulation.find_fracture_edges( face_centers[:, 2] <= -H) simulation.set_Neumann_fracture_edges(bottom_fracture_edges, Neumann) set_boundary_fluxes() final_time = 1 * day output_period = 0.1 * final_time standard_loop( simulation, final_time=final_time, time_step_manager=TimeStepManager(100, output_period), output_period=output_period, )
states.context[:] = 1 states.p[:] = p_reservoir states.T[:] = Tright states.S[:] = 1 states.C[:] = 1.0 set_states(ComPASS.node_states()) set_states(ComPASS.cell_states()) ComPASS.set_output_directory_and_logfile(__file__) ComPASS.init( mesh=grid, set_dirichlet_nodes=select_dirichlet_nodes, cell_thermal_conductivity=K_reservoir, cell_permeability=k_reservoir, cell_porosity=omega_reservoir, ) set_initial_values() set_boundary_conditions() output_period = final_time / nb_outputs standard_loop( final_time=final_time, output_period=output_period, time_step_manager=TimeStepManager(final_time / (10 * nb_steps), output_period), )