Skip to content

Commit

Permalink
Merge pull request #5769 from knelli2/element_dist_restriction
Browse files Browse the repository at this point in the history
Prevent NumGridPointsAndGridSpacing element dist when using GTS
  • Loading branch information
wthrowe authored Feb 17, 2024
2 parents 6f3ae8c + 66b4ccb commit 2a4c646
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 34 deletions.
18 changes: 0 additions & 18 deletions src/Domain/ElementDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "NumericalAlgorithms/Spectral/Mesh.hpp"
#include "NumericalAlgorithms/Spectral/Quadrature.hpp"
#include "Options/Options.hpp"
#include "Options/ParseError.hpp"
#include "Options/ParseOptions.hpp"
#include "Utilities/Algorithm.hpp"
#include "Utilities/ConstantExpressions.hpp"
Expand Down Expand Up @@ -343,20 +342,3 @@ GENERATE_INSTANTIATIONS(INSTANTIATION, (1, 2, 3))
#undef GET_DIM
#undef INSTANTIATION
} // namespace domain

template <>
domain::ElementWeight
Options::create_from_yaml<domain::ElementWeight>::create<void>(
const Options::Option& options) {
const auto ordering = options.parse_as<std::string>();
if (ordering == "Uniform") {
return domain::ElementWeight::Uniform;
} else if (ordering == "NumGridPoints") {
return domain::ElementWeight::NumGridPoints;
} else if (ordering == "NumGridPointsAndGridSpacing") {
return domain::ElementWeight::NumGridPointsAndGridSpacing;
}
PARSE_ERROR(options.context(),
"ElementWeight must be 'Uniform', 'NumGridPoints', or, "
"'NumGridPointsAndGridSpacing'");
}
33 changes: 27 additions & 6 deletions src/Domain/ElementDistribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include <array>
#include <cstddef>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include "Options/Options.hpp"
#include "Options/ParseError.hpp"
#include "Utilities/TypeTraits/CreateGetStaticMemberVariableOrDefault.hpp"

/// \cond
template <size_t Dim>
Expand Down Expand Up @@ -173,15 +176,33 @@ struct BlockZCurveProcDistribution {
};
} // namespace domain

namespace element_weight_detail {
CREATE_GET_STATIC_MEMBER_VARIABLE_OR_DEFAULT(local_time_stepping)
} // namespace element_weight_detail

template <>
struct Options::create_from_yaml<domain::ElementWeight> {
template <typename Metavariables>
static domain::ElementWeight create(const Options::Option& options) {
return create<void>(options);
const auto ordering = options.parse_as<std::string>();
if (ordering == "Uniform") {
return domain::ElementWeight::Uniform;
} else if (ordering == "NumGridPoints") {
return domain::ElementWeight::NumGridPoints;
} else if (ordering == "NumGridPointsAndGridSpacing") {
if constexpr (not element_weight_detail::
get_local_time_stepping_or_default_v<Metavariables,
false>) {
PARSE_ERROR(
options.context(),
"When not using local time stepping, you cannot use "
"NumGridPointsAndGridSpacing for the element distribution. Please "
"choose another element distribution.");
}
return domain::ElementWeight::NumGridPointsAndGridSpacing;
}
PARSE_ERROR(options.context(),
"ElementWeight must be 'Uniform', 'NumGridPoints', or, "
"'NumGridPointsAndGridSpacing'");
}
};

template <>
domain::ElementWeight
Options::create_from_yaml<domain::ElementWeight>::create<void>(
const Options::Option& options);
9 changes: 9 additions & 0 deletions src/Domain/Tags/ElementDistribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ struct ElementDistribution {
} // namespace OptionTags

namespace Tags {
/// \ingroup DataBoxTagsGroup
/// \ingroup ComputationalDomainGroup
/// Tag that holds method for how to distribute the elements on the given
/// resources.
///
/// \note When not using local time stepping (LTS), a user cannot choose the
/// NumGridPointsAndGridSpacing element distribution because grid spacing does
/// not affect the computational cost at all. Therefore, if a user does choose
/// NumGridPointsAndGridSpacing when not using LTS, an error will occur.
struct ElementDistribution : db::SimpleTag {
using type = std::optional<ElementWeight>;
using option_tags = tmpl::list<OptionTags::ElementDistribution>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ExpectedOutput:
---

Parallelization:
ElementDistribution: NumGridPointsAndGridSpacing
ElementDistribution: NumGridPoints

Amr:
Criteria:
Expand Down
56 changes: 47 additions & 9 deletions tests/Unit/Domain/Tags/Test_ElementDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,57 @@
#include "Helpers/DataStructures/DataBox/TestHelpers.hpp"
#include "Parallel/Tags/Parallelization.hpp"

namespace {
template <bool UseLTS>
struct TestMetavars {
static constexpr bool local_time_stepping = UseLTS;
};

template <bool UseLTS>
std::optional<domain::ElementWeight> make_option(
const std::string& option_string) {
return TestHelpers::test_option_tag<domain::OptionTags::ElementDistribution,
TestMetavars<UseLTS>>(option_string);
}

std::optional<domain::ElementWeight> make_option_without_lts_metavars(
const std::string& option_string) {
return TestHelpers::test_option_tag<domain::OptionTags::ElementDistribution>(
option_string);
}
} // namespace

SPECTRE_TEST_CASE("Unit.Domain.Tags.ElementDistribution", "[Unit][Domain]") {
TestHelpers::db::test_simple_tag<domain::Tags::ElementDistribution>(
"ElementDistribution");
const auto make_option = [](const std::string& option_string)
-> std::optional<domain::ElementWeight> {
return TestHelpers::test_option_tag<
domain::OptionTags::ElementDistribution>(option_string);
};
CHECK(make_option("Uniform") ==
CHECK(make_option<true>("Uniform") ==
std::optional{domain::ElementWeight::Uniform});
CHECK(make_option("NumGridPoints") ==
CHECK(make_option<true>("NumGridPoints") ==
std::optional{domain::ElementWeight::NumGridPoints});
CHECK(make_option("NumGridPointsAndGridSpacing") ==
CHECK(make_option<true>("NumGridPointsAndGridSpacing") ==
std::optional{domain::ElementWeight::NumGridPointsAndGridSpacing});
CHECK(make_option("RoundRobin") == std::nullopt);
CHECK(make_option<true>("RoundRobin") == std::nullopt);

CHECK(make_option<false>("Uniform") ==
std::optional{domain::ElementWeight::Uniform});
CHECK(make_option<false>("NumGridPoints") ==
std::optional{domain::ElementWeight::NumGridPoints});
CHECK_THROWS_WITH(make_option<false>("NumGridPointsAndGridSpacing"),
Catch::Matchers::ContainsSubstring(
"When not using local time stepping") and
Catch::Matchers::ContainsSubstring(
"Please choose another element distribution."));
CHECK(make_option<false>("RoundRobin") == std::nullopt);

CHECK(make_option_without_lts_metavars("Uniform") ==
std::optional{domain::ElementWeight::Uniform});
CHECK(make_option_without_lts_metavars("NumGridPoints") ==
std::optional{domain::ElementWeight::NumGridPoints});
CHECK_THROWS_WITH(
make_option_without_lts_metavars("NumGridPointsAndGridSpacing"),
Catch::Matchers::ContainsSubstring(
"When not using local time stepping") and
Catch::Matchers::ContainsSubstring(
"Please choose another element distribution."));
CHECK(make_option_without_lts_metavars("RoundRobin") == std::nullopt);
}

0 comments on commit 2a4c646

Please sign in to comment.