示例#1
0
def make_one_timestep(t, dt, cTold, c1old):

    ts_manager = FixedTimeStep(dt)
    # ts_manager = TimeStepManager(initial_timestep=720,)
    newton = ComPASS.newton.Newton(simulation, 1e-5, 20,
                                   ComPASS.newton.LinearSolver(
                                       1e-6,
                                       150))  # simulation.default_Newton() #
    context = SimulationContext()
    # do cT first (linear)
    set_concentrations(cTold)
    set_injection("cT")
    clear_source_term()

    timestep.make_one_timestep(newton,
                               ts_manager.steps(),
                               simulation_context=context)

    cTnew = retrieve_concentrations()

    print("---------- cT --> c1 ------------------")

    # Next do c1, solve non-linear system with Newton Krylov
    def freac(c1, cT):
        return Keq * rhos * cTbar * (c1 / (cT + (Keq - 1) * c1))

    fc1old = freac(c1old, cTold)

    def fchim(cprev):
        set_concentrations(c1old)
        set_injection("c1")
        set_source_term((freac(cprev, cTnew) - fc1old) / dt)

        timestep.make_one_timestep(newton,
                                   ts_manager.steps(),
                                   simulation_context=context)
        return retrieve_concentrations()

    cinit = c1old
    c1new = newton_krylov(lambda c: c - fchim(c),
                          cinit,
                          method="lgmres",
                          verbose=1)

    return cTnew, c1new
示例#2
0
文件: transport.py 项目: BRGM/ComPASS
    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

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
output_period = 0.1 * final_time