Skip to content
Permalink
Browse files

Merge pull request #1584 from nilsleiffischer/mutate_apply_action

Move MutateApply action and add test
  • Loading branch information...
nilsdeppe committed Jun 26, 2019
2 parents 95e36b4 + 585e4ab commit ed41521bdde3c62c1d85937234b38484a030f01e

This file was deleted.

@@ -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
@@ -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)
@@ -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
)
@@ -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);
}
@@ -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.
You can’t perform that action at this time.