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