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