Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #773 #776

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/t8_forest/t8_forest_cxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,28 @@ t8_forest_element_diam (t8_forest_t forest, t8_locidx_t ltreeid, const t8_elemen
void
t8_forest_element_centroid (t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *element, double *coordinates)
{
t8_eclass_t tree_class;
t8_element_shape_t element_shape;
t8_eclass_scheme_c *ts;
double corner_coords[3] = { 0.0 };

T8_ASSERT (t8_forest_is_committed (forest));

/* Get the tree's eclass and scheme */
tree_class = t8_forest_get_tree_class (forest, ltreeid);
/* Get the tree's eclass and scheme. */
t8_eclass_t tree_class = t8_forest_get_tree_class (forest, ltreeid);
ts = t8_forest_get_eclass_scheme (forest, tree_class);
T8_ASSERT (ts->t8_element_is_valid (element));

/* Get the element class and calculate the centroid using its element
* reference coordinates */
element_shape = t8_element_shape (ts, element);
t8_forest_element_from_ref_coords (forest, ltreeid, element, t8_element_centroid_ref_coords[element_shape], 1,
coordinates, NULL);
/* Initialize the centroid with (0, 0, 0). */
memset (coordinates, 0, 3 * sizeof (double));
/* Get the number of corners of the element. */
const int num_corners = ts->t8_element_num_corners (element);
for (int icorner = 0; icorner < num_corners; icorner++) {
/* For each corner, add its coordinates to the centroids coordinates. */
t8_forest_element_coordinate (forest, ltreeid, element, icorner, corner_coords);
/* coordinates = coordinates + corner_coords */
t8_vec_axpy (corner_coords, coordinates, 1);
}
/* Divide each coordinate by num_corners */
t8_vec_ax (coordinates, 1. / num_corners);
}

/* Compute the length of the line from one corner to a second corner in an element */
Expand Down