Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPT / YACSDriver.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2020  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 // Pilote l'ecriture du fichier xml pour lancer un schema YACS
23
24 #include <cstring>
25 #ifndef WIN32
26 #include <unistd.h>
27 #endif
28 #include <sys/stat.h>
29
30 #include "YACSDriver.hxx"
31 #include "HOMARD.hxx"
32 #include "Utils_SALOME_Exception.hxx"
33 #include "utilities.h"
34
35 //=============================================================================
36 //=============================================================================
37 YACSDriver::YACSDriver(const std::string XMLFile, const std::string DirName, const std::string LangueShort):
38   _XMLFile( "" ), _DirName( "" ),
39   _Texte( "" ),
40   _Texte_parametres( "" ),
41   _noeud_1( "CreateCase" ),
42   _LangueShort( "" ),
43   _bLu( false )
44 {
45   MESSAGE("XMLFile = "<<XMLFile<<", DirName ="<<DirName);
46   _XMLFile = XMLFile;
47   _DirName = DirName;
48   _LangueShort = LangueShort;
49 }
50 //=============================================================================
51 //=============================================================================
52 YACSDriver::~YACSDriver()
53 {
54 }
55 //===============================================================================
56 // Ajout d'une ligne simple
57 //===============================================================================
58 void YACSDriver::TexteAdd( const std::string ligne )
59 {
60 //   MESSAGE("TexteAdd, ligne ="<<ligne);
61 //
62   _Texte += ligne + "\n" ;
63 //
64 }
65 //===============================================================================
66 // Nom du fichier du maillage initial
67 //===============================================================================
68 void YACSDriver::Texte_DataInit_MeshFile( const std::string Meshfile )
69 {
70   MESSAGE("TexteInitMeshfile, Meshfile ="<<Meshfile);
71 //
72   _Texte += "         <value><string>" ;
73   _Texte += Meshfile ;
74   _Texte += "</string></value>\n" ;
75 //
76 }
77 //===============================================================================
78 // Le repertoire de calcul
79 // Le script de lancement
80 //===============================================================================
81 void YACSDriver::Texte_Alternance_Calcul_HOMARD_Calcul( const std::string FileName )
82 {
83   MESSAGE("Texte_Alternance_Calcul_HOMARD_Calcul, FileName : "<<FileName);
84 //
85   int position = FileName.find_last_of( '/' ) ;
86   std::string nomfic = FileName.substr( position+1 ) ;
87   position = nomfic.find_last_of( '.' ) ;;
88   nomfic = nomfic.substr( 0, position ) ;
89   MESSAGE("nomfic : "<<nomfic) ;
90 //
91   _Texte += "rep_calc = \"" + _DirName + "\"\n" ;
92   _Texte += "rep_script = os.path.dirname(\"" + FileName + "\")\n" ;
93   _Texte += "sys.path.append(rep_script)\n" ;
94   _Texte += "from " + nomfic + " import Script\n" ;
95 //
96 }
97 //===============================================================================
98 // Les options du cas
99 //===============================================================================
100 void YACSDriver::Texte_Iter_1_Case_Options( const std::string pythonTexte )
101 {
102   MESSAGE("Texte_Iter_1_Case_Options, pythonTexte\n"<<pythonTexte);
103 //
104   _Texte += "DirName = \"" + _DirName + "/HOMARD\"\n" ;
105   _Texte += "Case.SetDirName(DirName)\n" ;
106
107   Texte_python_1( pythonTexte, 1, "Case" ) ;
108 //
109 }
110 //===============================================================================
111 // La description des zones
112 // ZoneType : le type de la zone
113 // pythonStructure : le python correspondant a la zone
114 // methode : methode associee a la creation de la zone
115 // ZoneName : nom de la zone
116 //===============================================================================
117 std::string YACSDriver::Texte_Iter_1_Zone( int ZoneType, const std::string pythonStructure, const std::string methode, const std::string ZoneName )
118 {
119   MESSAGE("Texte_Iter_1_Zone, ZoneType = "<<ZoneType<<", pythonStructure = "<<pythonStructure);
120   MESSAGE("methode = "<<methode<<", ZoneName = "<<ZoneName );
121 //
122 // 1. Le nom du noeud
123   std::string noeud_2 = methode + "_" + ZoneName ;
124   std::string node ;
125   if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
126   else                        { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
127   node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1." ;
128   node += noeud_2 ;
129 // 2. Texte de controle : le noeud precedent est _noeud_1, le noeud courant noeud_2.
130 //                        A la fin, on bascule le courant dans le precedent
131   std::string texte_control = Texte_control (_noeud_1, noeud_2, 1) ;
132   _noeud_1 = noeud_2 ;
133 // 3. Definition du service
134   std::string motcle ;
135   _Texte += "                           <service name=\"" + noeud_2 + "\">\n" ;
136   INFOS("_LangueShort = "<<_LangueShort );
137   if ( _LangueShort == "fr" ) { motcle = "Etude_Initialisation" ; }
138   else                        { motcle = "Study_Initialisation" ; }
139   INFOS("motcle = "<<motcle );
140   _Texte += "                              <node>" + motcle + ".UpdateStudy</node>\n" ;
141   _Texte += "                              <method>" + methode + "</method>\n" ;
142 // 4. Les inports
143 // 4.1. Le nom de la zone
144   _Texte += Texte_inport( "string", "ZoneName" ) ;
145    TexteParametre( node, "ZoneName", "string", ZoneName ) ;
146 // 4.2. Les valeurs numeriques
147 //      ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc ADAPT_Gen.idl
148 // 4.2.1. Decodage des valeurs
149 // La chaine pythonStructure est de ce genre :
150 //   CreateZoneBox( "Zone_1", 0.144, 0.216, 0.096, 0.1464, 0.076, 0.12)
151   std::string ligne = pythonStructure ;
152 // On commence par ne garder que ce qui suit la premiere virgule
153   ligne = GetStringInTexte( ligne, ",", 1 );
154 // On boucle pour isoler toutes les chaines dans les virgules
155   std::string lignebis ;
156   std::string x0, x1, x2, x3, x4, x5, x6, x7, x8  ;
157   int iaux = 0  ;
158   while ( ligne != lignebis )
159   {
160     lignebis = GetStringInTexte ( ligne, ",", 0 ) ;
161 //     MESSAGE("lignebis = "<<lignebis );
162     if      ( iaux == 0 ) { x0 = lignebis ; }
163     else if ( iaux == 1 ) { x1 = lignebis ; }
164     else if ( iaux == 2 ) { x2 = lignebis ; }
165     else if ( iaux == 3 ) { x3 = lignebis ; }
166     else if ( iaux == 4 ) { x4 = lignebis ; }
167     else if ( iaux == 5 ) { x5 = lignebis ; }
168     else if ( iaux == 6 ) { x6 = lignebis ; }
169     else if ( iaux == 7 ) { x7 = lignebis ; }
170     ligne = GetStringInTexte( ligne, ",", 1 );
171     iaux += 1 ;
172   }
173 // La derniere valeur est toujours mise dans x8
174   x8 = GetStringInTexte ( ligne, ")", 0 ) ;
175   MESSAGE("coor = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5<<","<<x6<<","<<x7<<","<<x8);
176 // 4.2.2. Cas du parallelepipede (2)
177   if ( ZoneType == 2 )
178   {
179     _Texte += Texte_inport( "double", "Xmini" ) ;
180     _Texte += Texte_inport( "double", "Xmaxi" ) ;
181     _Texte += Texte_inport( "double", "Ymini" ) ;
182     _Texte += Texte_inport( "double", "Ymaxi" ) ;
183     _Texte += Texte_inport( "double", "Zmini" ) ;
184     _Texte += Texte_inport( "double", "Zmaxi" ) ;
185     TexteParametre( node, "Xmini", "double", x0 ) ;
186     TexteParametre( node, "Xmaxi", "double", x1 ) ;
187     TexteParametre( node, "Ymini", "double", x2 ) ;
188     TexteParametre( node, "Ymaxi", "double", x3 ) ;
189     TexteParametre( node, "Zmini", "double", x4 ) ;
190     TexteParametre( node, "Zmaxi", "double", x8 ) ;
191   }
192 //
193 // 4.2.3. Cas du rectangle (11, 12, 13)
194   else if ( ( ZoneType > 10 ) && ( ZoneType < 14 ) )
195   {
196     _Texte += Texte_inport( "double", "Umini" ) ;
197     _Texte += Texte_inport( "double", "Umaxi" ) ;
198     _Texte += Texte_inport( "double", "Vmini" ) ;
199     _Texte += Texte_inport( "double", "Vmaxi" ) ;
200     _Texte += Texte_inport( "long", "Orient" ) ;
201     TexteParametre( node, "Umini", "double", x0 ) ;
202     TexteParametre( node, "Umaxi", "double", x1 ) ;
203     TexteParametre( node, "Vmini", "double", x2 ) ;
204     TexteParametre( node, "Vmaxi", "double", x3 ) ;
205     TexteParametre( node, "Orient", "int", x8 ) ;
206   }
207 //
208 // 4.2.4. Cas du disque (31, 32, 33) ou du disque perce (61, 62, 63)
209   else if ( ( ( ZoneType > 30 ) && ( ZoneType < 34 ) ) || ( ( ZoneType > 60 ) && ( ZoneType < 64 ) ) )
210   {
211     _Texte += Texte_inport( "double", "Ucentre" ) ;
212     _Texte += Texte_inport( "double", "Vcentre" ) ;
213     _Texte += Texte_inport( "double", "Radius" ) ;
214     TexteParametre( node, "Ucentre", "double", x0 ) ;
215     TexteParametre( node, "Vcentre", "double", x1 ) ;
216     TexteParametre( node, "Radius", "double", x2 ) ;
217     if ( ZoneType > 60 )
218     {
219       _Texte += Texte_inport( "double", "InternalRadius" ) ;
220       TexteParametre( node, "InternalRadius", "double", x3 ) ;
221     }
222     _Texte += Texte_inport( "long", "Orient" ) ;
223     TexteParametre( node, "Orient", "int", x8 ) ;
224   }
225 //
226 // 4.2.5. Cas de la sphere (4)
227   else if ( ZoneType == 4 )
228   {
229     _Texte += Texte_inport( "double", "Xcentre" ) ;
230     _Texte += Texte_inport( "double", "Ycentre" ) ;
231     _Texte += Texte_inport( "double", "Zcentre" ) ;
232     _Texte += Texte_inport( "double", "Radius" ) ;
233     TexteParametre( node, "Xcentre", "double", x0 ) ;
234     TexteParametre( node, "Ycentre", "double", x1 ) ;
235     TexteParametre( node, "Zcentre", "double", x2 ) ;
236     TexteParametre( node, "Radius", "double", x8 ) ;
237   }
238 //
239 // 4.2.6. Cas du cylindre (5) ou du tuyau (7)
240   else if ( ZoneType == 5 || ZoneType == 7 )
241   {
242     _Texte += Texte_inport( "double", "Xcentre" ) ;
243     _Texte += Texte_inport( "double", "Ycentre" ) ;
244     _Texte += Texte_inport( "double", "Zcentre" ) ;
245     _Texte += Texte_inport( "double", "Xaxis" ) ;
246     _Texte += Texte_inport( "double", "Yaxis" ) ;
247     _Texte += Texte_inport( "double", "Zaxis" ) ;
248     _Texte += Texte_inport( "double", "Radius" ) ;
249     _Texte += Texte_inport( "double", "Height" ) ;
250     TexteParametre( node, "Xcentre", "double", x0 ) ;
251     TexteParametre( node, "Ycentre", "double", x1 ) ;
252     TexteParametre( node, "Zcentre", "double", x2 ) ;
253     TexteParametre( node, "Xaxis", "double", x3 ) ;
254     TexteParametre( node, "Yaxis", "double", x4 ) ;
255     TexteParametre( node, "Zaxis", "double", x5 ) ;
256     TexteParametre( node, "Radius", "double", x6 ) ;
257     if ( ZoneType == 5 )
258     {
259       TexteParametre( node, "Height", "double", x8 ) ;
260     }
261     else
262     {
263       _Texte += Texte_inport( "double", "InternalRadius" ) ;
264       TexteParametre( node, "Height", "double", x7 ) ;
265       TexteParametre( node, "InternalRadius", "double", x8 ) ;
266     }
267   }
268 //
269 // 4.2.7. Erreur
270   else
271   { VERIFICATION("Type de zone inconnu." == 0); }
272
273 //
274 // 5. La fin
275   _Texte += "                              <outport name=\"return\" type=\"HOMARD_Zone\"/>\n" ;
276   _Texte += "                           </service>\n" ;
277 //
278   return texte_control ;
279 //
280 }
281 //===============================================================================
282 // La description des frontieres
283 // BoundaryType : le type de la frontiere
284 // pythonStructure : le python correspondant a la frontiere
285 // methode : methode associee a la creation de la frontiere
286 // BoundaryName : nom de la frontiere
287 // MeshName : nom du maillage dans le cas d'une frontiere discrete
288 // MeshFile : nom du fichier du maillage dans le cas d'une frontiere discrete
289 //===============================================================================
290 std::string YACSDriver::Texte_Iter_1_Boundary( int BoundaryType, const std::string pythonStructure, const std::string methode, const std::string BoundaryName, const std::string MeshName, const std::string MeshFile )
291 {
292   MESSAGE("Texte_Iter_1_Boundary, BoundaryType = "<<BoundaryType<<", pythonStructure = "<<pythonStructure);
293   MESSAGE("methode = "<<methode<<", BoundaryName = "<<BoundaryName );
294   if (BoundaryType == 0) { MESSAGE("MeshName = "<<MeshName<<", MeshFile = "<<MeshFile ); }
295 //
296 // 1. Le nom du noeud
297   std::string noeud_2 = methode + "_" + BoundaryName ;
298   std::string node ;
299   if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
300   else                        { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
301   node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1." ;
302   node += noeud_2 ;
303 // 2. Texte de controle : le noeud precedent est _noeud_1, le noeud courant noeud_2.
304 //                        A la fin, on bascule le courant dans le precedent
305   std::string texte_control = Texte_control (_noeud_1, noeud_2, 1) ;
306   _noeud_1 = noeud_2 ;
307 // 3. Definition du service
308   std::string motcle ;
309   _Texte += "                           <service name=\"" + noeud_2 + "\">\n" ;
310   if ( _LangueShort == "fr" ) { motcle = "Etude_Initialisation" ; }
311   else                        { motcle = "Study_Initialisation" ; }
312   _Texte += "                              <node>" + motcle + ".UpdateStudy</node>\n" ;
313   _Texte += "                              <method>" + methode + "</method>\n" ;
314 // 4. Les inports
315 //    ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc ADAPT_Gen.idl
316 // 4.1. Le nom de la frontiere
317   _Texte += Texte_inport( "string", "BoundaryName" ) ;
318   TexteParametre( node, "BoundaryName", "string", BoundaryName ) ;
319 // 4.2. Cas d une frontiere discrete
320   if (BoundaryType == 0)
321   {
322     _Texte += Texte_inport( "string", "MeshName" ) ;
323     TexteParametre( node, "MeshName", "string", MeshName ) ;
324     _Texte += Texte_inport( "string", "FileName" ) ;
325     TexteParametre( node, "FileName", "string", MeshFile ) ;
326   }
327 // 4.3. Cas d'une frontiere analytique : les valeurs numeriques
328   else
329   {
330 // 4.3.1. Decodage des valeurs
331 // La chaine pythonStructure est de ce genre :
332 //   CreateBoundaryCylinder('cyl_2', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
333 //   CreateBoundaryDi("intersection", "PIQUAGE", "/scratch/D68518/Salome/script/sfr_2d_piquage.fr.med")
334     std::string ligne = pythonStructure ;
335 // On commence par ne garder que ce qui suit la premiere virgule
336     ligne = GetStringInTexte( ligne, ",", 1 );
337 // On boucle pour isoler toutes les chaines dans les virgules
338     std::string lignebis ;
339     std::string x0, x1, x2, x3, x4, x5, x6, x7  ;
340     int iaux = 0  ;
341     while ( ligne != lignebis )
342     {
343       lignebis = GetStringInTexte ( ligne, ",", 0 ) ;
344 //     MESSAGE("lignebis = "<<lignebis );
345       if      ( iaux == 0 ) { x0 = lignebis ; }
346       else if ( iaux == 1 ) { x1 = lignebis ; }
347       else if ( iaux == 2 ) { x2 = lignebis ; }
348       else if ( iaux == 3 ) { x3 = lignebis ; }
349       else if ( iaux == 4 ) { x4 = lignebis ; }
350       else if ( iaux == 5 ) { x5 = lignebis ; }
351       else if ( iaux == 6 ) { x6 = lignebis ; }
352       ligne = GetStringInTexte( ligne, ",", 1 );
353       iaux += 1 ;
354     }
355 // La derniere valeur est toujours mise dans x7
356     x7 = GetStringInTexte ( ligne, ")", 0 ) ;
357     MESSAGE("Valeurs = "<< x0<<", "<<x1<< ", "<< x2<< ", "<< x3<<", "<<x4<<", "<<x5<<", "<<x6<<", x7"<<x7);
358 //
359 // 4.3.2. Cas du cylindre (1)
360     if ( BoundaryType == 1 )
361     {
362       _Texte += Texte_inport( "double", "Xcentre" ) ;
363       _Texte += Texte_inport( "double", "Ycentre" ) ;
364       _Texte += Texte_inport( "double", "Zcentre" ) ;
365       _Texte += Texte_inport( "double", "Xaxis" ) ;
366       _Texte += Texte_inport( "double", "Yaxis" ) ;
367       _Texte += Texte_inport( "double", "Zaxis" ) ;
368       _Texte += Texte_inport( "double", "Radius" ) ;
369       TexteParametre( node, "Xcentre", "double", x0 ) ;
370       TexteParametre( node, "Ycentre", "double", x1 ) ;
371       TexteParametre( node, "Zcentre", "double", x2 ) ;
372       TexteParametre( node, "Xaxis", "double", x3 ) ;
373       TexteParametre( node, "Yaxis", "double", x4 ) ;
374       TexteParametre( node, "Zaxis", "double", x5 ) ;
375       TexteParametre( node, "Radius", "double", x7 ) ;
376     }
377 //
378 // 4.3.3. Cas de la sphere (2)
379     else if ( BoundaryType == 2 )
380     {
381       _Texte += Texte_inport( "double", "Xcentre" ) ;
382       _Texte += Texte_inport( "double", "Ycentre" ) ;
383       _Texte += Texte_inport( "double", "Zcentre" ) ;
384       _Texte += Texte_inport( "double", "Radius" ) ;
385       TexteParametre( node, "Xcentre", "double", x0 ) ;
386       TexteParametre( node, "Ycentre", "double", x1 ) ;
387       TexteParametre( node, "Zcentre", "double", x2 ) ;
388       TexteParametre( node, "Radius", "double", x7 ) ;
389     }
390 //
391 // 4.3.4. Cas d un cone defini par un axe et un angle
392     else if ( BoundaryType == 3 )
393     {
394       _Texte += Texte_inport( "double", "Xaxis" ) ;
395       _Texte += Texte_inport( "double", "Yaxis" ) ;
396       _Texte += Texte_inport( "double", "Zaxis" ) ;
397       _Texte += Texte_inport( "double", "Angle" ) ;
398       _Texte += Texte_inport( "double", "Xcentre" ) ;
399       _Texte += Texte_inport( "double", "Ycentre" ) ;
400       _Texte += Texte_inport( "double", "Zcentre" ) ;
401       TexteParametre( node, "Xaxis", "double", x0 ) ;
402       TexteParametre( node, "Yaxis", "double", x1 ) ;
403       TexteParametre( node, "Zaxis", "double", x2 ) ;
404       TexteParametre( node, "Angle", "double", x3 ) ;
405       TexteParametre( node, "Xcentre", "double", x4 ) ;
406       TexteParametre( node, "Ycentre", "double", x5 ) ;
407       TexteParametre( node, "Zcentre", "double", x7 ) ;
408     }
409 //
410 // 4.3.5. Cas d un cone defini par les 2 rayons
411     else if ( BoundaryType == 4 )
412     {
413       _Texte += Texte_inport( "double", "Xcentre1" ) ;
414       _Texte += Texte_inport( "double", "Ycentre1" ) ;
415       _Texte += Texte_inport( "double", "Zcentre1" ) ;
416       _Texte += Texte_inport( "double", "Radius1" ) ;
417       _Texte += Texte_inport( "double", "Xcentre2" ) ;
418       _Texte += Texte_inport( "double", "Ycentre2" ) ;
419       _Texte += Texte_inport( "double", "Zcentre2" ) ;
420       _Texte += Texte_inport( "double", "Radius2" ) ;
421       TexteParametre( node, "Xcentre1", "double", x0 ) ;
422       TexteParametre( node, "Ycentre1", "double", x1 ) ;
423       TexteParametre( node, "Zcentre1", "double", x2 ) ;
424       TexteParametre( node, "Radius1", "double", x3 ) ;
425       TexteParametre( node, "Xcentre2", "double", x4 ) ;
426       TexteParametre( node, "Ycentre2", "double", x5 ) ;
427       TexteParametre( node, "Zcentre2", "double", x6 ) ;
428       TexteParametre( node, "Radius2", "double", x7 ) ;
429     }
430 // 4.3.6. Cas du tore (5)
431     else if ( BoundaryType == 5 )
432     {
433       _Texte += Texte_inport( "double", "Xcentre" ) ;
434       _Texte += Texte_inport( "double", "Ycentre" ) ;
435       _Texte += Texte_inport( "double", "Zcentre" ) ;
436       _Texte += Texte_inport( "double", "Xaxis" ) ;
437       _Texte += Texte_inport( "double", "Yaxis" ) ;
438       _Texte += Texte_inport( "double", "Zaxis" ) ;
439       _Texte += Texte_inport( "double", "RRev" ) ;
440       _Texte += Texte_inport( "double", "RPri" ) ;
441       TexteParametre( node, "Xcentre", "double", x0 ) ;
442       TexteParametre( node, "Ycentre", "double", x1 ) ;
443       TexteParametre( node, "Zcentre", "double", x2 ) ;
444       TexteParametre( node, "Xaxis", "double", x3 ) ;
445       TexteParametre( node, "Yaxis", "double", x4 ) ;
446       TexteParametre( node, "Zaxis", "double", x5 ) ;
447       TexteParametre( node, "RRev", "double", x6 ) ;
448       TexteParametre( node, "RPri", "double", x7 ) ;
449     }
450 //
451 // 4.3.7. Erreur
452     else
453     { VERIFICATION("Type de frontiere inconnu." == 0); }
454   }
455 //
456 // 5. La fin
457   _Texte += "                              <outport name=\"return\" type=\"HOMARD_Boundary\"/>\n" ;
458   _Texte += "                           </service>\n" ;
459 //
460   return texte_control ;
461 //
462 }
463 //===============================================================================
464 // Fin du controle des enchainements de noeud dans le noeud Iter_1
465 //===============================================================================
466   std::string YACSDriver::Texte_Iter_1_control()
467 {
468   MESSAGE("Texte_Iter_1_control");
469 //
470   std::string texte ;
471   texte  = Texte_control (_noeud_1, "CreateHypothesis", 1) ;
472   texte += Texte_control ("CreateHypothesis", "Case_Options", 0) ;
473 //
474   return texte ;
475 //
476 }
477 //===============================================================================
478 // Controle des enchainements de noeuds
479 // noeud_1 : noeud de depart
480 // noeud_2 : noeud d'arrivee
481 // option : 0 : sans caractere de saut de ligne a la fin
482 //          1 : avec caractere de saut de ligne a la fin
483 //===============================================================================
484   std::string YACSDriver::Texte_control( const std::string noeud_1, const std::string noeud_2, int option )
485 {
486   MESSAGE("Texte_control, noeud_1 = "<<noeud_1<<", noeud_2 = "<<noeud_2<<", option = "<<option);
487 //
488   std::string texte ;
489   texte  = "                           <control> " ;
490   texte += "<fromnode>" + noeud_1 + "</fromnode>" ;
491   texte += " <tonode>"  + noeud_2 + "</tonode>" ;
492   texte += " </control>" ;
493   if ( option == 1 ) { texte += "\n" ; }
494
495   return texte ;
496 //
497 }
498 //===============================================================================
499 // Inport
500 // inport_type : type de la donnee a importer
501 // inport_nom : nom de la donnee a importer
502 //===============================================================================
503   std::string YACSDriver::Texte_inport( const std::string inport_type, const std::string inport_nom )
504 {
505 //   MESSAGE("Texte_inport, inport_type = "<<inport_type<<", inport_nom = "<<inport_nom);
506 //
507   std::string texte ;
508   texte  = "                              <inport " ;
509   texte += "name=\"" + inport_nom + "\" " ;
510   texte += "type=\"" + inport_type + "\"" ;
511   texte += "/>\n" ;
512
513   return texte ;
514 //
515 }
516 //===============================================================================
517 // Le repertoire d'execution
518 //===============================================================================
519 void YACSDriver::Texte_HOMARD_Exec_DirName( )
520 {
521   MESSAGE("Texte_HOMARD_Exec_DirName");
522 //
523   _Texte += "DirName = \"" + _DirName + "\"\n" ;
524 //
525 }
526 //===============================================================================
527 // Le nom du maillage
528 //===============================================================================
529 void YACSDriver::Texte_HOMARD_Exec_MeshName( const std::string MeshName )
530 {
531   MESSAGE("Texte_HOMARD_Exec_MeshName pour "<<MeshName);
532 //
533   _Texte += "MeshName = \"" + MeshName + "\"\n" ;
534 //
535 }
536 //===============================================================================
537 // Manipulation des instructions python - 1
538 // pythonTexte : le texte des instructions python a manipuler
539 // indice : numero de la premiere ligne voulue
540 // concept : nom du concept a inserer
541 //===============================================================================
542 void YACSDriver::Texte_python_1( const std::string pythonTexte, int indice, const std::string concept )
543 {
544   MESSAGE("Texte_python_1, pythonTexte\n"<<pythonTexte);
545   MESSAGE("indice = "<<indice<<", concept = "<<concept);
546 //
547 // Conversion de type
548   std::istringstream tout (pythonTexte) ;
549 //   MESSAGE("\ntout :"<<tout);
550   std::string ligne; // variable contenant chaque ligne de python
551   std::string ligne_bis ; // variable contenant la portion de ligne de python apres '.'
552   int cptr = 0 ;
553   indice -= 1 ;
554   while ( std::getline( tout, ligne ) )
555   {
556     if ( cptr > indice )
557     {
558       int position = ligne.find_first_of( "." ) ;
559       MESSAGE("\nposition : "<< position);
560       if ( position > 0 )
561       {
562         ligne_bis = ligne.substr( position );
563         MESSAGE("\nligne_bis : "<< ligne_bis);
564         _Texte += concept + ligne_bis + "\n" ;
565       }
566     }
567     cptr += 1 ;
568   }
569 //
570 }
571 //===============================================================================
572 // Manipulation des instructions python - 2
573 // pythonTexte : le texte des instructions python a manipuler
574 // mot_cle : mot-cle dans les lignes a inserer
575 // concept : nom du concept a inserer
576 //===============================================================================
577 void YACSDriver::Texte_python_2( const std::string pythonTexte, const std::string mot_cle, const std::string concept )
578 {
579   MESSAGE("Texte_python_2, pythonTexte\n"<<pythonTexte);
580   MESSAGE("mot_cle = "<<mot_cle<<", concept = "<<concept);
581 //
582 // Conversion de type
583   std::istringstream tout (pythonTexte) ;
584 //   MESSAGE("\ntout :"<<tout);
585   std::string ligne; // variable contenant chaque ligne de python
586   std::string ligne_bis ; // variable contenant la portion de ligne de python apres '.'
587   while ( std::getline( tout, ligne ) )
588   {
589     int reperage = ligne.find( mot_cle ) ;
590     if ( reperage > 0 )
591     {
592       int position = ligne.find_first_of( "." ) ;
593 //       MESSAGE("\nposition : "<< position);
594       if ( position > 0 )
595       {
596         ligne_bis = ligne.substr( position );
597 //         MESSAGE("\nligne_bis : "<< ligne_bis);
598         _Texte += concept + ligne_bis + "\n" ;
599       }
600     }
601   }
602 //
603 }
604 //===============================================================================
605 // Parametres de tests de convergence
606 //===============================================================================
607 void YACSDriver::TexteAnalyse_Test_Convergence( int MaxIter, int MaxNode, int MaxElem )
608 {
609 //
610 //   MESSAGE("TexteAnalyse_Test_Convergence");
611   std::string chaine ;
612   std::ostringstream oss1;
613   oss1 << MaxIter;
614   chaine = oss1.str();
615   _Texte += "MaxIter = " + chaine + "\n" ;
616   std::ostringstream oss2;
617   oss2 << MaxNode;
618   chaine = oss2.str();
619   _Texte += "MaxNode = " + chaine + "\n" ;
620   std::ostringstream oss3;
621   oss3 << MaxElem;
622   chaine = oss3.str();
623   _Texte += "MaxElem = " + chaine + "\n" ;
624 //
625 }
626 //===============================================================================
627 // Creation d'un parametre
628 //===============================================================================
629 void YACSDriver::TexteParametre( const std::string node, const std::string port, const std::string type_value, const std::string value )
630 {
631 //
632 //   MESSAGE("TexteParametre");
633   _Texte_parametres += "   <parameter>\n" ;
634   _Texte_parametres += "      <tonode>" + node + "</tonode>" ;
635   _Texte_parametres += "<toport>" + port + "</toport>\n" ;
636   _Texte_parametres += "      <value><" + type_value + ">" + value + "</" + type_value + "></value>\n" ;
637   _Texte_parametres += "   </parameter>\n" ;
638 //
639 }
640 //===============================================================================
641 // Ajout des parametres
642 //===============================================================================
643 void YACSDriver::TexteAddParametres( )
644 {
645 //
646   MESSAGE("TexteAddParametres");
647   TexteAdd(_Texte_parametres) ;
648 //
649 }
650 //===============================================================================
651 void YACSDriver::CreeFichier( )
652 {
653 //
654   MESSAGE("CreeFichier sur le fichier "<<_XMLFile);
655   std::ofstream Fic(_XMLFile.c_str(), std::ios::out ) ;
656   if (Fic.is_open() == true) { Fic << _Texte << std::endl ; }
657   Fic.close() ;
658 //
659 }
660 //===============================================================================
661 // REMARQUE : on devrait utiliser le GetStringInTexte de ADAPT_Gen_i mais je ne sais pas
662 //            comment l'appeler. ALors je clone.
663 // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte
664 // ligne : la ligne a manipuler
665 // texte : le texte a reperer
666 // option : 0 : la chaine avant le texte
667 //          1 : la chaine apres le texte
668 // Si le texte est absent, on retourne la chaine totale
669 //===============================================================================
670 std::string YACSDriver::GetStringInTexte( const std::string ligne, const std::string texte, int option )
671 {
672 //   MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
673 //
674   std::string chaine = ligne ;
675   int position = ligne.find_first_of( texte ) ;
676   if ( position > 0 )
677   {
678     if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
679     else               { chaine = ligne.substr( position+1 ) ; }
680   }
681 // Conversion de type
682   return chaine ;
683 //
684 }