-
Notifications
You must be signed in to change notification settings - Fork 184
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 #728 from wthrowe/conservative_actions
Conservative actions
- Loading branch information
Showing
8 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
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,61 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <tuple> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "DataStructures/DataBox/Prefixes.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/Requires.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
#include "Utilities/TaggedTuple.hpp" | ||
|
||
/// \cond | ||
namespace Frame { | ||
struct Inertial; | ||
} // namespace Frame | ||
namespace Parallel { | ||
template <typename Metavariables> | ||
class ConstGlobalCache; | ||
} // namespace Parallel | ||
// IWYU pragma: no_forward_declare db::DataBox | ||
/// \endcond | ||
|
||
namespace Actions { | ||
/// \ingroup ActionsGroup | ||
/// \brief Compute the volume fluxes of the evolved variables | ||
/// | ||
/// Uses: | ||
/// - DataBox: Items in system::volume_fluxes::argument_tags | ||
/// | ||
/// DataBox changes: | ||
/// - Adds: nothing | ||
/// - Removes: nothing | ||
/// - Modifies: | ||
/// db::add_tag_prefix<Tags::Flux, variables_tag, | ||
/// tmpl::size_t<system::volume_dim>, Frame::Inertial> | ||
struct ComputeVolumeFluxes { | ||
template <typename DbTagsList, typename... InboxTags, typename Metavariables, | ||
typename ArrayIndex, typename ActionList, | ||
typename ParallelComponent, | ||
Requires<tmpl::size<DbTagsList>::value != 0> = nullptr> | ||
static auto apply(db::DataBox<DbTagsList>& box, | ||
const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, | ||
const Parallel::ConstGlobalCache<Metavariables>& /*cache*/, | ||
const ArrayIndex& /*array_index*/, | ||
const ActionList /*meta*/, | ||
const ParallelComponent* const /*meta*/) noexcept { | ||
using system = typename Metavariables::system; | ||
using variables_tag = typename system::variables_tag; | ||
db::mutate_apply<db::split_tag<db::add_tag_prefix< | ||
Tags::Flux, variables_tag, | ||
tmpl::size_t<system::volume_dim>, Frame::Inertial>>, | ||
typename system::volume_fluxes::argument_tags>( | ||
typename system::volume_fluxes{}, make_not_null(&box)); | ||
return std::forward_as_tuple(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <tuple> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "DataStructures/DataBox/Prefixes.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/Requires.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
#include "Utilities/TaggedTuple.hpp" | ||
|
||
/// \cond | ||
namespace Parallel { | ||
template <typename Metavariables> | ||
class ConstGlobalCache; | ||
} // namespace Parallel | ||
// IWYU pragma: no_forward_declare db::DataBox | ||
/// \endcond | ||
|
||
namespace Actions { | ||
/// \ingroup ActionsGroup | ||
/// \brief Compute the volume sources of the evolved variables | ||
/// | ||
/// Uses: | ||
/// - DataBox: Items in system::volume_sources::argument_tags | ||
/// | ||
/// DataBox changes: | ||
/// - Adds: nothing | ||
/// - Removes: nothing | ||
/// - Modifies: db::wrap_tags_in<Tags::Source, sourced_variables> | ||
struct ComputeVolumeSources { | ||
template <typename DbTagsList, typename... InboxTags, typename Metavariables, | ||
typename ArrayIndex, typename ActionList, | ||
typename ParallelComponent, | ||
Requires<tmpl::size<DbTagsList>::value != 0> = nullptr> | ||
static auto apply(db::DataBox<DbTagsList>& box, | ||
const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, | ||
const Parallel::ConstGlobalCache<Metavariables>& /*cache*/, | ||
const ArrayIndex& /*array_index*/, | ||
const ActionList /*meta*/, | ||
const ParallelComponent* const /*meta*/) noexcept { | ||
using system = typename Metavariables::system; | ||
db::mutate_apply< | ||
db::wrap_tags_in<Tags::Source, typename system::sourced_variables>, | ||
typename system::volume_sources::argument_tags>( | ||
typename system::volume_sources{}, make_not_null(&box)); | ||
return std::forward_as_tuple(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,23 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "tests/Unit/TestingFramework.hpp" | ||
|
||
#include <string> | ||
|
||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "DataStructures/DataBox/Prefixes.hpp" | ||
|
||
namespace { | ||
struct Tag : db::SimpleTag { | ||
static std::string name() noexcept { return "Tag"; } | ||
using type = double; | ||
}; | ||
} // namespace | ||
|
||
SPECTRE_TEST_CASE("Unit.DataStructures.DataBox.Prefixes", | ||
"[Unit][DataStructures]") { | ||
/// [source_name] | ||
CHECK(Tags::Source<Tag>::name() == "Source(" + Tag::name() + ")"); | ||
/// [source_name] | ||
} |
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,82 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "tests/Unit/TestingFramework.hpp" | ||
|
||
#include <cstddef> | ||
#include <string> | ||
#include <tuple> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "DataStructures/DataBox/Prefixes.hpp" | ||
#include "DataStructures/Tensor/Tensor.hpp" | ||
#include "Domain/ElementId.hpp" | ||
#include "Domain/ElementIndex.hpp" | ||
#include "Evolution/Actions/ComputeVolumeFluxes.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
#include "tests/Unit/ActionTesting.hpp" | ||
|
||
// IWYU pragma: no_forward_declare Tensor | ||
|
||
namespace { | ||
constexpr size_t dim = 2; | ||
|
||
struct Var1 : db::SimpleTag { | ||
static std::string name() noexcept { return "Var1"; } | ||
using type = Scalar<double>; | ||
}; | ||
|
||
struct Var2 : db::SimpleTag { | ||
static std::string name() noexcept { return "Var2"; } | ||
using type = tnsr::I<double, dim, Frame::Inertial>; | ||
}; | ||
|
||
struct ComputeFluxes { | ||
using argument_tags = tmpl::list<Var2, Var1>; | ||
static void apply( | ||
const gsl::not_null<tnsr::I<double, dim, Frame::Inertial>*> flux1, | ||
const tnsr::I<double, dim, Frame::Inertial>& var2, | ||
const Scalar<double>& var1) noexcept { | ||
get<0>(*flux1) = get(var1) * (get<0>(var2) - get<1>(var2)); | ||
get<1>(*flux1) = get(var1) * (get<0>(var2) + get<1>(var2)); | ||
} | ||
}; | ||
|
||
struct System { | ||
static constexpr size_t volume_dim = dim; | ||
using variables_tag = Var1; | ||
using volume_fluxes = ComputeFluxes; | ||
}; | ||
|
||
using ElementIndexType = ElementIndex<dim>; | ||
|
||
struct Metavariables; | ||
using component = | ||
ActionTesting::MockArrayComponent<Metavariables, ElementIndexType, | ||
tmpl::list<>, | ||
tmpl::list<Actions::ComputeVolumeFluxes>>; | ||
|
||
struct Metavariables { | ||
using component_list = tmpl::list<component>; | ||
using system = System; | ||
using const_global_cache_tag_list = tmpl::list<>; | ||
}; | ||
} // namespace | ||
|
||
SPECTRE_TEST_CASE("Unit.Evolution.ComputeVolumeFluxes", | ||
"[Unit][Evolution][Actions]") { | ||
ActionTesting::ActionRunner<Metavariables> runner{{}}; | ||
const ElementId<dim> self(1); | ||
|
||
using flux_tag = Tags::Flux<Var1, tmpl::size_t<dim>, Frame::Inertial>; | ||
auto start_box = db::create<db::AddSimpleTags<Var1, Var2, flux_tag>>( | ||
db::item_type<Var1>{{{3.}}}, db::item_type<Var2>{{{7., 12.}}}, | ||
db::item_type<flux_tag>{{{-100.}}}); | ||
|
||
const auto box = get<0>( | ||
runner.apply<component, Actions::ComputeVolumeFluxes>(start_box, self)); | ||
CHECK(get<0>(db::get<flux_tag>(box)) == -15.); | ||
CHECK(get<1>(db::get<flux_tag>(box)) == 57.); | ||
} |
98 changes: 98 additions & 0 deletions
98
tests/Unit/Evolution/Actions/Test_ComputeVolumeSources.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,98 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "tests/Unit/TestingFramework.hpp" | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <string> | ||
#include <tuple> | ||
#include <utility> | ||
|
||
#include "DataStructures/DataBox/DataBox.hpp" | ||
#include "DataStructures/DataBox/DataBoxTag.hpp" | ||
#include "DataStructures/DataBox/Prefixes.hpp" | ||
#include "DataStructures/DataVector.hpp" | ||
#include "DataStructures/Tensor/Tensor.hpp" | ||
#include "DataStructures/Variables.hpp" | ||
#include "Domain/ElementId.hpp" | ||
#include "Domain/ElementIndex.hpp" | ||
#include "Evolution/Actions/ComputeVolumeSources.hpp" | ||
#include "Utilities/Gsl.hpp" | ||
#include "Utilities/TMPL.hpp" | ||
#include "tests/Unit/ActionTesting.hpp" | ||
|
||
// IWYU pragma: no_forward_declare Tensor | ||
|
||
namespace { | ||
constexpr size_t dim = 2; | ||
|
||
struct Var1 : db::SimpleTag { | ||
static std::string name() noexcept { return "Var1"; } | ||
using type = Scalar<DataVector>; | ||
}; | ||
|
||
struct Var2 : db::SimpleTag { | ||
static std::string name() noexcept { return "Var2"; } | ||
using type = tnsr::I<DataVector, dim, Frame::Inertial>; | ||
}; | ||
|
||
struct Var3 : db::SimpleTag { | ||
static std::string name() noexcept { return "Var3"; } | ||
using type = Scalar<DataVector>; | ||
}; | ||
|
||
struct ComputeSources { | ||
using argument_tags = tmpl::list<Var1, Var3>; | ||
static void apply( | ||
const gsl::not_null<tnsr::I<DataVector, dim, Frame::Inertial>*> source2, | ||
const Scalar<DataVector>& var1, const Scalar<DataVector>& var3) noexcept { | ||
get<0>(*source2) = get(var1); | ||
get<1>(*source2) = get(var3); | ||
} | ||
}; | ||
|
||
struct System { | ||
static constexpr size_t volume_dim = dim; | ||
using variables_tag = Tags::Variables<tmpl::list<Var1, Var2>>; | ||
using sourced_variables = tmpl::list<Var2>; | ||
using volume_sources = ComputeSources; | ||
}; | ||
|
||
using ElementIndexType = ElementIndex<dim>; | ||
|
||
struct Metavariables; | ||
using component = ActionTesting::MockArrayComponent< | ||
Metavariables, ElementIndexType, tmpl::list<>, | ||
tmpl::list<Actions::ComputeVolumeSources>>; | ||
|
||
struct Metavariables { | ||
using component_list = tmpl::list<component>; | ||
using system = System; | ||
using const_global_cache_tag_list = tmpl::list<>; | ||
}; | ||
} // namespace | ||
|
||
SPECTRE_TEST_CASE("Unit.Evolution.ComputeVolumeSources", | ||
"[Unit][Evolution][Actions]") { | ||
ActionTesting::ActionRunner<Metavariables> runner{{}}; | ||
const ElementId<dim> self(1); | ||
|
||
const Scalar<DataVector> var1{{{{3., 4.}}}}; | ||
const Scalar<DataVector> var3{{{{5., 6.}}}}; | ||
|
||
db::item_type<System::variables_tag> vars(2); | ||
get<Var1>(vars) = var1; | ||
|
||
using source_tag = | ||
Tags::Source<Tags::Variables<tmpl::list<Tags::Source<Var2>>>>; | ||
|
||
auto start_box = | ||
db::create<db::AddSimpleTags<System::variables_tag, Var3, source_tag>>( | ||
std::move(vars), var3, db::item_type<source_tag>(2)); | ||
|
||
const auto box = get<0>( | ||
runner.apply<component, Actions::ComputeVolumeSources>(start_box, self)); | ||
CHECK(get<0>(db::get<Tags::Source<Var2>>(box)) == get(var1)); | ||
CHECK(get<1>(db::get<Tags::Source<Var2>>(box)) == get(var3)); | ||
} |