Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boundary component for Klein-Gordon CCE #5683

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions src/Evolution/Systems/Cce/Actions/InitializeWorldtubeBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ struct H5WorldtubeBoundary;
template <typename Metavariables>
struct AnalyticWorldtubeBoundary;
template <typename Metavariables>
struct KleinGordonH5WorldtubeBoundary;
template <typename Metavariables>
struct GhWorldtubeBoundary;
/// \endcond
namespace Actions {

namespace detail {
template <typename Initializer, typename ManagerTags,
typename BoundaryCommunicationTagsList>
typename... BoundaryCommunicationTagsList>
struct InitializeWorldtubeBoundaryBase {
using simple_tags_from_options = ManagerTags;
using const_global_cache_tags = tmpl::list<Tags::LMax>;

using simple_tags =
tmpl::list<::Tags::Variables<BoundaryCommunicationTagsList>>;
tmpl::list<::Tags::Variables<BoundaryCommunicationTagsList>...>;

template <typename DataBoxTagsList, typename... InboxTags,
typename ArrayIndex, typename Metavariables, typename ActionList,
Expand All @@ -78,11 +80,11 @@ struct InitializeWorldtubeBoundaryBase {
}
}
const size_t l_max = db::get<Tags::LMax>(box);
Variables<BoundaryCommunicationTagsList> boundary_variables{
Spectral::Swsh::number_of_swsh_collocation_points(l_max)};

Initialization::mutate_assign<simple_tags>(make_not_null(&box),
std::move(boundary_variables));
Initialization::mutate_assign<simple_tags>(
make_not_null(&box),
Variables<BoundaryCommunicationTagsList>{
Spectral::Swsh::number_of_swsh_collocation_points(l_max)}...);
return {Parallel::AlgorithmExecution::Continue, std::nullopt};
}
};
Expand All @@ -103,7 +105,7 @@ struct InitializeWorldtubeBoundary;
* \brief Initializes a H5WorldtubeBoundary
*
* \details Uses:
* - initialization tag
* - simple tags from options
* `Cce::Tags::H5WorldtubeBoundaryDataManager`,
* - const global cache tag `Cce::Tags::LMax`.
*
Expand Down Expand Up @@ -132,12 +134,57 @@ struct InitializeWorldtubeBoundary<H5WorldtubeBoundary<Metavariables>>
using typename base_type::simple_tags_from_options;
};

/*!
* \ingroup ActionsGroup
* \brief Initializes a KleinGordonH5WorldtubeBoundary
*
* \details Uses:
* - simple tags from options
* `Cce::Tags::H5WorldtubeBoundaryDataManager`,
* `Cce::Tags::KleinGordonH5WorldtubeBoundaryDataManager`.
* - const global cache tag `Cce::Tags::LMax`.
*
* Databox changes:
* - Adds:
* - `Cce::Tags::H5WorldtubeBoundaryDataManager`
* - `Cce::Tags::KleinGordonH5WorldtubeBoundaryDataManager`
* - `Tags::Variables<typename
* Metavariables::cce_boundary_communication_tags>`
* - `Tags::Variables<typename
* Metavariables::klein_gordon_boundary_communication_tags>`
* - Removes: nothing
* - Modifies: nothing
*/
template <typename Metavariables>
struct InitializeWorldtubeBoundary<
KleinGordonH5WorldtubeBoundary<Metavariables>>
: public detail::InitializeWorldtubeBoundaryBase<
InitializeWorldtubeBoundary<
KleinGordonH5WorldtubeBoundary<Metavariables>>,
tmpl::list<Tags::H5WorldtubeBoundaryDataManager,
Tags::KleinGordonH5WorldtubeBoundaryDataManager>,
typename Metavariables::cce_boundary_communication_tags,
typename Metavariables::klein_gordon_boundary_communication_tags> {
using base_type = detail::InitializeWorldtubeBoundaryBase<
InitializeWorldtubeBoundary<
KleinGordonH5WorldtubeBoundary<Metavariables>>,
tmpl::list<Tags::H5WorldtubeBoundaryDataManager,
Tags::KleinGordonH5WorldtubeBoundaryDataManager>,
typename Metavariables::cce_boundary_communication_tags,
typename Metavariables::klein_gordon_boundary_communication_tags>;
using base_type::apply;
using typename base_type::simple_tags;
using const_global_cache_tags =
tmpl::list<Tags::LMax, Tags::EndTimeFromFile, Tags::StartTimeFromFile>;
using typename base_type::simple_tags_from_options;
};

