]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARD_I/HOMARD_Cas_i.cxx
Salome HOME
Catalogue pour YACS ; liberation de structures allouees ; documentation
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
1 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Remarques :
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
25 //
26 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
27 //
28
29 #include "HOMARD_Cas_i.hxx"
30 #include "HOMARD_Gen_i.hxx"
31 #include "HOMARD_Cas.hxx"
32 #include "HOMARD_DriverTools.hxx"
33
34 #include "utilities.h"
35 #include <vector>
36
37 //=============================================================================
38 /*!
39  *  standard constructor
40  */
41 //=============================================================================
42 HOMARD_Cas_i::HOMARD_Cas_i()
43 {
44   MESSAGE( "Default constructor, not for use" );
45   ASSERT( 0 );
46 }
47
48 //=============================================================================
49 /*!
50  *  standard constructor
51  */
52 //=============================================================================
53 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
54                             HOMARD::HOMARD_Gen_var engine )
55 {
56   MESSAGE( "HOMARD_Cas_i" );
57   _gen_i = engine;
58   _orb = orb;
59   myHomardCas = new ::HOMARD_Cas();
60   ASSERT( myHomardCas );
61 }
62
63 //=============================================================================
64 /*!
65  *  standard destructor
66  */
67 //=============================================================================
68 HOMARD_Cas_i::~HOMARD_Cas_i()
69 {
70 }
71 //=============================================================================
72 //=============================================================================
73 // Generalites
74 //=============================================================================
75 //=============================================================================
76 void HOMARD_Cas_i::SetName( const char* Name )
77 {
78   ASSERT( myHomardCas );
79   myHomardCas->SetName( Name );
80 }
81 //=============================================================================
82 char* HOMARD_Cas_i::GetName()
83 {
84   ASSERT( myHomardCas );
85   return CORBA::string_dup( myHomardCas->GetName().c_str() );
86 }
87 //=============================================================================
88 CORBA::Long  HOMARD_Cas_i::Delete()
89 {
90   ASSERT( myHomardCas );
91   char* CaseName = GetName() ;
92   MESSAGE ( "Delete : destruction du cas " << CaseName );
93   return _gen_i->DeleteCase(CaseName) ;
94 }
95 //=============================================================================
96 char* HOMARD_Cas_i::GetDumpPython()
97 {
98   ASSERT( myHomardCas );
99   return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
100 }
101 //=============================================================================
102 std::string HOMARD_Cas_i::Dump() const
103 {
104   return HOMARD::Dump( *myHomardCas );
105 }
106 //=============================================================================
107 bool HOMARD_Cas_i::Restore( const std::string& stream )
108 {
109   return HOMARD::Restore( *myHomardCas, stream );
110 }
111 //=============================================================================
112 //=============================================================================
113 // Caracteristiques
114 //=============================================================================
115 //=============================================================================
116 void HOMARD_Cas_i::SetDirName( const char* NomDir )
117 {
118   ASSERT( myHomardCas );
119   int codret ;
120   // A. Changement/creation du repertoire
121   char* oldrep = GetDirName() ;
122   codret = myHomardCas->SetDirName( NomDir );
123   if ( codret != 0 )
124   {
125     SALOME::ExceptionStruct es;
126     es.type = SALOME::BAD_PARAM;
127     std::string text ;
128     if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
129     else               { text = "The directory for the case cannot be reached." ; }
130     es.text = CORBA::string_dup(text.c_str());
131     throw SALOME::SALOME_Exception(es);
132   }
133   // B. En cas de reprise, deplacement du point de depart
134   if ( GetState() != 0 )
135   {
136     MESSAGE ( "etat : " << GetState() ) ;
137     char* Iter0Name = GetIter0Name() ;
138     HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
139     char* DirNameIter = Iter->GetDirNameLoc() ;
140     std::string commande = "mv " + std::string(oldrep) + "/" + std::string(DirNameIter) + " " + std::string(NomDir) ;
141     codret = system(commande.c_str()) ;
142     if ( codret != 0 )
143     {
144       SALOME::ExceptionStruct es;
145       es.type = SALOME::BAD_PARAM;
146       std::string text = "The starting point for the case cannot be moved into the new directory." ;
147       es.text = CORBA::string_dup(text.c_str());
148       throw SALOME::SALOME_Exception(es);
149     }
150   }
151   return ;
152 }
153 //=============================================================================
154 char* HOMARD_Cas_i::GetDirName()
155 {
156   ASSERT( myHomardCas );
157   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
158 }
159 //=============================================================================
160 CORBA::Long HOMARD_Cas_i::GetState()
161 {
162   ASSERT( myHomardCas );
163 // Nom de l'iteration initiale
164   char* Iter0Name = GetIter0Name() ;
165   HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
166   int state = Iter->GetNumber() ;
167   return state ;
168 }
169 //=============================================================================
170 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
171 {
172   ASSERT( myHomardCas );
173   return myHomardCas->GetNumberofIter();
174 }
175 //=============================================================================
176 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
177 {
178   ASSERT( myHomardCas );
179   myHomardCas->SetConfType( ConfType );
180 }
181 //=============================================================================
182 CORBA::Long HOMARD_Cas_i::GetConfType()
183 {
184   ASSERT( myHomardCas );
185   return myHomardCas->GetConfType();
186 }
187 //=============================================================================
188 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
189 {
190   ASSERT( myHomardCas );
191   std::vector<double> VExtrema;
192   ASSERT( LesExtrema.length() == 10 );
193   VExtrema.resize( LesExtrema.length() );
194   for ( int i = 0; i < LesExtrema.length(); i++ )
195   {
196     VExtrema[i] = LesExtrema[i];
197   }
198   myHomardCas->SetBoundingBox( VExtrema );
199 }
200 //=============================================================================
201 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
202 {
203   ASSERT(myHomardCas );
204   HOMARD::extrema_var aResult = new HOMARD::extrema();
205   std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
206   ASSERT( LesExtremes.size() == 10 );
207   aResult->length( 10 );
208   for ( int i = 0; i < LesExtremes.size(); i++ )
209   {
210     aResult[i] = LesExtremes[i];
211   }
212   return aResult._retn();
213 }
214 //=============================================================================
215 void HOMARD_Cas_i::AddGroup( const char* Group)
216 {
217   ASSERT( myHomardCas );
218   myHomardCas->AddGroup( Group );
219 }
220 //=============================================================================
221 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
222 {
223   ASSERT( myHomardCas );
224   std::list<std::string> ListString ;
225   for ( int i = 0; i < ListGroup.length(); i++ )
226   {
227     ListString.push_back(std::string(ListGroup[i]));
228   }
229   myHomardCas->SetGroups( ListString );
230 }
231 //=============================================================================
232 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
233 {
234   ASSERT(myHomardCas );
235   const std::list<std::string>& ListString = myHomardCas->GetGroups();
236   HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
237   aResult->length( ListString.size() );
238   std::list<std::string>::const_iterator it;
239   int i = 0;
240   for ( it = ListString.begin(); it != ListString.end(); it++ )
241   {
242     aResult[i++] = CORBA::string_dup( (*it).c_str() );
243   }
244   return aResult._retn();
245 }
246 //=============================================================================
247 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
248 {
249   MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
250   ASSERT( myHomardCas );
251   // La frontiere est-elle deja enregistree pour ce cas ?
252   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
253   std::list<std::string>::const_iterator it;
254   int existe = 0;
255   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
256   {
257     if ( *it == BoundaryName )
258     { existe = 1 ; }
259     it++ ;
260   }
261   // Enregistrement de la frontiere dans la reference du cas
262   myHomardCas->AddBoundaryGroup( BoundaryName, Group );
263   // Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
264   if ( existe == 0 )
265   {
266     char* CaseName = GetName() ;
267     MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
268     _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
269   }
270 }
271 //=============================================================================
272 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
273 {
274   MESSAGE ("GetBoundaryGroup");
275   ASSERT(myHomardCas );
276   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
277   HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
278   aResult->length( ListBoundaryGroup.size() );
279   std::list<std::string>::const_iterator it;
280   int i = 0;
281   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
282   {
283     aResult[i++] = CORBA::string_dup( (*it).c_str() );
284   }
285   return aResult._retn();
286 }
287 //=============================================================================
288 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
289 {
290   MESSAGE ("SetPyram, Pyram = " << Pyram );
291   ASSERT( myHomardCas );
292   myHomardCas->SetPyram( Pyram );
293 }
294 //=============================================================================
295 CORBA::Long HOMARD_Cas_i::GetPyram()
296 {
297   MESSAGE ("GetPyram");
298   ASSERT( myHomardCas );
299   return myHomardCas->GetPyram();
300 }
301 //=============================================================================
302 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
303 {
304   MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
305   ASSERT( myHomardCas );
306 //
307 // Nom de l'iteration
308   char* IterName = GetIter0Name() ;
309   CORBA::Long etatMenage = -1 ;
310   CORBA::Long modeHOMARD = 7 ;
311   CORBA::Long Option1 = 1 ;
312   CORBA::Long Option2 = 1 ;
313   if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
314   if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
315   if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
316   if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
317   if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
318   CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
319   MESSAGE ( "MeshInfo : codret = " << codret );
320   return ;
321 }
322 //=============================================================================
323 //=============================================================================
324 // Liens avec les autres structures
325 //=============================================================================
326 //=============================================================================
327 char* HOMARD_Cas_i::GetIter0Name()
328 {
329   ASSERT( myHomardCas );
330   return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
331 }
332 //=============================================================================
333 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
334 {
335 // Nom de l'iteration initiale
336   char* Iter0Name = GetIter0Name() ;
337   MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
338   return _gen_i->GetIteration(Iter0Name) ;
339 }
340 //=============================================================================
341 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
342 {
343 // Nom de l'iteration parent
344   char* NomIterParent = GetIter0Name() ;
345   MESSAGE ( "NextIteration : IterName      = " << IterName );
346   MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
347   return _gen_i->CreateIteration(IterName, NomIterParent) ;
348 }
349 //=============================================================================
350 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
351 {
352   HOMARD::HOMARD_Iteration_ptr Iter ;
353   HOMARD::listeIterFilles_var ListeIterFilles ;
354   char* IterName ;
355 // Iteration initiale du cas
356   IterName = GetIter0Name() ;
357 // On va explorer la descendance de cette iteration initiale
358 // jusqu'a trouver celle qui n'a pas de filles
359   int nbiterfilles = 1 ;
360   while ( nbiterfilles == 1 )
361   {
362 // L'iteration associee
363 //     MESSAGE ( ".. IterName = " << IterName );
364     Iter = _gen_i->GetIteration(IterName) ;
365 // Les filles de cette iteration
366     ListeIterFilles = Iter->GetIterations() ;
367     nbiterfilles = ListeIterFilles->length() ;
368 //     MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
369 // S'il y a au moins 2 filles, arret : on ne sait pas faire
370     ASSERT( nbiterfilles <= 1 ) ;
371 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
372     if ( nbiterfilles == 1 )
373     { IterName = ListeIterFilles[0] ; }
374   }
375 //
376   return Iter ;
377 }
378 //=============================================================================
379 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
380 {
381   ASSERT( myHomardCas );
382   myHomardCas->AddIteration( NomIteration );
383 }