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

Use DirectionalIdMaps for data on mortars #6051

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
7 changes: 2 additions & 5 deletions src/Elliptic/DiscontinuousGalerkin/SubdomainOperator/Tags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

#pragma once

#include <boost/functional/hash.hpp>
#include <cstddef>
#include <unordered_map>

#include "DataStructures/DataBox/Tag.hpp"
#include "Domain/Structure/DirectionalId.hpp"
#include "Domain/Structure/DirectionalIdMap.hpp"

namespace elliptic::dg::subdomain_operator::Tags {

Expand All @@ -26,8 +24,7 @@ struct ExtrudingExtent : db::SimpleTag {
template <typename Tag, size_t VolumeDim>
struct NeighborMortars : db::PrefixTag, db::SimpleTag {
using tag = Tag;
using Key = DirectionalId<VolumeDim>;
using type = std::unordered_map<Key, typename Tag::type, boost::hash<Key>>;
using type = DirectionalIdMap<VolumeDim, typename Tag::type>;
};

} // namespace elliptic::dg::subdomain_operator::Tags
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ struct ReceiveDataForReconstruction {
}

using ::operator<<;
using Key = DirectionalId<Dim>;
const auto& current_time_step_id = db::get<::Tags::TimeStepId>(box);
std::map<TimeStepId,
DirectionalIdMap<Dim, evolution::dg::BoundaryData<Dim>>>& inbox =
Expand Down Expand Up @@ -351,11 +350,10 @@ struct ReceiveDataForReconstruction {
const gsl::not_null<DirectionalIdMap<Dim, GhostData>*>
ghost_data_ptr,
const gsl::not_null<RdmpTciData*> rdmp_tci_data_ptr,
const gsl::not_null<std::unordered_map<
Key, evolution::dg::MortarData<Dim>, boost::hash<Key>>*>
mortar_data,
const gsl::not_null<
std::unordered_map<Key, TimeStepId, boost::hash<Key>>*>
DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>*>
mortar_data,
const gsl::not_null<DirectionalIdMap<Dim, TimeStepId>*>
mortar_next_time_step_id,
const gsl::not_null<DirectionalIdMap<Dim, Mesh<Dim>>*>
neighbor_mesh,
Expand Down
6 changes: 2 additions & 4 deletions src/Evolution/DgSubcell/CorrectPackagedData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#pragma once

#include <algorithm>
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <unordered_map>
#include <utility>

#include "DataStructures/DataVector.hpp"
Expand All @@ -16,6 +14,7 @@
#include "DataStructures/Variables.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/DirectionalId.hpp"
#include "Domain/Structure/DirectionalIdMap.hpp"
#include "Domain/Structure/Element.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Evolution/DgSubcell/Projection.hpp"
Expand Down Expand Up @@ -77,8 +76,7 @@ void correct_package_data(
const gsl::not_null<Variables<DgPackageFieldTags>*> upper_packaged_data,
const size_t logical_dimension_to_operate_in, const Element<Dim>& element,
const Mesh<Dim>& subcell_volume_mesh,
const std::unordered_map<DirectionalId<Dim>, evolution::dg::MortarData<Dim>,
boost::hash<DirectionalId<Dim>>>& mortar_data,
const DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>& mortar_data,
const size_t variables_to_offset_in_dg_grid) {
const Direction<Dim> upper_direction{logical_dimension_to_operate_in,
Side::Upper};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ bool receive_boundary_data_global_time_stepping(
constexpr size_t volume_dim = Metavariables::system::volume_dim;

const TimeStepId& temporal_id = get<::Tags::TimeStepId>(*box);
using Key = DirectionalId<volume_dim>;
std::map<TimeStepId,
DirectionalIdMap<volume_dim,
evolution::dg::BoundaryData<volume_dim>>>& inbox =
Expand All @@ -125,8 +124,8 @@ bool receive_boundary_data_global_time_stepping(
db::get<domain::Tags::Element<volume_dim>>(*box);
for (const auto& [direction, neighbors] : element.neighbors()) {
for (const auto& neighbor : neighbors) {
const auto neighbor_received =
received_neighbor_data.find(Key{direction, neighbor});
const auto neighbor_received = received_neighbor_data.find(
DirectionalId<volume_dim>{direction, neighbor});
if (neighbor_received == received_neighbor_data.end()) {
return false;
}
Expand All @@ -147,11 +146,10 @@ bool receive_boundary_data_global_time_stepping(
evolution::dg::Tags::MortarNextTemporalId<volume_dim>,
domain::Tags::NeighborMesh<volume_dim>>(
[&received_temporal_id_and_data](
const gsl::not_null<std::unordered_map<
Key, evolution::dg::MortarData<volume_dim>, boost::hash<Key>>*>
const gsl::not_null<DirectionalIdMap<
volume_dim, evolution::dg::MortarData<volume_dim>>*>
mortar_data,
const gsl::not_null<
std::unordered_map<Key, TimeStepId, boost::hash<Key>>*>
const gsl::not_null<DirectionalIdMap<volume_dim, TimeStepId>*>
mortar_next_time_step_id,
const gsl::not_null<DirectionalIdMap<volume_dim, Mesh<volume_dim>>*>
neighbor_mesh) {
Expand Down Expand Up @@ -209,7 +207,6 @@ bool receive_boundary_data_local_time_stepping(
// using the `NormalDotNumericalFlux` prefix tag. This is because the
// returned quantity is more a `dt` quantity than a
// `NormalDotNormalDotFlux` since it's been lifted to the volume.
using Key = DirectionalId<Dim>;
std::map<TimeStepId, DirectionalIdMap<Dim, evolution::dg::BoundaryData<Dim>>>&
inbox = tuples::get<
evolution::dg::Tags::BoundaryCorrectionAndGhostCellsInbox<Dim>>(
Expand Down Expand Up @@ -238,19 +235,15 @@ bool receive_boundary_data_local_time_stepping(
evolution::dg::Tags::MortarNextTemporalId<Dim>,
domain::Tags::NeighborMesh<Dim>>(
[&inbox, &needed_time](
const gsl::not_null<
std::unordered_map<Key,
TimeSteppers::BoundaryHistory<
evolution::dg::MortarData<Dim>,
evolution::dg::MortarData<Dim>,
typename dt_variables_tag::type>,
boost::hash<Key>>*>
const gsl::not_null<DirectionalIdMap<
Dim,
TimeSteppers::BoundaryHistory<evolution::dg::MortarData<Dim>,
evolution::dg::MortarData<Dim>,
typename dt_variables_tag::type>>*>
boundary_data_history,
const gsl::not_null<
std::unordered_map<Key, TimeStepId, boost::hash<Key>>*>
const gsl::not_null<DirectionalIdMap<Dim, TimeStepId>*>
mortar_next_time_step_ids,
const gsl::not_null<DirectionalIdMap<Dim, Mesh<Dim>>*>
neighbor_mesh,
const gsl::not_null<DirectionalIdMap<Dim, Mesh<Dim>>*> neighbor_mesh,
const Element<Dim>& element) {
// Remove neighbor meshes for neighbors that don't exist anymore
domain::remove_nonexistent_neighbors(neighbor_mesh, element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,23 +787,21 @@ void ComputeTimeDerivative<Dim, EvolutionSystem, DgStepChoosers,
// using the `NormalDotNumericalFlux` prefix tag. This is because the
// returned quantity is more a `dt` quantity than a
// `NormalDotNormalDotFlux` since it's been lifted to the volume.
using Key = DirectionalId<Dim>;
const auto integration_order =
db::get<::Tags::HistoryEvolvedVariables<>>(*box).integration_order();
db::mutate<evolution::dg::Tags::MortarData<Dim>,
evolution::dg::Tags::MortarDataHistory<
Dim, typename dt_variables_tag::type>>(
[&element, integration_order, &time_step_id, using_gauss_points,
&volume_det_inv_jacobian](
const gsl::not_null<std::unordered_map<
Key, evolution::dg::MortarData<Dim>, boost::hash<Key>>*>
const gsl::not_null<
DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>*>
mortar_data,
const gsl::not_null<std::unordered_map<
Key,
TimeSteppers::BoundaryHistory<evolution::dg::MortarData<Dim>,
evolution::dg::MortarData<Dim>,
typename dt_variables_tag::type>,
boost::hash<Key>>*>
const gsl::not_null<
DirectionalIdMap<Dim, TimeSteppers::BoundaryHistory<
evolution::dg::MortarData<Dim>,
evolution::dg::MortarData<Dim>,
typename dt_variables_tag::type>>*>
boundary_data_history,
const Mesh<Dim>& volume_mesh,
const DirectionMap<Dim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

#pragma once

#include <boost/functional/hash.hpp>
#include <cstddef>
#include <optional>
#include <type_traits>
#include <unordered_map>
#include <utility>

#include "DataStructures/DataBox/DataBox.hpp"
Expand All @@ -20,6 +18,7 @@
#include "Domain/FaceNormal.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/DirectionMap.hpp"
#include "Domain/Structure/DirectionalIdMap.hpp"
#include "Domain/Structure/Element.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Domain/Tags.hpp"
Expand Down Expand Up @@ -51,9 +50,7 @@ void internal_mortar_data_impl(
evolution::dg::Tags::MagnitudeOfNormal,
evolution::dg::Tags::NormalCovector<Dim>>>>>*>
normal_covector_and_magnitude_ptr,
const gsl::not_null<
std::unordered_map<DirectionalId<Dim>, evolution::dg::MortarData<Dim>,
boost::hash<DirectionalId<Dim>>>*>
const gsl::not_null<DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>*>
mortar_data_ptr,
const gsl::not_null<gsl::span<double>*> face_temporaries,
const gsl::not_null<gsl::span<double>*> packaged_data_buffer,
Expand All @@ -67,11 +64,9 @@ void internal_mortar_data_impl(
const Variables<get_primitive_vars_tags_from_system<System>>* const
volume_primitive_variables,
const Element<Dim>& element, const Mesh<Dim>& volume_mesh,
const std::unordered_map<DirectionalId<Dim>, Mesh<Dim - 1>,
boost::hash<DirectionalId<Dim>>>& mortar_meshes,
const std::unordered_map<DirectionalId<Dim>,
std::array<Spectral::MortarSize, Dim - 1>,
boost::hash<DirectionalId<Dim>>>& mortar_sizes,
const DirectionalIdMap<Dim, Mesh<Dim - 1>>& mortar_meshes,
const DirectionalIdMap<Dim, std::array<Spectral::MortarSize, Dim - 1>>&
mortar_sizes,
const TimeStepId& temporal_id,
const domain::CoordinateMapBase<Frame::Grid, Frame::Inertial, Dim>&
moving_mesh_map,
Expand Down
41 changes: 13 additions & 28 deletions src/Evolution/DiscontinuousGalerkin/Initialization/Mortars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <array>
#include <cstddef>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

Expand All @@ -23,27 +22,18 @@

namespace evolution::dg::Initialization::detail {
namespace {
template <size_t Dim>
using Key = DirectionalId<Dim>;
template <typename MappedType, size_t Dim>
using MortarMap =
std::unordered_map<Key<Dim>, MappedType, boost::hash<Key<Dim>>>;
using MortarMap = DirectionalIdMap<Dim, MappedType>;
} // namespace

template <size_t Dim>
std::tuple<
std::unordered_map<DirectionalId<Dim>, evolution::dg::MortarData<Dim>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>, Mesh<Dim - 1>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>,
std::array<Spectral::MortarSize, Dim - 1>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>, TimeStepId,
boost::hash<DirectionalId<Dim>>>,
DirectionMap<Dim, std::optional<Variables<tmpl::list<
evolution::dg::Tags::MagnitudeOfNormal,
evolution::dg::Tags::NormalCovector<Dim>>>>>>
std::tuple<DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>,
DirectionalIdMap<Dim, Mesh<Dim - 1>>,
DirectionalIdMap<Dim, std::array<Spectral::MortarSize, Dim - 1>>,
DirectionalIdMap<Dim, TimeStepId>,
DirectionMap<Dim, std::optional<Variables<tmpl::list<
evolution::dg::Tags::MagnitudeOfNormal,
evolution::dg::Tags::NormalCovector<Dim>>>>>>
mortars_apply_impl(const std::vector<std::array<size_t, Dim>>& initial_extents,
const Spectral::Quadrature quadrature,
const Element<Dim>& element,
Expand Down Expand Up @@ -93,16 +83,11 @@ mortars_apply_impl(const std::vector<std::array<size_t, Dim>>& initial_extents,

#define INSTANTIATION(r, data) \
template std::tuple< \
std::unordered_map<DirectionalId<DIM(data)>, \
evolution::dg::MortarData<DIM(data)>, \
boost::hash<DirectionalId<DIM(data)>>>, \
std::unordered_map<DirectionalId<DIM(data)>, Mesh<DIM(data) - 1>, \
boost::hash<DirectionalId<DIM(data)>>>, \
std::unordered_map<DirectionalId<DIM(data)>, \
std::array<Spectral::MortarSize, DIM(data) - 1>, \
boost::hash<DirectionalId<DIM(data)>>>, \
std::unordered_map<DirectionalId<DIM(data)>, TimeStepId, \
boost::hash<DirectionalId<DIM(data)>>>, \
DirectionalIdMap<DIM(data), evolution::dg::MortarData<DIM(data)>>, \
DirectionalIdMap<DIM(data), Mesh<DIM(data) - 1>>, \
DirectionalIdMap<DIM(data), \
std::array<Spectral::MortarSize, DIM(data) - 1>>, \
DirectionalIdMap<DIM(data), TimeStepId>, \
DirectionMap<DIM(data), \
std::optional<Variables<tmpl::list< \
evolution::dg::Tags::MagnitudeOfNormal, \
Expand Down
25 changes: 8 additions & 17 deletions src/Evolution/DiscontinuousGalerkin/Initialization/Mortars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include <array>
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <optional>
#include <tuple>
Expand Down Expand Up @@ -60,19 +59,13 @@ class TaggedTuple;
namespace evolution::dg::Initialization {
namespace detail {
template <size_t Dim>
std::tuple<
std::unordered_map<DirectionalId<Dim>, evolution::dg::MortarData<Dim>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>, Mesh<Dim - 1>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>,
std::array<Spectral::MortarSize, Dim - 1>,
boost::hash<DirectionalId<Dim>>>,
std::unordered_map<DirectionalId<Dim>, TimeStepId,
boost::hash<DirectionalId<Dim>>>,
DirectionMap<Dim, std::optional<Variables<tmpl::list<
evolution::dg::Tags::MagnitudeOfNormal,
evolution::dg::Tags::NormalCovector<Dim>>>>>>
std::tuple<DirectionalIdMap<Dim, evolution::dg::MortarData<Dim>>,
DirectionalIdMap<Dim, Mesh<Dim - 1>>,
DirectionalIdMap<Dim, std::array<Spectral::MortarSize, Dim - 1>>,
DirectionalIdMap<Dim, TimeStepId>,
DirectionMap<Dim, std::optional<Variables<tmpl::list<
evolution::dg::Tags::MagnitudeOfNormal,
evolution::dg::Tags::NormalCovector<Dim>>>>>>
mortars_apply_impl(const std::vector<std::array<size_t, Dim>>& initial_extents,
Spectral::Quadrature quadrature, const Element<Dim>& element,
const TimeStepId& next_temporal_id,
Expand Down Expand Up @@ -102,10 +95,8 @@ mortars_apply_impl(const std::vector<std::array<size_t, Dim>>& initial_extents,
*/
template <size_t Dim, typename System>
struct Mortars {
using Key = DirectionalId<Dim>;

template <typename MappedType>
using MortarMap = std::unordered_map<Key, MappedType, boost::hash<Key>>;
using MortarMap = DirectionalIdMap<Dim, MappedType>;

public:
using simple_tags_from_options =
Expand Down
Loading
Loading