Changed: handleDataOutput is now a SIMSolver member

This commit is contained in:
Knut Morten Okstad 2017-04-20 15:45:40 +02:00
parent e1b2f6d1b3
commit 8765eb75e3
6 changed files with 62 additions and 62 deletions

View File

@ -15,9 +15,6 @@
#define _APP_COMMON_H_ #define _APP_COMMON_H_
#include "XMLInputBase.h" #include "XMLInputBase.h"
#include "HDF5Writer.h"
#include "XMLWriter.h"
#include "IFEM.h"
namespace SIM namespace SIM
@ -36,30 +33,6 @@ namespace SIM
public: public:
int dim; //!< Dimensionality of simulation int dim; //!< Dimensionality of simulation
}; };
//! \brief Handles application data output.
//! \param[in] simulator The top SIMbase instance of your application
//! \param[in] solver The SIMSolver instance of your application
//! \param[in] hdf5file The file to save to
//! \param[in] append Whether or not to append to file
//! \param[in] interval The stride in the output file
//! \param[in] restartInterval The stride in the restart file
template<class Simulator, class Solver>
DataExporter* handleDataOutput(Simulator& simulator, Solver& solver,
const std::string& hdf5file,
bool append = false,
int interval = 1,
int restartInterval = 0)
{
DataExporter* writer = new DataExporter(true,interval,restartInterval);
XMLWriter* xml = new XMLWriter(hdf5file,solver.getProcessAdm());
HDF5Writer* hdf = new HDF5Writer(hdf5file,solver.getProcessAdm(),append);
writer->registerWriter(xml);
writer->registerWriter(hdf);
simulator.registerFields(*writer);
IFEM::registerCallback(*writer);
return writer;
}
} }
#endif #endif

View File

@ -166,14 +166,14 @@ public:
//! \brief Serialize internal state for restarting purposes. //! \brief Serialize internal state for restarting purposes.
//! \param data Container for serialized data //! \param data Container for serialized data
bool serialize(DataExporter::SerializeData& data) bool serialize(std::map<std::string,std::string>& data)
{ {
return S1.serialize(data) && S2.serialize(data); return S1.serialize(data) && S2.serialize(data);
} }
//! \brief Set internal state from a serialized state. //! \brief Set internal state from a serialized state.
//! \param[in] data Container for serialized data //! \param[in] data Container for serialized data
bool deSerialize(const DataExporter::SerializeData& data) bool deSerialize(const std::map<std::string,std::string>& data)
{ {
return S1.deSerialize(data) && S2.deSerialize(data); return S1.deSerialize(data) && S2.deSerialize(data);
} }

View File

@ -13,10 +13,12 @@
#ifndef SIM_EXPLICIT_RK_H_ #ifndef SIM_EXPLICIT_RK_H_
#define SIM_EXPLICIT_RK_H_ #define SIM_EXPLICIT_RK_H_
#include "DataExporter.h"
#include "TimeIntUtils.h" #include "TimeIntUtils.h"
#include "TimeStep.h" #include "TimeStep.h"
class DataExporter;
namespace TimeIntegration { namespace TimeIntegration {
//! \brief Explicit Runge-Kutta based time stepping for SIM classes //! \brief Explicit Runge-Kutta based time stepping for SIM classes
@ -77,20 +79,18 @@ public:
} }
//! \copydoc ISolver::solveStep(TimeStep&) //! \copydoc ISolver::solveStep(TimeStep&)
bool solveStep(TimeStep& tp) virtual bool solveStep(TimeStep& tp)
{ {
std::cout <<"\n step = "<< tp.step <<" time = "<< tp.time.t << std::endl; std::cout <<"\n step = "<< tp.step <<" time = "<< tp.time.t << std::endl;
std::vector<Vector> stages; Vectors stages;
return solveRK(stages, tp); return this->solveRK(stages, tp);
return true;
} }
//! \brief Apply the Runge-Kutta scheme //! \brief Applies the Runge-Kutta scheme.
//! \param stages Vector of stage vectors //! \param stages Vector of stage vectors
//! \param tp Time stepping information //! \param[in] tp Time stepping information
bool solveRK(std::vector<Vector>& stages, TimeStep& tp) bool solveRK(Vectors& stages, const TimeStep& tp)
{ {
TimeDomain time(tp.time); TimeDomain time(tp.time);
Vector dum; Vector dum;
@ -142,16 +142,22 @@ public:
return solver.saveStep(tp, nBlock); return solver.saveStep(tp, nBlock);
} }
//! \copydoc ISolver::registerFields(DataExporter&)
void registerFields(DataExporter& exporter)
{
solver.registerFields(exporter);
}
//! \brief Serialize internal state for restarting purposes. //! \brief Serialize internal state for restarting purposes.
//! \param data Container for serialized data //! \param data Container for serialized data
bool serialize(DataExporter::SerializeData& data) bool serialize(std::map<std::string,std::string>& data)
{ {
return solver.serialize(data); return solver.serialize(data);
} }
//! \brief Set internal state from a serialized state. //! \brief Set internal state from a serialized state.
//! \param[in] data Container for serialized data //! \param[in] data Container for serialized data
bool deSerialize(const DataExporter::SerializeData& data) bool deSerialize(const std::map<std::string,std::string>& data)
{ {
return solver.deSerialize(data); return solver.deSerialize(data);
} }

