Skip to content

Commit

Permalink
Add functionality needed to have empty vars for MC system
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Foucart committed Dec 20, 2024
1 parent 4176489 commit c6e137f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
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

0 comments on commit c6e137f

Please sign in to comment.