Skip to content

Commit

Permalink
extracts xyz to ref_nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Park authored and Mike Park committed Sep 28, 2022
1 parent aa77402 commit 1c2d815
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/ref_oct.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ REF_FCN REF_STATUS ref_oct_gradation(REF_OCT ref_oct) {
}

REF_FCN static REF_STATUS ref_oct_unique_nodes_node(REF_OCT ref_oct,
REF_INT node,
REF_DBL *bbox) {
REF_INT node, REF_DBL *bbox,
REF_NODE ref_node) {
if (ref_oct_leaf_node(ref_oct, node)) {
REF_INT corner;
for (corner = 0; corner < 8; corner++) {
Expand All @@ -246,8 +246,14 @@ REF_FCN static REF_STATUS ref_oct_unique_nodes_node(REF_OCT ref_oct,
RSS(ref_oct_bbox_corner(bbox, corner, xyz), "corner xyz");
insert_node = REF_EMPTY;
if (REF_EMPTY == ref_oct_c2n(ref_oct, corner, node)) {
REF_INT new_node;
insert_node = ref_oct_nnode(ref_oct);
ref_oct_nnode(ref_oct)++;
RSS(ref_node_add(ref_node, insert_node, &new_node), "add node");
REIS(insert_node, new_node, "expects to match");
ref_node_xyz(ref_node, 0, new_node) = xyz[0];
ref_node_xyz(ref_node, 1, new_node) = xyz[1];
ref_node_xyz(ref_node, 2, new_node) = xyz[2];
} else {
insert_node = ref_oct_c2n(ref_oct, corner, node);
}
Expand All @@ -258,17 +264,22 @@ REF_FCN static REF_STATUS ref_oct_unique_nodes_node(REF_OCT ref_oct,
for (child_index = 0; child_index < 8; child_index++) {
REF_DBL box[6];
RSS(ref_oct_child_bbox(bbox, child_index, box), "bbox");
RSS(ref_oct_unique_nodes_node(
ref_oct, ref_oct_child(ref_oct, child_index, node), box),
RSS(ref_oct_unique_nodes_node(ref_oct,
ref_oct_child(ref_oct, child_index, node),
box, ref_node),
"recurse");
}
}
return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_unique_nodes(REF_OCT ref_oct) {
REIS(0, ref_oct_nnode(ref_oct), "expected zero nodes");
RSS(ref_oct_unique_nodes_node(ref_oct, 0, ref_oct->bbox), "descend");
REF_FCN REF_STATUS ref_oct_unique_nodes(REF_OCT ref_oct, REF_NODE ref_node) {
REIS(0, ref_oct_nnode(ref_oct), "expected zero oct nodes");
REIS(0, ref_node_n(ref_node), "expected zero grid nodes");
RSS(ref_oct_unique_nodes_node(ref_oct, 0, ref_oct->bbox, ref_node),
"descend");
RSS(ref_node_initialize_n_global(ref_node, ref_oct_nnode(ref_oct)),
"init glob");
return REF_SUCCESS;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ref_oct.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef struct REF_OCT_STRUCT REF_OCT_STRUCT;
typedef REF_OCT_STRUCT *REF_OCT;
END_C_DECLORATION

#include "ref_node.h"

BEGIN_C_DECLORATION
struct REF_OCT_STRUCT {
REF_DBL bbox[6];
Expand Down Expand Up @@ -60,7 +62,7 @@ REF_FCN REF_STATUS ref_oct_split_at(REF_OCT ref_oct, REF_DBL *xyz, REF_DBL h);
REF_FCN REF_STATUS ref_oct_split_touching(REF_OCT ref_oct, REF_DBL *bbox,
REF_DBL h);
REF_FCN REF_STATUS ref_oct_gradation(REF_OCT ref_oct);
REF_FCN REF_STATUS ref_oct_unique_nodes(REF_OCT ref_oct);
REF_FCN REF_STATUS ref_oct_unique_nodes(REF_OCT ref_oct, REF_NODE ref_node);
REF_FCN REF_STATUS ref_oct_set_node_at(REF_OCT ref_oct, REF_INT insert_node,
REF_DBL *xyz);

Expand Down
14 changes: 12 additions & 2 deletions src/ref_oct_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,30 @@ int main(int argc, char *argv[]) {
}

{ /* root unique nodes */
REF_NODE ref_node;
REF_OCT ref_oct;
RSS(ref_node_create(&ref_node, ref_mpi), "make node");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_unique_nodes(ref_oct), "make nodes");
RSS(ref_oct_unique_nodes(ref_oct, ref_node), "make nodes");
REIS(8, ref_oct_nnode(ref_oct), "expects 8 node hex");
REIS(8, ref_node_n(ref_node), "ref_node n");
REIS(8, ref_node_n_global(ref_node), "ref_node global n");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_node_free(ref_node), "free node");
}

{ /* one split unique nodes */
REF_NODE ref_node;
REF_OCT ref_oct;
RSS(ref_node_create(&ref_node, ref_mpi), "make node");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_unique_nodes(ref_oct), "make nodes");
RSS(ref_oct_unique_nodes(ref_oct, ref_node), "make nodes");
REIS(27, ref_oct_nnode(ref_oct), "expects 8 node hex");
REIS(27, ref_node_n(ref_node), "ref_node n");
REIS(27, ref_node_n_global(ref_node), "ref_node global n");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_node_free(ref_node), "free node");
}

{ /* contains root */
Expand Down

0 comments on commit 1c2d815

Please sign in to comment.