Skip to content

Commit

Permalink
integrate error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Park authored and Mike Park committed Jun 30, 2021
1 parent 07f6b11 commit 525812b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/ref_metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,42 @@ REF_STATUS ref_metric_interpolation_error(REF_DBL *metric, REF_DBL *hess,
return REF_SUCCESS;
}

REF_STATUS ref_metric_integrate_error(REF_GRID ref_grid,
REF_DBL *interpolation_error,
REF_DBL *total_error) {
REF_NODE ref_node = ref_grid_node(ref_grid);
REF_CELL ref_cell;
REF_INT cell_node, cell, nodes[REF_CELL_MAX_SIZE_PER];
REF_DBL volume;
REF_BOOL have_tet;
REF_LONG ntet;
RSS(ref_cell_ncell(ref_grid_tet(ref_grid), ref_node, &ntet), "count");
have_tet = (0 < ntet);
if (have_tet) {
ref_cell = ref_grid_tet(ref_grid);
} else {
ref_cell = ref_grid_tri(ref_grid);
}
*total_error = 0.0;
each_ref_cell_valid_cell_with_nodes(ref_cell, cell, nodes) {
if (have_tet) {
RSS(ref_node_tet_vol(ref_node, nodes, &volume), "vol");
} else {
RSS(ref_node_tri_area(ref_node, nodes, &volume), "area");
}
for (cell_node = 0; cell_node < ref_cell_node_per(ref_cell); cell_node++) {
if (ref_node_owned(ref_node, nodes[cell_node])) {
(*total_error) += interpolation_error[nodes[cell_node]] * volume /
((REF_DBL)ref_cell_node_per(ref_cell));
}
}
}
RSS(ref_mpi_allsum(ref_grid_mpi(ref_grid), total_error, 1, REF_DBL_TYPE),
"dbl sum");

return REF_SUCCESS;
}

REF_STATUS ref_metric_gradation_at_complexity(REF_DBL *metric,
REF_GRID ref_grid,
REF_DBL gradation,
Expand Down
3 changes: 3 additions & 0 deletions src/ref_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ REF_STATUS ref_metric_smr(REF_DBL *metric0, REF_DBL *metric1, REF_DBL *metric,
REF_STATUS ref_metric_interpolation_error(REF_DBL *metric, REF_DBL *hess,
REF_GRID ref_grid,
REF_DBL *interpolation_error);
REF_STATUS ref_metric_integrate_error(REF_GRID ref_grid,
REF_DBL *interpolation_error,
REF_DBL *total_error);
REF_STATUS ref_metric_complexity(REF_DBL *metric, REF_GRID ref_grid,
REF_DBL *complexity);
REF_STATUS ref_metric_set_complexity(REF_DBL *metric, REF_GRID ref_grid,
Expand Down
4 changes: 4 additions & 0 deletions src/ref_metric_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,7 @@ int main(int argc, char *argv[]) {
if (error_pos != REF_EMPTY) {
REF_GRID ref_grid;
REF_DBL *field, *hess, *metric, *error;
REF_DBL total_error;
REF_INT ldim;

REIS(1, error_pos,
Expand Down Expand Up @@ -2010,6 +2011,9 @@ int main(int argc, char *argv[]) {

RSS(ref_metric_interpolation_error(metric, hess, ref_grid, error), "error")

RSS(ref_metric_integrate_error(ref_grid, error, &total_error), "int")
if (ref_mpi_once(ref_mpi)) printf("total error %e\n", total_error);

/*
each_ref_node_valid_node(ref_grid_node(ref_grid), node) {
REF_DBL diag[12];
Expand Down

0 comments on commit 525812b

Please sign in to comment.