12#ifndef MFEM_TEMPLATE_LAYOUT
13#define MFEM_TEMPLATE_LAYOUT
24template <
int N1,
int S1>
25struct OffsetStridedLayout1D;
26template <
int N1,
int S1,
int N2,
int S2>
27struct StridedLayout2D;
29template <
int N1,
int S1>
34 static const int size = N1;
36 MFEM_HOST_DEVICE
static inline int ind(
int i1)
49 template <
int N1_1,
int N1_2>
53 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
58template <
int N1,
int S1,
int N2,
int S2>
59struct OffsetStridedLayout2D;
61template <
int N1,
int S1>
66 static const int size = N1;
72 MFEM_HOST_DEVICE
inline int ind(
int i1)
const
85 template <
int N1_1,
int N1_2>
89 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
94template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3>
95struct StridedLayout3D;
96template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3,
int N4,
int S4>
97struct StridedLayout4D;
99template <
int N1,
int S1,
int N2,
int S2>
107 MFEM_HOST_DEVICE
static inline int ind(
int i1,
int i2)
109 return (S1*i1+S2*i2);
120 template <
int M1,
int M2>
128 template <
int N1_1,
int N1_2>
132 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
135 template <
int N2_1,
int N2_2>
139 MFEM_STATIC_ASSERT(N2_1*N2_2 == N2,
"invalid dimensions");
142 template <
int N1_1,
int N1_2,
int N2_1,
int N2_2>
146 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1 && N2_1*N2_2 == N2,
147 "invalid dimensions");
155 MFEM_STATIC_ASSERT(S2 == S1*N1 || S1 == S2*N2,
"invalid reshape");
164template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3>
165struct OffsetStridedLayout3D;
166template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3,
int N4,
int S4>
167struct OffsetStridedLayout4D;
169template <
int N1,
int S1,
int N2,
int S2>
181 MFEM_HOST_DEVICE
inline int ind(
int i1,
int i2)
const
183 return offset+S1*i1+S2*i2;
194 template <
int M1,
int M2>
202 template <
int N1_1,
int N1_2>
206 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
209 template <
int N2_1,
int N2_2>
213 MFEM_STATIC_ASSERT(N2_1*N2_2 == N2,
"invalid dimensions");
216 template <
int N1_1,
int N1_2,
int N2_1,
int N2_2>
221 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1 && N2_1*N2_2 == N2,
222 "invalid dimensions");
224 N1_1,S1,N1_2,S1*N1_1,N2_1,S2,N2_2,S2*N2_1>(
offset);
231 MFEM_STATIC_ASSERT(S2 == S1*N1 || S1 == S2*N2,
"invalid reshape");
240template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3>
247 static const int size = N1*N2*N3;
249 static inline int ind(
int i1,
int i2,
int i3)
251 return S1*i1+S2*i2+S3*i3;
272 MFEM_STATIC_ASSERT(S2 == S1*N1,
"invalid reshape");
283 MFEM_STATIC_ASSERT(S3 == S2*N2,
"invalid reshape");
287 template <
int N1_1,
int N1_2>
291 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
294 template <
int N2_1,
int N2_2>
298 MFEM_STATIC_ASSERT(N2_1*N2_2 == N2,
"invalid dimensions");
301 template <
int N3_1,
int N3_2>
305 MFEM_STATIC_ASSERT(N3_1*N3_2 == N3,
"invalid dimensions");
323template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3>
330 static const int size = N1*N2*N3;
336 inline int ind(
int i1,
int i2,
int i3)
const
338 return offset+S1*i1+S2*i2+S3*i3;
359 MFEM_STATIC_ASSERT(S2 == S1*N1,
"invalid reshape");
366 MFEM_STATIC_ASSERT(S3 == S2*N2,
"invalid reshape");
370 template <
int N1_1,
int N1_2>
374 MFEM_STATIC_ASSERT(N1_1*N1_2 == N1,
"invalid dimensions");
377 template <
int N2_1,
int N2_2>
381 MFEM_STATIC_ASSERT(N2_1*N2_2 == N2,
"invalid dimensions");
386template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3,
int N4,
int S4>
394 static const int size = N1*N2*N3*N4;
396 static inline int ind(
int i1,
int i2,
int i3,
int i4)
398 return S1*i1+S2*i2+S3*i3+S4*i4;
417 MFEM_STATIC_ASSERT(S2 == S1*N1,
"invalid reshape");
424 MFEM_STATIC_ASSERT(S4 == S3*N3,
"invalid reshape");
429template <
int N1,
int S1,
int N2,
int S2,
int N3,
int S3,
int N4,
int S4>
437 static const int size = N1*N2*N3*N4;
443 inline int ind(
int i1,
int i2,
int i3,
int i4)
const
445 return offset+S1*i1+S2*i2+S3*i3+S4*i4;
449template <
int N1,
int N2>
453template <
int N1,
int N2,
int N3>
457template <
int N1,
int N2,
int N3,
int N4>
491 Init(ordering, scalar_size, num_comp);
501 int ind(
int scalar_idx,
int comp_idx)
const
514template <Ordering::Type Ord,
int NumComp = 0>
529 "invalid number of components");
536 MFEM_ASSERT(fes.
GetOrdering() == Ord,
"ordering mismatch");
538 "invalid number of components");
544 int ind(
int scalar_idx,
int comp_idx)
const
552 return comp_idx + (NumComp ? NumComp :
num_components) * scalar_idx;
559 (NumComp == 0 || NumComp == fes.
GetVDim()));
572 MFEM_ASSERT(fes.
GetVDim() == 1,
"invalid number of components");
577 int ind(
int scalar_idx,
int comp_idx)
const {
return scalar_idx; }
DynamicVectorLayout(Ordering::Type ordering, int scalar_size, int num_comp)
static bool Matches(const FiniteElementSpace &fes)
int ind(int scalar_idx, int comp_idx) const
int NumComponents() const
DynamicVectorLayout(const FiniteElementSpace &fes)
void Init(Ordering::Type ordering, int scalar_size, int num_comp)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetNDofs() const
Returns number of degrees of freedom. This is the number of Local Degrees of Freedom.
Ordering::Type GetOrdering() const
Return the ordering method.
int GetVDim() const
Returns vector dimension.
ScalarLayout(const FiniteElementSpace &fes)
int NumComponents() const
static bool Matches(const FiniteElementSpace &fes)
int ind(int scalar_idx, int comp_idx) const
static bool Matches(const FiniteElementSpace &fes)
VectorLayout(int scalar_size_, int num_comp_=NumComp)
int NumComponents() const
int ind(int scalar_idx, int comp_idx) const
VectorLayout(const FiniteElementSpace &fes)
OffsetStridedLayout1D< M1, S1 > sub(int o1) const
OffsetStridedLayout2D< N1_1, S1, N1_2, S1 *N1_1 > split_1() const
MFEM_HOST_DEVICE int ind(int i1) const
OffsetStridedLayout1D(int offset_)
OffsetStridedLayout3D< N1_1, S1, N1_2, S1 *N1_1, N2, S2 > split_1() const
OffsetStridedLayout2D< M1, S1, M2, S2 > sub(int o1, int o2) const
OffsetStridedLayout2D(int offset_)
OffsetStridedLayout4D< N1_1, S1, N1_2, S1 *N1_1, N2_1, S2, N2_2, S2 *N2_1 > split_12() const
OffsetStridedLayout1D< N1 *N2,(S1< S2)?S1:S2 > merge_12() const
MFEM_HOST_DEVICE int ind(int i1, int i2) const
OffsetStridedLayout2D< N2, S2, N1, S1 > transpose_12() const
OffsetStridedLayout1D< N1, S1 > ind2(int i2) const
OffsetStridedLayout1D< N2, S2 > ind1(int i1) const
OffsetStridedLayout3D< N1, S1, N2_1, S2, N2_2, S2 *N2_1 > split_2() const
OffsetStridedLayout4D< N1, S1, N2_1, S2, N2_2, S2 *N2_1, N3, S3 > split_2() const
OffsetStridedLayout2D< N1 *N2, S1, N3, S3 > merge_12() const
int ind(int i1, int i2, int i3) const
OffsetStridedLayout2D< N1, S1, N2, S2 > ind3(int i3) const
OffsetStridedLayout2D< N2, S2, N3, S3 > ind1(int i1) const
OffsetStridedLayout3D(int offset_)
OffsetStridedLayout2D< N1, S1, N3, S3 > ind2(int i2) const
OffsetStridedLayout2D< N1, S1, N2 *N3, S2 > merge_23() const
OffsetStridedLayout4D< N1_1, S1, N1_2, S1 *N1_1, N2, S2, N3, S3 > split_1() const
int ind(int i1, int i2, int i3, int i4) const
OffsetStridedLayout4D(int offset_)
static MFEM_HOST_DEVICE int ind(int i1)
static StridedLayout2D< N1_1, S1, N1_2, S1 *N1_1 > split_1()
static OffsetStridedLayout1D< M1, S1 > sub(int o1)
static OffsetStridedLayout1D< N1, S1 > ind2(int i2)
static StridedLayout1D< N1 *N2,(S1< S2)?S1:S2 > merge_12()
static MFEM_HOST_DEVICE int ind(int i1, int i2)
static StridedLayout2D< N2, S2, N1, S1 > transpose_12()
static OffsetStridedLayout1D< N2, S2 > ind1(int i1)
static StridedLayout4D< N1_1, S1, N1_2, S1 *N1_1, N2_1, S2, N2_2, S2 *N2_1 > split_12()
static StridedLayout3D< N1_1, S1, N1_2, S1 *N1_1, N2, S2 > split_1()
static OffsetStridedLayout2D< M1, S1, M2, S2 > sub(int o1, int o2)
static StridedLayout3D< N1, S1, N2_1, S2, N2_2, S2 *N2_1 > split_2()
static StridedLayout3D< N3, S3, N2, S2, N1, S1 > transpose_13()
static StridedLayout3D< N2, S2, N1, S1, N3, S3 > transpose_12()
static OffsetStridedLayout2D< N1, S1, N2, S2 > ind3(int i3)
static StridedLayout4D< N1, S1, N2_1, S2, N2_2, S2 *N2_1, N3, S3 > split_2()
static StridedLayout2D< N1, S1, N2 *N3, S2 > merge_23()
static StridedLayout2D< N1 *N2, S1, N3, S3 > merge_12()
static int ind(int i1, int i2, int i3)
static StridedLayout4D< N1, S1, N2, S2, N3_1, S3, N3_2, S3 *N3_1 > split_3()
static StridedLayout3D< N1, S1, N3, S3, N2, S2 > transpose_23()
static StridedLayout4D< N1_1, S1, N1_2, S1 *N1_1, N2, S2, N3, S3 > split_1()
static OffsetStridedLayout2D< N2, S2, N3, S3 > ind1(int i1)
static OffsetStridedLayout2D< N1, S1, N3, S3 > ind2(int i2)
static OffsetStridedLayout2D< N2, S2, N3, S3 > ind14(int i1, int i4)
static int ind(int i1, int i2, int i3, int i4)
static StridedLayout3D< N1, S1, N2, S2, N3 *N4, S3 > merge_34()
static OffsetStridedLayout2D< N1, S1, N4, S4 > ind23(int i2, int i3)
static OffsetStridedLayout3D< N1, S1, N2, S2, N3, S3 > ind4(int i4)
static StridedLayout3D< N1 *N2, S1, N3, S3, N4, S4 > merge_12()