37 #ifndef ABSTRACTDYNAMICLINEARPDESOLVER_HPP_
38 #define ABSTRACTDYNAMICLINEARPDESOLVER_HPP_
41 #include "TimeStepper.hpp"
42 #include "AbstractLinearPdeSolver.hpp"
43 #include "PdeSimulationTime.hpp"
44 #include "AbstractTimeAdaptivityController.hpp"
45 #include "Hdf5DataWriter.hpp"
46 #include "Hdf5ToVtkConverter.hpp"
47 #include "Hdf5ToTxtConverter.hpp"
55 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
58 friend class TestSimpleLinearParabolicSolver;
160 void SetTimes(
double tStart,
double tEnd);
222 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
226 if ((mOutputDirectory==
"") || (mFilenamePrefix==
""))
228 EXCEPTION(
"Output directory or filename prefix has not been set");
232 mpHdf5Writer =
new Hdf5DataWriter(*(this->mpMesh)->GetDistributedVectorFactory(),
237 mpHdf5Writer->DefineFixedDimension((this->mpMesh)->GetNumNodes());
240 unsigned estimated_num_printing_timesteps = 1u + (
unsigned)((mTend - mTstart)/(mIdealTimeStep*mPrintingTimestepMultiple));
248 assert(mVariableColumnIds.empty());
249 for (
unsigned i=0; i<PROBLEM_DIM; i++)
251 std::stringstream variable_name;
252 variable_name <<
"Variable_" << i;
253 mVariableColumnIds.push_back(mpHdf5Writer->DefineVariable(variable_name.str(),
"undefined"));
255 mpHdf5Writer->DefineUnlimitedDimension(
"Time",
"undefined", estimated_num_printing_timesteps);
258 mpHdf5Writer->EndDefineMode();
261 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
265 mInitialCondition(NULL),
266 mMatrixIsAssembled(false),
267 mMatrixIsConstant(false),
268 mIdealTimeStep(-1.0),
269 mLastWorkingTimeStep(-1),
270 mpTimeAdaptivityController(NULL),
272 mOutputToParallelVtk(false),
274 mOutputDirectory(
""),
276 mPrintingTimestepMultiple(1),
281 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
287 if (mTstart >= mTend)
289 EXCEPTION(
"Start time has to be less than end time");
295 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
300 EXCEPTION(
"Time step has to be greater than zero");
306 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
309 assert(initialCondition != NULL);
310 mInitialCondition = initialCondition;
313 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
316 mpHdf5Writer->PutUnlimitedVariable(time);
317 if (PROBLEM_DIM == 1)
319 mpHdf5Writer->PutVector(mVariableColumnIds[0], solution);
323 mpHdf5Writer->PutStripedVector(mVariableColumnIds, solution);
327 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
333 EXCEPTION(
"SetTimes() has not been called");
335 if ((mIdealTimeStep <= 0.0) && (mpTimeAdaptivityController==NULL))
337 EXCEPTION(
"SetTimeStep() has not been called");
339 if (mInitialCondition == NULL)
341 EXCEPTION(
"SetInitialCondition() has not been called");
345 bool print_output = (mOutputToVtk || mOutputToParallelVtk || mOutputToTxt);
348 InitialiseHdf5Writer();
349 WriteOneStep(mTstart, mInitialCondition);
350 mpHdf5Writer->AdvanceAlongUnlimitedDimension();
353 this->InitialiseForSolve(mInitialCondition);
355 if (mIdealTimeStep < 0)
357 mIdealTimeStep = mpTimeAdaptivityController->GetNextTimeStep(mTstart, mInitialCondition);
367 TimeStepper stepper(mTstart, mTend, mIdealTimeStep, mMatrixIsConstant);
369 Vec solution = mInitialCondition;
374 bool timestep_changed =
false;
380 if (mpTimeAdaptivityController)
383 mIdealTimeStep = mpTimeAdaptivityController->GetNextTimeStep(stepper.
GetTime(), solution);
392 timestep_changed = (fabs(new_dt/mLastWorkingTimeStep - 1.0) > 1e-5);
400 if (mMatrixIsConstant && fabs(new_dt/mIdealTimeStep - 1.0) > 1e-5)
410 mLastWorkingTimeStep = new_dt;
417 this->PrepareForSetupLinearSystem(solution);
423 if (solution != mInitialCondition)
432 bool compute_matrix = (!mMatrixIsConstant || !mMatrixIsAssembled || timestep_changed);
434 this->SetupLinearSystem(solution, compute_matrix);
436 this->FinaliseLinearSystem(solution);
440 this->mpLinearSystem->ResetKspSolver();
443 next_solution = this->mpLinearSystem->Solve(solution);
445 if (mMatrixIsConstant)
447 mMatrixIsAssembled =
true;
450 this->FollowingSolveLinearSystem(next_solution);
455 if (solution != mInitialCondition)
461 solution = next_solution;
466 WriteOneStep(stepper.
GetTime(), solution);
467 mpHdf5Writer->AdvanceAlongUnlimitedDimension();
472 if (mpHdf5Writer != NULL)
483 mFilenamePrefix, this->mpMesh,
false,
false);
485 if (mOutputToParallelVtk)
488 mFilenamePrefix, this->mpMesh,
true,
false);
493 mFilenamePrefix, this->mpMesh);
499 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
502 mMatrixIsAssembled =
false;
505 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
508 assert(pTimeAdaptivityController != NULL);
509 assert(mpTimeAdaptivityController == NULL);
510 mpTimeAdaptivityController = pTimeAdaptivityController;
513 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
516 mOutputToVtk = output;
519 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
522 mOutputToParallelVtk = output;
525 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
528 mOutputToTxt = output;
531 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
534 mOutputDirectory = outputDirectory;
535 mFilenamePrefix = prefix;
538 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned PROBLEM_DIM>
541 mPrintingTimestepMultiple = multiple;
bool mOutputToParallelVtk
double mLastWorkingTimeStep
void InitialiseHdf5Writer()
#define EXCEPTION(message)
void SetTimeStep(double dt)
static void BeginEvent(unsigned event)
void SetInitialCondition(Vec initialCondition)
void SetOutputToParallelVtk(bool output)
void ResetTimeStep(double dt)
void SetOutputDirectoryAndPrefix(std::string outputDirectory, std::string prefix)
void SetPrintingTimestepMultiple(unsigned multiple)
void AdvanceOneTimeStep()
void SetTimes(double tStart, double tEnd)
std::string mFilenamePrefix
void SetOutputToVtk(bool output)
AbstractTimeAdaptivityController * mpTimeAdaptivityController
unsigned GetTotalTimeStepsTaken() const
void SetOutputToTxt(bool output)
void SetTimeAdaptivityController(AbstractTimeAdaptivityController *pTimeAdaptivityController)
std::vector< int > mVariableColumnIds
std::string mOutputDirectory
Hdf5DataWriter * mpHdf5Writer
void WriteOneStep(double time, Vec solution)
static void EndEvent(unsigned event)
static void SetTime(double time)
void SetMatrixIsNotAssembled()
double GetNextTime() const
static void SetPdeTimeStepAndNextTime(double timestep, double next_time)
AbstractDynamicLinearPdeSolver(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)
unsigned mPrintingTimestepMultiple