Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality needed to have empty vars for MC system #6424

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DataStructures/Variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ class Variables<tmpl::list<>> {
template <typename T>
Variables(const T* /*pointer*/, const size_t /*size*/) {}
static constexpr size_t size() { return 0; }
static constexpr size_t number_of_grid_points() { return 0; }
void assign_subset(const Variables<tmpl::list<>>& /*unused*/) {}
void assign_subset(const tuples::TaggedTuple<>& /*unused*/) {}
// Initialization for empty variables should ignore any input.
void initialize(size_t /*number_of_grid_points*/) {}
};

// gcc8 screams when the empty Variables has pup as a member function, so we
Expand Down
3 changes: 2 additions & 1 deletion src/Evolution/DgSubcell/Actions/Initialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struct SetSubcellGrid {
subcell::Tags::ReconstructionOrder<Dim>,
evolution::dg::subcell::Tags::InterpolatorsFromFdToNeighborFd<Dim>,
evolution::dg::subcell::Tags::InterpolatorsFromDgToNeighborFd<Dim>,
evolution::dg::subcell::Tags::InterpolatorsFromNeighborDgToFd<Dim>>;
evolution::dg::subcell::Tags::InterpolatorsFromNeighborDgToFd<Dim>,
typename System::variables_tag>;
using compute_tags =
tmpl::list<Tags::MeshCompute<Dim>, Tags::LogicalCoordinatesCompute<Dim>,
::domain::Tags::MappedCoordinates<
Expand Down
33 changes: 20 additions & 13 deletions src/Evolution/DgSubcell/BackgroundGrVars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ struct BackgroundGrVars : tt::ConformsTo<db::protocols::Mutator> {
cell_centered_impl(active_gr_vars, time, subcell_inertial_coords,
solution_or_data);
}

face_centered_impl(subcell_face_gr_vars, time, functions_of_time,
logical_to_grid_map, grid_to_inertial_map,
subcell_mesh, solution_or_data);
if constexpr (not std::is_same_v<
typename SubcellFaceGrVars::value_type::tags_list,
tmpl::list<>>){
face_centered_impl(subcell_face_gr_vars, time, functions_of_time,
logical_to_grid_map, grid_to_inertial_map,
subcell_mesh, solution_or_data);
}
}
}

Expand All @@ -158,19 +161,23 @@ struct BackgroundGrVars : tt::ConformsTo<db::protocols::Mutator> {
"The subcell mesh must have isotropic basis, quadrature. and "
"extents but got "
<< subcell_mesh);
const size_t num_face_centered_mesh_grid_pts =
(subcell_mesh.extents(0) + 1) * subcell_mesh.extents(1) *
subcell_mesh.extents(2);
for (size_t d = 0; d < volume_dim; ++d) {
gsl::at(*subcell_face_gr_vars, d)
.initialize(num_face_centered_mesh_grid_pts);
if constexpr (not std::is_same_v<
typename SubcellFaceGrVars::value_type::tags_list,
tmpl::list<>>){
const size_t num_face_centered_mesh_grid_pts =
(subcell_mesh.extents(0) + 1) * subcell_mesh.extents(1) *
subcell_mesh.extents(2);
for (size_t d = 0; d < volume_dim; ++d) {
gsl::at(*subcell_face_gr_vars, d)
.initialize(num_face_centered_mesh_grid_pts);
}
face_centered_impl(subcell_face_gr_vars, time, functions_of_time,
logical_to_grid_map, grid_to_inertial_map,
subcell_mesh, solution_or_data);
}

cell_centered_impl(inactive_gr_vars, time, subcell_inertial_coords,
solution_or_data);
face_centered_impl(subcell_face_gr_vars, time, functions_of_time,
logical_to_grid_map, grid_to_inertial_map,
subcell_mesh, solution_or_data);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/ParallelAlgorithms/Events/ObserveTimeStep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ class ObserveTimeStep : public Event {
const ArrayIndex& array_index,
const ParallelComponent* const /*meta*/,
const ObservationValue& observation_value) const {
const size_t number_of_grid_points = variables.number_of_grid_points();
// For empty vars, we use 1 grid point to avoid divisions by zero
// after reduction.
size_t number_of_grid_points = 1;
if constexpr (not std::is_same_v<typename System::variables_tag::tags_list,
tmpl::list<>>) {
number_of_grid_points = variables.number_of_grid_points();
}
const double slab_size = time_step.slab().duration().value();
const double step_size = abs(time_step.value());
const double wall_time = sys::wall_time();
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/DataStructures/Test_Variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void test_empty_variables() {
CHECK(get_output(tuple_with_empty_vars) == "(3,hello,{})");

CHECK(not contains_allocations(empty_vars));
// Functions do nothing, but need to compile
empty_vars.initialize(0);
const Variables<tmpl::list<>> input_vars;
empty_vars.assign_subset(input_vars);
CHECK(empty_vars.number_of_grid_points() == 0);
CHECK(empty_vars.size() == 0);
}

template <typename VectorType>
Expand Down
Loading