1 #ifndef MEDMEM_MAPPING_HXX
2 #define MEDMEM_MAPPING_HXX
4 #include "MEDMEM_MappingTools.hxx"
5 #include "MEDMEM_dTree.hxx"
7 #define NBR_MAX_MAILLES_EXAMINEES 100
10 #define NBR_FACES_MAX 6
13 #define _TEMPLATE_ template <class MAILLAGE, class NUAGEMAILLE, class NUAGENOEUD, class NOEUD, int DIMENSION>
14 #define _MAPPING_ Mapping<MAILLAGE,NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION>
17 //////////////////////////////////////////////////////////////////
21 //////////////////////////////////////////////////////////////////
23 /*********************************************************/
27 /*********************************************************/
29 // ATTENTION LE NUAGE DE NOEUD EST SUPPOSE NON REDONDANT ET AUCUNE VERIFICATION N'EST FAITE !
31 template <class MAILLAGE, class NUAGEMAILLE, class NUAGENOEUD, class NOEUD, int DIMENSION> class Mapping
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;
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
60 for (int i=0;i<resultat_mapping.size();i++) cout<<"Noeud "<<i<<" de noeud plus proche "<<point_le_plus_proche[i]<<" mappé dans maille "<<resultat_mapping[i]<<endl;
64 //////////////////////////////////////////////////////////////////
68 //////////////////////////////////////////////////////////////////
70 _TEMPLATE_ void _MAPPING_::Cree_Mapping(NUAGENOEUD * nf, int flag_convexe)
73 Cree_Mapping(flag_convexe);
76 _TEMPLATE_ void _MAPPING_::Cree_Mapping(int flag_convexe)
79 if (resultat_mapping.size()==0)
83 cerr<<"Mapping : Pas de noeuds à mapper !"<<endl;
88 int nbr_noeuds=noeuds_front->SIZE();
89 int num_maille_depart;
91 resultat_mapping = vector<int>(nbr_noeuds,UNDEFINED);
92 point_le_plus_proche = vector<int>(nbr_noeuds,UNDEFINED);
94 // noeuds_back->affiche();
96 for (i=0;i<nbr_noeuds;i++)
98 point_le_plus_proche[i]=my_dTree->trouve_plus_proche_point((*noeuds_front)[i]);
99 num_maille_depart=maillage_back->DONNE_PREMIERE_MAILLE_CONTENANT(point_le_plus_proche[i]);
100 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);
106 cout<<"Le mapping semble déja existé, interrogation sur l'existant"<<endl;
110 _TEMPLATE_ _MAPPING_::Mapping(MAILLAGE * mb,NUAGENOEUD * nb,NUAGENOEUD * nf):maillage_back(mb),noeuds_back(nb),noeuds_front(nf),my_dTree(NULL)
115 cerr<<"Mapping : constructeur appelé avec Maillage Vide"<<endl;
121 cerr<<"Mapping : constructeur appelé avec Nuage Noeuds Vide"<<endl;
125 mailles_back=maillage_back->DONNE_POINTEUR_NUAGEMAILLE();
127 CB=new Coordonnees_Barycentriques<NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION>(mailles_back,noeuds_back);
131 int nnb=noeuds_back->SIZE();
134 cout<<"MAPPING : VERIFICATION REDONDANCES DANS NUAGE NOEUD BACK"<<endl;
135 noeuds_back->affiche();
137 vector<int> redondance(nnb,0);
140 for (j=i+1;j<nnb;j++) if ((*noeuds_back)[i]==(*noeuds_back)[j])
142 cerr<<"Le Noeud "<<j<<" est identique au Noeud "<<i<<endl;
146 cout<<"FIN TEST VERIFICATION REDONDANCES"<<endl;
150 my_dTree=new dTree<NOEUD,NUAGENOEUD,DIMENSION>(noeuds_back);
154 // 1 si le point est intérieur
155 // -1 si le point est extérieur à la maille via uniquement des faces qui ne sont pas au bord
156 // -2 si le point est extérieur à la maille par au moins une face de bord
157 // Et modifie etat_face de telle sorte que :
158 // etat_face[i] = -1 s'il n'existe pas de voisin via la face i
159 // etat_face[i] = 0 si le point est intérieur via la face i et que le voisin i existe
160 // etat_face[i] = 1 si le point est extérieur via la face i et que le voisin i existe
161 _TEMPLATE_ int _MAPPING_::Donne_Directions(int num_maille,const NOEUD &n,int etat_face[NBR_FACES_MAX])
163 vector<double> ef=CB->Donne_Pseudo_Coord_Baryc(num_maille,n);
165 int etat_ext_bord=FAUX;
167 int nbr_faces=(*mailles_back)[num_maille].DONNE_NBR_FACES();
168 for (int i=0;i<nbr_faces;i++)
171 tv=(maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,i)==UNDEFINED);
172 tb=(maillage_back->EST_AU_BORD_FACE_DE_MAILLE(num_maille,i));
176 if (tb) etat_ext_bord=VRAI;
178 if (tv) etat_face[i]=-1;
181 if (tf) etat_face[i]=1;
185 if (etat_int) return 1;
186 if (etat_ext_bord) return -2;
189 _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)
192 int etat_face[NBR_FACES_MAX];
194 int indirection[NBR_FACES_MAX];
197 int new_num=UNDEFINED;
199 int test=Donne_Directions(num_maille,n,etat_face);
201 int nbr_faces=maillage_back->DONNE_NBR_FACES_MAILLE(num_maille);
203 for (i=0;i<nbr_faces;i++) indirection[i]=i;
205 nbr_mailles_examinees=0;
207 while (nbr_mailles_examinees<max_loop)
213 if ((test==-2)&&(flag_convexe))
217 nbr_mailles_examinees++;
218 for (i=0;i<nbr_faces;i++)
221 nbr_rnd=rand()%nbr_faces;
222 indirection[i]=indirection[nbr_rnd];
223 indirection[nbr_rnd]=tmp;
225 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++)
227 ind_reel=indirection[i];
228 num_reel=maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,ind_reel);
229 if ((etat_face[ind_reel]==1)&&(num_reel!=num_maille_interdit))
234 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++)
236 ind_reel=indirection[i];
237 num_reel=maillage_back->DONNE_VOISIN_DE_MAILLE(num_maille,ind_reel);
238 if ((etat_face[ind_reel]==0)&&(num_reel!=num_maille_interdit))
243 if (new_num==UNDEFINED)
245 new_num=num_maille_interdit;
247 num_maille_interdit=num_maille;
250 test=Donne_Directions(num_maille,n,etat_face);