Salome HOME
Revert "Synchronize adm files"
[modules/homard.git] / src / HOMARD / HOMARD_DriverTools.cxx
1 // Copyright (C) 2011-2014  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
116     std::vector<double> coor = cas.GetBoundingBox();
117     os << separator() << coor.size();
118     for ( int i = 0; i < coor.size(); i++ )
119           os << separator() << coor[i];
120
121     std::list<std::string> ListString = cas.GetIterations();
122     os << separator() << ListString.size();
123     std::list<std::string>::const_iterator it;
124     for ( it = ListString.begin(); it != ListString.end(); ++it )
125           os << separator() << *it;
126
127     ListString = cas.GetGroups();
128     os << separator() << ListString.size();
129     for ( it = ListString.begin(); it != ListString.end(); ++it )
130          os << separator() << *it;
131     ListString = cas.GetBoundaryGroup();
132     os << separator() << ListString.size();
133     for ( it = ListString.begin(); it != ListString.end(); ++it )
134          os << separator() << *it;
135
136     os << separator() << cas.GetPyram();
137
138     saux = os.str();
139 //     MESSAGE( ". Fin avec "<<saux);
140     return saux ;
141   }
142 //
143 // ==============
144 // 1.2. Iteration
145 // ==============
146 //
147   /*!
148     \brief Dump iteration to the string
149     \param iteration iteration being dumped
150     \return string representation of the iteration
151   */
152   std::string Dump( const HOMARD_Iteration& iteration )
153   {
154     std::stringstream os;
155     std::string saux ;
156     // ...
157     MESSAGE( ". Sauvegarde de l'iteration "<<iteration.GetName());
158     os << iteration.GetName();
159     os << separator() << iteration.GetState();
160     os << separator() << iteration.GetNumber();
161     os << separator() << iteration.GetMeshFile();
162     os << separator() << iteration.GetLogFile();
163     os << separator() << iteration.GetMeshName();
164     os << separator() << iteration.GetFieldFile();
165     os << separator() << iteration.GetTimeStep();
166     os << separator() << iteration.GetRank();
167     os << separator() << iteration.GetIterParentName();
168     //
169     std::list<std::string> ListString = iteration.GetIterations();
170     os << separator() << ListString.size();
171     std::list<std::string>::const_iterator it;
172     for ( it = ListString.begin(); it != ListString.end(); ++it )
173       os << separator() << *it;
174
175     os << separator() << iteration.GetHypoName();
176     os << separator() << iteration.GetCaseName();
177     os << separator() << iteration.GetDirNameLoc();
178
179     saux = os.str();
180 //     MESSAGE( ". Fin avec "<<saux);
181     return saux ;
182   }
183 //
184 // ==============
185 // 1.3. hypothese
186 // ==============
187   /*!
188     \brief Dump hypothesis to the string
189     \param hypothesis hypothesis being dumped
190     \return string representation of the hypothesis
191   */
192   std::string Dump( const HOMARD_Hypothesis& hypothesis )
193   {
194     std::stringstream os;
195     std::string saux ;
196     // ...
197     MESSAGE( ". Sauvegarde de l'hypothese "<<hypothesis.GetName());
198     os << hypothesis.GetName();
199     os << separator() << hypothesis.GetCaseCreation();
200     os << separator() << hypothesis.GetAdapType();
201     os << separator() << hypothesis.GetRefinType();
202     os << separator() << hypothesis.GetUnRefType();
203     os << separator() << hypothesis.GetFieldName();
204     os << separator() << hypothesis.GetRefinThrType();
205     os << separator() << hypothesis.GetThreshR();
206     os << separator() << hypothesis.GetUnRefThrType();
207     os << separator() << hypothesis.GetThreshC();
208     os << separator() << hypothesis.GetUseField();
209     os << separator() << hypothesis.GetUseComp();
210     os << separator() << hypothesis.GetTypeFieldInterp();
211
212     std::list<std::string> ListString = hypothesis.GetIterations();
213     std::list<std::string>::const_iterator it;
214     os << separator() << ListString.size();
215     for ( it = ListString.begin(); it != ListString.end(); ++it )
216          os << separator() << *it;
217
218     ListString = hypothesis.GetZones();
219     os << separator() << ListString.size();
220     for ( it = ListString.begin(); it != ListString.end(); ++it )
221           os << separator() << *it;
222
223     ListString = hypothesis.GetComps();
224     os << separator() << ListString.size();
225     for ( it = ListString.begin(); it != ListString.end(); ++it )
226          os << separator() << *it;
227
228     ListString = hypothesis.GetGroups();
229     os << separator() << ListString.size();
230     for ( it = ListString.begin(); it != ListString.end(); ++it )
231           os << separator() << *it;
232
233     ListString = hypothesis.GetFieldInterps();
234     os << separator() << ListString.size();
235     for ( it = ListString.begin(); it != ListString.end(); ++it )
236           os << separator() << *it;
237
238     os << separator() << hypothesis.GetNivMax();
239     os << separator() << hypothesis.GetDiamMin();
240     os << separator() << hypothesis.GetAdapInit();
241     os << separator() << hypothesis.GetExtraOutput();
242
243     saux = os.str();
244 //     MESSAGE( ". Fin avec "<<saux);
245     return saux ;
246   }
247 //
248 // =========
249 // 1.4. Zone
250 // =========
251
252   /*!
253     \brief Dump zone to the string
254     \param zone zone being dumped
255     \return string representation of the zone
256   */
257   std::string Dump( const HOMARD_Zone& zone )
258   {
259     std::stringstream os;
260     std::string saux ;
261     MESSAGE( ". Sauvegarde de la zone "<<zone.GetName());
262     os << zone.GetName();
263     os << separator() << zone.GetType();
264
265     std::vector<double> coords = zone.GetCoords();
266     for ( int i = 0; i < coords.size(); i++ )
267       os << separator() << ( i < coords.size() ? coords[i] : 0. );
268
269     std::vector<double> limit = zone.GetLimit();
270     for ( int i = 0; i < 3; i++ )
271       os << separator() << ( i < limit.size() ? limit[i] : 0. );
272
273     std::list<std::string> hypos = zone.GetHypo();
274     os << separator() << hypos.size();
275     std::list<std::string>::const_iterator it;
276     for ( it = hypos.begin(); it != hypos.end(); ++it )
277       os << separator() << *it;
278
279     saux = os.str();
280 //     MESSAGE( ". Fin avec "<<saux);
281     return saux ;
282   }
283 //
284 // ==============================
285 // 1.5. Archivage d'une frontiere
286 // ==============================
287
288   /*!
289     \brief Dump boundary to the string
290     \param boundary boundary being dumped
291     \return string representation of the boundary
292   */
293   std::string Dump( const HOMARD_Boundary& boundary )
294   {
295     std::stringstream os;
296     std::string saux ;
297     MESSAGE( ". Sauvegarde de la frontiere "<<boundary.GetName());
298
299     int BoundaryType = boundary.GetType() ;
300
301     os << boundary.GetName() ;
302     os << separator() << BoundaryType ;
303     os << separator() << boundary.GetCaseCreation() ;
304
305     if ( BoundaryType == 0 )
306     {
307       os << separator() << boundary.GetMeshName();
308       os << separator() << boundary.GetMeshFile();
309     }
310     else {
311       std::vector<double> coor = boundary.GetCoords() ;
312       for ( int i = 0; i < coor.size(); i++ )
313             os << separator() << coor[i];
314       std::vector<double> limit = boundary.GetLimit();
315       for ( int i = 0; i < limit.size(); i++ )
316             os << separator() << limit[i];
317     }
318
319     std::list<std::string> ListString = boundary.GetGroups();
320     std::list<std::string>::const_iterator it;
321     os << separator() << ListString.size();
322     for ( it = ListString.begin(); it != ListString.end(); ++it )
323           os << separator() << *it;
324
325     saux = os.str();
326 //     MESSAGE( ". Fin avec "<<saux);
327     return saux ;
328   }
329
330 //
331 // =========
332 // 1.6. YACS
333 // =========
334
335   /*!
336     \brief Dump YACS to the string
337     \param yacs yacs being dumped
338     \return string representation of the zone
339   */
340   std::string Dump( const HOMARD_YACS& yacs )
341   {
342     std::stringstream os;
343     std::string saux ;
344     MESSAGE( ". Sauvegarde du schema YACS "<<yacs.GetName());
345     os << yacs.GetName();
346     os << separator() << yacs.GetType();
347
348     saux = os.str();
349 //     MESSAGE( ". Fin avec "<<saux);
350     return saux ;
351   }
352 //
353 // 2. Restauration des objets
354 // ==========================
355 // 2.1. Case
356 // ==========================
357 //
358   /*!
359     \brief Restore case from the string
360     \param cas case being restored
361     \param stream string representation of the case
362     \return \c true if case is correctly restored or \c false otherwise
363   */
364   bool Restore( HOMARD_Cas& cas, const std::string& stream )
365   {
366     MESSAGE( ". Restoration du cas ");
367     std::string::size_type start = 0;
368     std::string chunk, chunkNext;
369     bool ok;
370     // ...
371     chunk = getNextChunk( stream, start, ok );
372     if ( !ok ) return false;
373     cas.SetName( chunk.c_str() );
374
375     chunk = getNextChunk( stream, start, ok );
376     if ( !ok ) return false;
377     cas.SetDirName( chunk.c_str() );
378
379     chunk = getNextChunk( stream, start, ok );
380     if ( !ok ) return false;
381     cas.SetConfType( atoi( chunk.c_str() ) );
382
383     chunk = getNextChunk( stream, start, ok );
384     if ( !ok ) return false;
385
386     int size = atoi( chunk.c_str() );
387     std::vector<double> boite;
388     boite.resize( size );
389     for ( int i = 0; i < size; i++ ) {
390       chunk = getNextChunk( stream, start, ok );
391       if ( !ok ) return false;
392       boite[i] = strtod( chunk.c_str(), 0 );
393     }
394     cas.SetBoundingBox( boite );
395
396     chunk = getNextChunk( stream, start, ok );
397     if ( !ok ) return false;
398
399     size = atoi( chunk.c_str() );
400     for ( int i = 0; i < size; i++ ) {
401       chunk = getNextChunk( stream, start, ok );
402       if ( !ok ) return false;
403       cas.AddIteration( chunk.c_str() );
404     }
405
406     chunk = getNextChunk( stream, start, ok );
407     if ( !ok ) return false;
408     size = atoi( chunk.c_str() );
409     for ( int i = 0; i < size; i++ )
410     {
411       chunk = getNextChunk( stream, start, ok );
412       if ( !ok ) return false;
413       cas.AddGroup( chunk.c_str() );
414     }
415
416     chunk = getNextChunk( stream, start, ok );
417     if ( !ok ) return false;
418     size = atoi( chunk.c_str() );
419     for ( int i = 0; i < size; i++ ) {
420       chunk = getNextChunk( stream, start, ok );
421       if ( !ok ) return false;
422       i++;
423       chunkNext = getNextChunk( stream, start, ok );
424       if ( !ok ) return false;
425       cas.AddBoundaryGroup( chunk.c_str(), chunkNext.c_str() );
426     }
427
428     chunk = getNextChunk( stream, start, ok );
429     if ( !ok ) return false;
430     cas.SetPyram( atoi( chunk.c_str() ) );
431
432     return true;
433   }
434 //
435 // ==============
436 // 2.2. Iteration
437 // ==============
438   /*!
439     \brief Restore iteration from the string
440     \param iteration iteration being restored
441     \param stream string representation of the iteration
442     \return \c true if iteration is correctly restored or \c false otherwise
443   */
444   bool Restore( HOMARD_Iteration& iteration, const std::string& stream )
445   {
446     std::string::size_type start = 0;
447     std::string chunk;
448     bool ok;
449     chunk = getNextChunk( stream, start, ok );
450     if ( !ok ) return false;
451
452     iteration.SetName( chunk.c_str() );
453     chunk = getNextChunk( stream, start, ok );
454     if ( !ok ) return false;
455     iteration.SetState( atoi( chunk.c_str() ) );
456     chunk = getNextChunk( stream, start, ok );
457     if ( !ok ) return false;
458     iteration.SetNumber( atoi( chunk.c_str() ) );
459     chunk = getNextChunk( stream, start, ok );
460     if ( !ok ) return false;
461     iteration.SetMeshFile( chunk.c_str() );
462     chunk = getNextChunk( stream, start, ok );
463     if ( !ok ) return false;
464     iteration.SetLogFile( chunk.c_str() );
465     chunk = getNextChunk( stream, start, ok );
466     if ( !ok ) return false;
467     iteration.SetMeshName( chunk.c_str() );
468     chunk = getNextChunk( stream, start, ok );
469     if ( !ok ) return false;
470     iteration.SetFieldFile( chunk.c_str() );
471     // .
472     int timestep, rank;
473     chunk = getNextChunk( stream, start, ok );
474     if ( !ok ) return false;
475     timestep = atoi( chunk.c_str() );
476     chunk = getNextChunk( stream, start, ok );
477     if ( !ok ) return false;
478     rank = atoi( chunk.c_str() );
479     iteration.SetTimeStepRank( timestep, rank );
480     chunk = getNextChunk( stream, start, ok );
481     if ( !ok ) return false;
482     iteration.SetIterParentName( chunk.c_str() );
483     //
484     chunk = getNextChunk( stream, start, ok );
485     if ( !ok ) return false;
486     int size = atoi( chunk.c_str() );
487     for ( int i = 0; i < size; i++ ) {
488       chunk = getNextChunk( stream, start, ok );
489       if ( !ok ) return false;
490       iteration.LinkNextIteration( chunk.c_str() );
491     }
492     //
493     chunk = getNextChunk( stream, start, ok );
494     if ( !ok ) return false;
495     iteration.SetHypoName( chunk.c_str() );
496     chunk = getNextChunk( stream, start, ok );
497     if ( !ok ) return false;
498     iteration.SetCaseName( chunk.c_str() );
499     chunk = getNextChunk( stream, start, ok );
500     if ( !ok ) return false;
501     iteration.SetDirNameLoc( chunk.c_str() );
502     return true;
503   }
504
505 //
506 // ==============
507 // 2.3. hypothese
508 // ==============
509   /*!
510     \brief Restore hypothesis from the string
511     \param hypothesis hypothesis being restored
512     \param stream string representation of the hypothesis
513     \return \c true if hypothesis is correctly restored or \c false otherwise
514   */
515   bool Restore( HOMARD_Hypothesis& hypothesis, const std::string& stream )
516   {
517     std::string::size_type start = 0;
518     std::string chunk, chunkNext;
519     bool ok;
520
521     chunk = getNextChunk( stream, start, ok );
522     if ( !ok ) return false;
523     hypothesis.SetName( chunk.c_str() );
524
525     chunk = getNextChunk( stream, start, ok );
526     if ( !ok ) return false;
527     hypothesis.SetCaseCreation( chunk.c_str() );
528
529     chunk = getNextChunk( stream, start, ok );
530     if ( !ok ) return false;
531     hypothesis.SetAdapType( atoi( chunk.c_str() ) );
532
533     chunk = getNextChunk( stream, start, ok );
534     if ( !ok ) return false;
535     int typeraff = atoi( chunk.c_str() );
536     chunk = getNextChunk( stream, start, ok );
537     if ( !ok ) return false;
538     int typedera = atoi( chunk.c_str() );
539     hypothesis.SetRefinTypeDera( typeraff, typedera );
540
541     chunk = getNextChunk( stream, start, ok );
542     if ( !ok ) return false;
543     hypothesis.SetField( chunk.c_str() );
544
545     chunk = getNextChunk( stream, start, ok );
546     if ( !ok ) return false;
547     int typethr = atoi( chunk.c_str() );
548     chunk = getNextChunk( stream, start, ok );
549     if ( !ok ) return false;
550     double threshr = strtod( chunk.c_str(), 0 );
551     hypothesis.SetRefinThr( typethr, threshr );
552
553     chunk = getNextChunk( stream, start, ok );
554     if ( !ok ) return false;
555     int typethc = atoi( chunk.c_str() );
556     chunk = getNextChunk( stream, start, ok );
557     if ( !ok ) return false;
558     double threshc = strtod( chunk.c_str(), 0 );
559     hypothesis.SetUnRefThr( typethc, threshc );
560
561     chunk = getNextChunk( stream, start, ok );
562     if ( !ok ) return false;
563     hypothesis.SetUseField(atoi(chunk.c_str()));
564
565     chunk = getNextChunk( stream, start, ok );
566     if ( !ok ) return false;
567     hypothesis.SetUseComp(atoi(chunk.c_str()));
568
569     chunk = getNextChunk( stream, start, ok );
570     if ( !ok ) return false;
571     hypothesis.SetTypeFieldInterp(atoi(chunk.c_str()));
572
573     chunk = getNextChunk( stream, start, ok );
574     if ( !ok ) return false;
575     int size = atoi( chunk.c_str() );
576     for ( int i = 0; i < size; i++ ) {
577       chunk = getNextChunk( stream, start, ok );
578       if ( !ok ) return false;
579       hypothesis.LinkIteration( chunk.c_str() );
580     }
581
582     chunk = getNextChunk( stream, start, ok );
583     if ( !ok ) return false;
584     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       i++;
589       chunkNext = getNextChunk( stream, start, ok );
590       int typeuse = atoi( chunkNext.c_str() );
591       if ( !ok ) return false;
592       hypothesis.AddZone( chunk.c_str(), typeuse );
593     }
594
595     chunk = getNextChunk( stream, start, ok );
596     if ( !ok ) return false;
597     size = atoi( chunk.c_str() );
598     for ( int i = 0; i < size; i++ ) {
599       chunk = getNextChunk( stream, start, ok );
600       if ( !ok ) return false;
601       hypothesis.AddComp( chunk.c_str() );
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.AddGroup( 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       i++;
620       chunkNext = getNextChunk( stream, start, ok );
621       int TypeInterp = atoi( chunkNext.c_str() );
622       if ( !ok ) return false;
623       hypothesis.AddFieldInterpType( chunk.c_str(), TypeInterp );
624     }
625
626     chunk = getNextChunk( stream, start, ok );
627     if ( !ok ) return false;
628     hypothesis.SetNivMax( atoi( chunk.c_str() ) );
629
630     chunk = getNextChunk( stream, start, ok );
631     if ( !ok ) return false;
632     hypothesis.SetDiamMin( strtod( chunk.c_str(), 0 ) );
633
634     chunk = getNextChunk( stream, start, ok );
635     if ( !ok ) return false;
636     hypothesis.SetAdapInit( strtod( chunk.c_str(), 0 ) );
637
638     chunk = getNextChunk( stream, start, ok );
639     if ( !ok ) return false;
640     hypothesis.SetExtraOutput( strtod( chunk.c_str(), 0 ) );
641
642     return true;
643   }
644
645 //
646 // =========
647 // 2.4. Zone
648 // =========
649   /*!
650     \brief Restore zone from the string
651     \param zone zone being restored
652     \param stream string representation of the zone
653     \return \c true if zone is correctly restored or \c false otherwise
654   */
655   bool Restore( HOMARD_Zone& zone, const std::string& stream )
656   {
657     std::string::size_type start = 0;
658     std::string chunk;
659     bool ok;
660     //
661     chunk = getNextChunk( stream, start, ok );
662     if ( !ok ) return false;
663     zone.SetName( chunk.c_str() );
664     //
665     chunk = getNextChunk( stream, start, ok );
666     if ( !ok ) return false;
667     int ZoneType = atoi( chunk.c_str() ) ;
668     zone.SetType( ZoneType );
669     // Les coordonnees des zones : le nombre depend du type
670     std::vector<double> coords;
671     int lgcoords ;
672     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) ) { lgcoords = 6 ; }
673     else if ( ZoneType == 4 ) { lgcoords = 4 ; }
674     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) ) { lgcoords = 8 ; }
675     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) ) { lgcoords = 9 ; }
676     else return false;
677     coords.resize( lgcoords );
678     for ( int i = 0; i < lgcoords; i++ ) {
679       chunk = getNextChunk( stream, start, ok );
680       if ( !ok ) return false;
681       coords[i] = strtod( chunk.c_str(), 0 );
682     }
683     if ( ZoneType == 2 || ( ZoneType >= 11 && ZoneType <= 13 ) )
684     { zone.SetBox( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5] ); }
685     else if ( ZoneType == 4 )
686     { zone.SetSphere( coords[0], coords[1], coords[2], coords[3] ); }
687     else if ( ZoneType == 5 || ( ZoneType >= 31 && ZoneType <= 33 ) )
688     { zone.SetCylinder( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7] ); }
689     else if ( ZoneType == 7 || ( ZoneType >= 61 && ZoneType <= 63 ) )
690     { zone.SetPipe( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7], coords[8] ); }
691     // Remarque : la taille de coords est suffisante pour les limites
692     for ( int i = 0; i < 3; i++ ) {
693       chunk = getNextChunk( stream, start, ok );
694       if ( !ok ) return false;
695       coords[i] = strtod( chunk.c_str(), 0 );
696     }
697     zone.SetLimit( coords[0], coords[1], coords[2]);
698
699     chunk = getNextChunk( stream, start, ok );
700     if ( !ok ) return false;
701     int size = atoi( chunk.c_str() );
702     for ( int i = 0; i < size; i++ ) {
703       chunk = getNextChunk( stream, start, ok );
704       if ( !ok ) return false;
705       zone.AddHypo( chunk.c_str() );
706     }
707     return true;
708   }
709
710 //
711 // =================================
712 // 2.5. Restauration d'une frontiere
713 // =================================
714
715   /*!
716     \brief Restore boundary from the string
717     \param boundary boundary being restored
718     \param stream string representation of the boundary
719     \return \c true if the boundary is correctly restored or \c false otherwise
720   */
721   bool Restore( HOMARD_Boundary& boundary, const std::string& stream )
722   {
723     std::string::size_type start = 0;
724     std::string chunk;
725     bool ok;
726
727     chunk = getNextChunk( stream, start, ok );
728     if ( !ok ) return false;
729     boundary.SetName( chunk.c_str() );
730
731     chunk = getNextChunk( stream, start, ok );
732     if ( !ok ) return false;
733     int BoundaryType = atoi( chunk.c_str() ) ;
734     boundary.SetType( BoundaryType );
735
736     chunk = getNextChunk( stream, start, ok );
737     if ( !ok ) return false;
738     boundary.SetCaseCreation( chunk.c_str() );
739
740     // Si analytique, les coordonnees des frontieres : le nombre depend du type
741     // Si discret, le maillage
742     int lgcoords ;
743     if ( BoundaryType == 1 ) { lgcoords = 7 ; }
744     else if ( BoundaryType == 2 ) { lgcoords = 4 ; }
745     else { lgcoords = 0 ; }
746 //
747     if ( lgcoords == 0 )
748     {
749       chunk = getNextChunk( stream, start, ok );
750       if ( !ok ) return false;
751       boundary.SetMeshName( chunk.c_str() );
752
753       chunk = getNextChunk( stream, start, ok );
754       if ( !ok ) return false;
755       boundary.SetMeshFile( chunk.c_str() );
756     }
757     else
758     { std::vector<double> coords;
759       coords.resize( lgcoords );
760       for ( int i = 0; i < lgcoords; i++ ) {
761         chunk = getNextChunk( stream, start, ok );
762         if ( !ok ) return false;
763         coords[i] = strtod( chunk.c_str(), 0 );
764       }
765       if ( BoundaryType == 1 )
766       { boundary.SetCylinder(coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],coords[6]); }
767       else if ( BoundaryType == 2 )
768       { boundary.SetSphere( coords[0], coords[1], coords[2], coords[3]); }
769       else if ( BoundaryType == 3 )
770       { boundary.SetConeA( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6]); }
771       else if ( BoundaryType == 4 )
772       { boundary.SetConeR( coords[0], coords[1], coords[2], coords[3], coords[4], coords[5], coords[6], coords[7]); }
773       // Remarque : la taille de coords est suffisante pour les limites
774       for ( int i = 0; i < 3; i++ ) {
775         chunk = getNextChunk( stream, start, ok );
776         if ( !ok ) return false;
777         coords[i] = strtod( chunk.c_str(), 0 );
778       }
779       boundary.SetLimit( coords[0], coords[1], coords[2]);
780     }
781     // Les groupes
782     chunk = getNextChunk( stream, start, ok );
783     if ( !ok ) return false;
784     int size = atoi( chunk.c_str() );
785     for ( int i = 0; i < size; i++ ) {
786       chunk = getNextChunk( stream, start, ok );
787       if ( !ok ) return false;
788       boundary.AddGroup( chunk.c_str() );
789     }
790
791     return true;
792   }
793
794 //
795 // ==================================
796 // 2.6. Restauration d'un schema YACS
797 // ==================================
798
799   /*!
800     \brief Restore a schema YACS from the string
801     \param yacs yacs being restored
802     \param stream string representation of the schema yacs
803     \return \c true if yacs is correctly restored or \c false otherwise
804   */
805   bool Restore( HOMARD_YACS& yacs, const std::string& stream )
806   {
807     std::string::size_type start = 0;
808     std::string chunk;
809     bool ok;
810
811     chunk = getNextChunk( stream, start, ok );
812     if ( !ok ) return false;
813     yacs.SetName( chunk.c_str() );
814
815     chunk = getNextChunk( stream, start, ok );
816     if ( !ok ) return false;
817     int YACSType = atoi( chunk.c_str() ) ;
818     yacs.SetType( YACSType );
819
820     return true;
821   }
822
823 } // namespace HOMARD /end/