Skip to content

Commit

Permalink
Merge pull request #890 from wthrowe/advance_to_start
Browse files Browse the repository at this point in the history
Use AdvanceTime action for initialization
  • Loading branch information
nilsdeppe committed Aug 24, 2018
2 parents bc042dc + 8184974 commit d6c146e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 67 deletions.
16 changes: 5 additions & 11 deletions src/Evolution/DiscontinuousGalerkin/InitializeElement.hpp
Expand Up @@ -274,16 +274,9 @@ struct InitializeElement {
using Vars = typename variables_tag::type;
using DtVars = typename dt_variables_tag::type;

const auto& time_stepper = Parallel::get<CacheTags::TimeStepper>(cache);

// This is stored as Next<TimeId> and will be used to update
// TimeId at the start of the algorithm.
const TimeId time_id(initial_dt.is_positive(), 0, initial_time);
TimeId next_time_id = time_stepper.next_time_id(time_id, initial_dt);
if (next_time_id.is_at_slab_boundary()) {
const auto next_time = next_time_id.step_time();
next_time_id = TimeId(
initial_dt.is_positive(), 1,
next_time.with_slab(next_time.slab().advance_towards(initial_dt)));
}

const size_t num_grid_points =
db::get<Tags::Mesh<Dim>>(box).number_of_grid_points();
Expand All @@ -296,6 +289,7 @@ struct InitializeElement {
typename Tags::HistoryEvolvedVariables<variables_tag,
dt_variables_tag>::type history;
using solution_tag = CacheTags::AnalyticSolutionBase;
const auto& time_stepper = Parallel::get<CacheTags::TimeStepper>(cache);
if (not time_stepper.is_self_starting()) {
// We currently just put initial points at past slab boundaries.
Time past_t = initial_time;
Expand All @@ -317,7 +311,7 @@ struct InitializeElement {
}

return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
std::move(box), time_id, next_time_id, initial_dt, std::move(dt_vars),
std::move(box), TimeId{}, time_id, initial_dt, std::move(dt_vars),
std::move(history));
}
};
Expand All @@ -344,7 +338,7 @@ struct InitializeElement {
typename Tags::Mortars<Tags::Mesh<Dim - 1>, Dim>::type mortar_meshes{};
typename Tags::Mortars<Tags::MortarSize<Dim - 1>, Dim>::type
mortar_sizes{};
const auto& temporal_id = get<temporal_id_tag>(box);
const auto& temporal_id = get<Tags::Next<temporal_id_tag>>(box);
for (const auto& direction_neighbors : element.neighbors()) {
const auto& direction = direction_neighbors.first;
const auto& neighbors = direction_neighbors.second;
Expand Down
5 changes: 3 additions & 2 deletions src/Evolution/Executables/Burgers/EvolveBurgers.hpp
Expand Up @@ -50,12 +50,13 @@ struct EvolutionMetavars {

using component_list = tmpl::list<DgElementArray<
EvolutionMetavars,
tmpl::list<Actions::ComputeVolumeFluxes,
tmpl::list<Actions::AdvanceTime, Actions::FinalTime,
Actions::ComputeVolumeFluxes,
dg::Actions::SendDataForFluxes<EvolutionMetavars>,
Actions::ComputeVolumeDuDt<1>,
dg::Actions::ReceiveDataForFluxes<EvolutionMetavars>,
dg::Actions::ApplyBoundaryFluxesGlobalTimeStepping,
Actions::UpdateU, Actions::AdvanceTime, Actions::FinalTime>>>;
Actions::UpdateU>>>;

static constexpr OptionString help{
"Evolve the Burgers equation.\n\n"
Expand Down
5 changes: 3 additions & 2 deletions src/Evolution/Executables/ScalarWave/EvolveScalarWave.hpp
Expand Up @@ -49,12 +49,13 @@ struct EvolutionMetavars {

using component_list = tmpl::list<DgElementArray<
EvolutionMetavars,
tmpl::list<Actions::ComputeVolumeDuDt<Dim>,
tmpl::list<Actions::AdvanceTime, Actions::FinalTime,
Actions::ComputeVolumeDuDt<Dim>,
dg::Actions::ComputeNonconservativeBoundaryFluxes,
dg::Actions::SendDataForFluxes<EvolutionMetavars>,
dg::Actions::ReceiveDataForFluxes<EvolutionMetavars>,
dg::Actions::ApplyBoundaryFluxesGlobalTimeStepping,
Actions::UpdateU, Actions::AdvanceTime, Actions::FinalTime>>>;
Actions::UpdateU>>>;

static constexpr OptionString help{
"Evolve a Scalar Wave in Dim spatial dimension.\n\n"
Expand Down
2 changes: 2 additions & 0 deletions src/Time/Actions/AdvanceTime.hpp
Expand Up @@ -43,6 +43,8 @@ namespace Actions {
/// - Removes: nothing
/// - Modifies: Tags::TimeId, Tags::TimeStep
struct AdvanceTime {
using const_global_cache_tags = tmpl::list<CacheTags::TimeStepper>;

template <typename DbTags, typename... InboxTags, typename Metavariables,
typename ArrayIndex, typename ActionList,
typename ParallelComponent>
Expand Down
100 changes: 48 additions & 52 deletions tests/Unit/Evolution/DiscontinuousGalerkin/Test_InitializeElement.cpp
Expand Up @@ -137,19 +137,24 @@ struct Metavariables {
using const_global_cache_tag_list = tmpl::list<>;
};

template <typename Tag, typename Box>
bool box_contains(const Box& /*box*/) noexcept {
return tmpl::list_contains_v<typename Box::tags_list, Tag>;
}

template <bool IsConservative>
struct TestConservativeOrNonconservativeParts {
template <typename Metavariables, typename DbTags>
static void apply(const gsl::not_null<db::DataBox<DbTags>*> box) noexcept {
using system = typename Metavariables::system;
constexpr size_t dim = system::volume_dim;

(void)db::get<
Tags::deriv<typename system::variables_tag::tags_list,
typename system::gradients_tags,
Tags::InverseJacobian<Tags::ElementMap<dim>,
Tags::LogicalCoordinates<dim>>>>(
*box);
CHECK(box_contains<
Tags::deriv<typename system::variables_tag::tags_list,
typename system::gradients_tags,
Tags::InverseJacobian<Tags::ElementMap<dim>,
Tags::LogicalCoordinates<dim>>>>(
*box));
}
};

Expand All @@ -171,19 +176,16 @@ struct TestConservativeOrNonconservativeParts<true> {
CHECK(db::get<db::add_tag_prefix<Tags::Source, variables_tag>>(*box)
.number_of_grid_points() == number_of_grid_points);

using flux_tag = db::add_tag_prefix<Tags::Flux, variables_tag,
tmpl::size_t<dim>, Frame::Inertial>;
// Don't try to take the divergence of NaN
db::mutate<flux_tag>(box, [](const auto vars) noexcept {
vars->initialize(vars->number_of_grid_points(), 0.);
});
(void)db::get<Tags::ComputeDiv<
flux_tag, Tags::InverseJacobian<Tags::ElementMap<dim>,
Tags::LogicalCoordinates<dim>>>>(*box);

(void)db::get<Tags::Interface<
Tags::InternalDirections<dim>,
Tags::ComputeNormalDotFlux<variables_tag, dim, Frame::Inertial>>>(*box);
CHECK(box_contains<Tags::ComputeDiv<
db::add_tag_prefix<Tags::Flux, variables_tag, tmpl::size_t<dim>,
Frame::Inertial>,
Tags::InverseJacobian<Tags::ElementMap<dim>,
Tags::LogicalCoordinates<dim>>>>(*box));

CHECK(box_contains<Tags::Interface<
Tags::InternalDirections<dim>,
Tags::ComputeNormalDotFlux<variables_tag, dim, Frame::Inertial>>>(
*box));
}
};

Expand All @@ -208,18 +210,12 @@ void test_initialize_element(
dg::Actions::InitializeElement<dim>>(
empty_box, element_id, domain_creator.initial_extents(),
domain_creator.create_domain(), slab.start(), slab.duration()));
CHECK(db::get<Tags::TimeId>(box) == TimeId(true, 0, slab.start()));
const auto expected_next_time_id =
get<CacheTags::TimeStepper>(runner.cache())
.next_time_id(TimeId(true, 0, slab.start()), slab.duration());
// The slab can differ from the expected value if the first substep
// crosses the entire slab.
CHECK(db::get<Tags::Next<Tags::TimeId>>(box).substep() ==
expected_next_time_id.substep());
CHECK(db::get<Tags::Next<Tags::TimeId>>(box).time() ==
expected_next_time_id.time());
CHECK_FALSE(db::get<Tags::Next<Tags::TimeId>>(box).time().is_at_slab_end());
CHECK(db::get<Tags::Time>(box) == slab.start());
CHECK(db::get<Tags::Next<Tags::TimeId>>(box) ==
TimeId(true, 0, slab.start()));
// The TimeId is uninitialized and is updated immediately by the
// algorithm loop.
CHECK(box_contains<Tags::TimeId>(box));
CHECK(box_contains<Tags::Time>(box));
CHECK(db::get<Tags::TimeStep>(box) == slab.duration());

const auto& my_block = domain.blocks()[element_id.block_id()];
Expand All @@ -233,9 +229,7 @@ void test_initialize_element(
CHECK(db::get<Tags::LogicalCoordinates<dim>>(box) == logical_coords);
CHECK(db::get<Tags::Mesh<dim>>(box) == mesh);
CHECK(db::get<Tags::Element<dim>>(box) == element);
// Can't test ElementMap directly, only via inverse jacobian and grid
// coordinates. We can check that we can retrieve it.
(void)db::get<Tags::ElementMap<dim>>(box);
CHECK(box_contains<Tags::ElementMap<dim>>(box));
CHECK(db::get<Var>(box) == ([&inertial_coords, &slab]() {
double time = slab.start().value();
Scalar<DataVector> var{inertial_coords.get(0) + time};
Expand Down Expand Up @@ -294,26 +288,28 @@ void test_initialize_element(
CHECK(db::get<Tags::Mortars<Tags::MortarSize<dim - 1>, dim>>(box).size() ==
element.number_of_neighbors());

(void)db::get<Tags::Interface<Tags::InternalDirections<dim>,
Tags::UnnormalizedFaceNormal<dim>>>(box);
CHECK(box_contains<Tags::Interface<Tags::InternalDirections<dim>,
Tags::UnnormalizedFaceNormal<dim>>>(box));
using magnitude_tag =
Tags::EuclideanMagnitude<Tags::UnnormalizedFaceNormal<dim>>;
(void)db::get<Tags::Interface<Tags::InternalDirections<dim>, magnitude_tag>>(
box);
(void)db::get<Tags::Interface<
Tags::InternalDirections<dim>,
Tags::Normalized<Tags::UnnormalizedFaceNormal<dim>>>>(box);
(void)db::get<Tags::Interface<Tags::InternalDirections<dim>,
typename system::variables_tag>>(box);
(void)db::get<Tags::Interface<Tags::BoundaryDirections<dim>,
Tags::UnnormalizedFaceNormal<dim>>>(box);
(void)db::get<Tags::Interface<Tags::BoundaryDirections<dim>, magnitude_tag>>(
box);
(void)db::get<Tags::Interface<
Tags::BoundaryDirections<dim>,
Tags::Normalized<Tags::UnnormalizedFaceNormal<dim>>>>(box);
(void)db::get<Tags::Interface<Tags::BoundaryDirections<dim>,
typename system::variables_tag>>(box);
CHECK(box_contains<
Tags::Interface<Tags::InternalDirections<dim>, magnitude_tag>>(box));
CHECK(box_contains<
Tags::Interface<Tags::InternalDirections<dim>,
Tags::Normalized<Tags::UnnormalizedFaceNormal<dim>>>>(
box));
CHECK(box_contains<Tags::Interface<Tags::InternalDirections<dim>,
typename system::variables_tag>>(box));
CHECK(box_contains<Tags::Interface<Tags::BoundaryDirections<dim>,
Tags::UnnormalizedFaceNormal<dim>>>(box));
CHECK(box_contains<
Tags::Interface<Tags::BoundaryDirections<dim>, magnitude_tag>>(box));
CHECK(box_contains<
Tags::Interface<Tags::BoundaryDirections<dim>,
Tags::Normalized<Tags::UnnormalizedFaceNormal<dim>>>>(
box));
CHECK(box_contains<Tags::Interface<Tags::BoundaryDirections<dim>,
typename system::variables_tag>>(box));

TestConservativeOrNonconservativeParts<system::is_conservative>::
template apply<Metavariables>(make_not_null(&box));
Expand Down

0 comments on commit d6c146e

Please sign in to comment.