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"
39 //=============================================================================
41 * standard constructor
43 //=============================================================================
44 HOMARD_Cas_i::HOMARD_Cas_i()
46 MESSAGE( "Default constructor, not for use" );
50 //=============================================================================
52 * standard constructor
54 //=============================================================================
55 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
56 HOMARD::HOMARD_Gen_var engine )
58 MESSAGE( "HOMARD_Cas_i" );
61 myHomardCas = new ::HOMARD_Cas();
62 ASSERT( myHomardCas );
65 //=============================================================================
69 //=============================================================================
70 HOMARD_Cas_i::~HOMARD_Cas_i()
73 //=============================================================================
74 //=============================================================================
76 //=============================================================================
77 //=============================================================================
78 void HOMARD_Cas_i::SetName( const char* Name )
80 ASSERT( myHomardCas );
81 myHomardCas->SetName( Name );
83 //=============================================================================
84 char* HOMARD_Cas_i::GetName()
86 ASSERT( myHomardCas );
87 return CORBA::string_dup( myHomardCas->GetName().c_str() );
89 //=============================================================================
90 CORBA::Long HOMARD_Cas_i::Delete( CORBA::Long Option )
92 ASSERT( myHomardCas );
93 char* CaseName = GetName() ;
94 MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
95 return _gen_i->DeleteCase(CaseName, Option) ;
97 //=============================================================================
98 char* HOMARD_Cas_i::GetDumpPython()
100 ASSERT( myHomardCas );
101 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
103 //=============================================================================
104 std::string HOMARD_Cas_i::Dump() const
106 return HOMARD::Dump( *myHomardCas );
108 //=============================================================================
109 bool HOMARD_Cas_i::Restore( const std::string& stream )
111 return HOMARD::Restore( *myHomardCas, stream );
113 //=============================================================================
114 //=============================================================================
116 //=============================================================================
117 //=============================================================================
118 void HOMARD_Cas_i::SetDirName( const char* NomDir )
120 ASSERT( myHomardCas );
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 )
130 INFOS ( "Le repertoire " << NomDir << " est deja utilise pour le cas "<< casename );
131 SALOME::ExceptionStruct es;
132 es.type = SALOME::BAD_PARAM;
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);
138 // C. Changement/creation du repertoire
139 codret = myHomardCas->SetDirName( NomDir );
142 SALOME::ExceptionStruct es;
143 es.type = SALOME::BAD_PARAM;
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);
150 // D. En cas de reprise, deplacement du point de depart
151 if ( GetState() != 0 )
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)
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);
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()) ;
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);
186 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
187 codret = system(commande.c_str()) ;
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);
196 // D.5. Memorisation du nom du repertoire de l'iteration
197 Iter->SetDirNameLoc(nomDirIter) ;
201 //=============================================================================
202 char* HOMARD_Cas_i::GetDirName()
204 ASSERT( myHomardCas );
205 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
207 //=============================================================================
208 CORBA::Long HOMARD_Cas_i::GetState()
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() ;
217 //=============================================================================
218 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
220 ASSERT( myHomardCas );
221 return myHomardCas->GetNumberofIter();
223 //=============================================================================
224 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
226 ASSERT( myHomardCas );
227 myHomardCas->SetConfType( ConfType );
229 //=============================================================================
230 CORBA::Long HOMARD_Cas_i::GetConfType()
232 ASSERT( myHomardCas );
233 return myHomardCas->GetConfType();
235 //=============================================================================
236 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
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++ )
244 VExtrema[i] = LesExtrema[i];
246 myHomardCas->SetBoundingBox( VExtrema );
248 //=============================================================================
249 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
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++ )
258 aResult[i] = LesExtremes[i];
260 return aResult._retn();
262 //=============================================================================
263 void HOMARD_Cas_i::AddGroup( const char* Group)
265 ASSERT( myHomardCas );
266 myHomardCas->AddGroup( Group );
268 //=============================================================================
269 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
271 ASSERT( myHomardCas );
272 std::list<std::string> ListString ;
273 for ( int i = 0; i < ListGroup.length(); i++ )
275 ListString.push_back(std::string(ListGroup[i]));
277 myHomardCas->SetGroups( ListString );
279 //=============================================================================
280 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
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;
288 for ( it = ListString.begin(); it != ListString.end(); it++ )
290 aResult[i++] = CORBA::string_dup( (*it).c_str() );
292 return aResult._retn();
294 //=============================================================================
295 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
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;
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++ )
307 // MESSAGE (".. Frontiere : "<< *it );
308 if ( *it == BoundaryName ) { existe = true ; }
311 // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
314 char* CaseName = GetName() ;
315 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
316 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
318 // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
319 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
321 std::string boun = *it ;
323 // MESSAGE (".. Group : "<< *it );
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);
333 // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
334 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
336 //=============================================================================
337 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
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;
346 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
348 aResult[i++] = CORBA::string_dup( (*it).c_str() );
350 return aResult._retn();
352 //=============================================================================
353 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
355 MESSAGE ("SetPyram, Pyram = " << Pyram );
356 ASSERT( myHomardCas );
357 myHomardCas->SetPyram( Pyram );
359 //=============================================================================
360 CORBA::Long HOMARD_Cas_i::GetPyram()
362 MESSAGE ("GetPyram");
363 ASSERT( myHomardCas );
364 return myHomardCas->GetPyram();
366 //=============================================================================
367 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
369 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
370 ASSERT( myHomardCas );
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 );
387 //=============================================================================
388 //=============================================================================
389 // Liens avec les autres structures
390 //=============================================================================
391 //=============================================================================
392 char* HOMARD_Cas_i::GetIter0Name()
394 ASSERT( myHomardCas );
395 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
397 //=============================================================================
398 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
400 // Nom de l'iteration initiale
401 char* Iter0Name = GetIter0Name() ;
402 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
403 return _gen_i->GetIteration(Iter0Name) ;
405 //=============================================================================
406 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
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) ;
414 //=============================================================================
415 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
417 HOMARD::HOMARD_Iteration_ptr Iter ;
418 HOMARD::listeIterFilles_var ListeIterFilles ;
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 )
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] ; }
443 //=============================================================================
444 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
446 ASSERT( myHomardCas );
447 myHomardCas->AddIteration( NomIteration );
449 //=============================================================================
450 //=============================================================================
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 )
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) ;