/*!
* \ingroup ActionsGroup
* \brief Initializes a GhWorldtubeBoundary
*
* \details Uses:
* - initialization tags
* - simple tags from options
* `Cce::Tags::GhWorldtubeBoundaryDataManager`, `Tags::GhInterfaceManager`
* - const global cache tags `Tags::LMax`, `Tags::ExtractionRadius`.
*
Expand Down Expand Up @@ -173,7 +220,7 @@ struct InitializeWorldtubeBoundary<GhWorldtubeBoundary<Metavariables>>
* \brief Initializes an AnalyticWorldtubeBoundary
*
* \details Uses:
* - initialization tag
* - simple tags from options
* `Cce::Tags::AnalyticBoundaryDataManager`,
* - const global cache tags `Tags::LMax`,
* `Tags::ExtractionRadius`.
Expand Down
44 changes: 44 additions & 0 deletions src/Evolution/Systems/Cce/Components/WorldtubeBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,50 @@ struct H5WorldtubeBoundary
using end_time_tag = Tags::EndTimeFromFile;
};

/*!
* \brief Component that supplies scalar-tensor worldtube boundary data.
*
* \details The \ref DataBoxGroup associated with the worldtube boundary
* component contains two data managers (`WorldtubeDataManager`) linked to
* one or two H5 files (scalar and tensor sectors, respectively). The data
* managers handle buffering and interpolating to desired target time points
* when requested via the simple action `BoundaryComputeAndSendToEvolution`, at
* which point they will send the required collection of boundary quantities to
* the identified `KleinGordonCharacteristicEvolution` component. It is assumed
* that the simple action `BoundaryComputeAndSendToEvolution` will only be
* called during the `Evolve` phase.
*
* Uses const global tags:
* - `Tags::LMax`
*
* `Metavariables` must contain:
* - the `enum` `Phase` with at least `Initialization` and `Evolve` phases.
* - a type alias `cce_boundary_communication_tags` for the set of tensor tags
* to send from the worldtube to the evolution component. This will typically be
* `Cce::Tags::characteristic_worldtube_boundary_tags<Tags::BoundaryValue>`.
* - a type alias `klein_gordon_boundary_communication_tags` for the set of
* scalar tags to send from the worldtube to the evolution component. This will
* typically be `Cce::Tags::klein_gordon_worldtube_boundary_tags`.
*/
template <class Metavariables>
struct KleinGordonH5WorldtubeBoundary
: public WorldtubeComponentBase<
KleinGordonH5WorldtubeBoundary<Metavariables>, Metavariables> {
using base_type =
WorldtubeComponentBase<KleinGordonH5WorldtubeBoundary<Metavariables>,
Metavariables>;
using base_type::execute_next_phase;
using base_type::initialize;
using typename base_type::chare_type;
using const_global_cache_tags =
tmpl::list<Tags::InitializeJ<Metavariables::evolve_ccm>>;
using typename base_type::metavariables;
using typename base_type::options;
using typename base_type::phase_dependent_action_list;
using typename base_type::simple_tags_from_options;
using end_time_tag = Tags::EndTimeFromFile;
};

