Commit 52d5144a authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Bla

parent 9df9d4af
...@@ -45,20 +45,20 @@ namespace AMDiS { ...@@ -45,20 +45,20 @@ namespace AMDiS {
*/ */
AdaptBase(const std::string& name, AdaptBase(const std::string& name,
ProblemIterationInterface *problemIteration, ProblemIterationInterface *problemIteration,
AdaptInfo *adaptInfo, AdaptInfo *adapt,
ProblemTimeInterface *problemTime = NULL, ProblemTimeInterface *problemTime = NULL,
AdaptInfo *initialAdaptInfo = NULL) AdaptInfo *initialAdaptInfo = NULL)
: name_(name), : name_(name),
problemIteration_(problemIteration), problemIteration_(problemIteration),
adaptInfo_(adaptInfo), adaptInfo(adapt),
problemTime_(problemTime), problemTime_(problemTime),
initialAdaptInfo_(initialAdaptInfo) initialAdaptInfo_(initialAdaptInfo)
{}; {}
/** \brief /** \brief
* Destructor * Destructor
*/ */
virtual ~AdaptBase() {}; virtual ~AdaptBase() {}
/** \brief /** \brief
* Pure virtual method. Must be overloaded by sub classes to perform * Pure virtual method. Must be overloaded by sub classes to perform
...@@ -71,32 +71,32 @@ namespace AMDiS { ...@@ -71,32 +71,32 @@ namespace AMDiS {
*/ */
inline const std::string& getName() const { inline const std::string& getName() const {
return name_; return name_;
}; }
/** \brief /** \brief
* Returns \ref problemIteration_ * Returns \ref problemIteration_
*/ */
inline ProblemIterationInterface *getProblemIteration() { inline ProblemIterationInterface *getProblemIteration() {
return problemIteration_; return problemIteration_;
}; }
inline void setProblemIteration(ProblemIterationInterface *pii) { inline void setProblemIteration(ProblemIterationInterface *pii) {
problemIteration_ = pii; problemIteration_ = pii;
}; }
/** \brief /** \brief
* Returns \ref adaptInfo_ * Returns \ref adaptInfo
*/ */
inline AdaptInfo *getAdaptInfo() { inline AdaptInfo *getAdaptInfo() {
return adaptInfo_; return adaptInfo;
}; }
/** \brief /** \brief
* Returns \ref problemTime_ * Returns \ref problemTime_
*/ */
inline ProblemTimeInterface *getProblemTime() { inline ProblemTimeInterface *getProblemTime() {
return problemTime_; return problemTime_;
}; }
inline void setProblemTime(ProblemTimeInterface *pti) { inline void setProblemTime(ProblemTimeInterface *pti) {
problemTime_ = pti; problemTime_ = pti;
...@@ -107,7 +107,7 @@ namespace AMDiS { ...@@ -107,7 +107,7 @@ namespace AMDiS {
*/ */
inline AdaptInfo *getInitialAdaptInfo() { inline AdaptInfo *getInitialAdaptInfo() {
return initialAdaptInfo_; return initialAdaptInfo_;
}; }
protected: protected:
/** \brief /** \brief
...@@ -123,7 +123,7 @@ namespace AMDiS { ...@@ -123,7 +123,7 @@ namespace AMDiS {
/** \brief /** \brief
* Main adapt info * Main adapt info
*/ */
AdaptInfo *adaptInfo_; AdaptInfo *adaptInfo;
/** \brief /** \brief
* problem time interface * problem time interface
......
...@@ -31,6 +31,7 @@ namespace AMDiS { ...@@ -31,6 +31,7 @@ namespace AMDiS {
out.write(reinterpret_cast<const char*>(&minTimestep), sizeof(double)); out.write(reinterpret_cast<const char*>(&minTimestep), sizeof(double));
out.write(reinterpret_cast<const char*>(&maxTimestep), sizeof(double)); out.write(reinterpret_cast<const char*>(&maxTimestep), sizeof(double));
out.write(reinterpret_cast<const char*>(&timestepNumber), sizeof(int)); out.write(reinterpret_cast<const char*>(&timestepNumber), sizeof(int));
out.write(reinterpret_cast<const char*>(&nTimesteps), sizeof(int));
out.write(reinterpret_cast<const char*>(&solverIterations), sizeof(int)); out.write(reinterpret_cast<const char*>(&solverIterations), sizeof(int));
out.write(reinterpret_cast<const char*>(&maxSolverIterations), sizeof(int)); out.write(reinterpret_cast<const char*>(&maxSolverIterations), sizeof(int));
out.write(reinterpret_cast<const char*>(&solverTolerance), sizeof(double)); out.write(reinterpret_cast<const char*>(&solverTolerance), sizeof(double));
...@@ -80,6 +81,7 @@ namespace AMDiS { ...@@ -80,6 +81,7 @@ namespace AMDiS {
in.read(reinterpret_cast<char*>(&minTimestep), sizeof(double)); in.read(reinterpret_cast<char*>(&minTimestep), sizeof(double));
in.read(reinterpret_cast<char*>(&maxTimestep), sizeof(double)); in.read(reinterpret_cast<char*>(&maxTimestep), sizeof(double));
in.read(reinterpret_cast<char*>(&timestepNumber), sizeof(int)); in.read(reinterpret_cast<char*>(&timestepNumber), sizeof(int));
in.read(reinterpret_cast<char*>(&nTimesteps), sizeof(int));
in.read(reinterpret_cast<char*>(&solverIterations), sizeof(int)); in.read(reinterpret_cast<char*>(&solverIterations), sizeof(int));
in.read(reinterpret_cast<char*>(&maxSolverIterations), sizeof(int)); in.read(reinterpret_cast<char*>(&maxSolverIterations), sizeof(int));
in.read(reinterpret_cast<char*>(&solverTolerance), sizeof(double)); in.read(reinterpret_cast<char*>(&solverTolerance), sizeof(double));
......
...@@ -165,6 +165,7 @@ namespace AMDiS { ...@@ -165,6 +165,7 @@ namespace AMDiS {
minTimestep(0.0), minTimestep(0.0),
maxTimestep(1.0), maxTimestep(1.0),
timestepNumber(0), timestepNumber(0),
nTimesteps(0),
solverIterations(0), solverIterations(0),
maxSolverIterations(0), maxSolverIterations(0),
solverTolerance(1e-8), solverTolerance(1e-8),
...@@ -183,6 +184,8 @@ namespace AMDiS { ...@@ -183,6 +184,8 @@ namespace AMDiS {
GET_PARAMETER(0, name_ + "->min timestep", "%f", &minTimestep); GET_PARAMETER(0, name_ + "->min timestep", "%f", &minTimestep);
GET_PARAMETER(0, name_ + "->max timestep", "%f", &maxTimestep); GET_PARAMETER(0, name_ + "->max timestep", "%f", &maxTimestep);
GET_PARAMETER(0, name_ + "->number of timesteps", "%d", &nTimesteps);
if (size == 1) { if (size == 1) {
scalContents[0] = new ScalContent(name); scalContents[0] = new ScalContent(name);
} else { } else {
...@@ -400,6 +403,11 @@ namespace AMDiS { ...@@ -400,6 +403,11 @@ namespace AMDiS {
return timestepNumber; return timestepNumber;
} }
/// Returns \ref nTimesteps.
inline int getNumberOfTimesteps() {
return nTimesteps;
}
/** \brief /** \brief
* Increments \ref timestepNumber by 1; * Increments \ref timestepNumber by 1;
*/ */
...@@ -536,6 +544,15 @@ namespace AMDiS { ...@@ -536,6 +544,15 @@ namespace AMDiS {
return timestep; return timestep;
} }
/** \brief
* Returns true, if the end time is reached and no more timestep
* computations must be done.
*/
inline bool reachedEndTime() {
return !(time < endTime - DBL_TOL ||
(nTimesteps > 0 && timestepNumber < nTimesteps));
}
/** \brief /** \brief
* Gets \ref timestep * Gets \ref timestep
*/ */
...@@ -798,6 +815,13 @@ namespace AMDiS { ...@@ -798,6 +815,13 @@ namespace AMDiS {
* Number of current time step * Number of current time step
*/ */
int timestepNumber; int timestepNumber;
/** \brief
* Per default this value is 0 and not used. If it is set to a non-zero value,
* the computation of the stationary problem is done nTimesteps times with a
* fixed timestep.
*/
int nTimesteps;
/** \brief /** \brief
* number of iterations needed of linear or nonlinear solver * number of iterations needed of linear or nonlinear solver
......
...@@ -78,24 +78,24 @@ namespace AMDiS { ...@@ -78,24 +78,24 @@ namespace AMDiS {
FUNCNAME("AdaptInstationary::explicitTimeStrategy()"); FUNCNAME("AdaptInstationary::explicitTimeStrategy()");
// estimate before first adaption // estimate before first adaption
if (adaptInfo_->getTime() <= adaptInfo_->getStartTime()) { if (adaptInfo->getTime() <= adaptInfo->getStartTime()) {
problemIteration_->oneIteration(adaptInfo_, ESTIMATE); problemIteration_->oneIteration(adaptInfo, ESTIMATE);
} }
// increment time // increment time
adaptInfo_->setTime(adaptInfo_->getTime() + adaptInfo_->getTimestep()); adaptInfo->setTime(adaptInfo->getTime() + adaptInfo->getTimestep());
problemTime_->setTime(adaptInfo_); problemTime_->setTime(adaptInfo);
INFO(info_,6)("time = %e, timestep = %e\n", INFO(info_,6)("time = %e, timestep = %e\n",
adaptInfo_->getTime(), adaptInfo_->getTimestep()); adaptInfo->getTime(), adaptInfo->getTimestep());
adaptInfo_->setSpaceIteration(0); adaptInfo->setSpaceIteration(0);
// do the iteration // do the iteration
problemIteration_->beginIteration(adaptInfo_); problemIteration_->beginIteration(adaptInfo);
problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION); problemIteration_->oneIteration(adaptInfo, FULL_ITERATION);
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
} }
void AdaptInstationary::implicitTimeStrategy() void AdaptInstationary::implicitTimeStrategy()
...@@ -103,66 +103,66 @@ namespace AMDiS { ...@@ -103,66 +103,66 @@ namespace AMDiS {
FUNCNAME("AdaptInstationary::implicitTimeStrategy()"); FUNCNAME("AdaptInstationary::implicitTimeStrategy()");
do { do {
adaptInfo_->setTime(adaptInfo_->getTime() + adaptInfo_->getTimestep()); adaptInfo->setTime(adaptInfo->getTime() + adaptInfo->getTimestep());
problemTime_->setTime(adaptInfo_); problemTime_->setTime(adaptInfo);
INFO(info_,6)("time = %e, try timestep = %e\n", INFO(info_,6)("time = %e, try timestep = %e\n",
adaptInfo_->getTime(), adaptInfo_->getTimestep()); adaptInfo->getTime(), adaptInfo->getTimestep());
problemIteration_->oneIteration(adaptInfo_, NO_ADAPTION); problemIteration_->oneIteration(adaptInfo, NO_ADAPTION);
adaptInfo_->incTimestepIteration(); adaptInfo->incTimestepIteration();
if (!fixedTimestep_ && if (!fixedTimestep_ &&
!adaptInfo_->timeToleranceReached() && !adaptInfo->timeToleranceReached() &&
!adaptInfo_->getTimestep() <= adaptInfo_->getMinTimestep()) { !adaptInfo->getTimestep() <= adaptInfo->getMinTimestep()) {
adaptInfo_->setTime(adaptInfo_->getTime() - adaptInfo_->getTimestep()); adaptInfo->setTime(adaptInfo->getTime() - adaptInfo->getTimestep());
adaptInfo_->setTimestep(adaptInfo_->getTimestep() * time_delta_1); adaptInfo->setTimestep(adaptInfo->getTimestep() * time_delta_1);
continue; continue;
} }
adaptInfo_->setSpaceIteration(0); adaptInfo->setSpaceIteration(0);
/* === Do only space iterations only if the maximum is higher than 0. === */ /* === Do only space iterations only if the maximum is higher than 0. === */
if (adaptInfo_->getMaxSpaceIteration() > 0) { if (adaptInfo->getMaxSpaceIteration() > 0) {
/* === Space iterations === */ /* === Space iterations === */
do { do {
problemIteration_->beginIteration(adaptInfo_); problemIteration_->beginIteration(adaptInfo);
if (problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION)) { if (problemIteration_->oneIteration(adaptInfo, FULL_ITERATION)) {
if (!fixedTimestep_ && if (!fixedTimestep_ &&
!adaptInfo_->timeToleranceReached() && !adaptInfo->timeToleranceReached() &&
!adaptInfo_->getTimestep() <= adaptInfo_->getMinTimestep()) !adaptInfo->getTimestep() <= adaptInfo->getMinTimestep())
{ {
adaptInfo_->setTime(adaptInfo_->getTime() - adaptInfo_->getTimestep()); adaptInfo->setTime(adaptInfo->getTime() - adaptInfo->getTimestep());
adaptInfo_->setTimestep(adaptInfo_->getTimestep() * time_delta_1); adaptInfo->setTimestep(adaptInfo->getTimestep() * time_delta_1);
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
adaptInfo_->incSpaceIteration(); adaptInfo->incSpaceIteration();
break; break;
} }
} }
adaptInfo_->incSpaceIteration(); adaptInfo->incSpaceIteration();
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
} while(!adaptInfo_->spaceToleranceReached() && } while(!adaptInfo->spaceToleranceReached() &&
adaptInfo_->getSpaceIteration() <= adaptInfo_->getMaxSpaceIteration()); adaptInfo->getSpaceIteration() <= adaptInfo->getMaxSpaceIteration());
} else { } else {
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
} }
} while(!adaptInfo_->timeToleranceReached() && } while(!adaptInfo->timeToleranceReached() &&
!adaptInfo_->getTimestep() <= adaptInfo_->getMinTimestep() && !adaptInfo->getTimestep() <= adaptInfo->getMinTimestep() &&
adaptInfo_->getTimestepIteration() <= adaptInfo_->getMaxTimestepIteration()); adaptInfo->getTimestepIteration() <= adaptInfo->getMaxTimestepIteration());
if (!fixedTimestep_ && adaptInfo_->timeErrorLow()) { if (!fixedTimestep_ && adaptInfo->timeErrorLow()) {
adaptInfo_->setTimestep(adaptInfo_->getTimestep() *time_delta_2); adaptInfo->setTimestep(adaptInfo->getTimestep() *time_delta_2);
if (dbgMode) { if (dbgMode) {
// print information about timestep increase // print information about timestep increase
} }
...@@ -173,8 +173,8 @@ namespace AMDiS { ...@@ -173,8 +173,8 @@ namespace AMDiS {
if (fixedTimestep_) { if (fixedTimestep_) {
std::cout << " fixedTimestep = true\n"; std::cout << " fixedTimestep = true\n";
} }
if (!adaptInfo_->timeErrorLow()) { if (!adaptInfo->timeErrorLow()) {
adaptInfo_->printTimeErrorLowInfo(); adaptInfo->printTimeErrorLowInfo();
} }
} }
} }
...@@ -184,7 +184,7 @@ namespace AMDiS { ...@@ -184,7 +184,7 @@ namespace AMDiS {
{ {
FUNCNAME("AdaptInstationary::oneTimestep()"); FUNCNAME("AdaptInstationary::oneTimestep()");
adaptInfo_->setTimestepIteration(0); adaptInfo->setTimestepIteration(0);
switch (strategy) { switch (strategy) {
case 0: case 0:
...@@ -198,7 +198,7 @@ namespace AMDiS { ...@@ -198,7 +198,7 @@ namespace AMDiS {
explicitTimeStrategy(); explicitTimeStrategy();
} }
adaptInfo_->incTimestepNumber(); adaptInfo->incTimestepNumber();
} }
int AdaptInstationary::adapt() int AdaptInstationary::adapt()
...@@ -207,35 +207,33 @@ namespace AMDiS { ...@@ -207,35 +207,33 @@ namespace AMDiS {
int errorCode = 0; int errorCode = 0;
TEST_EXIT(adaptInfo_->getTimestep() >= adaptInfo_->getMinTimestep()) TEST_EXIT(adaptInfo->getTimestep() >= adaptInfo->getMinTimestep())
("timestep < min timestep\n"); ("timestep < min timestep\n");
TEST_EXIT(adaptInfo_->getTimestep() <= adaptInfo_->getMaxTimestep()) TEST_EXIT(adaptInfo->getTimestep() <= adaptInfo->getMaxTimestep())
("timestep > max timestep\n"); ("timestep > max timestep\n");
TEST_EXIT(adaptInfo_->getTimestep() > 0)("timestep <= 0!\n"); TEST_EXIT(adaptInfo->getTimestep() > 0)("timestep <= 0!\n");
if (adaptInfo_->getTimestepNumber() == 0) { if (adaptInfo->getTimestepNumber() == 0) {
adaptInfo_->setTime(adaptInfo_->getStartTime()); adaptInfo->setTime(adaptInfo->getStartTime());
initialAdaptInfo_->setStartTime(adaptInfo_->getStartTime()); initialAdaptInfo_->setStartTime(adaptInfo->getStartTime());
initialAdaptInfo_->setTime(adaptInfo_->getStartTime()); initialAdaptInfo_->setTime(adaptInfo->getStartTime());
problemTime_->setTime(adaptInfo_); problemTime_->setTime(adaptInfo);
// initial adaption // initial adaption
problemTime_->solveInitialProblem(initialAdaptInfo_); problemTime_->solveInitialProblem(initialAdaptInfo_);
problemTime_->transferInitialSolution(adaptInfo_); problemTime_->transferInitialSolution(adaptInfo);
} }
while (adaptInfo_->getTime() < adaptInfo_->getEndTime() - DBL_TOL) { while (!adaptInfo->reachedEndTime()) {
iterationTimestamp_ = time(NULL); iterationTimestamp_ = time(NULL);
problemTime_->initTimestep(adaptInfo_); problemTime_->initTimestep(adaptInfo);
oneTimestep(); oneTimestep();
problemTime_->closeTimestep(adaptInfo);
problemTime_->closeTimestep(adaptInfo_); if (breakWhenStable && (adaptInfo->getSolverIterations() == 0)) {
if (breakWhenStable && (adaptInfo_->getSolverIterations() == 0)) {
break; break;
} }
...@@ -277,7 +275,7 @@ namespace AMDiS { ...@@ -277,7 +275,7 @@ namespace AMDiS {
FUNCNAME("AdaptInstationary::serialize()"); FUNCNAME("AdaptInstationary::serialize()");
problemIteration_->serialize(out); problemIteration_->serialize(out);
adaptInfo_->serialize(out); adaptInfo->serialize(out);
if (problemTime_) { if (problemTime_) {
problemTime_->serialize(out); problemTime_->serialize(out);
} }
...@@ -288,7 +286,7 @@ namespace AMDiS { ...@@ -288,7 +286,7 @@ namespace AMDiS {
FUNCNAME("AdaptInstationary::deserialize()"); FUNCNAME("AdaptInstationary::deserialize()");
problemIteration_->deserialize(in); problemIteration_->deserialize(in);
adaptInfo_->deserialize(in); adaptInfo->deserialize(in);
if (problemTime_) { if (problemTime_) {
problemTime_->deserialize(in); problemTime_->deserialize(in);
} }
......
...@@ -78,7 +78,7 @@ namespace AMDiS { ...@@ -78,7 +78,7 @@ namespace AMDiS {
*/ */
const int getStrategy() const { const int getStrategy() const {
return strategy; return strategy;
}; }
/** \brief /** \brief
* Implementation of AdaptBase::adapt() * Implementation of AdaptBase::adapt()
......
...@@ -20,26 +20,26 @@ namespace AMDiS { ...@@ -20,26 +20,26 @@ namespace AMDiS {
FUNCNAME("AdaptStationary::adapt()"); FUNCNAME("AdaptStationary::adapt()");
// initial iteration // initial iteration
if (adaptInfo_->getSpaceIteration() == -1) { if (adaptInfo->getSpaceIteration() == -1) {
problemIteration_->beginIteration(adaptInfo_); problemIteration_->beginIteration(adaptInfo);
problemIteration_->oneIteration(adaptInfo_, NO_ADAPTION); problemIteration_->oneIteration(adaptInfo, NO_ADAPTION);
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
adaptInfo_->incSpaceIteration(); adaptInfo->incSpaceIteration();
} }
// adaption loop // adaption loop
while (!adaptInfo_->spaceToleranceReached() && while (!adaptInfo->spaceToleranceReached() &&
(adaptInfo_->getSpaceIteration() < adaptInfo_->getMaxSpaceIteration() || (adaptInfo->getSpaceIteration() < adaptInfo->getMaxSpaceIteration() ||
adaptInfo_->getMaxSpaceIteration() < 0) ) { adaptInfo->getMaxSpaceIteration() < 0) ) {
problemIteration_->beginIteration(adaptInfo_); problemIteration_->beginIteration(adaptInfo);
Flag adapted = problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION); Flag adapted = problemIteration_->oneIteration(adaptInfo, FULL_ITERATION);
problemIteration_->endIteration(adaptInfo_); problemIteration_->endIteration(adaptInfo);
if (!adapted) if (!adapted)
break; break;
adaptInfo_->incSpaceIteration(); adaptInfo->incSpaceIteration();
} }
return 0; return 0;
......
...@@ -65,7 +65,7 @@ namespace AMDiS { ...@@ -65,7 +65,7 @@ namespace AMDiS {
/** \brief /** \brief
* Destructor * Destructor
*/ */
virtual ~AdaptStationary() {}; virtual ~AdaptStationary() {}
/** \brief /** \brief
* Implementation of AdaptBase::adapt() * Implementation of AdaptBase::adapt()
......
...@@ -5,11 +5,11 @@ namespace AMDiS { ...@@ -5,11 +5,11 @@ namespace AMDiS {
int AdaptParaReal::adapt() int AdaptParaReal::adapt()
{ {
// Compute number of coarse and fine time stages. // Compute number of coarse and fine time stages.
int coarseStages = static_cast<int>(round(adaptInfo_->getEndTime() / coarseTimestep)); int coarseStages = static_cast<int>(round(adaptInfo->getEndTime() / coarseTimestep));
int fineStages = static_cast<int>(round(coarseTimestep / fineTimestep)); int fineStages = static_cast<int>(round(coarseTimestep / fineTimestep));