21 #ifndef FUB_STATE_ARRAY_HPP
22 #define FUB_STATE_ARRAY_HPP
26 #include <boost/mp11/algorithm.hpp>
30 template <
typename Depths,
int W
idth>
struct ArrayStateBaseImpl {
32 using fn =
typename DepthToStateValueTypeImpl<T, Width>::type;
33 using type = boost::mp11::mp_transform<fn, Depths>;
37 template <
typename Depths,
int W
idth>
38 using ArrayStateBase =
typename detail::ArrayStateBaseImpl<Depths, Width>::type;
40 template <
typename Depths,
int W
idth>
47 template <
typename Equation>
53 [&](
auto&& ids,
auto depth) {
54 if constexpr (std::is_same_v<std::decay_t<decltype(depth)>,
58 ids =
Array<double, decltype(depth)::value>::Zero();
66 ForEachVariable([](
auto&& that,
auto&& other) { that += other; }, *
this,
72 ForEachVariable([](
auto&& that,
auto&& other) { that -= other; }, *
this,
84 template <
typename Depths,
int W
idth>
88 template <
typename Eq,
int W
idth = kDefaultChunkSize>
95 template <
typename Eq,
int W
idth>
97 :
StateTraits<ArrayState<typename Eq::PrimitiveDepths, Width>> {};
99 template <
typename Eq,
int W
idth = kDefaultChunkSize>
101 :
ArrayState<typename Eq::CharacteristicsDepths, Width> {
107 template <
typename Eq,
int W
idth = kDefaultChunkSize>
114 template <
typename Eq,
int W
idth>
116 :
StateTraits<ArrayState<typename Eq::KineticStateDepths, Width>> {};
118 template <
typename Eq,
int W
idth>
120 :
StateTraits<ArrayState<typename Eq::CharacteristicsDepths, Width>> {};
123 template <
typename Eq,
int W
idth>
struct ConservativeArrayBaseImpl {
124 template <
typename T>
125 using fn =
typename DepthToStateValueTypeImpl<T, Width>::type;
126 using type = boost::mp11::mp_transform<fn, typename Eq::ConservativeDepths>;
130 template <
typename Eq,
int W
idth = kDefaultChunkSize>
132 typename detail::ConservativeArrayBaseImpl<Eq, Width>::type;
134 template <
typename Eq,
int W
idth = kDefaultChunkSize>
140 static constexpr
int Size() {
return Width; }
148 [&](
auto&& ids,
auto depth) {
149 if constexpr (std::is_same_v<std::decay_t<decltype(depth)>,
153 ids =
Array<double, decltype(depth)::value>::Zero();
161 template <
typename Eq,
int W
idth>
163 :
StateTraits<ConservativeArrayBase<Eq, Width>> {};
166 template <
typename Eq,
int W
idth>
struct CompleteArrayBaseImpl {
167 template <
typename T>
168 using fn =
typename DepthToStateValueTypeImpl<T, Width>::type;
169 using type = boost::mp11::mp_transform<fn, typename Eq::CompleteDepths>;
173 template <
typename Eq,
int W
idth>
175 typename detail::CompleteArrayBaseImpl<Eq, Width>::type;
177 template <
typename Eq,
int W
idth = kDefaultChunkSize>
183 static constexpr
int Size() {
return Width; }
191 [&](
auto&& ids,
auto depth) {
192 if constexpr (std::is_same_v<std::decay_t<decltype(depth)>,
196 ids =
Array<double, decltype(depth)::value>::Zero();
204 template <
typename Eq,
int W
idth>
208 template <
typename Eq,
int N>
213 template <
typename Eq,
int N>
218 template <
typename Eq,
int N>
223 template <
typename Eq,
int N>
228 template <
typename Eq,
int N>
233 template <
typename Eq,
int N>
238 template <
typename Eq,
int N,
typename Layout, std::
size_t Rank>
241 static_cast<int>(Rank)>&>
243 std::array<std::ptrdiff_t, Rank>
index) {
245 [&](
auto& component,
auto data) {
246 component = std::apply(
253 template <
typename Eq,
int N,
typename Layout,
int Rank>
257 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&>
index) {
259 [&](
auto&& component,
auto data) {
265 template <
typename Eq>
270 [](
Array1d& x,
const double* p) { x = Eigen::Map<const Array1d>(p); },
271 [](
auto& xs, std::pair<const double*, std::ptrdiff_t> ps) {
272 const double* p = ps.first;
273 for (
int i = 0; i < xs.rows(); ++i) {
274 xs.row(i) = Eigen::Map<const Array1d>(p);
281 template <
typename Eq,
int N,
typename Layout,
int Rank>
285 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&>
index) {
287 [&](
auto&& component,
auto data) {
293 template <
typename Eq>
298 [](
Array1d& x,
const double* p) { x = Eigen::Map<const Array1d>(p); },
299 [](
auto& xs, std::pair<const double*, std::ptrdiff_t> ps) {
300 const double* p = ps.first;
301 for (
int i = 0; i < xs.rows(); ++i) {
302 xs.row(i) = Eigen::Map<const Array1d>(p);
309 template <
typename Eq,
int N,
typename Layout,
int Rank>
313 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&> pos) {
319 template <
typename Eq,
int N,
typename Layout,
int Rank>
323 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&> pos) {
329 template <
typename Eq>
336 #pragma clang loop vectorize(disable)
338 for (
int i = 0; i < n; ++i) {
342 [n](
auto& xs, std::pair<const double*, std::ptrdiff_t> ps) {
343 const double* p = ps.first;
344 for (
int i = 0; i < xs.rows(); ++i) {
346 #pragma clang loop vectorize(disable)
348 for (
int j = 0; j < n; ++j) {
357 template <
typename Eq>
364 #pragma clang loop vectorize(disable)
366 for (
int i = 0; i < n; ++i) {
370 [n](
auto& xs, std::pair<const double*, std::ptrdiff_t> ps) {
371 const double* p = ps.first;
372 for (
int i = 0; i < xs.rows(); ++i) {
374 #pragma clang loop vectorize(disable)
376 for (
int j = 0; j < n; ++j) {
385 template <
typename Eq>
389 Eigen::Map<Array1d>{p} = x;
391 [](
auto& ptr,
const auto& x) {
392 for (
int i = 0; i < x.rows(); ++i) {
393 Eigen::Map<Array1d>(ptr.first) = x.row(i);
394 ptr.first += ptr.second;
400 template <
typename Eq>
404 Eigen::Map<Array1d>{p} = x;
406 [](
auto& ptr,
const auto& x) {
407 for (
int i = 0; i < x.rows(); ++i) {
408 Eigen::Map<Array1d>(ptr.first) = x.row(i);
409 ptr.first += ptr.second;
415 template <
typename Eq>
420 #pragma clang loop vectorize(disable)
422 for (
int i = 0; i < n; ++i) {
426 [n](
auto& ptr,
const auto& x) {
427 for (
int i = 0; i < x.rows(); ++i) {
429 #pragma clang loop vectorize(disable)
431 for (
int j = 0; j < n; ++j) {
432 ptr.first[i * ptr.second + j] = x(i, j);
439 template <
typename Eq>
444 #pragma clang loop vectorize(disable)
446 for (
int i = 0; i < n; ++i) {
450 [n](
auto& ptr,
const auto& x) {
451 for (
int i = 0; i < x.rows(); ++i) {
453 #pragma clang loop vectorize(disable)
455 for (
int j = 0; j < n; ++j) {
456 ptr.first[i * ptr.second + j] = x(i, j);
463 template <
typename Eq,
int N,
typename Layout,
int Rank>
467 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&>
index) {
472 template <
typename Eq,
int N,
typename Layout,
int Rank>
476 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&>
index) {
481 template <
typename Eq,
int N,
typename Layout,
int Rank>
485 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&> pos) {
490 template <
typename Eq,
int N,
typename Layout,
int Rank>
494 nodeduce_t<
const std::array<std::ptrdiff_t, std::size_t(Rank)>&> pos) {
#define FUB_ASSERT(x)
Definition: assert.hpp:39
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
typename detail::CompleteArrayBaseImpl< Eq, Width >::type CompleteArrayBase
Definition: StateArray.hpp:175
std::conditional_t< N==1||M==1, Eigen::Array< T, N, M >, Eigen::Array< T, N, M, Eigen::RowMajor > > Array
Definition: Eigen.hpp:50
Array< double, 1 > Array1d
Definition: Eigen.hpp:53
constexpr const int kDefaultChunkSize
Definition: Eigen.hpp:39
void ForEachVariable(F function, Ts &&... states)
Definition: State.hpp:89
void StoreN(nodeduce_t< ViewPointer< Conservative< Eq >>> pointer, const ConservativeArray< Eq > &state, int n)
Definition: StateArray.hpp:416
typename nodeduce< T >::type nodeduce_t
Definition: type_traits.hpp:47
constexpr struct fub::DepthsFn Depths
void Load(State &state, const BasicView< const State, Layout, Rank > &view, const std::array< std::ptrdiff_t, State::Equation::Rank()> &index)
Definition: State.hpp:640
void LoadN(CompleteArray< Eq, N > &state, const BasicView< const Complete< Eq >, Layout, Rank > &view, int size, nodeduce_t< const std::array< std::ptrdiff_t, std::size_t(Rank)> & > pos)
Definition: StateArray.hpp:310
typename detail::ArrayStateBaseImpl< Depths, Width >::type ArrayStateBase
Definition: StateArray.hpp:38
const Conservative< Eq > & AsCons(const Conservative< Eq > &x)
Definition: State.hpp:438
void Store(const BasicView< Conservative< Eq >, Layout, Eq::Rank()> &view, const Conservative< Eq > &state, const std::array< std::ptrdiff_t, Eq::Rank()> &index)
Definition: State.hpp:663
void ForEachComponent(F function, Ts &&... states)
Definition: State.hpp:624
std::integral_constant< int, I > int_constant
Definition: type_traits.hpp:183
typename detail::ConservativeArrayBaseImpl< Eq, Width >::type ConservativeArrayBase
Definition: StateArray.hpp:132
std::ptrdiff_t index
Definition: type_traits.hpp:179
Definition: StateArray.hpp:41
ArrayState & operator-=(const Base &other)
Definition: StateArray.hpp:71
ArrayState & operator+=(const Base &other)
Definition: StateArray.hpp:65
ArrayState & operator*=(double lambda)
Definition: StateArray.hpp:77
ArrayStateBase< Depths, Width > Base
Definition: StateArray.hpp:43
ArrayState(const Equation &eq)
Definition: StateArray.hpp:48
Definition: State.hpp:403
Definition: StateArray.hpp:101
Definition: StateArray.hpp:178
static constexpr int Size()
Definition: StateArray.hpp:183
CompleteArray(const Equation &eq)
Definition: StateArray.hpp:186
Eq Equation
Definition: StateArray.hpp:179
Definition: StateArray.hpp:135
Eq Equation
Definition: StateArray.hpp:136
ConservativeArray()=default
ConservativeArray(const Equation &eq)
Definition: StateArray.hpp:143
static constexpr int Size()
Definition: StateArray.hpp:140
Definition: StateArray.hpp:108
Definition: StateArray.hpp:89
This type is used to tag scalar quantities.
Definition: State.hpp:109
Definition: State.hpp:162
Definition: State.hpp:750
Definition: type_traits.hpp:291