]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/INTERPOLATION/MEDMEM_Mapping.hxx
Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / INTERPOLATION / MEDMEM_Mapping.hxx
1 #ifndef MEDMEM_MAPPING_HXX
2 #define MEDMEM_MAPPING_HXX
3
4 #include "MEDMEM_MappingTools.hxx"
5 #include "MEDMEM_dTree.hxx"
6
7 #define NBR_MAX_MAILLES_EXAMINEES 100
8
9 #ifndef  NBR_FACES_MAX
10 #define NBR_FACES_MAX 6
11 #endif
12
13 #define _TEMPLATE_ template <class MAILLAGE, class NUAGEMAILLE, class NUAGENOEUD, class NOEUD, int DIMENSION>
14 #define _MAPPING_ Mapping<MAILLAGE,NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION>
15
16
17 //////////////////////////////////////////////////////////////////
18 ///                                                            ///
19 ///                        DECLARATIONS                        ///
20 ///                                                            ///
21 //////////////////////////////////////////////////////////////////
22
23 /*********************************************************/
24 /*                                                       */
25 /*                   Classe  Mapping                     */
26 /*                                                       */
27 /*********************************************************/
28
29 // ATTENTION LE NUAGE DE NOEUD EST SUPPOSE NON REDONDANT ET AUCUNE VERIFICATION N'EST FAITE !
30
31 template <class MAILLAGE, class NUAGEMAILLE, class NUAGENOEUD, class NOEUD, int DIMENSION> class Mapping
32 {
33 protected :
34         MAILLAGE * maillage_back;
35         NUAGEMAILLE * mailles_back;
36         NUAGENOEUD * noeuds_back;
37         NUAGENOEUD * noeuds_front;
38         Coordonnees_Barycentriques<NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION> * CB;
39         dTree<NOEUD,NUAGENOEUD,DIMENSION> * my_dTree;
40         vector<int> resultat_mapping;
41         vector<int> point_le_plus_proche;
42         
43 public :
44         
45         Mapping():maillage_back(NULL),mailles_back(NULL),noeuds_back(NULL),noeuds_front(NULL),CB(NULL),my_dTree(NULL) {}
46         Mapping(MAILLAGE * mb,NUAGENOEUD * nb,NUAGENOEUD * nf); // le dTree est crée à l'initialisation, par contre, le mapping lui meme doit etre invoqué
47         ~Mapping() {if (CB) delete CB;if (my_dTree) delete my_dTree;}
48         dTree<NOEUD,NUAGENOEUD,DIMENSION> * Donne_dTree() {return my_dTree;}
49         int Donne_Directions(int num_maille,const NOEUD &n,int etat_face[NBR_FACES_MAX]);
50         // Méthode interne de localisation
51         int Trouve_Maille_Contenant_Point_Mth_Co(const NOEUD &n,int num_maille,int num_maille_interdit,int max_loop,int &nbr_mailles_examinees,int flag_convexe);
52         void Cree_Mapping(int flag_convexe=0);                                             // SUPPOSE NON CONVEXE PAR DEFAUT
53         void Cree_Mapping(NUAGENOEUD * nf, int flag_convexe=0);                            // SUPPOSE NON CONVEXE PAR DEFAUT
54         inline int operator[](int i) const {return resultat_mapping[i];}                   // Renvoie la valeur mappé, si le mapping a été fait, sinon, n'importe quoi
55         inline vector<int> Get_Mapping() {return resultat_mapping;}                        // Renvoie le vector contenant le mapping
56         inline int Get_Noeud_Le_Plus_Proche(int i) const {return point_le_plus_proche[i];} // Invoque la méthode de d-Tree qui donne le noeud le plus proche
57         inline int Exist_dTree() const {return (my_dTree);}                                // Teste si le dTree existe
58 };
59
60 //////////////////////////////////////////////////////////////////
61 ///                                                            ///
62 ///                            CODE                            ///
63 ///                                                            ///
64 //////////////////////////////////////////////////////////////////
65
66 _TEMPLATE_ void _MAPPING_::Cree_Mapping(NUAGENOEUD * nf, int flag_convexe)
67         {
68         noeuds_front=nf;
69         Cree_Mapping(flag_convexe);
70         }
71
72 _TEMPLATE_ void _MAPPING_::Cree_Mapping(int flag_convexe)
73         {
74         if (!noeuds_front) 
75                  {
76                  cerr<<"Mapping : Pas de noeuds à mapper !"<<endl;
77                  exit(-1);
78                  }
79                  
80         int i,j,k;
81         int nbr_noeuds=noeuds_front->SIZE();
82         int num_maille_depart;
83         int nma=0;
84         resultat_mapping     = vector<int>(nbr_noeuds,UNDEFINED);
85         point_le_plus_proche = vector<int>(nbr_noeuds,UNDEFINED);
86         noeuds_back->affiche();
87                 
88         for (i=0;i<nbr_noeuds;i++)
89                 {
90                 point_le_plus_proche[i]=my_dTree->trouve_plus_proche_point((*noeuds_front)[i]);
91                 num_maille_depart=maillage_back->DONNE_PREMIERE_MAILLE_CONTENANT(point_le_plus_proche[i]);
92                 resultat_mapping[i]=Trouve_Maille_Contenant_Point_Mth_Co((*noeuds_front)[i],num_maille_depart,num_maille_depart,NBR_MAX_MAILLES_EXAMINEES,nma,flag_convexe);
93                 }
94         }
95 _TEMPLATE_ _MAPPING_::Mapping(MAILLAGE * mb,NUAGENOEUD * nb,NUAGENOEUD * nf):maillage_back(mb),noeuds_back(nb),noeuds_front(nf),my_dTree(NULL)
96         {
97         
98         if (!maillage_back)
99                 {
100                 cerr<<"Mapping : constructeur appelé avec Maillage Vide"<<endl;
101                 exit(-1);
102                 }
103                 
104         if (!noeuds_back)
105                 {
106                 cerr<<"Mapping : constructeur appelé avec Nuage Noeuds Vide"<<endl;
107                 exit(-1);
108                 }
109                 
110         mailles_back=maillage_back->DONNE_POINTEUR_NUAGEMAILLE();
111         
112         CB=new Coordonnees_Barycentriques<NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION>(mailles_back,noeuds_back);
113
114         cout<<"MAPPING : VERIFICATION REDONDANCES DANS NUAGE NOEUD BACK"<<endl;
115         
116         int i,j;
117         
118         int nnb=noeuds_back->SIZE();
119         
120         vector<int> redondance(nnb,0);
121         
122         for (i=0;i<nnb;i++) 
123                 {
124                 for (j=i+1;j<nnb;j++) if ((*noeuds_back)[i]==(*noeuds_back)[j]) 
125                         {
126                         cerr<<"Le Noeud "<<j<<" est identique au Noeud "<<i<<endl;
127                         exit(-1);
128                         }
129                 }
130         
131         cout<<"MAPPING : FIN VERIFICATION"<<endl;
132         
133         my_dTree=new dTree<NOEUD,NUAGENOEUD,DIMENSION>(noeuds_back);
134
135
136         }
137 // Renvoie :
138 //     1 si le point est intérieur
139 //    -1 si le point est extérieur à la maille via uniquement des faces qui ne sont pas au bord
140 //    -2 si le point est extérieur à la maille par au moins une face de bord
141 // Et modifie etat_face de telle sorte que :
142 // etat_face[i] = -1 s'il n'existe pas de voisin via la face i
143 // etat_face[i] =  0 si le point est intérieur via la face i et que le voisin i existe
144 // etat_face[i] =  1 si le point est extérieur via la face i et que le voisin i existe
145 _TEMPLATE_ int _MAPPING_::Donne_Directions(int num_maille,const NOEUD &n,int etat_face[NBR_FACES_MAX])
146         {
147         vector<double> ef=CB->Donne_Pseudo_Coord_Baryc(num_maille,n);
148         int etat_int=VRAI;
149         int etat_ext_bord=FAUX;
150         int tf,tv,tb;
151         int nbr_faces=mailles_back->DONNE_NBR_FACES(num_maille);
152         for (int i=0;i<nbr_faces;i++)
153                 {
154                 tf=(ef[i]<0);
155                 tv=(maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,i)==UNDEFINED);
156                 tb=(maillage_back->EST_AU_BORD_FACE_DE_MAILLE(num_maille,i));
157                 if (tf) 
158                         {
159                         etat_int=FAUX;
160                         if (tb) etat_ext_bord=VRAI;
161                         }
162                 if (tv) etat_face[i]=-1;
163                 else
164                         {
165                         if (tf) etat_face[i]=1;
166                         else etat_face[i]=0;
167                         }
168                 }
169         if (etat_int) return 1;
170         if (etat_ext_bord) return -2;
171         return -1;
172         }
173 _TEMPLATE_ int _MAPPING_::Trouve_Maille_Contenant_Point_Mth_Co(const NOEUD &n,int num_maille,int num_maille_interdit,int max_loop,int &nbr_mailles_examinees,int flag_convexe)
174         {
175
176         int etat_face[NBR_FACES_MAX];
177         int i,tmp,nbr_rnd;
178         int indirection[NBR_FACES_MAX];
179         int ind_reel;
180         int num_reel;
181         int new_num=UNDEFINED;
182         
183         int test=Donne_Directions(num_maille,n,etat_face);
184         
185         int nbr_faces=maillage_back->DONNE_NBR_FACES_MAILLE(num_maille);
186         
187         for (i=0;i<nbr_faces;i++) indirection[i]=i;
188         
189         nbr_mailles_examinees=0;
190         
191         while (nbr_mailles_examinees<max_loop)
192                 {
193                 if (test==1) 
194                         {
195                         return num_maille;
196                         }
197                 if ((test==-2)&&(flag_convexe)) 
198                         {
199                         return 2*UNDEFINED;
200                         }
201                 nbr_mailles_examinees++;
202                 for (i=0;i<nbr_faces;i++)
203                         {
204                         tmp=indirection[i];
205                         nbr_rnd=rand()%nbr_faces;
206                         indirection[i]=indirection[nbr_rnd];
207                         indirection[nbr_rnd]=tmp;
208                         }
209                 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++) 
210                         {
211                         ind_reel=indirection[i];
212                         num_reel=maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,ind_reel);
213                         if ((etat_face[ind_reel]==1)&&(num_reel!=num_maille_interdit)) 
214                                 {
215                                 new_num=num_reel;
216                                 }
217                         }
218                 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++) 
219                         {
220                         ind_reel=indirection[i];
221                         num_reel=maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,ind_reel);
222                         if ((etat_face[ind_reel]==0)&&(num_reel!=num_maille_interdit)) 
223                                 {
224                                 new_num=num_reel;
225                                 }
226                         }
227                 if (new_num==UNDEFINED) 
228                         {
229                         new_num=num_maille_interdit;
230                         }
231                 num_maille_interdit=num_maille;
232                 num_maille=new_num;
233                 new_num=UNDEFINED;
234                 test=Donne_Directions(num_maille,n,etat_face);
235                 }
236         return UNDEFINED;
237         }
238
239 #undef _TEMPLATE_
240 #undef _MAPPING_
241
242 #endif