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
39
42 {{NeighCacheStrategy::SingleStage, "single_stage"},
43 {NeighCacheStrategy::TwoStage, "two_stage"},
44 {NeighCacheStrategy::SingleStageSharedOffload, "single_stage_shared_offload"},
45 {NeighCacheStrategy::TwoStageSharedOffload, "two_stage_shared_offload"}});
46
48 inline constexpr const char *neigh_cache_strategy_json_key = "neigh_cache_strategy";
49
51 inline constexpr const char *neigh_cache_strategy_legacy_json_key = "use_two_stage_search";
52
55 bool use_two_stage_search) {
56 return (use_two_stage_search) ? NeighCacheStrategy::TwoStage
58 }
59
75 const nlohmann::json &j,
76 NeighCacheStrategy &value,
77 const std::string &log_ctx,
78 bool &has_used_defaults,
79 bool &has_updated_config) {
80
81 if (j.contains(neigh_cache_strategy_json_key)) {
82 j.at(neigh_cache_strategy_json_key).get_to(value);
83 return;
84 }
85
88 j.at(neigh_cache_strategy_legacy_json_key).template get<bool>());
89 has_updated_config = true;
90 if (shamcomm::world_rank() == 0) {
92 log_ctx,
93 "Updating old key [" + std::string(neigh_cache_strategy_legacy_json_key)
94 + "] to new key [" + std::string(neigh_cache_strategy_json_key)
95 + "] in from_json");
96 }
97 return;
98 }
99
100 has_used_defaults = true;
101 }
102
103} // 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