Skip to content

Commit

Permalink
fix(gradient computation): Added functions to compute gradient giving…
Browse files Browse the repository at this point in the history
… no value vertices instead of nan, and gradient shape functions for grids.
  • Loading branch information
MelchiorSchuh committed Oct 25, 2024
1 parent 268a3d9 commit 49a09e3
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 74 deletions.
5 changes: 5 additions & 0 deletions include/geode/mesh/helpers/generic_edged_curve_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ namespace geode
{
}

[[nodiscard]] index_t nb_vertices() const
{
return mesh_.nb_vertices();
}

[[nodiscard]] index_t nb_elements() const
{
return mesh_.nb_edges();
Expand Down
50 changes: 42 additions & 8 deletions include/geode/mesh/helpers/generic_solid_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,40 @@ namespace geode
public:
using ElementVertex = PolyhedronVertex;
using ElementVertices = PolyhedronVertices;
using ElementFacet = PolyhedronFacet;
using ElementFacetVertices = PolyhedronFacetVertices;

struct ElementFacet
{
ElementFacet( index_t element, local_index_t facet )
: element_id( element ), facet_id( facet )
{
}
ElementFacet( PolyhedronFacet polyhedron_facet )
: element_id( polyhedron_facet.polyhedron_id ),
facet_id( polyhedron_facet.facet_id )
{
}

bool operator==( const ElementFacet& other ) const
{
return element_id == other.element_id
&& facet_id == other.facet_id;
}

index_t element_id;
local_index_t facet_id;
};

explicit GenericMeshAccessor( const SolidMesh< dimension >& mesh )
: mesh_( mesh )
{
}

[[nodiscard]] index_t nb_vertices() const
{
return mesh_.nb_vertices();
}

[[nodiscard]] index_t nb_elements() const
{
return mesh_.nb_polyhedra();
Expand Down Expand Up @@ -87,21 +113,29 @@ namespace geode
}

[[nodiscard]] ElementFacetVertices element_facet_vertices(
const ElementFacet& polyhedron_facet ) const
const ElementFacet& element_facet ) const
{
return mesh_.polyhedron_facet_vertices( polyhedron_facet );
return mesh_.polyhedron_facet_vertices(
{ element_facet.element_id, element_facet.facet_id } );
}

[[nodiscard]] std::optional< index_t > element_adjacent(
const ElementFacet& polyhedron_facet ) const
const ElementFacet& element_facet ) const
{
return mesh_.polyhedron_adjacent( polyhedron_facet );
return mesh_.polyhedron_adjacent(
{ element_facet.element_id, element_facet.facet_id } );
}

[[nodiscard]] std::optional< ElementFacet > element_adjacent_facet(
const ElementFacet& polyhedron_facet ) const
{
return mesh_.polyhedron_adjacent_facet( polyhedron_facet );
ElementFacet element_facet ) const
{
const auto adj = mesh_.polyhedron_adjacent_facet(
{ element_facet.element_id, element_facet.facet_id } );
if( adj )
{
return adj.value();
}
return std::nullopt;
}

[[nodiscard]] const uuid& id() const
Expand Down
48 changes: 41 additions & 7 deletions include/geode/mesh/helpers/generic_surface_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,40 @@ namespace geode
public:
using ElementVertex = PolygonVertex;
using ElementVertices = PolygonVertices;
using ElementFacet = PolygonEdge;
using ElementFacetVertices = std::array< index_t, 2 >;

struct ElementFacet
{
ElementFacet( index_t element, local_index_t facet )
: element_id( element ), facet_id( facet )
{
}
ElementFacet( PolygonEdge polygon_edge )
: element_id( polygon_edge.polygon_id ),
facet_id( polygon_edge.edge_id )
{
}

bool operator==( const ElementFacet& other ) const
{
return element_id == other.element_id
&& facet_id == other.facet_id;
}

index_t element_id;
local_index_t facet_id;
};

explicit GenericMeshAccessor( const SurfaceMesh< dimension >& mesh )
: mesh_( mesh )
{
}

[[nodiscard]] index_t nb_vertices() const
{
return mesh_.nb_vertices();
}

[[nodiscard]] index_t nb_elements() const
{
return mesh_.nb_polygons();
Expand Down Expand Up @@ -87,21 +113,29 @@ namespace geode
}

[[nodiscard]] ElementFacetVertices element_facet_vertices(
const ElementFacet& polygon_edge ) const
const ElementFacet& element_facet ) const
{
return mesh_.polygon_edge_vertices( polygon_edge );
return mesh_.polygon_edge_vertices(
{ element_facet.element_id, element_facet.facet_id } );
}

[[nodiscard]] std::optional< index_t > element_adjacent(
const ElementFacet& polygon_edge ) const
const ElementFacet& element_facet ) const
{
return mesh_.polygon_adjacent( polygon_edge );
return mesh_.polygon_adjacent(
{ element_facet.element_id, element_facet.facet_id } );
}

[[nodiscard]] std::optional< ElementFacet > element_adjacent_facet(
const ElementFacet& polygon_edge ) const
const ElementFacet& element_facet ) const
{
return mesh_.polygon_adjacent_edge( polygon_edge );
const auto adj = mesh_.polygon_adjacent_edge(
{ element_facet.element_id, element_facet.facet_id } );
if( adj )
{
return adj.value();
}
return std::nullopt;
}

[[nodiscard]] const uuid& id() const
Expand Down
16 changes: 16 additions & 0 deletions include/geode/mesh/helpers/gradient_computation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ namespace geode
[[nodiscard]] std::string opengeode_mesh_api
compute_solid_scalar_function_gradient(
const SolidMesh3D& mesh, std::string_view scalar_function_name );

namespace internal
{
template < index_t dimension >
[[nodiscard]] std::tuple< std::string, std::vector< index_t > >
compute_surface_scalar_function_gradient(
const SurfaceMesh< dimension >& mesh,
std::string_view scalar_function_name,
absl::Span< const index_t > no_value_vertices );

[[nodiscard]] std::tuple< std::string, std::vector< index_t > >
opengeode_mesh_api compute_solid_scalar_function_gradient(
const SolidMesh3D& mesh,
std::string_view scalar_function_name,
absl::Span< const index_t > no_value_vertices );
} // namespace internal
} // namespace geode
8 changes: 8 additions & 0 deletions include/geode/mesh/helpers/internal/grid_shape_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
FORWARD_DECLARATION_DIMENSION_CLASS( Grid );
} // namespace geode

Expand All @@ -41,5 +42,12 @@ namespace geode
const typename Grid< dimension >::CellIndices& cell_id,
local_index_t node_id,
const Point< dimension >& point_in_grid );

template < index_t dimension >
[[nodiscard]] double gradient_shape_function_value(
const typename Grid< dimension >::CellIndices& cell_id,
local_index_t node_id,
const Point< dimension >& point_in_grid,
local_index_t derivative_direction );
} // namespace internal
} // namespace geode
Loading

0 comments on commit 49a09e3

Please sign in to comment.