Skip to content

Commit 49a09e3

Browse files
committed
fix(gradient computation): Added functions to compute gradient giving no value vertices instead of nan, and gradient shape functions for grids.
1 parent 268a3d9 commit 49a09e3

File tree

8 files changed

+330
-74
lines changed

8 files changed

+330
-74
lines changed

include/geode/mesh/helpers/generic_edged_curve_accessor.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ namespace geode
5252
{
5353
}
5454

55+
[[nodiscard]] index_t nb_vertices() const
56+
{
57+
return mesh_.nb_vertices();
58+
}
59+
5560
[[nodiscard]] index_t nb_elements() const
5661
{
5762
return mesh_.nb_edges();

include/geode/mesh/helpers/generic_solid_accessor.hpp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,40 @@ namespace geode
4545
public:
4646
using ElementVertex = PolyhedronVertex;
4747
using ElementVertices = PolyhedronVertices;
48-
using ElementFacet = PolyhedronFacet;
4948
using ElementFacetVertices = PolyhedronFacetVertices;
5049

50+
struct ElementFacet
51+
{
52+
ElementFacet( index_t element, local_index_t facet )
53+
: element_id( element ), facet_id( facet )
54+
{
55+
}
56+
ElementFacet( PolyhedronFacet polyhedron_facet )
57+
: element_id( polyhedron_facet.polyhedron_id ),
58+
facet_id( polyhedron_facet.facet_id )
59+
{
60+
}
61+
62+
bool operator==( const ElementFacet& other ) const
63+
{
64+
return element_id == other.element_id
65+
&& facet_id == other.facet_id;
66+
}
67+
68+
index_t element_id;
69+
local_index_t facet_id;
70+
};
71+
5172
explicit GenericMeshAccessor( const SolidMesh< dimension >& mesh )
5273
: mesh_( mesh )
5374
{
5475
}
5576

77+
[[nodiscard]] index_t nb_vertices() const
78+
{
79+
return mesh_.nb_vertices();
80+
}
81+
5682
[[nodiscard]] index_t nb_elements() const
5783
{
5884
return mesh_.nb_polyhedra();
@@ -87,21 +113,29 @@ namespace geode
87113
}
88114

89115
[[nodiscard]] ElementFacetVertices element_facet_vertices(
90-
const ElementFacet& polyhedron_facet ) const
116+
const ElementFacet& element_facet ) const
91117
{
92-
return mesh_.polyhedron_facet_vertices( polyhedron_facet );
118+
return mesh_.polyhedron_facet_vertices(
119+
{ element_facet.element_id, element_facet.facet_id } );
93120
}
94121

95122
[[nodiscard]] std::optional< index_t > element_adjacent(
96-
const ElementFacet& polyhedron_facet ) const
123+
const ElementFacet& element_facet ) const
97124
{
98-
return mesh_.polyhedron_adjacent( polyhedron_facet );
125+
return mesh_.polyhedron_adjacent(
126+
{ element_facet.element_id, element_facet.facet_id } );
99127
}
100128

101129
[[nodiscard]] std::optional< ElementFacet > element_adjacent_facet(
102-
const ElementFacet& polyhedron_facet ) const
103-
{
104-
return mesh_.polyhedron_adjacent_facet( polyhedron_facet );
130+
ElementFacet element_facet ) const
131+
{
132+
const auto adj = mesh_.polyhedron_adjacent_facet(
133+
{ element_facet.element_id, element_facet.facet_id } );
134+
if( adj )
135+
{
136+
return adj.value();
137+
}
138+
return std::nullopt;
105139
}
106140

107141
[[nodiscard]] const uuid& id() const

include/geode/mesh/helpers/generic_surface_accessor.hpp

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,40 @@ namespace geode
4545
public:
4646
using ElementVertex = PolygonVertex;
4747
using ElementVertices = PolygonVertices;
48-
using ElementFacet = PolygonEdge;
4948
using ElementFacetVertices = std::array< index_t, 2 >;
5049

