Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPT / HOMARD_Iteration.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_Iteration.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_Iteration.hxx"
35 #include "HOMARD.hxx"
36 #include "utilities.h"
37
38 //=============================================================================
39 /*!
40  *  default constructor:
41  */
42 //=============================================================================
43 HOMARD_Iteration::HOMARD_Iteration():
44   _Name( "" ), _Etat( 0 ),
45  _NumIter( -1 ),
46   _NomMesh( "" ), _MeshFile( "" ),
47   _FieldFile( "" ), _TimeStep( -1 ), _Rank( -1 ),
48   _LogFile( "" ),
49   _IterParent( "" ),
50   _NomHypo( "" ), _NomCas( "" ), _NomDir( "" ),
51   _FileInfo( "" ),
52  _MessInfo( 1 )
53 {
54   MESSAGE("HOMARD_Iteration");
55 }
56 //=============================================================================
57 /*!
58  *
59  */
60 //=============================================================================
61 HOMARD_Iteration::~HOMARD_Iteration()
62 {
63   MESSAGE("~HOMARD_Iteration");
64 }
65 //=============================================================================
66 //=============================================================================
67 // Generalites
68 //=============================================================================
69 //=============================================================================
70 void HOMARD_Iteration::SetName( const char* Name )
71 {
72   _Name = std::string( Name );
73 }
74 //=============================================================================
75 std::string HOMARD_Iteration::GetName() const
76 {
77   return _Name;
78 }
79 //=============================================================================
80 std::string HOMARD_Iteration::GetDumpPython() const
81 {
82   if (_IterParent == "") return std::string(" ") ;   // Pas de creation explicite de iteration 0";
83
84   MESSAGE (". Ecriture de l iteration " << _Name );
85   std::ostringstream aScript;
86   aScript << "\n# Creation of the iteration " << _Name << "\n";
87   if( _NumIter == 1 )
88   {
89        aScript << "\t" << _Name << " = " << _NomCas << ".NextIteration(\"" << _Name << "\")\n";
90   }
91    else
92   {
93        aScript << "\t" << _Name << " = " << _IterParent << ".NextIteration(\"" << _Name << "\")\n";
94   }
95 // L'hypothese (doit etre au debut)
96   aScript << "\t" << _Name << ".AssociateHypo(\"" << _NomHypo << "\")\n";
97 // Le nom du maillage produit
98 //   MESSAGE (".. maillage produit " << _NomMesh );
99   aScript << "\t" << _Name << ".SetMeshName(\"" << _NomMesh << "\")\n" ;
100 // Le fichier du maillage produit
101   aScript << "\t" << _Name << ".SetMeshFile(\"" << _MeshFile << "\")\n";
102 // Le fichier des champs
103   if ( _FieldFile != "" )
104   {
105     aScript << "\t" << _Name << ".SetFieldFile(\"" << _FieldFile << "\")\n";
106   }
107 // Si champ de pilotage, valeurs de pas de temps
108   MESSAGE (". champ de pilotage : _TimeStep = " << _TimeStep << ", _Rank : " << _Rank);
109   if ( _TimeStep != -1 )
110   {
111     if ( _TimeStep == -2 ) {
112       aScript << "\t" << _Name << ".SetTimeStepRankLast()\n";
113     }
114     else
115     {
116       if ( _TimeStep != -1 )
117       {
118         if ( _Rank == -1 )
119         {
120           aScript << "\t" << _Name << ".SetTimeStep( " << _TimeStep << " )\n";
121         }
122         else
123         {
124           aScript << "\t" << _Name << ".SetTimeStepRank( " << _TimeStep << ", " << _Rank << " )\n";
125         }
126       }
127     }
128   }
129 // Les instants d'interpolation
130   MESSAGE (". instants d'interpolation ");
131   std::list<std::string>::const_iterator it = _ListFieldInterpTSR.begin() ;
132   while(it != _ListFieldInterpTSR.end())
133   {
134     std::string FieldName = std::string((*it)) ;
135 //     MESSAGE ("... FieldName = "<< FieldName);
136     (*it++);
137     std::string TimeStepstr = std::string((*it)) ;
138 //     MESSAGE ("... TimeStepstr = "<< TimeStepstr);
139     (*it++);
140     std::string Rankstr = std::string((*it)) ;
141 //     MESSAGE ("... Rankstr = "<< Rankstr);
142     (*it++);
143     aScript << "\t" << _Name << ".SetFieldInterpTimeStepRank( \"" << FieldName << "\"" ;
144     aScript << ", " << TimeStepstr ;
145     aScript << ", " << Rankstr << " )\n" ;
146   }
147
148 // Compute
149   MESSAGE (". Compute ");
150   if ( _Etat == 2 ) { aScript << "\tcodret = "  <<_Name << ".Compute(1, 1)\n"; }
151   else              { aScript << "\t#codret = " <<_Name << ".Compute(1, 1)\n"; }
152 //   MESSAGE (". Fin de l ecriture de l iteration " << _Name );
153
154   return aScript.str();
155 }
156 //=============================================================================
157 //=============================================================================
158 // Caracteristiques
159 //=============================================================================
160 //=============================================================================
161 void HOMARD_Iteration::SetDirNameLoc( const char* NomDir )
162 {
163   _NomDir = std::string( NomDir );
164 }
165 //=============================================================================
166 std::string HOMARD_Iteration::GetDirNameLoc() const
167 {
168    return _NomDir;
169 }
170 //=============================================================================
171 void HOMARD_Iteration::SetNumber( int NumIter )
172 {
173   _NumIter = NumIter;
174 }
175 //=============================================================================
176 int HOMARD_Iteration::GetNumber() const
177 {
178   return _NumIter;
179 }
180 //=============================================================================
181 void HOMARD_Iteration::SetState( int etat )
182 {
183   _Etat = etat;
184 }
185 //=============================================================================
186 int HOMARD_Iteration::GetState() const
187 {
188   return _Etat;
189 }
190 //=============================================================================
191 void HOMARD_Iteration::SetMeshName( const char* NomMesh )
192 {
193   _NomMesh = std::string( NomMesh );
194 }
195 //=============================================================================
196 std::string HOMARD_Iteration::GetMeshName() const
197 {
198   return _NomMesh;
199 }
200 //=============================================================================
201 void HOMARD_Iteration::SetMeshFile( const char* MeshFile )
202 {
203   _MeshFile = std::string( MeshFile );
204 }
205 //=============================================================================
206 std::string HOMARD_Iteration::GetMeshFile() const
207 {
208   return _MeshFile;
209 }
210 //=============================================================================
211 void HOMARD_Iteration::SetFieldFile( const char* FieldFile )
212 {
213   _FieldFile = std::string( FieldFile );
214 }
215 //=============================================================================
216 std::string HOMARD_Iteration::GetFieldFile() const
217 {
218   return _FieldFile;
219 }
220 //=============================================================================
221 // Instants pour le champ de pilotage
222 //=============================================================================
223 void HOMARD_Iteration::SetTimeStep( int TimeStep )
224 {
225   _TimeStep = TimeStep;
226 }
227 //=============================================================================
228 void HOMARD_Iteration::SetTimeStepRank( int TimeStep, int Rank )
229 {
230   _TimeStep = TimeStep;
231   _Rank = Rank;
232 }
233 //=============================================================================
234 void HOMARD_Iteration::SetTimeStepRankLast()
235 {
236   _TimeStep = -2;
237 }
238 //=============================================================================
239 int HOMARD_Iteration::GetTimeStep() const
240 {
241   return _TimeStep;
242 }
243 //=============================================================================
244 int HOMARD_Iteration::GetRank() const
245 {
246   return _Rank;
247 }
248 //=============================================================================
249 // Instants pour un champ a interpoler
250 //=============================================================================
251 void HOMARD_Iteration::SetFieldInterpTimeStep( const char* FieldInterp, int TimeStep )
252 {
253   SetFieldInterpTimeStepRank( FieldInterp, TimeStep, TimeStep ) ;
254 }
255 //=============================================================================
256 void HOMARD_Iteration::SetFieldInterpTimeStepRank( const char* FieldInterp, int TimeStep, int Rank )
257 {
258   MESSAGE("Champ " << FieldInterp << ", hypothese " << _NomHypo )
259 // Verification de la presence du champ dans l'hypothese
260   std::list<std::string>::iterator it = find( _ListFieldInterp.begin(), _ListFieldInterp.end(), FieldInterp );
261   if ( it == _ListFieldInterp.end() )
262   {
263     INFOS("Champ " << FieldInterp << " ; hypothese " << _NomHypo )
264     VERIFICATION("Le champ est inconnu dans l'hypothese associee a cette iteration." == 0);
265   }
266
267 // . Nom du champ
268   _ListFieldInterpTSR.push_back( std::string( FieldInterp ) );
269 // . Pas de temps
270   std::stringstream saux1 ;
271   saux1 << TimeStep ;
272   _ListFieldInterpTSR.push_back( saux1.str() );
273 // . Numero d'ordre
274   std::stringstream saux2 ;
275   saux2 << Rank ;
276   _ListFieldInterpTSR.push_back( saux2.str() );
277 }
278 //=============================================================================
279 const std::list<std::string>& HOMARD_Iteration::GetFieldInterpsTimeStepRank() const
280 {
281   return _ListFieldInterpTSR;
282 }
283 //=============================================================================
284 void HOMARD_Iteration::SetFieldInterp( const char* FieldInterp )
285 {
286   _ListFieldInterp.push_back( std::string( FieldInterp ) );
287 }
288 //=============================================================================
289 const std::list<std::string>& HOMARD_Iteration::GetFieldInterps() const
290 {
291   return _ListFieldInterp;
292 }
293 //=============================================================================
294 void HOMARD_Iteration::SupprFieldInterps()
295 {
296   _ListFieldInterp.clear();
297 }
298 //=============================================================================
299 void HOMARD_Iteration::SetLogFile( const char* LogFile )
300 {
301   _LogFile = std::string( LogFile );
302 }
303 //=============================================================================
304 std::string HOMARD_Iteration::GetLogFile() const
305 {
306   return _LogFile;
307 }
308 //=============================================================================
309 void HOMARD_Iteration::SetFileInfo( const char* FileInfo )
310 {
311   _FileInfo = std::string( FileInfo );
312 }
313 //=============================================================================
314 std::string HOMARD_Iteration::GetFileInfo() const
315 {
316   return _FileInfo;
317 }
318 //=============================================================================
319 //=============================================================================
320 // Liens avec les autres iterations
321 //=============================================================================
322 //=============================================================================
323 void HOMARD_Iteration::LinkNextIteration( const char* NomIteration )
324 {
325   _mesIterFilles.push_back( std::string( NomIteration ) );
326 }
327 //=============================================================================
328 void HOMARD_Iteration::UnLinkNextIteration( const char* NomIteration )
329 {
330   std::list<std::string>::iterator it = find( _mesIterFilles.begin(), _mesIterFilles.end(), NomIteration ) ;
331   if ( it != _mesIterFilles.end() )
332   {
333     MESSAGE ("Dans UnLinkNextIteration pour " << NomIteration) ;
334     it = _mesIterFilles.erase( it ) ;
335   }
336 }
337 //=============================================================================
338 void HOMARD_Iteration::UnLinkNextIterations()
339 {
340   _mesIterFilles.clear();
341 }
342 //=============================================================================
343 const std::list<std::string>& HOMARD_Iteration::GetIterations() const
344 {
345   return _mesIterFilles;
346 }
347 //=============================================================================
348 void HOMARD_Iteration::SetIterParentName( const char* IterParent )
349 {
350   _IterParent = IterParent;
351 }
352 //=============================================================================
353 std::string HOMARD_Iteration::GetIterParentName() const
354 {
355   return _IterParent;
356 }
357 //=============================================================================
358 //=============================================================================
359 // Liens avec les autres structures
360 //=============================================================================
361 //=============================================================================
362 void HOMARD_Iteration::SetCaseName( const char* NomCas )
363 {
364   _NomCas = std::string( NomCas );
365 }
366 //=============================================================================
367 std::string HOMARD_Iteration::GetCaseName() const
368 {
369   return _NomCas;
370 }
371 //=============================================================================
372 void HOMARD_Iteration::SetHypoName( const char* NomHypo )
373 {
374   _NomHypo = std::string( NomHypo );
375 }
376 //=============================================================================
377 std::string HOMARD_Iteration::GetHypoName() const
378 {
379   return _NomHypo;
380 }
381 //=============================================================================
382 //=============================================================================
383 // Divers
384 //=============================================================================
385 //=============================================================================
386 void HOMARD_Iteration::SetInfoCompute( int MessInfo )
387 {
388   _MessInfo = MessInfo;
389 }
390 //=============================================================================
391 int HOMARD_Iteration::GetInfoCompute() const
392 {
393   return _MessInfo;
394 }