Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
LoopSmoothingLengthIter.cpp
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
17#include "shambase/memory.hpp"
25
27
28 template<class Tvec>
30 StackEntry stack_loc{};
31
32 auto edges = get_edges();
33
34 auto &eps_h = edges.eps_h;
35 auto &is_converged = edges.is_converged;
36
37 Tscal local_min_eps_h = -1;
38 Tscal local_max_eps_h = shambase::get_max<Tscal>();
39
40 u32 iter_h = 0;
41 for (; iter_h < h_iter_per_subcycles; iter_h++) {
42
43 shambase::get_check_ref(iterate_smth_length_once_ptr).evaluate();
44
45 local_max_eps_h = shamrock::solvergraph::get_rank_max(eps_h);
46
47 shamlog_debug_ln("Smoothinglength", "iteration :", iter_h, "epsmax", local_max_eps_h);
48
49 // either converged or require gz re-exchange
50 if (local_max_eps_h < epsilon_h) {
51 break;
52 }
53 }
54
55 local_min_eps_h = shamrock::solvergraph::get_rank_min(eps_h);
56
57 // if a particle need a gz update eps_h is set to -1
58 bool local_should_rerun_gz = local_min_eps_h < 0;
59 bool local_is_h_below_tol = local_max_eps_h < epsilon_h;
60
61 bool local_is_converged = local_is_h_below_tol && (!local_should_rerun_gz);
62
63 is_converged.value
64 = shamalgs::collective::are_all_rank_true(local_is_converged, MPI_COMM_WORLD);
65
66 if (is_converged.value && print_info) {
67
68 Tscal min_eps_h = shamalgs::collective::allreduce_min(local_min_eps_h);
69 Tscal max_eps_h = shamalgs::collective::allreduce_max(local_max_eps_h);
70
71 if (shamcomm::world_rank() == 0) {
72 std::string log = "";
73 log += "smoothing length iteration converged\n";
74 log += shambase::format(
75 " eps min = {}, max = {}\n iterations = {}", min_eps_h, max_eps_h, iter_h);
76
77 logger::info_ln("Smoothinglength", log);
78 }
79 }
80 }
81
82 template<class Tvec>
84 return "TODO";
85 }
86
87} // namespace shammodels::sph::modules
Declares the LoopSmoothingLengthIter module for looping over the smoothing length iteration until con...
std::uint32_t u32
32 bit unsigned integer
Collective boolean reduction to check if all ranks have true as input.
virtual std::string _impl_get_tex() const
get the tex of the node
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 sph model modules
Functions related to the MPI communicator.