Skip to content

Commit 9d52a80

Browse files
authored
Merge pull request #54 from SCOREC/jk/fixOversizing
Jk/fix oversizing
2 parents 10d7db3 + 75368d1 commit 9d52a80

File tree

6 files changed

+41
-37
lines changed

6 files changed

+41
-37
lines changed

src/MeshField.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ MeshField::MeshInfo getMeshInfo(Omega_h::Mesh &mesh) {
3232
return meshInfo;
3333
}
3434

35-
template <typename ExecutionSpace, template <typename...> typename Controller =
36-
MeshField::KokkosController>
37-
decltype(MeshField::CreateCoordinateField<ExecutionSpace, Controller>(
35+
template <typename ExecutionSpace, size_t dim,
36+
template <typename...>
37+
typename Controller = MeshField::KokkosController>
38+
decltype(MeshField::CreateCoordinateField<ExecutionSpace, Controller, dim>(
3839
MeshField::MeshInfo()))
3940
createCoordinateField(const MeshField::MeshInfo &mesh_info,
4041
Omega_h::Reals coords) {
4142
const auto meshDim = mesh_info.dim;
4243
auto coordField =
43-
MeshField::CreateCoordinateField<ExecutionSpace, Controller>(mesh_info);
44+
MeshField::CreateCoordinateField<ExecutionSpace, Controller, dim>(
45+
mesh_info);
4446
auto setCoordField = KOKKOS_LAMBDA(const int &i) {
4547
coordField(i, 0, 0, MeshField::Vertex) = coords[i * meshDim];
4648
coordField(i, 0, 1, MeshField::Vertex) = coords[i * meshDim + 1];
@@ -167,23 +169,27 @@ template <int ShapeOrder> auto getTriangleElement(Omega_h::Mesh &mesh) {
167169

168170
} // namespace Omegah
169171

170-
template <typename ExecutionSpace, template <typename...> typename Controller =
171-
MeshField::KokkosController>
172+
template <typename ExecutionSpace, size_t dim,
173+
template <typename...> typename Controller =
174+
MeshField::KokkosController>
172175
class OmegahMeshField {
173176
private:
174177
Omega_h::Mesh &mesh;
175178
const MeshField::MeshInfo meshInfo;
176-
using CoordField = decltype(createCoordinateField<ExecutionSpace, Controller>(
177-
MeshField::MeshInfo(), Omega_h::Reals()));
179+
using CoordField =
180+
decltype(createCoordinateField<ExecutionSpace, dim, Controller>(
181+
MeshField::MeshInfo(), Omega_h::Reals()));
178182
CoordField coordField;
179183

180184
public:
181185
OmegahMeshField(Omega_h::Mesh &mesh_in)
182186
: mesh(mesh_in), meshInfo(getMeshInfo(mesh)),
183-
coordField(createCoordinateField<ExecutionSpace, Controller>(
184-
getMeshInfo(mesh_in), mesh_in.coords())) {}
187+
coordField(createCoordinateField<ExecutionSpace, dim, Controller>(
188+
getMeshInfo(mesh_in), mesh_in.coords())) {
189+
static_assert(dim == 1 || dim == 2 || dim == 3);
190+
}
185191

186-
template <typename DataType, size_t order, size_t dim>
192+
template <typename DataType, size_t order>
187193
// Ordering of field indexing changed to 'entity, node, component'
188194
auto CreateLagrangeField() {
189195
return MeshField::CreateLagrangeField<ExecutionSpace, Controller, DataType,

src/MeshField_ShapeField.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,23 @@ auto CreateLagrangeField(const MeshInfo &meshInfo) {
267267
* @return a linear ShapeField
268268
*/
269269

270-
template <typename ExecutionSpace, template <typename...> typename Controller =
271-
MeshField::KokkosController>
270+
template <typename ExecutionSpace,
271+
template <typename...>
272+
typename Controller = MeshField::KokkosController,
273+
size_t dim>
272274
auto CreateCoordinateField(const MeshInfo &meshInfo) {
273275
if (meshInfo.numVtx <= 0) {
274276
fail("mesh has no vertices\n");
275277
}
276278
using DataType = Real;
277279
using MemorySpace = typename ExecutionSpace::memory_space;
278280
const int numComp = meshInfo.dim;
279-
// FIXME Oversized cabana datatypes when numComp = 1|2
280281
#ifdef MESHFIELDS_ENABLE_CABANA
281282
using Ctrlr = std::conditional_t<
282283
std::is_same_v<
283284
Controller<ExecutionSpace, MemorySpace, DataType>,
284285
MeshField::CabanaController<ExecutionSpace, MemorySpace, DataType>>,
285-
Controller<ExecutionSpace, MemorySpace, DataType[1][3]>,
286+
Controller<ExecutionSpace, MemorySpace, DataType[1][dim]>,
286287
Controller<MemorySpace, ExecutionSpace, DataType ***>>;
287288
auto createController = [](const int numComp, auto numVtx) {
288289
if constexpr (std::is_same_v<

test/testCountIntegrator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ int main(int argc, char **argv) {
6060
Kokkos::initialize(argc, argv);
6161
auto lib = Omega_h::Library(&argc, &argv);
6262
auto mesh = createMeshTri18(lib);
63-
MeshField::OmegahMeshField<ExecutionSpace, MeshField::KokkosController> omf(
64-
mesh);
63+
MeshField::OmegahMeshField<ExecutionSpace, 2, MeshField::KokkosController>
64+
omf(mesh);
6565

6666
const auto ShapeOrder = 1;
6767
auto field = omf.getCoordField();

test/testElementJacobian1d.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ void setEdgeCoords(size_t numVerts, Kokkos::View<MeshField::Real *> coords,
4444

4545
void edgeJacobian() {
4646
const MeshField::MeshInfo meshInfo{.numVtx = 2, .numEdge = 1, .dim = 1};
47-
auto coordField =
48-
MeshField::CreateCoordinateField<ExecutionSpace,
49-
MeshField::KokkosController>(meshInfo);
47+
auto coordField = MeshField::CreateCoordinateField<
48+
ExecutionSpace, MeshField::KokkosController, 1>(meshInfo);
5049
Kokkos::View<MeshField::Real *, Kokkos::HostSpace> coords_h("coords_h", 2);
5150
coords_h[0] = -1;
5251
coords_h[1] = 1;

test/testElementJacobian2d.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ void setVtxCoords(size_t numVerts, size_t meshDim, TriangleTestCase testTri,
7272
void triJacobian() {
7373
const MeshField::MeshInfo meshInfo{
7474
.numVtx = 3, .numEdge = 3, .numTri = 1, .dim = 2};
75-
auto coordField =
76-
MeshField::CreateCoordinateField<ExecutionSpace,
77-
MeshField::KokkosController>(meshInfo);
78-
75+
auto coordField = MeshField::CreateCoordinateField<
76+
ExecutionSpace, MeshField::KokkosController, 2>(meshInfo);
7977
TriangleTestCase rightTriangle({0, 0, 1, 0, 0, 1}, {1, 0, 0, 1}, 1);
8078
TriangleTestCase skewedTriangle({0, 0, 5, 1, 3, 4}, {5, 1, 3, 4}, 17);
8179
for (auto testCase : {rightTriangle, skewedTriangle}) {

test/testOmegahElement.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void doFail(std::string_view order, std::string_view function,
143143

144144
template <template <typename...> typename Controller>
145145
void doRun(Omega_h::Mesh &mesh,
146-
MeshField::OmegahMeshField<ExecutionSpace, Controller> &omf) {
146+
MeshField::OmegahMeshField<ExecutionSpace, 2, Controller> &omf) {
147147

148148
// setup field with values from the analytic function
149149
static const size_t OnePtPerElem = 1;
@@ -166,14 +166,14 @@ void doRun(Omega_h::Mesh &mesh,
166166
// clang-format on
167167

168168
auto coords = mesh.coords();
169-
const auto MeshDim = 2;
170169
for (auto testCase : cases) {
171170
using ViewType = decltype(testCase.coords);
172171
{
173172
const auto ShapeOrder = 1;
174-
auto field = omf.template CreateLagrangeField<MeshField::Real, ShapeOrder,
175-
MeshDim>();
176-
auto func = LinearFunction();
173+
174+
auto field =
175+
omf.template CreateLagrangeField<MeshField::Real, ShapeOrder>();
176+
LinearFunction func = LinearFunction();
177177
setVertices(mesh, func, field);
178178
using FieldType = decltype(field);
179179
auto result = omf.template triangleLocalPointEval<ViewType, FieldType>(
@@ -186,8 +186,8 @@ void doRun(Omega_h::Mesh &mesh,
186186

187187
{
188188
const auto ShapeOrder = 2;
189-
auto field = omf.template CreateLagrangeField<MeshField::Real, ShapeOrder,
190-
MeshDim>();
189+
auto field =
190+
omf.template CreateLagrangeField<MeshField::Real, ShapeOrder>();
191191
auto func = QuadraticFunction();
192192
setVertices(mesh, func, field);
193193
setEdges(mesh, func, field);
@@ -202,8 +202,8 @@ void doRun(Omega_h::Mesh &mesh,
202202

203203
{
204204
const auto ShapeOrder = 2;
205-
auto field = omf.template CreateLagrangeField<MeshField::Real, ShapeOrder,
206-
MeshDim>();
205+
auto field =
206+
omf.template CreateLagrangeField<MeshField::Real, ShapeOrder>();
207207
auto func = LinearFunction();
208208
setVertices(mesh, func, field);
209209
setEdges(mesh, func, field);
@@ -225,15 +225,15 @@ int main(int argc, char **argv) {
225225
#ifdef MESHFIELDS_ENABLE_CABANA
226226
{
227227
auto mesh = createMeshTri18(lib);
228-
MeshField::OmegahMeshField<ExecutionSpace, MeshField::CabanaController> omf(
229-
mesh);
228+
MeshField::OmegahMeshField<ExecutionSpace, 2, MeshField::CabanaController>
229+
omf(mesh);
230230
doRun<MeshField::CabanaController>(mesh, omf);
231231
}
232232
#endif
233233
{
234234
auto mesh = createMeshTri18(lib);
235-
MeshField::OmegahMeshField<ExecutionSpace, MeshField::KokkosController> omf(
236-
mesh);
235+
MeshField::OmegahMeshField<ExecutionSpace, 2, MeshField::KokkosController>
236+
omf(mesh);
237237
doRun<MeshField::KokkosController>(mesh, omf);
238238
}
239239
Kokkos::finalize();

0 commit comments

Comments
 (0)