50+
struct ElementFacet
51+
{
52+
ElementFacet( index_t element, local_index_t facet )
53+
: element_id( element ), facet_id( facet )
54+
{
55+
}
56+
ElementFacet( PolygonEdge polygon_edge )
57+
: element_id( polygon_edge.polygon_id ),
58+
facet_id( polygon_edge.edge_id )
59+
{
60+
}
61+
62+
bool operator==( const ElementFacet& other ) const
63+
{
64+
return element_id == other.element_id
65+
&& facet_id == other.facet_id;
66+
}
67+
68+
index_t element_id;
69+
local_index_t facet_id;
70+
};
71+
5172
explicit GenericMeshAccessor( const SurfaceMesh< dimension >& mesh )
5273
: mesh_( mesh )
5374
{
5475
}
5576

77+
[[nodiscard]] index_t nb_vertices() const
78+
{
79+
return mesh_.nb_vertices();
80+
}
81+
5682
[[nodiscard]] index_t nb_elements() const
5783
{
5884
return mesh_.nb_polygons();
@@ -87,21 +113,29 @@ namespace geode
87113
}
88114

89115
[[nodiscard]] ElementFacetVertices element_facet_vertices(
90-
const ElementFacet& polygon_edge ) const
116+
const ElementFacet& element_facet ) const
91117
{
92-
return mesh_.polygon_edge_vertices( polygon_edge );
118+
return mesh_.polygon_edge_vertices(
119+
{ element_facet.element_id, element_facet.facet_id } );
93120
}
94121

95122
[[nodiscard]] std::optional< index_t > element_adjacent(
96-
const ElementFacet& polygon_edge ) const
123+
const ElementFacet& element_facet ) const
97124
{
98-
return mesh_.polygon_adjacent( polygon_edge );
125+
return mesh_.polygon_adjacent(
126+
{ element_facet.element_id, element_facet.facet_id } );
99127
}
100128

101129
[[nodiscard]] std::optional< ElementFacet > element_adjacent_facet(
102-
const ElementFacet& polygon_edge ) const
130+
const ElementFacet& element_facet ) const
103131
{
104-
return mesh_.polygon_adjacent_edge( polygon_edge );
132+
const auto adj = mesh_.polygon_adjacent_edge(
133+
{ element_facet.element_id, element_facet.facet_id } );
134+
if( adj )
135+
{
136+
return adj.value();
137+
}
138+
return std::nullopt;
105139
}
106140

107141
[[nodiscard]] const uuid& id() const

include/geode/mesh/helpers/gradient_computation.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ namespace geode
4343
[[nodiscard]] std::string opengeode_mesh_api
4444
compute_solid_scalar_function_gradient(
4545
const SolidMesh3D& mesh, std::string_view scalar_function_name );
46+
47+
namespace internal
48+
{
49+
template < index_t dimension >
50+
[[nodiscard]] std::tuple< std::string, std::vector< index_t > >
51+
compute_surface_scalar_function_gradient(
52+
const SurfaceMesh< dimension >& mesh,
53+
std::string_view scalar_function_name,
54+
absl::Span< const index_t > no_value_vertices );
55+
56+
[[nodiscard]] std::tuple< std::string, std::vector< index_t > >
57+
opengeode_mesh_api compute_solid_scalar_function_gradient(
58+
const SolidMesh3D& mesh,
59+
std::string_view scalar_function_name,
60+
absl::Span< const index_t > no_value_vertices );
61+
} // namespace internal
4662
} // namespace geode

include/geode/mesh/helpers/internal/grid_shape_function.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
namespace geode
3030
{
3131
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
3233
FORWARD_DECLARATION_DIMENSION_CLASS( Grid );
3334
} // namespace geode
3435

@@ -41,5 +42,12 @@ namespace geode
4142
const typename Grid< dimension >::CellIndices& cell_id,
4243
local_index_t node_id,
4344
const Point< dimension >& point_in_grid );
45+
46+
template < index_t dimension >
47+
[[nodiscard]] double gradient_shape_function_value(
48+
const typename Grid< dimension >::CellIndices& cell_id,
49+
local_index_t node_id,
50+
const Point< dimension >& point_in_grid,
51+
local_index_t derivative_direction );
4452
} // namespace internal
4553
} // namespace geode

0 commit comments

Comments
 (0)