Commit 95525b1f authored by Margaux Boxho's avatar Margaux Boxho
Browse files

Local adaptation of the mesh (version2)

parent 68fc0517
Pipeline #5346 passed with stage
in 26 seconds
......@@ -1104,12 +1104,14 @@ void get_the_mapping(Tree_cell *Tree, Tree_cell **map, int *map2Tree, int size){
for (int ii=0; ii<Tree[iel].num_children; ii++) {
elt = Tree[iel].children[ii].tag;
map[elt] = &Tree[iel].children[ii];
map2Tree[elt] = iel;
//map2Tree[elt] = iel;
map2Tree[elt] = Tree[iel].children[ii].tag;
}
}else{
elt = Tree[iel].tag;
map[elt] = &Tree[iel];
map2Tree[elt] = iel;
//map2Tree[elt] = iel;
map2Tree[elt] = Tree[iel].tag;
}
}
}
......@@ -1135,78 +1137,115 @@ void deep_tree_walk_tree(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int *map2
printf("Number of elements in the initial mesh : %d \n", elt);
printf("Number of nodes in the initial mesh : %d \n", index);
int n_boundaries = 0;
/*FILE *file_ibd = fopen("boundaries.dat", "w");
if(file_ibd == NULL){
printf("Error at opening file boundaries.dat!\n");
exit(1);
}*/
for (int kk=0; kk<mesh->n_interfaces; kk++) {
int *interface = &mesh->interfaces[kk*4];
int el0 = interface[0];
int cl0 = interface[1];
int el1 = interface[2];
int cl1 = interface[3];
if (el1==-1) {
map[el0]->phys[cl0%3] = cl1;
printf("tag : %i\n", cl1);
map[el0]->neighbours[cl0%3] = -1;
map[el0]->nghb[cl0%3] = NULL;
n_boundaries++;
}
else {
map[el0]->neighbours[cl0%3] = el1;
map[el0]->nghb[cl0%3] = map[el1];
map[el1]->neighbours[cl1%3] = el0;
map[el1]->nghb[cl1%3] = map[el0];
}
int *interface = &mesh->interfaces[kk*4];
int el0 = interface[0];
int cl0 = interface[1];
int el1 = interface[2];
int cl1 = interface[3];
int match_index0 = map2Tree[el0];
int match_index1 = map2Tree[el1];
if (el1==-1) {
map[match_index0]->phys[cl0%3] = cl1;
//printf("map[el0].tag == match_index = %4d\n", map[el0]->tag==match_index0);
//printf("el0 : %d ==> tag : %i ==>", el0, cl1);
//printf("CURRENT : %d \n", map[match_index0]->tag);
map[match_index0]->neighbours[cl0%3] = -1;
map[match_index0]->nghb[cl0%3] = NULL;
n_boundaries++;
//const int *buf = &mesh->elements[el0*N_N];
//int nod0 = buf[elbnd[cl0][0]];
//int nod1 = buf[elbnd[cl0][1]];
//fprintf(file_ibd, "%f, %f, %f, %f\n", mesh->x[nod0*3+0], mesh->x[nod0*3+1], mesh->x[nod1*3+0], mesh->x[nod1*3+1]);
}
else {
map[match_index0]->neighbours[cl0%3] = el1;
map[match_index0]->nghb[cl0%3] = map[match_index1];
map[match_index1]->neighbours[cl1%3] = el0;
map[match_index1]->nghb[cl1%3] = map[match_index0];
}
}
//fclose(file_ibd);
printf("Number of boundaries in the initial mesh : %d \n", n_boundaries);
int ref_count = 0;
for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
double X1, X2, X3, Y1, Y2, Y3;
X1 = mesh->x[current->nodes[0]*3+0];
Y1 = mesh->x[current->nodes[0]*3+1];
X2 = mesh->x[current->nodes[1]*3+0];
Y2 = mesh->x[current->nodes[1]*3+1];
X3 = mesh->x[current->nodes[2]*3+0];
Y3 = mesh->x[current->nodes[2]*3+1];
current->XY[0] = X1; current->XY[1] = Y1;
current->XY[2] = X2; current->XY[3] = Y2;
current->XY[4] = X3; current->XY[5] = Y3;
double x[6] = {X1, Y1, X2, Y2, X3, Y3};
int iel = current->tag;
current->bool_ref = need_refinement(x, mesh->min_h_target[iel], h_min);
}
for (int iel=0; iel<size; iel++) {
deep_tree_refinement(mesh, Tree, &Tree[iel], h_min, &index, &elt);
}
for (int iel=0; iel<size; iel++) {
deep_tree_complete_the_refinement(mesh, Tree, &Tree[iel], &index, &elt);
Tree_cell *current = map[iel];
double X1, X2, X3, Y1, Y2, Y3;
X1 = mesh->x[current->nodes[0]*3+0];
Y1 = mesh->x[current->nodes[0]*3+1];
X2 = mesh->x[current->nodes[1]*3+0];
Y2 = mesh->x[current->nodes[1]*3+1];
X3 = mesh->x[current->nodes[2]*3+0];
Y3 = mesh->x[current->nodes[2]*3+1];
current->XY[0] = X1; current->XY[1] = Y1;
current->XY[2] = X2; current->XY[3] = Y2;
current->XY[4] = X3; current->XY[5] = Y3;
double x[6] = {X1, Y1, X2, Y2, X3, Y3};
int iel = current->tag;
current->bool_ref = need_refinement(x, mesh->min_h_target[iel], h_min);
/*if (current->neighbours[0]==-1 || current->neighbours[1]==-1 || current->neighbours[2]==-1) {
printf("iel %d ==> phys : (%d, %d, %d) and nghb : (%d, %d, %d) \n", current->tag, current->phys[0], current->phys[1], current->phys[2], current->neighbours[0], current->neighbours[1], current->neighbours[2]);
printf("nodes : (%4d, %4d, %4d) \n", current->nodes[0], current->nodes[1], current->nodes[2]);
}
if (map2Tree[iel]==2581) {
print_current(current, 0);
}*/
ref_count+=1*(current->bool_ref==1);
}
int num = 1;
int n_max = 20;
int n = 0;
while (num!=0 && n<n_max) {
num = 0;
if (ref_count!=0) {
for (int iel=0; iel<size; iel++) {
deep_tree_remove_illegale_refinement(mesh, Tree, &Tree[iel], &index, &elt, &ibd, &num);
deep_tree_refinement(mesh, Tree, &Tree[iel], h_min, &index, &elt);
}
printf("num=%d\n", num);
n++;
// IF NUM IS EQUAL TO ZERO IT MEANS THAT NO NODE WAS ADDED IN THE PREVIOUS LOOP
// OTHERWISE ONE NODE WAS ADDED AND WE NEED TO PERFORM GREEN REFINEMENT
if (num!=0) {
for (int iel=0; iel<size; iel++) {
deep_tree_complete_the_refinement(mesh, Tree, &Tree[iel], &index, &elt);
}
int num = 1;
int n_max = 20;
int n = 0;
while (num!=0 && n<n_max) {
num = 0;
for (int iel=0; iel<size; iel++) {
deep_tree_complete_the_refinement(mesh, Tree, &Tree[iel], &index, &elt);
deep_tree_remove_illegale_refinement(mesh, Tree, &Tree[iel], &index, &elt, &ibd, &num);
}
printf("num=%d\n", num);
n++;
// IF NUM IS EQUAL TO ZERO IT MEANS THAT NO NODE WAS ADDED IN THE PREVIOUS LOOP
// OTHERWISE ONE NODE WAS ADDED AND WE NEED TO PERFORM GREEN REFINEMENT
if (num!=0) {
for (int iel=0; iel<size; iel++) {
deep_tree_complete_the_refinement(mesh, Tree, &Tree[iel], &index, &elt);
}
}
}
// PERFORM THE GREEN REFINEMENT
printf("===> GREEN REFINEMENT\n");
for (int iel=0; iel<size; iel++) {
deep_tree_green_refinement(mesh, Tree, &Tree[iel], &index, &elt);
}
}
// PERFORM THE GREEN REFINEMENT
printf("===> GREEN REFINEMENT\n");
// COUNT THE NUMBER OF BOUNDARIES
printf("===> COUNT THE NUMBER OF BOUNDARIES \n");
ibd = 0;
for (int iel=0; iel<size; iel++) {
deep_tree_green_refinement(mesh, Tree, &Tree[iel], &index, &elt);
deep_tree_count_boundaries(&Tree[iel], &ibd);
}
// CREATE
......@@ -1217,6 +1256,28 @@ void deep_tree_walk_tree(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int *map2
printf("Number of elements in the new mesh : %d \n", *n_elements_new);
printf("Number of nodes in the new mesh : %d \n", *n_nodes_new);
printf("Number of boundaries in the new mesh : %d \n", *n_boundaries_new);
/*for (int iel=0; iel<mesh->n_elements; iel++) {
Tree_cell *current = map[iel];
if (current->neighbours[0]==-1 || current->neighbours[1]==-1 || current->neighbours[2]==-1) {
printf("iel %4d ==> phys : (%4d, %4d, %4d) and nghb : (%4d, %4d, %4d) \n", current->tag, current->phys[0], current->phys[1], current->phys[2], current->neighbours[0], current->neighbours[1], current->neighbours[2]);
printf("nodes : (%4d, %4d, %4d) \n", current->nodes[0], current->nodes[1], current->nodes[2]);
}
}*/
}
void deep_tree_count_boundaries(Tree_cell *current, int *ibd){
if (current->children==NULL) {
for (int ii=0; ii<3; ii++) {
if (current->neighbours[ii]==-1) {
*ibd+=1;
}
}
}else{
for (int ii=0; ii<current->num_children; ii++) {
deep_tree_count_boundaries(&current->children[ii], ibd);
}
}
}
void deep_tree_create_the_data_structure(Mesh *mesh, Tree_cell *Tree, double *x_new, int n_nodes_new, int *elements_new, int n_elements_new, int *boundaries_new, int n_boundaries_new, int *boundary_tags_new, Tree_cell **map_new, int *map2Tree_new, int size){
......@@ -1243,7 +1304,7 @@ void deep_tree_create_the_data_structure(Mesh *mesh, Tree_cell *Tree, double *x_
for (int iel=0; iel<size; iel++) {
deep_tree_get_map(&Tree[iel], map_new, map2Tree_new, &elt, iel);
}
//printing_post_processing_files(mesh, elements_new, x_new, boundaries_new, n_elements_new, ibd);
printing_post_processing_files(mesh, elements_new, x_new, boundaries_new, n_elements_new, ibd);
}
void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, int *elements_new, int *boundaries_new, int *boundary_tags_new, int *ibd){
......@@ -1257,6 +1318,7 @@ void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, in
x_new[(current->nodes[ii])*3+2] = 0.;
elements_new[current->tag*3+ii] = current->nodes[ii];
if (current->neighbours[ii]==-1) {
//printf("tag : %d => NODES (%d, %d)\n", current->tag, current->nodes[ii], current->nodes[(ii+1)%3]);
boundaries_new[*ibd*2+0] = current->nodes[ii];
boundaries_new[*ibd*2+1] = current->nodes[(ii+1)%3];
boundary_tags_new[*ibd] = current->phys[ii];
......@@ -1268,6 +1330,7 @@ void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, in
for (int ii=0; ii<3; ii++) {
elements_new[current->tag*3+ii] = current->nodes[ii];
if (current->neighbours[ii]==-1) {
//printf("tag : %d => NODES (%d, %d)\n", current->tag, current->nodes[ii], current->nodes[(ii+1)%3]);
boundaries_new[*ibd*2+0] = current->nodes[ii];
boundaries_new[*ibd*2+1] = current->nodes[(ii+1)%3];
boundary_tags_new[*ibd] = current->phys[ii];
......@@ -1279,6 +1342,7 @@ void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, in
for (int ii=0; ii<3; ii++) {
elements_new[current->tag*3+ii] = current->nodes[ii];
if (current->neighbours[ii]==-1) {
//printf("tag : %d => NODES (%d, %d)\n", current->tag, current->nodes[ii], current->nodes[(ii+1)%3]);
boundaries_new[*ibd*2+0] = current->nodes[ii];
boundaries_new[*ibd*2+1] = current->nodes[(ii+1)%3];
boundary_tags_new[*ibd] = current->phys[ii];
......@@ -1296,7 +1360,8 @@ void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, in
void deep_tree_get_map(Tree_cell *current, Tree_cell **map_new, int *map2Tree_new, int *elt, int root){
if (current->children==NULL) {
map_new[*elt] = current;
map2Tree_new[*elt] = root;
//map2Tree_new[*elt] = current->tag;
map2Tree_new[current->tag] = *elt;
*elt+=1;
}else{
for (int ii=0; ii<current->num_children; ii++) {
......@@ -1493,11 +1558,11 @@ void deep_tree_remove_illegale_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell
int bool_2_nodes3 = (current->sub_nodes[0]==-1 && current->sub_nodes[1]!=-1 && current->sub_nodes[2]!=-1);
int bool_2_nodes = (bool_2_nodes1 || bool_2_nodes2 || bool_2_nodes3);
for (int ii=0; ii<3; ii++) {
/*for (int ii=0; ii<3; ii++) {
if (current->neighbours[ii]==-1) {
*ibd+=1;
}
}
}*/
if (bool_2_nodes) {
printf("%d : (%d, %d, %d)\n", current->tag, current->sub_nodes[0], current->sub_nodes[1], current->sub_nodes[2]);
// CREATE A REGULAR REFINEMENT
......
......@@ -156,6 +156,7 @@ void deep_tree_create_x_elt_bd(Mesh *mesh, Tree_cell *current, double *x_new, in
//void deep_tree_init_nghb_step2(Mesh *mesh, Tree_cell *Tree, Tree_cell **map, int *map2Tree, Tree_cell *current);
//void deep_tree_transfert_nghb(Tree_cell *current, Tree_cell *tree_elt, int buffer, int bool_nghb0, int bool_nghb1);
void deep_tree_transfer(Tree_cell *current, int iel);
void deep_tree_count_boundaries(Tree_cell *current, int *ibd);
//void deep_tree_set_bool_ref(Mesh *mesh, Tree_cell *current, double h_min);
void deep_tree_refinement(Mesh *mesh, Tree_cell *Tree, Tree_cell *current, double h_min, int *index, int *elt);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment