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 //////////////////////////////////////////////////////////////////
64 //////////////////////////////////////////////////////////////////
66 _TEMPLATE_ void _MAPPING_::Cree_Mapping(NUAGENOEUD * nf, int flag_convexe)
69 Cree_Mapping(flag_convexe);
72 _TEMPLATE_ void _MAPPING_::Cree_Mapping(int flag_convexe)
76 cerr<<"Mapping : Pas de noeuds à mapper !"<<endl;
81 int nbr_noeuds=noeuds_front->SIZE();
82 int num_maille_depart;
84 resultat_mapping = vector<int>(nbr_noeuds,UNDEFINED);
85 point_le_plus_proche = vector<int>(nbr_noeuds,UNDEFINED);
86 noeuds_back->affiche();
88 for (i=0;i<nbr_noeuds;i++)
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);
95 _TEMPLATE_ _MAPPING_::Mapping(MAILLAGE * mb,NUAGENOEUD * nb,NUAGENOEUD * nf):maillage_back(mb),noeuds_back(nb),noeuds_front(nf),my_dTree(NULL)
100 cerr<<"Mapping : constructeur appelé avec Maillage Vide"<<endl;
106 cerr<<"Mapping : constructeur appelé avec Nuage Noeuds Vide"<<endl;
110 mailles_back=maillage_back->DONNE_POINTEUR_NUAGEMAILLE();
112 CB=new Coordonnees_Barycentriques<NUAGEMAILLE,NUAGENOEUD,NOEUD,DIMENSION>(mailles_back,noeuds_back);
114 cout<<"MAPPING : VERIFICATION REDONDANCES DANS NUAGE NOEUD BACK"<<endl;
118 int nnb=noeuds_back->SIZE();
120 vector<int> redondance(nnb,0);
124 for (j=i+1;j<nnb;j++) if ((*noeuds_back)[i]==(*noeuds_back)[j])
126 cerr<<"Le Noeud "<<j<<" est identique au Noeud "<<i<<endl;
131 cout<<"MAPPING : FIN VERIFICATION"<<endl;
133 my_dTree=new dTree<NOEUD,NUAGENOEUD,DIMENSION>(noeuds_back);
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])
147 vector<double> ef=CB->Donne_Pseudo_Coord_Baryc(num_maille,n);
149 int etat_ext_bord=FAUX;
151 int nbr_faces=mailles_back->DONNE_NBR_FACES(num_maille);
152 for (int i=0;i<nbr_faces;i++)
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));
160 if (tb) etat_ext_bord=VRAI;
162 if (tv) etat_face[i]=-1;
165 if (tf) etat_face[i]=1;
169 if (etat_int) return 1;
170 if (etat_ext_bord) return -2;
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)
176 int etat_face[NBR_FACES_MAX];
178 int indirection[NBR_FACES_MAX];
181 int new_num=UNDEFINED;
183 int test=Donne_Directions(num_maille,n,etat_face);
185 int nbr_faces=maillage_back->DONNE_NBR_FACES_MAILLE(num_maille);
187 for (i=0;i<nbr_faces;i++) indirection[i]=i;
189 nbr_mailles_examinees=0;
191 while (nbr_mailles_examinees<max_loop)
197 if ((test==-2)&&(flag_convexe))
201 nbr_mailles_examinees++;
202 for (i=0;i<nbr_faces;i++)
205 nbr_rnd=rand()%nbr_faces;
206 indirection[i]=indirection[nbr_rnd];
207 indirection[nbr_rnd]=tmp;
209 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++)
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))
218 for (i=0;(i<nbr_faces)&&(new_num==UNDEFINED);i++)
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))
227 if (new_num==UNDEFINED)
229 new_num=num_maille_interdit;
231 num_maille_interdit=num_maille;
234 test=Donne_Directions(num_maille,n,etat_face);