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>
31 inline int trouve_plus_proche_point(double *node);
34 /*********************************************************/
36 /* Meta_Nuage_Maille */
38 /*********************************************************/
41 class Meta_Nuage_Maille : public Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>
44 Wrapper_Med_Connectivity * connectivite_med;
46 Meta_Nuage_Maille(CONNECTIVITY * connmed);
47 Meta_Nuage_Maille():connectivite_med(NULL) {}
48 ~Meta_Nuage_Maille() {if (connectivite_med) delete connectivite_med;}
51 /*********************************************************/
55 /*********************************************************/
58 typedef Wrapper_Maillage<Meta_Nuage_Maille> Meta_Maillage;
60 /*********************************************************/
64 /*********************************************************/
66 template <int DIMENSION> class Meta_Mapping : public Mapping<Meta_Maillage,Meta_Nuage_Maille,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,DIMENSION>
69 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) {}
70 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()) {}
71 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);}
72 inline int Trouve_Maille_Contenant_Noeud(double * node,int num_maille, int flag_convexe=0);
75 /*********************************************************/
79 /*********************************************************/
82 template <int DIMENSION> class Meta_Wrapper
85 Wrapper_Nuage_Noeud<DIMENSION> * noeuds ;
86 Meta_Nuage_Maille * mailles ;
87 Meta_Maillage * maillage ;
88 Wrapper_MED_Field * champ ;
90 void init( ){noeuds=NULL;mailles=NULL;maillage=NULL;champ=NULL;}
92 Meta_Wrapper():noeuds(NULL),mailles(NULL),maillage(NULL),champ(NULL){}
94 inline void Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes );
95 inline void Construit_Wrapper_Nuage_Maille ( CONNECTIVITY * connmed );
96 inline void Construit_Wrapper_Maillage ( void );
97 inline void Construit_Wrapper_Champ ( const FIELD<double> * medfield );
98 Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, int flag_maillage=1);
99 Meta_Wrapper(int nn,double *nodes);
100 // defaultly, the connectivity (neighbouhood and so like) is built,
101 // Set flag_mesh to 0 if you don't want these informations to be built
102 Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, const FIELD<double> * c,int flag_mesh=1);
103 // fonctions d'acces sures
104 inline Wrapper_Nuage_Noeud<DIMENSION> * Get_Nuage_Noeuds ( void );
105 inline Meta_Nuage_Maille * Get_Nuage_Mailles ( void );
106 inline Meta_Maillage * Get_Maillage ( void );
107 inline Wrapper_MED_Field * Get_Champ ( void );
110 /*********************************************************/
112 /* Meta_Calcul_Interpolation_Hybride */
114 /*********************************************************/
116 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>
119 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()) {}
120 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);}
121 Valeur<double> operator() (double * node, int num_maille)
123 static Wrapper_Noeud<DIMENSION> tmp;
124 tmp.positionne(node);
125 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
129 /*********************************************************/
131 /* Meta_Calcul_Interpolation_Hybride_P1 */
133 /*********************************************************/
135 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>
138 Meta_Calcul_Interpolation_Hybride_P1(Meta_Wrapper<DIMENSION> * MW)
141 Wrapper_Nuage_Noeud<DIMENSION> * nn = MW->Get_Nuage_Noeuds();
142 Meta_Nuage_Maille * nm = MW->Get_Nuage_Mailles();
143 Wrapper_MED_Field * c = MW->Get_Champ();
147 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);
148 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);
149 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);
150 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);
151 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);
152 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);
153 fonctions[MED_TRIA6 ]=fonctions[MED_TRIA3 ];
154 fonctions[MED_QUAD8 ]=fonctions[MED_QUAD4 ];
155 fonctions[MED_TETRA10]=fonctions[MED_TETRA4 ];
156 fonctions[MED_HEXA20 ]=fonctions[MED_HEXA8 ];
157 fonctions[MED_PENTA15]=fonctions[MED_PENTA6 ];
158 fonctions[MED_PYRA13 ]=fonctions[MED_PYRA5 ];
160 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);}
161 Valeur<double> operator() (double * node, int num_maille)
163 static Wrapper_Noeud<DIMENSION> tmp;
164 tmp.positionne(node);
165 return Calcul_Hybride<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
169 /*********************************************************/
171 /* Meta_Calcul_Interpolation_P0 */
173 /*********************************************************/
175 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>
178 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()) {}
179 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);}
180 Valeur<double> operator() (double * node, int num_maille)
182 static Wrapper_Noeud<DIMENSION> tmp;
183 tmp.positionne(node);
184 return Calcul_Interpolation_P0<Wrapper_MED_Field,Valeur<double>,Wrapper_Nuage_Noeud<DIMENSION>,Wrapper_Noeud<DIMENSION>,Meta_Nuage_Maille>(tmp,num_maille);
188 /*********************************************************/
190 /* Meta_Interpolateur */
192 /*********************************************************/
194 template <class FONCTEUR, int DIMENSION> class Meta_Interpolateur
198 Meta_Mapping<DIMENSION> * mapping;
199 Meta_Wrapper<DIMENSION> * fromWrapper;
201 Meta_Interpolateur():fct(NULL),mapping(NULL),fromWrapper(NULL) {}
202 Meta_Interpolateur(Meta_Mapping<DIMENSION> * map, Meta_Wrapper<DIMENSION> * mw):mapping(map),fromWrapper(mw),fct(new FONCTEUR(mw)){}
203 ~Meta_Interpolateur() {if (fct) delete fct;}
204 Wrapper_MED_Field Perform_Interpolation(Wrapper_Nuage_Noeud<DIMENSION> * toNodes)
208 int nbr_composantes = fromWrapper->Get_Champ()->Get_Nbr_Composantes();
209 int nbr_valeurs = toNodes->SIZE();
211 double * valeurs=new double[nbr_valeurs*nbr_composantes];
213 Wrapper_MED_Field resultat(nbr_valeurs,nbr_composantes,valeurs);
217 for (i=0;i<nbr_valeurs;i++)
219 cout<<"Interpolation du noeud "<<i<<flush;
221 cout<<" | mappé dans la maille "<<nmc<<flush;
222 cout<<" | coordonnées = "<<flush<<(*toNodes)[i]<<flush;
225 cout<<" | valeurs qui va etre assignée = "<<flush<<(*fct)((*toNodes)[i],nmc)<<flush;
226 resultat[i]=(*fct)((*toNodes)[i],nmc);
230 nlpp = mapping->Get_Noeud_Le_Plus_Proche(i);
231 cout<<" | et dont le point le plus proche a pour numéro : "<<nlpp<<flush;
232 cout<<" | valeurs qui va etre assignée = "<<(*fromWrapper->Get_Champ())[nlpp]<<flush;
233 if (nlpp!=UNDEFINED) resultat[i]=(*fromWrapper->Get_Champ())[nlpp];
236 cerr<<"Meta_Interpolateur : Le noeud "<<i+1<<" n'a ni maille contenante, ni point le plus proche"<<flush;
240 cout<<" | => OK ! "<<endl;
243 cout<<"Avant return"<<endl;
252 //////////////////////////////////////////////////////////////////
256 //////////////////////////////////////////////////////////////////
258 /*********************************************************/
262 /*********************************************************/
264 template <int DIMENSION> inline int Meta_dTree<DIMENSION>::trouve_plus_proche_point(double *node)
266 static Wrapper_Noeud<DIMENSION> nodetmp;
267 nodetmp.positionne(node);
268 return dTree<Wrapper_Noeud<DIMENSION>,Wrapper_Nuage_Noeud<DIMENSION>,DIMENSION>::trouve_plus_proche_point(Wrapper_Noeud<DIMENSION>(nodetmp));
271 /*********************************************************/
273 /* Meta_Nuage_Maille */
275 /*********************************************************/
277 Meta_Nuage_Maille::Meta_Nuage_Maille(CONNECTIVITY * conmed):Wrapper_Nuage_Maille<Wrapper_Med_Connectivity>(connectivite_med=new Wrapper_Med_Connectivity(conmed))
281 /*********************************************************/
285 /*********************************************************/
287 template <int DIMENSION> inline int Meta_Mapping<DIMENSION>::Trouve_Maille_Contenant_Noeud(double * node,int num_maille,int flag_convexe)
289 int interdit=num_maille;
292 static Wrapper_Noeud<DIMENSION> nodetmp;
293 nodetmp.positionne(node);
294 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);
297 /*********************************************************/
301 /*********************************************************/
303 template <int DIMENSION> Meta_Wrapper<DIMENSION>::~Meta_Wrapper()
305 if ( noeuds ) delete noeuds ;
306 if ( mailles ) delete mailles ;
307 if ( maillage ) delete maillage ;
308 if ( champ ) delete champ ;
310 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Noeud ( int nn, double * nodes )
312 if (nodes) noeuds=new Wrapper_Nuage_Noeud<DIMENSION>(nn,nodes);
315 cerr<<"Meta_Wrapper : Nuage MED_FULL_INTERLACE vide passé en argument au constructeur"<<endl;
319 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Nuage_Maille ( CONNECTIVITY * connmed )
321 if (connmed) mailles=new Meta_Nuage_Maille(connmed);
324 cerr<<"Meta_Wrapper : CONNECTIVITY vide passée en argument au constructeur"<<endl;
328 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Maillage ( void )
332 cerr<<"Meta_Wrapper : Le nuage de maille n'a pas été initialisé !"<<endl;
337 cerr<<"Meta_Wrapper : Le nuage de noeuds n'a pas été initialisé !"<<endl;
340 maillage=new Meta_Maillage(mailles,noeuds->SIZE());
342 template <int DIMENSION> inline void Meta_Wrapper<DIMENSION>::Construit_Wrapper_Champ ( const FIELD<double> * medfield )
344 if (medfield) champ=new Wrapper_MED_Field(medfield);
347 cerr<<"Meta_Wrapper : FIELD MED vide passé en argument au constructeur"<<endl;
351 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, int flag_maillage=1)
354 Construit_Wrapper_Nuage_Noeud(nn,nodes);
355 Construit_Wrapper_Nuage_Maille(connmed);
356 if (flag_maillage) Construit_Wrapper_Maillage();
358 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes,CONNECTIVITY *connmed, const FIELD<double> * c,int flag_maillage=1)
361 Construit_Wrapper_Nuage_Noeud(nn,nodes);
362 Construit_Wrapper_Nuage_Maille(connmed);
363 if (flag_maillage) Construit_Wrapper_Maillage();
364 Construit_Wrapper_Champ(c);
366 template <int DIMENSION> Meta_Wrapper<DIMENSION>::Meta_Wrapper(int nn,double *nodes)
369 Construit_Wrapper_Nuage_Noeud(nn,nodes);
371 template <int DIMENSION> inline Wrapper_Nuage_Noeud<DIMENSION> * Meta_Wrapper<DIMENSION>::Get_Nuage_Noeuds ( void )
373 if (noeuds) return noeuds;
376 cerr<<"Meta_Wrapper : Nuage noeuds demandé alors qu'il n'est pas construit !"<<endl;
380 template <int DIMENSION> inline Meta_Nuage_Maille * Meta_Wrapper<DIMENSION>::Get_Nuage_Mailles ( void )
382 if (mailles) return mailles ;
385 cerr<<"Meta_Wrapper : Nuage mailles demandé alors qu'il n'est pas construit !"<<endl;
389 template <int DIMENSION> inline Meta_Maillage * Meta_Wrapper<DIMENSION>::Get_Maillage ( void )
391 if (maillage) return maillage ;
394 cerr<<"Meta_Wrapper : Connectivitée maillage demandée alors qu'elle n'est pas construite !"<<endl;
399 template <int DIMENSION> inline Wrapper_MED_Field * Meta_Wrapper<DIMENSION>::Get_Champ ( void )
401 if (champ) return champ;
404 cerr<<"Meta_Wrapper : Champ demandé alors qu'il n'est pas construit !"<<endl;