Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
enum_NeighCacheStrategy.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
17
19#include "nlohmann/json.hpp"
21#include <string>
22
23namespace shammodels {
24
35
38 {{NeighCacheStrategy::SingleStage, "single_stage"},
39 {NeighCacheStrategy::TwoStage, "two_stage"}});
40
42 inline constexpr const char *neigh_cache_strategy_json_key = "neigh_cache_strategy";
43
45 inline constexpr const char *neigh_cache_strategy_legacy_json_key = "use_two_stage_search";
46
49 bool use_two_stage_search) {
50 return (use_two_stage_search) ? NeighCacheStrategy::TwoStage
52 }
53
69 const nlohmann::json &j,
70 NeighCacheStrategy &value,
71 const std::string &log_ctx,
72 bool &has_used_defaults,
73 bool &has_updated_config) {
74
75 if (j.contains(neigh_cache_strategy_json_key)) {
76 j.at(neigh_cache_strategy_json_key).get_to(value);
77 return;
78 }
79
82 j.at(neigh_cache_strategy_legacy_json_key).template get<bool>());
83 has_updated_config = true;
84 if (shamcomm::world_rank() == 0) {
86 log_ctx,
87 "Updating old key [" + std::string(neigh_cache_strategy_legacy_json_key)
88 + "] to new key [" + std::string(neigh_cache_strategy_json_key)
89 + "] in from_json");
90 }
91 return;
92 }
93
94 has_used_defaults = true;
95 }
96
97} // namespace shammodels
This header file contains utility functions related to exception handling in the code.
#define SHAMROCK_JSON_SERIALIZE_ENUM(ENUM_TYPE,...)
Macro to serialize/deserialize an enum to/from a JSON object modified from the NLOHMANN_JSON_SERIALIZ...
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:41
namespace for models
Definition AMRBlock.hpp:26
constexpr const char * neigh_cache_strategy_legacy_json_key
Legacy json key, which used to hold the strategy as a boolean.
constexpr const char * neigh_cache_strategy_json_key
Json key holding the neighbour cache strategy.
void get_to_neigh_cache_strategy(const nlohmann::json &j, NeighCacheStrategy &value, const std::string &log_ctx, bool &has_used_defaults, bool &has_updated_config)
Deserialize the neighbour cache strategy, falling back on the legacy boolean key.
NeighCacheStrategy neigh_cache_strategy_from_two_stage_search(bool use_two_stage_search)
Map the legacy use_two_stage_search boolean onto the strategy enum.
NeighCacheStrategy
Strategy used to build the neighbour cache out of the tree traversal.
@ SingleStage
Single tree traversal per particle.
@ TwoStage
Two stage neighbours search (see shamrock paper).
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132