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 MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
125 if ( oldrep == NomDir ) { return ; }
126 // B. Changement/creation du repertoire
127 codret = myHomardCas->SetDirName( NomDir );
130 SALOME::ExceptionStruct es;
131 es.type = SALOME::BAD_PARAM;
133 if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
134 else { text = "The directory for the case cannot be reached." ; }
135 es.text = CORBA::string_dup(text.c_str());
136 throw SALOME::SALOME_Exception(es);
138 // C. En cas de reprise, deplacement du point de depart
139 if ( GetState() != 0 )
141 MESSAGE ( "etat : " << GetState() ) ;
142 // C.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
143 HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
144 char* DirNameIter = Iter->GetDirNameLoc() ;
145 MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
146 // C.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
147 char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
148 MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
149 // C.3. Creation du futur repertoire local pour l'iteration de depart
150 std::string nomDirIterTotal ;
151 nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
152 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
154 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
155 SALOME::ExceptionStruct es;
156 es.type = SALOME::BAD_PARAM;
157 std::string text = "The directory for the starting iteration cannot be created." ;
158 es.text = CORBA::string_dup(text.c_str());
159 throw SALOME::SALOME_Exception(es);
161 // C.4. Deplacement du contenu du repertoire
162 std::string oldnomDirIterTotal ;
163 oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
164 std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
165 codret = system(commande.c_str()) ;
168 SALOME::ExceptionStruct es;
169 es.type = SALOME::BAD_PARAM;
170 std::string text = "The starting point for the case cannot be moved into the new directory." ;
171 es.text = CORBA::string_dup(text.c_str());
172 throw SALOME::SALOME_Exception(es);
174 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
175 codret = system(commande.c_str()) ;
178 SALOME::ExceptionStruct es;
179 es.type = SALOME::BAD_PARAM;
180 std::string text = "The starting point for the case cannot be deleted." ;
181 es.text = CORBA::string_dup(text.c_str());
182 throw SALOME::SALOME_Exception(es);
184 // C.5. Memorisation du nom du repertoire de l'iteration
185 Iter->SetDirNameLoc(nomDirIter) ;
189 //=============================================================================
190 char* HOMARD_Cas_i::GetDirName()
192 ASSERT( myHomardCas );
193 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
195 //=============================================================================
196 CORBA::Long HOMARD_Cas_i::GetState()
198 ASSERT( myHomardCas );
199 // Nom de l'iteration initiale
200 char* Iter0Name = GetIter0Name() ;
201 HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
202 int state = Iter->GetNumber() ;
205 //=============================================================================
206 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
208 ASSERT( myHomardCas );
209 return myHomardCas->GetNumberofIter();
211 //=============================================================================
212 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
214 ASSERT( myHomardCas );
215 myHomardCas->SetConfType( ConfType );
217 //=============================================================================
218 CORBA::Long HOMARD_Cas_i::GetConfType()
220 ASSERT( myHomardCas );
221 return myHomardCas->GetConfType();
223 //=============================================================================
224 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
226 ASSERT( myHomardCas );
227 std::vector<double> VExtrema;
228 ASSERT( LesExtrema.length() == 10 );
229 VExtrema.resize( LesExtrema.length() );
230 for ( int i = 0; i < LesExtrema.length(); i++ )
232 VExtrema[i] = LesExtrema[i];
234 myHomardCas->SetBoundingBox( VExtrema );
236 //=============================================================================
237 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
239 ASSERT(myHomardCas );
240 HOMARD::extrema_var aResult = new HOMARD::extrema();
241 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
242 ASSERT( LesExtremes.size() == 10 );
243 aResult->length( 10 );
244 for ( int i = 0; i < LesExtremes.size(); i++ )
246 aResult[i] = LesExtremes[i];
248 return aResult._retn();
250 //=============================================================================
251 void HOMARD_Cas_i::AddGroup( const char* Group)
253 ASSERT( myHomardCas );
254 myHomardCas->AddGroup( Group );
256 //=============================================================================
257 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
259 ASSERT( myHomardCas );
260 std::list<std::string> ListString ;
261 for ( int i = 0; i < ListGroup.length(); i++ )
263 ListString.push_back(std::string(ListGroup[i]));
265 myHomardCas->SetGroups( ListString );
267 //=============================================================================
268 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
270 ASSERT(myHomardCas );
271 const std::list<std::string>& ListString = myHomardCas->GetGroups();
272 HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
273 aResult->length( ListString.size() );
274 std::list<std::string>::const_iterator it;
276 for ( it = ListString.begin(); it != ListString.end(); it++ )
278 aResult[i++] = CORBA::string_dup( (*it).c_str() );
280 return aResult._retn();
282 //=============================================================================
283 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
285 MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
286 ASSERT( myHomardCas );
287 // A. La liste des frontiere+groupes
288 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
289 std::list<std::string>::const_iterator it;
291 // B.1. La frontiere est-elle deja enregistree pour ce cas ?
292 bool existe = false ;
293 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
295 // MESSAGE (".. Frontiere : "<< *it );
296 if ( *it == BoundaryName ) { existe = true ; }
299 // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
302 char* CaseName = GetName() ;
303 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
304 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
306 // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
307 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
309 std::string boun = *it ;
311 // MESSAGE (".. Group : "<< *it );
313 { INFOS ("Le groupe " << Group << " est deja associe a la frontiere " << boun) ;
314 SALOME::ExceptionStruct es;
315 es.type = SALOME::BAD_PARAM;
316 es.text = "Invalid AddBoundaryGroup";
317 throw SALOME::SALOME_Exception(es);
321 // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
322 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
324 //=============================================================================
325 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
327 MESSAGE ("GetBoundaryGroup");
328 ASSERT(myHomardCas );
329 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
330 HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
331 aResult->length( ListBoundaryGroup.size() );
332 std::list<std::string>::const_iterator it;
334 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
336 aResult[i++] = CORBA::string_dup( (*it).c_str() );
338 return aResult._retn();
340 //=============================================================================
341 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
343 MESSAGE ("SetPyram, Pyram = " << Pyram );
344 ASSERT( myHomardCas );
345 myHomardCas->SetPyram( Pyram );
347 //=============================================================================
348 CORBA::Long HOMARD_Cas_i::GetPyram()
350 MESSAGE ("GetPyram");
351 ASSERT( myHomardCas );
352 return myHomardCas->GetPyram();
354 //=============================================================================
355 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
357 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
358 ASSERT( myHomardCas );
360 // Nom de l'iteration
361 char* IterName = GetIter0Name() ;
362 CORBA::Long etatMenage = -1 ;
363 CORBA::Long modeHOMARD = 7 ;
364 CORBA::Long Option1 = 1 ;
365 CORBA::Long Option2 = 1 ;
366 if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
367 if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
368 if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
369 if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
370 if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
371 CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
372 MESSAGE ( "MeshInfo : codret = " << codret );
375 //=============================================================================
376 //=============================================================================
377 // Liens avec les autres structures
378 //=============================================================================
379 //=============================================================================
380 char* HOMARD_Cas_i::GetIter0Name()
382 ASSERT( myHomardCas );
383 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
385 //=============================================================================
386 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
388 // Nom de l'iteration initiale
389 char* Iter0Name = GetIter0Name() ;
390 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
391 return _gen_i->GetIteration(Iter0Name) ;
393 //=============================================================================
394 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
396 // Nom de l'iteration parent
397 char* NomIterParent = GetIter0Name() ;
398 MESSAGE ( "NextIteration : IterName = " << IterName );
399 MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
400 return _gen_i->CreateIteration(IterName, NomIterParent) ;
402 //=============================================================================
403 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
405 HOMARD::HOMARD_Iteration_ptr Iter ;
406 HOMARD::listeIterFilles_var ListeIterFilles ;
408 // Iteration initiale du cas
409 IterName = GetIter0Name() ;
410 // On va explorer la descendance de cette iteration initiale
411 // jusqu'a trouver celle qui n'a pas de filles
412 int nbiterfilles = 1 ;
413 while ( nbiterfilles == 1 )
415 // L'iteration associee
416 // MESSAGE ( ".. IterName = " << IterName );
417 Iter = _gen_i->GetIteration(IterName) ;
418 // Les filles de cette iteration
419 ListeIterFilles = Iter->GetIterations() ;
420 nbiterfilles = ListeIterFilles->length() ;
421 // MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
422 // S'il y a au moins 2 filles, arret : on ne sait pas faire
423 VERIFICATION( nbiterfilles <= 1 ) ;
424 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
425 if ( nbiterfilles == 1 )
426 { IterName = ListeIterFilles[0] ; }
431 //=============================================================================
432 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
434 ASSERT( myHomardCas );
435 myHomardCas->AddIteration( NomIteration );
437 //=============================================================================
438 //=============================================================================
440 //=============================================================================
441 //=============================================================================
442 //=============================================================================
443 // Creation d'un schema YACS
444 // YACSName : nom du schema
445 // ScriptFile : nom du fichier contenant le script de lancement du calcul
446 // DirName : le repertoire de lancement des calculs du schéma
447 // MeshFile : nom du fichier contenant le maillage pour le premier calcul
448 //=============================================================================
449 HOMARD::HOMARD_YACS_ptr HOMARD_Cas_i::CreateYACSSchema( const char* YACSName, const char* ScriptFile, const char* DirName, const char* MeshFile )
452 const char* CaseName = GetName() ;
453 MESSAGE ( "CreateYACSSchema : Schema YACS pour le cas " << YACSName);
454 MESSAGE ( "nomCas : " << CaseName);
455 MESSAGE ( "ScriptFile : " << ScriptFile);
456 MESSAGE ( "DirName : " << DirName);
457 MESSAGE ( "MeshFile : " << MeshFile);
458 return _gen_i->CreateYACSSchema(YACSName, CaseName, ScriptFile, DirName, MeshFile) ;