Skip to content

Commit f03497c

Browse files
committed
fix(shape_function): Moved utilitary function from namespace to api.
1 parent 784077a commit f03497c

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ namespace geode
3737
{
3838
namespace internal
3939
{
40+
[[nodiscard]] bool opengeode_mesh_api local_cell_node_is_on_axis_origin(
41+
geode::local_index_t node_id, geode::local_index_t axis_id );
42+
4043
template < index_t dimension >
4144
[[nodiscard]] double shape_function_value(
4245
const typename Grid< dimension >::CellIndices& cell_id,

src/geode/mesh/helpers/internal/grid_shape_function.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@
3030

3131
namespace
3232
{
33-
template < geode::index_t dimension >
34-
bool node_is_on_axis_origin(
35-
geode::local_index_t node_id, geode::local_index_t axis_id )
36-
{
37-
/* returns ((node_id / pow(2,axis_id)) modulo 2) using binary
38-
* operators (faster). */
39-
return ( ( node_id / ( 1 << axis_id ) ) & 1 ) == 0;
40-
}
41-
4233
template < geode::index_t dimension >
4334
double local_point_value( const geode::Point< dimension >& point_in_grid,
4435
const typename geode::Grid< dimension >::CellIndices& cell_id,
@@ -62,24 +53,29 @@ namespace geode
6253
{
6354
namespace internal
6455
{
56+
bool local_cell_node_is_on_axis_origin(
57+
geode::local_index_t node_id, geode::local_index_t axis_id )
58+
{
59+
/* returns ((node_id / pow(2,axis_id)) modulo 2) using binary
60+
* operators (faster). */
61+
return ( ( node_id / ( 1 << axis_id ) ) & 1 ) == 0;
62+
}
63+
6564
template < index_t dimension >
6665
double shape_function_value(
6766
const typename Grid< dimension >::CellIndices& cell_id,
6867
local_index_t node_id,
6968
const Point< dimension >& point_in_grid )
7069
{
7170
double result{ 1. };
72-
for( const auto d : LRange{ dimension } )
71+
for( const auto axis : LRange{ dimension } )
7372
{
74-
if( node_is_on_axis_origin< dimension >( node_id, d ) )
75-
{
76-
result *= 1.
77-
- local_point_value< dimension >(
78-
point_in_grid, cell_id, d );
79-
continue;
80-
}
81-
result *=
82-
local_point_value< dimension >( point_in_grid, cell_id, d );
73+
result *= local_cell_node_is_on_axis_origin( node_id, axis )
74+
? 1.
75+
- local_point_value< dimension >(
76+
point_in_grid, cell_id, axis )
77+
: local_point_value< dimension >(
78+
point_in_grid, cell_id, axis );
8379
}
8480
return result;
8581
}
@@ -92,23 +88,20 @@ namespace geode
9288
local_index_t direction )
9389
{
9490
double result{ 1. };
95-
for( const auto dim : LRange{ dimension } )
91+
for( const auto axis : LRange{ dimension } )
9692
{
97-
if( dim == direction )
98-
{
99-
continue;
100-
}
101-
if( node_is_on_axis_origin< dimension >( node_id, dim ) )
93+
if( axis == direction )
10294
{
103-
result *= 1.
104-
- local_point_value< dimension >(
105-
point_in_grid, cell_id, dim );
10695
continue;
10796
}
108-
result *= local_point_value< dimension >(
109-
point_in_grid, cell_id, dim );
97+
result *= local_cell_node_is_on_axis_origin( node_id, axis )
98+
? 1.
99+
- local_point_value< dimension >(
100+
point_in_grid, cell_id, axis )
101+
: local_point_value< dimension >(
102+
point_in_grid, cell_id, axis );
110103
}
111-
if( node_is_on_axis_origin< dimension >( node_id, direction ) )
104+
if( local_cell_node_is_on_axis_origin( node_id, direction ) )
112105
{
113106
result *= -1.;
114107
}

0 commit comments

Comments
 (0)