Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit fe43ddea authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Added ParaReal sources

parent 3c846dd3
#include "parareal/ProblemBase.h"
#include "parareal/AdaptParaReal.h"
namespace AMDiS {
int AdaptParaReal::adapt()
{
int coarseStages = static_cast<int>(round(adaptInfo_->getEndTime() / coarseTimestep));
int fineStages = static_cast<int>(round(coarseTimestep / fineTimestep));
adaptInfo_->setTimestep(coarseTimestep);
pararealProb->setStoreSolutions(false, true);
pararealProb->setStoreInitSolution(true);
AdaptInstationary::adapt();
for (int k = 0; k < pararealIter; k++) {
for (int i = 0; i < coarseStages; i++) {
adaptInfo_->resetTimeValues(fineTimestep,
i * coarseTimestep,
(i + 1) *coarseTimestep);
pararealProb->setStoreSolutions(true, false);
pararealProb->setStoreInitSolution(false);
pararealProb->setInitSolutionVec((*pararealProb->getCoarseSolutions())[i]);
pararealProb->cleanUp();
AdaptInstationary::adapt();
}
std::vector<DOFVector<double> *> coarseSolutions =
(*pararealProb->getCoarseSolutions());
pararealProb->clearCoarseSolutions();
(*pararealProb->getCoarseSolutions()).push_back(coarseSolutions[0]);
for (int i = 1; i <= coarseStages; i++) {
adaptInfo_->resetTimeValues(coarseTimestep,
(i - 1) * coarseTimestep,
i * coarseTimestep);
pararealProb->setStoreSolutions(false, true);
pararealProb->setStoreInitSolution(false);
pararealProb->setInitSolutionVec((*pararealProb->getCoarseSolutions())[i - 1]);
AdaptInstationary::adapt();
DOFVector<double>* tmp = (*pararealProb->getCoarseSolutions())[i];
*tmp += *(*pararealProb->getFineSolutions())[(i * fineStages) - 1];
*tmp -= *(coarseSolutions[i]);
}
}
return 0;
}
}
// ============================================================================
// == ==
// == AMDiS - Adaptive multidimensional simulations ==
// == ==
// ============================================================================
// == ==
// == crystal growth group ==
// == ==
// == Stiftung caesar ==
// == Ludwig-Erhard-Allee 2 ==
// == 53175 Bonn ==
// == germany ==
// == ==
// ============================================================================
// == ==
// == http://www.caesar.de/cg/AMDiS ==
// == ==
// ============================================================================
/** \file parareal/AdaptInfo.h */
#ifndef AMDIS_PARAREAL_ADAPTINFO_H
#define AMDIS_PARAREAL_ADAPTINFO_H
#include "AdaptInstationary.h"
#include "parareal/ProblemBase.h"
namespace AMDiS {
class AdaptParaReal : public AdaptInstationary
{
public:
MEMORY_MANAGED(AdaptParaReal);
AdaptParaReal(const char *name,
ProblemIterationInterface *problemStat,
AdaptInfo *info,
ProblemTimeInterface *problemInstat,
ParaRealProblemBase< DOFVector<double> > *paraProb,
AdaptInfo *initialInfo,
time_t initialTimestamp = 0)
: AdaptInstationary(name, problemStat, info, problemInstat, initialInfo, initialTimestamp),
coarseTimestep(0.0),
fineTimestep(0.0),
pararealIter(1),
pararealProb(paraProb)
{
GET_PARAMETER(0, static_cast<std::string>(name) + "->coarse timestep", "%f", &coarseTimestep);
GET_PARAMETER(0, static_cast<std::string>(name) + "->timestep", "%f", &fineTimestep);
GET_PARAMETER(0, static_cast<std::string>(name) + "->parareal iteration", "%d", &pararealIter);
TEST_EXIT(fineTimestep > 0.0)("fineTimestep must be greater than zero!\n");
TEST_EXIT(coarseTimestep > 0.0)("coarseTimestep must be greater than zero!\n");
TEST_EXIT(fineTimestep < coarseTimestep)("fineTimestep must be smaller than coarseTimestep!\n");
TEST_EXIT(pararealIter > 0)("ParaReal Iterations must be greater than zero!\n");
}
/** \brief
* Here, the parareal algorithm is executed.
*/
virtual int adapt();
protected:
/** \brief
* Timestep for the coarse time grid.
*/
double coarseTimestep;
/** \brief
* Timestep for the fine time grid.
*/
double fineTimestep;
/** \brief
* Number of parareal iterations.
*/
int pararealIter;
/** \brief
* Pointer to the parareal problem.
*/
ParaRealProblemBase< DOFVector<double> > *pararealProb;
};
}
#endif // AMDIS_PARAREAL_ADAPTINFO
// ============================================================================
// == ==
// == AMDiS - Adaptive multidimensional simulations ==
// == ==
// ============================================================================
// == ==
// == crystal growth group ==
// == ==
// == Stiftung caesar ==
// == Ludwig-Erhard-Allee 2 ==
// == 53175 Bonn ==
// == germany ==
// == ==
// ============================================================================
// == ==
// == http://www.caesar.de/cg/AMDiS ==
// == ==
// ============================================================================
/** \file parareal/ProblemBase.h */
#ifndef AMDIS_PARAREAL_PROBLEMBASE_H
#define AMDIS_PARAREAL_PROBLEMBASE_H
#include <vector>
#include "CreatorInterface.h"
#include "DOFVector.h"
#include "SystemVector.h"
#include "ProblemInstat.h"
namespace AMDiS {
template<typename T>
class ParaRealProblemBase
{
public:
ParaRealProblemBase(CreatorInterface<T> *creator)
: storeFineSolutions(false),
storeCoarseSolutions(false),
vectorCreator(creator)
{
fineSolutions.clear();
coarseSolutions.clear();
}
void storeSolution(T *vec)
{
if (storeFineSolutions) {
storeFineSolution(vec);
}
if (storeCoarseSolutions) {
storeCoarseSolution(vec);
}
}
void storeFineSolution(T *vec)
{
T *tmp = vectorCreator->create();
*tmp = *vec;
fineSolutions.push_back(tmp);
}
void storeCoarseSolution(T *vec)
{
T *tmp = vectorCreator->create();
*tmp = *vec;
coarseSolutions.push_back(tmp);
}
void setStoreSolutions(bool fine, bool coarse) {
storeFineSolutions = fine;
storeCoarseSolutions = coarse;
}
void setInitSolutionVec(T *vec) {
initSolutionVec = vec;
}
void setStoreInitSolution(bool store) {
storeInitSolution = store;
}
std::vector<T*> *getFineSolutions() {
return &fineSolutions;
}
std::vector<T*> *getCoarseSolutions() {
return &coarseSolutions;
}
void clearFineSolutions() {
fineSolutions.clear();
}
void clearCoarseSolutions() {
coarseSolutions.clear();
}
/** \brief
* This functions is called between switching from coarse
* time grid to fine time grid, or vice versa. Can be overwritten
* to clean up some data.
*/
virtual void cleanUp() {};
protected:
/** \brief
* Stores all solutions on the fine time grid.
*/
std::vector<T*> fineSolutions;
/** \brief
* Stores all solutions on the coarse time grid.
*/
std::vector<T*> coarseSolutions;
/** \brief
* If true, after closeTimestep() the solution is stored
* in vector \ref fineSolutions .
*/
bool storeFineSolutions;
/** \brief
* If true, after closeTimestep() the solution is stored
* in vector \ref coarseSolution .
*/
bool storeCoarseSolutions;
/** \brief
* If true, the initial solution is also stored in either
* \ref fineSolutions or in \ref coarseSolutions .
*/
bool storeInitSolution;
/** \brief
* Creator interface to create new vectors (either DOFVector or
* SystemVector).
*/
CreatorInterface<T> *vectorCreator;
/** \brief
* The initial solution for the problem can be set to this
* vector.
*/
T* initSolutionVec;
};
class ParaRealScal : public ProblemInstatScal,
public ParaRealProblemBase< DOFVector<double> >
{
public:
ParaRealScal(char* name,
ProblemScal *prob,
ProblemStatBase *initialProb = NULL)
: ProblemInstatScal(name, prob, initialProb),
ParaRealProblemBase< DOFVector<double> >(new DOFVector<double>::Creator(prob->getFESpace()))
{}
virtual void closeTimestep(AdaptInfo *adaptInfo) {
ProblemInstatScal::closeTimestep(adaptInfo);
storeSolution(problemStat->getSolution());
}
virtual void solveInitialProblem(AdaptInfo *adaptInfo) {
ProblemInstatScal::solveInitialProblem(adaptInfo);
if (storeInitSolution) {
storeSolution(problemStat->getSolution());
}
}
};
class ParaRealVec : public ProblemInstatVec,
public ParaRealProblemBase< SystemVector >
{
public:
ParaRealVec(char *name,
ProblemVec *prob,
ProblemStatBase *initialProb = NULL)
: ProblemInstatVec(name, prob, initialProb),
ParaRealProblemBase< SystemVector >(new SystemVector::Creator(name,
prob->getFESpaces(),
prob->getNumComponents()))
{}
virtual void closeTimestep(AdaptInfo *adaptInfo) {
ProblemInstatVec::closeTimestep(adaptInfo);
storeSolution(problemStat->getSolution());
}
virtual void solveInitialProblem(AdaptInfo *adaptInfo) {
ProblemInstatVec::solveInitialProblem(adaptInfo);
if (storeInitSolution) {
storeSolution(problemStat->getSolution());
}
}
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment