Salome HOME
Merge branch 'gni/adaptation' of https://codev-tuleap.cea.fr/plugins/git/salome/smesh...
[modules/smesh.git] / src / ADAPT / HOMARD_Hypothesis.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2020  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //  File   : HOMARD_Hypothesis.cxx
22 //  Author : Gerald NICOLAS, EDF
23 //  Module : HOMARD
24 //
25 // Remarques :
26 // L'ordre de description des fonctions est le meme dans tous les fichiers
27 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
28 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
29 // 2. Les caracteristiques
30 // 3. Le lien avec les autres structures
31 //
32 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
33
34 #include "HOMARD_Hypothesis.hxx"
35 #include "HOMARD.hxx"
36 #include "utilities.h"
37
38 //=============================================================================
39 /*!
40  *  default constructor:
41  */
42 //=============================================================================
43 HOMARD_Hypothesis::HOMARD_Hypothesis():
44   _Name(""), _NomCasCreation(""),
45   _TypeAdap(-1), _TypeRaff(0), _TypeDera(0),
46   _Field(""),
47   _TypeThR(0), _ThreshR(0),
48   _TypeThC(0), _ThreshC(0),
49   _UsField(0), _UsCmpI(0),  _TypeFieldInterp(0)
50 {
51   MESSAGE("HOMARD_Hypothesis");
52 }
53
54 //=============================================================================
55 /*!
56  */
57 //=============================================================================
58 HOMARD_Hypothesis::~HOMARD_Hypothesis()
59 {
60   MESSAGE("~HOMARD_Hypothesis");
61 }
62 //=============================================================================
63 //=============================================================================
64 // Generalites
65 //=============================================================================
66 //=============================================================================
67 void HOMARD_Hypothesis::SetName( const char* Name )
68 {
69   _Name = std::string( Name );
70 }
71 //=============================================================================
72 std::string HOMARD_Hypothesis::GetName() const
73 {
74   return _Name;
75 }
76 //=============================================================================
77 std::string HOMARD_Hypothesis::GetDumpPython() const
78 {
79   std::ostringstream aScript;
80   aScript << "\n# Creation of the hypothesis " << _Name << "\n" ;
81   aScript << "\t" << _Name << " = homard.CreateHypothesis(\"" << _Name << "\")\n";
82   if ( _TypeAdap == -1 )
83   {
84     int TypeRaffDera ;
85     if ( _TypeRaff == 1 ) { TypeRaffDera = 1 ; }
86     else                  { TypeRaffDera = -1 ; }
87     aScript << "\t" << _Name << ".SetUnifRefinUnRef(" << TypeRaffDera << ")\n";
88   }
89
90 // Raffinement selon des zones geometriques
91   std::list<std::string>::const_iterator it = _ListZone.begin();
92   int TypeUse ;
93   while(it != _ListZone.end())
94   {
95       aScript << "\t" << _Name << ".AddZone(\"" << *it;
96       it++;
97       if ( *it == "1" ) { TypeUse =  1 ; }
98       else              { TypeUse = -1 ; }
99       aScript << "\", " << TypeUse << ")\n";
100       it++;
101   }
102
103 // Raffinement selon un champ
104   if ( _TypeAdap == 1 )
105   {
106     aScript << "\t" << _Name << ".SetField(\"" << _Field << "\")\n";
107     aScript << "\t" << _Name << ".SetUseField(" << _UsField << ")\n";
108     aScript << "\t" << _Name << ".SetUseComp(" << _UsCmpI << ")\n";
109     std::list<std::string>::const_iterator it_comp = _ListComp.begin();
110     while(it_comp != _ListComp.end())
111     {
112       aScript << "\t" << _Name << ".AddComp(\"" << *it_comp << "\")\n";
113       it_comp++;
114     }
115     if ( _TypeRaff == 1 )
116     {
117       aScript << "\t" << _Name << ".SetRefinThr(" << _TypeThR << ", " << _ThreshR << ")\n";
118     }
119     if ( _TypeDera == 1 )
120     {
121       aScript << "\t" << _Name << ".SetUnRefThr(" << _TypeThC << ", " << _ThreshC << ")\n";
122     }
123   }
124
125 // Filtrage du raffinement par des groupes
126    for ( it=_ListGroupSelected.begin(); it!=_ListGroupSelected.end();it++)
127        aScript << "\t" << _Name << ".AddGroup(\""  << (*it) <<  "\")\n" ;
128
129 // Interpolation des champs
130   if ( _TypeFieldInterp == 2 )
131   {
132     std::list<std::string>::const_iterator it_champ = _ListFieldInterp.begin();
133     while(it_champ != _ListFieldInterp.end())
134     {
135       aScript << "\t" << _Name << ".AddFieldInterpType( \"" << *it_champ  <<  "\" " ;
136       it_champ++;
137       aScript << ", " << *it_champ << ")\n";
138       it_champ++;
139     }
140   }
141   else if ( _TypeFieldInterp != 0 )
142   {
143     aScript << "\t" << _Name << ".SetTypeFieldInterp(" << _TypeFieldInterp << ")\n";
144   }
145   if ( _NivMax > 0 )
146   {
147     aScript << "\t" <<_Name << ".SetNivMax(" << _NivMax << ")\n";
148   }
149   if ( _DiamMin > 0 )
150   {
151     aScript << "\t" <<_Name << ".SetDiamMin(" << _DiamMin << ")\n";
152   }
153   if ( _AdapInit != 0 )
154   {
155     aScript << "\t" <<_Name << ".SetAdapInit(" << _AdapInit << ")\n";
156   }
157   if ( _ExtraOutput != 1 )
158   {
159     aScript << "\t" <<_Name << ".SetExtraOutput(" << _ExtraOutput << ")\n";
160   }
161
162   return aScript.str();
163 }
164 //=============================================================================
165 //=============================================================================
166 // Caracteristiques
167 //=============================================================================
168 //=============================================================================
169 void HOMARD_Hypothesis::SetAdapType( int TypeAdap )
170 {
171   VERIFICATION( (TypeAdap>=-1) && (TypeAdap<=1) );
172   _TypeAdap = TypeAdap;
173 }
174 //=============================================================================
175 int HOMARD_Hypothesis::GetAdapType() const
176 {
177   return _TypeAdap;
178 }
179 //=============================================================================
180 void HOMARD_Hypothesis::SetRefinTypeDera( int TypeRaff, int TypeDera )
181 {
182   VERIFICATION( (TypeRaff>=-1) && (TypeRaff<=1) );
183   _TypeRaff = TypeRaff;
184   VERIFICATION( (TypeDera>=-1) && (TypeDera<=1) );
185   _TypeDera = TypeDera;
186 }
187 //=============================================================================
188 int HOMARD_Hypothesis::GetRefinType() const
189 {
190   return _TypeRaff;
191 }
192 //=============================================================================
193 int HOMARD_Hypothesis::GetUnRefType() const
194 {
195   return _TypeDera;
196 }
197 //=============================================================================
198 void HOMARD_Hypothesis::SetField( const char* FieldName )
199 {
200   _Field = std::string( FieldName );
201   MESSAGE( "SetField : FieldName = " << FieldName );
202 }
203 //=============================================================================
204 std::string HOMARD_Hypothesis::GetFieldName() const
205 {
206   return _Field;
207 }
208 //=============================================================================
209 void HOMARD_Hypothesis::SetUseField( int UsField )
210 {
211   VERIFICATION( (UsField>=0) && (UsField<=1) );
212   _UsField = UsField;
213 }
214 //=============================================================================
215 int HOMARD_Hypothesis::GetUseField() const
216 {
217   return _UsField;
218 }
219 //=============================================================================
220 void HOMARD_Hypothesis::SetUseComp( int UsCmpI )
221 {
222   MESSAGE ("SetUseComp pour UsCmpI = "<<UsCmpI) ;
223   VERIFICATION( (UsCmpI>=0) && (UsCmpI<=2) );
224   _UsCmpI = UsCmpI;
225 }
226 //=============================================================================
227 int HOMARD_Hypothesis::GetUseComp() const
228 {
229   return _UsCmpI;
230 }
231 //=============================================================================
232 void HOMARD_Hypothesis::AddComp( const char* NomComp )
233 {
234 // On commence par supprimer la composante au cas ou elle aurait deja ete inseree
235 // Cela peut se produire dans un schema YACS quand on repasse plusieurs fois par la
236 // definition de l'hypothese
237   SupprComp( NomComp ) ;
238 // Insertion veritable
239   _ListComp.push_back( std::string( NomComp ) );
240 }
241 //=============================================================================
242 void HOMARD_Hypothesis::SupprComp( const char* NomComp )
243 {
244   MESSAGE ("SupprComp pour "<<NomComp) ;
245   std::list<std::string>::iterator it = find( _ListComp.begin(), _ListComp.end(), NomComp );
246   if ( it != _ListComp.end() ) { it = _ListComp.erase( it ); }
247 }
248 //=============================================================================
249 void HOMARD_Hypothesis::SupprComps()
250 {
251   _ListComp.clear();
252 }
253 //=============================================================================
254 const std::list<std::string>& HOMARD_Hypothesis::GetComps() const
255 {
256   return _ListComp;
257 }
258 //=============================================================================
259 void HOMARD_Hypothesis::SetRefinThr( int TypeThR, double ThreshR )
260 {
261   MESSAGE( "SetRefinThr : TypeThR = " << TypeThR << ", ThreshR = " << ThreshR );
262   VERIFICATION( (TypeThR>=0) && (TypeThR<=4) );
263   _TypeThR = TypeThR;
264   _ThreshR = ThreshR;
265 }
266 //=============================================================================
267 int HOMARD_Hypothesis::GetRefinThrType() const
268 {
269   return _TypeThR;
270 }
271 //=============================================================================
272 double HOMARD_Hypothesis::GetThreshR() const
273 {
274   return _ThreshR;
275 }
276 //=============================================================================
277 void HOMARD_Hypothesis::SetUnRefThr( int TypeThC, double ThreshC )
278 {
279   VERIFICATION( (TypeThC>=0) && (TypeThC<=4) );
280   _TypeThC = TypeThC;
281   _ThreshC = ThreshC;
282 }
283 //=============================================================================
284 int HOMARD_Hypothesis::GetUnRefThrType() const
285 {
286   return _TypeThC;
287 }
288 //=============================================================================
289 double HOMARD_Hypothesis::GetThreshC() const
290 {
291   return _ThreshC;
292 }
293 //=============================================================================
294 void HOMARD_Hypothesis::SetNivMax( int NivMax )
295 //=============================================================================
296 {
297   _NivMax = NivMax;
298 }
299 //=============================================================================
300 const int HOMARD_Hypothesis::GetNivMax() const
301 //=============================================================================
302 {
303   return _NivMax;
304 }
305 //=============================================================================
306 void HOMARD_Hypothesis::SetDiamMin( double DiamMin )
307 //=============================================================================
308 {
309   _DiamMin = DiamMin;
310 }
311 //=============================================================================
312 const double HOMARD_Hypothesis::GetDiamMin() const
313 //=============================================================================
314 {
315   return _DiamMin;
316 }
317 //=============================================================================
318 void HOMARD_Hypothesis::SetAdapInit( int AdapInit )
319 //=============================================================================
320 {
321   _AdapInit = AdapInit;
322 }
323 //=============================================================================
324 const int HOMARD_Hypothesis::GetAdapInit() const
325 //=============================================================================
326 {
327   return _AdapInit;
328 }
329 //=============================================================================
330 void HOMARD_Hypothesis::SetExtraOutput( int ExtraOutput )
331 //=============================================================================
332 {
333   _ExtraOutput = ExtraOutput;
334 }
335 //=============================================================================
336 const int HOMARD_Hypothesis::GetExtraOutput() const
337 //=============================================================================
338 {
339   return _ExtraOutput;
340 }
341 //=============================================================================
342 void HOMARD_Hypothesis::AddGroup( const char* Group)
343 {
344 // On commence par supprimer le groupe au cas ou il aurait deja ete insere
345 // Cela peut se produire dans un schema YACS quand on repasse plusieurs fois par la
346 // definition de l'hypothese
347   SupprGroup( Group ) ;
348 // Insertion veritable
349   _ListGroupSelected.push_back(Group);
350 }
351 //=============================================================================
352 void HOMARD_Hypothesis::SupprGroup( const char* Group )
353 {
354   MESSAGE ("SupprGroup pour "<<Group) ;
355   std::list<std::string>::iterator it = find( _ListGroupSelected.begin(), _ListGroupSelected.end(), Group );
356   if ( it != _ListGroupSelected.end() ) { it = _ListGroupSelected.erase( it ); }
357 }
358 //=============================================================================
359 void HOMARD_Hypothesis::SupprGroups()
360 {
361   _ListGroupSelected.clear();
362 }
363 //=============================================================================
364 void HOMARD_Hypothesis::SetGroups( const std::list<std::string>& ListGroup )
365 {
366   _ListGroupSelected.clear();
367   std::list<std::string>::const_iterator it = ListGroup.begin();
368   while(it != ListGroup.end())
369     _ListGroupSelected.push_back((*it++));
370 }
371 //=============================================================================
372 const std::list<std::string>& HOMARD_Hypothesis::GetGroups() const
373 {
374   return _ListGroupSelected;
375 }
376 //=============================================================================
377 // Type d'interpolation des champs :
378 //   0 : aucun champ n'est interpole
379 //   1 : tous les champs sont interpoles
380 //   2 : certains champs sont interpoles
381 void HOMARD_Hypothesis::SetTypeFieldInterp( int TypeFieldInterp )
382 {
383   VERIFICATION( (TypeFieldInterp>=0) && (TypeFieldInterp<=2) );
384   _TypeFieldInterp = TypeFieldInterp;
385 }
386 //=============================================================================
387 int HOMARD_Hypothesis::GetTypeFieldInterp() const
388 {
389   return _TypeFieldInterp;
390 }
391 //=============================================================================
392 void HOMARD_Hypothesis::AddFieldInterpType( const char* FieldInterp, int TypeInterp )
393 {
394   MESSAGE ("Dans AddFieldInterpType pour " << FieldInterp << " et TypeInterp = " << TypeInterp) ;
395 // On commence par supprimer le champ au cas ou il aurait deja ete insere
396 // Cela peut se produire dans un schema YACS quand on repasse plusieurs fois par la
397 // definition de l'hypothese
398   SupprFieldInterp( FieldInterp ) ;
399 // Insertion veritable
400 // . Nom du champ
401   _ListFieldInterp.push_back( std::string( FieldInterp ) );
402 // . Usage du champ
403   std::stringstream saux1 ;
404   saux1 << TypeInterp ;
405   _ListFieldInterp.push_back( saux1.str() );
406 // . Indication generale : certains champs sont a interpoler
407   SetTypeFieldInterp ( 2 ) ;
408 }
409 //=============================================================================
410 void HOMARD_Hypothesis::SupprFieldInterp( const char* FieldInterp )
411 {
412   MESSAGE ("Dans SupprFieldInterp pour " << FieldInterp) ;
413   std::list<std::string>::iterator it = find( _ListFieldInterp.begin(), _ListFieldInterp.end(), FieldInterp ) ;
414 // Attention a supprimer le nom du champ et le type d'usage
415   if ( it != _ListFieldInterp.end() )
416   {
417     it = _ListFieldInterp.erase( it ) ;
418     it = _ListFieldInterp.erase( it ) ;
419   }
420 // Decompte du nombre de champs restant a interpoler
421   it = _ListFieldInterp.begin() ;
422   int cpt = 0 ;
423   while(it != _ListFieldInterp.end())
424   {
425     cpt += 1 ;
426     (*it++);
427   }
428   MESSAGE("Nombre de champ restants = "<<cpt/2);
429 // . Indication generale : aucun champ ne reste a interpoler
430   if ( cpt == 0 )
431   {
432     SetTypeFieldInterp ( 0 ) ;
433   }
434 }
435 //=============================================================================
436 void HOMARD_Hypothesis::SupprFieldInterps()
437 {
438   MESSAGE ("SupprFieldInterps") ;
439   _ListFieldInterp.clear();
440 // . Indication generale : aucun champ ne reste a interpoler
441   SetTypeFieldInterp ( 0 ) ;
442 }
443 //=============================================================================
444 const std::list<std::string>& HOMARD_Hypothesis::GetFieldInterps() const
445 {
446   return _ListFieldInterp;
447 }
448 //=============================================================================
449 //=============================================================================
450 // Liens avec les autres structures
451 //=============================================================================
452 //=============================================================================
453 void HOMARD_Hypothesis::SetCaseCreation( const char* NomCasCreation )
454 {
455   _NomCasCreation = std::string( NomCasCreation );
456 }
457 //=============================================================================
458 std::string HOMARD_Hypothesis::GetCaseCreation() const
459 {
460   return _NomCasCreation;
461 }
462 //=============================================================================
463 void HOMARD_Hypothesis::LinkIteration( const char* NomIteration )
464 {
465   _ListIter.push_back( std::string( NomIteration ) );
466 }
467 //=============================================================================
468 void HOMARD_Hypothesis::UnLinkIteration( const char* NomIteration )
469 {
470   std::list<std::string>::iterator it = find( _ListIter.begin(), _ListIter.end(), NomIteration ) ;
471   if ( it != _ListIter.end() )
472   {
473     MESSAGE ("Dans UnLinkIteration pour " << NomIteration) ;
474     it = _ListIter.erase( it ) ;
475   }
476 }
477 //=============================================================================
478 void HOMARD_Hypothesis::UnLinkIterations()
479 {
480   _ListIter.clear();
481 }
482 //=============================================================================
483 const std::list<std::string>& HOMARD_Hypothesis::GetIterations() const
484 {
485   return _ListIter;
486 }
487 //=============================================================================
488 void HOMARD_Hypothesis::AddZone( const char* NomZone, int TypeUse )
489 {
490   MESSAGE ("Dans AddZone pour " << NomZone << " et TypeUse = " << TypeUse) ;
491 // On commence par supprimer la zone au cas ou elle aurait deja ete inseree
492 // Cela peut se produire dans un schema YACS quand on repasse plusieurs fois par la
493 // definition de l'hypothese
494   SupprZone( NomZone ) ;
495 // Insertion veritable
496 // . Nom de la zone
497   _ListZone.push_back( std::string( NomZone ) );
498 // . Usage de la zone
499   std::stringstream saux1 ;
500   saux1 << TypeUse ;
501   _ListZone.push_back( saux1.str() );
502 }
503 //=============================================================================
504 void HOMARD_Hypothesis::SupprZone( const char* NomZone )
505 {
506   MESSAGE ("Dans SupprZone pour " << NomZone) ;
507   std::list<std::string>::iterator it = find( _ListZone.begin(), _ListZone.end(), NomZone );
508 // Attention a supprimer le nom de zone et le type d'usage
509   if ( it != _ListZone.end() )
510   {
511     it = _ListZone.erase( it );
512     it = _ListZone.erase( it );
513   }
514 }
515 //=============================================================================
516 void HOMARD_Hypothesis::SupprZones()
517 {
518   _ListZone.clear();
519 }
520 //=============================================================================
521 const std::list<std::string>& HOMARD_Hypothesis::GetZones() const
522 {
523   return _ListZone;
524 }