/*!
* \brief Component that supplies CCE worldtube boundary data sourced from an
* analytic solution.
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Evolution/Systems/Cce/Actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(LIBRARY_SOURCES
Test_GhBoundaryCommunication.cpp
Test_H5BoundaryCommunication.cpp
Test_InitializeCharacteristicEvolution.cpp
Test_InitializeKleinGordonWorldtubeBoundary.cpp
Test_InitializeWorldtubeBoundary.cpp
Test_Psi0Matching.cpp
Test_RequestBoundaryData.cpp
Expand All @@ -28,6 +29,7 @@ target_link_libraries(
${LIBRARY}
PRIVATE
Cce
CceHelpers
GeneralRelativitySolutions
Interpolation
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Framework/TestingFramework.hpp"

#include "Framework/TestHelpers.hpp"
#include "Helpers/DataStructures/MakeWithRandomValues.hpp"
#include "Helpers/Evolution/Systems/Cce/Actions/WorldtubeBoundaryMocking.hpp"
#include "Helpers/Evolution/Systems/Cce/KleinGordonBoundaryTestHelpers.hpp"
#include "NumericalAlgorithms/Interpolation/BarycentricRationalSpanInterpolator.hpp"
#include "PointwiseFunctions/AnalyticSolutions/GeneralRelativity/KerrSchild.hpp"
#include "Utilities/Gsl.hpp"

namespace Cce {

namespace {

struct KleinGordonH5Metavariables {
using cce_boundary_communication_tags =
Tags::characteristic_worldtube_boundary_tags<Tags::BoundaryValue>;
using klein_gordon_boundary_communication_tags =
Tags::klein_gordon_worldtube_boundary_tags;
using component_list = tmpl::list<
mock_klein_gordon_h5_worldtube_boundary<KleinGordonH5Metavariables>>;

static constexpr bool evolve_ccm = false;
};

// This function tests the action
// `InitializeWorldtubeBoundary<KleinGordonH5WorldtubeBoundary<Metavariables>>`.
// The action is responsible for initializing the tags
// `Metavariables::cce_boundary_communication_tags` and
// `Metavariables::klein_gordon_boundary_communication_tags` for the boundary
// component. The initialization process involves reading tensor and scalar data
// separately from an HDF5 file. This is handled by two managers:
// `Tags::H5WorldtubeBoundaryDataManager` and
// `Tags::KleinGordonH5WorldtubeBoundaryDataManager`.
//
// The function begins by generating and storing some scalar and tensor data
// into an HDF5 file named `filename` using `write_scalar_tensor_test_file`.
// Subsequently, it initializes a mocked worldtube boundary component that
// contains two optional tags: `Tags::H5WorldtubeBoundaryDataManager` and
// `Tags::KleinGordonH5WorldtubeBoundaryDataManager`.
// The function then invokes the action under examination within the
// initialize-action list to initialize the specified tags. Finally, it tests
// whether the tags are in the expected state.
template <typename Generator>
void test_klein_gordon_h5_initialization(const gsl::not_null<Generator*> gen) {
using component =
mock_klein_gordon_h5_worldtube_boundary<KleinGordonH5Metavariables>;
const size_t l_max = 8;
const size_t end_time = 100.0;
const size_t start_time = 0.0;

const size_t buffer_size = 8;
const std::string filename =
"InitializeKleinGordonWorldtubeBoundaryTest_CceR0100.h5";

// create the test file, because on initialization the manager will need to
// get basic data out of the file
UniformCustomDistribution<double> value_dist{0.1, 0.5};
const double mass = value_dist(*gen);
const std::array<double, 3> spin{
{value_dist(*gen), value_dist(*gen), value_dist(*gen)}};
const std::array<double, 3> center{
{value_dist(*gen), value_dist(*gen), value_dist(*gen)}};
gr::Solutions::KerrSchild solution{mass, spin, center};

const double extraction_radius = 100.0;
const double frequency = 0.1 * value_dist(*gen);
const double amplitude = 0.1 * value_dist(*gen);
const double target_time = 50.0 * value_dist(*gen);
TestHelpers::write_scalar_tensor_test_file(solution, filename, target_time,
extraction_radius, frequency,
amplitude, l_max);

// tests start here
ActionTesting::MockRuntimeSystem<KleinGordonH5Metavariables> runner{
tuples::tagged_tuple_from_typelist<
Parallel::get_const_global_cache_tags<KleinGordonH5Metavariables>>{
l_max, end_time, start_time}};
ActionTesting::set_phase(make_not_null(&runner),
Parallel::Phase::Initialization);
ActionTesting::emplace_component<component>(
&runner, 0,
Tags::H5WorldtubeBoundaryDataManager::create_from_options(
l_max, filename, buffer_size,
std::make_unique<intrp::BarycentricRationalSpanInterpolator>(3u, 4u),
false, false, std::optional<double>{}),
Tags::KleinGordonH5WorldtubeBoundaryDataManager::create_from_options(
l_max, filename, buffer_size,
std::make_unique<intrp::BarycentricRationalSpanInterpolator>(3u, 4u),
std::optional<double>{}));

// go through the initialization list
for (size_t i = 0; i < 2; ++i) {
ActionTesting::next_action<component>(make_not_null(&runner), 0);
}
ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve);

// The tensor part:
//
// check that the tensor data manager copied out of the databox has the
// correct properties
const auto& tensor_data_manager =
ActionTesting::get_databox_tag<component,
Tags::H5WorldtubeBoundaryDataManager>(
runner, 0);
CHECK(tensor_data_manager.get_l_max() == l_max);
const auto tensor_time_span = tensor_data_manager.get_time_span();
CHECK(tensor_time_span.first == 0);
CHECK(tensor_time_span.second == 0);

// check that the tensor Variables is in the expected state (here we just make
// sure it has the right size - it shouldn't have been written to yet)
const auto& tensor_variables = ActionTesting::get_databox_tag<
component, ::Tags::Variables<typename KleinGordonH5Metavariables::
cce_boundary_communication_tags>>(runner,
0);
CHECK(
get(get<Tags::BoundaryValue<Tags::BondiBeta>>(tensor_variables)).size() ==
Spectral::Swsh::number_of_swsh_collocation_points(l_max));

// then we repeat the tests for the scalar (Klein-Gordon) part
const auto& scalar_data_manager = ActionTesting::get_databox_tag<
component, Tags::KleinGordonH5WorldtubeBoundaryDataManager>(runner, 0);
CHECK(scalar_data_manager.get_l_max() == l_max);
const auto scalar_time_span = scalar_data_manager.get_time_span();
CHECK(scalar_time_span.first == 0);
CHECK(scalar_time_span.second == 0);

// check that the scalar Variables is in the expected state (here we just make
// sure it has the right size - it shouldn't have been written to yet)
const auto& scalar_variables = ActionTesting::get_databox_tag<
component,
::Tags::Variables<typename KleinGordonH5Metavariables::
klein_gordon_boundary_communication_tags>>(runner,
0);
CHECK(get(get<Tags::BoundaryValue<Tags::KleinGordonPsi>>(scalar_variables))
.size() ==
Spectral::Swsh::number_of_swsh_collocation_points(l_max));

if (file_system::check_if_file_exists(filename)) {
file_system::rm(filename, true);
}
}
} // namespace

SPECTRE_TEST_CASE(
"Unit.Evolution.Systems.Cce.Actions.InitializeKleinGordonWorldtubeBoundary",
"[Unit][Cce]") {
MAKE_GENERATOR(gen);
test_klein_gordon_h5_initialization(make_not_null(&gen));
}
} // namespace Cce
Loading
Loading