View File

@ -14,10 +14,11 @@
#ifndef _SIM_SOLVER_H_ #ifndef _SIM_SOLVER_H_
#define _SIM_SOLVER_H_ #define _SIM_SOLVER_H_
#include "IFEM.h"
#include "SIMadmin.h" #include "SIMadmin.h"
#include "TimeStep.h" #include "TimeStep.h"
#include "HDF5Writer.h" #include "HDF5Writer.h"
#include "IFEM.h" #include "XMLWriter.h"
#include "tinyxml.h" #include "tinyxml.h"
@ -60,10 +61,11 @@ public:
SIMSolver(T1& s1) : SIMadmin("Time integration driver"), S1(s1) SIMSolver(T1& s1) : SIMadmin("Time integration driver"), S1(s1)
{ {
saveDivergedSol = false; saveDivergedSol = false;
exporter = nullptr;
} }
//! \brief Empty destructor. //! \brief The destructor deletes the results data exporter object.
virtual ~SIMSolver() {} virtual ~SIMSolver() { delete exporter; }
//! \brief Returns a const reference to the time stepping information. //! \brief Returns a const reference to the time stepping information.
const TimeStep& getTimePrm() const { return tp; } const TimeStep& getTimePrm() const { return tp; }
@ -77,13 +79,13 @@ public:
void postSolve(const TimeStep& t, bool rst = false) { S1.postSolve(t,rst); } void postSolve(const TimeStep& t, bool rst = false) { S1.postSolve(t,rst); }
//! \brief Solves the problem up to the final time. //! \brief Solves the problem up to the final time.
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr, virtual int solveProblem(char* infile, const char* heading = nullptr,
const char* heading = nullptr, bool saveInit = true) bool saveInit = true)
{ {
// Save FE model to VTF and HDF5 for visualization // Save FE model to VTF and HDF5 for visualization
// Optionally save the initial configuration also // Optionally save the initial configuration also
int geoBlk = 0, nBlock = 0; int geoBlk = 0, nBlock = 0;
if (!this->saveState(exporter,geoBlk,nBlock,true,infile,saveInit)) if (!this->saveState(geoBlk,nBlock,true,infile,saveInit))
return 2; return 2;
this->printHeading(heading); this->printHeading(heading);
@ -92,7 +94,7 @@ public:
for (int iStep = 1; this->advanceStep(); iStep++) for (int iStep = 1; this->advanceStep(); iStep++)
if (!S1.solveStep(tp)) if (!S1.solveStep(tp))
return saveDivergedSol && !S1.saveStep(tp,nBlock) ? 4 : 3; return saveDivergedSol && !S1.saveStep(tp,nBlock) ? 4 : 3;
else if (!this->saveState(exporter,geoBlk,nBlock)) else if (!this->saveState(geoBlk,nBlock))
return 4; return 4;
else else
IFEM::pollControllerFifo(); IFEM::pollControllerFifo();
@ -147,9 +149,8 @@ protected:
} }
//! \brief Saves geometry and results to VTF and HDF5 for current time step. //! \brief Saves geometry and results to VTF and HDF5 for current time step.
bool saveState(DataExporter* exporter, int& geoBlk, int& nBlock, bool saveState(int& geoBlk, int& nBlock, bool newMesh = false,
bool newMesh = false, char* infile = nullptr, char* infile = nullptr, bool saveRes = true)
bool saveRes = true)
{ {
if (newMesh && !S1.saveModel(infile,geoBlk,nBlock)) if (newMesh && !S1.saveModel(infile,geoBlk,nBlock))
return false; return false;
@ -195,12 +196,34 @@ public:
return restartStep; return restartStep;
} }
//! \brief Handles application data output.
//! \param[in] hdf5file The file to save to
//! \param[in] saveInterval The stride in the output file
//! \param[in] restartInterval The stride in the restart file
void handleDataOutput(const std::string& hdf5file,
int saveInterval = 1, int restartInterval = 0)
{
if (IFEM::getOptions().discretization < ASM::Spline && !hdf5file.empty())
IFEM::cout <<"\n ** HDF5 output is available for spline discretization"
<<" only. Deactivating...\n"<< std::endl;
else
{
exporter = new DataExporter(true,saveInterval,restartInterval);
exporter->registerWriter(new XMLWriter(hdf5file,adm));
exporter->registerWriter(new HDF5Writer(hdf5file,adm));
S1.registerFields(*exporter);
IFEM::registerCallback(*exporter);
}
}
private: private:
bool saveDivergedSol; //!< If \e true, save also the diverged solution to VTF bool saveDivergedSol; //!< If \e true, save also the diverged solution to VTF
protected: protected:
TimeStep tp; //!< Time stepping information TimeStep tp; //!< Time stepping information
T1& S1; //!< The actual solver T1& S1; //!< The actual solver
DataExporter* exporter; //!< Administrator for result output to HDF5 file
}; };
#endif #endif

