Salome HOME
Copyright update: 2016
[modules/homard.git] / src / HOMARD / HOMARD_DriverTools.cxx
1 // Copyright (C) 2011-2016  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 == 0 )
307     {
308       os << separator() << boundary.GetMeshName();
309       os << separator() << boundary.GetMeshFile();
310     }
311     else {
312       std::vector<double> coor = boundary.GetCoords() ;
313       for ( int i = 0; i < coor.size(); i++ )
314             os << separator() << coor[i];
315       std::vector<double> limit = boundary.GetLimit();
316       for ( int i = 0; i < limit.size(); i++ )
317             os << separator() << limit[i];
318     }
319
320     std::list<std::string> ListString = boundary.GetGroups();
321     std::list<std::string>::const_iterator it;
322     os << separator() << ListString.size();
323     for ( it = ListString.begin(); it != ListString.end(); ++it )
324           os << separator() << *it;
325
326     saux = os.str();
327 //     MESSAGE( ". Fin avec "<<saux);
328     return saux ;
329   }
330
331 //
332 // =========
333 // 1.6. YACS
334 // =========
335
336   /*!
337     \brief Dump YACS to the string
338     \param yacs yacs being dumped
339     \return string representation of the zone
340   */
341   std::string Dump( const HOMARD_YACS& yacs )
342   {
343     std::stringstream os;
344     std::string saux ;
345     MESSAGE( ". Sauvegarde du schema YACS "<<yacs.GetName());
346     os << yacs.GetName();
347     os << separator() << yacs.GetType();
348
349     saux = os.str();
350 //     MESSAGE( ". Fin avec "<<saux);
351     return saux ;
352   }
353 //
354 // 2. Restauration des objets
355 // ==========================
356 // 2.1. Case
357 // ==========================
358 //
359   /*!
360     \brief Restore case from the string
361     \param cas case being restored
362     \param stream string representation of the case
363     \return \c true if case is correctly restored or \c false otherwise
364   */
365   bool Restore( HOMARD_Cas& cas, const std::string& stream )
366   {
367     MESSAGE( ". Restoration du cas ");
368     std::string::size_type start = 0;
369     std::string chunk, chunkNext;
370     bool ok;
371     // ...
372     chunk = getNextChunk( stream, start, ok );
373     if ( !ok ) return false;
374     cas.SetName( chunk.c_str() );
375
376     chunk = getNextChunk( stream, start, ok );
377     if ( !ok ) return false;
378     cas.SetDirName( chunk.c_str() );
379
380     chunk = getNextChunk( stream, start, ok );
381     if ( !ok ) return false;
382     cas.SetConfType( atoi( chunk.c_str() ) );
383
384     chunk = getNextChunk( stream, start, ok );
385     if ( !ok ) return false;
386     cas.SetExtType( atoi( chunk.c_str() ) );
387
388     chunk = getNextChunk( stream, start, ok );
389     if ( !ok ) return false;
390
391     int size = atoi( chunk.c_str() );
392     std::vector<double> boite;
393     boite.resize( size );
394     for ( int i = 0; i < size; i++ ) {
395       chunk = getNextChunk( stream, start, ok );
396       if ( !ok ) return false;
397       boite[i] = strtod( chunk.c_str(), 0 );
398     }
399     cas.SetBoundingBox( boite );
400
401     chunk = getNextChunk( stream, start, ok );
402     if ( !ok ) return false;
403
404     size = atoi( chunk.c_str() );
405     for ( int i = 0; i < size; i++ ) {
406       chunk = getNextChunk( stream, start, ok );
407       if ( !ok ) return false;
408       cas.AddIteration( chunk.c_str() );
409     }
410
411     chunk = getNextChunk( stream, start, ok );
412     if ( !ok ) return false;
413     size = atoi( chunk.c_str() );
414     for ( int i = 0; i < size; i++ )
415     {
416       chunk = getNextChunk( stream, start, ok );
417       if ( !ok ) return false;
418       cas.AddGroup( chunk.c_str() );
419     }
420
421     chunk = getNextChunk( stream, start, ok );
422     if ( !ok ) return false;
423     size = atoi( chunk.c_str() );
424     for ( int i = 0; i < size; i++ ) {
425       chunk = getNextChunk( stream, start, ok );
426       if ( !ok ) return false;
427       i++;
428       chunkNext = getNextChunk( stream, start, ok );
429       if ( !ok ) return false;
430       cas.AddBoundaryGroup( chunk.c_str(), chunkNext.c_str() );
431     }
432
433     chunk = getNextChunk( stream, start, ok );
434     if ( !ok ) return false;
435     cas.SetPyram( atoi( chunk.c_str() ) );
436
437     return true;
438   }
439 //
440 // ==============
441 // 2.2. Iteration
442 // ==============
443   /*!
444     \brief Restore iteration from the string
445     \param iteration iteration being restored
446     \param stream string representation of the iteration
447     \return \c true if iteration is correctly restored or \c false otherwise
448   */
449   bool Restore( HOMARD_Iteration& iteration, const std::string& stream )
450   {
451     std::string::size_type start = 0;
452     std::string chunk;
453     bool ok;
454     chunk = getNextChunk( stream, start, ok );
455     if ( !ok ) return false;
456
457     iteration.SetName( chunk.c_str() );
458     chunk = getNextChunk( stream, start, ok );
459     if ( !ok ) return false;
460     iteration.SetState( atoi( chunk.c_str() ) );
461     chunk = getNextChunk( stream, start, ok );
462     if ( !ok ) return false;
463     iteration.SetNumber( atoi( chunk.c_str() ) );
464     chunk = getNextChunk( stream, start, ok );
465     if ( !ok ) return false;
466     iteration.SetMeshFile( chunk.c_str() );
467     chunk = getNextChunk( stream, start, ok );
468     if ( !ok ) return false;
469     iteration.SetLogFile( chunk.c_str() );
470     chunk = getNextChunk( stream, start, ok );
471     if ( !ok ) return false;
472     iteration.SetMeshName( chunk.c_str() );
473     chunk = getNextChunk( stream, start, ok );
474     if ( !ok ) return false;
475     iteration.SetFieldFile( chunk.c_str() );
476     // .
477     int timestep, rank;
478     chunk = getNextChunk( stream, start, ok );
479     if ( !ok ) return false;
480     timestep = atoi( chunk.c_str() );
481     chunk = getNextChunk( stream, start, ok );
482     if ( !ok ) return false;
483     rank = atoi( chunk.c_str() );
484     iteration.SetTimeStepRank( timestep, rank );
485     chunk = getNextChunk( stream, start, ok );
486     if ( !ok ) return false;
487     iteration.SetIterParentName( chunk.c_str() );
488     //
489     chunk = getNextChunk( stream, start, ok );
490     if ( !ok ) return false;
491     int size = atoi( chunk.c_str() );
492     for ( int i = 0; i < size; i++ ) {
493       chunk = getNextChunk( stream, start, ok );
494       if ( !ok ) return false;
495       iteration.LinkNextIteration( chunk.c_str() );
496     }
497     //
498     chunk = getNextChunk( stream, start, ok );
499     if ( !ok ) return false;
500     iteration.SetHypoName( chunk.c_str() );
501     chunk = getNextChunk( stream, start, ok );
502     if ( !ok ) return false;
503     iteration.SetCaseName( chunk.c_str() );
504     chunk = getNextChunk( stream, start, ok );
505     if ( !ok ) return false;
506     iteration.SetDirNameLoc( chunk.c_str() );
507     return true;
508   }
509
510 //
511 // ==============
512 // 2.3. hypothese
513 // ==============
514   /*!
515     \brief Restore hypothesis from the string
516     \param hypothesis hypothesis being restored
517     \param stream string representation of the hypothesis
518     \return \c true if hypothesis is correctly restored or \c false otherwise
519   */
520   bool Restore( HOMARD_Hypothesis& hypothesis, const std::string& stream )
521   {
522     std::string::size_type start = 0;
523     std::string chunk, chunkNext;
524     bool ok;
525
526     chunk = getNextChunk( stream, start, ok );
527     if ( !ok ) return false;
528     hypothesis.SetName( chunk.c_str() );
529
530     chunk = getNextChunk( stream, start, ok );
531     if ( !ok ) return false;
532     hypothesis.SetCaseCreation( chunk.c_str() );
533
534     chunk = getNextChunk( stream, start, ok );
535     if ( !ok ) return false;
536     hypothesis.SetAdapType( atoi( chunk.c_str() ) );
537
538     chunk = getNextChunk( stream, start, ok );
539     if ( !ok ) return false;
540     int typeraff = atoi( chunk.c_str() );
541     chunk = getNextChunk( stream, start, ok );
542     if ( !ok ) return false;
543     int typedera = atoi( chunk.c_str() );
544     hypothesis.SetRefinTypeDera( typeraff, typedera );
545
546     chunk = getNextChunk( stream, start, ok );
547     if ( !ok ) return false;
548     hypothesis.SetField( chunk.c_str() );
549
550     chunk = getNextChunk( stream, start, ok );
551     if ( !ok ) return false;
552     int typethr = atoi( chunk.c_str() );
553     chunk = getNextChunk( stream, start, ok );
554     if ( !ok ) return false;
555     double threshr = strtod( chunk.c_str(), 0 );
556     hypothesis.SetRefinThr( typethr, threshr );
557
558     chunk = getNextChunk( stream, start, ok );
559     if ( !ok ) return false;
560     int typethc = atoi( chunk.c_str() );
561     chunk = getNextChunk( stream, start, ok );
562     if ( !ok ) return false;
563     double threshc = strtod( chunk.c_str(), 0 );
564     hypothesis.SetUnRefThr( typethc, threshc );
565
566     chunk = getNextChunk( stream, start, ok );
567     if ( !ok ) return false;
568     hypothesis.SetUseField(atoi(chunk.c_str()));
569
570     chunk = getNextChunk( stream, start, ok );
571     if ( !ok ) return false;
572     hypothesis.SetUseComp(atoi(chunk.c_str()));
573
574     chunk = getNextChunk( stream, start, ok );
575     if ( !ok ) return false;
576     hypothesis.SetTypeFieldInterp(atoi(chunk.c_str()));
577
578     chunk = getNextChunk( stream, start, ok );
579     if ( !ok ) return false;
580     int size = atoi( chunk.c_str() );
581     for ( int i = 0; i < size; i++ ) {
582       chunk = getNextChunk( stream, start, ok );
583       if ( !ok ) return false;
584       hypothesis.LinkIteration( chunk.c_str() );
585     }
586
587     chunk = getNextChunk( stream, start, ok );
588     if ( !ok ) return false;
589     size = atoi( chunk.c_str() );
590     for ( int i = 0; i < size; i++ ) {
591       chunk = getNextChunk( stream, start, ok );
592       if ( !ok ) return false;
593       i++;
594       chunkNext = getNextChunk( stream, start, ok );
595       int typeuse = atoi( chunkNext.c_str() );
596       if ( !ok ) return false;
597       hypothesis.AddZone( chunk.c_str(), typeuse );
598     }
599
600     chunk = getNextChunk( stream, start, ok );
601     if ( !ok ) return false;
602     size = atoi( chunk.c_str() );
603     for ( int i = 0; i < size; i++ ) {
604       chunk = getNextChunk( stream, start, ok );
605       if ( !ok ) return false;
606       hypothesis.AddComp( chunk.c_str() );
607     }
608
609     chunk = getNextChunk( stream, start, ok );
610     if ( !ok ) return false;
611     size = atoi( chunk.c_str() );
612     for ( int i = 0; i < size; i++ ) {
613       chunk = getNextChunk( stream, start, ok );
614       if ( !ok ) return false;
615       hypothesis.AddGroup( chunk.c_str() );
616     }
617
618     chunk = getNextChunk( stream, start, ok );
619     if ( !ok ) return false;
620     size = atoi( chunk.c_str() );
621     for ( int i = 0; i < size; i++ ) {
622       chunk = getNextChunk( stream, start, ok );
623       if ( !ok ) return false;
624       i++;
625       chunkNext = getNextChunk( stream, start, ok );
626       int TypeInterp = atoi( chunkNext.c_str() );
627       if ( !ok ) return false;
628       hypothesis.AddFieldInterpType( chunk.c_str(), TypeInterp );
629     }
630
631     chunk = getNextChunk( stream, start, ok );
632     if ( !ok ) return false;
633     hypothesis.SetNivMax( atoi( chunk.c_str() ) );
634
635     chunk = getNextChunk( stream, start, ok );
636     if ( !ok ) return false;
637     hypothesis.SetDiamMin( strtod( chunk.c_str(), 0 ) );
638
639     chunk = getNextChunk( stream, start, ok );
640     if ( !ok ) return false;
641     hypothesis.SetAdapInit( strtod( chunk.c_str(), 0 ) );
642
643     chunk = getNextChunk( stream, start, ok );
644     if ( !ok ) return false;
645     hypothesis.SetExtraOutput( strtod( chunk.c_str(), 0 ) );
646
647     return true;
648   }
649
650 //
651 // =========
652 // 2.4. Zone
653 // =========
654   /*!
655     \brief Restore zone from the string
656     \param zone zone being restored
657     \param stream string representation of the zone
658     \return \c true if zone is correctly restored or \c false otherwise
659   */
660   bool Restore( HOMARD_Zone& zone, const std::string& stream )
661   {
662     std::string::size_type start = 0;
663     std::string chunk;
664     bool ok;
665     //
666     chunk = getNextChunk( stream, start, ok );
667     if ( !ok ) return false;
668     zone.SetName( chunk.c_str() );
669     //
670     chunk = getNextChunk( stream, start, ok );
671     if ( !ok ) return false;
672     int ZoneType = atoi( chunk.c_str() ) ;
673     zone.SetType( ZoneType );
674     // Les coordonnees des zones : le nombre depend du type
675     std::vector<double> coords;
676     int lgcoords ;
677     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) ) { lgcoords = 6 ; }
678     else if ( ZoneType == 4 ) { lgcoords = 4 ; }
679     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) ) { lgcoords = 8 ; }
680     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) ) { lgcoords = 9 ; }
681     else return false;
682     coords.resize( lgcoords );
683     for ( int i = 0; i < lgcoords; i++ ) {
684       chunk = getNextChunk( stream, start, ok );
685       if ( !ok ) return false;
686       coords[i] = strtod( chunk.c_str(), 0 );
687     }
688     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) )
689     { zone.SetBox( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5] ); }
690     else if ( ZoneType == 4 )
691     { zone.SetSphere( coords[0], coords[1], coords[2], coords[3] ); }
692     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) )
693     { zone.SetCylinder( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7] ); }
694     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) )
695     { zone.SetPipe( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7], coords[8] ); }
696     // Remarque : la taille de coords est suffisante pour les limites
697     for ( int i = 0; i < 3; i++ ) {
698       chunk = getNextChunk( stream, start, ok );
699       if ( !ok ) return false;
700       coords[i] = strtod( chunk.c_str(), 0 );
701     }
702     zone.SetLimit( coords[0], coords[1], coords[2]);
703
704     chunk = getNextChunk( stream, start, ok );
705     if ( !ok ) return false;
706     int size = atoi( chunk.c_str() );
707     for ( int i = 0; i < size; i++ ) {
708       chunk = getNextChunk( stream, start, ok );
709       if ( !ok ) return false;
710       zone.AddHypo( chunk.c_str() );
711     }
712     return true;
713   }
714
715 //
716 // =================================
717 // 2.5. Restauration d'une frontiere
718 // =================================
719
720   /*!
721     \brief Restore boundary from the string
722     \param boundary boundary being restored
723     \param stream string representation of the boundary
724     \return \c true if the boundary is correctly restored or \c false otherwise
725   */
726   bool Restore( HOMARD_Boundary& boundary, const std::string& stream )
727   {
728     std::string::size_type start = 0;
729     std::string chunk;
730     bool ok;
731
732     chunk = getNextChunk( stream, start, ok );
733     if ( !ok ) return false;
734     boundary.SetName( chunk.c_str() );
735
736     chunk = getNextChunk( stream, start, ok );
737     if ( !ok ) return false;
738     int BoundaryType = atoi( chunk.c_str() ) ;
739     boundary.SetType( BoundaryType );
740
741     chunk = getNextChunk( stream, start, ok );
742     if ( !ok ) return false;
743     boundary.SetCaseCreation( chunk.c_str() );
744
745     // Si analytique, les coordonnees des frontieres : le nombre depend du type
746     // Si discret, le maillage
747     int lgcoords ;
748     if ( BoundaryType == 1 ) { lgcoords = 7 ; }
749     else if ( BoundaryType == 2 ) { lgcoords = 4 ; }
750     else { lgcoords = 0 ; }
751 //
752     if ( lgcoords == 0 )
753     {
754       chunk = getNextChunk( stream, start, ok );
755       if ( !ok ) return false;
756       boundary.SetMeshName( chunk.c_str() );
757
758       chunk = getNextChunk( stream, start, ok );
759       if ( !ok ) return false;
760       boundary.SetMeshFile( chunk.c_str() );
761     }
762     else
763     { std::vector<double> coords;
764       coords.resize( lgcoords );
765       for ( int i = 0; i < lgcoords; i++ ) {
766         chunk = getNextChunk( stream, start, ok );
767         if ( !ok ) return false;
768         coords[i] = strtod( chunk.c_str(), 0 );
769       }
770       if ( BoundaryType == 1 )
771       { boundary.SetCylinder(coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],coords[6]); }
772       else if ( BoundaryType == 2 )
773       { boundary.SetSphere( coords[0], coords[1], coords[2], coords[3]); }
774       else if ( BoundaryType == 3 )
775       { boundary.SetConeA( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6]); }
776       else if ( BoundaryType == 4 )
777       { boundary.SetConeR( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7]); }
778       // Remarque : la taille de coords est suffisante pour les limites
779       for ( int i = 0; i < 3; i++ ) {
780         chunk = getNextChunk( stream, start, ok );
781         if ( !ok ) return false;
782         coords[i] = strtod( chunk.c_str(), 0 );
783       }
784       boundary.SetLimit( coords[0], coords[1], coords[2]);
785     }
786     // Les groupes
787     chunk = getNextChunk( stream, start, ok );
788     if ( !ok ) return false;
789     int size = atoi( chunk.c_str() );
790     for ( int i = 0; i < size; i++ ) {
791       chunk = getNextChunk( stream, start, ok );
792       if ( !ok ) return false;
793       boundary.AddGroup( chunk.c_str() );
794     }
795
796     return true;
797   }
798
799 //
800 // ==================================
801 // 2.6. Restauration d'un schema YACS
802 // ==================================
803
804   /*!
805     \brief Restore a schema YACS from the string
806     \param yacs yacs being restored
807     \param stream string representation of the schema yacs
808     \return \c true if yacs is correctly restored or \c false otherwise
809   */
810   bool Restore( HOMARD_YACS& yacs, const std::string& stream )
811   {
812     std::string::size_type start = 0;
813     std::string chunk;
814     bool ok;
815
816     chunk = getNextChunk( stream, start, ok );
817     if ( !ok ) return false;
818     yacs.SetName( chunk.c_str() );
819
820     chunk = getNextChunk( stream, start, ok );
821     if ( !ok ) return false;
822     int YACSType = atoi( chunk.c_str() ) ;
823     yacs.SetType( YACSType );
824
825     return true;
826   }
827
828 } // namespace HOMARD /end/