Skip to content

Commit

Permalink
fishy stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoo1042 committed Dec 8, 2023
1 parent d74eebb commit 1299b27
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 146 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
57 changes: 8 additions & 49 deletions src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedFmDisk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,54 +162,16 @@ 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>{}, vars);
}
}()))...};
}

template <typename DataType, typename Tag>
tuples::TaggedTuple<Tag> variables(const tnsr::I<DataType, 3>& x,
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());
if constexpr (std::is_same_v<hydro::Tags::MagneticField<DataType, 3>,
Tag>) {
return variables(x, tmpl::list<Tag>{}, intermediate_vars, 0);
} else {
return fm_disk_.variables(x, tmpl::list<Tag>{}, intermediate_vars, 0);
}
}
/// @}

// NOLINTNEXTLINE(google-runtime-references)
Expand All @@ -220,14 +182,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
Loading

0 comments on commit 1299b27

Please sign in to comment.