1 #ifndef MEDMEM_INTERPOLATION_HIGHLEVEL_OBJECTS_HXX
2 #define MEDMEM_INTERPOLATION_HIGHLEVEL_OBJECTS_HXX
4 #include "MEDMEM_Connectivity.hxx"
5 #include "MEDMEM_WrapperConnectivity.hxx"
6 #include "MEDMEM_dTree.hxx"
7 #include "MEDMEM_WrapperNodes.hxx"
8 #include "MEDMEM_WrapperMesh.hxx"
9 #include "MEDMEM_WrapperCells.hxx"
10 #include "MEDMEM_Mapping.hxx"
11 #include "MEDMEM_WrapperField.hxx"
12 #include "MEDMEM_InterpolationTools.hxx"
14 #define _CALCUL_HYBRIDE_ Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>
16 //////////////////////////////////////////////////////////////////
20 //////////////////////////////////////////////////////////////////
22 template <int DIMENSION> class Meta_Wrapper;
24 /*********************************************************/
28 /*********************************************************/
30 template <int DIMENSION> class Meta_dTree : public dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>
34 Wrapper_Nuage_Noeud<DIMENSION> * noeuds;
38 Meta_dTree():noeuds(NULL) {}
39 ~Meta_dTree() {if (noeuds) delete noeuds;}
40 Meta_dTree(int nbr_noeuds,double *coord):dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>(noeuds=new Wrapper_Nuage_Noeud<DIMENSION>(nbr_noeuds,coord)) {}
41 inline int trouve_plus_proche_point_bourrin(double *node);
43 inline int trouve_plus_proche_point(double * node);
46 /*********************************************************/
48 /* Meta_Nuage_Maille */
50 /*********************************************************/
53 class Meta_Nuage_Maille : public Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>
56 Wrapper_Med_Connectivity * connectivite_med;
58 Meta_Nuage_Maille(MEDMEM::CONNECTIVITY * connmed);
59 Meta_Nuage_Maille():connectivite_med(NULL) {}
60 ~Meta_Nuage_Maille() {if (connectivite_med) delete connectivite_med;}
63 /*********************************************************/
67 /*********************************************************/
70 typedef Wrapper_Maillage<Meta_Nuage_Maille> Meta_Maillage;
72 /*********************************************************/
76 /*********************************************************/
78 template <int DIMENSION> class Meta_Mapping : public Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>
81 Meta_Mapping(Meta_Wrapper<DIMENSION> * MW):Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>(MW->Get_Maillage(),MW->Get_Nuage_Noeuds(),NULL) {}
82 Meta_Mapping(Meta_Wrapper<DIMENSION> * MW,Meta_Wrapper<DIMENSION> * TWB):Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>(MW->Get_Maillage(),MW->Get_Nuage_Noeuds(),TWB->Get_Nuage_Noeuds()) {}
84 inline void Cree_Mapping(Meta_Wrapper<DIMENSION> * MWB, int flag_convexe) {Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>::Cree_Mapping(MWB->Get_Nuage_Noeuds(),flag_convexe);}
85 inline void Cree_Mapping(int flag_convexe) {Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>::Cree_Mapping(flag_convexe);}
86 inline vector<int> & Get_Mapping() {return Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>::Get_Mapping();}
88 inline int Trouve_Maille_Contenant_Noeud(double * node,int num_maille, int flag_convexe=0);
91 /*********************************************************/
95 /*********************************************************/
98 template <int DIMENSION> class Meta_Wrapper
101 Wrapper_Nuage_Noeud<DIMENSION> * noeuds ;
102 Meta_Nuage_Maille * mailles ;
103 Meta_Maillage * maillage ;
104 Wrapper_MED_Field * champ ;
106 void init( ){noeuds=NULL;mailles=NULL;maillage=NULL;champ=NULL;}
108 Meta_Wrapper():noeuds(NULL),mailles(NULL),maillage(NULL),champ(NULL){}
110 inline void Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes );
111 inline void Construit_Wrapper_Nuage_Maille ( MEDMEM::CONNECTIVITY * connmed );
112 inline void Construit_Wrapper_Maillage ( void );
113 inline void Construit_Wrapper_Champ ( const MEDMEM::FIELD<double> * medfield );
114 Meta_Wrapper(int nn,double *nodes,MEDMEM::CONNECTIVITY *connmed, int flag_maillage=1);
115 Meta_Wrapper(int nn,double *nodes);
116 // defaultly, the connectivity (neighbouhood and so like) is built,
117 // Set flag_mesh to 0 if you don't want these informations to be built
118 Meta_Wrapper(int nn,double *nodes,MEDMEM::CONNECTIVITY *connmed, const MEDMEM::FIELD<double> * c,int flag_mesh=1);
119 // fonctions d'acces sures
120 inline Wrapper_Nuage_Noeud<DIMENSION> * Get_Nuage_Noeuds ( void );
121 inline Meta_Nuage_Maille * Get_Nuage_Mailles ( void );
122 inline Meta_Maillage * Get_Maillage ( void );
123 inline Wrapper_MED_Field * Get_Champ ( void );
124 inline void Change_Champ ( const MEDMEM::FIELD<double> * medfield );
127 /*********************************************************/
129 /* Meta_Calcul_Interpolation_Hybride */
131 /*********************************************************/
133 template <int DIMENSION> class Meta_Calcul_Interpolation_Hybride : public Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>
136 Meta_Calcul_Interpolation_Hybride(Meta_Wrapper<DIMENSION> * MW):Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(MW->Get_Nuage_Noeuds(),MW->Get_Nuage_Mailles(),MW->Get_Champ()) {}
137 Valeur<double> operator() (Wrapper_Noeud<DIMENSION> & node, int num_maille){return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>::operator()(node,num_maille);}
138 Valeur<double> operator() (double * node, int num_maille)
140 static Wrapper_Noeud<DIMENSION> tmp;
141 tmp.positionne(node);
142 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
146 /*********************************************************/
148 /* Meta_Calcul_Interpolation_Hybride_P1 */
150 /*********************************************************/
152 template <int DIMENSION> class Meta_Calcul_Interpolation_Hybride_P1 : public Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>
155 Meta_Calcul_Interpolation_Hybride_P1(Meta_Wrapper<DIMENSION> * MW)
158 Wrapper_Nuage_Noeud<DIMENSION> * nn = MW->Get_Nuage_Noeuds();
159 Meta_Nuage_Maille * nm = MW->Get_Nuage_Mailles();
160 Wrapper_MED_Field * c = MW->Get_Champ();
162 _CALCUL_HYBRIDE_::mailles=nm;
164 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TRIA3 ]=new Calcul_Interpolation_Tria3 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
165 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_QUAD4 ]=new Calcul_Interpolation_Quad4 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
166 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TETRA4 ]=new Calcul_Interpolation_Tetra4 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
167 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_HEXA8 ]=new Calcul_Interpolation_Hexa8 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
168 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PENTA6 ]=new Calcul_Interpolation_Penta6 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
169 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PYRA5 ]=new Calcul_Interpolation_Pyra5 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
170 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TRIA6 ]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TRIA3 ];
171 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_QUAD8 ]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_QUAD4 ];
172 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TETRA10]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_TETRA4 ];
173 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_HEXA20 ]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_HEXA8 ];
174 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PENTA15]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PENTA6 ];
175 _CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PYRA13 ]=_CALCUL_HYBRIDE_::fonctions[ MED_EN::MED_PYRA5 ];
177 Valeur<double> operator() (Wrapper_Noeud<DIMENSION> & node, int num_maille){return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>::operator()(node,num_maille);}
178 Valeur<double> operator() (double * node, int num_maille)
180 static Wrapper_Noeud<DIMENSION> tmp;
181 tmp.positionne(node);
182 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
186 /*********************************************************/
188 /* Meta_Calcul_Interpolation_P0 */
190 /*********************************************************/
192 template <int DIMENSION> class Meta_Calcul_Interpolation_P0 : public Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>
195 Meta_Calcul_Interpolation_P0(Meta_Wrapper<DIMENSION> * MW):Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(MW->Get_Nuage_Noeuds(),MW->Get_Nuage_Mailles(),MW->Get_Champ()) {}
196 Valeur<double> operator() (Wrapper_Noeud<DIMENSION> & node, int num_maille){return Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>::operator()(node,num_maille);}
197 Valeur<double> operator() (double * node, int num_maille)
199 static Wrapper_Noeud<DIMENSION> tmp;
200 tmp.positionne(node);
201 return Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
205 /*********************************************************/
207 /* Meta_Interpolateur */
209 /*********************************************************/
211 template <class FONCTEUR, int DIMENSION> class Meta_Interpolateur
215 Meta_Mapping<DIMENSION> * mapping;
216 Meta_Wrapper<DIMENSION> * fromWrapper;
218 Meta_Interpolateur():fct(NULL),mapping(NULL),fromWrapper(NULL) {}
219 Meta_Interpolateur(Meta_Mapping<DIMENSION> * map, Meta_Wrapper<DIMENSION> * mw):mapping(map),fromWrapper(mw),fct(new FONCTEUR(mw)){}
220 ~Meta_Interpolateur() {if (fct) delete fct;}
221 Wrapper_MED_Field Perform_Interpolation(Wrapper_Nuage_Noeud<DIMENSION> * toNodes)
228 int nbr_composantes = fromWrapper->Get_Champ()->Get_Nbr_Composantes();
229 int nbr_valeurs = toNodes->SIZE();
231 double * valeurs=new double[nbr_valeurs*nbr_composantes];
233 Wrapper_MED_Field resultat(nbr_valeurs,nbr_composantes,valeurs);
237 for (i=0;i<nbr_valeurs;i++)
239 //cout<<"Interpolation du noeud "<<i<<flush;
241 //cout<<" | mappé dans la maille "<<nmc<<flush;
242 //cout<<" | coordonnées = "<<flush<<(*toNodes)[i]<<flush;
245 //cout<<" | valeurs qui va etre assignée = "<<flush<<(*fct)((*toNodes)[i],nmc)<<flush;
246 resultat[i]=(*fct)((*toNodes)[i],nmc);
251 nlpp = mapping->Get_Noeud_Le_Plus_Proche(i);
252 //cout<<" | et dont le point le plus proche a pour numéro : "<<nlpp<<flush;
253 //cout<<" | valeurs qui va etre assignée = "<<(*fromWrapper->Get_Champ())[nlpp]<<flush;
256 resultat[i]=(*fromWrapper->Get_Champ())[nlpp];
261 cerr<<"Meta_Interpolateur : Le noeud "<<i+1<<" n'a ni maille contenante, ni point le plus proche"<<flush;
265 //cout<<" | => OK ! "<<endl;
268 cout<<"Résultat de l'interpolation : "<<endl;
269 cout<<"Nombre de noeuds intérieurs = "<<ni<<endl;
270 cout<<"Nombre de noeuds extérieurs = "<<ne<<endl;
279 //////////////////////////////////////////////////////////////////
283 //////////////////////////////////////////////////////////////////
285 /*********************************************************/
289 /*********************************************************/
291 template <int DIMENSION> inline int Meta_dTree<DIMENSION>::trouve_plus_proche_point(double *node)
293 static Wrapper_Noeud<DIMENSION> nodetmp;
294 nodetmp.positionne(node);
295 return dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>::trouve_plus_proche_point(Wrapper_Noeud<DIMENSION>(nodetmp));
298 template <int DIMENSION> inline int Meta_dTree<DIMENSION>::trouve_plus_proche_point_bourrin(double *node)
300 static Wrapper_Noeud<DIMENSION> nodetmp;
301 nodetmp.positionne(node);
302 return dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>::trouve_plus_proche_point_bourrin(Wrapper_Noeud<DIMENSION>(nodetmp));
304 /*********************************************************/
306 /* Meta_Nuage_Maille */
308 /*********************************************************/
310 inline Meta_Nuage_Maille::Meta_Nuage_Maille(MEDMEM::CONNECTIVITY * conmed):Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>(connectivite_med=new Wrapper_Med_Connectivity(conmed))
314 /*********************************************************/
318 /*********************************************************/
320 template <int DIMENSION> inline int Meta_Mapping<DIMENSION>::Trouve_Maille_Contenant_Noeud(double * node,int num_maille,int flag_convexe)
322 int interdit=num_maille;
325 static Wrapper_Noeud<DIMENSION> nodetmp;
326 nodetmp.positionne(node);
327 return Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>::Trouve_Maille_Contenant_Point_Mth_Co(nodetmp,num_maille,interdit,max_loop,nme,flag_convexe);
330 /*********************************************************/
334 /*********************************************************/
336 template <int DIMENSION> Meta_Wrapper<DIMENSION>::~Meta_Wrapper()
338 if ( noeuds ) delete noeuds ;
339 if ( mailles ) delete mailles ;
340 if ( maillage ) delete maillage ;
341 if ( champ ) delete champ ;
343 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes )
345 if (nodes) noeuds=new Wrapper_Nuage_Noeud<DIMENSION>(nn,nodes);
348 cerr<<"Meta_Wrapper : Nuage MED_FULL_INTERLACE vide passé en argument au constructeur"<<endl;
352 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Maille ( MEDMEM::CONNECTIVITY * connmed )
354 if (connmed) mailles=new Meta_Nuage_Maille(connmed);
357 cerr<<"Meta_Wrapper : CONNECTIVITY vide passée en argument au constructeur"<<endl;
361 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Maillage ( void )
365 cerr<<"Meta_Wrapper : Le nuage de maille n'a pas été initialisé !"<<endl;
370 cerr<<"Meta_Wrapper : Le nuage de noeuds n'a pas été initialisé !"<<endl;
373 maillage=new Meta_Maillage(mailles,noeuds->SIZE());
375 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Champ ( const MEDMEM::FIELD<double> * medfield )
377 if (medfield) champ=new Wrapper_MED_Field(medfield);
380 cerr<<"Meta_Wrapper : FIELD MED vide passé en argument au constructeur"<<endl;
384 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Change_Champ ( const MEDMEM::FIELD<double> * medfield )
388 if (champ) delete champ;
389 champ=new Wrapper_MED_Field(medfield);
393 cerr<<"Meta_Wrapper : FIELD MED vide passé en argument Change_Champ"<<endl;
397 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,MEDMEM::CONNECTIVITY *connmed, int flag_maillage)
400 Construit_Wrapper_Nuage_Noeud(nn,nodes);
401 Construit_Wrapper_Nuage_Maille(connmed);
402 if (flag_maillage) Construit_Wrapper_Maillage();
404 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,MEDMEM::CONNECTIVITY *connmed, const MEDMEM::FIELD<double> * c,int flag_maillage)
407 Construit_Wrapper_Nuage_Noeud(nn,nodes);
408 Construit_Wrapper_Nuage_Maille(connmed);
409 if (flag_maillage) Construit_Wrapper_Maillage();
410 Construit_Wrapper_Champ(c);
412 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes)
415 Construit_Wrapper_Nuage_Noeud(nn,nodes);
417 template <int DIMENSION> inline Wrapper_Nuage_Noeud<DIMENSION> * Meta_Wrapper<DIMENSION>::Get_Nuage_Noeuds ( void )
419 if (noeuds) return noeuds;
422 cerr<<"Meta_Wrapper : Nuage noeuds demandé alors qu'il n'est pas construit !"<<endl;
426 template <int DIMENSION> inline Meta_Nuage_Maille * Meta_Wrapper<DIMENSION>::Get_Nuage_Mailles ( void )
428 if (mailles) return mailles ;
431 cerr<<"Meta_Wrapper : Nuage mailles demandé alors qu'il n'est pas construit !"<<endl;
435 template <int DIMENSION> inline Meta_Maillage * Meta_Wrapper<DIMENSION>::Get_Maillage ( void )
437 if (maillage) return maillage ;
440 cerr<<"Meta_Wrapper : Connectivitée maillage demandée alors qu'elle n'est pas construite !"<<endl;
445 template <int DIMENSION> inline Wrapper_MED_Field * Meta_Wrapper<DIMENSION>::Get_Champ ( void )
447 if (champ) return champ;
450 cerr<<"Meta_Wrapper : Champ demandé alors qu'il n'est pas construit !"<<endl;