Changed: handleDataOutput is now a SIMSolver member
This commit is contained in:
parent
e1b2f6d1b3
commit
8765eb75e3
@ -15,9 +15,6 @@
|
||||
#define _APP_COMMON_H_
|
||||
|
||||
#include "XMLInputBase.h"
|
||||
#include "HDF5Writer.h"
|
||||
#include "XMLWriter.h"
|
||||
#include "IFEM.h"
|
||||
|
||||
|
||||
namespace SIM
|
||||
@ -36,30 +33,6 @@ namespace SIM
|
||||
public:
|
||||
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
|
||||
|
@ -166,14 +166,14 @@ public:
|
||||
|
||||
//! \brief Serialize internal state for restarting purposes.
|
||||
//! \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);
|
||||
}
|
||||
|
||||
//! \brief Set internal state from a serialized state.
|
||||
//! \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);
|
||||
}
|
||||
|
@ -13,10 +13,12 @@
|
||||
#ifndef SIM_EXPLICIT_RK_H_
|
||||
#define SIM_EXPLICIT_RK_H_
|
||||
|
||||
#include "DataExporter.h"
|
||||
#include "TimeIntUtils.h"
|
||||
#include "TimeStep.h"
|
||||
|
||||
class DataExporter;
|
||||
|
||||
|
||||
namespace TimeIntegration {
|
||||
|
||||
//! \brief Explicit Runge-Kutta based time stepping for SIM classes
|
||||
@ -77,20 +79,18 @@ public:
|
||||
}
|
||||
|
||||
//! \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::vector<Vector> stages;
|
||||
return solveRK(stages, tp);
|
||||
|
||||
return true;
|
||||
Vectors stages;
|
||||
return this->solveRK(stages, tp);
|
||||
}
|
||||
|
||||
//! \brief Apply the Runge-Kutta scheme
|
||||
//! \brief Applies the Runge-Kutta scheme.
|
||||
//! \param stages Vector of stage vectors
|
||||
//! \param tp Time stepping information
|
||||
bool solveRK(std::vector<Vector>& stages, TimeStep& tp)
|
||||
//! \param[in] tp Time stepping information
|
||||
bool solveRK(Vectors& stages, const TimeStep& tp)
|
||||
{
|
||||
TimeDomain time(tp.time);
|
||||
Vector dum;
|
||||
@ -142,16 +142,22 @@ public:
|
||||
return solver.saveStep(tp, nBlock);
|
||||
}
|
||||
|
||||
//! \copydoc ISolver::registerFields(DataExporter&)
|
||||
void registerFields(DataExporter& exporter)
|
||||
{
|
||||
solver.registerFields(exporter);
|
||||
}
|
||||
|
||||
//! \brief Serialize internal state for restarting purposes.
|
||||
//! \param data Container for serialized data
|
||||
bool serialize(DataExporter::SerializeData& data)
|
||||
bool serialize(std::map<std::string,std::string>& data)
|
||||
{
|
||||
return solver.serialize(data);
|
||||
}
|
||||
|
||||
//! \brief Set internal state from a serialized state.
|
||||
//! \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);
|
||||
}
|
||||
|
@ -14,10 +14,11 @@
|
||||
#ifndef _SIM_SOLVER_H_
|
||||
#define _SIM_SOLVER_H_
|
||||
|
||||
#include "IFEM.h"
|
||||
#include "SIMadmin.h"
|
||||
#include "TimeStep.h"
|
||||
#include "HDF5Writer.h"
|
||||
#include "IFEM.h"
|
||||
#include "XMLWriter.h"
|
||||
#include "tinyxml.h"
|
||||
|
||||
|
||||
@ -60,10 +61,11 @@ public:
|
||||
SIMSolver(T1& s1) : SIMadmin("Time integration driver"), S1(s1)
|
||||
{
|
||||
saveDivergedSol = false;
|
||||
exporter = nullptr;
|
||||
}
|
||||
|
||||
//! \brief Empty destructor.
|
||||
virtual ~SIMSolver() {}
|
||||
//! \brief The destructor deletes the results data exporter object.
|
||||
virtual ~SIMSolver() { delete exporter; }
|
||||
|
||||
//! \brief Returns a const reference to the time stepping information.
|
||||
const TimeStep& getTimePrm() const { return tp; }
|
||||
@ -77,13 +79,13 @@ public:
|
||||
void postSolve(const TimeStep& t, bool rst = false) { S1.postSolve(t,rst); }
|
||||
|
||||
//! \brief Solves the problem up to the final time.
|
||||
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr,
|
||||
const char* heading = nullptr, bool saveInit = true)
|
||||
virtual int solveProblem(char* infile, const char* heading = nullptr,
|
||||
bool saveInit = true)
|
||||
{
|
||||
// Save FE model to VTF and HDF5 for visualization
|
||||
// Optionally save the initial configuration also
|
||||
int geoBlk = 0, nBlock = 0;
|
||||
if (!this->saveState(exporter,geoBlk,nBlock,true,infile,saveInit))
|
||||
if (!this->saveState(geoBlk,nBlock,true,infile,saveInit))
|
||||
return 2;
|
||||
|
||||
this->printHeading(heading);
|
||||
@ -92,7 +94,7 @@ public:
|
||||
for (int iStep = 1; this->advanceStep(); iStep++)
|
||||
if (!S1.solveStep(tp))
|
||||
return saveDivergedSol && !S1.saveStep(tp,nBlock) ? 4 : 3;
|
||||
else if (!this->saveState(exporter,geoBlk,nBlock))
|
||||
else if (!this->saveState(geoBlk,nBlock))
|
||||
return 4;
|
||||
else
|
||||
IFEM::pollControllerFifo();
|
||||
@ -147,9 +149,8 @@ protected:
|
||||
}
|
||||
|
||||
//! \brief Saves geometry and results to VTF and HDF5 for current time step.
|
||||
bool saveState(DataExporter* exporter, int& geoBlk, int& nBlock,
|
||||
bool newMesh = false, char* infile = nullptr,
|
||||
bool saveRes = true)
|
||||
bool saveState(int& geoBlk, int& nBlock, bool newMesh = false,
|
||||
char* infile = nullptr, bool saveRes = true)
|
||||
{
|
||||
if (newMesh && !S1.saveModel(infile,geoBlk,nBlock))
|
||||
return false;
|
||||
@ -195,12 +196,34 @@ public:
|
||||
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:
|
||||
bool saveDivergedSol; //!< If \e true, save also the diverged solution to VTF
|
||||
|
||||
protected:
|
||||
TimeStep tp; //!< Time stepping information
|
||||
T1& S1; //!< The actual solver
|
||||
|
||||
DataExporter* exporter; //!< Administrator for result output to HDF5 file
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -37,11 +37,10 @@ public:
|
||||
virtual ~SIMSolverAdap() {}
|
||||
|
||||
//! \brief Solves the problem up to the final time.
|
||||
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr,
|
||||
const char* heading = nullptr, bool = false)
|
||||
virtual int solveProblem(char* infile, const char* heading, bool = false)
|
||||
{
|
||||
if (exporter)
|
||||
exporter->setNormPrefixes(aSim.getNormPrefixes());
|
||||
if (SIMSolver<T1>::exporter)
|
||||
SIMSolver<T1>::exporter->setNormPrefixes(aSim.getNormPrefixes());
|
||||
|
||||
aSim.setupProjections();
|
||||
aSim.initAdaptor(0,2);
|
||||
@ -53,8 +52,8 @@ public:
|
||||
return 1;
|
||||
else if (!aSim.writeGlv(infile,iStep,aSim.getNoNorms()))
|
||||
return 2;
|
||||
else if (exporter)
|
||||
exporter->dumpTimeLevel(nullptr,true);
|
||||
else if (SIMSolver<T1>::exporter)
|
||||
SIMSolver<T1>::exporter->dumpTimeLevel(nullptr,true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -43,8 +43,7 @@ public:
|
||||
virtual ~SIMSolverTS() {}
|
||||
|
||||
//! \brief Solves the problem up to the final time.
|
||||
virtual int solveProblem(char* infile, DataExporter* exporter = nullptr,
|
||||
const char* heading = nullptr, bool saveInit = true)
|
||||
virtual int solveProblem(char* infile, const char* heading, bool saveInit)
|
||||
{
|
||||
// Perform some initial refinement to resolve geometric features, etc.
|
||||
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
|
||||
int geoBlk = 0, nBlock = 0;
|
||||
if (!this->saveState(exporter,geoBlk,nBlock,true,infile,saveInit))
|
||||
if (!this->saveState(geoBlk,nBlock,true,infile,saveInit))
|
||||
return 2;
|
||||
|
||||
this->printHeading(heading);
|
||||
@ -81,7 +80,7 @@ public:
|
||||
if (!this->advanceStep()) // Final time reached
|
||||
// Save updated FE model if mesh has been refined
|
||||
// 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))
|
||||
return 3;
|
||||
|
||||
@ -106,7 +105,7 @@ public:
|
||||
// The mesh is sufficiently refined at this state.
|
||||
// Save the current results to VTF and HDF5, and continue.
|
||||
// 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;
|
||||
}
|
||||
else
|
||||
@ -124,7 +123,7 @@ public:
|
||||
return 0; // Final time reached, we're done
|
||||
else if (!this->S1.solveStep(this->tp))
|
||||
return 3;
|
||||
else if (!this->saveState(exporter,geoBlk,nBlock,j < 1))
|
||||
else if (!this->saveState(geoBlk,nBlock,j < 1))
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user