Skip to content

Commit

Permalink
Change SphericalKerrSchild and FMdisk
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoo1042 committed Dec 8, 2023
1 parent 2ecb266 commit 787524e
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 299 deletions.
1 change: 1 addition & 0 deletions src/DataStructures/CachedTempBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CachedTempBuffer {
}
return get<Tag>(data_);
}
size_t size() const { return data_.size(); }

private:
template <typename Tag>
Expand Down
2 changes: 2 additions & 0 deletions src/DataStructures/TempBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ template <typename TagList>
struct TempBuffer<TagList, true> : tuples::tagged_tuple_from_typelist<TagList> {
explicit TempBuffer(const size_t /*size*/)
: tuples::tagged_tuple_from_typelist<TagList>::TaggedTuple() {}

static size_t size() { return 1; }
};

template <typename TagList>
Expand Down
13 changes: 4 additions & 9 deletions src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedFmDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,12 @@ tnsr::I<DataType, 3> MagnetizedFmDisk::unnormalized_magnetic_field(
std::move(magnetic_field), x);
}

template <typename DataType, bool NeedSpacetime>
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::MagneticField<DataType, 3>>
MagnetizedFmDisk::variables(
const tnsr::I<DataType, 3>& x,
tmpl::list<hydro::Tags::MagneticField<DataType, 3>> /*meta*/,
const typename FmDisk::IntermediateVariables<DataType,
NeedSpacetime>& /*vars*/,
const size_t /*index*/) const {
const typename FmDisk::IntermediateVariables<DataType>& /*vars*/) const {
auto result = unnormalized_magnetic_field(x);
for (size_t i = 0; i < 3; ++i) {
result.get(i) *= b_field_normalization_;
Expand All @@ -249,20 +247,17 @@ bool operator!=(const MagnetizedFmDisk& lhs, const MagnetizedFmDisk& rhs) {
}

#define DTYPE(data) BOOST_PP_TUPLE_ELEM(0, data)
#define NEED_SPACETIME(data) BOOST_PP_TUPLE_ELEM(1, data)

#define INSTANTIATE(_, data) \
template tuples::TaggedTuple<hydro::Tags::MagneticField<DTYPE(data), 3>> \
MagnetizedFmDisk::variables( \
const tnsr::I<DTYPE(data), 3>& x, \
tmpl::list<hydro::Tags::MagneticField<DTYPE(data), 3>> /*meta*/, \
const typename FmDisk::FishboneMoncriefDisk::IntermediateVariables< \
DTYPE(data), NEED_SPACETIME(data)>& vars, \
const size_t) const;
DTYPE(data)>& vars) const;

GENERATE_INSTANTIATIONS(INSTANTIATE, (double, DataVector), (true, false))
GENERATE_INSTANTIATIONS(INSTANTIATE, (double, DataVector))

#undef DTYPE
#undef NEED_SPACETIME
#undef INSTANTIATE
} // namespace grmhd::AnalyticData
49 changes: 11 additions & 38 deletions src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedFmDisk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,13 @@ class MagnetizedFmDisk : public virtual evolution::initial_data::InitialData,
tmpl::list<Tags...> /*meta*/) const {
// Can't store IntermediateVariables as member variable because we
// need to be threadsafe.
constexpr double dummy_time = 0.0;
typename FmDisk::IntermediateVariables<
DataType,
tmpl2::flat_any_v<(
std::is_same_v<Tags, hydro::Tags::SpatialVelocity<DataType, 3>> or
std::is_same_v<Tags, hydro::Tags::LorentzFactor<DataType>> or
not tmpl::list_contains_v<hydro::grmhd_tags<DataType>, Tags>)...>>
vars(fm_disk_.background_spacetime_, x, dummy_time,
FmDisk::index_helper(
tmpl::index_of<tmpl::list<Tags...>,
hydro::Tags::SpatialVelocity<DataType, 3>>{}),
FmDisk::index_helper(
tmpl::index_of<tmpl::list<Tags...>,
hydro::Tags::LorentzFactor<DataType>>{}));
typename FmDisk::IntermediateVariables<DataType> vars(x);
return {std::move(get<Tags>([this, &x, &vars]() {
if constexpr (std::is_same_v<hydro::Tags::MagneticField<DataType, 3>,
Tags>) {
return variables(x, tmpl::list<Tags>{}, vars,
tmpl::index_of<tmpl::list<Tags...>, Tags>::value);
return variables(x, tmpl::list<Tags>{}, vars);
} else {
return fm_disk_.variables(
x, tmpl::list<Tags>{}, vars,
tmpl::index_of<tmpl::list<Tags...>, Tags>::value);
return fm_disk_.variables(x, tmpl::list<Tags>{}, make_not_null(&vars));
}
}()))...};
}
Expand All @@ -194,20 +178,12 @@ class MagnetizedFmDisk : public virtual evolution::initial_data::InitialData,
tmpl::list<Tag> /*meta*/) const {
// Can't store IntermediateVariables as member variable because we need to
// be threadsafe.
constexpr double dummy_time = 0.0;
typename FmDisk::IntermediateVariables<
DataType,
std::is_same_v<Tag, hydro::Tags::SpatialVelocity<DataType, 3>> or
std::is_same_v<Tag, hydro::Tags::LorentzFactor<DataType>> or
not tmpl::list_contains_v<hydro::grmhd_tags<DataType>, Tag>>
intermediate_vars(fm_disk_.background_spacetime_,
x, dummy_time, std::numeric_limits<size_t>::max(),
std::numeric_limits<size_t>::max());
typename FmDisk::IntermediateVariables<DataType> vars(x);
if constexpr (std::is_same_v<hydro::Tags::MagneticField<DataType, 3>,
Tag>) {
return variables(x, tmpl::list<Tag>{}, intermediate_vars, 0);
return variables(x, tmpl::list<Tag>{}, vars);
} else {
return fm_disk_.variables(x, tmpl::list<Tag>{}, intermediate_vars, 0);
return fm_disk_.variables(x, tmpl::list<Tag>{}, make_not_null(&vars));
}
}
/// @}
Expand All @@ -220,14 +196,11 @@ class MagnetizedFmDisk : public virtual evolution::initial_data::InitialData,
}

