Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Solver.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
22#include "shambackends/vec.hpp"
23#include "shamcomm/logs.hpp"
31
33 template<class Tvec, class TgridVec>
34 class Solver {
35 public:
36 using Tscal = shambase::VecComponent<Tvec>;
37 using Tgridscal = shambase::VecComponent<TgridVec>;
39
40 using u_morton = u64;
42
43 using AMRBlock = typename Config::AMRBlock;
44
45 ShamrockCtx &context;
46 inline PatchScheduler &scheduler() { return shambase::get_check_ref(context.sched); }
47
48 Config solver_config;
49
51
52 inline void init_required_fields() { solver_config.set_layout(context.get_pdl_write()); }
53
54 Solver(ShamrockCtx &context) : context(context) {}
55
56 void do_debug_vtk_dump(std::string filename);
57
58 inline void print_timestep_logs() {
59 if (shamcomm::world_rank() == 0) {
60 // logger::info_ln("Godunov", "iteration since start :",
61 // solve_logs.get_iteration_count());
62 logger::info_ln(
63 "Godunov", "time since start :", shambase::details::get_wtime(), "(s)");
64 }
65 }
66
67 void evolve_once();
68
69 inline Tscal evolve_once_time_expl(Tscal t_current, Tscal dt_input) {
70 solver_config.set_time(t_current);
71 solver_config.set_next_dt(dt_input);
73 return solver_config.get_dt();
74 }
75
76 inline bool evolve_until(Tscal target_time, i32 niter_max) {
77 auto step = [&]() {
78 Tscal dt = solver_config.get_dt();
79 Tscal t = solver_config.get_time();
80
81 if (t > target_time) {
83 "the target time is higher than the current time");
84 }
85
86 if (t + dt > target_time) {
87 solver_config.set_next_dt(target_time - t);
88 }
90 };
91
92 i32 iter_count = 0;
93
94 while (solver_config.get_time() < target_time) {
95 step();
96 iter_count++;
97
98 if ((iter_count >= niter_max) && (niter_max != -1)) {
99 logger::info_ln("SPH", "stopping evolve until because of niter =", iter_count);
100 return false;
101 }
102 }
103
104 print_timestep_logs();
105
106 return true;
107 }
108
109 void init_solver_graph();
110 };
111
112} // namespace shammodels::basegodunov
utility to manipulate AMR blocks
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
The MPI scheduler.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
namespace for the basegodunov model
utility class to handle AMR blocks
Definition AMRBlock.hpp:35
Tscal get_time()
Get the current time.
void set_next_dt(Tscal dt)
Set the time step for the next iteration.
Tscal get_dt()
Get the time step for the next iteration.
void set_time(Tscal t)
Set the current time.