Skip to content

Commit

Permalink
Merge pull request #1584 from nilsleiffischer/mutate_apply_action
Browse files Browse the repository at this point in the history
Move MutateApply action and add test
  • Loading branch information
nilsdeppe committed Jun 26, 2019
2 parents 95e36b4 + 585e4ab commit ed41521
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 58 deletions.
58 changes: 0 additions & 58 deletions src/DataStructures/DataBox/Actions/MutateApply.hpp

This file was deleted.

53 changes: 53 additions & 0 deletions src/ParallelAlgorithms/Actions/MutateApply.hpp
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
1 change: 1 addition & 0 deletions tests/Unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_subdirectory(Informer)
add_subdirectory(NumericalAlgorithms)
add_subdirectory(Options)
add_subdirectory(Parallel)
add_subdirectory(ParallelAlgorithms)
add_subdirectory(PointwiseFunctions)
add_subdirectory(Pypp)
add_subdirectory(TestUtilities)
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/ParallelAlgorithms/Actions/CMakeLists.txt
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 tests/Unit/ParallelAlgorithms/Actions/Test_MutateApply.cpp
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);
}
4 changes: 4 additions & 0 deletions tests/Unit/ParallelAlgorithms/CMakeLists.txt
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)

0 comments on commit ed41521

Please sign in to comment.