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