-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1584 from nilsleiffischer/mutate_apply_action
Move MutateApply action and add test
- Loading branch information
Showing
6 changed files
with
152 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <tuple> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
|
||
/// \cond | ||
namespace tuples { | ||
template <typename...> | ||
class TaggedTuple; | ||
} // namespace tuples | ||
|
||
namespace Parallel { | ||
template <typename Metavariables> | ||
class ConstGlobalCache; | ||
} // namespace Parallel | ||
/// \endcond | ||
|
||
namespace Actions { | ||
/*! | ||
* \ingroup ActionsGroup | ||
* \brief Apply the function `Mutator::apply` to the DataBox | ||
* | ||
* The function `Mutator::apply` is invoked with the `Mutator::argument_tags`. | ||
* The result of this computation is stored in the `Mutator::return_tags`. | ||
* | ||
* Uses: | ||
* - DataBox: | ||
* - All elements in `Mutator::argument_tags` | ||
* | ||
* DataBox changes: | ||
* - Modifies: | ||
* - All elements in `Mutator::return_tags` | ||
*/ | ||
template <typename Mutator> | ||
struct MutateApply { | ||
template <typename DataBox, typename... InboxTags, typename Metavariables, | ||
typename ArrayIndex, typename ActionList, | ||
typename ParallelComponent> | ||
static std::tuple<DataBox&&> apply( | ||
DataBox& box, const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, | ||
const Parallel::ConstGlobalCache<Metavariables>& /*cache*/, | ||
const ArrayIndex& /*array_index*/, const ActionList /*meta*/, | ||
const ParallelComponent* const /*meta*/) noexcept { | ||
db::mutate_apply<Mutator>(make_not_null(&box)); | ||
return {std::move(box)}; | ||
} | ||
}; | ||
} // namespace Actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Distributed under the MIT License. | ||
# See LICENSE.txt for details. | ||
|
||
set(LIBRARY "Test_ParallelAlgorithmsActions") | ||
|
||
set(LIBRARY_SOURCES | ||
Test_MutateApply.cpp | ||
) | ||
|
||
add_test_library( | ||
${LIBRARY} | ||
"ParallelAlgorithms/Actions/" | ||
"${LIBRARY_SOURCES}" | ||
"DataStructures" | ||
) | ||
|
||
add_dependencies( | ||
${LIBRARY} | ||
module_ConstGlobalCache | ||
) |
74 changes: 74 additions & 0 deletions
74
tests/Unit/ParallelAlgorithms/Actions/Test_MutateApply.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "tests/Unit/TestingFramework.hpp" | ||
|
||
#include <string> | ||
|
||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "Parallel/AddOptionsToDataBox.hpp" | ||
#include "Parallel/PhaseDependentActionList.hpp" | ||
#include "ParallelAlgorithms/Actions/MutateApply.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
#include "tests/Unit/ActionTesting.hpp" | ||
|
||
namespace { | ||
|
||
struct SomeNumber : db::SimpleTag { | ||
using type = int; | ||
static std::string name() noexcept { return "SomeNumber"; } | ||
}; | ||
|
||
struct TestValue : db::SimpleTag { | ||
using type = int; | ||
static std::string name() noexcept { return "TestValue"; } | ||
}; | ||
|
||
struct AddTheNumber { | ||
using argument_tags = tmpl::list<SomeNumber>; | ||
using return_tags = tmpl::list<TestValue>; | ||
static void apply(const gsl::not_null<int*> test_value, | ||
const int& some_number) noexcept { | ||
*test_value += some_number; | ||
} | ||
}; | ||
|
||
template <typename Metavariables> | ||
struct Component { | ||
using metavariables = Metavariables; | ||
using chare_type = ActionTesting::MockArrayChare; | ||
using array_index = int; | ||
using const_global_cache_tag_list = tmpl::list<>; | ||
using add_options_to_databox = Parallel::AddNoOptionsToDataBox; | ||
using phase_dependent_action_list = tmpl::list< | ||
Parallel::PhaseActions<typename Metavariables::Phase, | ||
Metavariables::Phase::Initialization, | ||
tmpl::list<ActionTesting::InitializeDataBox< | ||
tmpl::list<TestValue, SomeNumber>>>>, | ||
|
||
Parallel::PhaseActions<typename Metavariables::Phase, | ||
Metavariables::Phase::Testing, | ||
tmpl::list<::Actions::MutateApply<AddTheNumber>>>>; | ||
}; | ||
|
||
struct Metavariables { | ||
using component_list = tmpl::list<Component<Metavariables>>; | ||
using const_global_cache_tag_list = tmpl::list<>; | ||
enum class Phase { Initialization, Testing, Exit }; | ||
}; | ||
|
||
} // namespace | ||
|
||
SPECTRE_TEST_CASE("Unit.Actions.MutateApply", "[Unit][Actions]") { | ||
using component = Component<Metavariables>; | ||
|
||
ActionTesting::MockRuntimeSystem<Metavariables> runner{{}}; | ||
ActionTesting::emplace_component_and_initialize<component>(&runner, 0, | ||
{1, 3}); | ||
|
||
runner.set_phase(Metavariables::Phase::Testing); | ||
|
||
ActionTesting::next_action<component>(make_not_null(&runner), 0); | ||
CHECK(ActionTesting::get_databox_tag<component, TestValue>(runner, 0) == 4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Distributed under the MIT License. | ||
# See LICENSE.txt for details. | ||
|
||
add_subdirectory(Actions) |