From b4ea497474766c8897726aef10532836f5272cba Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Mon, 29 Jul 2024 16:30:51 -0600 Subject: [PATCH 01/40] make tensor indices accessible in packs --- src/interface/sparse_pack_base.cpp | 7 +++++++ src/interface/variable_state.hpp | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/interface/sparse_pack_base.cpp b/src/interface/sparse_pack_base.cpp index 5c387973804e..dc0b36fc860c 100644 --- a/src/interface/sparse_pack_base.cpp +++ b/src/interface/sparse_pack_base.cpp @@ -249,6 +249,13 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc, PARTHENON_REQUIRE( pack.pack_h_(0, b, idx).size() > 0, "Seems like this variable might not actually be allocated."); + + // Save the tensor indices for easy access + for (int l = 0; l < leading_dim; ++l) { + pack.pack_h_(l, b, idx).t = t; + pack.pack_h_(l, b, idx).u = u; + pack.pack_h_(l, b, idx).v = v; + } if (desc.flat) { coords_h(idx) = pmbd->GetBlockPointer()->coords_device; diff --git a/src/interface/variable_state.hpp b/src/interface/variable_state.hpp index d8a2ea1ba746..f25b39d423d5 100644 --- a/src/interface/variable_state.hpp +++ b/src/interface/variable_state.hpp @@ -61,7 +61,10 @@ struct VariableState : public empty_state_t { int sparse_id; int vector_component = NODIR; bool initialized = true; - + + int t{0}; + int u{0}; + int v{0}; TopologicalType topological_type = TopologicalType::Cell; TopologicalElement topological_element = TopologicalElement::CC; std::size_t tensor_components; From eac315a631001f661b2c2da16cb6cea2598d841e Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Mon, 29 Jul 2024 16:31:01 -0600 Subject: [PATCH 02/40] add radiation constant --- src/utils/constants.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/constants.hpp b/src/utils/constants.hpp index 72b706b5576f..17386cf54e61 100644 --- a/src/utils/constants.hpp +++ b/src/utils/constants.hpp @@ -117,6 +117,10 @@ class PhysicalConstants { static constexpr double stefan_boltzmann = 2.0 * M_PI * M_PI * M_PI * M_PI * M_PI * kb * kb * kb * kb / (15.0 * h * h * h * c * c); static constexpr double sb = stefan_boltzmann; + + // Radiation constant + static constexpr double radiation_constant = 4.0 * stefan_boltzmann / speed_of_light; + static constexpr double ar = radiation_constant; // Faraday constant static constexpr double faraday_constant = 96485.33645957 * capacitance; From d21f39096ad9de47bf0587387a14b7b8044da0b2 Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Tue, 30 Jul 2024 14:53:16 -0600 Subject: [PATCH 03/40] Add some nice stuff for type lists --- src/CMakeLists.txt | 1 + src/interface/make_pack_descriptor.hpp | 11 ++++ src/interface/sparse_pack.hpp | 1 + src/solvers/bicgstab_solver.hpp | 27 +++++---- src/solvers/mg_solver.hpp | 19 +++++-- src/utils/type_list.hpp | 76 ++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 src/utils/type_list.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 708d59b5ea65..7f66585a8e8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -270,6 +270,7 @@ add_library(parthenon utils/sort.hpp utils/string_utils.cpp utils/string_utils.hpp + utils/type_list.hpp utils/unique_id.cpp utils/unique_id.hpp utils/utils.hpp diff --git a/src/interface/make_pack_descriptor.hpp b/src/interface/make_pack_descriptor.hpp index f3cfe17ec4f3..7620a99a0c02 100644 --- a/src/interface/make_pack_descriptor.hpp +++ b/src/interface/make_pack_descriptor.hpp @@ -33,6 +33,7 @@ #include "interface/state_descriptor.hpp" #include "interface/variable.hpp" #include "mesh/mesh.hpp" +#include "utils/type_list.hpp" namespace parthenon { @@ -136,6 +137,16 @@ inline auto MakePackDescriptor(StateDescriptor *psd, const std::vector &v return typename SparsePack<>::Descriptor(base_desc); } +template +inline auto MakePackDescriptorFromTypeList(TypeList, Args&&... args) { + return MakePackDescriptor(std::forward(args)...); +} + +template +inline auto MakePackDescriptorFromTypeList(Args&&... args) { + return MakePackDescriptorFromTypeList(TL(), std::forward(args)...); +} + } // namespace parthenon #endif // INTERFACE_MAKE_PACK_DESCRIPTOR_HPP_ diff --git a/src/interface/sparse_pack.hpp b/src/interface/sparse_pack.hpp index b804839fa5a6..7ef7a6fe1f41 100644 --- a/src/interface/sparse_pack.hpp +++ b/src/interface/sparse_pack.hpp @@ -34,6 +34,7 @@ #include "interface/variable.hpp" #include "utils/concepts_lite.hpp" #include "utils/utils.hpp" +#include "utils/type_list.hpp" namespace parthenon { diff --git a/src/solvers/bicgstab_solver.hpp b/src/solvers/bicgstab_solver.hpp index 9f30de206478..9fa4d81d239a 100644 --- a/src/solvers/bicgstab_solver.hpp +++ b/src/solvers/bicgstab_solver.hpp @@ -24,8 +24,8 @@ #include "kokkos_abstraction.hpp" #include "solvers/mg_solver.hpp" #include "solvers/solver_utils.hpp" - #include "tasks/tasks.hpp" +#include "utils/type_list.hpp" namespace parthenon { @@ -69,21 +69,25 @@ class BiCGSTABSolver { PARTHENON_INTERNALSOLVERVARIABLE(u, r); PARTHENON_INTERNALSOLVERVARIABLE(u, p); PARTHENON_INTERNALSOLVERVARIABLE(u, x); + + using internal_types_tl = TypeList; + using preconditioner_t = MGSolver; + using all_internal_types_tl = concatenate_type_lists_t; std::vector GetInternalVariableNames() const { - std::vector names{rhat0::name(), v::name(), h::name(), s::name(), - t::name(), r::name(), p::name(), x::name()}; + std::vector names; if (params_.precondition) { - auto pre_names = preconditioner.GetInternalVariableNames(); - names.insert(names.end(), pre_names.begin(), pre_names.end()); + all_internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); + } else { + internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); } return names; } BiCGSTABSolver(StateDescriptor *pkg, BiCGSTABParams params_in, - equations eq_in = equations(), std::vector shape = {}) - : preconditioner(pkg, params_in.mg_params, eq_in, shape), params_(params_in), - iter_counter(0), eqs_(eq_in) { + equations eq_in = equations(), std::vector shape = {}, const std::string &container = "base") + : preconditioner(pkg, params_in.mg_params, eq_in, shape, container), params_(params_in), + iter_counter(0), eqs_(eq_in), container_(container) { using namespace refinement_ops; auto m_no_ghost = Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}, shape); @@ -105,8 +109,8 @@ class BiCGSTABSolver { TaskID AddTasks(TaskList &tl, TaskID dependence, Mesh *pmesh, const int partition) { using namespace utils; TaskID none; - auto &md = pmesh->mesh_data.GetOrAdd("base", partition); - std::string label = "bicg_comm_" + std::to_string(partition); + auto &md = pmesh->mesh_data.GetOrAdd(container_, partition); + std::string label = container_ + "bicg_comm_" + std::to_string(partition); auto &md_comm = pmesh->mesh_data.AddShallow(label, md, std::vector{u::name()}); iter_counter = 0; @@ -313,7 +317,7 @@ class BiCGSTABSolver { BiCGSTABParams &GetParams() { return params_; } protected: - MGSolver preconditioner; + preconditioner_t preconditioner; BiCGSTABParams params_; int iter_counter; AllReduce rtr, pAp, rhat0v, rhat0r, ts, tt, residual, rhs2; @@ -321,6 +325,7 @@ class BiCGSTABSolver { equations eqs_; Real final_residual; int final_iteration; + std::string container_; }; } // namespace solvers diff --git a/src/solvers/mg_solver.hpp b/src/solvers/mg_solver.hpp index 2a8e464503dd..4c5b7c5b9343 100644 --- a/src/solvers/mg_solver.hpp +++ b/src/solvers/mg_solver.hpp @@ -27,6 +27,7 @@ #include "solvers/solver_utils.hpp" #include "tasks/tasks.hpp" #include "utils/robust.hpp" +#include "utils/type_list.hpp" namespace parthenon { @@ -76,13 +77,17 @@ class MGSolver { PARTHENON_INTERNALSOLVERVARIABLE(u, temp); // Temporary storage PARTHENON_INTERNALSOLVERVARIABLE(u, u0); // Storage for initial solution during FAS PARTHENON_INTERNALSOLVERVARIABLE(u, D); // Storage for (approximate) diagonal + + using internal_types_tl = TypeList; std::vector GetInternalVariableNames() const { - return {res_err::name(), temp::name(), u0::name(), D::name()}; + std::vector names; + internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); + return names; } MGSolver(StateDescriptor *pkg, MGParams params_in, equations eq_in = equations(), - std::vector shape = {}) - : params_(params_in), iter_counter(0), eqs_(eq_in) { + std::vector shape = {}, const std::string& container = "base") + : params_(params_in), iter_counter(0), eqs_(eq_in), container_(container) { using namespace parthenon::refinement_ops; // The ghost cells of res_err need to be filled, but this is accomplished by // copying res_err into u, communicating, then copying u back into res_err @@ -128,7 +133,7 @@ class MGSolver { auto partitions = pmesh->GetDefaultBlockPartitions(GridIdentifier::leaf()); if (partition >= partitions.size()) PARTHENON_FAIL("Does not work with non-default partitioning."); - auto &md = pmesh->mesh_data.Add("base", partitions[partition]); + auto &md = pmesh->mesh_data.Add(container_, partitions[partition]); auto comm = AddBoundaryExchangeTasks(mg_finest, itl, md, pmesh->multilevel); auto calc_pointwise_res = eqs_.template Ax(itl, comm, md); @@ -207,6 +212,8 @@ class MGSolver { equations eqs_; Real final_residual; int final_iteration; + std::string container_; + // These functions apparently have to be public to compile with cuda since // they contain device side lambdas public: @@ -344,7 +351,7 @@ class MGSolver { auto partitions = pmesh->GetDefaultBlockPartitions(GridIdentifier::two_level_composite(level)); if (partition >= partitions.size()) return dependence; - auto &md = pmesh->mesh_data.Add("base", partitions[partition]); + auto &md = pmesh->mesh_data.Add(container_, partitions[partition]); auto task_out = dependence; if (level < max_level) { @@ -399,7 +406,7 @@ class MGSolver { auto partitions = pmesh->GetDefaultBlockPartitions(GridIdentifier::two_level_composite(level)); if (partition >= partitions.size()) return dependence; - auto &md = pmesh->mesh_data.Add("base", partitions[partition]); + auto &md = pmesh->mesh_data.Add(container_, partitions[partition]); auto &md_comm = pmesh->mesh_data.AddShallow( "mg_comm", md, std::vector{u::name(), res_err::name()}); diff --git a/src/utils/type_list.hpp b/src/utils/type_list.hpp new file mode 100644 index 000000000000..ede6ebdc4dc7 --- /dev/null +++ b/src/utils/type_list.hpp @@ -0,0 +1,76 @@ +//======================================================================================== +// (C) (or copyright) 2020-2024. Triad National Security, LLC. All rights reserved. +// +// This program was produced under U.S. Government contract 89233218CNA000001 for Los +// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC +// for the U.S. Department of Energy/National Nuclear Security Administration. All rights +// in the program are reserved by Triad National Security, LLC, and the U.S. Department +// of Energy/National Nuclear Security Administration. The Government is granted for +// itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide +// license in this material to reproduce, prepare derivative works, distribute copies to +// the public, perform publicly and display publicly, and to permit others to do so. +//======================================================================================== + +#ifndef UTILS_TYPE_LIST_HPP_ +#define UTILS_TYPE_LIST_HPP_ + +#include +#include +#include + +namespace parthenon { +template +struct TypeList { + using types = std::tuple; + + static constexpr std::size_t n_types{sizeof...(Args)}; + + template + using type = typename std::tuple_element::type; + + template + using sublist = TypeList...>; + + template + static constexpr std::size_t GetIdx(){ + static_assert(I < n_types, "Type is not present in TypeList."); + if constexpr (std::is_same_v>) { + return I; + } else { + return GetIdx(); + } + } + + template + static void IterateTypes(F func) { + (func(Args()), ...); + } + + private: + template + static auto ContinuousSublist() { + return ContinuousSublistImpl(std::make_index_sequence()); + } + template + static auto ContinuousSublistImpl(std::index_sequence) { + return sublist<(Start + Is)...>(); + } + + public: + template + using continuous_sublist = decltype(ContinuousSublist()); +}; + +namespace impl { + template + auto ConcatenateTypeLists(TypeList){return TypeList();} + + template + auto ConcatenateTypeLists(TypeList, TypeList, Args...){ return ConcatenateTypeLists(TypeList(), Args()...);} +} +template +using concatenate_type_lists_t = decltype(impl::ConcatenateTypeLists(std::declval()...)); + +} // namespace parthenon + +#endif // UTILS_TYPE_LIST_HPP_ \ No newline at end of file From 662c79224f4969608d8111beaf101893c42c2fea Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Tue, 30 Jul 2024 15:03:46 -0600 Subject: [PATCH 04/40] reorder --- src/solvers/bicgstab_solver.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solvers/bicgstab_solver.hpp b/src/solvers/bicgstab_solver.hpp index 9fa4d81d239a..a6579df0fd0b 100644 --- a/src/solvers/bicgstab_solver.hpp +++ b/src/solvers/bicgstab_solver.hpp @@ -91,7 +91,6 @@ class BiCGSTABSolver { using namespace refinement_ops; auto m_no_ghost = Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}, shape); - pkg->AddField(x::name(), m_no_ghost); pkg->AddField(rhat0::name(), m_no_ghost); pkg->AddField(v::name(), m_no_ghost); pkg->AddField(h::name(), m_no_ghost); @@ -99,6 +98,7 @@ class BiCGSTABSolver { pkg->AddField(t::name(), m_no_ghost); pkg->AddField(r::name(), m_no_ghost); pkg->AddField(p::name(), m_no_ghost); + pkg->AddField(x::name(), m_no_ghost); } template From d8306113dabf291b3ff7d3a4f5b9c22159959c3e Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Tue, 30 Jul 2024 20:56:34 -0600 Subject: [PATCH 05/40] add method for getting names from a typelist --- src/utils/type_list.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/type_list.hpp b/src/utils/type_list.hpp index ede6ebdc4dc7..ad64094a222c 100644 --- a/src/utils/type_list.hpp +++ b/src/utils/type_list.hpp @@ -68,9 +68,17 @@ namespace impl { template auto ConcatenateTypeLists(TypeList, TypeList, Args...){ return ConcatenateTypeLists(TypeList(), Args()...);} } + template using concatenate_type_lists_t = decltype(impl::ConcatenateTypeLists(std::declval()...)); +// Relevant only for lists of variable types +template +auto GetNames(){ + std::vector names; + TL::IterateTypes([&names](auto t){ names.push_back(decltype(t)::name()); }); + return names; +} } // namespace parthenon #endif // UTILS_TYPE_LIST_HPP_ \ No newline at end of file From 090a8d968f67aa9785bb6ecd9d64156d28206b5d Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Tue, 30 Jul 2024 21:47:12 -0600 Subject: [PATCH 06/40] format and lint --- src/interface/make_pack_descriptor.hpp | 8 ++-- src/interface/sparse_pack.hpp | 2 +- src/interface/sparse_pack_base.cpp | 6 +-- src/interface/variable_state.hpp | 8 ++-- src/solvers/bicgstab_solver.hpp | 21 ++++++---- src/solvers/mg_solver.hpp | 11 +++--- src/utils/constants.hpp | 4 +- src/utils/type_list.hpp | 55 +++++++++++++++----------- 8 files changed, 64 insertions(+), 51 deletions(-) diff --git a/src/interface/make_pack_descriptor.hpp b/src/interface/make_pack_descriptor.hpp index 7620a99a0c02..afae3c314787 100644 --- a/src/interface/make_pack_descriptor.hpp +++ b/src/interface/make_pack_descriptor.hpp @@ -137,13 +137,13 @@ inline auto MakePackDescriptor(StateDescriptor *psd, const std::vector &v return typename SparsePack<>::Descriptor(base_desc); } -template -inline auto MakePackDescriptorFromTypeList(TypeList, Args&&... args) { +template +inline auto MakePackDescriptorFromTypeList(TypeList, Args &&...args) { return MakePackDescriptor(std::forward(args)...); } -template -inline auto MakePackDescriptorFromTypeList(Args&&... args) { +template +inline auto MakePackDescriptorFromTypeList(Args &&...args) { return MakePackDescriptorFromTypeList(TL(), std::forward(args)...); } diff --git a/src/interface/sparse_pack.hpp b/src/interface/sparse_pack.hpp index 7ef7a6fe1f41..e939e3dc7004 100644 --- a/src/interface/sparse_pack.hpp +++ b/src/interface/sparse_pack.hpp @@ -33,8 +33,8 @@ #include "interface/sparse_pack_base.hpp" #include "interface/variable.hpp" #include "utils/concepts_lite.hpp" -#include "utils/utils.hpp" #include "utils/type_list.hpp" +#include "utils/utils.hpp" namespace parthenon { diff --git a/src/interface/sparse_pack_base.cpp b/src/interface/sparse_pack_base.cpp index dc0b36fc860c..d5a66db01498 100644 --- a/src/interface/sparse_pack_base.cpp +++ b/src/interface/sparse_pack_base.cpp @@ -249,9 +249,9 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc, PARTHENON_REQUIRE( pack.pack_h_(0, b, idx).size() > 0, "Seems like this variable might not actually be allocated."); - - // Save the tensor indices for easy access - for (int l = 0; l < leading_dim; ++l) { + + // Save the tensor indices for easy access + for (int l = 0; l < leading_dim; ++l) { pack.pack_h_(l, b, idx).t = t; pack.pack_h_(l, b, idx).u = u; pack.pack_h_(l, b, idx).v = v; diff --git a/src/interface/variable_state.hpp b/src/interface/variable_state.hpp index f25b39d423d5..5e8afcd79d7b 100644 --- a/src/interface/variable_state.hpp +++ b/src/interface/variable_state.hpp @@ -61,10 +61,10 @@ struct VariableState : public empty_state_t { int sparse_id; int vector_component = NODIR; bool initialized = true; - - int t{0}; - int u{0}; - int v{0}; + + int t{-1}; + int u{-1}; + int v{-1}; TopologicalType topological_type = TopologicalType::Cell; TopologicalElement topological_element = TopologicalElement::CC; std::size_t tensor_components; diff --git a/src/solvers/bicgstab_solver.hpp b/src/solvers/bicgstab_solver.hpp index a6579df0fd0b..caa594337b61 100644 --- a/src/solvers/bicgstab_solver.hpp +++ b/src/solvers/bicgstab_solver.hpp @@ -69,25 +69,30 @@ class BiCGSTABSolver { PARTHENON_INTERNALSOLVERVARIABLE(u, r); PARTHENON_INTERNALSOLVERVARIABLE(u, p); PARTHENON_INTERNALSOLVERVARIABLE(u, x); - + using internal_types_tl = TypeList; - using preconditioner_t = MGSolver; - using all_internal_types_tl = concatenate_type_lists_t; + using preconditioner_t = MGSolver; + using all_internal_types_tl = + concatenate_type_lists_t; std::vector GetInternalVariableNames() const { std::vector names; if (params_.precondition) { - all_internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); + all_internal_types_tl::IterateTypes( + [&names](auto t) { names.push_back(decltype(t)::name()); }); } else { - internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); + internal_types_tl::IterateTypes( + [&names](auto t) { names.push_back(decltype(t)::name()); }); } return names; } BiCGSTABSolver(StateDescriptor *pkg, BiCGSTABParams params_in, - equations eq_in = equations(), std::vector shape = {}, const std::string &container = "base") - : preconditioner(pkg, params_in.mg_params, eq_in, shape, container), params_(params_in), - iter_counter(0), eqs_(eq_in), container_(container) { + equations eq_in = equations(), std::vector shape = {}, + const std::string &container = "base") + : preconditioner(pkg, params_in.mg_params, eq_in, shape, container), + params_(params_in), iter_counter(0), eqs_(eq_in), container_(container) { using namespace refinement_ops; auto m_no_ghost = Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}, shape); diff --git a/src/solvers/mg_solver.hpp b/src/solvers/mg_solver.hpp index 4c5b7c5b9343..c44d3c020d25 100644 --- a/src/solvers/mg_solver.hpp +++ b/src/solvers/mg_solver.hpp @@ -77,16 +77,17 @@ class MGSolver { PARTHENON_INTERNALSOLVERVARIABLE(u, temp); // Temporary storage PARTHENON_INTERNALSOLVERVARIABLE(u, u0); // Storage for initial solution during FAS PARTHENON_INTERNALSOLVERVARIABLE(u, D); // Storage for (approximate) diagonal - - using internal_types_tl = TypeList; + + using internal_types_tl = TypeList; std::vector GetInternalVariableNames() const { - std::vector names; - internal_types_tl::IterateTypes([&names](auto t){names.push_back(decltype(t)::name());}); + std::vector names; + internal_types_tl::IterateTypes( + [&names](auto t) { names.push_back(decltype(t)::name()); }); return names; } MGSolver(StateDescriptor *pkg, MGParams params_in, equations eq_in = equations(), - std::vector shape = {}, const std::string& container = "base") + std::vector shape = {}, const std::string &container = "base") : params_(params_in), iter_counter(0), eqs_(eq_in), container_(container) { using namespace parthenon::refinement_ops; // The ghost cells of res_err need to be filled, but this is accomplished by diff --git a/src/utils/constants.hpp b/src/utils/constants.hpp index 17386cf54e61..69f03d6ca716 100644 --- a/src/utils/constants.hpp +++ b/src/utils/constants.hpp @@ -117,8 +117,8 @@ class PhysicalConstants { static constexpr double stefan_boltzmann = 2.0 * M_PI * M_PI * M_PI * M_PI * M_PI * kb * kb * kb * kb / (15.0 * h * h * h * c * c); static constexpr double sb = stefan_boltzmann; - - // Radiation constant + + // Radiation constant static constexpr double radiation_constant = 4.0 * stefan_boltzmann / speed_of_light; static constexpr double ar = radiation_constant; diff --git a/src/utils/type_list.hpp b/src/utils/type_list.hpp index ad64094a222c..965c4e4be9bb 100644 --- a/src/utils/type_list.hpp +++ b/src/utils/type_list.hpp @@ -14,71 +14,78 @@ #ifndef UTILS_TYPE_LIST_HPP_ #define UTILS_TYPE_LIST_HPP_ +#include #include #include #include +#include namespace parthenon { -template +template struct TypeList { using types = std::tuple; - + static constexpr std::size_t n_types{sizeof...(Args)}; template using type = typename std::tuple_element::type; - + template using sublist = TypeList...>; template - static constexpr std::size_t GetIdx(){ + static constexpr std::size_t GetIdx() { static_assert(I < n_types, "Type is not present in TypeList."); if constexpr (std::is_same_v>) { return I; } else { - return GetIdx(); + return GetIdx(); } - } - - template + } + + template static void IterateTypes(F func) { (func(Args()), ...); } - private: - template + private: + template static auto ContinuousSublist() { return ContinuousSublistImpl(std::make_index_sequence()); } - template + template static auto ContinuousSublistImpl(std::index_sequence) { return sublist<(Start + Is)...>(); } public: - template + template using continuous_sublist = decltype(ContinuousSublist()); }; namespace impl { - template - auto ConcatenateTypeLists(TypeList){return TypeList();} - - template - auto ConcatenateTypeLists(TypeList, TypeList, Args...){ return ConcatenateTypeLists(TypeList(), Args()...);} +template +auto ConcatenateTypeLists(TypeList) { + return TypeList(); +} + +template +auto ConcatenateTypeLists(TypeList, TypeList, Args...) { + return ConcatenateTypeLists(TypeList(), Args()...); } +} // namespace impl template -using concatenate_type_lists_t = decltype(impl::ConcatenateTypeLists(std::declval()...)); +using concatenate_type_lists_t = + decltype(impl::ConcatenateTypeLists(std::declval()...)); -// Relevant only for lists of variable types -template -auto GetNames(){ - std::vector names; - TL::IterateTypes([&names](auto t){ names.push_back(decltype(t)::name()); }); +// Relevant only for lists of variable types +template +auto GetNames() { + std::vector names; + TL::IterateTypes([&names](auto t) { names.push_back(decltype(t)::name()); }); return names; } } // namespace parthenon -#endif // UTILS_TYPE_LIST_HPP_ \ No newline at end of file +#endif // UTILS_TYPE_LIST_HPP_ From 052b4d331eafea0c4aeec577021fc3b67ca18323 Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Tue, 30 Jul 2024 22:03:09 -0600 Subject: [PATCH 07/40] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb66c3d573f..40075a33864a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current develop ### Added (new features/APIs/variables/...) +- [[PR 1143]](https://github.com/parthenon-hpc-lab/parthenon/pull/1143) Add tensor indices to VariableState, add radiation constant to constants, add TypeLists, allow for arbitrary containers for solvers - [[PR 1140]](https://github.com/parthenon-hpc-lab/parthenon/pull/1140) Allow for relative convergence tolerance in BiCGSTAB solver. - [[PR 1047]](https://github.com/parthenon-hpc-lab/parthenon/pull/1047) General three- and four-valent 2D forests w/ arbitrary orientations. - [[PR 1130]](https://github.com/parthenon-hpc-lab/parthenon/pull/1130) Enable `parthenon::par_reduce` for MD loops with Kokkos 1D Range From 311de157c4285cd6db6ff63c13a9e85b6c4c0533 Mon Sep 17 00:00:00 2001 From: Luke Roberts Date: Wed, 31 Jul 2024 11:00:46 -0600 Subject: [PATCH 08/40] Update src/interface/make_pack_descriptor.hpp Co-authored-by: Adam C Reyes --- src/interface/make_pack_descriptor.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/interface/make_pack_descriptor.hpp b/src/interface/make_pack_descriptor.hpp index afae3c314787..2a604338cdb7 100644 --- a/src/interface/make_pack_descriptor.hpp +++ b/src/interface/make_pack_descriptor.hpp @@ -137,8 +137,8 @@ inline auto MakePackDescriptor(StateDescriptor *psd, const std::vector &v return typename SparsePack<>::Descriptor(base_desc); } -template -inline auto MakePackDescriptorFromTypeList(TypeList, Args &&...args) { +template