25#include <boost/filesystem.hpp>
27#include <dune/grid/common/backuprestore.hh>
28#include <dune/istl/bvector.hh>
82 boost::filesystem::path path =
directory/(gridName+
".grid");
83 boost::filesystem::path tmpPath = path;
84 tmpPath += std::string(
"~");
86 Dune::BackupRestoreFacility<Grid>::backup(grid, tmpPath.string());
87 boost::filesystem::rename(tmpPath, path);
98 std::unique_ptr<Grid>
readGrid(std::string
const& gridName)
const {
100 return std::unique_ptr<Grid>(Dune::BackupRestoreFacility<Grid>::restore((
directory/(gridName+
".grid")).
string()));
113 template <
class Index>
114 void writeRefinementHistory(std::vector<std::vector<std::pair<int, Index>>>
const& refHist, std::string
const& gridName)
const {
115 boost::filesystem::path path =
directory/(gridName+
".refHist");
116 boost::filesystem::path tmpPath = path;
118 std::ofstream out(tmpPath.string(), std::ios::binary);
119 for(
auto const& refStep : refHist) {
120 out << refStep.size() <<
" ";
121 out.write(
reinterpret_cast<char const*
>(refStep.data()),
sizeof(std::pair<int, Index>) * refStep.size());
123 boost::filesystem::rename(tmpPath, path);
133 template <
class Index>
135 boost::filesystem::path path =
directory/(gridName+
".refHist");
136 boost::filesystem::path tmpPath = path;
138 if(boost::filesystem::exists(path)) boost::filesystem::copy_file(path, tmpPath);
139 std::ofstream out(tmpPath.string(), std::ios::binary | std::ios::app);
140 out << refStep.size() <<
" ";
141 out.write(
reinterpret_cast<char const*
>(refStep.data()),
sizeof(std::pair<int, Index>) * refStep.size());
142 boost::filesystem::rename(tmpPath, path);
156 template <
class Index>
158 using RefHist = std::vector<std::vector<std::pair<int, Index>>>;
159 using RefStep =
typename RefHist::value_type;
161 std::ifstream in((
directory/(gridName+
".refHist")).
string(), std::ios::binary);
162 typename RefStep::size_type nRefCells;
163 while(in >> nRefCells) {
164 refHist.push_back(RefStep(nRefCells));
166 in.read(
reinterpret_cast<char *
>(refHist.back().data()),
sizeof(
typename RefStep::value_type) * nRefCells);
176 template <
template<
class,
int>
class Array,
class Scalar,
int dim>
178 boost::filesystem::path path =
directory/(dataName+
".data");
179 boost::filesystem::path tmpPath = path;
180 tmpPath += std::string(
"~");
181 writeData(data, std::ofstream(tmpPath.string(), std::ios::binary));
182 boost::filesystem::rename(tmpPath, path);
190 template <
class DataBlocks>
191 void writeData(DataBlocks
const& data, std::string
const& dataName)
const {
192 boost::filesystem::path path =
directory/(dataName+
".data");
193 boost::filesystem::path tmpPath = path;
194 tmpPath += std::string(
"~");
195 std::ofstream out(tmpPath.string(), std::ios::binary);
196 boost::fusion::for_each(data.data, [
this, &out](
auto const& dataBlock) {
197 out = this->writeData(dataBlock, std::move(out));
199 boost::filesystem::rename(tmpPath, path);
205 template <
class FeSpace,
int m>
215 template <
template<
class,
int>
class Array,
class Scalar,
int dim>
217 readData(data, std::ifstream((
directory/(dataName+
".data")).
string(), std::ios::binary));
225 template <
class DataBlocks>
226 void readData(DataBlocks & data, std::string
const& dataName)
const {
227 std::ifstream in((
directory/(dataName+
".data")).
string(), std::ios::binary);
228 boost::fusion::for_each(data.data, [
this, &in](
auto & dataBlock) {
229 in = this->readData(dataBlock, std::move(in));
236 template <
class FeSpace,
int m>
244 template <
template<
class,
int>
class Array,
class Scalar,
int dim>
246 out.write(
reinterpret_cast<char const*
>(&data[0]),
sizeof(
Scalar) * data.size() * dim);
250 template <
class FeSpace,
int m>
255 template <
template<
class,
int>
class Array,
class Scalar,
int dim>
257 in.read(
reinterpret_cast<char *
>(&data[0]),
sizeof(
Scalar) * data.size() * dim);
261 template <
class FeSpace,
int m>
A class for representing finite element functions.
StorageType const & coefficients() const
Provides read-only access to the coefficients of the finite element basis functions.
Grid const & grid() const
Returns a const reference on the owned grid.
Class that takes care of the transfer of data (of each FunctionSpaceElement) after modification of th...
bool readMode() const
readMode returns true if this check point was created in read mode (i.e. with existing directory give...
void appendRefinementHistory(std::vector< std::pair< int, Index > > const &refStep, std::string const &gridName) const
appends data of one refinement step of a grid to file.
void writeGrid(GridManager< Grid > const &gridManager, std::string const &gridName) const
writes grid into file with name gridName.
void writeData(Dune::BlockVector< Array< Scalar, dim > > const &data, std::string const &dataName) const
writes data into file with name dataName. Version for BlockVector.
CheckPoint()
CheckPoint creates a new empty directory with current time stamp as name. Later writes will refer to ...
void writeRefinementHistory(std::vector< std::vector< std::pair< int, Index > > > const &refHist, std::string const &gridName) const
writes the refinement history of a grid.
std::ofstream writeData(Dune::BlockVector< Array< Scalar, dim > > const &data, std::ofstream out) const
CheckPoint(std::string const &pathName)
CheckPoint. If the directory with pathName already exists later reads will refer to this directory....
void readData(DataBlocks &data, std::string const &dataName) const
reads data from file with name dataName. Version for LinearProductSpace (of FE-functions or coefficie...
void readData(FunctionSpaceElement< FeSpace, m > &data, std::string const &dataName) const
reads data from file with name dataName. Version for FE-function.
std::ifstream readData(Dune::BlockVector< Array< Scalar, dim > > &data, std::ifstream in) const
void writeGrid(Grid const &grid, std::string const &gridName) const
writes grid into file with name gridName.
void readData(Dune::BlockVector< Array< Scalar, dim > > &data, std::string const &dataName) const
reads data from file with name dataName. Version for BlockVector.
std::vector< std::vector< std::pair< int, Index > > > readRefinementHistory(std::string const &gridName) const
reads the refinement history of a grid.
std::string timeStamp() const
timeStamp gives the time stamp when directory was created (at construction of this CheckPoint instanc...
boost::filesystem::path directory
void writeData(DataBlocks const &data, std::string const &dataName) const
writes data into file with name dataName. Version for LinearProductSpace (of FE-functions or coeffici...
void writeData(FunctionSpaceElement< FeSpace, m > const &data, std::string const &dataName) const
writes data into file with name dataName. Version for FE-function.
std::ofstream writeData(FunctionSpaceElement< FeSpace, m > const &data, std::ofstream out) const
std::ifstream readData(FunctionSpaceElement< FeSpace, m > &data, std::ifstream in) const
std::unique_ptr< Grid > readGrid(std::string const &gridName) const
reads grid from file with name gridName.
Variables and their descriptions.