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