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 //////////////////////////////////////////////////////////////////
18 //////////////////////////////////////////////////////////////////
20 template <int DIMENSION> class Meta_Wrapper;
22 /*********************************************************/
26 /*********************************************************/
28 template <int DIMENSION> class Meta_dTree : public dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>
32 Wrapper_Nuage_Noeud<DIMENSION> * noeuds;
36 Meta_dTree():noeuds(NULL) {}
37 ~Meta_dTree() {if (noeuds) delete noeuds;}
38 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)) {}
39 inline int trouve_plus_proche_point_bourrin(double *node);
41 inline int trouve_plus_proche_point(double * node);
44 /*********************************************************/
46 /* Meta_Nuage_Maille */
48 /*********************************************************/
51 class Meta_Nuage_Maille : public Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>
54 Wrapper_Med_Connectivity * connectivite_med;
56 Meta_Nuage_Maille(CONNECTIVITY * connmed);
57 Meta_Nuage_Maille():connectivite_med(NULL) {}
58 ~Meta_Nuage_Maille() {if (connectivite_med) delete connectivite_med;}
61 /*********************************************************/
65 /*********************************************************/
68 typedef Wrapper_Maillage<Meta_Nuage_Maille> Meta_Maillage;
70 /*********************************************************/
74 /*********************************************************/
76 template <int DIMENSION> class Meta_Mapping : public Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>
79 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) {}
80 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()) {}
82 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);}
83 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);}
84 inline vector<int> & Get_Mapping() {return Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>::Get_Mapping();}
86 inline int Trouve_Maille_Contenant_Noeud(double * node,int num_maille, int flag_convexe=0);
89 /*********************************************************/
93 /*********************************************************/
96 template <int DIMENSION> class Meta_Wrapper
99 Wrapper_Nuage_Noeud<DIMENSION> * noeuds ;
100 Meta_Nuage_Maille * mailles ;
101 Meta_Maillage * maillage ;
102 Wrapper_MED_Field * champ ;
104 void init( ){noeuds=NULL;mailles=NULL;maillage=NULL;champ=NULL;}
106 Meta_Wrapper():noeuds(NULL),mailles(NULL),maillage(NULL),champ(NULL){}
108 inline void Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes );
109 inline void Construit_Wrapper_Nuage_Maille ( CONNECTIVITY * connmed );
110 inline void Construit_Wrapper_Maillage ( void );
111 inline void Construit_Wrapper_Champ ( const FIELD<double> * medfield );
112 Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, int flag_maillage=1);
113 Meta_Wrapper(int nn,double *nodes);
114 // defaultly, the connectivity (neighbouhood and so like) is built,
115 // Set flag_mesh to 0 if you don't want these informations to be built
116 Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, const FIELD<double> * c,int flag_mesh=1);
117 // fonctions d'acces sures
118 inline Wrapper_Nuage_Noeud<DIMENSION> * Get_Nuage_Noeuds ( void );
119 inline Meta_Nuage_Maille * Get_Nuage_Mailles ( void );
120 inline Meta_Maillage * Get_Maillage ( void );
121 inline Wrapper_MED_Field * Get_Champ ( void );
122 inline void Change_Champ ( const FIELD<double> * medfield );
125 /*********************************************************/
127 /* Meta_Calcul_Interpolation_Hybride */
129 /*********************************************************/
131 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>
134 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()) {}
135 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);}
136 Valeur<double> operator() (double * node, int num_maille)
138 static Wrapper_Noeud<DIMENSION> tmp;
139 tmp.positionne(node);
140 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
144 /*********************************************************/
146 /* Meta_Calcul_Interpolation_Hybride_P1 */
148 /*********************************************************/
150 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>
153 Meta_Calcul_Interpolation_Hybride_P1(Meta_Wrapper<DIMENSION> * MW)
156 Wrapper_Nuage_Noeud<DIMENSION> * nn = MW->Get_Nuage_Noeuds();
157 Meta_Nuage_Maille * nm = MW->Get_Nuage_Mailles();
158 Wrapper_MED_Field * c = MW->Get_Champ();
162 fonctions[MED_TRIA3 ]=new Calcul_Interpolation_Tria3 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
163 fonctions[MED_QUAD4 ]=new Calcul_Interpolation_Quad4 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
164 fonctions[MED_TETRA4 ]=new Calcul_Interpolation_Tetra4 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
165 fonctions[MED_HEXA8 ]=new Calcul_Interpolation_Hexa8 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
166 fonctions[MED_PENTA6 ]=new Calcul_Interpolation_Penta6 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
167 fonctions[MED_PYRA5 ]=new Calcul_Interpolation_Pyra5 <Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(nn,nm,c);
168 fonctions[MED_TRIA6 ]=fonctions[MED_TRIA3 ];
169 fonctions[MED_QUAD8 ]=fonctions[MED_QUAD4 ];
170 fonctions[MED_TETRA10]=fonctions[MED_TETRA4 ];
171 fonctions[MED_HEXA20 ]=fonctions[MED_HEXA8 ];
172 fonctions[MED_PENTA15]=fonctions[MED_PENTA6 ];
173 fonctions[MED_PYRA13 ]=fonctions[MED_PYRA5 ];
175 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);}
176 Valeur<double> operator() (double * node, int num_maille)
178 static Wrapper_Noeud<DIMENSION> tmp;
179 tmp.positionne(node);
180 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
184 /*********************************************************/
186 /* Meta_Calcul_Interpolation_P0 */
188 /*********************************************************/
190 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>
193 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()) {}
194 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);}
195 Valeur<double> operator() (double * node, int num_maille)
197 static Wrapper_Noeud<DIMENSION> tmp;
198 tmp.positionne(node);
199 return Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
203 /*********************************************************/
205 /* Meta_Interpolateur */
207 /*********************************************************/
209 template <class FONCTEUR, int DIMENSION> class Meta_Interpolateur
213 Meta_Mapping<DIMENSION> * mapping;
214 Meta_Wrapper<DIMENSION> * fromWrapper;
216 Meta_Interpolateur():fct(NULL),mapping(NULL),fromWrapper(NULL) {}
217 Meta_Interpolateur(Meta_Mapping<DIMENSION> * map, Meta_Wrapper<DIMENSION> * mw):mapping(map),fromWrapper(mw),fct(new FONCTEUR(mw)){}
218 ~Meta_Interpolateur() {if (fct) delete fct;}
219 Wrapper_MED_Field Perform_Interpolation(Wrapper_Nuage_Noeud<DIMENSION> * toNodes)
226 int nbr_composantes = fromWrapper->Get_Champ()->Get_Nbr_Composantes();
227 int nbr_valeurs = toNodes->SIZE();
229 double * valeurs=new double[nbr_valeurs*nbr_composantes];
231 Wrapper_MED_Field resultat(nbr_valeurs,nbr_composantes,valeurs);
235 for (i=0;i<nbr_valeurs;i++)
237 //cout<<"Interpolation du noeud "<<i<<flush;
239 //cout<<" | mappé dans la maille "<<nmc<<flush;
240 //cout<<" | coordonnées = "<<flush<<(*toNodes)[i]<<flush;
243 //cout<<" | valeurs qui va etre assignée = "<<flush<<(*fct)((*toNodes)[i],nmc)<<flush;
244 resultat[i]=(*fct)((*toNodes)[i],nmc);
249 nlpp = mapping->Get_Noeud_Le_Plus_Proche(i);
250 //cout<<" | et dont le point le plus proche a pour numéro : "<<nlpp<<flush;
251 //cout<<" | valeurs qui va etre assignée = "<<(*fromWrapper->Get_Champ())[nlpp]<<flush;
254 resultat[i]=(*fromWrapper->Get_Champ())[nlpp];
259 cerr<<"Meta_Interpolateur : Le noeud "<<i+1<<" n'a ni maille contenante, ni point le plus proche"<<flush;
263 //cout<<" | => OK ! "<<endl;
266 cout<<"Résultat de l'interpolation : "<<endl;
267 cout<<"Nombre de noeuds intérieurs = "<<ni<<endl;
268 cout<<"Nombre de noeuds extérieurs = "<<ne<<endl;
277 //////////////////////////////////////////////////////////////////
281 //////////////////////////////////////////////////////////////////
283 /*********************************************************/
287 /*********************************************************/
289 template <int DIMENSION> inline int Meta_dTree<DIMENSION>::trouve_plus_proche_point(double *node)
291 static Wrapper_Noeud<DIMENSION> nodetmp;
292 nodetmp.positionne(node);
293 return dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>::trouve_plus_proche_point(Wrapper_Noeud<DIMENSION>(nodetmp));
296 template <int DIMENSION> inline int Meta_dTree<DIMENSION>::trouve_plus_proche_point_bourrin(double *node)
298 static Wrapper_Noeud<DIMENSION> nodetmp;
299 nodetmp.positionne(node);
300 return dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>::trouve_plus_proche_point_bourrin(Wrapper_Noeud<DIMENSION>(nodetmp));
302 /*********************************************************/
304 /* Meta_Nuage_Maille */
306 /*********************************************************/
308 Meta_Nuage_Maille::Meta_Nuage_Maille(CONNECTIVITY * conmed):Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>(connectivite_med=new Wrapper_Med_Connectivity(conmed))
312 /*********************************************************/
316 /*********************************************************/
318 template <int DIMENSION> inline int Meta_Mapping<DIMENSION>::Trouve_Maille_Contenant_Noeud(double * node,int num_maille,int flag_convexe)
320 int interdit=num_maille;
323 static Wrapper_Noeud<DIMENSION> nodetmp;
324 nodetmp.positionne(node);
325 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);
328 /*********************************************************/
332 /*********************************************************/
334 template <int DIMENSION> Meta_Wrapper<DIMENSION>::~Meta_Wrapper()
336 if ( noeuds ) delete noeuds ;
337 if ( mailles ) delete mailles ;
338 if ( maillage ) delete maillage ;
339 if ( champ ) delete champ ;
341 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes )
343 if (nodes) noeuds=new Wrapper_Nuage_Noeud<DIMENSION>(nn,nodes);
346 cerr<<"Meta_Wrapper : Nuage MED_FULL_INTERLACE vide passé en argument au constructeur"<<endl;
350 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Maille ( CONNECTIVITY * connmed )
352 if (connmed) mailles=new Meta_Nuage_Maille(connmed);
355 cerr<<"Meta_Wrapper : CONNECTIVITY vide passée en argument au constructeur"<<endl;
359 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Maillage ( void )
363 cerr<<"Meta_Wrapper : Le nuage de maille n'a pas été initialisé !"<<endl;
368 cerr<<"Meta_Wrapper : Le nuage de noeuds n'a pas été initialisé !"<<endl;
371 maillage=new Meta_Maillage(mailles,noeuds->SIZE());
373 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Champ ( const FIELD<double> * medfield )
375 if (medfield) champ=new Wrapper_MED_Field(medfield);
378 cerr<<"Meta_Wrapper : FIELD MED vide passé en argument au constructeur"<<endl;
382 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Change_Champ ( const FIELD<double> * medfield )
386 if (champ) delete champ;
387 champ=new Wrapper_MED_Field(medfield);
391 cerr<<"Meta_Wrapper : FIELD MED vide passé en argument Change_Champ"<<endl;
395 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, int flag_maillage)
398 Construit_Wrapper_Nuage_Noeud(nn,nodes);
399 Construit_Wrapper_Nuage_Maille(connmed);
400 if (flag_maillage) Construit_Wrapper_Maillage();
402 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, const FIELD<double> * c,int flag_maillage)
405 Construit_Wrapper_Nuage_Noeud(nn,nodes);
406 Construit_Wrapper_Nuage_Maille(connmed);
407 if (flag_maillage) Construit_Wrapper_Maillage();
408 Construit_Wrapper_Champ(c);
410 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes)
413 Construit_Wrapper_Nuage_Noeud(nn,nodes);
415 template <int DIMENSION> inline Wrapper_Nuage_Noeud<DIMENSION> * Meta_Wrapper<DIMENSION>::Get_Nuage_Noeuds ( void )
417 if (noeuds) return noeuds;
420 cerr<<"Meta_Wrapper : Nuage noeuds demandé alors qu'il n'est pas construit !"<<endl;
424 template <int DIMENSION> inline Meta_Nuage_Maille * Meta_Wrapper<DIMENSION>::Get_Nuage_Mailles ( void )
426 if (mailles) return mailles ;
429 cerr<<"Meta_Wrapper : Nuage mailles demandé alors qu'il n'est pas construit !"<<endl;
433 template <int DIMENSION> inline Meta_Maillage * Meta_Wrapper<DIMENSION>::Get_Maillage ( void )
435 if (maillage) return maillage ;
438 cerr<<"Meta_Wrapper : Connectivitée maillage demandée alors qu'elle n'est pas construite !"<<endl;
443 template <int DIMENSION> inline Wrapper_MED_Field * Meta_Wrapper<DIMENSION>::Get_Champ ( void )
445 if (champ) return champ;
448 cerr<<"Meta_Wrapper : Champ demandé alors qu'il n'est pas construit !"<<endl;