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