Skip to content
Snippets Groups Projects
Commit 42ebaa04 authored by Elias Pipping's avatar Elias Pipping
Browse files

[Output] Overhaul writer logic, rename writeVTK

- The configuration parameter io.writeVTK is now io.vtk.write
- The configuration parameters restarts.first and restarts.spacing
  were moved into the io namespace
- Restarts are stored in a separate file
- VTK data, restarts (in HDF5), and the other HDF5 data are now
  each controlled through a parameter:
    io.data.write, io.restarts.write, io.vtk.write

In particular, it is thus now possible to write VTK data while
opening the data and restart files in read-only mode (or not at all);
This makes it possible to, by keeping the restarts file (and the binary!)
around, quickly (re-)compute a a small segment from the history.

The likeliest scenario: VTK files are huge and for a computation with
tens of thousands of timesteps (e.g. 30000), we know already (from the
data, or just expect it) that an event occurred during the last 500
timesteps. So we recompute them from a restart in the following mode:

  -io.restarts.first 29500
  -io.restarts.write false
  -io.data.write false
  -io.vtk.write true

Note that care needs to be taken to use a number for io.restarts.first
which is compatible with the old io.restarts.spacing
parent 5729c111
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "hdf5/frictionalboundary-writer.hh" #include "hdf5/frictionalboundary-writer.hh"
#include "hdf5/iteration-writer.hh" #include "hdf5/iteration-writer.hh"
#include "hdf5/patchinfo-writer.hh" #include "hdf5/patchinfo-writer.hh"
#include "hdf5/restart-io.hh"
#include "hdf5/surface-writer.hh" #include "hdf5/surface-writer.hh"
#include "hdf5/time-writer.hh" #include "hdf5/time-writer.hh"
...@@ -32,8 +31,8 @@ class HDF5Writer { ...@@ -32,8 +31,8 @@ class HDF5Writer {
patchInfoWriter_(file_, vertexBasis, frictionalBoundary, weakPatch), patchInfoWriter_(file_, vertexBasis, frictionalBoundary, weakPatch),
#endif #endif
surfaceWriter_(file_, vertexCoordinates, surface), surfaceWriter_(file_, vertexCoordinates, surface),
frictionalBoundaryWriter_(file_, vertexCoordinates, frictionalBoundary), frictionalBoundaryWriter_(file_, vertexCoordinates,
restartWriter_(file_, vertexCoordinates.size()) { frictionalBoundary) {
} }
template <class Friction> template <class Friction>
...@@ -53,10 +52,6 @@ class HDF5Writer { ...@@ -53,10 +52,6 @@ class HDF5Writer {
iterationWriter_.write(programState.timeStep, iterationCount); iterationWriter_.write(programState.timeStep, iterationCount);
} }
void writeRestart(ProgramState const &programState) {
restartWriter_.write(programState);
}
private: private:
HDF5::Grouplike &file_; HDF5::Grouplike &file_;
...@@ -67,7 +62,5 @@ class HDF5Writer { ...@@ -67,7 +62,5 @@ class HDF5Writer {
#endif #endif
SurfaceWriter<ProgramState, GridView> surfaceWriter_; SurfaceWriter<ProgramState, GridView> surfaceWriter_;
FrictionalBoundaryWriter<ProgramState, GridView> frictionalBoundaryWriter_; FrictionalBoundaryWriter<ProgramState, GridView> frictionalBoundaryWriter_;
RestartIO<ProgramState> restartWriter_;
}; };
#endif #endif
...@@ -5,18 +5,17 @@ ...@@ -5,18 +5,17 @@
#include "restart-io.hh" #include "restart-io.hh"
template <class ProgramState> template <class ProgramState>
RestartIO<ProgramState>::RestartIO(HDF5::Grouplike &file, size_t vertexCount) RestartIO<ProgramState>::RestartIO(HDF5::Grouplike &group, size_t vertexCount)
: group_(file, "restarts"), : displacementWriter_(group, "displacement", vertexCount,
displacementWriter_(group_, "displacement", vertexCount,
Vector::block_type::dimension), Vector::block_type::dimension),
velocityWriter_(group_, "velocity", vertexCount, velocityWriter_(group, "velocity", vertexCount,
Vector::block_type::dimension), Vector::block_type::dimension),
accelerationWriter_(group_, "acceleration", vertexCount, accelerationWriter_(group, "acceleration", vertexCount,
Vector::block_type::dimension), Vector::block_type::dimension),
stateWriter_(group_, "state", vertexCount), stateWriter_(group, "state", vertexCount),
weightedNormalStressWriter_(group_, "weightedNormalStress", vertexCount), weightedNormalStressWriter_(group, "weightedNormalStress", vertexCount),
relativeTimeWriter_(group_, "relativeTime"), relativeTimeWriter_(group, "relativeTime"),
relativeTimeIncrementWriter_(group_, "relativeTimeIncrement") {} relativeTimeIncrementWriter_(group, "relativeTimeIncrement") {}
template <class ProgramState> template <class ProgramState>
void RestartIO<ProgramState>::write(ProgramState const &programState) { void RestartIO<ProgramState>::write(ProgramState const &programState) {
......
...@@ -9,15 +9,13 @@ template <class ProgramState> class RestartIO { ...@@ -9,15 +9,13 @@ template <class ProgramState> class RestartIO {
using Vector = typename ProgramState::Vector; using Vector = typename ProgramState::Vector;
public: public:
RestartIO(HDF5::Grouplike &file, size_t vertexCount); RestartIO(HDF5::Grouplike &group, size_t vertexCount);
void write(ProgramState const &programState); void write(ProgramState const &programState);
void read(size_t timeStep, ProgramState &programState); void read(size_t timeStep, ProgramState &programState);
private: private:
HDF5::Group group_;
HDF5::SequenceIO<2> displacementWriter_; HDF5::SequenceIO<2> displacementWriter_;
HDF5::SequenceIO<2> velocityWriter_; HDF5::SequenceIO<2> velocityWriter_;
HDF5::SequenceIO<2> accelerationWriter_; HDF5::SequenceIO<2> accelerationWriter_;
......
...@@ -176,15 +176,29 @@ int main(int argc, char *argv[]) { ...@@ -176,15 +176,29 @@ int main(int argc, char *argv[]) {
_ell += gravityFunctional; _ell += gravityFunctional;
}; };
ProgramState<Vector, ScalarVector> programState(leafVertexCount); using MyProgramState = ProgramState<Vector, ScalarVector>;
auto const firstRestart = parset.get<size_t>("restarts.first"); MyProgramState programState(leafVertexCount);
auto const restartSpacing = parset.get<size_t>("restarts.spacing"); auto const firstRestart = parset.get<size_t>("io.restarts.first");
auto const restartTemplate = parset.get<std::string>("restarts.template"); auto const restartSpacing = parset.get<size_t>("io.restarts.spacing");
auto const writeRestarts = parset.get<bool>("io.restarts.write");
HDF5::File ioFile("output.h5"); auto const writeData = parset.get<bool>("io.data.write");
if (firstRestart != 0) bool const handleRestarts = writeRestarts or firstRestart > 0;
RestartIO<ProgramState<Vector, ScalarVector>>(ioFile, leafVertexCount)
.read(firstRestart, programState); auto dataFile =
writeData ? std::make_unique<HDF5::File>("output.h5") : nullptr;
auto restartFile = handleRestarts
? std::make_unique<HDF5::File>(
"restarts.h5",
writeRestarts ? HDF5::Access::READWRITE
: HDF5::Access::READONLY)
: nullptr;
auto restartIO = handleRestarts
? std::make_unique<RestartIO<MyProgramState>>(
*restartFile, leafVertexCount)
: nullptr;
if (firstRestart > 0) // automatically adjusts the time and timestep
restartIO->read(firstRestart, programState);
else else
programState.setupInitialConditions(parset, computeExternalForces, programState.setupInitialConditions(parset, computeExternalForces,
matrices, myAssembler, dirichletNodes, matrices, myAssembler, dirichletNodes,
...@@ -205,24 +219,30 @@ int main(int argc, char *argv[]) { ...@@ -205,24 +219,30 @@ int main(int argc, char *argv[]) {
vertexCoordinates[vertexMapper.index(v)] = geoToPoint(v.geometry()); vertexCoordinates[vertexMapper.index(v)] = geoToPoint(v.geometry());
} }
HDF5Writer<ProgramState<Vector, ScalarVector>, using MyVertexBasis = typename MyAssembler::VertexBasis;
typename MyAssembler::VertexBasis, GridView> auto dataWriter =
hdf5Writer(ioFile, vertexCoordinates, myAssembler.vertexBasis, surface, writeData ? std::make_unique<
frictionalBoundary, weakPatch); HDF5Writer<MyProgramState, MyVertexBasis, GridView>>(
MyVTKWriter<typename MyAssembler::VertexBasis, *dataFile, vertexCoordinates, myAssembler.vertexBasis,
typename MyAssembler::CellBasis> const surface, frictionalBoundary, weakPatch)
vtkWriter(myAssembler.cellBasis, myAssembler.vertexBasis, "obs"); : nullptr;
MyVTKWriter<MyVertexBasis, typename MyAssembler::CellBasis> const vtkWriter(
myAssembler.cellBasis, myAssembler.vertexBasis, "obs");
IterationRegister iterationCount; IterationRegister iterationCount;
auto const report = [&](bool initial = false) { auto const report = [&](bool initial = false) {
hdf5Writer.reportSolution(programState, *myGlobalFriction); if (writeData) {
if (!initial) dataWriter->reportSolution(programState, *myGlobalFriction);
hdf5Writer.reportIterations(programState, iterationCount); if (!initial)
dataWriter->reportIterations(programState, iterationCount);
if (!initial and programState.timeStep % restartSpacing == 0) dataFile->flush();
hdf5Writer.writeRestart(programState); }
ioFile.flush(); if (writeRestarts and !initial and
programState.timeStep % restartSpacing == 0) {
restartIO->write(programState);
restartFile->flush();
}
if (parset.get<bool>("io.printProgress")) if (parset.get<bool>("io.printProgress"))
std::cout << "timeStep = " << std::setw(6) << programState.timeStep std::cout << "timeStep = " << std::setw(6) << programState.timeStep
...@@ -230,7 +250,7 @@ int main(int argc, char *argv[]) { ...@@ -230,7 +250,7 @@ int main(int argc, char *argv[]) {
<< ", tau = " << std::setw(12) << programState.relativeTau << ", tau = " << std::setw(12) << programState.relativeTau
<< std::endl; << std::endl;
if (parset.get<bool>("io.writeVTK")) { if (parset.get<bool>("io.vtk.write")) {
ScalarVector stress; ScalarVector stress;
myAssembler.assembleVonMisesStress(body.getYoungModulus(), myAssembler.assembleVonMisesStress(body.getYoungModulus(),
body.getPoissonRatio(), body.getPoissonRatio(),
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
gravity = 9.81 # [m/s^2] gravity = 9.81 # [m/s^2]
[io] [io]
data.write = true
printProgress = false printProgress = false
writeVTK = false restarts.first = 0
restarts.spacing= 20
restarts.write = true
vtk.write = false
[problem] [problem]
finalTime = 1000 # [s] finalTime = 1000 # [s]
...@@ -35,11 +39,6 @@ b = 0.017 # [ ] ...@@ -35,11 +39,6 @@ b = 0.017 # [ ]
a = 0.020 # [ ] a = 0.020 # [ ]
b = 0.005 # [ ] b = 0.005 # [ ]
[restarts]
template = restart_%06d
first = 0
spacing = 20
[timeSteps] [timeSteps]
scheme = newmark scheme = newmark
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment