Skip to content

Commit ef76a31

Browse files
Making user functions as const where possible (#81)
* Making user functions as const where possible * Format * Converting some arguments to be const reference
1 parent 2807fa3 commit ef76a31

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/MeshField.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ class OmegahMeshField {
299299

300300
template <typename DataType, size_t order, size_t numComp>
301301
// Ordering of field indexing changed to 'entity, node, component'
302-
auto CreateLagrangeField() {
302+
auto CreateLagrangeField() const {
303303
return MeshField::CreateLagrangeField<ExecutionSpace, Controller, DataType,
304304
order, dim, numComp>(meshInfo);
305305
}
306306

307307
auto getCoordField() { return coordField; }
308308

309309
// FIXME support 2d and 3d and fields with order>1
310-
template <typename Field> void writeVtk(Field &field) {
310+
template <typename Field> void writeVtk(Field &field) const {
311311
using FieldDataType = typename decltype(field.vtxField)::BaseType;
312312
// HACK assumes there is a vertex field.. in the Field Mixin object
313313
auto field_view = field.vtxField.serialize();
@@ -318,7 +318,7 @@ class OmegahMeshField {
318318
}
319319

320320
template <typename ViewType = Kokkos::View<MeshField::LO *>>
321-
ViewType createOffsets(size_t numTri, size_t numPtsPerElem) {
321+
ViewType createOffsets(size_t numTri, size_t numPtsPerElem) const {
322322
ViewType offsets("offsets", numTri + 1);
323323
Kokkos::parallel_for(
324324
"setOffsets", numTri,
@@ -330,8 +330,8 @@ class OmegahMeshField {
330330

331331
// evaluate a field at the specified local coordinate for each triangle
332332
template <typename ViewType, typename ShapeField>
333-
auto triangleLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
334-
ShapeField field) {
333+
auto triangleLocalPointEval(const ViewType &localCoords, size_t NumPtsPerElem,
334+
const ShapeField &field) const {
335335
auto offsets = createOffsets(meshInfo.numTri, NumPtsPerElem);
336336
auto eval = triangleLocalPointEval<ViewType, ShapeField>(localCoords,
337337
offsets, field);
@@ -340,8 +340,9 @@ class OmegahMeshField {
340340

341341
// evaluate a field at the specified local coordinates for each triangle
342342
template <typename ViewType, typename ShapeField>
343-
auto triangleLocalPointEval(ViewType localCoords, Kokkos::View<LO *> offsets,
344-
ShapeField field) {
343+
auto triangleLocalPointEval(const ViewType &localCoords,
344+
Kokkos::View<LO *> offsets,
345+
const ShapeField &field) const {
345346
const auto MeshDim = 2;
346347
if (mesh.dim() != MeshDim) {
347348
MeshField::fail("input mesh must be 2d\n");
@@ -360,16 +361,18 @@ class OmegahMeshField {
360361
}
361362

362363
template <typename ViewType, typename ShapeField>
363-
auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
364-
ShapeField field) {
364+
auto tetrahedronLocalPointEval(const ViewType &localCoords,
365+
size_t NumPtsPerElem,
366+
const ShapeField &field) const {
365367
auto offsets = createOffsets(meshInfo.numTet, NumPtsPerElem);
366368
auto eval = tetrahedronLocalPointEval(localCoords, offsets, field);
367369
return eval;
368370
}
369371

370372
template <typename ViewType, typename ShapeField>
371-
auto tetrahedronLocalPointEval(ViewType localCoords,
372-
Kokkos::View<LO *> offsets, ShapeField field) {
373+
auto tetrahedronLocalPointEval(const ViewType &localCoords,
374+
Kokkos::View<LO *> offsets,
375+
const ShapeField &field) const {
373376
const auto MeshDim = 3;
374377
if (mesh.dim() != MeshDim) {
375378
MeshField::fail("input mesh must be 3d\n");

src/MeshField_Element.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct FieldElement {
236236
* heavily based on SCOREC/core @ 7cd76473 apf/apfVectorElement.cc
237237
*/
238238
template <typename Matrices>
239-
Kokkos::View<Real *> getJacobianDeterminants(Matrices const &J) {
239+
Kokkos::View<Real *> getJacobianDeterminants(Matrices const &J) const {
240240
static_assert(has_static_rank<Matrices>::value,
241241
"Matrices must have a static rank() method.");
242242
static_assert(has_extent_method<Matrices>::value,
@@ -321,7 +321,7 @@ struct FieldElement {
321321
* @return Kokkos::View containing the jacobian for all the mesh elements
322322
*/
323323
Kokkos::View<Real ***> getJacobians(Kokkos::View<Real **> localCoords,
324-
Kokkos::View<LO *> offsets) {
324+
Kokkos::View<LO *> offsets) const {
325325
if (Debug) {
326326
// check input parametric coords are positive and sum to one
327327
LO numErrors = 0;

0 commit comments

Comments
 (0)