private:
template <typename DataType, bool NeedSpacetime>
auto variables(
const tnsr::I<DataType, 3>& x,
tmpl::list<hydro::Tags::MagneticField<DataType, 3>> /*meta*/,
const typename FmDisk::IntermediateVariables<DataType, NeedSpacetime>&
vars,
size_t index) const
-> tuples::TaggedTuple<hydro::Tags::MagneticField<DataType, 3>>;
template <typename DataType>
auto variables(const tnsr::I<DataType, 3>& x,
tmpl::list<hydro::Tags::MagneticField<DataType, 3>> /*meta*/,
const typename FmDisk::IntermediateVariables<DataType>& vars)
const -> tuples::TaggedTuple<hydro::Tags::MagneticField<DataType, 3>>;

template <typename DataType>
tnsr::I<DataType, 3> unnormalized_magnetic_field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "PointwiseFunctions/GeneralRelativity/TagsDeclarations.hpp"
#include "Utilities/ContainerHelpers.hpp"
#include "Utilities/ForceInline.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeArray.hpp"
#include "Utilities/TMPL.hpp"
#include "Utilities/TaggedTuple.hpp"
Expand Down Expand Up @@ -429,6 +430,11 @@ class SphericalKerrSchild : public AnalyticSolution<3_st>,
SphericalKerrSchild& operator=(SphericalKerrSchild&& /*rhs*/) = default;
~SphericalKerrSchild() = default;

// forward-declaration needed.
template <typename DataType, typename Frame>
class IntermediateVars;

// Overload and call the second one.
template <typename DataType, typename Frame, typename... Tags>
tuples::TaggedTuple<Tags...> variables(
const tnsr::I<DataType, volume_dim, Frame>& x, double /*t*/,
Expand All @@ -443,6 +449,23 @@ class SphericalKerrSchild : public AnalyticSolution<3_st>,
return {cache.get_var(computer, Tags{})...};
}

template <typename DataType, typename Frame, typename... Tags>
tuples::TaggedTuple<Tags...> variables(
const tnsr::I<DataType, volume_dim, Frame>& x, double /*t*/,
tmpl::list<Tags...> /*meta*/,
gsl::not_null<IntermediateVars<DataType, Frame>*> cache) const {
static_assert(
tmpl2::flat_all_v<
tmpl::list_contains_v<tags<DataType, Frame>, Tags>...>,
"At least one of the requested tags is not supported. The requested "
"tags are listed as template parameters of the `variables` function.");
if (cache->size() != get_size(*x.begin())) {
*cache = IntermediateVars<DataType, Frame>(get_size(*x.begin()));
}
IntermediateComputer<DataType, Frame> computer(*this, x);
return {cache->get_var(computer, Tags{})...};
}

// NOLINTNEXTLINE(google-runtime-references)
void pup(PUP::er& p);

Expand Down
Loading

0 comments on commit 787524e

Please sign in to comment.