Commit 3bd4504a authored by Margaux Boxho's avatar Margaux Boxho
Browse files

Final version of refinement strategy

parent 54b3fa70
Pipeline #5460 passed with stage
in 27 seconds
......@@ -1809,6 +1809,7 @@ void fluid_problem_local_adapt_mesh(FluidProblem *problem, double lcmax, double
printf("==> INITIALIZED THE TREE STRUCTURE \n");
problem->Tree = (Tree_cell*) malloc(mesh->n_elements*sizeof(Tree_cell));
problem->size_initial_mesh = mesh->n_elements;
problem->size_initial_node = mesh->n_nodes;
deep_tree_initialized(mesh, problem->Tree, mesh->n_elements);
// INITIALISE THE MAPPING
......@@ -1820,23 +1821,89 @@ void fluid_problem_local_adapt_mesh(FluidProblem *problem, double lcmax, double
int n_nodes_new = 0;
int n_elements_new = 0;
int n_boundaries_new = 0;
deep_tree_refinement(mesh, problem->Tree, problem->map, problem->size_initial_mesh, lcmin, &n_nodes_new, &n_elements_new, &n_boundaries_new);
int n_nodes_removed = 0;
int n_elements_removed = 0;
// Let's create the correspondence table for the removed node
int len_node = mesh->n_nodes - problem->size_initial_node;
int *tab_node = (int*) malloc(len_node*sizeof(int));
for (int ii=0; ii<len_node; ii++) {
tab_node[ii]=-1;
}
// Let's create the correpondence table for the removed element
int len_elt = mesh->n_elements - problem->size_initial_mesh;
int *tab_elt = (int*) malloc(len_elt*sizeof(int));
for (int ii=0; ii<len_elt; ii++) {
tab_elt[ii]=-1;
}
deep_tree_refinement(mesh, problem->Tree, problem->map, problem->size_initial_mesh, lcmin, &n_nodes_new, &n_elements_new, &n_boundaries_new, len_node, tab_node, problem->size_initial_node, len_elt, tab_elt, problem->size_initial_mesh, &n_nodes_removed, &n_elements_removed);
printf("There are %d nodes, %d elements in the initial mesh\n", problem->size_initial_node, problem->size_initial_mesh);
printf("There are %d nodes, %d elements in the old mesh\n", mesh->n_nodes, mesh->n_elements);
printf("There are %d nodes, %d elements and %d boundaries in the mesh\n", n_nodes_new, n_elements_new, n_boundaries_new);
int *elements_new = (int*) malloc(3*n_elements_new*sizeof(int));
double *x_new = (double*) malloc(3*n_nodes_new*sizeof(double));
int *boundaries_new = (int*) calloc(2*n_boundaries_new, sizeof(int));
int *boundary_tags_new = (int*) malloc(n_boundaries_new*sizeof(int));
Tree_cell **map_new = malloc(n_elements_new*sizeof(Tree_cell*));
for (int n=0; n<mesh->n_nodes; n++) {
for (int ii=0; ii<3; ii++) {
x_new[n*3+ii] = mesh->x[n*3+ii];
if (len_node==0 && len_elt==0) {
for (int n=0; n<mesh->n_nodes; n++) {
for (int ii=0; ii<3; ii++) {
x_new[n*3+ii] = mesh->x[n*3+ii];
}
}
}else{
for (int n=0; n<mesh->n_nodes; n++) {
int m = n;
if (n>=problem->size_initial_node && n<len_node+problem->size_initial_node) {
m = tab_node[n-problem->size_initial_node];
}else if(n>=len_node+problem->size_initial_node){
m = n-n_nodes_removed;
}
if (m>-1) {
for (int ii=0; ii<3; ii++) {
x_new[m*3+ii] = mesh->x[n*3+ii];
}
}
}
}
deep_tree_travel(mesh, problem->Tree, problem->map, map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new, n_boundaries_new, problem->size_initial_mesh, len_node, tab_node, problem->size_initial_node, len_elt, tab_elt, problem->size_initial_mesh, n_nodes_removed, n_elements_removed);
/*printf("Print in post_processing files \n");
printing_post_processing_files(mesh, elements_new, x_new, boundaries_new, n_elements_new, n_boundaries_new);
if (mesh->n_nodes>855) {
int tag1 = 855;
printf("(%f, %f)\n", x_new[tag1*3+0], x_new[tag1*3+1]);
}
if (mesh->n_nodes>916) {
int tag1 = 916;
printf("(%f, %f)\n", x_new[tag1*3+0], x_new[tag1*3+1]);
}
if (mesh->n_nodes>1158) {
int tag1 = 1158;
printf("(%f, %f)\n", x_new[tag1*3+0], x_new[tag1*3+1]);
}
if (mesh->n_nodes>1223) {
int tag1 = 1223;
printf("(%f, %f)\n", x_new[tag1*3+0], x_new[tag1*3+1]);
}
FILE *file2 = fopen("/Users/margauxboxho/migflow/testcases/my_local_drop/element_new.dat", "w");
if(file2 == NULL){
printf("Error at opening file \n");
exit(1);
}
deep_tree_travel(mesh, problem->Tree, problem->map, map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new, n_boundaries_new, problem->size_initial_mesh);
for (int iel=0; iel<n_elements_new; iel++) {
fprintf(file2, "%4d, %4d, %4d, ", elements_new[iel*3+0], elements_new[iel*3+1], elements_new[iel*3+2]);
}
fclose(file2);*/
free(problem->map);
problem->map = NULL;
problem->map = map_new;
......@@ -1863,8 +1930,8 @@ void fluid_problem_local_adapt_mesh(FluidProblem *problem, double lcmax, double
free(x_new);
free(boundaries_new);
free(boundary_tags_new);
//free(problem->map);
//free(problem->Tree);
free(tab_node);
free(tab_elt);
}
}
......
......@@ -66,7 +66,8 @@ struct FluidProblem {
Tree_cell *Tree;
Tree_cell **map;
int *map2Tree;
int size_initial_mesh;
int size_initial_mesh; // number of initial elements in the mesh
int size_initial_node; // number of initial nodes in the mesh
MeshBoundary *boundaries;
double *porosity;
double *oldporosity;
......
......@@ -726,6 +726,7 @@ void initialize_children(Tree_cell *current, int excess){
current->children[ii].children=NULL;
current->children[ii].num_children = 0;
current->children[ii].bool_ref = 0;
current->children[ii].bool_def = 0;
for (int jj=0; jj<3; jj++) {
current->children[ii].neighbours[jj]=-1;
current->children[ii].phys[jj]=-1;
......@@ -737,22 +738,31 @@ void initialize_children(Tree_cell *current, int excess){
void deep_tree_check_for_refinement(Mesh *mesh, Tree_cell *current, double h_target, double h_min){
double x[6] = {mesh->x[current->nodes[0]*3+0], mesh->x[current->nodes[0]*3+1], mesh->x[current->nodes[1]*3+0], mesh->x[current->nodes[1]*3+1], mesh->x[current->nodes[2]*3+0], mesh->x[current->nodes[2]*3+1]};
double alpha = 1.5;
double J = (x[2]-x[0])*(x[5]-x[1]) - (x[4]-x[0])*(x[3]-x[1]);
double vol = J/2.0;
double a = sqrt((x[0]-x[2])*(x[0]-x[2])+(x[1]-x[3])*(x[1]-x[3]));
double b = sqrt((x[2]-x[4])*(x[2]-x[4])+(x[3]-x[5])*(x[3]-x[5]));
double c = sqrt((x[4]-x[0])*(x[4]-x[0])+(x[5]-x[1])*(x[5]-x[1]));
double h_k = 0.5*a*b*c/vol;
if (h_k>h_target) { //h_k>h_target && h_k/1.0>h_min
if (h_k/1.4>h_target) {
current->bool_ref = 1;
current->bool_def = 0;
}else if(h_k*alpha<h_target){
current->bool_ref = 0;
current->bool_def = 0; //1;
}else{
current->bool_def = 0;
current->bool_ref = 0;
}
}
void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size, int h_min, int *n_nodes_new, int *n_elements_new, int *n_boundaries_new){
void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size, int h_min, int *n_nodes_new, int *n_elements_new, int *n_boundaries_new, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt, int *n_nodes_removed, int *n_elements_removed){
int index = mesh->n_nodes;
int elt = mesh->n_elements;
int index_remove = 0;
int elt_remove = 0;
int ibd = 0;
// NEED TO CARRY ABOUT THE NEIGHBOURS
for (int kk=0; kk<mesh->n_interfaces; kk++) {
......@@ -770,26 +780,35 @@ void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size
}
else {
map[el0]->neighbours[cl0%3] = el1;
map[el0]->bdies[cl0%3] = -1;
map[el1]->neighbours[cl1%3] = el0;
map[el1]->bdies[cl1%3] = -1;
}
}
// ASK FOR REFINEMENT TO THE ESTIMATOR
for (int iel=0; iel<mesh->n_elements; iel++) {
deep_tree_check_for_refinement(mesh, map[iel], mesh->min_h_target[iel], h_min);
Tree_cell *current = map[iel];
if (current->children!=NULL && current->num_children==0) {
free(current->children);
current->children=NULL;
}
//printf("TAG %4d : (%4d, %4d, %4d)\n", current->tag, current->nodes[0], current->nodes[1], current->nodes[2]);
}
// CUT INTO 4 ELEMENTS
for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
int bool_boundary = 0;
if (current->parent!=NULL) {
if (current->parent->num_children==4 && current->bool_ref==1) {
if (current->parent->num_children==4 && current->bool_ref==1 && bool_boundary==0) {
//printf("====>CUT INTO 4\n");
current->children = (Tree_cell *) malloc(4*sizeof(Tree_cell));
current->num_children=4;
initialize_children(current, 0);
deep_tree_cut_into_4(current, map, &index, &elt, &ibd);
}
}else if(current->bool_ref==1){
}else if(current->bool_ref==1 && bool_boundary==0){
//printf("====>CUT INTO 4\n");
current->children = (Tree_cell *) malloc(4*sizeof(Tree_cell));
current->num_children=4;
......@@ -809,16 +828,16 @@ void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size
int bool_one_node = (current->sub_nodes[0]!=-1 && current->sub_nodes[1]==-1 && current->sub_nodes[2]==-1)||(current->sub_nodes[0]==-1 && current->sub_nodes[1]!=-1 && current->sub_nodes[2]==-1)||(current->sub_nodes[0]==-1 && current->sub_nodes[1]==-1 && current->sub_nodes[2]!=-1);
int bool_two_nodes = (current->sub_nodes[0]!=-1 && current->sub_nodes[1]!=-1 && current->sub_nodes[2]==-1)||(current->sub_nodes[0]==-1 && current->sub_nodes[1]!=-1 && current->sub_nodes[2]!=-1)||(current->sub_nodes[0]!=-1 && current->sub_nodes[1]==-1 && current->sub_nodes[2]!=-1);
if (current->parent->num_children==2) {
if (current->parent->num_children==2 ) {
// TRANSFORM A 2-CUT INTO A 4-CUT
if (current->bool_ref || bool_one_node || bool_two_nodes) {
printf("====>Transform 2 into 4\n");
//printf("====>Transform 2 into 4\n");
deep_tree_transform2_into_4(current, map, &index, &elt, &ibd);
}
}else if (current->parent->num_children==3){
// TRANSFORM A 3-CUT INTO A 4-CUT
if (current->bool_ref || bool_one_node || bool_two_nodes) {
printf("====>Transform 3 into 4\n");
//printf("====>Transform 3 into 4\n");
deep_tree_transform3_into_4(current, map, &index, &elt, &ibd);
}
}
......@@ -826,6 +845,85 @@ void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size
}
}
printf("=============================> STARTING COARSENING THE MESH <=============================\n");
FILE *file1 = fopen("/Users/margauxboxho/migflow/testcases/my_local_drop/Mesh_Remove.dat", "w");
if(file1 == NULL){
printf("Error at opening file \n");
exit(1);
}
for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
if (current->bool_def==1 && current->tag!=-1) {
if (current->parent!=NULL) {
for (int ii=0; ii<3; ii++) {
int tag_node_remove = current->parent->nodes[ii];
fprintf(file1, "%f, %f, ", mesh->x[tag_node_remove*3+0], mesh->x[tag_node_remove*3+1]);
}
fprintf(file1, "\n");
}
deep_tree_remove_elt(current, map, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt);
}
}
fclose(file1);
FILE *file2 = fopen("/Users/margauxboxho/migflow/testcases/my_local_drop/tab_node_before.dat", "w");
if(file2 == NULL){
printf("Error at opening file \n");
exit(1);
}
for (int ii=0; ii<len_node; ii++) {
fprintf(file2, "%4d, ", tab_node[ii]);
}
fclose(file2);
printf("=============================> STARTING SMOOTHING THE REFINEMENT (0)<=============================\n");
for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
if (current->parent!=NULL && current->tag!=-1 && current->children==NULL) {
Tree_cell *parent = current->parent;
int count_sub_nodes = 0;
for (int ii=0; ii<3; ii++) {
if (parent->sub_nodes[ii]!=-1) {
count_sub_nodes++;
}
}
if (count_sub_nodes != parent->num_children-1 && len_node!=0) {
if (count_sub_nodes==2 && parent->num_children==4) {
//printing_current(parent);
//printf("Transform 4->3\n");
deep_tree_transform4_into_3(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else if (count_sub_nodes==1 && parent->num_children==4){
//printing_current(parent);
//printf("Transform 4->2\n");
deep_tree_transform4_into_2(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else if (count_sub_nodes==0 && parent->num_children==4){
//printing_current(parent);
//printf("Transform 4->1\n");
deep_tree_transform4_into_1(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else if (count_sub_nodes==1 && parent->num_children==3){
//printf("Transform 3->2\n");
deep_tree_transform3_into_2(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else if (count_sub_nodes==0 && parent->num_children==3){
//printf("Transform 3->1\n");
deep_tree_transform3_into_1(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else if (count_sub_nodes==0 && parent->num_children==2){
//printf("Transform 2->1\n");
deep_tree_transform2_into_1(parent, len_elt, tab_elt, size_init_elt);
//printing_current(parent);
}else{
printf("ERROR IN SMOOTHING PROCEDURE (0)\n");
printing_current(parent);
exit(1);
}
}
}
}
printf("=============================> STARTING SMOOTHING THE REFINEMENT (1)<=============================\n");
// COMPLETE THE REFINEMENT BY CUTTING INTO 2 OR 3 DEENDING ON THE NUMBER OF SUB_NODES CONTAINED ON THE ELEMENT EDGES
for (int iel=0; iel<mesh->n_elements; iel++) {
......@@ -895,9 +993,6 @@ void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size
current->parent->children[ii].tag = save_tag[ii];
}
current->parent->children[3].tag = elt; elt+=1;
for (int jj=0; jj<4; jj++) {
printing_current(&current->parent->children[jj]);
}
}
}
}
......@@ -937,74 +1032,98 @@ void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int size
}
}
}
*n_nodes_new = index;
*n_elements_new = elt;
*n_boundaries_new = ibd;
/*FILE *file3 = fopen("/Users/margauxboxho/migflow/testcases/my_local_drop/tab_node_after.dat", "w");
if(file3 == NULL){
printf("Error at opening file \n");
exit(1);
}
for (int ii=0; ii<len_node; ii++) {
fprintf(file3, "%4d, ", tab_node[ii]);
}
fclose(file3);*/
deep_tree_correspondence(tab_node, len_node, size_init_node, tab_elt, len_elt, size_init_elt, &index_remove, &elt_remove);
/*FILE *file4 = fopen("/Users/margauxboxho/migflow/testcases/my_local_drop/tab_node_after_after.dat", "w");
if(file4 == NULL){
printf("Error at opening file \n");
exit(1);
}
for (int ii=0; ii<len_node; ii++) {
fprintf(file4, "%4d, ", tab_node[ii]);
}
fclose(file4);*/
*n_nodes_new = index-index_remove;
*n_elements_new = elt-elt_remove;
*n_boundaries_new = ibd; // we do not touch to the boundaries
printf("Number of nodes to be removed %4d\n", index_remove);
printf("Number of elements to be removed %4d\n", elt_remove);
*n_nodes_removed = index_remove;
*n_elements_removed = elt_remove;
}
void deep_tree_travel(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, Tree_cell **map_new, double *x_new, int *elements_new, int *boundaries_new, int *boundary_tags_new, int n_nodes_new, int n_elements_new, int n_boundaries_new, int size){
void deep_tree_travel(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, Tree_cell **map_new, double *x_new, int *elements_new, int *boundaries_new, int *boundary_tags_new, int n_nodes_new, int n_elements_new, int n_boundaries_new, int size, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt, int n_nodes_removed, int n_elements_removed){
printf("====> CREATE THE DATA STRUCTURE <====\n");
int ibd = 0;
for (int iel=0; iel<size; iel++) {
Tree_cell *current = &Tree[iel];
deep_tree_create_data_structure(mesh, current, map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new);
deep_tree_create_data_structure(mesh, current, map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed);
}
for (int iel=0; iel<mesh->n_elements; iel++) {
map[iel]->bool_boundary=1;
}
printf("====> CREATE THE BOUNDARY STRUCTURE <====\n");
int count = 0;
for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
if (current->tag==-1) {
// THE CURRENT ELEMENT IS A PARENT OF 2, 3 OR 4 CHILDREN
if (current->num_children==4) {
for (int ii=0; ii<4; ii++) {
for (int jj=0; jj<3; jj++) {
int ibd = current->children[ii].bdies[jj];
if (ibd>-1) {
count++;
boundaries_new[2*ibd+0] = current->children[ii].nodes[jj];
boundaries_new[2*ibd+1] = current->children[ii].nodes[(jj+1)%3];
boundary_tags_new[ibd] = current->children[ii].phys[jj];
}
}
}
}else{
for (int ii=0; ii<3; ii++) {
int ibd = current->bdies[ii];
if (ibd>-1) {
count++;
boundaries_new[2*ibd+0] = current->nodes[ii];
boundaries_new[2*ibd+1] = current->nodes[(ii+1)%3];
boundary_tags_new[ibd] = current->phys[ii];
}
}
}
}else{
// THE CURRENT ELEMENT IS EITHER AND OLD ELEMENT OR A TRANSFORM ELEMENT
for (int ii=0; ii<3; ii++) {
int ibd = current->bdies[ii];
if (ibd>-1) {
count++;
boundaries_new[2*ibd+0] = current->nodes[ii];
boundaries_new[2*ibd+1] = current->nodes[(ii+1)%3];
boundary_tags_new[ibd] = current->phys[ii];
}
for (int iel=0; iel<n_elements_new; iel++) {
Tree_cell *current = map_new[iel];
for (int ii=0; ii<3; ii++) {
int ibd = current->bdies[ii];
if (ibd>-1) {
count++;
boundaries_new[2*ibd+0] = current->nodes[ii];
boundaries_new[2*ibd+1] = current->nodes[(ii+1)%3];
boundary_tags_new[ibd] = current->phys[ii];
}
}
}
printf("count = %d\n", count);
printf("n_boundaries_new = %d \n", n_boundaries_new);
printf("Print in post_processing files \n");
printing_post_processing_files(mesh, elements_new, x_new, boundaries_new, n_elements_new, n_boundaries_new);
if (n_nodes_removed!=0 && n_elements_removed!=0) {
for (int iel=0; iel<size; iel++) {
Tree_cell *current = &Tree[iel];
deep_tree_travel_to_get_new_correspondence(current, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed);
}
}
}
void deep_tree_create_data_structure(Mesh *mesh, Tree_cell *current, Tree_cell **map_new, double *x_new, int *elements_new, int *boundaries_new, int *boundary_tags_new, int n_nodes_new, int n_elements_new){
if (current->children==NULL) {
void deep_tree_create_data_structure(Mesh *mesh, Tree_cell *current, Tree_cell **map_new, double *x_new, int *elements_new, int *boundaries_new, int *boundary_tags_new, int n_nodes_new, int n_elements_new, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt, int n_nodes_removed, int n_elements_removed){
if (current->children==NULL || current->num_children==0) { // the second statement will be used when elements are removed
int save_old_nodes[3];
if (current->parent!=NULL) {
if (current->parent->num_children==4){
for (int ii=0; ii<3; ii++) {
save_old_nodes[ii] = current->parent->nodes[ii];
}
}
}
// Get the new tag for the nodes, sub_nodes, neighbours and the current element
if (len_node!=0 && len_elt!=0 && n_nodes_removed!=0 && n_elements_removed!=0) {
deep_tree_map_for_remove(current, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed, 1);
}
if (current->tag>n_elements_new) {
printf("ERROR IN THE NODE TAG\n");
printing_current(current);
exit(1);
}
......@@ -1014,48 +1133,453 @@ void deep_tree_create_data_structure(Mesh *mesh, Tree_cell *current, Tree_cell *
printing_current(current->parent);
exit(1);
}
current->bool_boundary = 1;
map_new[current->tag] = current;
elements_new[current->tag*3+0] = current->nodes[0];
elements_new[current->tag*3+1] = current->nodes[1];
elements_new[current->tag*3+2] = current->nodes[2];
if (current->parent!=NULL) {
if (current->parent->num_children==4) {
if (current->parent->nodes[0]>mesh->n_nodes || current->parent->nodes[1]>mesh->n_nodes || current->parent->nodes[2]>mesh->n_nodes) {
printf("(%d, %d, %d) \n", current->parent->nodes[0], current->parent->nodes[1], current->parent->nodes[2]);
int count_sub_nodes = 0;
for (int ii=0; ii<3; ii++) {
if (current->parent->sub_nodes[ii]!=-1) {
count_sub_nodes ++;
}
}
if (current->parent->num_children==4 && count_sub_nodes==3) {
if (save_old_nodes[0]>mesh->n_nodes || save_old_nodes[1]>mesh->n_nodes || save_old_nodes[2]>mesh->n_nodes) {
printf("(%d, %d, %d) \n", save_old_nodes[0], save_old_nodes[1], save_old_nodes[2]);
printf("ERROR IN THE PARENT NODES TAG\n");
printing_current(current->parent);
exit(1);
}
double X1 = mesh->x[current->parent->nodes[0]*3+0]; double Y1 = mesh->x[current->parent->nodes[0]*3+1];
double X2 = mesh->x[current->parent->nodes[1]*3+0]; double Y2 = mesh->x[current->parent->nodes[1]*3+1];
double X3 = mesh->x[current->parent->nodes[2]*3+0]; double Y3 = mesh->x[current->parent->nodes[2]*3+1];
// Extract node using their old tag
double X1 = mesh->x[save_old_nodes[0]*3+0]; double Y1 = mesh->x[save_old_nodes[0]*3+1];
double X2 = mesh->x[save_old_nodes[1]*3+0]; double Y2 = mesh->x[save_old_nodes[1]*3+1];
double X3 = mesh->x[save_old_nodes[2]*3+0]; double Y3 = mesh->x[save_old_nodes[2]*3+1];
// Extract sub_nodes tag values in the old mesh numerotation
int ind0 = current->parent->sub_nodes[0];
int ind1 = current->parent->sub_nodes[1];
int ind2 = current->parent->sub_nodes[2];
// Finding the tag of the sub_nodes using the correspondence table
int ind[3] = {ind0, ind1, ind2};
for (int ii=0; ii<3; ii++) {
if (ind[ii]!=-1 && ind[ii]>=size_init_node && ind[ii]<len_node+size_init_node) {
ind[ii] = tab_node[ind[ii]-size_init_node];
}else if(ind[ii]>=len_node+size_init_node){
ind[ii] = ind[ii]-n_nodes_removed;
}
}
ind0 = ind[0]; ind1 = ind[1]; ind2 = ind[2];
if (ind0>n_nodes_new || ind1>n_nodes_new || ind2>n_nodes_new) {
printf("ERROR IN THE SUB_NODES TAG \n");
printing_current(current->parent);
exit(1);
}
x_new[ind0*3+0] = 0.5*(X1+X2); x_new[ind0*3+1] = 0.5*(Y1+Y2); x_new[ind0*3+2] = 0.;
x_new[ind1*3+0] = 0.5*(X2+X3); x_new[ind1*3+1] = 0.5*(Y2+Y3); x_new[ind1*3+2] = 0.;
x_new[ind2*3+0] = 0.5*(X3+X1); x_new[ind2*3+1] = 0.5*(Y3+Y1); x_new[ind2*3+2] = 0.;
}
}
}else{
for (int ii=0; ii<current->num_children; ii++) {
deep_tree_create_data_structure(mesh, &current->children[ii], map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed);
}
}
}
void deep_tree_travel_to_get_new_correspondence(Tree_cell *current, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt, int n_nodes_removed, int n_elements_removed){
if (current->children==NULL || current->num_children==0) {
// DO NOTHING ALREADY PERFORMED AT THE PREVIOUS STEP
}else{
if (len_node!=0 && len_elt!=0) {
deep_tree_map_for_remove(current, len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed, 1);
}
for (int ii=0; ii<current->num_children; ii++) {
deep_tree_create_data_structure(mesh, &current->children[ii], map_new, x_new, elements_new, boundaries_new, boundary_tags_new, n_nodes_new, n_elements_new);
deep_tree_travel_to_get_new_correspondence(&current->children[ii], len_node, tab_node, size_init_node, len_elt, tab_elt, size_init_elt, n_nodes_removed, n_elements_removed);
}
}
}
void deep_tree_map_for_remove(Tree_cell *current, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt, int n_nodes_removed, int n_elements_removed, int bool_tag){
// Change the tag of the element
if (bool_tag==1) {
if (current->tag>=size_init_elt && current->tag<len_elt+size_init_elt) {
current->tag = tab_elt[current->tag-size_init_elt];
}else if(current->tag>=len_elt+size_init_elt){
current->tag = current->tag-n_elements_removed;
}
}
// Change the tag of the nodes
for (int ii=0; ii<3; ii++) {
if (current->nodes[ii]>=size_init_node && current->nodes[ii]<len_node+size_init_node) {
current->nodes[ii] = tab_node[current->nodes[ii]-size_init_node];
}else if(current->nodes[ii]>=len_node+size_init_node){
current->nodes[ii] = current->nodes[ii]-n_nodes_removed;
}
}
// Change the tag of the sub_nodes
for (int ii=0; ii<3; ii++) {
if (current->sub_nodes[ii]!=-1 && current->sub_nodes[ii]>=size_init_node && current->sub_nodes[ii]<len_node+size_init_node) {