1 // Copyright (C) 2011-2014 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, or (at your option) any later version.
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
21 // L'ordre de description des fonctions est le meme dans tous les fichiers
22 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
23 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
24 // 2. Les caracteristiques
25 // 3. Le lien avec les autres structures
27 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
30 #include "HOMARD_Cas_i.hxx"
31 #include "HOMARD_Gen_i.hxx"
32 #include "HOMARD_Cas.hxx"
33 #include "HOMARD_DriverTools.hxx"
36 #include "utilities.h"
44 //=============================================================================
46 * standard constructor
48 //=============================================================================
49 HOMARD_Cas_i::HOMARD_Cas_i()
51 MESSAGE( "Default constructor, not for use" );
55 //=============================================================================
57 * standard constructor
59 //=============================================================================
60 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
61 HOMARD::HOMARD_Gen_var engine )
63 MESSAGE( "HOMARD_Cas_i" );
66 myHomardCas = new ::HOMARD_Cas();
67 ASSERT( myHomardCas );
70 //=============================================================================
74 //=============================================================================
75 HOMARD_Cas_i::~HOMARD_Cas_i()
78 //=============================================================================
79 //=============================================================================
81 //=============================================================================
82 //=============================================================================
83 void HOMARD_Cas_i::SetName( const char* Name )
85 ASSERT( myHomardCas );
86 myHomardCas->SetName( Name );
88 //=============================================================================
89 char* HOMARD_Cas_i::GetName()
91 ASSERT( myHomardCas );
92 return CORBA::string_dup( myHomardCas->GetName().c_str() );
94 //=============================================================================
95 CORBA::Long HOMARD_Cas_i::Delete( CORBA::Long Option )
97 ASSERT( myHomardCas );
98 char* CaseName = GetName() ;
99 MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
100 return _gen_i->DeleteCase(CaseName, Option) ;
102 //=============================================================================
103 char* HOMARD_Cas_i::GetDumpPython()
105 ASSERT( myHomardCas );
106 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
108 //=============================================================================
109 std::string HOMARD_Cas_i::Dump() const
111 return HOMARD::Dump( *myHomardCas );
113 //=============================================================================
114 bool HOMARD_Cas_i::Restore( const std::string& stream )
116 return HOMARD::Restore( *myHomardCas, stream );
118 //=============================================================================
119 //=============================================================================
121 //=============================================================================
122 //=============================================================================
123 void HOMARD_Cas_i::SetDirName( const char* NomDir )
125 ASSERT( myHomardCas );
127 // A. recuperation du nom ; on ne fait rien si c'est le meme
128 char* oldrep = GetDirName() ;
129 if ( strcmp(oldrep,NomDir) == 0 )
133 MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
134 // B. controle de l'usage du repertoire
135 char* CaseName = GetName() ;
136 char* casenamedir = _gen_i->VerifieDir(NomDir) ;
137 if ( ( std::string(casenamedir).size() > 0 ) & ( strcmp(CaseName,casenamedir)!=0 ) )
139 INFOS ( "Le repertoire " << NomDir << " est deja utilise pour le cas "<< casenamedir );
140 SALOME::ExceptionStruct es;
141 es.type = SALOME::BAD_PARAM;
143 text = "The directory " + std::string(NomDir) + " is already used for the case " + std::string(casenamedir) ;
144 es.text = CORBA::string_dup(text.c_str());
145 throw SALOME::SALOME_Exception(es);
147 // C. Changement/creation du repertoire
148 codret = myHomardCas->SetDirName( NomDir );
151 SALOME::ExceptionStruct es;
152 es.type = SALOME::BAD_PARAM;
154 if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
155 else { text = "The directory for the case cannot be reached." ; }
156 es.text = CORBA::string_dup(text.c_str());
157 throw SALOME::SALOME_Exception(es);
159 // D. En cas de reprise, deplacement du point de depart
160 if ( GetState() != 0 )
162 MESSAGE ( "etat : " << GetState() ) ;
163 // D.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
164 HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
165 char* DirNameIter = Iter->GetDirNameLoc() ;
166 MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
167 // D.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
168 char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
169 MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
170 // D.3. Creation du futur repertoire local pour l'iteration de depart
171 std::string nomDirIterTotal ;
172 nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
174 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
176 if (_mkdir(nomDirIterTotal.c_str()) != 0)
179 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
180 SALOME::ExceptionStruct es;
181 es.type = SALOME::BAD_PARAM;
182 std::string text = "The directory for the starting iteration cannot be created." ;
183 es.text = CORBA::string_dup(text.c_str());
184 throw SALOME::SALOME_Exception(es);
186 // D.4. Deplacement du contenu du repertoire
187 std::string oldnomDirIterTotal ;
188 oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
189 std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
190 codret = system(commande.c_str()) ;
193 SALOME::ExceptionStruct es;
194 es.type = SALOME::BAD_PARAM;
195 std::string text = "The starting point for the case cannot be moved into the new directory." ;
196 es.text = CORBA::string_dup(text.c_str());
197 throw SALOME::SALOME_Exception(es);
199 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
200 codret = system(commande.c_str()) ;
203 SALOME::ExceptionStruct es;
204 es.type = SALOME::BAD_PARAM;
205 std::string text = "The starting point for the case cannot be deleted." ;
206 es.text = CORBA::string_dup(text.c_str());
207 throw SALOME::SALOME_Exception(es);
209 // D.5. Memorisation du nom du repertoire de l'iteration
210 Iter->SetDirNameLoc(nomDirIter) ;
214 //=============================================================================
215 char* HOMARD_Cas_i::GetDirName()
217 ASSERT( myHomardCas );
218 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
220 //=============================================================================
221 CORBA::Long HOMARD_Cas_i::GetState()
223 ASSERT( myHomardCas );
224 // Nom de l'iteration initiale
225 char* Iter0Name = GetIter0Name() ;
226 HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
227 int state = Iter->GetNumber() ;
230 //=============================================================================
231 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
233 ASSERT( myHomardCas );
234 return myHomardCas->GetNumberofIter();
236 //=============================================================================
237 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
239 ASSERT( myHomardCas );
240 // VERIFICATION( (ConfType>=1) && (ConfType<=4) );
241 myHomardCas->SetConfType( ConfType );
243 //=============================================================================
244 CORBA::Long HOMARD_Cas_i::GetConfType()
246 ASSERT( myHomardCas );
247 return myHomardCas->GetConfType();
249 //=============================================================================
250 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
252 ASSERT( myHomardCas );
253 std::vector<double> VExtrema;
254 ASSERT( LesExtrema.length() == 10 );
255 VExtrema.resize( LesExtrema.length() );
256 for ( int i = 0; i < LesExtrema.length(); i++ )
258 VExtrema[i] = LesExtrema[i];
260 myHomardCas->SetBoundingBox( VExtrema );
262 //=============================================================================
263 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
265 ASSERT(myHomardCas );
266 HOMARD::extrema_var aResult = new HOMARD::extrema();
267 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
268 ASSERT( LesExtremes.size() == 10 );
269 aResult->length( 10 );
270 for ( int i = 0; i < LesExtremes.size(); i++ )
272 aResult[i] = LesExtremes[i];
274 return aResult._retn();
276 //=============================================================================
277 void HOMARD_Cas_i::AddGroup( const char* Group)
279 ASSERT( myHomardCas );
280 myHomardCas->AddGroup( Group );
282 //=============================================================================
283 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
285 ASSERT( myHomardCas );
286 std::list<std::string> ListString ;
287 for ( int i = 0; i < ListGroup.length(); i++ )
289 ListString.push_back(std::string(ListGroup[i]));
291 myHomardCas->SetGroups( ListString );
293 //=============================================================================
294 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
296 ASSERT(myHomardCas );
297 const std::list<std::string>& ListString = myHomardCas->GetGroups();
298 HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
299 aResult->length( ListString.size() );
300 std::list<std::string>::const_iterator it;
302 for ( it = ListString.begin(); it != ListString.end(); it++ )
304 aResult[i++] = CORBA::string_dup( (*it).c_str() );
306 return aResult._retn();
308 //=============================================================================
309 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
311 MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
312 ASSERT( myHomardCas );
313 // A. La liste des frontiere+groupes
314 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
315 std::list<std::string>::const_iterator it;
317 // B.1. La frontiere est-elle deja enregistree pour ce cas ?
318 bool existe = false ;
319 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
321 // MESSAGE (".. Frontiere : "<< *it );
322 if ( *it == BoundaryName ) { existe = true ; }
325 // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
328 char* CaseName = GetName() ;
329 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
330 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
332 // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
333 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
335 std::string boun = *it ;
337 // MESSAGE (".. Group : "<< *it );
339 { INFOS ("Frontiere " << boun << " Un groupe est deja associe " << Group ) ;
340 SALOME::ExceptionStruct es;
341 es.type = SALOME::BAD_PARAM;
342 es.text = "Invalid AddBoundaryGroup";
343 throw SALOME::SALOME_Exception(es);
347 // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
348 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
350 //=============================================================================
351 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
353 MESSAGE ("GetBoundaryGroup");
354 ASSERT(myHomardCas );
355 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
356 HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
357 aResult->length( ListBoundaryGroup.size() );
358 std::list<std::string>::const_iterator it;
360 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
362 aResult[i++] = CORBA::string_dup( (*it).c_str() );
364 return aResult._retn();
366 //=============================================================================
367 void HOMARD_Cas_i::SupprBoundaryGroup()
369 MESSAGE ("SupprBoundaryGroup");
370 ASSERT(myHomardCas );
371 myHomardCas->SupprBoundaryGroup();
373 //=============================================================================
374 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
376 MESSAGE ("SetPyram, Pyram = " << Pyram );
377 ASSERT( myHomardCas );
378 myHomardCas->SetPyram( Pyram );
380 //=============================================================================
381 CORBA::Long HOMARD_Cas_i::GetPyram()
383 MESSAGE ("GetPyram");
384 ASSERT( myHomardCas );
385 return myHomardCas->GetPyram();
387 //=============================================================================
388 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
390 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
391 ASSERT( myHomardCas );
393 // Nom de l'iteration
394 char* IterName = GetIter0Name() ;
395 CORBA::Long etatMenage = -1 ;
396 CORBA::Long modeHOMARD = 7 ;
397 CORBA::Long Option1 = 1 ;
398 CORBA::Long Option2 = 1 ;
399 if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
400 if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
401 if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
402 if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
403 if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
404 CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
405 MESSAGE ( "MeshInfo : codret = " << codret );
408 //=============================================================================
409 //=============================================================================
410 // Liens avec les autres structures
411 //=============================================================================
412 //=============================================================================
413 char* HOMARD_Cas_i::GetIter0Name()
415 ASSERT( myHomardCas );
416 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
418 //=============================================================================
419 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
421 // Nom de l'iteration initiale
422 char* Iter0Name = GetIter0Name() ;
423 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
424 return _gen_i->GetIteration(Iter0Name) ;
426 //=============================================================================
427 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
429 // Nom de l'iteration parent
430 char* NomIterParent = GetIter0Name() ;
431 MESSAGE ( "NextIteration : IterName = " << IterName );
432 MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
433 return _gen_i->CreateIteration(IterName, NomIterParent) ;
435 //=============================================================================
436 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
438 HOMARD::HOMARD_Iteration_ptr Iter ;
439 HOMARD::listeIterFilles_var ListeIterFilles ;
441 // Iteration initiale du cas
442 IterName = GetIter0Name() ;
443 // On va explorer la descendance de cette iteration initiale
444 // jusqu'a trouver celle qui n'a pas de filles
445 int nbiterfilles = 1 ;
446 while ( nbiterfilles == 1 )
448 // L'iteration associee
449 // MESSAGE ( ".. IterName = " << IterName );
450 Iter = _gen_i->GetIteration(IterName) ;
451 // Les filles de cette iteration
452 ListeIterFilles = Iter->GetIterations() ;
453 nbiterfilles = ListeIterFilles->length() ;
454 // MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
455 // S'il y a au moins 2 filles, arret : on ne sait pas faire
456 VERIFICATION( nbiterfilles <= 1 ) ;
457 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
458 if ( nbiterfilles == 1 )
459 { IterName = ListeIterFilles[0] ; }
464 //=============================================================================
465 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
467 ASSERT( myHomardCas );
468 myHomardCas->AddIteration( NomIteration );
470 //=============================================================================
471 //=============================================================================
473 //=============================================================================
474 //=============================================================================
475 //=============================================================================
476 // Creation d'un schema YACS
477 // YACSName : nom du schema
478 // ScriptFile : nom du fichier contenant le script de lancement du calcul
479 // DirName : le repertoire de lancement des calculs du sch?ma
480 // MeshFile : nom du fichier contenant le maillage pour le premier calcul
481 //=============================================================================
482 HOMARD::HOMARD_YACS_ptr HOMARD_Cas_i::CreateYACSSchema( const char* YACSName, const char* ScriptFile, const char* DirName, const char* MeshFile )
485 const char* CaseName = GetName() ;
486 MESSAGE ( "CreateYACSSchema : Schema YACS pour le cas " << YACSName);
487 MESSAGE ( "nomCas : " << CaseName);
488 MESSAGE ( "ScriptFile : " << ScriptFile);
489 MESSAGE ( "DirName : " << DirName);
490 MESSAGE ( "MeshFile : " << MeshFile);
491 return _gen_i->CreateYACSSchema(YACSName, CaseName, ScriptFile, DirName, MeshFile) ;