~esys-p-dev/esys-particle/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2014 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////


#include "Foundation/StringUtil.h"
#include "Parallel/CheckPointInfo.h"
#include "Geometry/GeometryInfo.h"
#include "Foundation/version.h"
#include "bzrversion.h"

namespace esys
{
  namespace lsm
  {
    class CheckPointInfo::Impl
    {
    public:
      Impl()
        : m_numTimeSteps(0),
          m_timeStepSize(0.0),
          m_timeStep(0),
          m_geoInfo(),
          m_fileNames(),
	  m_bzrVersion(s_bzr_revision)
      {
      }

      ~Impl()
      {
      }

      bool operator==(const Impl &impl) const
      {
        return
          (
            (m_numTimeSteps == impl.m_numTimeSteps)
            &&
            (m_timeStepSize == impl.m_timeStepSize)
            &&
            (m_timeStep     == impl.m_timeStep)
            &&
            (m_geoInfo      == impl.m_geoInfo)
            &&
            (m_fileNames    == impl.m_fileNames)
          );
      }
      
      void read(std::istream &iStream)
      {
	string magic;
	int version;
        iStream	>> magic >> version; 
	iStream 
          >> m_numTimeSteps
          >> m_timeStepSize
          >> m_timeStep;
          m_geoInfo.read(iStream);

          std::string fileNames;
          /*
           * Skip over any blank lines.
           */
          while (fileNames.size() <= 0) {
            std::getline(iStream, fileNames);
            fileNames = StringUtil::trim(fileNames);
          }
          m_fileNames = StringUtil::splitStrings(fileNames, " ");
      }

      /*!
	write checkpoint info to output stream

	\param oStream the output stream
      */
      void write(std::ostream &oStream) const
      {
        const char delim = '\n';
        oStream
	  << "V " << lsm_version_info::CheckPointVersion << delim
          << m_numTimeSteps << delim
          << m_timeStepSize << delim
          << m_timeStep     << delim;
	// ESyS-Particle version info
	oStream << lsm_version_info::ESySParticleVersion << m_bzrVersion << delim ;
        m_geoInfo.writeWithoutVersion(oStream);
        oStream
          << delim
          << StringUtil::join(
              m_fileNames.begin(),
              m_fileNames.end(),
              std::string(" "),
              StringUtil::StdOStreamOp<StringVector::const_iterator>()
            );
      }

      int          m_numTimeSteps;
      double       m_timeStepSize;
      int          m_timeStep;
      GeometryInfo m_geoInfo;
      StringVector m_fileNames;
      int          m_bzrVersion;
    };

    CheckPointInfo::CheckPointInfo() : m_pImpl(new CheckPointInfo::Impl)
    {
    }

    CheckPointInfo::~CheckPointInfo()
    {
      delete m_pImpl;
    }
    
    bool CheckPointInfo::operator==(const CheckPointInfo &cpInfo) const
    {
      return (*m_pImpl == *(cpInfo.m_pImpl));
    }

    const GeometryInfo &CheckPointInfo::getGeometryInfo() const
    {
      return m_pImpl->m_geoInfo;
    }

    void CheckPointInfo::setGeometryInfo(const GeometryInfo &geoInfo)
    {
      m_pImpl->m_geoInfo = geoInfo;
    }
    
    const StringVector &CheckPointInfo::getLatticeDataFiles() const
    {
      return m_pImpl->m_fileNames;
    }

    void CheckPointInfo::setLatticeDataFiles(const StringVector &fileNames)
    {
      m_pImpl->m_fileNames = fileNames;
    }
    
    void CheckPointInfo::setNumTimeSteps(int numTimeSteps)
    {
      m_pImpl->m_numTimeSteps = numTimeSteps;
    }

    void CheckPointInfo::setTimeStep(int timeStep)
    {
      m_pImpl->m_timeStep = timeStep;
    }

    int CheckPointInfo::getTimeStep() const
    {
      return m_pImpl->m_timeStep;
    }
    
    void CheckPointInfo::setTimeStepSize(double timeStepSize)
    {
      m_pImpl->m_timeStepSize = timeStepSize;
    }

    void CheckPointInfo::read(std::istream &iStream)
    {
      m_pImpl->read(iStream);
    }

    void CheckPointInfo::write(std::ostream &oStream) const
    {
      m_pImpl->write(oStream);
    }
  }
}