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"
34 #include "utilities.h"
38 //=============================================================================
40 * standard constructor
42 //=============================================================================
43 HOMARD_Cas_i::HOMARD_Cas_i()
45 MESSAGE( "Default constructor, not for use" );
49 //=============================================================================
51 * standard constructor
53 //=============================================================================
54 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
55 HOMARD::HOMARD_Gen_var engine )
57 MESSAGE( "HOMARD_Cas_i" );
60 myHomardCas = new ::HOMARD_Cas();
61 ASSERT( myHomardCas );
64 //=============================================================================
68 //=============================================================================
69 HOMARD_Cas_i::~HOMARD_Cas_i()
72 //=============================================================================
73 //=============================================================================
75 //=============================================================================
76 //=============================================================================
77 void HOMARD_Cas_i::SetName( const char* Name )
79 ASSERT( myHomardCas );
80 myHomardCas->SetName( Name );
82 //=============================================================================
83 char* HOMARD_Cas_i::GetName()
85 ASSERT( myHomardCas );
86 return CORBA::string_dup( myHomardCas->GetName().c_str() );
88 //=============================================================================
89 CORBA::Long HOMARD_Cas_i::Delete( CORBA::Long Option )
91 ASSERT( myHomardCas );
92 char* CaseName = GetName() ;
93 MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
94 return _gen_i->DeleteCase(CaseName, Option) ;
96 //=============================================================================
97 char* HOMARD_Cas_i::GetDumpPython()
99 ASSERT( myHomardCas );
100 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
102 //=============================================================================
103 std::string HOMARD_Cas_i::Dump() const
105 return HOMARD::Dump( *myHomardCas );
107 //=============================================================================
108 bool HOMARD_Cas_i::Restore( const std::string& stream )
110 return HOMARD::Restore( *myHomardCas, stream );
112 //=============================================================================
113 //=============================================================================
115 //=============================================================================
116 //=============================================================================
117 void HOMARD_Cas_i::SetDirName( const char* NomDir )
119 ASSERT( myHomardCas );
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 );
129 SALOME::ExceptionStruct es;
130 es.type = SALOME::BAD_PARAM;
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);
137 // C. En cas de reprise, deplacement du point de depart
138 if ( GetState() != 0 )
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)
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);
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()) ;
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);
173 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
174 codret = system(commande.c_str()) ;
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);
183 // C.5. Memorisation du nom du repertoire de l'iteration
184 Iter->SetDirNameLoc(nomDirIter) ;
188 //=============================================================================
189 char* HOMARD_Cas_i::GetDirName()
191 ASSERT( myHomardCas );
192 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
194 //=============================================================================
195 CORBA::Long HOMARD_Cas_i::GetState()
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() ;
204 //=============================================================================
205 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
207 ASSERT( myHomardCas );
208 return myHomardCas->GetNumberofIter();
210 //=============================================================================
211 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
213 ASSERT( myHomardCas );
214 myHomardCas->SetConfType( ConfType );
216 //=============================================================================
217 CORBA::Long HOMARD_Cas_i::GetConfType()
219 ASSERT( myHomardCas );
220 return myHomardCas->GetConfType();
222 //=============================================================================
223 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
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++ )
231 VExtrema[i] = LesExtrema[i];
233 myHomardCas->SetBoundingBox( VExtrema );
235 //=============================================================================
236 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
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++ )
245 aResult[i] = LesExtremes[i];
247 return aResult._retn();
249 //=============================================================================
250 void HOMARD_Cas_i::AddGroup( const char* Group)
252 ASSERT( myHomardCas );
253 myHomardCas->AddGroup( Group );
255 //=============================================================================
256 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
258 ASSERT( myHomardCas );
259 std::list<std::string> ListString ;
260 for ( int i = 0; i < ListGroup.length(); i++ )
262 ListString.push_back(std::string(ListGroup[i]));
264 myHomardCas->SetGroups( ListString );
266 //=============================================================================
267 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
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;
275 for ( it = ListString.begin(); it != ListString.end(); it++ )
277 aResult[i++] = CORBA::string_dup( (*it).c_str() );
279 return aResult._retn();
281 //=============================================================================
282 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
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;
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++ )
294 // MESSAGE (".. Frontiere : "<< *it );
295 if ( *it == BoundaryName ) { existe = true ; }
298 // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
301 char* CaseName = GetName() ;
302 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
303 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
305 // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
306 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
308 std::string boun = *it ;
310 // MESSAGE (".. Group : "<< *it );
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);
320 // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
321 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
323 //=============================================================================
324 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
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;
333 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
335 aResult[i++] = CORBA::string_dup( (*it).c_str() );
337 return aResult._retn();
339 //=============================================================================
340 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
342 MESSAGE ("SetPyram, Pyram = " << Pyram );
343 ASSERT( myHomardCas );
344 myHomardCas->SetPyram( Pyram );
346 //=============================================================================
347 CORBA::Long HOMARD_Cas_i::GetPyram()
349 MESSAGE ("GetPyram");
350 ASSERT( myHomardCas );
351 return myHomardCas->GetPyram();
353 //=============================================================================
354 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
356 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
357 ASSERT( myHomardCas );
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 );
374 //=============================================================================
375 //=============================================================================
376 // Liens avec les autres structures
377 //=============================================================================
378 //=============================================================================
379 char* HOMARD_Cas_i::GetIter0Name()
381 ASSERT( myHomardCas );
382 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
384 //=============================================================================
385 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
387 // Nom de l'iteration initiale
388 char* Iter0Name = GetIter0Name() ;
389 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
390 return _gen_i->GetIteration(Iter0Name) ;
392 //=============================================================================
393 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
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) ;
401 //=============================================================================
402 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
404 HOMARD::HOMARD_Iteration_ptr Iter ;
405 HOMARD::listeIterFilles_var ListeIterFilles ;
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 )
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] ; }
430 //=============================================================================
431 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
433 ASSERT( myHomardCas );
434 myHomardCas->AddIteration( NomIteration );
436 //=============================================================================
437 //=============================================================================
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 )
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) ;