mesh.h 9.38 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
/*
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
2
 * MigFlow - Copyright (C) <2010-2018>
3
4
 * <Universite catholique de Louvain (UCL), Belgium
 *  Universite de Montpellier, France>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
5
 * 	
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
6
 * List of the contributors to the development of MigFlow: see AUTHORS file.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
7
8
 * Description and complete License: see LICENSE file.
 * 	
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
9
 * This program (MigFlow) is free software: 
10
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
11
12
13
14
15
16
 * Public License as published by the Free Software Foundation, either version
 * 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Lesser General Public License for more details.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
18
 * 
19
20
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program (see COPYING and COPYING.LESSER files).  If not, 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
21
22
 * see <http://www.gnu.org/licenses/>.
 */
23
 
24
25
26
#ifndef MESH_H
#define MESH_H

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
27
#include <stdio.h>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
28
#include <stdint.h>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
29

30
31
32
typedef struct {
  int n_nodes;
  double *x;
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
33
  int n_elements;
34
  int *elements;
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
35
36
  int n_boundaries;
  char **boundary_names;
Jonathan Lambrechts's avatar
broken    
Jonathan Lambrechts committed
37
  int n_interfaces;
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
38
  int *interfaces; // eid0, closure0, {(eid1, closure1),(-1,phys_id)}
Margaux Boxho's avatar
wip    
Margaux Boxho committed
39
  double *min_h_target; // added attribut for "in advance" strategy
40
41
42
43
} Mesh;

Mesh *mesh_load_msh(const char *filename);
void mesh_free(Mesh *m);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
44
45
int mesh_write_msh(Mesh *mesh, FILE *f);
int mesh_write_msh_scalar(const Mesh *mesh, FILE *f, const char *field_name, double t, int iter, const double *solution, int n_fields, int field_id);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
46
int mesh_write_msh_vector(const Mesh *mesh, FILE *f, const char *field_name, double t, int iter, const double *solution, int n_fields, int field_id[DIMENSION]);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
47
void mesh_gen_edges(Mesh *m, int n_bnd_elements, int *bnd_elements, int *bnd_tags);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
48
49

int mesh_write_pos_scalar(const Mesh *mesh, const char *dir_name, const char *field_name, double t, int iter, const double *solution, int n_fields, int field_id);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
50
int mesh_write_pos_vector(const Mesh *mesh, const char *dir_name, const char *field_name, double t, int iter, const double *solution, int n_fields, int field_id[DIMENSION]);
Margaux Boxho's avatar
wip    
Margaux Boxho committed
51
52
53
54
/*
 Initialized the min_h_target attribut of the Mesh structure
 */
void mesh_initialized_min_h_target(Mesh *mesh);
55

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
56
57
58
59
60
61
62
63
64
65
66
// not really necessary but useful to implement bnd conditions,
// can be rebuilt from the interface list 
typedef struct {
  int n_interfaces;
  int *interfaces;
  int n_nodes;
  int *nodes;
} MeshBoundary;

MeshBoundary *mesh_boundaries_create(const Mesh *m);
void mesh_boundaries_free(MeshBoundary *mbnd, int n);
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#if DIMENSION == 2
static  int elbnd[6][2] = {
  {0,1},{1,2},{2,0},
  {1,0},{2,1},{0,2}};
#else
static int elbnd[24][3] = {
  {0,1,2},{0,2,3},{0,3,1},{1,3,2},
  {2,0,1},{3,0,2},{1,0,3},{2,1,3},
  {1,2,0},{2,3,0},{3,1,0},{3,2,1},

  {0,2,1},{0,3,2},{0,1,3},{1,2,3},
  {2,1,0},{3,2,0},{1,3,0},{2,3,1},
  {1,0,2},{2,0,3},{3,0,1},{3,1,2}
};
#endif
Margaux Boxho's avatar
wip    
Margaux Boxho committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

// Creating a structure to work with edges and traingles neighbors in 2D unstructure mesh
// Creation of the structure for Edge
//        --> tag         ==> an integer representong the tag of the edge
//        --> tag_Node[2] ==> an array describing the edge
//        --> tag_Tri[2]  ==> an array of two neighbors traingles having the same edge
//        --> jumpX       ==> a double representing the average jump in the x-gradient
//        --> jumpY       ==> a double representing the average jump in the y-gradient
typedef struct Edge Edge;
struct Edge
{
    int tag;
    int tag_Node[2]; // because an edge is defined by two nodes
    int tag_Tri[2]; // because an edge connects two triangles
    double jumpX; // mean gradient jump value
    double jumpY; // mean gradient jump value
};

