Salome HOME
0d5d998f4524e59b6022601b835db75a1b10d8d5
[modules/smesh.git] / src / SMESH / SMESH_Homard.cxx
1 // SMESH HOMARD : implementation of SMESHHOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2021  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21
22 #include "SMESH_Homard.hxx"
23
24 #include <Utils_SALOME_Exception.hxx>
25 #include <utilities.h>
26
27 #include <iostream>
28 #include <sstream>
29 #include <cstdlib>
30 #include <sys/stat.h>
31
32 #ifndef WIN32
33 #include <unistd.h>
34 #else
35 #include <direct.h>
36 #endif
37
38 // La gestion des repertoires
39 #ifndef CHDIR
40   #ifdef WIN32
41     #define CHDIR _chdir
42   #else
43     #define CHDIR chdir
44   #endif
45 #endif
46
47 namespace SMESHHOMARDImpl
48 {
49
50 //=============================================================================
51 /*!
52  *  default constructor:
53  */
54 //=============================================================================
55 HOMARD_Boundary::HOMARD_Boundary():
56   _Name( "" ),_Type( 1 ),
57   _Xmin( 0 ), _Xmax( 0 ), _Ymin( 0 ), _Ymax( 0 ), _Zmin( 0 ), _Zmax( 0 ),
58   _Xaxe( 0 ), _Yaxe( 0 ), _Zaxe( 0 ),
59   _Xcentre( 0 ), _Ycentre( 0 ), _Zcentre( 0 ), _rayon( 0 ),
60   _Xincr( 0 ), _Yincr( 0 ), _Zincr( 0 )
61 {
62   MESSAGE("HOMARD_Boundary");
63 }
64
65 //=============================================================================
66 HOMARD_Boundary::~HOMARD_Boundary()
67 {
68   MESSAGE("~HOMARD_Boundary");
69 }
70 //=============================================================================
71 //=============================================================================
72 // Generalites
73 //=============================================================================
74 //=============================================================================
75 void HOMARD_Boundary::SetName( const char* Name )
76 {
77   _Name = std::string( Name );
78 }
79 //=============================================================================
80 std::string HOMARD_Boundary::GetName() const
81 {
82   return _Name;
83 }
84 //=============================================================================
85 std::string HOMARD_Boundary::GetDumpPython() const
86 {
87   std::ostringstream aScript;
88   switch (_Type) {
89     case -1:
90     {
91       aScript << _Name << " = smeshhomard.CreateBoundaryCAO(\"" << _Name << "\", ";
92       aScript << "\"" << _DataFile << "\")\n";
93       break ;
94     }
95     case 0:
96     {
97       aScript << _Name << " = smeshhomard.CreateBoundaryDi(\"" << _Name << "\", ";
98       aScript << "\"" << _MeshName << "\", ";
99       aScript << "\"" << _DataFile << "\")\n";
100       break ;
101     }
102     case 1:
103     {
104       aScript << _Name << " = smeshhomard.CreateBoundaryCylinder(\"" << _Name << "\", ";
105       aScript << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _rayon << ")\n";
106       break ;
107     }
108     case 2:
109     {
110       aScript << _Name << " = smeshhomard.CreateBoundarySphere(\"" << _Name << "\", ";
111       aScript << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _rayon << ")\n";
112       break ;
113     }
114     case 3:
115     {
116       aScript << _Name << " = smeshhomard.CreateBoundaryConeA(\"" << _Name << "\", ";
117       aScript << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Angle << ", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ")\n";
118       break ;
119     }
120     case 4:
121     {
122       aScript << _Name << " = smeshhomard.CreateBoundaryConeR(\"" << _Name << "\", ";
123       aScript << _Xcentre1 << ", " << _Ycentre1 << ", " << _Zcentre1 << ", " << _Rayon1 << ", " << _Xcentre2 << ", " << _Ycentre2 << ", " << _Zcentre2 << ", " << _Rayon2 << ")\n";
124       break ;
125     }
126     case 5:
127     {
128       aScript << _Name << " = smeshhomard.CreateBoundaryTorus(\"" << _Name << "\", ";
129       aScript << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Rayon1 << ", " << _Rayon2 << ")\n";
130       break ;
131     }
132   }
133
134   return aScript.str();
135 }
136 //=============================================================================
137 //=============================================================================
138 // Caracteristiques
139 //=============================================================================
140 //=============================================================================
141 void HOMARD_Boundary::SetType( int Type )
142 {
143   _Type = Type;
144 }
145 //=============================================================================
146 int HOMARD_Boundary::GetType() const
147 {
148   return _Type;
149 }
150 //=============================================================================
151 void HOMARD_Boundary::SetMeshName( const char* MeshName )
152 {
153   _MeshName = std::string( MeshName );
154 }
155 //=============================================================================
156 std::string HOMARD_Boundary::GetMeshName() const
157 {
158   return _MeshName;
159 }
160 //=============================================================================
161 void HOMARD_Boundary::SetDataFile( const char* DataFile )
162 {
163   _DataFile = std::string( DataFile );
164 }
165 //=============================================================================
166 std::string HOMARD_Boundary::GetDataFile() const
167 {
168   return _DataFile;
169 }
170 //=======================================================================================
171 void HOMARD_Boundary::SetCylinder( double X0, double X1, double X2,
172                                    double X3, double X4, double X5, double X6 )
173 {
174   _Xcentre = X0; _Ycentre = X1; _Zcentre = X2;
175   _Xaxe = X3; _Yaxe = X4; _Zaxe = X5;
176   _rayon = X6;
177 }
178 //======================================================================
179 void HOMARD_Boundary::SetSphere( double X0, double X1, double X2, double X3 )
180 {
181   _Xcentre = X0; _Ycentre = X1; _Zcentre = X2;
182   _rayon = X3;
183 }
184 //======================================================================
185 void HOMARD_Boundary::SetConeR( double Xcentre1, double Ycentre1, double Zcentre1, double Rayon1,
186                                 double Xcentre2, double Ycentre2, double Zcentre2, double Rayon2)
187 {
188   _Xcentre1 = Xcentre1; _Ycentre1 = Ycentre1; _Zcentre1 = Zcentre1;
189   _Rayon1 = Rayon1;
190   _Xcentre2 = Xcentre2; _Ycentre2 = Ycentre2; _Zcentre2 = Zcentre2;
191   _Rayon2 = Rayon2;
192 }
193 //======================================================================
194 void HOMARD_Boundary::SetConeA( double Xaxe, double Yaxe, double Zaxe, double Angle,
195                                 double Xcentre, double Ycentre, double Zcentre)
196 {
197   _Xaxe = Xaxe; _Yaxe = Yaxe; _Zaxe = Zaxe;
198   _Angle = Angle;
199   _Xcentre = Xcentre; _Ycentre = Ycentre; _Zcentre = Zcentre;
200 }
201 //=======================================================================================
202 void HOMARD_Boundary::SetTorus( double X0, double X1, double X2,
203                                 double X3, double X4, double X5, double X6, double X7 )
204 {
205   _Xcentre = X0; _Ycentre = X1; _Zcentre = X2;
206   _Xaxe = X3; _Yaxe = X4; _Zaxe = X5;
207   _Rayon1 = X6;
208   _Rayon2 = X7;
209 }
210 //=======================================================================================
211 std::vector<double> HOMARD_Boundary::GetCoords() const
212 {
213   std::vector<double> mesCoor;
214   switch (_Type)
215   {
216     //  Cylindre
217     case 1:
218     {
219       mesCoor.push_back( _Xcentre );
220       mesCoor.push_back( _Ycentre );
221       mesCoor.push_back( _Zcentre );
222       mesCoor.push_back( _Xaxe );
223       mesCoor.push_back( _Yaxe );
224       mesCoor.push_back( _Zaxe );
225       mesCoor.push_back( _rayon );
226       break ;
227     }
228     //  Sphere
229     case 2:
230     {
231       mesCoor.push_back( _Xcentre );
232       mesCoor.push_back( _Ycentre );
233       mesCoor.push_back( _Zcentre );
234       mesCoor.push_back( _rayon );
235       break ;
236     }
237     //  Cone defini par un axe et un angle
238     case 3:
239     {
240       mesCoor.push_back( _Xaxe );
241       mesCoor.push_back( _Yaxe );
242       mesCoor.push_back( _Zaxe );
243       mesCoor.push_back( _Angle );
244       mesCoor.push_back( _Xcentre );
245       mesCoor.push_back( _Ycentre );
246       mesCoor.push_back( _Zcentre );
247       break ;
248     }
249     //  Cone defini par les 2 rayons
250     case 4:
251     {
252       mesCoor.push_back( _Xcentre1 );
253       mesCoor.push_back( _Ycentre1 );
254       mesCoor.push_back( _Zcentre1 );
255       mesCoor.push_back( _Rayon1 );
256       mesCoor.push_back( _Xcentre2 );
257       mesCoor.push_back( _Ycentre2 );
258       mesCoor.push_back( _Zcentre2 );
259       mesCoor.push_back( _Rayon2 );
260       break ;
261     }
262     //  Tore
263     case 5:
264     {
265       mesCoor.push_back( _Xcentre );
266       mesCoor.push_back( _Ycentre );
267       mesCoor.push_back( _Zcentre );
268       mesCoor.push_back( _Xaxe );
269       mesCoor.push_back( _Yaxe );
270       mesCoor.push_back( _Zaxe );
271       mesCoor.push_back( _Rayon1 );
272       mesCoor.push_back( _Rayon2 );
273       break ;
274     }
275     default:
276       break ;
277   }
278   return mesCoor;
279 }
280 //======================================================================
281 void HOMARD_Boundary::SetLimit( double X0, double X1, double X2 )
282 {
283   _Xincr = X0; _Yincr = X1; _Zincr = X2;
284 }
285 //=======================================================================================
286 std::vector<double> HOMARD_Boundary::GetLimit() const
287 {
288   std::vector<double> mesLimit;
289   mesLimit.push_back( _Xincr );
290   mesLimit.push_back( _Yincr );
291   mesLimit.push_back( _Zincr );
292   return mesLimit;
293 }
294 //=============================================================================
295 void HOMARD_Boundary::AddGroup( const char* Group)
296 {
297   _ListGroupSelected.push_back(Group);
298 }
299 //=============================================================================
300 void HOMARD_Boundary::SetGroups( const std::list<std::string>& ListGroup )
301 {
302   _ListGroupSelected.clear();
303   std::list<std::string>::const_iterator it = ListGroup.begin();
304   while(it != ListGroup.end())
305     _ListGroupSelected.push_back((*it++));
306 }
307 //=============================================================================
308 const std::list<std::string>& HOMARD_Boundary::GetGroups() const
309 {
310   return _ListGroupSelected;
311 }
312 //=============================================================================
313 //=============================================================================
314 // Liens avec les autres structures
315 //=============================================================================
316 //=============================================================================
317 void HOMARD_Boundary::SetCaseCreation( const char* NomCasCreation )
318 {
319   _NomCasCreation = std::string( NomCasCreation );
320 }
321 //=============================================================================
322 std::string HOMARD_Boundary::GetCaseCreation() const
323 {
324   return _NomCasCreation;
325 }
326 //=============================================================================
327
328 //=============================================================================
329 /*!
330  *  default constructor:
331  *  Par defaut, l'adaptation est conforme, sans suivi de frontiere
332  */
333 //=============================================================================
334 HOMARD_Cas::HOMARD_Cas():
335   _Name(""), _NomDir("/tmp")
336 {
337   MESSAGE("HOMARD_Cas");
338 }
339 //=============================================================================
340 HOMARD_Cas::~HOMARD_Cas()
341 //=============================================================================
342 {
343   MESSAGE("~HOMARD_Cas");
344 }
345 //=============================================================================
346 //=============================================================================
347 // Generalites
348 //=============================================================================
349 //=============================================================================
350 void HOMARD_Cas::SetName( const char* Name )
351 {
352   _Name = std::string( Name );
353 }
354 //=============================================================================
355 std::string HOMARD_Cas::GetName() const
356 {
357   return _Name;
358 }
359 //=============================================================================
360 std::string HOMARD_Cas::GetDumpPython() const
361 {
362   std::ostringstream aScript;
363   // Suivi de frontieres
364   std::list<std::string>::const_iterator it = _ListBoundaryGroup.begin();
365   while (it != _ListBoundaryGroup.end()) {
366     aScript << "smeshhomard.AddBoundaryGroup(\"" << *it << "\", \"";
367     it++;
368     aScript << *it << "\")\n";
369     it++;
370   }
371
372   return aScript.str();
373 }
374 //=============================================================================
375 //=============================================================================
376 // Caracteristiques
377 //=============================================================================
378 //=============================================================================
379 int HOMARD_Cas::SetDirName( const char* NomDir )
380 {
381   int erreur = 0 ;
382   // On vérifie qu'aucun calcul n'a eu lieu pour ce cas
383   if ( _ListIter.size() > 1 ) { erreur = 1 ; }
384   // Creation
385   if ( CHDIR(NomDir) == 0 ) {
386     _NomDir = std::string( NomDir );
387   }
388   else {
389 #ifndef WIN32
390     if ( mkdir(NomDir, S_IRWXU|S_IRGRP|S_IXGRP) == 0 )
391 #else
392     if ( _mkdir(NomDir) == 0 )
393 #endif
394     {
395       if ( CHDIR(NomDir) == 0 ) { _NomDir = std::string( NomDir ); }
396       else                      { erreur = 2 ; }
397     }
398     else { erreur = 2 ; }
399   }
400   return erreur;
401 }
402 //=============================================================================
403 std::string HOMARD_Cas::GetDirName() const
404 {
405   return _NomDir;
406 }
407 //
408 // La boite englobante
409 //
410 //=============================================================================
411 void HOMARD_Cas::SetBoundingBox( const std::vector<double>& extremas )
412 {
413   _Boite.clear();
414   _Boite.resize( extremas.size() );
415   for ( unsigned int i = 0; i < extremas.size(); i++ )
416     _Boite[i] = extremas[i];
417 }
418 //=============================================================================
419 const std::vector<double>& HOMARD_Cas::GetBoundingBox() const
420 {
421   return _Boite;
422 }
423 //
424 // Les groupes
425 //
426 //=============================================================================
427 void HOMARD_Cas::AddGroup( const char* Group )
428 {
429   _ListGroup.push_back(Group);
430 }
431 //=============================================================================
432 void HOMARD_Cas::SetGroups( const std::list<std::string>& ListGroup )
433 {
434   _ListGroup.clear();
435   std::list<std::string>::const_iterator it = ListGroup.begin();
436   while(it != ListGroup.end())
437   {
438     _ListGroup.push_back((*it++));
439   }
440 }
441 //=============================================================================
442 const std::list<std::string>& HOMARD_Cas::GetGroups() const
443 {
444   return _ListGroup;
445 }
446 //=============================================================================
447 void HOMARD_Cas::SupprGroups()
448 {
449   _ListGroup.clear();
450 }
451 //
452 // Les frontieres
453 //
454 //=============================================================================
455 void HOMARD_Cas::AddBoundary( const char* Boundary )
456 {
457 //   MESSAGE ( ". HOMARD_Cas::AddBoundary : Boundary = " << Boundary );
458   const char* Group = "";
459   AddBoundaryGroup( Boundary, Group );
460 }
461 //=============================================================================
462 void HOMARD_Cas::AddBoundaryGroup( const char* Boundary, const char* Group )
463 {
464 //   MESSAGE ( ". HOMARD_Cas::AddBoundaryGroup : Boundary = " << Boundary );
465 //   MESSAGE ( ". HOMARD_Cas::AddBoundaryGroup : Group = " << Group );
466   _ListBoundaryGroup.push_back( Boundary );
467   _ListBoundaryGroup.push_back( Group    );
468 }
469 //=============================================================================
470 const std::list<std::string>& HOMARD_Cas::GetBoundaryGroup() const
471 {
472   return _ListBoundaryGroup;
473 }
474 //=============================================================================
475 void HOMARD_Cas::SupprBoundaryGroup()
476 {
477   _ListBoundaryGroup.clear();
478 }
479 //=============================================================================
480 //=============================================================================
481 // Liens avec les autres structures
482 //=============================================================================
483 //=============================================================================
484 void HOMARD_Cas::AddIteration( const char* NomIteration )
485 {
486   _ListIter.push_back( std::string( NomIteration ) );
487 }
488
489 //=============================================================================
490 //=============================================================================
491 HomardDriver::HomardDriver(const std::string siter, const std::string siterp1):
492   _HOMARD_Exec( "" ), _NomDir( "" ), _NomFichierConfBase( "HOMARD.Configuration" ),
493   _NomFichierConf( "" ), _NomFichierDonn( "" ), _siter( "" ), _siterp1( "" ),
494   _Texte( "" ), _bLu( false )
495 {
496   MESSAGE("siter = "<<siter<<", siterp1 = "<<siterp1);
497   // Le repertoire ou se trouve l'executable HOMARD
498   std::string dir ;
499   // TODO?
500   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { dir = getenv("HOMARD_ROOT_DIR") ; }
501   dir += "/bin/salome";
502   MESSAGE("dir ="<<dir);
503   // L'executable HOMARD
504   std::string executable = "homard";
505   MESSAGE("executable ="<<executable);
506   // Memorisation du nom complet de l'executable HOMARD
507   _HOMARD_Exec = dir + "/" + executable ;
508   MESSAGE("==> _HOMARD_Exec ="<<_HOMARD_Exec) ;
509   //
510   _siter = siter ;
511   _siterp1 = siterp1 ;
512 }
513 //=============================================================================
514 //=============================================================================
515 HomardDriver::~HomardDriver()
516 {
517 }
518 //===============================================================================
519 // A. Generalites
520 //===============================================================================
521 void HomardDriver::TexteInit( const std::string DirCompute, const std::string LogFile, const std::string Langue )
522 {
523   MESSAGE("TexteInit, DirCompute ="<<DirCompute<<", LogFile ="<<LogFile);
524 //
525   _Texte  = "ListeStd \"" + LogFile + "\"\n" ;
526   _Texte += "RepeTrav \"" + DirCompute + "\"\n" ;
527   _Texte += "RepeInfo \"" + DirCompute + "\"\n" ;
528   _Texte += "Langue \"" + Langue + "\"\n" ;
529 //
530 }
531 //===============================================================================
532 void HomardDriver::TexteAdap()
533 {
534   MESSAGE("TexteAdap");
535
536   _Texte += "Action   homa\n";
537   _Texte += "CCAssoci med\n";
538   _Texte += "ModeHOMA 1\n";
539   _Texte += "NumeIter " + _siter + "\n";
540   _modeHOMARD = 1;
541 }
542 //===============================================================================
543 void HomardDriver::TexteInfo( int TypeBila, int NumeIter )
544 {
545   MESSAGE("TexteInfo: TypeBila ="<<TypeBila<<", NumeIter ="<<NumeIter);
546 //
547   _Texte += "ModeHOMA 2\n" ;
548   std::stringstream saux1 ;
549   saux1 << TypeBila ;
550   std::string saux2 = saux1.str() ;
551   _Texte += "TypeBila " + saux2 + "\n" ;
552   if ( NumeIter ==  0 )
553   {
554     _Texte += "NumeIter 0\n" ;
555     _Texte += "Action   info_av\n" ;
556     _Texte += "CCAssoci med\n" ;
557   }
558   else
559   {
560     _Texte += "NumeIter " + _siter + "\n" ;
561     _Texte += "Action   info_ap\n" ;
562     _Texte += "CCAssoci homard\n" ;
563   }
564   _modeHOMARD = 2 ;
565 //
566 }
567 //===============================================================================
568 void HomardDriver::TexteMajCoords( int NumeIter )
569 {
570   MESSAGE("TexteMajCoords: NumeIter ="<<NumeIter);
571 //
572   _Texte += "ModeHOMA 5\n" ;
573   _Texte += "NumeIter " + _siterp1 + "\n" ;
574   _Texte += "Action   homa\n" ;
575   _Texte += "CCAssoci med\n" ;
576   _Texte += "EcriFiHO N_SANS_FRONTIERE\n" ;
577   _modeHOMARD = 5 ;
578 //
579 }
580 //===============================================================================
581 // B. Les maillages en entree et en sortie
582 //===============================================================================
583 void HomardDriver::TexteMaillage( const std::string NomMesh, const std::string MeshFile, int apres )
584 {
585   MESSAGE("TexteMaillage, NomMesh  = "<<NomMesh);
586   MESSAGE("TexteMaillage, MeshFile = "<<MeshFile);
587   MESSAGE("TexteMaillage, apres = "<<apres);
588   std::string saux ;
589   saux = "P1" ;
590   if ( apres < 1 ) { saux = "__" ; }
591
592   _Texte += "# Maillages Med " + saux + "\n" ;
593   _Texte += "CCNoMN" + saux + " \"" + NomMesh  + "\"\n" ;
594   _Texte += "CCMaiN" + saux + " \"" + MeshFile + "\"\n" ;
595 }
596
597 //===============================================================================
598 void HomardDriver::TexteMaillageHOMARD( const std::string Dir, const std::string liter, int apres )
599 {
600   MESSAGE("TexteMaillageHOMARD, Dir ="<<Dir<<", liter ="<<liter<<", apres ="<<apres);
601   std::string saux ;
602   if ( apres < 1 ) { saux = "__" ; }
603   else             { saux = "P1" ; }
604
605   _Texte += "# Maillage HOMARD " + liter + "\n" ;
606   _Texte += "HOMaiN" + saux + " Mai" + liter   + " \"" + Dir + "/maill." + liter   + ".hom.med\"\n" ;
607 }
608
609 //===============================================================================
610 // C. Le pilotage de l'adaptation
611 //===============================================================================
612 void HomardDriver::TexteConfRaffDera( int ConfType )
613 {
614   MESSAGE("TexteConfRaffDera, ConfType = " << ConfType);
615   //
616   // Type de conformite
617   //
618   std::string saux;
619   switch (ConfType)
620   {
621     case -2: //
622     {
623       saux = "NON_CONFORME_1_ARETE" ;
624       break;
625     }
626     case -1: //
627     {
628       saux = "CONFORME_BOITES" ;
629       break;
630     }
631     case 0: //
632     {
633       saux = "CONFORME" ;
634       break;
635     }
636     case 1: //
637     {
638       saux = "NON_CONFORME" ;
639       break;
640     }
641     case 2: //
642     {
643       saux = "NON_CONFORME_1_NOEUD" ;
644       break;
645     }
646     case 3: //
647     {
648       saux = "NON_CONFORME_INDICATEUR" ;
649       break;
650     }
651   }
652   _Texte += "# Type de conformite\nTypeConf " + saux + "\n" ;
653   //
654   // Type de raffinement/deraffinement
655   //
656   saux = "TypeRaff uniforme\n" ;
657   saux += "TypeDera non" ;
658   _Texte += "# Type de raffinement/deraffinement\n" + saux + "\n" ;
659 }
660 //===============================================================================
661 // D. Les frontieres
662 //===============================================================================
663 void HomardDriver::TexteBoundaryOption( int BoundaryOption )
664 {
665   MESSAGE("TexteBoundaryOption, BoundaryOption = "<<BoundaryOption);
666 //
667 // Type de suivi de frontiere
668 //
669   std::stringstream saux1 ;
670   saux1 << BoundaryOption ;
671   std::string saux = saux1.str() ;
672   _Texte += "SuivFron " + saux + "\n" ;
673 //
674 }//===============================================================================
675 void HomardDriver::TexteBoundaryCAOGr(  const std::string GroupName )
676 {
677   MESSAGE("TexteBoundaryCAOGr, GroupName  = "<<GroupName);
678 //
679   _Texte += "GrFroCAO \"" + GroupName + "\"\n" ;
680 //
681 }
682
683 //===============================================================================
684 void HomardDriver::TexteBoundaryDi(  const std::string MeshName, const std::string MeshFile )
685 {
686   MESSAGE("TexteBoundaryDi, MeshName  = "<<MeshName);
687   MESSAGE("TexteBoundaryDi, MeshFile  = "<<MeshFile);
688 //
689   _Texte += "#\n# Frontiere discrete\n" ;
690   _Texte += "CCNoMFro \"" + MeshName + "\"\n" ;
691   _Texte += "CCFronti \"" + MeshFile + "\"\n" ;
692 //
693 }
694 //===============================================================================
695 void HomardDriver::TexteBoundaryDiGr(  const std::string GroupName )
696 {
697   MESSAGE("TexteBoundaryDiGr, GroupName  = "<<GroupName);
698 //
699   _Texte += "CCGroFro \"" + GroupName + "\"\n" ;
700 //
701 }
702 //===============================================================================
703 void HomardDriver::TexteBoundaryAn( const std::string NameBoundary, int NumeBoundary, int BoundaryType, double x0, double x1, double x2, double x3, double x4, double x5, double x6, double x7 )
704 {
705   MESSAGE("TexteBoundaryAn, NameBoundary = "<<NameBoundary);
706 //   MESSAGE("TexteBoundaryAn, NumeBoundary = "<<NumeBoundary);
707   MESSAGE("TexteBoundaryAn, BoundaryType = "<<BoundaryType);
708 //   MESSAGE("TexteBoundaryAn, coor         = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5<<","<<x6","<<x7);
709 //
710   std::string saux, saux2 ;
711 //
712 // Commentaires
713 //
714   std::stringstream saux1 ;
715   saux1 << NumeBoundary ;
716   saux2 = saux1.str() ;
717   saux = "#\n# Frontiere numero " + saux2 + "\n" ;
718   if ( BoundaryType == 1 )
719   { saux += "# Cylindre\n" ; }
720   if ( BoundaryType == 2 )
721   { saux += "# Sphere\n" ; }
722   if ( BoundaryType == 3 || BoundaryType == 4 )
723   { saux += "# Cone\n" ; }
724   if ( BoundaryType == 5 )
725   { saux += "# Tore\n" ; }
726 //
727 // Le nom de la frontiere
728 //
729   { std::stringstream saux1 ;
730     saux1 << NumeBoundary ;
731     saux += "FANom " + saux1.str() + " \"" + NameBoundary + "\"\n" ;
732   }
733 //
734 // Type de frontiere
735 //
736   { std::stringstream saux1 ;
737     saux1 << NumeBoundary << " " << BoundaryType ;
738     saux += "FAType " + saux1.str() + "\n" ;
739   }
740 //
741 // Cas du cylindre
742 //
743   if ( BoundaryType == 1 )
744   {
745     { std::stringstream saux1 ;
746       saux1 << NumeBoundary << " " << x0 ;
747       saux2 = saux1.str() ;
748       saux += "FAXCen " + saux1.str() + "\n" ;
749     }
750     { std::stringstream saux1 ;
751       saux1 << NumeBoundary << " " << x1 ;
752       saux += "FAYCen " + saux1.str() + "\n" ;
753     }
754     { std::stringstream saux1 ;
755       saux1 << NumeBoundary << " " << x2 ;
756       saux += "FAZCen " + saux1.str() + "\n" ;
757     }
758     { std::stringstream saux1 ;
759       saux1 << NumeBoundary << " " << x3 ;
760       saux += "FAXAxe " + saux1.str() + "\n" ;
761     }
762     { std::stringstream saux1 ;
763       saux1 << NumeBoundary << " " << x4 ;
764       saux += "FAYAxe " + saux1.str() + "\n" ;
765     }
766     { std::stringstream saux1 ;
767       saux1 << NumeBoundary << " " << x5 ;
768       saux += "FAZAxe " + saux1.str() + "\n" ;
769     }
770     { std::stringstream saux1 ;
771       saux1 << NumeBoundary << " " << x6 ;
772       saux += "FARayon " + saux1.str() + "\n" ;
773     }
774  }
775 //
776 // Cas de la sphere
777 //
778   else if ( BoundaryType == 2 )
779   {
780     { std::stringstream saux1 ;
781       saux1 << NumeBoundary << " " << x0 ;
782       saux += "FAXCen " + saux1.str() + "\n" ;
783     }
784     { std::stringstream saux1 ;
785       saux1 << NumeBoundary << " " << x1 ;
786       saux += "FAYCen " + saux1.str() + "\n" ;
787     }
788     { std::stringstream saux1 ;
789       saux1 << NumeBoundary << " " << x2 ;
790       saux += "FAZCen " + saux1.str() + "\n" ;
791     }
792     { std::stringstream saux1 ;
793       saux1 << NumeBoundary << " " << x3 ;
794       saux += "FARayon " + saux1.str() + "\n" ;
795     }
796   }
797 //
798 // Cas du cone defini par un axe et un angle
799 //
800   if ( BoundaryType == 3 )
801   {
802     { std::stringstream saux1 ;
803       saux1 << NumeBoundary << " " << x0 ;
804       saux += "FAXAxe " + saux1.str() + "\n" ;
805     }
806     { std::stringstream saux1 ;
807       saux1 << NumeBoundary << " " << x1 ;
808       saux += "FAYAxe " + saux1.str() + "\n" ;
809     }
810     { std::stringstream saux1 ;
811       saux1 << NumeBoundary << " " << x2 ;
812       saux += "FAZAxe " + saux1.str() + "\n" ;
813     }
814     { std::stringstream saux1 ;
815       saux1 << NumeBoundary << " " << x3 ;
816       saux += "FAAngle " + saux1.str() + "\n" ;
817     }
818     { std::stringstream saux1 ;
819       saux1 << NumeBoundary << " " << x4 ;
820       saux += "FAXCen " + saux1.str() + "\n" ;
821     }
822     { std::stringstream saux1 ;
823       saux1 << NumeBoundary << " " << x5 ;
824       saux += "FAYCen " + saux1.str() + "\n" ;
825     }
826     { std::stringstream saux1 ;
827       saux1 << NumeBoundary << " " << x6 ;
828       saux += "FAZCen " + saux1.str() + "\n" ;
829     }
830  }
831 //
832 // Cas du cone defini par les 2 rayons
833 //
834   if ( BoundaryType == 4 )
835   {
836     { std::stringstream saux1 ;
837       saux1 << NumeBoundary << " " << x0 ;
838       saux += "FAXCen " + saux1.str() + "\n" ;
839     }
840     { std::stringstream saux1 ;
841       saux1 << NumeBoundary << " " << x1 ;
842       saux += "FAYCen " + saux1.str() + "\n" ;
843     }
844     { std::stringstream saux1 ;
845       saux1 << NumeBoundary << " " << x2 ;
846       saux += "FAZCen " + saux1.str() + "\n" ;
847     }
848     { std::stringstream saux1 ;
849       saux1 << NumeBoundary << " " << x3 ;
850       saux += "FARayon " + saux1.str() + "\n" ;
851     }
852     { std::stringstream saux1 ;
853       saux1 << NumeBoundary << " " << x4 ;
854       saux += "FAXCen2 " + saux1.str() + "\n" ;
855     }
856     { std::stringstream saux1 ;
857       saux1 << NumeBoundary << " " << x5 ;
858       saux += "FAYCen2 " + saux1.str() + "\n" ;
859     }
860     { std::stringstream saux1 ;
861       saux1 << NumeBoundary << " " << x6 ;
862       saux += "FAZCen2 " + saux1.str() + "\n" ;
863     }
864     { std::stringstream saux1 ;
865       saux1 << NumeBoundary << " " << x7 ;
866       saux += "FARayon2 " + saux1.str() + "\n" ;
867     }
868  }
869 //
870 // Cas du tore
871 //
872   if ( BoundaryType == 5 )
873   {
874     { std::stringstream saux1 ;
875       saux1 << NumeBoundary << " " << x0 ;
876       saux2 = saux1.str() ;
877       saux += "FAXCen " + saux1.str() + "\n" ;
878     }
879     { std::stringstream saux1 ;
880       saux1 << NumeBoundary << " " << x1 ;
881       saux += "FAYCen " + saux1.str() + "\n" ;
882     }
883     { std::stringstream saux1 ;
884       saux1 << NumeBoundary << " " << x2 ;
885       saux += "FAZCen " + saux1.str() + "\n" ;
886     }
887     { std::stringstream saux1 ;
888       saux1 << NumeBoundary << " " << x3 ;
889       saux += "FAXAxe " + saux1.str() + "\n" ;
890     }
891     { std::stringstream saux1 ;
892       saux1 << NumeBoundary << " " << x4 ;
893       saux += "FAYAxe " + saux1.str() + "\n" ;
894     }
895     { std::stringstream saux1 ;
896       saux1 << NumeBoundary << " " << x5 ;
897       saux += "FAZAxe " + saux1.str() + "\n" ;
898     }
899     { std::stringstream saux1 ;
900       saux1 << NumeBoundary << " " << x6 ;
901       saux += "FARayon  " + saux1.str() + "\n" ;
902     }
903     { std::stringstream saux1 ;
904       saux1 << NumeBoundary << " " << x7 ;
905       saux += "FARayon2 " + saux1.str() + "\n" ;
906     }
907  }
908 //
909   _Texte += saux + "#\n" ;
910 //
911 }
912 //===============================================================================
913 void HomardDriver::TexteBoundaryAnGr( const std::string NameBoundary, int NumeBoundary, const std::string GroupName )
914 {
915   MESSAGE("TexteBoundaryAnGr, NameBoundary  = "<<NameBoundary);
916 //   MESSAGE("TexteBoundaryAnGr, NumeBoundary  = "<<NumeBoundary);
917 //   MESSAGE("TexteBoundaryAnGr, GroupName  = "<<GroupName);
918 //
919 // Commentaires
920 //
921   std::string saux, saux2 ;
922   std::stringstream saux1 ;
923   saux1 << NumeBoundary ;
924   saux2 = saux1.str() ;
925   saux = "#\n# Lien Frontiere/Groupe numero " + saux2 + "\n" ;
926 //
927   saux += "FGNomFro " + saux2 + " \"" + NameBoundary + "\"\n" ;
928   saux += "FGNomGro " + saux2 + " \"" + GroupName + "\"\n" ;
929 //
930   _Texte += saux + "#\n" ;
931 //
932 }
933 //===============================================================================
934 // F. Les options avancees
935 //===============================================================================
936 void HomardDriver::TexteAdvanced( int NivMax, double DiamMin, int AdapInit, int ExtraOutput )
937 {
938   MESSAGE("TexteAdvanced, NivMax ="<<NivMax<<", DiamMin ="<<DiamMin<<
939           ", AdapInit ="<<AdapInit<<", ExtraOutput ="<<ExtraOutput);
940
941   if ( NivMax > 0 )
942   {
943     _Texte += "# Niveaux extremes\n" ;
944     { std::stringstream saux1 ;
945       saux1 << NivMax ;
946       _Texte += "NiveauMa " + saux1.str() + "\n" ;
947     }
948   }
949   if ( DiamMin > 0 )
950   {
951     _Texte += "# Diametre minimal\n" ;
952     { std::stringstream saux1 ;
953       saux1 << DiamMin ;
954       _Texte += "DiametMi " + saux1.str()  + "\n" ;
955     }
956   }
957   if ( AdapInit != 0 )
958   {
959     if ( AdapInit > 0 )
960     { _Texte += "# Raffinement" ; }
961     else
962     { _Texte += "# Deraffinement" ; }
963     _Texte += " des regions sans indicateur\n" ;
964     { std::stringstream saux1 ;
965       saux1 << AdapInit ;
966       _Texte += "AdapInit " + saux1.str() + "\n" ;
967     }
968   }
969   if ( ExtraOutput % 2 == 0 )
970   {
971     _Texte += "# Sortie des niveaux de raffinement\n" ;
972     _Texte += "NCNiveau NIVEAU\n" ;
973   }
974   if ( ExtraOutput % 3 == 0 )
975   {
976     _Texte += "# Sortie des qualités des mailles\n" ;
977     _Texte += "NCQualit QUAL\n" ;
978   }
979   if ( ExtraOutput % 5 == 0 )
980   {
981     _Texte += "# Sortie des diamètres des mailles\n" ;
982     _Texte += "NCDiamet DIAM\n" ;
983   }
984   if ( ExtraOutput % 7 == 0 )
985   {
986     _Texte += "# Sortie des parents des mailles\n" ;
987     _Texte += "NCParent PARENT\n" ;
988   }
989   if ( ExtraOutput % 11 == 0 )
990   {
991     _Texte += "# Volumes voisins par recollement\n" ;
992     _Texte += "NCVoisRc Voisin-Recollement\n" ;
993   }
994 }
995 //===============================================================================
996 // G. Les messages
997 //===============================================================================
998 void HomardDriver::TexteInfoCompute( int MessInfo )
999 {
1000   MESSAGE("TexteAdvanced, MessInfo ="<<MessInfo);
1001
1002   if ( MessInfo != 0 )
1003   {
1004      _Texte += "# Messages d'informations\n" ;
1005     { std::stringstream saux1 ;
1006       saux1 << MessInfo ;
1007       _Texte += "MessInfo " + saux1.str()  + "\n" ;
1008     }
1009    }
1010 }
1011 //===============================================================================
1012 void HomardDriver::CreeFichier( )
1013 {
1014 //
1015   if ( _modeHOMARD == 1 )
1016   { _NomFichierConf = _NomFichierConfBase + "." + _siter + ".vers." + _siterp1 ; }
1017   else if ( _modeHOMARD == 2 )
1018   { _NomFichierConf = _NomFichierConfBase + "." + _siter + ".info" ; }
1019   else if ( _modeHOMARD == 5 )
1020   { _NomFichierConf = _NomFichierConfBase + ".majc" ; }
1021 //
1022   std::ofstream Fic(_NomFichierConf.c_str(), std::ios::out ) ;
1023   if (Fic.is_open() == true) { Fic << _Texte << std::endl ; }
1024   Fic.close() ;
1025 //
1026 }
1027 //===============================================================================
1028 // Creation du fichier de donnees pour l'information
1029 //===============================================================================
1030 void HomardDriver::CreeFichierDonn( )
1031 {
1032 //
1033   MESSAGE("CreeFichierDonn");
1034   _NomFichierDonn = "info.donn" ;
1035 //
1036   std::string data ;
1037   data  = "0\n" ;
1038   data += "0\n" ;
1039   data += "q\n" ;
1040   std::ofstream Fic(_NomFichierDonn.c_str(), std::ios::out ) ;
1041   if (Fic.is_open() == true) { Fic << data << std::endl ; }
1042   Fic.close() ;
1043 //
1044 }
1045 //===============================================================================
1046 int HomardDriver::ExecuteHomard()
1047 {
1048   MESSAGE("ExecuteHomard");
1049   std::string commande ;
1050   int codret ;
1051   // Copie des Fichiers HOMARD
1052   commande = "cp " + _NomFichierConf + " " + _NomFichierConfBase ;
1053   codret = system(commande.c_str()) ;
1054
1055 // Execution de HOMARD
1056   if ( codret == 0)
1057   {
1058     commande = _HOMARD_Exec.c_str() ;
1059     if ( _NomFichierDonn != "" ) { commande += " < " + _NomFichierDonn ; }
1060     codret = system(commande.c_str());
1061     if ( codret != 0) { MESSAGE ( "Erreur en executant HOMARD : " << codret ); };
1062     _NomFichierDonn = "" ;
1063   };
1064   return codret ;
1065 }
1066
1067 //=============================================================================
1068 //=============================================================================
1069 HOMARD_Gen::HOMARD_Gen()
1070 {
1071   MESSAGE("HOMARD_Gen");
1072 }
1073
1074 //=============================================================================
1075 //=============================================================================
1076 HOMARD_Gen::~HOMARD_Gen()
1077 {
1078   MESSAGE("~HOMARD_Gen");
1079 }
1080 //=============================================================================
1081
1082 //=============================================================================
1083 /*!
1084  *  default constructor:
1085  */
1086 //=============================================================================
1087 HOMARD_Iteration::HOMARD_Iteration():
1088   _Name( "" ),
1089   _Etat( 0 ),
1090   _NumIter( -1 ),
1091   _NomMesh( "" ),
1092   _MeshFile( "" ),
1093   _LogFile( "" ),
1094   _NomDir( "" ),
1095   _FileInfo( "" ),
1096   _MessInfo( 1 )
1097 {
1098   MESSAGE("HOMARD_Iteration");
1099 }
1100 //=============================================================================
1101 /*!
1102  *
1103  */
1104 //=============================================================================
1105 HOMARD_Iteration::~HOMARD_Iteration()
1106 {
1107   MESSAGE("~HOMARD_Iteration");
1108 }
1109 //=============================================================================
1110 //=============================================================================
1111 // Generalites
1112 //=============================================================================
1113 //=============================================================================
1114 void HOMARD_Iteration::SetName( const char* Name )
1115 {
1116   _Name = std::string( Name );
1117 }
1118 //=============================================================================
1119 std::string HOMARD_Iteration::GetName() const
1120 {
1121   return _Name;
1122 }
1123 //=============================================================================
1124 //=============================================================================
1125 // Caracteristiques
1126 //=============================================================================
1127 //=============================================================================
1128 void HOMARD_Iteration::SetDirNameLoc( const char* NomDir )
1129 {
1130   _NomDir = std::string( NomDir );
1131 }
1132 //=============================================================================
1133 std::string HOMARD_Iteration::GetDirNameLoc() const
1134 {
1135    return _NomDir;
1136 }
1137 //=============================================================================
1138 void HOMARD_Iteration::SetNumber( int NumIter )
1139 {
1140   _NumIter = NumIter;
1141 }
1142 //=============================================================================
1143 int HOMARD_Iteration::GetNumber() const
1144 {
1145   return _NumIter;
1146 }
1147 //=============================================================================
1148 void HOMARD_Iteration::SetState( int etat )
1149 {
1150   _Etat = etat;
1151 }
1152 //=============================================================================
1153 int HOMARD_Iteration::GetState() const
1154 {
1155   return _Etat;
1156 }
1157 //=============================================================================
1158 void HOMARD_Iteration::SetMeshName( const char* NomMesh )
1159 {
1160   _NomMesh = std::string( NomMesh );
1161 }
1162 //=============================================================================
1163 std::string HOMARD_Iteration::GetMeshName() const
1164 {
1165   return _NomMesh;
1166 }
1167 //=============================================================================
1168 void HOMARD_Iteration::SetMeshFile( const char* MeshFile )
1169 {
1170   _MeshFile = std::string( MeshFile );
1171 }
1172 //=============================================================================
1173 std::string HOMARD_Iteration::GetMeshFile() const
1174 {
1175   return _MeshFile;
1176 }
1177 //=============================================================================
1178 void HOMARD_Iteration::SetLogFile( const char* LogFile )
1179 {
1180   _LogFile = std::string( LogFile );
1181 }
1182 //=============================================================================
1183 std::string HOMARD_Iteration::GetLogFile() const
1184 {
1185   return _LogFile;
1186 }
1187 //=============================================================================
1188 void HOMARD_Iteration::SetFileInfo( const char* FileInfo )
1189 {
1190   _FileInfo = std::string( FileInfo );
1191 }
1192 //=============================================================================
1193 std::string HOMARD_Iteration::GetFileInfo() const
1194 {
1195   return _FileInfo;
1196 }
1197 //=============================================================================
1198 void HOMARD_Iteration::SetInfoCompute( int MessInfo )
1199 {
1200   _MessInfo = MessInfo;
1201 }
1202 //=============================================================================
1203 int HOMARD_Iteration::GetInfoCompute() const
1204 {
1205   return _MessInfo;
1206 }
1207
1208 } // namespace SMESHHOMARDImpl /end/