Skip to content

Commit c732361

Browse files
committed
fix(RegularGrid): adapt to unstructured convention
1 parent 5ef6b7c commit c732361

File tree

8 files changed

+80
-63
lines changed

8 files changed

+80
-63
lines changed

include/geode/mesh/core/private/grid_impl.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,6 @@ namespace geode
128128
return vertex_id;
129129
}
130130

131-
absl::optional< index_t > cell_adjacent(
132-
const RegularGrid< dimension >& grid,
133-
index_t element,
134-
local_index_t facet ) const
135-
{
136-
const auto cell = cell_indices( grid, element );
137-
const index_t direction = static_cast< index_t >( facet / 2 );
138-
if( ( facet & 1 ) == 0 /* modulo 2 */ )
139-
{
140-
if( const auto adj = grid.previous_cell( cell, direction ) )
141-
{
142-
return grid.cell_index( adj.value() );
143-
}
144-
}
145-
else
146-
{
147-
if( const auto adj = grid.next_cell( cell, direction ) )
148-
{
149-
return grid.cell_index( adj.value() );
150-
}
151-
}
152-
return absl::nullopt;
153-
}
154-
155131
protected:
156132
void do_update_origin( RegularGrid< dimension >& grid,
157133
PointsImpl< dimension >& impl,

include/geode/mesh/helpers/private/regular_grid_shape_function.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,17 @@
2929
namespace geode
3030
{
3131
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
32-
FORWARD_DECLARATION_DIMENSION_CLASS( RegularGrid );
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Grid );
3333
} // namespace geode
3434

3535
namespace geode
3636
{
3737
namespace detail
3838
{
3939
template < index_t dimension >
40-
double shape_function_value( const RegularGrid< dimension >& grid,
40+
double shape_function_value( const Grid< dimension >& grid,
4141
const GridCellIndices< dimension >& cell_id,
4242
local_index_t node_id,
4343
const Point< dimension >& point );
44-
45-
template < index_t dimension >
46-
GridVertexIndices< dimension > cell_node_index(
47-
const GridCellIndices< dimension >& cell_id,
48-
local_index_t node_id );
4944
} // namespace detail
5045
} // namespace geode

src/geode/mesh/core/geode_regular_grid_solid.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ namespace geode
8989
return { facet.polyhedron_id, vertex };
9090
}
9191

92+
absl::optional< index_t > cell_adjacent( const RegularGrid3D& grid,
93+
const PolyhedronFacet& polyhedron_facet ) const
94+
{
95+
const auto cell =
96+
cell_indices( grid, polyhedron_facet.polyhedron_id );
97+
const index_t direction =
98+
static_cast< index_t >( polyhedron_facet.facet_id / 2 );
99+
if( ( polyhedron_facet.facet_id & 1 ) == 0 /* modulo 2 */ )
100+
{
101+
if( const auto adj = grid.previous_cell( cell, direction ) )
102+
{
103+
return grid.cell_index( adj.value() );
104+
}
105+
}
106+
else
107+
{
108+
if( const auto adj = grid.next_cell( cell, direction ) )
109+
{
110+
return grid.cell_index( adj.value() );
111+
}
112+
}
113+
return absl::nullopt;
114+
}
115+
92116
private:
93117
Impl() = default;
94118

@@ -169,8 +193,7 @@ namespace geode
169193
OpenGeodeRegularGrid< 3 >::get_polyhedron_adjacent(
170194
const PolyhedronFacet& polyhedron_facet ) const
171195
{
172-
return impl_->cell_adjacent(
173-
*this, polyhedron_facet.polyhedron_id, polyhedron_facet.facet_id );
196+
return impl_->cell_adjacent( *this, polyhedron_facet );
174197
}
175198

176199
void OpenGeodeRegularGrid< 3 >::update_origin(

src/geode/mesh/core/geode_regular_grid_surface.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
namespace
3939
{
4040
static constexpr std::array< std::array< geode::local_index_t, 2 >, 4 >
41-
cell_vertices_translations{ { { 0, 0 }, { 1, 0 }, { 0, 1 },
42-
{ 1, 1 } } };
41+
cell_vertices_translations{ { { 0, 0 }, { 1, 0 }, { 1, 1 },
42+
{ 0, 1 } } };
43+
static constexpr std::array< std::pair< bool, geode::index_t >, 4 >
44+
cell_adjacent_directions{ { { false, 1 }, { true, 0 }, { true, 1 },
45+
{ false, 0 } } };
4346
} // namespace
4447

4548
namespace geode
@@ -72,6 +75,29 @@ namespace geode
7275
return vertex_index( grid, cell_vertex );
7376
}
7477

78+
absl::optional< index_t > cell_adjacent(
79+
const RegularGrid2D& grid, const PolygonEdge& edge ) const
80+
{
81+
const auto cell = cell_indices( grid, edge.polygon_id );
82+
const auto& direction = cell_adjacent_directions[edge.edge_id];
83+
if( direction.first )
84+
{
85+
if( const auto adj = grid.next_cell( cell, direction.second ) )
86+
{
87+
return grid.cell_index( adj.value() );
88+
}
89+
}
90+
else
91+
{
92+
if( const auto adj =
93+
grid.previous_cell( cell, direction.second ) )
94+
{
95+
return grid.cell_index( adj.value() );
96+
}
97+
}
98+
return absl::nullopt;
99+
}
100+
75101
private:
76102
Impl() = default;
77103

@@ -145,7 +171,7 @@ namespace geode
145171
absl::optional< index_t > OpenGeodeRegularGrid< 2 >::get_polygon_adjacent(
146172
const PolygonEdge& edge ) const
147173
{
148-
return impl_->cell_adjacent( *this, edge.polygon_id, edge.edge_id );
174+
return impl_->cell_adjacent( *this, edge );
149175
}
150176

