Skip to content

Conversation

@Joshua-Kloepfer
Copy link
Collaborator

Added quadratic and linear tet as shape functions.

@cwsmith
Copy link
Contributor

cwsmith commented Aug 1, 2025

/runtests


template <typename ViewType, typename ShapeField>
auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
ShapeField field) {

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
ShapeField<1UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>>
is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type
ShapeField<1UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>>
is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<2UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<3UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<2UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<3UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***>, LinearTriangleShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTriangleShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 344 bytes - consider passing a const pointer/reference instead.

Copilot Autofix

AI 5 months ago

To fix the problem, we should change the parameter type of field in the function tetrahedronLocalPointEval (lines 359–364) from being passed by value to being passed by const reference. This means changing the function signature from ShapeField field to const ShapeField& field. This change should be made in both the declaration and the definition of the function template. Since the function is a template, this change will not affect its usage elsewhere, as template argument deduction will still work. No other code changes are needed unless there are other overloads or calls that rely on the value semantics, but from the provided snippet, this is not the case.


Suggested changeset 1
src/MeshField.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/MeshField.hpp b/src/MeshField.hpp
--- a/src/MeshField.hpp
+++ b/src/MeshField.hpp
@@ -359,3 +359,3 @@
   auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
-                                 ShapeField field) {
+                                 const ShapeField& field) {
     auto offsets = createOffsets(meshInfo.numTet, NumPtsPerElem);
EOF
@@ -359,3 +359,3 @@
auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
ShapeField field) {
const ShapeField& field) {
auto offsets = createOffsets(meshInfo.numTet, NumPtsPerElem);
Copilot is powered by AI and may make mistakes. Always verify output.

template <typename ViewType, typename ShapeField>
auto tetrahedronLocalPointEval(ViewType localCoords,
Kokkos::View<LO *> offsets, ShapeField field) {

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
ShapeField<3UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>>
is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type
ShapeField<2UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>>
is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<3UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<2UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTetrahedronShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***>, LinearTetrahedronShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***, double ***>, QuadraticTriangleShape, QuadraticAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>, Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 344 bytes - consider passing a const pointer/reference instead.
This parameter of type ShapeField<1UL, KokkosController<HostSpace, Serial, double ***>, LinearTriangleShape, LinearAccessor<Field<KokkosSliceWrapper<View<double ***, HostSpace>, double ***>>>> is 200 bytes - consider passing a const pointer/reference instead.

Copilot Autofix

AI 5 months ago

To fix the problem, we should change the field parameter in the relevant function templates from being passed by value to being passed by const reference. This means changing the parameter type from ShapeField field to const ShapeField& field in both overloads of tetrahedronLocalPointEval (lines 359 and 368). This change should be made in the function declarations and definitions within the shown code. No additional imports or definitions are needed, as this is standard C++ practice.


Suggested changeset 1
src/MeshField.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/MeshField.hpp b/src/MeshField.hpp
--- a/src/MeshField.hpp
+++ b/src/MeshField.hpp
@@ -359,3 +359,3 @@
   auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
-                                 ShapeField field) {
+                                 const ShapeField& field) {
     auto offsets = createOffsets(meshInfo.numTet, NumPtsPerElem);
@@ -367,3 +367,3 @@
   auto tetrahedronLocalPointEval(ViewType localCoords,
-                                 Kokkos::View<LO *> offsets, ShapeField field) {
+                                 Kokkos::View<LO *> offsets, const ShapeField& field) {
     const auto MeshDim = 3;
EOF
@@ -359,3 +359,3 @@
auto tetrahedronLocalPointEval(ViewType localCoords, size_t NumPtsPerElem,
ShapeField field) {
const ShapeField& field) {
auto offsets = createOffsets(meshInfo.numTet, NumPtsPerElem);
@@ -367,3 +367,3 @@
auto tetrahedronLocalPointEval(ViewType localCoords,
Kokkos::View<LO *> offsets, ShapeField field) {
Kokkos::View<LO *> offsets, const ShapeField& field) {
const auto MeshDim = 3;
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link

github-actions bot commented Aug 1, 2025

Test Result: success (details)

Copy link
Contributor

@cwsmith cwsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you.

One small change is requested below for the name of the new test file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename this to testOmegahTet.cpp. In a subsequent PR/commit we can rename testOmegahElement.cpp to testOmegahTri.cpp for consistency.

Likewise, in another PR we should add tests for multiple components and the cabana backend.

#include <MeshField.hpp>
#include <Omega_h_build.hpp>
#include <Omega_h_mesh.hpp>
template <size_t order> void runTest(Omega_h::Mesh mesh) {

Check warning

Code scanning / CodeQL

Poorly documented large function Warning test

Poorly documented function: fewer than 2% comments for a function of 121 lines.

Copilot Autofix

AI 5 months ago

To fix the problem, we should add comments to the runTest function to document its purpose, parameters, and the main steps of its logic. This includes a function-level comment explaining what the function does, what its template parameter and arguments mean, and inline comments throughout the function to clarify non-obvious code sections. The changes should be made directly above and within the runTest function in test/testOmegahTet.cpp, without altering the function's logic or behavior.


Suggested changeset 1
test/testOmegahTet.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/testOmegahTet.cpp b/test/testOmegahTet.cpp
--- a/test/testOmegahTet.cpp
+++ b/test/testOmegahTet.cpp
@@ -4,8 +4,23 @@
 #include <Omega_h_mesh.hpp>
+/**
+ * @brief Runs a test of Lagrange field interpolation and evaluation on a given mesh.
+ *
+ * This function creates a Lagrange field of the specified order on the input mesh,
+ * assigns values to the field at mesh vertices (and edges for quadratic order),
+ * evaluates the field at local points within each element, and checks the accuracy
+ * of the mapping between local and global coordinates.
+ *
+ * @tparam order The order of the Lagrange field (1 for linear, 2 for quadratic).
+ * @param mesh The Omega_h mesh on which to run the test.
+ */
 template <size_t order> void runTest(Omega_h::Mesh mesh) {
+  // Create a mesh field object for the given mesh.
   MeshField::OmegahMeshField<Kokkos::DefaultExecutionSpace, 3> mesh_field(mesh);
+  // Create a Lagrange field of the specified order and scalar type.
   auto shape_field =
       mesh_field.template CreateLagrangeField<double, order, 1>();
+  // Get mesh dimension and coordinates array.
   auto dim = mesh.dim();
   auto coords = mesh.coords();
+  // Define a test function to assign to the field: f(x, y, z) = 2x + 3y + 4z.
   auto f = KOKKOS_LAMBDA(double x, double y, double z)->double {
@@ -13,4 +28,6 @@
   };
+  // Get edge-to-vertex and element-to-edge connectivity.
   auto edge2vtx = mesh.ask_down(1, 0).ab2b;
   auto edgeMap = mesh.ask_down(dim, 1).ab2b;
+  // Assign field values at mesh vertices using the test function.
   Kokkos::parallel_for(
@@ -22,2 +39,3 @@
       });
+  // For quadratic (order 2) fields, assign values at edge midpoints.
   if (order == 2) {
@@ -27,2 +45,3 @@
           const auto right = edge2vtx[edge * 2 + 1];
+          // Compute midpoint coordinates of the edge.
           const auto x = (coords[left * dim] + coords[right * dim]) / 2.0;
@@ -35,4 +54,7 @@
   }
+  // Set the number of nodes per element based on the field order.
   const auto numNodesPerElem = order == 2 ? 10 : 4;
+  // Allocate a Kokkos view for local coordinates in each element.
   Kokkos::View<double **> local_coords("", mesh.nelems() * numNodesPerElem, 4);
+  // Set local coordinates for each node in each element.
   Kokkos::parallel_for(
@@ -66,2 +88,3 @@
       });
+  // Evaluate the field at the specified local coordinates in each element.
   auto eval_results = mesh_field.tetrahedronLocalPointEval(
@@ -70,4 +93,6 @@
   int errors = 0;
+  // Get element-to-vertex connectivity and the coordinate field.
   const auto tetVerts = mesh.ask_elem_verts();
   const auto coordField = mesh_field.getCoordField();
+  // Check that the mapping from local to global coordinates is accurate.
   Kokkos::parallel_reduce(
@@ -121,5 +146,2 @@
       errors);
-  if (errors > 0) {
-    MeshField::fail("One or more mappings did not match\n");
-  }
 }
EOF
@@ -4,8 +4,23 @@
#include <Omega_h_mesh.hpp>
/**
* @brief Runs a test of Lagrange field interpolation and evaluation on a given mesh.
*
* This function creates a Lagrange field of the specified order on the input mesh,
* assigns values to the field at mesh vertices (and edges for quadratic order),
* evaluates the field at local points within each element, and checks the accuracy
* of the mapping between local and global coordinates.
*
* @tparam order The order of the Lagrange field (1 for linear, 2 for quadratic).
* @param mesh The Omega_h mesh on which to run the test.
*/
template <size_t order> void runTest(Omega_h::Mesh mesh) {
// Create a mesh field object for the given mesh.
MeshField::OmegahMeshField<Kokkos::DefaultExecutionSpace, 3> mesh_field(mesh);
// Create a Lagrange field of the specified order and scalar type.
auto shape_field =
mesh_field.template CreateLagrangeField<double, order, 1>();
// Get mesh dimension and coordinates array.
auto dim = mesh.dim();
auto coords = mesh.coords();
// Define a test function to assign to the field: f(x, y, z) = 2x + 3y + 4z.
auto f = KOKKOS_LAMBDA(double x, double y, double z)->double {
@@ -13,4 +28,6 @@
};
// Get edge-to-vertex and element-to-edge connectivity.
auto edge2vtx = mesh.ask_down(1, 0).ab2b;
auto edgeMap = mesh.ask_down(dim, 1).ab2b;
// Assign field values at mesh vertices using the test function.
Kokkos::parallel_for(
@@ -22,2 +39,3 @@
});
// For quadratic (order 2) fields, assign values at edge midpoints.
if (order == 2) {
@@ -27,2 +45,3 @@
const auto right = edge2vtx[edge * 2 + 1];
// Compute midpoint coordinates of the edge.
const auto x = (coords[left * dim] + coords[right * dim]) / 2.0;
@@ -35,4 +54,7 @@
}
// Set the number of nodes per element based on the field order.
const auto numNodesPerElem = order == 2 ? 10 : 4;
// Allocate a Kokkos view for local coordinates in each element.
Kokkos::View<double **> local_coords("", mesh.nelems() * numNodesPerElem, 4);
// Set local coordinates for each node in each element.
Kokkos::parallel_for(
@@ -66,2 +88,3 @@
});
// Evaluate the field at the specified local coordinates in each element.
auto eval_results = mesh_field.tetrahedronLocalPointEval(
@@ -70,4 +93,6 @@
int errors = 0;
// Get element-to-vertex connectivity and the coordinate field.
const auto tetVerts = mesh.ask_elem_verts();
const auto coordField = mesh_field.getCoordField();
// Check that the mapping from local to global coordinates is accurate.
Kokkos::parallel_reduce(
@@ -121,5 +146,2 @@
errors);
if (errors > 0) {
MeshField::fail("One or more mappings did not match\n");
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

@cwsmith cwsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cwsmith cwsmith merged commit fc4ef7d into main Aug 5, 2025
6 checks passed
@cwsmith cwsmith deleted the jk/linearTet branch August 5, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants