1 // HOMARD HOMARD : implementaion of HOMARD idl descriptions
3 // Copyright (C) 2011 CEA/DEN, EDF R&D
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.
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.
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
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #include "Utils_SALOME_Exception.hxx"
27 #include "utilities.h"
28 #include "HomardDriver.hxx"
30 //=============================================================================
31 //=============================================================================
32 HomardDriver::HomardDriver(const std::string siter, const std::string siterp1):
33 _HOMARD_Exec( "" ), _NomDir( "" ), _NomFichierConfBase( "HOMARD.Configuration" ),
34 _NomFichierConf( "" ), _siter( "" ), _siterp1( "" ),
35 _Texte( "" ), _bLu( false )
37 // Memorisation du nom complet de l'executable HOMARD
38 char* dirchar; char* execchar;
40 std::string executable;
41 if ( !(dirchar = getenv("HOMARD_REP_EXE")) )
42 dir = "/logiciels/HOMARD/HOMARD_PUBLIC/Linux64" ;
44 dir = std::string(dirchar);
45 if ( !(execchar = getenv("HOMARD_EXE")) )
46 executable = "HOMARD";
48 executable = std::string(execchar);
49 _HOMARD_Exec = dir + "/" + executable ;
50 MESSAGE("Dans HomardDriver::HomardDriver, _HOMARD_Exec ="<<_HOMARD_Exec);
56 //=============================================================================
57 //=============================================================================
58 HomardDriver::~HomardDriver()
62 ////=============================================================================
63 void HomardDriver::TexteInit( const std::string DirCompute, const std::string DirComputePa, const std::string MessFile )
65 MESSAGE("Dans HomardDriver::TexteInit, MessFile ="<<MessFile);
67 _Texte = "Action homa\n" ;
68 _Texte += "CCAssoci med\n" ;
69 _Texte += "ModeHOMA 1\n" ;
70 _Texte += "NumeIter " + _siter + "\n" ;
71 _Texte += "ListeStd " + MessFile + "\n" ;
72 _Texte += "# Maillages HOMARD \n" ;
73 _Texte += "HOMaiN__ Mai" + _siter + " " + DirComputePa + "/maill." + _siter + ".hom.med\n" ;
74 _Texte += "HOMaiNP1 Mai" + _siterp1 + " " + DirCompute + "/maill." + _siterp1 + ".hom.med\n" ;
75 _Texte += "RepeTrav " + DirCompute + "\n" ;
79 ////=============================================================================
80 void HomardDriver::TexteMaillage( const std::string NomMesh, const std::string MeshFile, int apres )
82 MESSAGE("Dans HomardDriver::TexteMaillage, NomMesh ="<<NomMesh<<", MeshFile ="<<MeshFile);
85 if ( apres < 1 ) { saux = "__" ; }
87 _Texte += "# Maillages Med " + saux + "\n" ;
88 _Texte += "CCNoMN" + saux + " \"" + NomMesh + "\"\n" ;
89 _Texte += "CCMaiN" + saux + " " + MeshFile + "\n" ;
92 ////=============================================================================
93 void HomardDriver::TexteConfRaffDera( int ConfType, int TypeAdap, int TypeRaff, int TypeDera )
95 MESSAGE("Dans HomardDriver::TexteConfRaffDera, ConfType ="<<ConfType);
96 MESSAGE("Dans HomardDriver::TexteConfRaffDera, TypeAdap ="<<TypeAdap<<", TypeRaff ="<<TypeRaff<<", TypeDera ="<<TypeDera);
110 saux = "non_conforme_1_noeud" ;
115 saux = "non_conforme_1_arete" ;
120 saux = "non_conforme_indicateur" ;
124 _Texte += "# Type de conformite\nTypeConf " + saux + "\n" ;
126 // Type de raffinement/deraffinement
128 if ( TypeAdap == -1 )
132 saux = "TypeRaff uniforme\n" ;
136 saux = "TypeRaff non\n" ;
140 saux += "TypeDera uniforme" ;
144 saux += "TypeDera non" ;
151 saux = "TypeRaff libre\n" ;
155 saux = "TypeRaff non\n" ;
159 saux += "TypeDera libre" ;
163 saux += "TypeDera non" ;
166 _Texte += "# Type de raffinement/deraffinement\n" + saux + "\n" ;
168 // MESSAGE("A la fin de HomardDriver::TexteConfRaffDera, _Texte ="<<_Texte);
170 ////=============================================================================
171 void HomardDriver::TexteCompo( int NumeComp, const std::string NompCompo)
173 MESSAGE("Dans HomardDriver::TexteCompo, NumeComp = "<<NumeComp<<", NompCompo = "<<NompCompo);
174 _Texte +="CCCoChaI \"" + NompCompo + "\"\n" ;
177 ////=============================================================================
178 void HomardDriver::TexteZone( int NumeZone, int ZoneType, double x0, double x1, double x2, double x3, double x4, double x5 )
180 MESSAGE("Dans HomardDriver::TexteZone, NumeZone = "<<NumeZone<<", ZoneType = "<<ZoneType);
181 MESSAGE("Dans HomardDriver::TexteZone, coor = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5);
183 std::string saux, saux2 ;
187 std::stringstream saux1 ;
189 saux2 = saux1.str() ;
190 saux = "#\n# Zone numero " + saux2 + "\n" ;
192 { std::stringstream saux1 ;
193 saux1 << NumeZone << " " << ZoneType ;
194 saux2 = saux1.str() ;
195 saux += "ZoRaType " + saux2 + "\n" ;
198 // Cas du rectangle/parallelepipede
202 saux += "# Boite\n" ;
203 { std::stringstream saux1 ;
204 saux1 << NumeZone << " " << x0 ;
205 saux2 = saux1.str() ;
206 saux += "ZoRaXmin " + saux2 + "\n" ;
208 { std::stringstream saux1 ;
209 saux1 << NumeZone << " " << x1 ;
210 saux2 = saux1.str() ;
211 saux += "ZoRaXmax " + saux2 + "\n" ;
213 { std::stringstream saux1 ;
214 saux1 << NumeZone << " " << x2 ;
215 saux2 = saux1.str() ;
216 saux += "ZoRaYmin " + saux2 + "\n" ;
218 { std::stringstream saux1 ;
219 saux1 << NumeZone << " " << x3 ;
220 saux2 = saux1.str() ;
221 saux += "ZoRaYmax " + saux2 + "\n" ;
223 { std::stringstream saux1 ;
224 saux1 << NumeZone << " " << x4 ;
225 saux2 = saux1.str() ;
226 saux += "ZoRaZmin " + saux2 + "\n" ;
228 { std::stringstream saux1 ;
229 saux1 << NumeZone << " " << x5 ;
230 saux2 = saux1.str() ;
231 saux += "ZoRaZmax " + saux2 + "\n" ;
235 // Cas du cercle/sphere
237 else if ( ZoneType == 4 )
239 saux += "# Sphere\n" ;
240 { std::stringstream saux1 ;
241 saux1 << NumeZone << " " << x0 ;
242 saux2 = saux1.str() ;
243 saux += "ZoRaXCen " + saux2 + "\n" ;
245 { std::stringstream saux1 ;
246 saux1 << NumeZone << " " << x1 ;
247 saux2 = saux1.str() ;
248 saux += "ZoRaYCen " + saux2 + "\n" ;
250 { std::stringstream saux1 ;
251 saux1 << NumeZone << " " << x2 ;
252 saux2 = saux1.str() ;
253 saux += "ZoRaZCen " + saux2 + "\n" ;
255 { std::stringstream saux1 ;
256 saux1 << NumeZone << " " << x3 ;
257 saux2 = saux1.str() ;
258 saux += "ZoRaRayo " + saux2 + "\n" ;
262 _Texte += saux + "#\n" ;
264 // MESSAGE("A la fin de HomardDriver::TexteZone, _Texte ="<<_Texte);
267 ////=============================================================================
268 void HomardDriver::TexteField( const std::string FieldName, const std::string FieldFile, int TimeStep, int Rank,
269 int TypeThR, double ThreshR, int TypeThC, double ThreshC, int UsCmpI )
271 MESSAGE("Dans HomardDriver::TexteField, FieldName = "<<FieldName<<", FieldFile = "<<FieldFile);
272 MESSAGE("Dans HomardDriver::TexteField, TimeStep = "<<TimeStep<<", Rank = "<<Rank);
274 std::string saux, saux2 ;
277 _Texte += "# Champ d'indicateurs\n" ;
278 _Texte += "CCIndica " + FieldFile + "\n" ;
279 _Texte += "CCNoChaI \"" + FieldName + "\"\n" ;
281 // Cas ou on prend le dernier pas de temps
282 if ( TimeStep == -2 )
283 { _Texte += "CCNumPTI Last\n" ; }
284 // Cas avec pas de temps
285 else if ( TimeStep >= 0 )
288 std::stringstream saux1 ;
290 saux2 = saux1.str() ;
291 _Texte += "CCNumPTI " + saux2 + "\n" ;
294 std::stringstream saux1 ;
296 saux2 = saux1.str() ;
297 _Texte += "CCNumOrI " + saux2 + "\n" ;
310 std::stringstream saux1 ;
312 saux2 = saux1.str() ;
313 _Texte += "Seuil" + saux + " " + saux2 + "\n" ;
325 std::stringstream saux1 ;
327 saux2 = saux1.str() ;
328 _Texte += "Seuil" + saux + " " + saux2 + "\n" ;
335 { saux = "INFINI" ; }
337 { saux = "V_RELATIVE" ; }
340 _Texte += "CCUsCmpI " + saux + "\n" ;
344 ////=============================================================================
345 void HomardDriver::TexteGroup( const std::string GroupName )
347 MESSAGE("Dans HomardDriver::TexteGroup, GroupName = "<<GroupName);
349 _Texte += "CCGroAda " + GroupName + "\n" ;
352 ////=============================================================================
353 void HomardDriver::TexteBoundaryOption( int BoundaryOption )
355 MESSAGE("Dans HomardDriver::TexteBoundaryOption, BoundaryOption = "<<BoundaryOption);
357 // Type de suivi de frontiere
359 std::stringstream saux1 ;
360 saux1 << BoundaryOption ;
361 std::string saux = saux1.str() ;
362 _Texte += "SuivFron " + saux + "\n" ;
365 ////=============================================================================
366 void HomardDriver::TexteBoundaryDi( const std::string MeshName, const std::string MeshFile )
368 MESSAGE("Dans HomardDriver::TexteBoundaryDi, MeshName = "<<MeshName);
369 MESSAGE("Dans HomardDriver::TexteBoundaryDi, MeshFile = "<<MeshFile);
371 _Texte += "CCNoMFro " + MeshName + "\n" ;
372 _Texte += "CCFronti " + MeshFile + "\n" ;
375 ////=============================================================================
376 void HomardDriver::TexteBoundaryDiGr( const std::string GroupName )
378 MESSAGE("Dans HomardDriver::TexteBoundaryDiGr, GroupName = "<<GroupName);
380 _Texte += "CCGroFro " + GroupName + "\n" ;
383 ////=============================================================================
384 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 )
386 MESSAGE("Dans HomardDriver::TexteBoundaryAn, NameBoundary = "<<NameBoundary);
387 MESSAGE("Dans HomardDriver::TexteBoundaryAn, NumeBoundary = "<<NumeBoundary);
388 MESSAGE("Dans HomardDriver::TexteBoundaryAn, BoundaryType = "<<BoundaryType);
389 MESSAGE("Dans HomardDriver::TexteBoundaryAn, coor = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5<<","<<x6);
391 std::string saux, saux2 ;
395 std::stringstream saux1 ;
396 saux1 << NumeBoundary ;
397 saux2 = saux1.str() ;
398 saux = "#\n# Frontiere numero " + saux2 + "\n" ;
399 if ( BoundaryType == 1 )
400 { saux += "# Cylindre\n" ; }
401 if ( BoundaryType == 2 )
402 { saux += "# Sphere\n" ; }
404 // Le nom de la frontiere
406 { std::stringstream saux1 ;
407 saux1 << NumeBoundary ;
408 saux2 = saux1.str() ;
409 saux += "FANom " + saux2 + " '" + NameBoundary + "'\n" ;
414 { std::stringstream saux1 ;
415 saux1 << NumeBoundary << " " << BoundaryType ;
416 saux2 = saux1.str() ;
417 saux += "FAType " + saux2 + "\n" ;
422 if ( BoundaryType == 1 )
424 { std::stringstream saux1 ;
425 saux1 << NumeBoundary << " " << x0 ;
426 saux2 = saux1.str() ;
427 saux += "FAXCen " + saux2 + "\n" ;
429 { std::stringstream saux1 ;
430 saux1 << NumeBoundary << " " << x1 ;
431 saux2 = saux1.str() ;
432 saux += "FAYCen " + saux2 + "\n" ;
434 { std::stringstream saux1 ;
435 saux1 << NumeBoundary << " " << x2 ;
436 saux2 = saux1.str() ;
437 saux += "FAZCen " + saux2 + "\n" ;
439 { std::stringstream saux1 ;
440 saux1 << NumeBoundary << " " << x3 ;
441 saux2 = saux1.str() ;
442 saux += "FAXAxe " + saux2 + "\n" ;
444 { std::stringstream saux1 ;
445 saux1 << NumeBoundary << " " << x4 ;
446 saux2 = saux1.str() ;
447 saux += "FAYAxe " + saux2 + "\n" ;
449 { std::stringstream saux1 ;
450 saux1 << NumeBoundary << " " << x5 ;
451 saux2 = saux1.str() ;
452 saux += "FAZAxe " + saux2 + "\n" ;
454 { std::stringstream saux1 ;
455 saux1 << NumeBoundary << " " << x6 ;
456 saux2 = saux1.str() ;
457 saux += "FARayon " + saux2 + "\n" ;
463 else if ( BoundaryType == 2 )
465 { std::stringstream saux1 ;
466 saux1 << NumeBoundary << " " << x0 ;
467 saux2 = saux1.str() ;
468 saux += "FAXCen " + saux2 + "\n" ;
470 { std::stringstream saux1 ;
471 saux1 << NumeBoundary << " " << x1 ;
472 saux2 = saux1.str() ;
473 saux += "FAYCen " + saux2 + "\n" ;
475 { std::stringstream saux1 ;
476 saux1 << NumeBoundary << " " << x2 ;
477 saux2 = saux1.str() ;
478 saux += "FAZCen " + saux2 + "\n" ;
480 { std::stringstream saux1 ;
481 saux1 << NumeBoundary << " " << x3 ;
482 saux2 = saux1.str() ;
483 saux += "FARayon " + saux2 + "\n" ;
487 _Texte += saux + "#\n" ;
490 ////=============================================================================
491 void HomardDriver::TexteBoundaryAnGr( const std::string NameBoundary, int NumeBoundary, const std::string GroupName )
493 MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, NameBoundary = "<<NameBoundary);
494 MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, NumeBoundary = "<<NumeBoundary);
495 MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, GroupName = "<<GroupName);
499 std::string saux, saux2 ;
500 std::stringstream saux1 ;
501 saux1 << NumeBoundary ;
502 saux2 = saux1.str() ;
503 saux = "#\n# Lien Frontiere/Groupe numero " + saux2 + "\n" ;
505 saux += "FGNomFro " + saux2 + " '" + NameBoundary + "'\n" ;
506 saux += "FGNomGro " + saux2 + " '" + GroupName + "'\n" ;
508 _Texte += saux + "#\n" ;
511 ////=============================================================================
512 void HomardDriver::TexteFieldInterp( int TypeFieldInterp, const std::string FieldFile, const std::string MeshFile, int TimeStep, int Rank )
514 MESSAGE("Dans HomardDriver::TexteFieldInterp, TypeFieldInterp = "<<TypeFieldInterp);
515 MESSAGE("Dans HomardDriver::TexteFieldInterp, FieldFile = "<<FieldFile<<", MeshFile = "<<MeshFile);
516 MESSAGE("Dans HomardDriver::TexteFieldInterp, TimeStep = "<<TimeStep<<", Rank = "<<Rank);
518 // Type d'interpolation
520 _Texte += "# Interpolations des champs\n" ;
521 _Texte += "CCSolN__ " + FieldFile + "\n" ;
522 _Texte += "CCSolNP1 " + MeshFile + "\n" ;
523 if ( TypeFieldInterp == 1 )
525 _Texte += "CCChaTou oui\n" ;
528 _TimeStep = TimeStep ;
531 // std::cerr << "A la fin de TexteFieldInterp _Texte ="<<_Texte << std::endl;
533 ////=============================================================================
534 void HomardDriver::TexteFieldInterpName( int NumeChamp, const std::string FieldName)
536 MESSAGE("Dans HomardDriver::TexteFieldInterpName, NumeChamp = "<<NumeChamp<<", FieldName = "<<FieldName);
537 std::stringstream saux1 ;
538 saux1 << NumeChamp+1 ;
539 std::string saux = saux1.str() ;
540 _Texte +="CCChaNom " + saux + " \"" + FieldName + "\"\n" ;
542 MESSAGE("TexteFieldInterpName, _TimeStep = "<<_TimeStep<<", _Rank = "<<_Rank);
543 if ( _TimeStep >= 0 )
546 std::stringstream saux1 ;
548 std::string saux2 = saux1.str() ;
549 _Texte += "CCChaPdT " + saux + " " + saux2 + "\n" ;
552 std::stringstream saux1 ;
554 std::string saux2 = saux1.str() ;
555 _Texte += "CCChaNuO " + saux + " " + saux2 + "\n" ;
561 ////=============================================================================
562 void HomardDriver::CreeFichier( )
565 _NomFichierConf = _NomFichierConfBase + "." + _siter + ".vers." + _siterp1 ;
567 std::ofstream FicConf(_NomFichierConf.c_str(), std::ios::out ) ;
568 if (FicConf.is_open() == true)
570 FicConf << _Texte << std::endl ;
576 ////=============================================================================
577 int HomardDriver::ExecuteHomard()
579 // Copie des Fichiers HOMARD
580 std::string commande= "cp " + _NomFichierConf + " " + _NomFichierConfBase ;
581 system(commande.c_str());
583 MESSAGE("ExecuteHomard");
584 int codret = system(_HOMARD_Exec.c_str()) ;
587 // GERALD -- QMESSAGE BOX
588 MESSAGE ( "Erreur en executant HOMARD : " << codret );
589 // ASSERT("Erreur en executant HOMARD" == 0);