47 inline f64 rate_sum() {
return shamalgs::collective::allreduce_sum(rate); }
49 inline u64 npart_sum() {
return shamalgs::collective::allreduce_sum(npart); }
51 inline f64 tcompute_max() {
return shamalgs::collective::allreduce_max(tcompute); }
60 template<
class Tvec,
template<
class>
class SPHKernel>
63 using Tscal = shambase::VecComponent<Tvec>;
65 using Kernel = SPHKernel<Tscal>;
71 static constexpr Tscal Rkern = Kernel::Rkern;
82 std::optional<std::function<void(
void)>> step_begin_callback;
83 std::optional<std::function<void(
void)>> step_end_callback;
85 std::vector<SolverStepCallback> timestep_callbacks{};
87 inline void init_required_fields() { solver_config.set_layout(context.get_pdl_write()); }
90 void gen_serial_patch_tree();
94 using GhostHandle = sph::BasicSPHGhostHandler<Tvec>;
95 using GhostHandleCache =
typename GhostHandle::CacheMap;
97 inline void gen_ghost_handler(Tscal time_val) {
99 using CfgClass = sph::BasicSPHGhostHandlerConfig<Tvec>;
100 using BCConfig =
typename CfgClass::Variant;
102 using BCFree =
typename CfgClass::Free;
103 using BCPeriodic =
typename CfgClass::Periodic;
104 using BCShearingPeriodic =
typename CfgClass::ShearingPeriodic;
107 using SolverBCFree =
typename SolverConfigBC::Free;
108 using SolverBCPeriodic =
typename SolverConfigBC::Periodic;
109 using SolverBCShearingPeriodic =
typename SolverConfigBC::ShearingPeriodic;
122 = std::get_if<SolverBCPeriodic>(&solver_config.
boundary_config.config)) {
130 SolverBCShearingPeriodic *c
131 = std::get_if<SolverBCShearingPeriodic>(&solver_config.
boundary_config.config)) {
136 c->shear_base, c->shear_dir, c->shear_speed * time_val, c->shear_speed},
141 inline void reset_ghost_handler() { storage.
ghost_handler.reset(); }
152 using RTree =
typename Config::RTree;
215 void vtk_do_dump(std::string filename,
bool add_patch_world_id);
217 void set_debug_dump(
bool _do_debug_dump, std::string _debug_dump_filename) {
218 solver_config.
set_debug_dump(_do_debug_dump, _debug_dump_filename);
221 inline void print_timestep_logs() {
223 logger::info_ln(
"SPH",
"iteration since start :", solve_logs.get_iteration_count());
224 logger::info_ln(
"SPH",
"time since start :", shambase::details::get_wtime(),
"(s)");
239 inline bool evolve_until(Tscal target_time,
i32 niter_max) {
244 if (t > target_time) {
246 "the target time is higher than the current time");
249 if (t + dt > target_time) {
257 while (solver_config.
get_time() < target_time) {
261 if ((iter_count >= niter_max) && (niter_max != -1)) {
262 logger::info_ln(
"SPH",
"stopping evolve until because of niter =", iter_count);
267 print_timestep_logs();
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
void reset_presteps_rint()
Resets tree radius interval field.
void reset_merge_ghosts_fields()
Resets merged ghost field data.
void update_sync_load_values()
Updates load balancing values and synchronizes patch ownership.
bool apply_corrector(Tscal dt, u64 Npart_all)
void update_derivs()
Updates time derivatives and applies external forces.
void merge_position_ghost()
Merges ghost particle positions from neighboring patches.
void reset_eos_fields()
Frees memory allocated for EOS fields.
void do_predictor_leapfrog(Tscal dt)
Performs predictor step for leapfrog integration.
void prepare_corrector()
Saves old derivative fields for predictor-corrector integration.
void build_ghost_cache()
Builds ghost particle interface cache for inter-patch communication.
void update_artificial_viscosity(Tscal dt)
Updates artificial viscosity coefficients for shock capturing.
TimestepLog evolve_once()
Performs one complete SPH timestep evolution.
void vtk_do_dump(std::string filename, bool add_patch_world_id)
Writes VTK dump file for visualization.
void build_merged_pos_trees()
Builds spatial BVH trees for merged positions including ghosts.
void clear_merged_pos_trees()
Clears merged position trees to free memory.
void init_solver_graph()
Initializes the solver graph for computation pipeline.
void sph_prestep(Tscal time_val, Tscal dt)
Performs pre-step operations for SPH timestep.
void compute_presteps_rint()
Computes maximum smoothing length in tree nodes for neighbor search.
void compute_eos_fields()
Computes equation of state fields (pressure, sound speed)
void apply_position_boundary(Tscal time_val)
Applies position-based boundary conditions.
void reset_neighbors_cache()
Resets neighbor cache.
Tscal evolve_once_time_expl(Tscal t_current, Tscal dt_input)
Evolves system by one explicit timestep with specified time and dt.
void communicate_merge_ghosts_fields()
Communicates and merges ghost particle fields across processes.
void clear_ghost_cache()
Clears ghost particle cache to free memory.
void init_ghost_layout()
Initializes data layout for ghost particle fields.
void start_neighbors_cache()
Builds neighbor particle cache for SPH calculations.
This header file contains utility functions related to exception handling in the code.
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...
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
namespace for the sph model
std::shared_ptr< shamrock::solvergraph::RankGetter > patch_rank_owner
Patch rank ownership.
std::shared_ptr< shamrock::patch::PatchDataLayerLayout > xyzh_ghost_layout
Ghost data layout and merged data.
Component< SerialPatchTree< Tvec > > serial_patch_tree
Serial patch tree for load balancing.
std::shared_ptr< solvergraph::GhostHandlerEdge< Tvec > > ghost_handler
Ghost handler for boundary particles.
The configuration for a sph solver.
BCConfig boundary_config
Boundary condition configuration.
void set_time(Tscal t)
Set the current time.
Tscal get_time()
Get the current time.
void set_debug_dump(bool _do_debug_dump, std::string _debug_dump_filename)
Set whether to dump debug information to file.
u32 u_morton
The type of the Morton code for the tree.
Tscal get_dt_sph()
Get the time step for the next iteration.
BCConfig< Tvec > BCConfig
Configuration of the boundary conditions.
void set_next_dt(Tscal dt)
Set the time step for the next iteration.
Class holding the logs of the solver /todo add a variable to keep only a definite number of steps in ...