Salome HOME
a41217d2fd203b43b3be3444ef9ce99fd8e3b701
[modules/homard.git] / src / HOMARD / HOMARD_DriverTools.cxx
1 // Copyright (C) 2011-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  File   : HOMARD_DriverTools.cxx
20 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21 //
22 // ----------------------------------------------------------------------------
23
24 #include "HOMARD_DriverTools.hxx"
25 #include "HOMARD_Boundary.hxx"
26 #include "HOMARD_Cas.hxx"
27 #include "HOMARD_Hypothesis.hxx"
28 #include "HOMARD_Iteration.hxx"
29 #include "HOMARD_Zone.hxx"
30 #include "HOMARD_YACS.hxx"
31 #include <sstream>
32 #include <cstdlib>
33 #include "utilities.h"
34
35 namespace HOMARD
36 {
37
38   std::string SEPARATOR = "|" ;
39
40   /*!
41     \brief Read next chunk of data from the string
42     \internal
43
44     The function tries to read next chunk of the data from the input string \a str.
45     The parameter \a start specifies the start position of next chunk. If the operation
46     read the chunk successfully, after its completion this parameter will refer to the
47     start position of the next chunk. The function returns resulting chunk as a string.
48     The status of the operation is returned via \a ok parameter.
49
50     \param str source data stream string
51     \param start start position to get next chunk
52     \param ok in this variable the status of the chunk reading operation is returned
53     \return next chunk read from the string
54   */
55   static std::string getNextChunk( const std::string& str, std::string::size_type& start, bool& ok )
56   {
57     std::string chunk = "";
58     ok = false;
59     if ( start <= str.size() ) {
60       std::string::size_type end = str.find( separator(), start );
61       chunk = str.substr( start, end == std::string::npos ? std::string::npos : end-start );
62       start = end == std::string::npos ? str.size()+1 : end + separator().size();
63       ok = true;
64     }
65     return chunk;
66   }
67
68   /*!
69     \brief Get persistence signature
70     \param type persistence entity type
71     \return persistence signature
72   */
73   std::string GetSignature( SignatureType type )
74   {
75     std::string signature = "";
76     switch ( type ) {
77     case Case:       signature = "CASE"; break;
78     case Zone:       signature = "ZONE"; break;
79     case Hypothesis: signature = "HYPO"; break;
80     case Iteration:  signature = "ITER"; break;
81     case Boundary:   signature = "BOUNDARY"; break;
82     case YACS:       signature = "YACS"; break;
83     default: break;
84     }
85     signature += separator();
86     return signature;
87   }
88
89   /*!
90     \brief Get data separator
91     \return string that is used to separate data entities in the stream
92   */
93   std::string separator()
94   {
95     return SEPARATOR ;
96   }
97
98 // =======================
99 // 1.1. Case
100 // =======================
101   /*!
102     \brief Dump case to the string
103     \param cas case being dumped
104     \return string representation of the case
105   */
106   std::string Dump( const HOMARD_Cas& cas )
107   {
108     std::stringstream os;
109     std::string saux ;
110     // ...
111     MESSAGE( ". Sauvegarde du cas "<<cas.GetName());
112     os << cas.GetName();
113     os << separator() << cas.GetDirName();
114     os << separator() << cas.GetConfType();
115     os << separator() << cas.GetExtType();
116
117     std::vector<double> coor = cas.GetBoundingBox();
118     os << separator() << coor.size();
119     for ( int i = 0; i < coor.size(); i++ )
120           os << separator() << coor[i];
121
122     std::list<std::string> ListString = cas.GetIterations();
123     os << separator() << ListString.size();
124     std::list<std::string>::const_iterator it;
125     for ( it = ListString.begin(); it != ListString.end(); ++it )
126           os << separator() << *it;
127
128     ListString = cas.GetGroups();
129     os << separator() << ListString.size();
130     for ( it = ListString.begin(); it != ListString.end(); ++it )
131          os << separator() << *it;
132     ListString = cas.GetBoundaryGroup();
133     os << separator() << ListString.size();
134     for ( it = ListString.begin(); it != ListString.end(); ++it )
135          os << separator() << *it;
136
137     os << separator() << cas.GetPyram();
138
139     saux = os.str();
140 //     MESSAGE( ". Fin avec "<<saux);
141     return saux ;
142   }
143 //
144 // ==============
145 // 1.2. Iteration
146 // ==============
147 //
148   /*!
149     \brief Dump iteration to the string
150     \param iteration iteration being dumped
151     \return string representation of the iteration
152   */
153   std::string Dump( const HOMARD_Iteration& iteration )
154   {
155     std::stringstream os;
156     std::string saux ;
157     // ...
158     MESSAGE( ". Sauvegarde de l'iteration "<<iteration.GetName());
159     os << iteration.GetName();
160     os << separator() << iteration.GetState();
161     os << separator() << iteration.GetNumber();
162     os << separator() << iteration.GetMeshFile();
163     os << separator() << iteration.GetLogFile();
164     os << separator() << iteration.GetMeshName();
165     os << separator() << iteration.GetFieldFile();
166     os << separator() << iteration.GetTimeStep();
167     os << separator() << iteration.GetRank();
168     os << separator() << iteration.GetIterParentName();
169     //
170     std::list<std::string> ListString = iteration.GetIterations();
171     os << separator() << ListString.size();
172     std::list<std::string>::const_iterator it;
173     for ( it = ListString.begin(); it != ListString.end(); ++it )
174       os << separator() << *it;
175
176     os << separator() << iteration.GetHypoName();
177     os << separator() << iteration.GetCaseName();
178     os << separator() << iteration.GetDirNameLoc();
179
180     saux = os.str();
181 //     MESSAGE( ". Fin avec "<<saux);
182     return saux ;
183   }
184 //
185 // ==============
186 // 1.3. hypothese
187 // ==============
188   /*!
189     \brief Dump hypothesis to the string
190     \param hypothesis hypothesis being dumped
191     \return string representation of the hypothesis
192   */
193   std::string Dump( const HOMARD_Hypothesis& hypothesis )
194   {
195     std::stringstream os;
196     std::string saux ;
197     // ...
198     MESSAGE( ". Sauvegarde de l'hypothese "<<hypothesis.GetName());
199     os << hypothesis.GetName();
200     os << separator() << hypothesis.GetCaseCreation();
201     os << separator() << hypothesis.GetAdapType();
202     os << separator() << hypothesis.GetRefinType();
203     os << separator() << hypothesis.GetUnRefType();
204     os << separator() << hypothesis.GetFieldName();
205     os << separator() << hypothesis.GetRefinThrType();
206     os << separator() << hypothesis.GetThreshR();
207     os << separator() << hypothesis.GetUnRefThrType();
208     os << separator() << hypothesis.GetThreshC();
209     os << separator() << hypothesis.GetUseField();
210     os << separator() << hypothesis.GetUseComp();
211     os << separator() << hypothesis.GetTypeFieldInterp();
212
213     std::list<std::string> ListString = hypothesis.GetIterations();
214     std::list<std::string>::const_iterator it;
215     os << separator() << ListString.size();
216     for ( it = ListString.begin(); it != ListString.end(); ++it )
217          os << separator() << *it;
218
219     ListString = hypothesis.GetZones();
220     os << separator() << ListString.size();
221     for ( it = ListString.begin(); it != ListString.end(); ++it )
222           os << separator() << *it;
223
224     ListString = hypothesis.GetComps();
225     os << separator() << ListString.size();
226     for ( it = ListString.begin(); it != ListString.end(); ++it )
227          os << separator() << *it;
228
229     ListString = hypothesis.GetGroups();
230     os << separator() << ListString.size();
231     for ( it = ListString.begin(); it != ListString.end(); ++it )
232           os << separator() << *it;
233
234     ListString = hypothesis.GetFieldInterps();
235     os << separator() << ListString.size();
236     for ( it = ListString.begin(); it != ListString.end(); ++it )
237           os << separator() << *it;
238
239     os << separator() << hypothesis.GetNivMax();
240     os << separator() << hypothesis.GetDiamMin();
241     os << separator() << hypothesis.GetAdapInit();
242     os << separator() << hypothesis.GetExtraOutput();
243
244     saux = os.str();
245 //     MESSAGE( ". Fin avec "<<saux);
246     return saux ;
247   }
248 //
249 // =========
250 // 1.4. Zone
251 // =========
252
253   /*!
254     \brief Dump zone to the string
255     \param zone zone being dumped
256     \return string representation of the zone
257   */
258   std::string Dump( const HOMARD_Zone& zone )
259   {
260     std::stringstream os;
261     std::string saux ;
262     MESSAGE( ". Sauvegarde de la zone "<<zone.GetName());
263     os << zone.GetName();
264     os << separator() << zone.GetType();
265
266     std::vector<double> coords = zone.GetCoords();
267     for ( int i = 0; i < coords.size(); i++ )
268       os << separator() << ( i < coords.size() ? coords[i] : 0. );
269
270     std::vector<double> limit = zone.GetLimit();
271     for ( int i = 0; i < 3; i++ )
272       os << separator() << ( i < limit.size() ? limit[i] : 0. );
273
274     std::list<std::string> hypos = zone.GetHypo();
275     os << separator() << hypos.size();
276     std::list<std::string>::const_iterator it;
277     for ( it = hypos.begin(); it != hypos.end(); ++it )
278       os << separator() << *it;
279
280     saux = os.str();
281 //     MESSAGE( ". Fin avec "<<saux);
282     return saux ;
283   }
284 //
285 // ==============================
286 // 1.5. Archivage d'une frontiere
287 // ==============================
288
289   /*!
290     \brief Dump boundary to the string
291     \param boundary boundary being dumped
292     \return string representation of the boundary
293   */
294   std::string Dump( const HOMARD_Boundary& boundary )
295   {
296     std::stringstream os;
297     std::string saux ;
298     MESSAGE( ". Sauvegarde de la frontiere "<<boundary.GetName());
299
300     int BoundaryType = boundary.GetType() ;
301
302     os << boundary.GetName() ;
303     os << separator() << BoundaryType ;
304     os << separator() << boundary.GetCaseCreation() ;
305
306     if ( BoundaryType == -1 )
307     {
308       os << separator() << boundary.GetDataFile();
309     }
310     else if ( BoundaryType == 0 )
311     {
312       os << separator() << boundary.GetMeshName();
313       os << separator() << boundary.GetDataFile();
314     }
315     else {
316       std::vector<double> coor = boundary.GetCoords() ;
317       for ( int i = 0; i < coor.size(); i++ )
318             os << separator() << coor[i];
319       std::vector<double> limit = boundary.GetLimit();
320       for ( int i = 0; i < limit.size(); i++ )
321             os << separator() << limit[i];
322     }
323
324     std::list<std::string> ListString = boundary.GetGroups();
325     std::list<std::string>::const_iterator it;
326     os << separator() << ListString.size();
327     for ( it = ListString.begin(); it != ListString.end(); ++it )
328           os << separator() << *it;
329
330     saux = os.str();
331 //     MESSAGE( ". Fin avec "<<saux);
332     return saux ;
333   }
334
335 //
336 // =========
337 // 1.6. YACS
338 // =========
339
340   /*!
341     \brief Dump YACS to the string
342     \param yacs yacs being dumped
343     \return string representation of the zone
344   */
345   std::string Dump( const HOMARD_YACS& yacs )
346   {
347     std::stringstream os;
348     std::string saux ;
349     MESSAGE( ". Sauvegarde du schema YACS "<<yacs.GetName());
350     os << yacs.GetName();
351     os << separator() << yacs.GetType();
352
353     saux = os.str();
354 //     MESSAGE( ". Fin avec "<<saux);
355     return saux ;
356   }
357 //
358 // 2. Restauration des objets
359 // ==========================
360 // 2.1. Case
361 // ==========================
362 //
363   /*!
364     \brief Restore case from the string
365     \param cas case being restored
366     \param stream string representation of the case
367     \return \c true if case is correctly restored or \c false otherwise
368   */
369   bool Restore( HOMARD_Cas& cas, const std::string& stream )
370   {
371     MESSAGE( ". Restoration du cas ");
372     std::string::size_type start = 0;
373     std::string chunk, chunkNext;
374     bool ok;
375     // ...
376     chunk = getNextChunk( stream, start, ok );
377     if ( !ok ) return false;
378     cas.SetName( chunk.c_str() );
379
380     chunk = getNextChunk( stream, start, ok );
381     if ( !ok ) return false;
382     cas.SetDirName( chunk.c_str() );
383
384     chunk = getNextChunk( stream, start, ok );
385     if ( !ok ) return false;
386     cas.SetConfType( atoi( chunk.c_str() ) );
387
388     chunk = getNextChunk( stream, start, ok );
389     if ( !ok ) return false;
390     cas.SetExtType( atoi( chunk.c_str() ) );
391
392     chunk = getNextChunk( stream, start, ok );
393     if ( !ok ) return false;
394
395     int size = atoi( chunk.c_str() );
396     std::vector<double> boite;
397     boite.resize( size );
398     for ( int i = 0; i < size; i++ ) {
399       chunk = getNextChunk( stream, start, ok );
400       if ( !ok ) return false;
401       boite[i] = strtod( chunk.c_str(), 0 );
402     }
403     cas.SetBoundingBox( boite );
404
405     chunk = getNextChunk( stream, start, ok );
406     if ( !ok ) return false;
407
408     size = atoi( chunk.c_str() );
409     for ( int i = 0; i < size; i++ ) {
410       chunk = getNextChunk( stream, start, ok );
411       if ( !ok ) return false;
412       cas.AddIteration( chunk.c_str() );
413     }
414
415     chunk = getNextChunk( stream, start, ok );
416     if ( !ok ) return false;
417     size = atoi( chunk.c_str() );
418     for ( int i = 0; i < size; i++ )
419     {
420       chunk = getNextChunk( stream, start, ok );
421       if ( !ok ) return false;
422       cas.AddGroup( chunk.c_str() );
423     }
424
425     chunk = getNextChunk( stream, start, ok );
426     if ( !ok ) return false;
427     size = atoi( chunk.c_str() );
428     for ( int i = 0; i < size; i++ ) {
429       chunk = getNextChunk( stream, start, ok );
430       if ( !ok ) return false;
431       i++;
432       chunkNext = getNextChunk( stream, start, ok );
433       if ( !ok ) return false;
434       cas.AddBoundaryGroup( chunk.c_str(), chunkNext.c_str() );
435     }
436
437     chunk = getNextChunk( stream, start, ok );
438     if ( !ok ) return false;
439     cas.SetPyram( atoi( chunk.c_str() ) );
440
441     return true;
442   }
443 //
444 // ==============
445 // 2.2. Iteration
446 // ==============
447   /*!
448     \brief Restore iteration from the string
449     \param iteration iteration being restored
450     \param stream string representation of the iteration
451     \return \c true if iteration is correctly restored or \c false otherwise
452   */
453   bool Restore( HOMARD_Iteration& iteration, const std::string& stream )
454   {
455     std::string::size_type start = 0;
456     std::string chunk;
457     bool ok;
458     chunk = getNextChunk( stream, start, ok );
459     if ( !ok ) return false;
460
461     iteration.SetName( chunk.c_str() );
462     chunk = getNextChunk( stream, start, ok );
463     if ( !ok ) return false;
464     iteration.SetState( atoi( chunk.c_str() ) );
465     chunk = getNextChunk( stream, start, ok );
466     if ( !ok ) return false;
467     iteration.SetNumber( atoi( chunk.c_str() ) );
468     chunk = getNextChunk( stream, start, ok );
469     if ( !ok ) return false;
470     iteration.SetMeshFile( chunk.c_str() );
471     chunk = getNextChunk( stream, start, ok );
472     if ( !ok ) return false;
473     iteration.SetLogFile( chunk.c_str() );
474     chunk = getNextChunk( stream, start, ok );
475     if ( !ok ) return false;
476     iteration.SetMeshName( chunk.c_str() );
477     chunk = getNextChunk( stream, start, ok );
478     if ( !ok ) return false;
479     iteration.SetFieldFile( chunk.c_str() );
480     // .
481     int timestep, rank;
482     chunk = getNextChunk( stream, start, ok );
483     if ( !ok ) return false;
484     timestep = atoi( chunk.c_str() );
485     chunk = getNextChunk( stream, start, ok );
486     if ( !ok ) return false;
487     rank = atoi( chunk.c_str() );
488     iteration.SetTimeStepRank( timestep, rank );
489     chunk = getNextChunk( stream, start, ok );
490     if ( !ok ) return false;
491     iteration.SetIterParentName( chunk.c_str() );
492     //
493     chunk = getNextChunk( stream, start, ok );
494     if ( !ok ) return false;
495     int size = atoi( chunk.c_str() );
496     for ( int i = 0; i < size; i++ ) {
497       chunk = getNextChunk( stream, start, ok );
498       if ( !ok ) return false;
499       iteration.LinkNextIteration( chunk.c_str() );
500     }
501     //
502     chunk = getNextChunk( stream, start, ok );
503     if ( !ok ) return false;
504     iteration.SetHypoName( chunk.c_str() );
505     chunk = getNextChunk( stream, start, ok );
506     if ( !ok ) return false;
507     iteration.SetCaseName( chunk.c_str() );
508     chunk = getNextChunk( stream, start, ok );
509     if ( !ok ) return false;
510     iteration.SetDirNameLoc( chunk.c_str() );
511     return true;
512   }
513
514 //
515 // ==============
516 // 2.3. hypothese
517 // ==============
518   /*!
519     \brief Restore hypothesis from the string
520     \param hypothesis hypothesis being restored
521     \param stream string representation of the hypothesis
522     \return \c true if hypothesis is correctly restored or \c false otherwise
523   */
524   bool Restore( HOMARD_Hypothesis& hypothesis, const std::string& stream )
525   {
526     std::string::size_type start = 0;
527     std::string chunk, chunkNext;
528     bool ok;
529
530     chunk = getNextChunk( stream, start, ok );
531     if ( !ok ) return false;
532     hypothesis.SetName( chunk.c_str() );
533
534     chunk = getNextChunk( stream, start, ok );
535     if ( !ok ) return false;
536     hypothesis.SetCaseCreation( chunk.c_str() );
537
538     chunk = getNextChunk( stream, start, ok );
539     if ( !ok ) return false;
540     hypothesis.SetAdapType( atoi( chunk.c_str() ) );
541
542     chunk = getNextChunk( stream, start, ok );
543     if ( !ok ) return false;
544     int typeraff = atoi( chunk.c_str() );
545     chunk = getNextChunk( stream, start, ok );
546     if ( !ok ) return false;
547     int typedera = atoi( chunk.c_str() );
548     hypothesis.SetRefinTypeDera( typeraff, typedera );
549
550     chunk = getNextChunk( stream, start, ok );
551     if ( !ok ) return false;
552     hypothesis.SetField( chunk.c_str() );
553
554     chunk = getNextChunk( stream, start, ok );
555     if ( !ok ) return false;
556     int typethr = atoi( chunk.c_str() );
557     chunk = getNextChunk( stream, start, ok );
558     if ( !ok ) return false;
559     double threshr = strtod( chunk.c_str(), 0 );
560     hypothesis.SetRefinThr( typethr, threshr );
561
562     chunk = getNextChunk( stream, start, ok );
563     if ( !ok ) return false;
564     int typethc = atoi( chunk.c_str() );
565     chunk = getNextChunk( stream, start, ok );
566     if ( !ok ) return false;
567     double threshc = strtod( chunk.c_str(), 0 );
568     hypothesis.SetUnRefThr( typethc, threshc );
569
570     chunk = getNextChunk( stream, start, ok );
571     if ( !ok ) return false;
572     hypothesis.SetUseField(atoi(chunk.c_str()));
573
574     chunk = getNextChunk( stream, start, ok );
575     if ( !ok ) return false;
576     hypothesis.SetUseComp(atoi(chunk.c_str()));
577
578     chunk = getNextChunk( stream, start, ok );
579     if ( !ok ) return false;
580     hypothesis.SetTypeFieldInterp(atoi(chunk.c_str()));
581
582     chunk = getNextChunk( stream, start, ok );
583     if ( !ok ) return false;
584     int size = atoi( chunk.c_str() );
585     for ( int i = 0; i < size; i++ ) {
586       chunk = getNextChunk( stream, start, ok );
587       if ( !ok ) return false;
588       hypothesis.LinkIteration( chunk.c_str() );
589     }
590
591     chunk = getNextChunk( stream, start, ok );
592     if ( !ok ) return false;
593     size = atoi( chunk.c_str() );
594     for ( int i = 0; i < size; i++ ) {
595       chunk = getNextChunk( stream, start, ok );
596       if ( !ok ) return false;
597       i++;
598       chunkNext = getNextChunk( stream, start, ok );
599       int typeuse = atoi( chunkNext.c_str() );
600       if ( !ok ) return false;
601       hypothesis.AddZone( chunk.c_str(), typeuse );
602     }
603
604     chunk = getNextChunk( stream, start, ok );
605     if ( !ok ) return false;
606     size = atoi( chunk.c_str() );
607     for ( int i = 0; i < size; i++ ) {
608       chunk = getNextChunk( stream, start, ok );
609       if ( !ok ) return false;
610       hypothesis.AddComp( chunk.c_str() );
611     }
612
613     chunk = getNextChunk( stream, start, ok );
614     if ( !ok ) return false;
615     size = atoi( chunk.c_str() );
616     for ( int i = 0; i < size; i++ ) {
617       chunk = getNextChunk( stream, start, ok );
618       if ( !ok ) return false;
619       hypothesis.AddGroup( chunk.c_str() );
620     }
621
622     chunk = getNextChunk( stream, start, ok );
623     if ( !ok ) return false;
624     size = atoi( chunk.c_str() );
625     for ( int i = 0; i < size; i++ ) {
626       chunk = getNextChunk( stream, start, ok );
627       if ( !ok ) return false;
628       i++;
629       chunkNext = getNextChunk( stream, start, ok );
630       int TypeInterp = atoi( chunkNext.c_str() );
631       if ( !ok ) return false;
632       hypothesis.AddFieldInterpType( chunk.c_str(), TypeInterp );
633     }
634
635     chunk = getNextChunk( stream, start, ok );
636     if ( !ok ) return false;
637     hypothesis.SetNivMax( atoi( chunk.c_str() ) );
638
639     chunk = getNextChunk( stream, start, ok );
640     if ( !ok ) return false;
641     hypothesis.SetDiamMin( strtod( chunk.c_str(), 0 ) );
642
643     chunk = getNextChunk( stream, start, ok );
644     if ( !ok ) return false;
645     hypothesis.SetAdapInit( strtod( chunk.c_str(), 0 ) );
646
647     chunk = getNextChunk( stream, start, ok );
648     if ( !ok ) return false;
649     hypothesis.SetExtraOutput( strtod( chunk.c_str(), 0 ) );
650
651     return true;
652   }
653
654 //
655 // =========
656 // 2.4. Zone
657 // =========
658   /*!
659     \brief Restore zone from the string
660     \param zone zone being restored
661     \param stream string representation of the zone
662     \return \c true if zone is correctly restored or \c false otherwise
663   */
664   bool Restore( HOMARD_Zone& zone, const std::string& stream )
665   {
666     std::string::size_type start = 0;
667     std::string chunk;
668     bool ok;
669     //
670     chunk = getNextChunk( stream, start, ok );
671     if ( !ok ) return false;
672     zone.SetName( chunk.c_str() );
673     //
674     chunk = getNextChunk( stream, start, ok );
675     if ( !ok ) return false;
676     int ZoneType = atoi( chunk.c_str() ) ;
677     zone.SetType( ZoneType );
678     // Les coordonnees des zones : le nombre depend du type
679     std::vector<double> coords;
680     int lgcoords ;
681     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) ) { lgcoords = 6 ; }
682     else if ( ZoneType == 4 ) { lgcoords = 4 ; }
683     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) ) { lgcoords = 8 ; }
684     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) ) { lgcoords = 9 ; }
685     else return false;
686     coords.resize( lgcoords );
687     for ( int i = 0; i < lgcoords; i++ ) {
688       chunk = getNextChunk( stream, start, ok );
689       if ( !ok ) return false;
690       coords[i] = strtod( chunk.c_str(), 0 );
691     }
692     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) )
693     { zone.SetBox( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5] ); }
694     else if ( ZoneType == 4 )
695     { zone.SetSphere( coords[0], coords[1], coords[2], coords[3] ); }
696     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) )
697     { zone.SetCylinder( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7] ); }
698     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) )
699     { zone.SetPipe( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7], coords[8] ); }
700     // Remarque : la taille de coords est suffisante pour les limites
701     for ( int i = 0; i < 3; i++ ) {
702       chunk = getNextChunk( stream, start, ok );
703       if ( !ok ) return false;
704       coords[i] = strtod( chunk.c_str(), 0 );
705     }
706     zone.SetLimit( coords[0], coords[1], coords[2]);
707
708     chunk = getNextChunk( stream, start, ok );
709     if ( !ok ) return false;
710     int size = atoi( chunk.c_str() );
711     for ( int i = 0; i < size; i++ ) {
712       chunk = getNextChunk( stream, start, ok );
713       if ( !ok ) return false;
714       zone.AddHypo( chunk.c_str() );
715     }
716     return true;
717   }
718
719 //
720 // =================================
721 // 2.5. Restauration d'une frontiere
722 // =================================
723
724   /*!
725     \brief Restore boundary from the string
726     \param boundary boundary being restored
727     \param stream string representation of the boundary
728     \return \c true if the boundary is correctly restored or \c false otherwise
729   */
730   bool Restore( HOMARD_Boundary& boundary, const std::string& stream )
731   {
732     std::string::size_type start = 0;
733     std::string chunk;
734     bool ok;
735
736     chunk = getNextChunk( stream, start, ok );
737     if ( !ok ) return false;
738     boundary.SetName( chunk.c_str() );
739
740     chunk = getNextChunk( stream, start, ok );
741     if ( !ok ) return false;
742     int BoundaryType = atoi( chunk.c_str() ) ;
743     boundary.SetType( BoundaryType );
744
745     chunk = getNextChunk( stream, start, ok );
746     if ( !ok ) return false;
747     boundary.SetCaseCreation( chunk.c_str() );
748
749     // Si analytique, les coordonnees des frontieres : le nombre depend du type
750     // Si discret, le maillage
751     // Si CAO, la géométrie
752     int lgcoords ;
753     if ( BoundaryType == -1 ) { lgcoords = -1 ; }
754     else if ( BoundaryType == 1 ) { lgcoords = 7 ; }
755     else if ( BoundaryType == 2 ) { lgcoords = 4 ; }
756     else { lgcoords = 0 ; }
757 //
758     if ( lgcoords == -1 )
759     {
760       chunk = getNextChunk( stream, start, ok );
761       if ( !ok ) return false;
762       boundary.SetDataFile( chunk.c_str() );
763     }
764     else if ( lgcoords == 0 )
765     {
766       chunk = getNextChunk( stream, start, ok );
767       if ( !ok ) return false;
768       boundary.SetMeshName( chunk.c_str() );
769
770       chunk = getNextChunk( stream, start, ok );
771       if ( !ok ) return false;
772       boundary.SetDataFile( chunk.c_str() );
773     }
774     else
775     { std::vector<double> coords;
776       coords.resize( lgcoords );
777       for ( int i = 0; i < lgcoords; i++ ) {
778         chunk = getNextChunk( stream, start, ok );
779         if ( !ok ) return false;
780         coords[i] = strtod( chunk.c_str(), 0 );
781       }
782       if ( BoundaryType == 1 )
783       { boundary.SetCylinder(coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],coords[6]); }
784       else if ( BoundaryType == 2 )
785       { boundary.SetSphere( coords[0], coords[1], coords[2], coords[3]); }
786       else if ( BoundaryType == 3 )
787       { boundary.SetConeA( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6]); }
788       else if ( BoundaryType == 4 )
789       { boundary.SetConeR( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7]); }
790       // Remarque : la taille de coords est suffisante pour les limites
791       for ( int i = 0; i < 3; i++ ) {
792         chunk = getNextChunk( stream, start, ok );
793         if ( !ok ) return false;
794         coords[i] = strtod( chunk.c_str(), 0 );
795       }
796       boundary.SetLimit( coords[0], coords[1], coords[2]);
797     }
798     // Les groupes
799     chunk = getNextChunk( stream, start, ok );
800     if ( !ok ) return false;
801     int size = atoi( chunk.c_str() );
802     for ( int i = 0; i < size; i++ ) {
803       chunk = getNextChunk( stream, start, ok );
804       if ( !ok ) return false;
805       boundary.AddGroup( chunk.c_str() );
806     }
807
808     return true;
809   }
810
811 //
812 // ==================================
813 // 2.6. Restauration d'un schema YACS
814 // ==================================
815
816   /*!
817     \brief Restore a schema YACS from the string
818     \param yacs yacs being restored
819     \param stream string representation of the schema yacs
820     \return \c true if yacs is correctly restored or \c false otherwise
821   */
822   bool Restore( HOMARD_YACS& yacs, const std::string& stream )
823   {
824     std::string::size_type start = 0;
825     std::string chunk;
826     bool ok;
827
828     chunk = getNextChunk( stream, start, ok );
829     if ( !ok ) return false;
830     yacs.SetName( chunk.c_str() );
831
832     chunk = getNextChunk( stream, start, ok );
833     if ( !ok ) return false;
834     int YACSType = atoi( chunk.c_str() ) ;
835     yacs.SetType( YACSType );
836
837     return true;
838   }
839
840 } // namespace HOMARD /end/