1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
26 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
29 #include "HOMARD_Cas_i.hxx"
30 #include "HOMARD_Gen_i.hxx"
31 #include "HOMARD_Cas.hxx"
32 #include "HOMARD_DriverTools.hxx"
35 #include "utilities.h"
43 //=============================================================================
45 * standard constructor
47 //=============================================================================
48 HOMARD_Cas_i::HOMARD_Cas_i()
50 MESSAGE( "Default constructor, not for use" );
54 //=============================================================================
56 * standard constructor
58 //=============================================================================
59 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
60 HOMARD::HOMARD_Gen_var engine )
62 MESSAGE( "HOMARD_Cas_i" );
65 myHomardCas = new ::HOMARD_Cas();
66 ASSERT( myHomardCas );
69 //=============================================================================
73 //=============================================================================
74 HOMARD_Cas_i::~HOMARD_Cas_i()
77 //=============================================================================
78 //=============================================================================
80 //=============================================================================
81 //=============================================================================
82 void HOMARD_Cas_i::SetName( const char* Name )
84 ASSERT( myHomardCas );
85 myHomardCas->SetName( Name );
87 //=============================================================================
88 char* HOMARD_Cas_i::GetName()
90 ASSERT( myHomardCas );
91 return CORBA::string_dup( myHomardCas->GetName().c_str() );
93 //=============================================================================
94 CORBA::Long HOMARD_Cas_i::Delete( CORBA::Long Option )
96 ASSERT( myHomardCas );
97 char* CaseName = GetName() ;
98 MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
99 return _gen_i->DeleteCase(CaseName, Option) ;
101 //=============================================================================
102 char* HOMARD_Cas_i::GetDumpPython()
104 ASSERT( myHomardCas );
105 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
107 //=============================================================================
108 std::string HOMARD_Cas_i::Dump() const
110 return HOMARD::Dump( *myHomardCas );
112 //=============================================================================
113 bool HOMARD_Cas_i::Restore( const std::string& stream )
115 return HOMARD::Restore( *myHomardCas, stream );
117 //=============================================================================
118 //=============================================================================
120 //=============================================================================
121 //=============================================================================
122 void HOMARD_Cas_i::SetDirName( const char* NomDir )
124 ASSERT( myHomardCas );
126 // A. recuperation du nom ; on ne fait rien si c'est le meme
127 char* oldrep = GetDirName() ;
128 if ( strcmp(oldrep,NomDir) == 0 )
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 ) )
138 INFOS ( "Le repertoire " << NomDir << " est deja utilise pour le cas "<< casenamedir );
139 SALOME::ExceptionStruct es;
140 es.type = SALOME::BAD_PARAM;
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);
146 // C. Changement/creation du repertoire
147 codret = myHomardCas->SetDirName( NomDir );
150 SALOME::ExceptionStruct es;
151 es.type = SALOME::BAD_PARAM;
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);
158 // D. En cas de reprise, deplacement du point de depart
159 if ( GetState() != 0 )
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) ;
173 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
175 if (_mkdir(nomDirIterTotal.c_str()) != 0)
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);
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()) ;
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);
198 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
199 codret = system(commande.c_str()) ;
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);
208 // D.5. Memorisation du nom du repertoire de l'iteration
209 Iter->SetDirNameLoc(nomDirIter) ;
213 //=============================================================================
214 char* HOMARD_Cas_i::GetDirName()
216 ASSERT( myHomardCas );
217 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
219 //=============================================================================
220 CORBA::Long HOMARD_Cas_i::GetState()
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() ;
229 //=============================================================================
230 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
232 ASSERT( myHomardCas );
233 return myHomardCas->GetNumberofIter();
235 //=============================================================================
236 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
238 ASSERT( myHomardCas );
239 myHomardCas->SetConfType( ConfType );
241 //=============================================================================
242 CORBA::Long HOMARD_Cas_i::GetConfType()
244 ASSERT( myHomardCas );
245 return myHomardCas->GetConfType();
247 //=============================================================================
248 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
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++ )
256 VExtrema[i] = LesExtrema[i];
258 myHomardCas->SetBoundingBox( VExtrema );
260 //=============================================================================
261 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
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++ )
270 aResult[i] = LesExtremes[i];
272 return aResult._retn();
274 //=============================================================================
275 void HOMARD_Cas_i::AddGroup( const char* Group)
277 ASSERT( myHomardCas );
278 myHomardCas->AddGroup( Group );
280 //=============================================================================
281 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
283 ASSERT( myHomardCas );
284 std::list<std::string> ListString ;
285 for ( int i = 0; i < ListGroup.length(); i++ )
287 ListString.push_back(std::string(ListGroup[i]));
289 myHomardCas->SetGroups( ListString );
291 //=============================================================================
292 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
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;
300 for ( it = ListString.begin(); it != ListString.end(); it++ )
302 aResult[i++] = CORBA::string_dup( (*it).c_str() );
304 return aResult._retn();
306 //=============================================================================
307 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
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;
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++ )
319 // MESSAGE (".. Frontiere : "<< *it );
320 if ( *it == BoundaryName ) { existe = true ; }
323 // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
326 char* CaseName = GetName() ;
327 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
328 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
330 // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
331 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
333 std::string boun = *it ;
335 // MESSAGE (".. Group : "<< *it );
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);
345 // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
346 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
348 //=============================================================================
349 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
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;
358 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
360 aResult[i++] = CORBA::string_dup( (*it).c_str() );
362 return aResult._retn();
364 //=============================================================================
365 void HOMARD_Cas_i::SupprBoundaryGroup()
367 MESSAGE ("SupprBoundaryGroup");
368 ASSERT(myHomardCas );
369 myHomardCas->SupprBoundaryGroup();
371 //=============================================================================
372 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
374 MESSAGE ("SetPyram, Pyram = " << Pyram );
375 ASSERT( myHomardCas );
376 myHomardCas->SetPyram( Pyram );
378 //=============================================================================
379 CORBA::Long HOMARD_Cas_i::GetPyram()
381 MESSAGE ("GetPyram");
382 ASSERT( myHomardCas );
383 return myHomardCas->GetPyram();
385 //=============================================================================
386 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
388 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
389 ASSERT( myHomardCas );
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 );
406 //=============================================================================
407 //=============================================================================
408 // Liens avec les autres structures
409 //=============================================================================
410 //=============================================================================
411 char* HOMARD_Cas_i::GetIter0Name()
413 ASSERT( myHomardCas );
414 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
416 //=============================================================================
417 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
419 // Nom de l'iteration initiale
420 char* Iter0Name = GetIter0Name() ;
421 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
422 return _gen_i->GetIteration(Iter0Name) ;
424 //=============================================================================
425 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
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) ;
433 //=============================================================================
434 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
436 HOMARD::HOMARD_Iteration_ptr Iter ;
437 HOMARD::listeIterFilles_var ListeIterFilles ;
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 )
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] ; }
462 //=============================================================================
463 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
465 ASSERT( myHomardCas );
466 myHomardCas->AddIteration( NomIteration );
468 //=============================================================================
469 //=============================================================================
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 )
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) ;