Skip to content

Commit 377a8f1

Browse files
committed
fix(compute_gradient): Small changes to make the code more general and avoid exceptions.
1 parent 1ffbbd4 commit 377a8f1

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

include/geode/geometry/nn_search.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ namespace geode
5656
std::vector< Point< dimension > > unique_points;
5757
/*!
5858
* This list has the size of the number of points in the tree.
59-
* Each index is pointing to its old point index as given in input
60-
* vector.
59+
* Each index is pointing to its new unique point stored in the
60+
* unique_points vector.
6161
*/
6262
std::vector< index_t > colocated_mapping;
6363
/*!
6464
* This list has the size of the number of points in the tree.
65-
* Each index is pointing to its new unique point stored in the
66-
* unique_points vector.
65+
* Each index is pointing to its old point index as given in input
66+
* vector.
6767
*/
6868
std::vector< index_t > colocated_input_points;
6969
};

src/geode/mesh/helpers/gradient_computation.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace
132132
geode::Vector< Mesh::dim > computed_gradient;
133133
const auto vertices_around =
134134
mesh_.vertices_around_vertex( vertex_id );
135+
bool value_set{ false };
135136
for( const auto d : geode::LRange{ Mesh::dim } )
136137
{
137138
double contribution_sum{ 0 };
@@ -164,16 +165,18 @@ namespace
164165
inverse_dist_sum +=
165166
diff_sign * position_diff.value( d ) / dist2;
166167
}
167-
OPENGEODE_EXCEPTION(
168-
std::fabs( inverse_dist_sum ) > geode::GLOBAL_EPSILON,
169-
"[compute_scalar_function_gradient] Couldn't compute "
170-
"gradient on vertex ",
171-
vertex_id,
172-
": No vertex around it allows computation of the "
173-
"derivative along axis ",
174-
d );
168+
if( std::fabs( inverse_dist_sum ) <= geode::GLOBAL_EPSILON )
169+
{
170+
computed_gradient.set_value( d, 0 );
171+
continue;
172+
}
175173
computed_gradient.set_value(
176174
d, contribution_sum / inverse_dist_sum );
175+
value_set = true;
176+
}
177+
if( !value_set )
178+
{
179+
return false;
177180
}
178181
gradient_function.set_value( vertex_id, computed_gradient );
179182
return true;

0 commit comments

Comments
 (0)