Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/homard.git] / src / HOMARD / HomardDriver.cxx
1 //  HOMARD HOMARD : implementaion of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011  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.
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 <string.h>
23 #include <unistd.h>
24 #include <sys/stat.h>
25
26 #include "Utils_SALOME_Exception.hxx"
27 #include "utilities.h"
28 #include "HomardDriver.hxx"
29
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 )
36 {
37 // Memorisation du nom complet de l'executable HOMARD
38   char* dirchar; char* execchar;
39   std::string dir;
40   std::string executable;
41   if ( !(dirchar = getenv("HOMARD_REP_EXE")) )
42     dir = "/logiciels/HOMARD/HOMARD_PUBLIC/Linux64" ;
43   else
44     dir = std::string(dirchar);
45   if ( !(execchar = getenv("HOMARD_EXE")) )
46     executable = "HOMARD";
47   else
48     executable = std::string(execchar);
49   _HOMARD_Exec = dir + "/" + executable ;
50   MESSAGE("Dans HomardDriver::HomardDriver, _HOMARD_Exec ="<<_HOMARD_Exec);
51 //
52   _siter = siter ;
53   _siterp1 = siterp1 ;
54 }
55
56 //=============================================================================
57 //=============================================================================
58 HomardDriver::~HomardDriver()
59 {
60 }
61
62 ////=============================================================================
63 void HomardDriver::TexteInit( const std::string DirCompute, const std::string DirComputePa, const std::string MessFile )
64 {
65   MESSAGE("Dans HomardDriver::TexteInit, MessFile ="<<MessFile);
66 //
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" ;
76 //
77 }
78
79 ////=============================================================================
80 void HomardDriver::TexteMaillage( const std::string NomMesh, const std::string MeshFile, int apres )
81 {
82   MESSAGE("Dans HomardDriver::TexteMaillage, NomMesh ="<<NomMesh<<", MeshFile ="<<MeshFile);
83   std::string saux ;
84   saux = "P1" ;
85   if ( apres < 1 ) { saux = "__" ; }
86
87   _Texte += "# Maillages Med " + saux + "\n" ;
88   _Texte += "CCNoMN" + saux + " \"" + NomMesh  + "\"\n" ;
89   _Texte += "CCMaiN" + saux + " " + MeshFile + "\n" ;
90 }
91
92 ////=============================================================================
93 void HomardDriver::TexteConfRaffDera( int ConfType, int TypeAdap, int TypeRaff, int TypeDera )
94 {
95   MESSAGE("Dans HomardDriver::TexteConfRaffDera, ConfType ="<<ConfType);
96   MESSAGE("Dans HomardDriver::TexteConfRaffDera, TypeAdap ="<<TypeAdap<<", TypeRaff ="<<TypeRaff<<", TypeDera ="<<TypeDera);
97 //
98 // Type de conformite
99 //
100   std::string saux ;
101   switch (ConfType)
102   {
103     case 1: //
104     {
105       saux = "conforme" ;
106       break;
107     }
108     case 2: //
109     {
110       saux = "non_conforme_1_noeud" ;
111       break;
112     }
113     case 3: //
114     {
115       saux = "non_conforme_1_arete" ;
116       break;
117     }
118     case 4: //
119     {
120       saux = "non_conforme_indicateur" ;
121       break;
122     }
123   }
124   _Texte += "# Type de conformite\nTypeConf " + saux + "\n" ;
125 //
126 // Type de raffinement/deraffinement
127 //
128   if ( TypeAdap == -1 )
129   {
130     if ( TypeRaff == 1 )
131     {
132       saux = "TypeRaff uniforme\n" ;
133     }
134     else
135     {
136       saux = "TypeRaff non\n" ;
137     }
138     if ( TypeDera == 1 )
139     {
140       saux += "TypeDera uniforme" ;
141     }
142     else
143     {
144       saux += "TypeDera non" ;
145     }
146   }
147   else
148   {
149     if ( TypeRaff == 1 )
150     {
151       saux = "TypeRaff libre\n" ;
152     }
153     else
154     {
155       saux = "TypeRaff non\n" ;
156     }
157     if ( TypeDera == 1 )
158     {
159       saux += "TypeDera libre" ;
160     }
161     else
162     {
163       saux += "TypeDera non" ;
164     }
165   }
166   _Texte += "# Type de raffinement/deraffinement\n" + saux + "\n" ;
167 //
168 //   MESSAGE("A la fin de HomardDriver::TexteConfRaffDera, _Texte ="<<_Texte);
169 }
170 ////=============================================================================
171 void HomardDriver::TexteCompo( int NumeComp, const std::string NompCompo)
172 {
173   MESSAGE("Dans HomardDriver::TexteCompo, NumeComp = "<<NumeComp<<", NompCompo = "<<NompCompo);
174   _Texte +="CCCoChaI \"" + NompCompo + "\"\n" ;
175 }
176
177 ////=============================================================================
178 void HomardDriver::TexteZone( int NumeZone, int ZoneType, double x0, double x1, double x2, double x3, double x4, double x5 )
179 {
180   MESSAGE("Dans HomardDriver::TexteZone, NumeZone = "<<NumeZone<<", ZoneType = "<<ZoneType);
181   MESSAGE("Dans HomardDriver::TexteZone, coor = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5);
182 //
183   std::string saux, saux2 ;
184 //
185 // Type de zones
186 //
187   std::stringstream saux1 ;
188   saux1 << NumeZone ;
189   saux2 = saux1.str() ;
190   saux = "#\n# Zone numero " + saux2 + "\n" ;
191 //
192   { std::stringstream saux1 ;
193     saux1 << NumeZone << " " << ZoneType ;
194     saux2 = saux1.str() ;
195     saux += "ZoRaType " + saux2 + "\n" ;
196   }
197 //
198 // Cas du rectangle/parallelepipede
199 //
200   if ( ZoneType == 2 )
201   {
202     saux += "# Boite\n" ;
203     { std::stringstream saux1 ;
204       saux1 << NumeZone << " " << x0 ;
205       saux2 = saux1.str() ;
206       saux += "ZoRaXmin " + saux2 + "\n" ;
207     }
208     { std::stringstream saux1 ;
209       saux1 << NumeZone << " " << x1 ;
210       saux2 = saux1.str() ;
211       saux += "ZoRaXmax " + saux2 + "\n" ;
212     }
213     { std::stringstream saux1 ;
214       saux1 << NumeZone << " " << x2 ;
215       saux2 = saux1.str() ;
216       saux += "ZoRaYmin " + saux2 + "\n" ;
217     }
218     { std::stringstream saux1 ;
219       saux1 << NumeZone << " " << x3 ;
220       saux2 = saux1.str() ;
221       saux += "ZoRaYmax " + saux2 + "\n" ;
222     }
223     { std::stringstream saux1 ;
224       saux1 << NumeZone << " " << x4 ;
225       saux2 = saux1.str() ;
226       saux += "ZoRaZmin " + saux2 + "\n" ;
227     }
228     { std::stringstream saux1 ;
229       saux1 << NumeZone << " " << x5 ;
230       saux2 = saux1.str() ;
231       saux += "ZoRaZmax " + saux2 + "\n" ;
232     }
233   }
234 //
235 // Cas du cercle/sphere
236 //
237   else if ( ZoneType == 4 )
238   {
239     saux += "# Sphere\n" ;
240     { std::stringstream saux1 ;
241       saux1 << NumeZone << " " << x0 ;
242       saux2 = saux1.str() ;
243       saux += "ZoRaXCen " + saux2 + "\n" ;
244     }
245     { std::stringstream saux1 ;
246       saux1 << NumeZone << " " << x1 ;
247       saux2 = saux1.str() ;
248       saux += "ZoRaYCen " + saux2 + "\n" ;
249     }
250     { std::stringstream saux1 ;
251       saux1 << NumeZone << " " << x2 ;
252       saux2 = saux1.str() ;
253       saux += "ZoRaZCen " + saux2 + "\n" ;
254     }
255     { std::stringstream saux1 ;
256       saux1 << NumeZone << " " << x3 ;
257       saux2 = saux1.str() ;
258       saux += "ZoRaRayo " + saux2 + "\n" ;
259     }
260   }
261 //
262   _Texte += saux + "#\n" ;
263 //
264 //   MESSAGE("A la fin de HomardDriver::TexteZone, _Texte ="<<_Texte);
265 }
266
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 )
270 {
271   MESSAGE("Dans HomardDriver::TexteField, FieldName = "<<FieldName<<", FieldFile = "<<FieldFile);
272   MESSAGE("Dans HomardDriver::TexteField, TimeStep = "<<TimeStep<<", Rank = "<<Rank);
273
274   std::string saux, saux2 ;
275 //
276 //
277   _Texte += "# Champ d'indicateurs\n" ;
278   _Texte += "CCIndica " + FieldFile  + "\n" ;
279   _Texte += "CCNoChaI \"" + FieldName  + "\"\n" ;
280
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 )
286   {
287     {
288       std::stringstream saux1 ;
289       saux1 << TimeStep ;
290       saux2 = saux1.str() ;
291       _Texte += "CCNumPTI " + saux2  + "\n" ;
292     }
293     {
294       std::stringstream saux1 ;
295       saux1 << Rank ;
296       saux2 = saux1.str() ;
297       _Texte += "CCNumOrI " + saux2  + "\n" ;
298     }
299   }
300 //
301   saux = " " ;
302   if ( TypeThR == 1 )
303   { saux = "Hau" ; }
304   if ( TypeThR == 2 )
305   { saux = "HRe" ; }
306   if ( TypeThR == 3 )
307   { saux = "HPE" ; }
308   if ( saux != " " )
309   {
310     std::stringstream saux1 ;
311     saux1 << ThreshR ;
312     saux2 = saux1.str() ;
313     _Texte += "Seuil" + saux + " " + saux2  + "\n" ;
314   }
315 //
316   saux = " " ;
317   if ( TypeThC == 1 )
318   { saux = "Bas" ; }
319   if ( TypeThC == 2 )
320   { saux = "BRe" ; }
321   if ( TypeThC == 3 )
322   { saux = "BPE" ; }
323   if ( saux != " " )
324   {
325     std::stringstream saux1 ;
326     saux1 << ThreshC ;
327     saux2 = saux1.str() ;
328     _Texte += "Seuil" + saux + " " + saux2  + "\n" ;
329   }
330 //
331   saux = " " ;
332   if ( UsCmpI == 0 )
333   { saux = "L2" ; }
334   if ( UsCmpI == 1 )
335   { saux = "INFINI" ; }
336   if ( UsCmpI == 2 )
337   { saux = "V_RELATIVE" ; }
338   if ( saux != " " )
339   {
340     _Texte += "CCUsCmpI " + saux  + "\n" ;
341   }
342 }
343
344 ////=============================================================================
345 void HomardDriver::TexteGroup( const std::string GroupName )
346 {
347   MESSAGE("Dans HomardDriver::TexteGroup, GroupName = "<<GroupName);
348 //
349   _Texte += "CCGroAda " + GroupName  + "\n" ;
350 //
351 }
352 ////=============================================================================
353 void HomardDriver::TexteBoundaryOption( int BoundaryOption )
354 {
355   MESSAGE("Dans HomardDriver::TexteBoundaryOption, BoundaryOption = "<<BoundaryOption);
356 //
357 // Type de suivi de frontiere
358 //
359   std::stringstream saux1 ;
360   saux1 << BoundaryOption ;
361   std::string saux = saux1.str() ;
362   _Texte += "SuivFron " + saux + "\n" ;
363 //
364 }
365 ////=============================================================================
366 void HomardDriver::TexteBoundaryDi(  const std::string MeshName, const std::string MeshFile )
367 {
368   MESSAGE("Dans HomardDriver::TexteBoundaryDi, MeshName  = "<<MeshName);
369   MESSAGE("Dans HomardDriver::TexteBoundaryDi, MeshFile  = "<<MeshFile);
370 //
371   _Texte += "CCNoMFro " + MeshName + "\n" ;
372   _Texte += "CCFronti " + MeshFile + "\n" ;
373 //
374 }
375 ////=============================================================================
376 void HomardDriver::TexteBoundaryDiGr(  const std::string GroupName )
377 {
378   MESSAGE("Dans HomardDriver::TexteBoundaryDiGr, GroupName  = "<<GroupName);
379 //
380   _Texte += "CCGroFro " + GroupName + "\n" ;
381 //
382 }
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 )
385 {
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);
390 //
391   std::string saux, saux2 ;
392 //
393 // Commentaires
394 //
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" ; }
403 //
404 // Le nom de la frontiere
405 //
406   { std::stringstream saux1 ;
407     saux1 << NumeBoundary ;
408     saux2 = saux1.str() ;
409     saux += "FANom " + saux2 + " '" + NameBoundary + "'\n" ;
410   }
411 //
412 // Type de frontiere
413 //
414   { std::stringstream saux1 ;
415     saux1 << NumeBoundary << " " << BoundaryType ;
416     saux2 = saux1.str() ;
417     saux += "FAType " + saux2 + "\n" ;
418   }
419 //
420 // Cas du cylindre
421 //
422   if ( BoundaryType == 1 )
423   {
424     { std::stringstream saux1 ;
425       saux1 << NumeBoundary << " " << x0 ;
426       saux2 = saux1.str() ;
427       saux += "FAXCen " + saux2 + "\n" ;
428     }
429     { std::stringstream saux1 ;
430       saux1 << NumeBoundary << " " << x1 ;
431       saux2 = saux1.str() ;
432       saux += "FAYCen " + saux2 + "\n" ;
433     }
434     { std::stringstream saux1 ;
435       saux1 << NumeBoundary << " " << x2 ;
436       saux2 = saux1.str() ;
437       saux += "FAZCen " + saux2 + "\n" ;
438     }
439     { std::stringstream saux1 ;
440       saux1 << NumeBoundary << " " << x3 ;
441       saux2 = saux1.str() ;
442       saux += "FAXAxe " + saux2 + "\n" ;
443     }
444     { std::stringstream saux1 ;
445       saux1 << NumeBoundary << " " << x4 ;
446       saux2 = saux1.str() ;
447       saux += "FAYAxe " + saux2 + "\n" ;
448     }
449     { std::stringstream saux1 ;
450       saux1 << NumeBoundary << " " << x5 ;
451       saux2 = saux1.str() ;
452       saux += "FAZAxe " + saux2 + "\n" ;
453     }
454      { std::stringstream saux1 ;
455       saux1 << NumeBoundary << " " << x6 ;
456       saux2 = saux1.str() ;
457       saux += "FARayon " + saux2 + "\n" ;
458     }
459  }
460 //
461 // Cas de la sphere
462 //
463   else if ( BoundaryType == 2 )
464   {
465     { std::stringstream saux1 ;
466       saux1 << NumeBoundary << " " << x0 ;
467       saux2 = saux1.str() ;
468       saux += "FAXCen " + saux2 + "\n" ;
469     }
470     { std::stringstream saux1 ;
471       saux1 << NumeBoundary << " " << x1 ;
472       saux2 = saux1.str() ;
473       saux += "FAYCen " + saux2 + "\n" ;
474     }
475     { std::stringstream saux1 ;
476       saux1 << NumeBoundary << " " << x2 ;
477       saux2 = saux1.str() ;
478       saux += "FAZCen " + saux2 + "\n" ;
479     }
480     { std::stringstream saux1 ;
481       saux1 << NumeBoundary << " " << x3 ;
482       saux2 = saux1.str() ;
483       saux += "FARayon " + saux2 + "\n" ;
484     }
485   }
486 //
487   _Texte += saux + "#\n" ;
488 //
489 }
490 ////=============================================================================
491 void HomardDriver::TexteBoundaryAnGr( const std::string NameBoundary, int NumeBoundary, const std::string GroupName )
492 {
493   MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, NameBoundary  = "<<NameBoundary);
494   MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, NumeBoundary  = "<<NumeBoundary);
495   MESSAGE("Dans HomardDriver::TexteBoundaryAnGr, GroupName  = "<<GroupName);
496 //
497 // Commentaires
498 //
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" ;
504 //
505   saux += "FGNomFro " + saux2 + " '" + NameBoundary + "'\n" ;
506   saux += "FGNomGro " + saux2 + " '" + GroupName + "'\n" ;
507 //
508   _Texte += saux + "#\n" ;
509 //
510 }
511 ////=============================================================================
512 void HomardDriver::TexteFieldInterp( int TypeFieldInterp, const std::string FieldFile, const std::string MeshFile, int TimeStep, int Rank )
513 {
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);
517 //
518 // Type d'interpolation
519 //
520   _Texte += "# Interpolations des champs\n" ;
521   _Texte += "CCSolN__ " + FieldFile  + "\n" ;
522   _Texte += "CCSolNP1 " + MeshFile  + "\n" ;
523   if ( TypeFieldInterp == 1 )
524   {
525     _Texte += "CCChaTou oui\n" ;
526   }
527 //
528   _TimeStep = TimeStep ;
529   _Rank = Rank ;
530 //
531 //  std::cerr << "A la fin de TexteFieldInterp _Texte ="<<_Texte << std::endl;
532 }
533 ////=============================================================================
534 void HomardDriver::TexteFieldInterpName( int NumeChamp, const std::string FieldName)
535 {
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" ;
541 //
542   MESSAGE("TexteFieldInterpName, _TimeStep = "<<_TimeStep<<", _Rank = "<<_Rank);
543   if ( _TimeStep >= 0 )
544   {
545     {
546       std::stringstream saux1 ;
547       saux1 << _TimeStep ;
548       std::string saux2 = saux1.str() ;
549       _Texte += "CCChaPdT " + saux + " " + saux2  + "\n" ;
550     }
551     {
552       std::stringstream saux1 ;
553       saux1 << _Rank ;
554       std::string saux2 = saux1.str() ;
555       _Texte += "CCChaNuO " + saux + " " + saux2  + "\n" ;
556     }
557   }
558 }
559
560
561 ////=============================================================================
562 void HomardDriver::CreeFichier( )
563 {
564 //
565   _NomFichierConf = _NomFichierConfBase + "." + _siter + ".vers." + _siterp1 ;
566 //
567   std::ofstream FicConf(_NomFichierConf.c_str(), std::ios::out ) ;
568   if (FicConf.is_open() == true)
569   {
570     FicConf << _Texte << std::endl ;
571   }
572   FicConf.close() ;
573 //
574 }
575
576 ////=============================================================================
577 int HomardDriver::ExecuteHomard()
578 {
579 // Copie des Fichiers HOMARD
580   std::string commande= "cp " + _NomFichierConf + " " + _NomFichierConfBase ;
581   system(commande.c_str());
582
583   MESSAGE("ExecuteHomard");
584   int codret = system(_HOMARD_Exec.c_str()) ;
585   if ( codret != 0)
586   {
587       // GERALD -- QMESSAGE BOX
588       MESSAGE ( "Erreur en executant HOMARD : " << codret );
589 //       ASSERT("Erreur en executant HOMARD" == 0);
590   };
591
592   return codret ;
593 }