21 #ifndef FUB_SAMRAI_PATCH_VIEW_HPP
22 #define FUB_SAMRAI_PATCH_VIEW_HPP
26 #include <SAMRAI/hier/Patch.h>
27 #include <SAMRAI/pdat/ArrayData.h>
28 #include <SAMRAI/pdat/CellData.h>
29 #include <SAMRAI/pdat/SideData.h>
34 template <
int Rank,
typename T>
37 const int dim = box.getDim().getValue();
38 const int depth = array.getDepth();
39 if ((depth > 1 && Rank < dim + 1) || (depth == 1 && Rank < dim)) {
40 throw std::invalid_argument(
"Dimension mismatch in make_mdspan.");
42 std::array<std::ptrdiff_t, Rank>
extents;
44 for (
int d = 0; d < dim; ++d) {
45 extents[d] = box.numberCells(d);
50 T* pointer = array.getPointer();
54 template <
int Rank,
typename T>
57 const int dim = box.getDim().getValue();
58 const int depth = array.getDepth();
59 if ((depth > 1 && Rank < dim + 1) || (depth == 1 && Rank < dim)) {
60 throw std::invalid_argument(
"Dimension mismatch in make_mdspan.");
62 std::array<std::ptrdiff_t, Rank>
extents;
64 for (
int d = 0; d < dim; ++d) {
65 extents[d] = box.numberCells(d);
70 const T* pointer = array.getPointer();
76 const std::size_t dim =
static_cast<std::size_t
>(box.getDim().getValue());
77 for (std::size_t i = 0; i < dim; ++i) {
78 index_box.
lower[i] = box.lower(
static_cast<SAMRAI::hier::Box::dir_t
>(i));
80 box.upper(
static_cast<SAMRAI::hier::Box::dir_t
>(i)) + 1;
85 template <
int Rank,
typename T>
92 template <
int Rank,
typename T>
98 template <
typename PatchData>
99 std::enable_if_t<std::is_pointer_v<PatchData>,
void>
103 std::transform(data_ids.
begin(), data_ids.
end(), patch_datas.
begin(),
105 PatchData pointer_to_data =
106 dynamic_cast<PatchData>(patch.getPatchData(id).get());
107 FUB_ASSERT(pointer_to_data);
108 return pointer_to_data;
112 template <
typename PatchData>
113 std::enable_if_t<std::is_pointer_v<PatchData>,
void>
117 std::transform(data_ids.
begin(), data_ids.
end(), patch_datas.
begin(),
119 PatchData pointer_to_data =
120 dynamic_cast<PatchData>(patch.getPatchData(id).get());
121 FUB_ASSERT(pointer_to_data);
122 return pointer_to_data;
126 template <
typename State>
132 const int dir_value =
static_cast<int>(dir);
134 [&](
auto& variable) {
135 using type =
typename remove_cvref<decltype(variable)>::type;
136 constexpr
int Rank = type::rank();
137 variable = MakePatchDataView<Rank>(
span[i]->getArrayData(dir_value));
144 template <
typename State>
149 static constexpr
int Rank = State::Equation::Rank();
150 using T = std::conditional_t<std::is_const_v<State>,
const double,
double>;
153 variable = MakePatchDataView<Rank>(
span[i]->getArrayData());
158 MakePatchDataView<Rank + 1>(
span[i]->getArrayData());
165 template <
typename State>
171 static constexpr
int Rank = State::Equation::Rank();
174 variable = MakePatchDataView<Rank>(
span[i]->getArrayData());
179 MakePatchDataView<Rank + 1>(
span[i]->getArrayData());
186 template <
typename State,
typename Range>
188 const IndexBox<State::Equation::Rank()>& box) {
189 return Subview(MakeView<State>(std::forward<Range>(
span), equation), box);
192 template <
typename State,
typename Range>
195 const IndexBox<State::Equation::Rank()>& box) {
196 return Subview(MakeView<State>(std::forward<Range>(
span), equation, dir),
#define FUB_ASSERT(x)
Definition: assert.hpp:39
Definition: mdspan.hpp:573
An extents object defines a multidimensional index space which is the Cartesian product of integers e...
Definition: mdspan.hpp:208
A span is a view over a contiguous sequence of objects, the storage of which is owned by some other o...
Definition: span.hpp:81
constexpr index_type size() const noexcept
Returns the number of elements in the span.
Definition: span.hpp:392
constexpr iterator begin() const noexcept
Returns an iterator pointing to the first element of the span.
Definition: span.hpp:428
constexpr iterator end() const noexcept
Returns an iterator pointing one after the last element of the span.
Definition: span.hpp:438
mdspan< T, Rank > MakeMdSpan(SAMRAI::pdat::ArrayData< T > &array)
Definition: ViewPatch.hpp:35
IndexBox< Rank > AsIndexBox(const SAMRAI::hier::Box &box)
Definition: ViewPatch.hpp:74
int GetDirection(const SAMRAI::hier::IntVector &directions)
std::enable_if_t< std::is_pointer_v< PatchData >, void > GetPatchData(span< PatchData > patch_datas, SAMRAI::hier::Patch &patch, span< const int > data_ids)
Definition: ViewPatch.hpp:100
PatchDataView< const T, Rank > MakePatchDataView(const SAMRAI::pdat::ArrayData< T > &array)
Definition: ViewPatch.hpp:87
BasicView< State > MakeView(span< SAMRAI::pdat::SideData< double > * > span, const typename State::Equation &, Direction dir)
Definition: ViewPatch.hpp:127
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
View< State > Subview(const BasicView< State, Layout, Rank > &state, const IndexBox< Rank > &box)
Definition: Equation.hpp:86
void ForEachVariable(F function, Ts &&... states)
Definition: State.hpp:89
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
IndexBox< Rank > Box(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:486
Definition: State.hpp:403
Definition: PatchDataView.hpp:56
Index< Rank > lower
Definition: PatchDataView.hpp:57
Definition: PatchDataView.hpp:201
Definition: type_traits.hpp:291
This is equivalent to std::remove_cv_t<std::remove_reference_t<T>>.
Definition: type_traits.hpp:223