]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARD_I/HOMARD_Cas_i.cxx
Salome HOME
interpolation des champs
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
1 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Remarques :
20 // L'ordre de description des fonctions est le meme dans tous les fichiers
21 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
22 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
23 // 2. Les caracteristiques
24 // 3. Le lien avec les autres structures
25 //
26 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
27 //
28
29 #include "HOMARD_Cas_i.hxx"
30 #include "HOMARD_Gen_i.hxx"
31 #include "HOMARD_Cas.hxx"
32 #include "HOMARD_DriverTools.hxx"
33 #include "HOMARD.hxx"
34
35 #include "utilities.h"
36 #include <vector>
37 #include <sys/stat.h>
38
39 //=============================================================================
40 /*!
41  *  standard constructor
42  */
43 //=============================================================================
44 HOMARD_Cas_i::HOMARD_Cas_i()
45 {
46   MESSAGE( "Default constructor, not for use" );
47   ASSERT( 0 );
48 }
49
50 //=============================================================================
51 /*!
52  *  standard constructor
53  */
54 //=============================================================================
55 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
56                             HOMARD::HOMARD_Gen_var engine )
57 {
58   MESSAGE( "HOMARD_Cas_i" );
59   _gen_i = engine;
60   _orb = orb;
61   myHomardCas = new ::HOMARD_Cas();
62   ASSERT( myHomardCas );
63 }
64
65 //=============================================================================
66 /*!
67  *  standard destructor
68  */
69 //=============================================================================
70 HOMARD_Cas_i::~HOMARD_Cas_i()
71 {
72 }
73 //=============================================================================
74 //=============================================================================
75 // Generalites
76 //=============================================================================
77 //=============================================================================
78 void HOMARD_Cas_i::SetName( const char* Name )
79 {
80   ASSERT( myHomardCas );
81   myHomardCas->SetName( Name );
82 }
83 //=============================================================================
84 char* HOMARD_Cas_i::GetName()
85 {
86   ASSERT( myHomardCas );
87   return CORBA::string_dup( myHomardCas->GetName().c_str() );
88 }
89 //=============================================================================
90 CORBA::Long  HOMARD_Cas_i::Delete( CORBA::Long Option )
91 {
92   ASSERT( myHomardCas );
93   char* CaseName = GetName() ;
94   MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
95   return _gen_i->DeleteCase(CaseName, Option) ;
96 }
97 //=============================================================================
98 char* HOMARD_Cas_i::GetDumpPython()
99 {
100   ASSERT( myHomardCas );
101   return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
102 }
103 //=============================================================================
104 std::string HOMARD_Cas_i::Dump() const
105 {
106   return HOMARD::Dump( *myHomardCas );
107 }
108 //=============================================================================
109 bool HOMARD_Cas_i::Restore( const std::string& stream )
110 {
111   return HOMARD::Restore( *myHomardCas, stream );
112 }
113 //=============================================================================
114 //=============================================================================
115 // Caracteristiques
116 //=============================================================================
117 //=============================================================================
118 void HOMARD_Cas_i::SetDirName( const char* NomDir )
119 {
120   ASSERT( myHomardCas );
121   int codret ;
122   // A. recuperation du nom ; on ne fait rien si c'est le meme
123   char* oldrep = GetDirName() ;
124   MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
125   if ( oldrep == NomDir ) { return ; }
126   // B. Changement/creation du repertoire
127   codret = myHomardCas->SetDirName( NomDir );
128   if ( codret != 0 )
129   {
130     SALOME::ExceptionStruct es;
131     es.type = SALOME::BAD_PARAM;
132     std::string text ;
133     if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
134     else               { text = "The directory for the case cannot be reached." ; }
135     es.text = CORBA::string_dup(text.c_str());
136     throw SALOME::SALOME_Exception(es);
137   }
138   // C. En cas de reprise, deplacement du point de depart
139   if ( GetState() != 0 )
140   {
141     MESSAGE ( "etat : " << GetState() ) ;
142     // C.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
143     HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
144     char* DirNameIter = Iter->GetDirNameLoc() ;
145     MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
146     // C.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
147     char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
148     MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
149     // C.3. Creation du futur repertoire local pour l'iteration de depart
150     std::string nomDirIterTotal ;
151     nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
152     if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
153     {
154       MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
155       SALOME::ExceptionStruct es;
156       es.type = SALOME::BAD_PARAM;
157       std::string text = "The directory for the starting iteration cannot be created." ;
158       es.text = CORBA::string_dup(text.c_str());
159       throw SALOME::SALOME_Exception(es);
160     }
161     // C.4. Deplacement du contenu du repertoire
162     std::string oldnomDirIterTotal ;
163     oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
164     std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
165     codret = system(commande.c_str()) ;
166     if ( codret != 0 )
167     {
168       SALOME::ExceptionStruct es;
169       es.type = SALOME::BAD_PARAM;
170       std::string text = "The starting point for the case cannot be moved into the new directory." ;
171       es.text = CORBA::string_dup(text.c_str());
172       throw SALOME::SALOME_Exception(es);
173     }
174     commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
175     codret = system(commande.c_str()) ;
176     if ( codret != 0 )
177     {
178       SALOME::ExceptionStruct es;
179       es.type = SALOME::BAD_PARAM;
180       std::string text = "The starting point for the case cannot be deleted." ;
181       es.text = CORBA::string_dup(text.c_str());
182       throw SALOME::SALOME_Exception(es);
183     }
184     // C.5. Memorisation du nom du repertoire de l'iteration
185     Iter->SetDirNameLoc(nomDirIter) ;
186   }
187   return ;
188 }
189 //=============================================================================
190 char* HOMARD_Cas_i::GetDirName()
191 {
192   ASSERT( myHomardCas );
193   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
194 }
195 //=============================================================================
196 CORBA::Long HOMARD_Cas_i::GetState()
197 {
198   ASSERT( myHomardCas );
199 // Nom de l'iteration initiale
200   char* Iter0Name = GetIter0Name() ;
201   HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
202   int state = Iter->GetNumber() ;
203   return state ;
204 }
205 //=============================================================================
206 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
207 {
208   ASSERT( myHomardCas );
209   return myHomardCas->GetNumberofIter();
210 }
211 //=============================================================================
212 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
213 {
214   ASSERT( myHomardCas );
215   myHomardCas->SetConfType( ConfType );
216 }
217 //=============================================================================
218 CORBA::Long HOMARD_Cas_i::GetConfType()
219 {
220   ASSERT( myHomardCas );
221   return myHomardCas->GetConfType();
222 }
223 //=============================================================================
224 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
225 {
226   ASSERT( myHomardCas );
227   std::vector<double> VExtrema;
228   ASSERT( LesExtrema.length() == 10 );
229   VExtrema.resize( LesExtrema.length() );
230   for ( int i = 0; i < LesExtrema.length(); i++ )
231   {
232     VExtrema[i] = LesExtrema[i];
233   }
234   myHomardCas->SetBoundingBox( VExtrema );
235 }
236 //=============================================================================
237 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
238 {
239   ASSERT(myHomardCas );
240   HOMARD::extrema_var aResult = new HOMARD::extrema();
241   std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
242   ASSERT( LesExtremes.size() == 10 );
243   aResult->length( 10 );
244   for ( int i = 0; i < LesExtremes.size(); i++ )
245   {
246     aResult[i] = LesExtremes[i];
247   }
248   return aResult._retn();
249 }
250 //=============================================================================
251 void HOMARD_Cas_i::AddGroup( const char* Group)
252 {
253   ASSERT( myHomardCas );
254   myHomardCas->AddGroup( Group );
255 }
256 //=============================================================================
257 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
258 {
259   ASSERT( myHomardCas );
260   std::list<std::string> ListString ;
261   for ( int i = 0; i < ListGroup.length(); i++ )
262   {
263     ListString.push_back(std::string(ListGroup[i]));
264   }
265   myHomardCas->SetGroups( ListString );
266 }
267 //=============================================================================
268 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
269 {
270   ASSERT(myHomardCas );
271   const std::list<std::string>& ListString = myHomardCas->GetGroups();
272   HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
273   aResult->length( ListString.size() );
274   std::list<std::string>::const_iterator it;
275   int i = 0;
276   for ( it = ListString.begin(); it != ListString.end(); it++ )
277   {
278     aResult[i++] = CORBA::string_dup( (*it).c_str() );
279   }
280   return aResult._retn();
281 }
282 //=============================================================================
283 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
284 {
285   MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
286   ASSERT( myHomardCas );
287   // A. La liste des frontiere+groupes
288   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
289   std::list<std::string>::const_iterator it;
290   // B. La frontiere
291   // B.1. La frontiere est-elle deja enregistree pour ce cas ?
292   bool existe = false ;
293   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
294   {
295 //     MESSAGE ("..  Frontiere : "<< *it );
296     if ( *it == BoundaryName ) { existe = true ; }
297     it++ ;
298   }
299   // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
300   if ( !existe )
301   {
302     char* CaseName = GetName() ;
303     MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
304     _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
305   }
306   // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
307   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
308   {
309     std::string boun = *it ;
310     it++ ;
311 //     MESSAGE ("..  Group : "<< *it );
312     if ( *it == Group )
313     { INFOS ("Le groupe " << Group << " est deja associe a la frontiere " << boun) ;
314       SALOME::ExceptionStruct es;
315       es.type = SALOME::BAD_PARAM;
316       es.text = "Invalid AddBoundaryGroup";
317       throw SALOME::SALOME_Exception(es);
318       return ;
319     }
320   }
321   // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
322   myHomardCas->AddBoundaryGroup( BoundaryName, Group );
323 }
324 //=============================================================================
325 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
326 {
327   MESSAGE ("GetBoundaryGroup");
328   ASSERT(myHomardCas );
329   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
330   HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
331   aResult->length( ListBoundaryGroup.size() );
332   std::list<std::string>::const_iterator it;
333   int i = 0;
334   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
335   {
336     aResult[i++] = CORBA::string_dup( (*it).c_str() );
337   }
338   return aResult._retn();
339 }
340 //=============================================================================
341 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
342 {
343   MESSAGE ("SetPyram, Pyram = " << Pyram );
344   ASSERT( myHomardCas );
345   myHomardCas->SetPyram( Pyram );
346 }
347 //=============================================================================
348 CORBA::Long HOMARD_Cas_i::GetPyram()
349 {
350   MESSAGE ("GetPyram");
351   ASSERT( myHomardCas );
352   return myHomardCas->GetPyram();
353 }
354 //=============================================================================
355 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
356 {
357   MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
358   ASSERT( myHomardCas );
359 //
360 // Nom de l'iteration
361   char* IterName = GetIter0Name() ;
362   CORBA::Long etatMenage = -1 ;
363   CORBA::Long modeHOMARD = 7 ;
364   CORBA::Long Option1 = 1 ;
365   CORBA::Long Option2 = 1 ;
366   if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
367   if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
368   if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
369   if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
370   if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
371   CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
372   MESSAGE ( "MeshInfo : codret = " << codret );
373   return ;
374 }
375 //=============================================================================
376 //=============================================================================
377 // Liens avec les autres structures
378 //=============================================================================
379 //=============================================================================
380 char* HOMARD_Cas_i::GetIter0Name()
381 {
382   ASSERT( myHomardCas );
383   return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
384 }
385 //=============================================================================
386 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
387 {
388 // Nom de l'iteration initiale
389   char* Iter0Name = GetIter0Name() ;
390   MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
391   return _gen_i->GetIteration(Iter0Name) ;
392 }
393 //=============================================================================
394 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
395 {
396 // Nom de l'iteration parent
397   char* NomIterParent = GetIter0Name() ;
398   MESSAGE ( "NextIteration : IterName      = " << IterName );
399   MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
400   return _gen_i->CreateIteration(IterName, NomIterParent) ;
401 }
402 //=============================================================================
403 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
404 {
405   HOMARD::HOMARD_Iteration_ptr Iter ;
406   HOMARD::listeIterFilles_var ListeIterFilles ;
407   char* IterName ;
408 // Iteration initiale du cas
409   IterName = GetIter0Name() ;
410 // On va explorer la descendance de cette iteration initiale
411 // jusqu'a trouver celle qui n'a pas de filles
412   int nbiterfilles = 1 ;
413   while ( nbiterfilles == 1 )
414   {
415 // L'iteration associee
416 //     MESSAGE ( ".. IterName = " << IterName );
417     Iter = _gen_i->GetIteration(IterName) ;
418 // Les filles de cette iteration
419     ListeIterFilles = Iter->GetIterations() ;
420     nbiterfilles = ListeIterFilles->length() ;
421 //     MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
422 // S'il y a au moins 2 filles, arret : on ne sait pas faire
423     VERIFICATION( nbiterfilles <= 1 ) ;
424 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
425     if ( nbiterfilles == 1 )
426     { IterName = ListeIterFilles[0] ; }
427   }
428 //
429   return Iter ;
430 }
431 //=============================================================================
432 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
433 {
434   ASSERT( myHomardCas );
435   myHomardCas->AddIteration( NomIteration );
436 }
437 //=============================================================================
438 //=============================================================================
439 // YACS
440 //=============================================================================
441 //=============================================================================
442 //=============================================================================
443 // Creation d'un schema YACS
444 // YACSName : nom du schema
445 // ScriptFile : nom du fichier contenant le script de lancement du calcul
446 // DirName : le repertoire de lancement des calculs du schéma
447 // MeshFile : nom du fichier contenant le maillage pour le premier calcul
448 //=============================================================================
449 HOMARD::HOMARD_YACS_ptr HOMARD_Cas_i::CreateYACSSchema( const char* YACSName, const char* ScriptFile, const char* DirName, const char* MeshFile )
450 {
451 // Nom du cas
452   const char* CaseName = GetName() ;
453   MESSAGE ( "CreateYACSSchema : Schema YACS pour le cas " << YACSName);
454   MESSAGE ( "nomCas     : " << CaseName);
455   MESSAGE ( "ScriptFile : " << ScriptFile);
456   MESSAGE ( "DirName    : " << DirName);
457   MESSAGE ( "MeshFile   : " << MeshFile);
458   return _gen_i->CreateYACSSchema(YACSName, CaseName, ScriptFile, DirName, MeshFile) ;
459 }