View File

@ -37,11 +37,10 @@ public:
virtual ~SIMSolverAdap() {} virtual ~SIMSolverAdap() {}
//! \brief Solves the problem up to the final time. //! \brief Solves the problem up to the final time.
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr, virtual int solveProblem(char* infile, const char* heading, bool = false)
const char* heading = nullptr, bool = false)
{ {
if (exporter) if (SIMSolver<T1>::exporter)
exporter->setNormPrefixes(aSim.getNormPrefixes()); SIMSolver<T1>::exporter->setNormPrefixes(aSim.getNormPrefixes());
aSim.setupProjections(); aSim.setupProjections();
aSim.initAdaptor(0,2); aSim.initAdaptor(0,2);
@ -53,8 +52,8 @@ public:
return 1; return 1;
else if (!aSim.writeGlv(infile,iStep,aSim.getNoNorms())) else if (!aSim.writeGlv(infile,iStep,aSim.getNoNorms()))
return 2; return 2;
else if (exporter) else if (SIMSolver<T1>::exporter)
exporter->dumpTimeLevel(nullptr,true); SIMSolver<T1>::exporter->dumpTimeLevel(nullptr,true);
return 0; return 0;
} }

View File

@ -43,8 +43,7 @@ public:
virtual ~SIMSolverTS() {} virtual ~SIMSolverTS() {}
//! \brief Solves the problem up to the final time. //! \brief Solves the problem up to the final time.
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr, virtual int solveProblem(char* infile, const char* heading, bool saveInit)
const char* heading = nullptr, bool saveInit = true)
{ {
// Perform some initial refinement to resolve geometric features, etc. // Perform some initial refinement to resolve geometric features, etc.
if (!this->S1.initialRefine(beta,minFrac,maxRef)) if (!this->S1.initialRefine(beta,minFrac,maxRef))
@ -52,7 +51,7 @@ public:
// Save the initial FE model (and state) to VTF and HDF5 for visualization // Save the initial FE model (and state) to VTF and HDF5 for visualization
int geoBlk = 0, nBlock = 0; int geoBlk = 0, nBlock = 0;
if (!this->saveState(exporter,geoBlk,nBlock,true,infile,saveInit)) if (!this->saveState(geoBlk,nBlock,true,infile,saveInit))
return 2; return 2;
this->printHeading(heading); this->printHeading(heading);
@ -81,7 +80,7 @@ public:
if (!this->advanceStep()) // Final time reached if (!this->advanceStep()) // Final time reached
// Save updated FE model if mesh has been refined // Save updated FE model if mesh has been refined
// Save current results to VTF and HDF5 and then exit // Save current results to VTF and HDF5 and then exit
return this->saveState(exporter,geoBlk,nBlock,refElms > 0) ? 0 : 2; return this->saveState(geoBlk,nBlock,refElms > 0) ? 0 : 2;
else if (!this->S1.solveStep(this->tp)) else if (!this->S1.solveStep(this->tp))
return 3; return 3;
@ -106,7 +105,7 @@ public:
// The mesh is sufficiently refined at this state. // The mesh is sufficiently refined at this state.
// Save the current results to VTF and HDF5, and continue. // Save the current results to VTF and HDF5, and continue.
// Note: We then miss the results from the preceding nPredict-1 steps. // Note: We then miss the results from the preceding nPredict-1 steps.
if (!this->saveState(exporter,geoBlk,nBlock,refElms > 0)) if (!this->saveState(geoBlk,nBlock,refElms > 0))
return 2; return 2;
} }
else else
@ -124,7 +123,7 @@ public:
return 0; // Final time reached, we're done return 0; // Final time reached, we're done
else if (!this->S1.solveStep(this->tp)) else if (!this->S1.solveStep(this->tp))
return 3; return 3;
else if (!this->saveState(exporter,geoBlk,nBlock,j < 1)) else if (!this->saveState(geoBlk,nBlock,j < 1))
return 2; return 2;
} }
} }