/*
 The function initialized_edges_array aims to reference every edge with a tag, the tags of nodes creating the
 edge and the tags of neighbors traingles having this edge in common. 
 
 @inputs:  - a pointer to the structure mesh gathering information about nodes and elements
           - an array of edge structure (initialized to zero everywhere)
           - an integer n_edges, the number of edges in the structure mesh (this number is deduced form the 
             famour Euler formula for planar graph n-e+f=2) !!!!! 
 
 @outputs: - return nothing but write in the array edges_vec and complete information about tag, tag_node and
           tag_Tri.
*/
void initialized_edges_array(Mesh *mesh, Edge *edges_vec, int n_edges);
// void free_edges_array(Edge *edges_vec, int n_edges);
Margaux Boxho's avatar
Margaux Boxho committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128

// **********************************************************************************************************
// Local mesh adaptation
// **********************************************************************************************************


/* For each triangular elements present in the coarse mesh, we associate a Cell structure
 that contains either a NULL pointer if the current triangle should not be refined otherwise
 it contains a pointer to 4 Cell elements that will represent the refinement of the current
 triangular element.
 */
typedef struct Tree_cell
{
    struct Tree_cell *children;
129
130
131
    struct Tree_cell *parent;
    
    int tag;
132
    int bool_boundary;
133
    int bool_ref;
134
    int bool_def;
135
    int num_children;
136
    int sub_nodes[3];
137
138
139
    
    int nodes[3];       // nodes tag of the current triangle
    int neighbours[3];  // tag of the three neighbors of the current triangle
140
    int phys[3];        // -1 if the edge is not on the boundaries and phys_id if the edge is part of the boundaries.
141
    int bdies[3];
142
143
    
    
Margaux Boxho's avatar
Margaux Boxho committed
144
145
} Tree_cell ;

146
147
// INITIALIZATION OF STRUCTURE
void deep_tree_initialized(Mesh *mesh, Tree_cell *Tree, int size);
148
void initialize_children(Tree_cell *current, int excess);
149
void initialize_children_bis(Tree_cell *current); 
150
void look_for(Tree_cell *current, int elt);
151
152
153
154
155
// MAPPING
void deep_tree_get_mapping(Tree_cell *Tree, Tree_cell **map, int size);
void deep_tree_go_to_leaves(Tree_cell *current, Tree_cell **map);
// REFINEMENT
void deep_tree_check_for_refinement(Mesh *mesh, Tree_cell *current, double h_target, double h_min);
156
157
158
159
160
161
162
163
164
165
166
167
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);
// COARSENING
void deep_tree_correspondence(int *tab_node, int len_node, int size_init_node, int *tab_elt, int len_elt, int size_init_elt, int *index_remove, int *elt_remove);
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);
void deep_tree_check_for_coarsening(Tree_cell *current, Tree_cell **map, int bool_nghb[3], int bool_tag[3], int n_elements);
void deep_tree_remove_elt(Tree_cell *current, Tree_cell **map, int len_node, int *tab_node, int size_init_node, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform4_into_3(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform4_into_2(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform4_into_1(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform3_into_2(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform3_into_1(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
void deep_tree_transform2_into_1(Tree_cell *parent, int len_elt, int *tab_elt, int size_init_elt);
168
169
170
171
172
173
174
175
176
177
// CUTTING FUNCTION
void deep_tree_cut_into_4(Tree_cell *current, Tree_cell **map, int *index, int *elt, int *ibd);
void deep_tree_cut_into_2(Tree_cell *current, int *elt);
void deep_tree_cut_into_3(Tree_cell *current, int *elt);
void deep_tree_smooth_refinement(Tree_cell *current, Tree_cell **map, int *index, int *elt, int *ibd);
void deep_tree_transform2_into_4(Tree_cell *current, Tree_cell **map, int *index, int *elt, int *ibd);
void deep_tree_transform3_into_4(Tree_cell *current, Tree_cell **map, int *index, int *elt, int *ibd);
void deep_tree_transform(Tree_cell *current, Tree_cell **map, int *index, int *elt, int *ibd);
// CONSTRUCTION OF OUTPUTS DATA STRUCTURE
void deep_tree_count_boundaries(Tree_cell *current, int *ibd);
178
179
180
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);
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);
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);
181
// PRINTING TOOLS
Margaux Boxho's avatar
Margaux Boxho committed
182
void printing_post_processing_files(Mesh *mesh, int *elements_new, double *x_new, int *boundaries_new, int n_elements_new, int n_boundaries_new);
183
void printing_current(Tree_cell *current);
184
185
#endif

Margaux Boxho's avatar
Margaux Boxho committed
186
187
188
189
190
191
192
193
194
195
196