151177
void OpenGeodeRegularGrid< 2 >::update_origin(

src/geode/mesh/helpers/private/regular_grid_shape_function.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
#include <geode/geometry/point.h>
2727

28-
#include <geode/mesh/core/regular_grid_solid.h>
29-
#include <geode/mesh/core/regular_grid_surface.h>
28+
#include <geode/mesh/core/grid.h>
3029

3130
namespace
3231
{
@@ -41,7 +40,7 @@ namespace
4140

4241
template < geode::index_t dimension >
4342
geode::Point< dimension > local_point_coordinates(
44-
const geode::RegularGrid< dimension >& grid,
43+
const geode::Grid< dimension >& grid,
4544
const geode::Point< dimension >& point,
4645
const geode::GridCellIndices< dimension >& cell_id )
4746
{
@@ -69,7 +68,7 @@ namespace geode
6968
namespace detail
7069
{
7170
template < index_t dimension >
72-
double shape_function_value( const RegularGrid< dimension >& grid,
71+
double shape_function_value( const Grid< dimension >& grid,
7372
const GridCellIndices< dimension >& cell_id,
7473
local_index_t node_id,
7574
const Point< dimension >& point )
@@ -91,35 +90,16 @@ namespace geode
9190
return shape_function_value;
9291
}
9392

94-
template < index_t dimension >
95-
GridVertexIndices< dimension > cell_node_index(
96-
const GridCellIndices< dimension >& cell_id, local_index_t node_id )
97-
{
98-
auto node_index = cell_id;
99-
for( const auto d : LRange{ dimension } )
100-
{
101-
if( !node_is_on_axis_origin< dimension >( node_id, d ) )
102-
{
103-
node_index[d] += 1;
104-
}
105-
}
106-
return node_index;
107-
}
108-
10993
template double opengeode_mesh_api shape_function_value< 2 >(
110-
const RegularGrid< 2 >& grid,
94+
const Grid< 2 >& grid,
11195
const GridCellIndices< 2 >& cell_id,
11296
local_index_t node_id,
11397
const Point< 2 >& point );
114-
template GridVertexIndices< 2 > opengeode_mesh_api cell_node_index< 2 >(
115-
const GridCellIndices< 2 >& cell_id, local_index_t node_id );
11698

11799
template double opengeode_mesh_api shape_function_value< 3 >(
118-
const RegularGrid< 3 >& grid,
100+
const Grid< 3 >& grid,
119101
const GridCellIndices< 3 >& cell_id,
120102
local_index_t node_id,
121103
const Point< 3 >& point );
122-
template GridVertexIndices< 3 > opengeode_mesh_api cell_node_index< 3 >(
123-
const GridCellIndices< 3 >& cell_id, local_index_t node_id );
124104
} // namespace detail
125105
} // namespace geode

src/geode/mesh/helpers/regular_grid_point_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace geode
102102
for( const auto node_id : LRange{ grid_.nb_cell_vertices() } )
103103
{
104104
point_value += function_attribute_->value( grid_.vertex_index(
105-
detail::cell_node_index< dimension >(
105+
grid_.cell_vertex_indices(
106106
grid_cell_indices, node_id ) ) )
107107
* detail::shape_function_value< dimension >(
108108
grid_, grid_cell_indices, node_id, point );

src/geode/mesh/helpers/regular_grid_scalar_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace geode
101101
point_value += detail::shape_function_value< dimension >(
102102
grid_, grid_cell_indices, node_id, point )
103103
* function_attribute_->value( grid_.vertex_index(
104-
detail::cell_node_index< dimension >(
104+
grid_.cell_vertex_indices(
105105
grid_cell_indices, node_id ) ) );
106106
}
107107
return point_value;

tests/mesh/test-regular-grid.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include <geode/geometry/point.h>
3131

3232
#include <geode/mesh/builder/regular_grid_solid_builder.h>
33+
#include <geode/mesh/builder/regular_grid_surface_builder.h>
3334
#include <geode/mesh/core/regular_grid_solid.h>
35+
#include <geode/mesh/core/regular_grid_surface.h>
3436
#include <geode/mesh/io/regular_grid_input.h>
3537
#include <geode/mesh/io/regular_grid_output.h>
3638

@@ -392,6 +394,20 @@ void test_io( const geode::RegularGrid3D& grid, absl::string_view filename )
392394
geode::load_regular_grid< 3 >( filename );
393395
}
394396

397+
void test_adjacencies2D()
398+
{
399+
auto grid = geode::RegularGrid2D::create();
400+
auto builder = geode::RegularGridBuilder2D::create( *grid );
401+
builder->initialize_grid( { { 0., 0. } }, { 10, 10 }, 1 );
402+
for( const auto p : geode::Range{ grid->nb_polygons() } )
403+
{
404+
for( const auto ee : geode::LRange{ grid->nb_polygon_edges( p ) } )
405+
{
406+
grid->polygon_adjacent_edge( { p, ee } );
407+
}
408+
}
409+
}
410+
395411
void test()
396412
{
397413
auto grid = geode::RegularGrid3D::create();
@@ -408,6 +424,7 @@ void test()
408424
test_closest_vertex( *grid );
409425
test_clone( *grid );
410426
test_io( *grid, absl::StrCat( "test.", grid->native_extension() ) );
427+
test_adjacencies2D();
411428
}
412429

413430
OPENGEODE_TEST( "regular-grid" )

0 commit comments

Comments
 (0)