Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Attributes | Private Member Functions | Friends | List of all members
Nektar::SolverUtils::DriverParareal Class Reference

Base class for the development of solvers. More...

#include <DriverParareal.h>

Inheritance diagram for Nektar::SolverUtils::DriverParareal:
[legend]

Static Public Member Functions

static DriverSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

SOLVER_UTILS_EXPORT DriverParareal (const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
 Constructor. More...
 
virtual SOLVER_UTILS_EXPORT ~DriverParareal ()=default
 Destructor. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (std::ostream &out=std::cout) override
 Virtual function for initialisation implementation. More...
 
virtual SOLVER_UTILS_EXPORT void v_Execute (std::ostream &out=std::cout) override
 Virtual function for solve implementation. More...
 
virtual NekDouble v_EstimateCommunicationTime (void) override
 
virtual NekDouble v_EstimateRestrictionTime (void) override
 
virtual NekDouble v_EstimateInterpolationTime (void) override
 
virtual NekDouble v_EstimateCoarseSolverTime (void) override
 
virtual NekDouble v_EstimateFineSolverTime (void) override
 
virtual NekDouble v_EstimatePredictorTime (void) override
 
virtual NekDouble v_EstimateOverheadTime (void) override
 
virtual NekDouble v_ComputeSpeedUp (const size_t iter, NekDouble fineSolveTime, NekDouble coarseSolveTime, NekDouble restTime, NekDouble interTime, NekDouble commTime, NekDouble predictorOverheadTime, NekDouble overheadTime) override
 
- Protected Member Functions inherited from Nektar::SolverUtils::DriverParallelInTime
SOLVER_UTILS_EXPORT DriverParallelInTime (const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
 Constructor. More...
 
virtual SOLVER_UTILS_EXPORT ~DriverParallelInTime ()=default
 Destructor. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (std::ostream &out=std::cout) override
 Virtual function for initialisation implementation. More...
 
virtual SOLVER_UTILS_EXPORT void v_Execute (std::ostream &out=std::cout) override
 Virtual function for solve implementation. More...
 
virtual NekDouble v_EstimateCommunicationTime (void)
 
virtual NekDouble v_EstimateRestrictionTime (void)
 
virtual NekDouble v_EstimateInterpolationTime (void)
 
virtual NekDouble v_EstimateCoarseSolverTime (void)
 
virtual NekDouble v_EstimateFineSolverTime (void)
 
virtual NekDouble v_EstimatePredictorTime (void)
 
virtual NekDouble v_EstimateOverheadTime (void)
 
virtual NekDouble v_ComputeSpeedUp (const size_t iter, NekDouble fineSolveTime, NekDouble coarseSolveTime, NekDouble restTime, NekDouble interTime, NekDouble commTime, NekDouble predictorTime, NekDouble overheadTime)
 
void SetParallelInTimeEquationSystem (std::string AdvectiveType)
 
void GetParametersFromSession (void)
 
void InitialiseEqSystem (bool turnoff_output)
 
void AllocateMemory (void)
 
void InitialiseInterpolationField (void)
 
void PrintCoarseSolverInfo (std::ostream &out=std::cout)
 
void PrintFineSolverInfo (std::ostream &out=std::cout)
 
void PrintHeaderTitle1 (const std::string &title)
 
void PrintHeaderTitle2 (const std::string &title)
 
void PrintComputationalTime (const NekDouble time)
 
void RecvInitialConditionFromPreviousProc (Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
 
void RecvInitialConditionFromPreviousProc (Array< OneD, Array< OneD, NekDouble > > &array)
 
void SendSolutionToNextProc (Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
 
void SendSolutionToNextProc (Array< OneD, Array< OneD, NekDouble > > &array)
 
void CopySolutionVector (const Array< OneD, const Array< OneD, NekDouble > > &in, Array< OneD, Array< OneD, NekDouble > > &out)
 
void CopyFromFinePhysField (Array< OneD, Array< OneD, NekDouble > > &out)
 
void CopyFromCoarsePhysField (Array< OneD, Array< OneD, NekDouble > > &out)
 
void CopyToFinePhysField (const Array< OneD, const Array< OneD, NekDouble > > &in)
 
void CopyToCoarsePhysField (const Array< OneD, const Array< OneD, NekDouble > > &in)
 
void UpdateSolution (const Array< OneD, const Array< OneD, NekDouble > > &in)
 
void EvaluateExactSolution (const NekDouble &time)
 
void SolutionConvergenceMonitoring (const NekDouble &time)
 
void SolutionConvergenceSummary (const NekDouble &time)
 
void UpdateErrorNorm (const bool normalized)
 
void PrintErrorNorm (const bool normalized)
 
void Interpolator (const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
 
NekDouble vL2ErrorMax (void)
 
void SpeedUpAnalysis ()
 
void PrintSpeedUp (NekDouble fineSolveTime, NekDouble coarseSolveTime, NekDouble restTime, NekDouble interTime, NekDouble commTime, NekDouble predictorOverheadTime, NekDouble overheadTime)
 
NekDouble EstimateCommunicationTime (Array< OneD, Array< OneD, NekDouble > > &buffer1, Array< OneD, Array< OneD, NekDouble > > &buffer2)
 
- Protected Member Functions inherited from Nektar::SolverUtils::Driver
 Driver (const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
 Initialises EquationSystem class members. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (std::ostream &out=std::cout)
 Virtual function for initialisation implementation. More...
 
virtual SOLVER_UTILS_EXPORT void v_Execute (std::ostream &out=std::cout)=0
 Virtual function for solve implementation. More...
 

Static Protected Attributes

static std::string driverLookupId
 
- Static Protected Attributes inherited from Nektar::SolverUtils::Driver
static std::string evolutionOperatorLookupIds []
 
static std::string evolutionOperatorDef
 
static std::string driverDefault
 

Private Member Functions

void AssertParameters (void)
 
void RunCoarseSolve (const NekDouble time, const size_t nstep, const Array< OneD, const Array< OneD, NekDouble > > &input, Array< OneD, Array< OneD, NekDouble > > &output)
 
void RunFineSolve (const NekDouble time, const size_t nstep, const size_t iter, const size_t wd, const Array< OneD, const Array< OneD, NekDouble > > &input, Array< OneD, Array< OneD, NekDouble > > &output)
 
void PararealCorrection (const Array< OneD, const Array< OneD, NekDouble > > &coarse_new, const Array< OneD, const Array< OneD, NekDouble > > &coarse_old, Array< OneD, Array< OneD, NekDouble > > &fine)
 
void PrintSolutionFile (void)
 
void ApplyWindowing (const Array< OneD, const Array< OneD, NekDouble > > &in, Array< OneD, Array< OneD, NekDouble > > &out)
 
void CopyConvergedCheckPoints (const size_t w, const size_t k, size_t kmax)
 

Friends

class MemoryManager< DriverParareal >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::SolverUtils::Driver
virtual ~Driver ()
 Destructor. More...
 
SOLVER_UTILS_EXPORT void InitObject (std::ostream &out=std::cout)
 Initialise Object. More...
 
SOLVER_UTILS_EXPORT void Execute (std::ostream &out=std::cout)
 Execute driver. More...
 
SOLVER_UTILS_EXPORT Array< OneD, EquationSystemSharedPtrGetEqu ()
 
- Protected Attributes inherited from Nektar::SolverUtils::DriverParallelInTime
NekDouble m_fineTimeStep
 Timestep for fine solver. More...
 
NekDouble m_coarseTimeStep
 Timestep for coarse solver. More...
 
NekDouble m_totalTime
 Total time integration interval. More...
 
NekDouble m_chunkTime
 Time for chunks. More...
 
NekDouble m_time
 Local time. More...
 
size_t m_infoSteps = 0
 Number of steps for info I/O. More...
 
size_t m_checkSteps = 0
 Number of steps for checkpoint. More...
 
size_t m_fineSteps = 1
 Number of steps for the fine solver. More...
 
size_t m_coarseSteps = 1
 Number of steps for the coarse solver. More...
 
size_t m_numChunks = 1
 Number of time chunks. More...
 
size_t m_chunkRank = 0
 Rank in time. More...
 
size_t m_iterMaxPIT = 0
 Maximum number of parallel-in-time iteration. More...
 
size_t m_numWindowsPIT = 1
 
bool m_exactSolution = 0
 Using exact solution to compute error norms. More...
 
NekDouble m_tolerPIT = 1e-15
 ParallelInTime tolerance. More...
 
size_t m_fineQuadPts
 
size_t m_coarseQuadPts
 
size_t m_fineNpts
 
size_t m_coarseNpts
 
size_t m_nVar
 
std::shared_ptr< SolverUtils::UnsteadySystemm_fineEqSys
 
std::shared_ptr< SolverUtils::UnsteadySystemm_coarseEqSys
 
Array< OneD, NekDoublem_vL2Errors
 
Array< OneD, NekDoublem_vLinfErrors
 
Array< OneD, Array< OneD, NekDouble > > m_exactsoln
 
Array< OneD, Array< OneD, NekDouble > > m_tmpfine
 
Array< OneD, Array< OneD, NekDouble > > m_tmpcoarse
 
Array< OneD, MultiRegions::ExpListSharedPtrm_fineFields
 
Array< OneD, MultiRegions::ExpListSharedPtrm_coarseFields
 
- Protected Attributes inherited from Nektar::SolverUtils::Driver
LibUtilities::CommSharedPtr m_comm
 Communication object. More...
 
LibUtilities::SessionReaderSharedPtr m_session
 Session reader object. More...
 
LibUtilities::SessionReaderSharedPtr session_LinNS
 Coupling between SFD and arnoldi. More...
 
SpatialDomains::MeshGraphSharedPtr m_graph
 MeshGraph object. More...
 
Array< OneD, EquationSystemSharedPtrm_equ
 Equation system to solve. More...
 
int m_nequ
 number of equations More...
 
enum EvolutionOperatorType m_EvolutionOperator
 Evolution Operator. More...
 

Detailed Description

Base class for the development of solvers.

Definition at line 46 of file DriverParareal.h.

Constructor & Destructor Documentation

◆ DriverParareal()

Nektar::SolverUtils::DriverParareal::DriverParareal ( const LibUtilities::SessionReaderSharedPtr  pSession,
const SpatialDomains::MeshGraphSharedPtr  pGraph 
)
protected

Constructor.

Definition at line 54 of file DriverParareal.cpp.

57 : DriverParallelInTime(pSession, pGraph)
58{
59}
SOLVER_UTILS_EXPORT DriverParallelInTime(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Constructor.

◆ ~DriverParareal()

virtual SOLVER_UTILS_EXPORT Nektar::SolverUtils::DriverParareal::~DriverParareal ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ ApplyWindowing()

void Nektar::SolverUtils::DriverParareal::ApplyWindowing ( const Array< OneD, const Array< OneD, NekDouble > > &  in,
Array< OneD, Array< OneD, NekDouble > > &  out 
)
private

Definition at line 560 of file DriverParareal.cpp.

563{
564 LibUtilities::CommSharedPtr tComm = m_session->GetComm()->GetTimeComm();
565
566 // Use last chunk solution as initial condition for the next
567 // window.
568 if (m_chunkRank == m_numChunks - 1)
569 {
570 for (size_t i = 0; i < in.size(); ++i)
571 {
572 Vmath::Vcopy(in[i].size(), in[i], 1, out[i], 1);
573 }
574 }
575
576 // Broadcast I.C. for windowing.
577 for (size_t i = 0; i < out.size(); ++i)
578 {
579 tComm->Bcast(out[i], m_numChunks - 1);
580 }
581}
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:85
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:57
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191

References Nektar::SolverUtils::DriverParallelInTime::m_chunkRank, Nektar::SolverUtils::DriverParallelInTime::m_numChunks, Nektar::SolverUtils::Driver::m_session, and Vmath::Vcopy().

Referenced by v_Execute().

◆ AssertParameters()

void Nektar::SolverUtils::DriverParareal::AssertParameters ( void  )
private

Definition at line 415 of file DriverParareal.cpp.

416{
417 // Assert time-stepping parameters
418 ASSERTL0(
420 "Total number of fine step should be divisible by number of chunks.");
421
422 ASSERTL0(
424 "Total number of coarse step should be divisible by number of chunks.");
425
427 "Total number of fine step should be divisible by number of "
428 "windows times number of chunks.");
429
431 "Total number of coarse step should be divisible by number of "
432 "windows times number of chunks.");
433
435 m_fineTimeStep * m_fineSteps) < 1e-12,
436 "Fine and coarse total computational times do not match");
437
438 // Assert I/O parameters
439 if (m_infoSteps)
440 {
442 0,
443 "number of IO_InfoSteps should divide number of fine steps "
444 "per time chunk");
445 }
446
447 if (m_checkSteps)
448 {
450 0,
451 "number of IO_CheckSteps should divide number of fine steps "
452 "per time chunk");
453 }
454}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
size_t m_coarseSteps
Number of steps for the coarse solver.
size_t m_fineSteps
Number of steps for the fine solver.
NekDouble m_coarseTimeStep
Timestep for coarse solver.
NekDouble m_fineTimeStep
Timestep for fine solver.
size_t m_checkSteps
Number of steps for checkpoint.
size_t m_infoSteps
Number of steps for info I/O.

References ASSERTL0, Nektar::SolverUtils::DriverParallelInTime::m_checkSteps, Nektar::SolverUtils::DriverParallelInTime::m_coarseSteps, Nektar::SolverUtils::DriverParallelInTime::m_coarseTimeStep, Nektar::SolverUtils::DriverParallelInTime::m_fineSteps, Nektar::SolverUtils::DriverParallelInTime::m_fineTimeStep, Nektar::SolverUtils::DriverParallelInTime::m_infoSteps, Nektar::SolverUtils::DriverParallelInTime::m_numChunks, and Nektar::SolverUtils::DriverParallelInTime::m_numWindowsPIT.

Referenced by v_Execute().

◆ CopyConvergedCheckPoints()

void Nektar::SolverUtils::DriverParareal::CopyConvergedCheckPoints ( const size_t  w,
const size_t  k,
size_t  kmax 
)
private

Output directory name.

Definition at line 586 of file DriverParareal.cpp.

588{
589 // Determine max number of iteration.
590 LibUtilities::CommSharedPtr tComm = m_session->GetComm()->GetTimeComm();
591 tComm->AllReduce(kmax, Nektar::LibUtilities::ReduceMax);
592
593 if (m_comm->GetSpaceComm()->GetRank() == 0 && m_checkSteps)
594 {
595 for (size_t j = k; j < kmax; j++)
596 {
597 // Copy converged solution files from directory corresponding to
598 // iteration j to the directory corresponding to iteration j + 1.
599
600 // Input directory name.
601 std::string indir = m_fineEqSys->GetSessionName() + "_" +
602 boost::lexical_cast<std::string>(j) + ".pit";
603
604 /// Output directory name.
605 std::string outdir = m_fineEqSys->GetSessionName() + "_" +
606 boost::lexical_cast<std::string>(j + 1) +
607 ".pit";
608
609 // Number of checkpoint by chunk.
610 size_t nChkPts = m_fineSteps / m_checkSteps;
611
612 // Checkpoint index.
613 size_t iChkPts = (m_chunkRank + w * m_numChunks) * nChkPts + 1;
614
615 for (size_t i = 0; i < nChkPts; i++)
616 {
617 // Filename corresponding to checkpoint iChkPts.
618 std::string filename =
619 m_fineEqSys->GetSessionName() + "_" +
620 boost::lexical_cast<std::string>(iChkPts) + ".chk";
621
622 // Intput full file name.
623 std::string infullname = indir + "/" + filename;
624
625 // Output full file name.
626 std::string outfullname = outdir + "/" + filename;
627
628 // Remove output file if already existing.
629 fs::remove_all(outfullname);
630
631 // Copy converged solution files.
632 fs::copy(infullname, outfullname);
633 }
634 }
635 }
636}
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:82
std::shared_ptr< SolverUtils::UnsteadySystem > m_fineEqSys
def copy(self)
Definition: pycml.py:2663
std::vector< double > w(NPUPPER)

References CellMLToNektar.pycml::copy(), Nektar::SolverUtils::DriverParallelInTime::m_checkSteps, Nektar::SolverUtils::DriverParallelInTime::m_chunkRank, Nektar::SolverUtils::Driver::m_comm, Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, Nektar::SolverUtils::DriverParallelInTime::m_fineSteps, Nektar::SolverUtils::DriverParallelInTime::m_numChunks, Nektar::SolverUtils::Driver::m_session, Nektar::LibUtilities::ReduceMax, and Nektar::UnitTests::w().

Referenced by v_Execute().

◆ create()

static DriverSharedPtr Nektar::SolverUtils::DriverParareal::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const SpatialDomains::MeshGraphSharedPtr pGraph 
)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file DriverParareal.h.

55 {
58 p->InitObject();
59 return p;
60 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:54

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ PararealCorrection()

void Nektar::SolverUtils::DriverParareal::PararealCorrection ( const Array< OneD, const Array< OneD, NekDouble > > &  coarse_new,
const Array< OneD, const Array< OneD, NekDouble > > &  coarse_old,
Array< OneD, Array< OneD, NekDouble > > &  fine 
)
private

Definition at line 536 of file DriverParareal.cpp.

540{
541 for (size_t i = 0; i < fine.size(); ++i)
542 {
543 Vmath::Vadd(fine[i].size(), fine[i], 1, coarse_new[i], 1, fine[i], 1);
544 Vmath::Vsub(fine[i].size(), fine[i], 1, coarse_old[i], 1, fine[i], 1);
545 }
546}
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:354
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:414

References Vmath::Vadd(), and Vmath::Vsub().

Referenced by v_Execute().

◆ PrintSolutionFile()

void Nektar::SolverUtils::DriverParareal::PrintSolutionFile ( void  )
private

Definition at line 551 of file DriverParareal.cpp.

552{
553 PrintHeaderTitle2("PRINT SOLUTION FILES");
554 m_fineEqSys->Output();
555}
void PrintHeaderTitle2(const std::string &title)

References Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, and Nektar::SolverUtils::DriverParallelInTime::PrintHeaderTitle2().

Referenced by v_Execute().

◆ RunCoarseSolve()

void Nektar::SolverUtils::DriverParareal::RunCoarseSolve ( const NekDouble  time,
const size_t  nstep,
const Array< OneD, const Array< OneD, NekDouble > > &  input,
Array< OneD, Array< OneD, NekDouble > > &  output 
)
private

Definition at line 459 of file DriverParareal.cpp.

463{
464 // Set to coarse timestep.
465 m_coarseEqSys->SetTime(time);
466 m_coarseEqSys->SetSteps(nstep);
467
468 // Restrict initial condition from input.
470
471 // Copy initial condition.
472 for (size_t i = 0; i < m_fineEqSys->GetNvariables(); ++i)
473 {
474 m_coarseEqSys->CopyToPhysField(i, m_tmpcoarse[i]);
475 }
476
477 // Solve equations.
478 m_coarseEqSys->DoSolve();
479
480 // Copy solution.
481 for (size_t i = 0; i < m_coarseEqSys->GetNvariables(); ++i)
482 {
483 m_coarseEqSys->CopyFromPhysField(i, m_tmpcoarse[i]);
484 }
485
486 // Interpolate solution to output.
487 Interpolator(m_tmpcoarse, output);
488}
void Interpolator(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
std::shared_ptr< SolverUtils::UnsteadySystem > m_coarseEqSys
Array< OneD, Array< OneD, NekDouble > > m_tmpcoarse

References Nektar::SolverUtils::DriverParallelInTime::Interpolator(), Nektar::SolverUtils::DriverParallelInTime::m_coarseEqSys, Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, and Nektar::SolverUtils::DriverParallelInTime::m_tmpcoarse.

Referenced by v_Execute().

◆ RunFineSolve()

void Nektar::SolverUtils::DriverParareal::RunFineSolve ( const NekDouble  time,
const size_t  nstep,
const size_t  iter,
const size_t  wd,
const Array< OneD, const Array< OneD, NekDouble > > &  input,
Array< OneD, Array< OneD, NekDouble > > &  output 
)
private

Definition at line 493 of file DriverParareal.cpp.

497{
498 // Number of checkpoint by chunk.
499 size_t nChkPts = m_checkSteps ? m_fineSteps / m_checkSteps : 1;
500
501 // Checkpoint index.
502 size_t iChkPts = (m_chunkRank + wd * m_numChunks) * nChkPts + 1;
503
504 // Set to fine timestep.
505 m_fineEqSys->SetTime(time);
506 m_fineEqSys->SetSteps(nstep);
507
508 // Reinitialize check point number for each parallel-in-time iteration.
509 m_fineEqSys->SetCheckpointNumber(iChkPts);
510
511 // Update parallel-in-time iteration number.
512 m_fineEqSys->SetIterationNumberPIT(iter + 1);
513
514 // Update parallel-in-time window number.
515 m_fineEqSys->SetWindowNumberPIT(wd);
516
517 // Copy initial condition from input.
518 for (size_t i = 0; i < m_fineEqSys->GetNvariables(); ++i)
519 {
520 m_fineEqSys->CopyToPhysField(i, input[i]);
521 }
522
523 // Solve equations.
524 m_fineEqSys->DoSolve();
525
526 // Copy solution to output.
527 for (size_t i = 0; i < m_fineEqSys->GetNvariables(); ++i)
528 {
529 m_fineEqSys->CopyFromPhysField(i, output[i]);
530 }
531}

References Nektar::SolverUtils::DriverParallelInTime::m_checkSteps, Nektar::SolverUtils::DriverParallelInTime::m_chunkRank, Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, Nektar::SolverUtils::DriverParallelInTime::m_fineSteps, and Nektar::SolverUtils::DriverParallelInTime::m_numChunks.

Referenced by v_EstimateFineSolverTime(), and v_Execute().

◆ v_ComputeSpeedUp()

NekDouble Nektar::SolverUtils::DriverParareal::v_ComputeSpeedUp ( const size_t  iter,
NekDouble  fineSolveTime,
NekDouble  coarseSolveTime,
NekDouble  restTime,
NekDouble  interTime,
NekDouble  commTime,
NekDouble  predictorOverheadTime,
NekDouble  overheadTime 
)
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 390 of file DriverParareal.cpp.

394{
395 // The speed-up estimate is based on "Lunet, T., Bodart, J., Gratton, S., &
396 // Vasseur, X. (2018). Time-parallel simulation of the decay of homogeneous
397 // turbulence using parareal with spatial coarsening. Computing and
398 // Visualization in Science, 19, 31-44".
399
400 size_t nComm = (iter * (2 * m_numChunks - iter - 1)) / 2;
401 NekDouble ratio = double(iter) / m_numChunks;
402 NekDouble ratioPredictor = predictorTime / fineSolveTime;
403 NekDouble ratioSolve = coarseSolveTime / fineSolveTime;
404 NekDouble ratioInterp = (restTime + interTime) / fineSolveTime;
405 NekDouble ratioComm = commTime / fineSolveTime;
406 NekDouble ratioOverhead = overheadTime / fineSolveTime;
407
408 return 1.0 / (ratioPredictor + ratio * (1.0 + ratioSolve + ratioInterp) +
409 (ratioComm * nComm + ratioOverhead) / m_numChunks);
410}
double NekDouble

References Nektar::SolverUtils::DriverParallelInTime::m_numChunks.

◆ v_EstimateCoarseSolverTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateCoarseSolverTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 301 of file DriverParareal.cpp.

302{
303 // Allocate memory.
304 Array<OneD, Array<OneD, NekDouble>> sol(m_nVar);
305 for (size_t i = 0; i < m_nVar; ++i)
306 {
307 sol[i] = Array<OneD, NekDouble>(m_coarseNpts);
308 }
309
310 // Turnoff I/O.
311 m_coarseEqSys->SetInfoSteps(0);
312 m_coarseEqSys->SetCheckpointSteps(0);
313
314 // Get initial condition.
316
317 // Estimate coarse solver time.
319 timer.Start();
320
321 // Set to coarse timestep.
322 m_coarseEqSys->SetTime(m_time + m_chunkTime);
323 m_coarseEqSys->SetSteps(10);
324
325 // Copy initial condition.
326 for (size_t i = 0; i < m_fineEqSys->GetNvariables(); ++i)
327 {
328 m_coarseEqSys->CopyToPhysField(i, sol[i]);
329 }
330
331 // Solve equations.
332 m_coarseEqSys->DoSolve();
333
334 // Copy solution.
335 for (size_t i = 0; i < m_coarseEqSys->GetNvariables(); ++i)
336 {
337 m_coarseEqSys->CopyFromPhysField(i, sol[i]);
338 }
339
340 timer.Stop();
341 return 0.1 * timer.Elapsed().count() * m_coarseSteps;
342}
void CopyFromFinePhysField(Array< OneD, Array< OneD, NekDouble > > &out)

References Nektar::SolverUtils::DriverParallelInTime::CopyFromFinePhysField(), Nektar::LibUtilities::Timer::Elapsed(), Nektar::SolverUtils::DriverParallelInTime::m_chunkTime, Nektar::SolverUtils::DriverParallelInTime::m_coarseEqSys, Nektar::SolverUtils::DriverParallelInTime::m_coarseNpts, Nektar::SolverUtils::DriverParallelInTime::m_coarseSteps, Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, Nektar::SolverUtils::DriverParallelInTime::m_nVar, Nektar::SolverUtils::DriverParallelInTime::m_time, Nektar::LibUtilities::Timer::Start(), and Nektar::LibUtilities::Timer::Stop().

Referenced by v_EstimatePredictorTime().

◆ v_EstimateCommunicationTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateCommunicationTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 235 of file DriverParareal.cpp.

236{
237 // Allocate memory.
238 Array<OneD, Array<OneD, NekDouble>> buffer1(m_nVar);
239 Array<OneD, Array<OneD, NekDouble>> buffer2(m_nVar);
240 for (size_t i = 0; i < m_nVar; ++i)
241 {
242 buffer1[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
243 buffer2[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
244 }
245
246 // Estimate communication time.
247 return EstimateCommunicationTime(buffer1, buffer2);
248}
NekDouble EstimateCommunicationTime(Array< OneD, Array< OneD, NekDouble > > &buffer1, Array< OneD, Array< OneD, NekDouble > > &buffer2)

References Nektar::SolverUtils::DriverParallelInTime::EstimateCommunicationTime(), Nektar::SolverUtils::DriverParallelInTime::m_fineNpts, and Nektar::SolverUtils::DriverParallelInTime::m_nVar.

◆ v_EstimateFineSolverTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateFineSolverTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 347 of file DriverParareal.cpp.

348{
349 // Allocate memory.
350 Array<OneD, Array<OneD, NekDouble>> sol(m_nVar);
351 for (size_t i = 0; i < m_nVar; ++i)
352 {
353 sol[i] = Array<OneD, NekDouble>(m_fineNpts);
354 }
355
356 // Turnoff I/O.
357 m_fineEqSys->SetInfoSteps(0);
358 m_fineEqSys->SetCheckpointSteps(0);
359
360 // Get initial condition.
362
363 // Estimate fine solver time.
365 timer.Start();
366 RunFineSolve(m_time + m_chunkTime, 100, 0, 0, sol, sol);
367 timer.Stop();
368 return 0.01 * timer.Elapsed().count() * m_fineSteps;
369}
void RunFineSolve(const NekDouble time, const size_t nstep, const size_t iter, const size_t wd, const Array< OneD, const Array< OneD, NekDouble > > &input, Array< OneD, Array< OneD, NekDouble > > &output)

References Nektar::SolverUtils::DriverParallelInTime::CopyFromFinePhysField(), Nektar::LibUtilities::Timer::Elapsed(), Nektar::SolverUtils::DriverParallelInTime::m_chunkTime, Nektar::SolverUtils::DriverParallelInTime::m_fineEqSys, Nektar::SolverUtils::DriverParallelInTime::m_fineNpts, Nektar::SolverUtils::DriverParallelInTime::m_fineSteps, Nektar::SolverUtils::DriverParallelInTime::m_nVar, Nektar::SolverUtils::DriverParallelInTime::m_time, RunFineSolve(), Nektar::LibUtilities::Timer::Start(), and Nektar::LibUtilities::Timer::Stop().

◆ v_EstimateInterpolationTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateInterpolationTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 277 of file DriverParareal.cpp.

278{
280 {
281 return 0.0; // No interpolation
282 }
283 else
284 {
285 // Average interpolation time over niter iteration.
286 size_t niter = 20;
288 timer.Start();
289 for (size_t n = 0; n < niter; n++)
290 {
292 }
293 timer.Stop();
294 return timer.Elapsed().count() / niter;
295 }
296}
Array< OneD, Array< OneD, NekDouble > > m_tmpfine

References Nektar::LibUtilities::Timer::Elapsed(), Nektar::SolverUtils::DriverParallelInTime::Interpolator(), Nektar::SolverUtils::DriverParallelInTime::m_coarseNpts, Nektar::SolverUtils::DriverParallelInTime::m_fineNpts, Nektar::SolverUtils::DriverParallelInTime::m_tmpcoarse, Nektar::SolverUtils::DriverParallelInTime::m_tmpfine, Nektar::LibUtilities::Timer::Start(), and Nektar::LibUtilities::Timer::Stop().

◆ v_EstimateOverheadTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateOverheadTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 382 of file DriverParareal.cpp.

383{
384 return 0.0;
385}

◆ v_EstimatePredictorTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimatePredictorTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 374 of file DriverParareal.cpp.

375{
377}
virtual NekDouble v_EstimateCoarseSolverTime(void) override

References v_EstimateCoarseSolverTime().

◆ v_EstimateRestrictionTime()

NekDouble Nektar::SolverUtils::DriverParareal::v_EstimateRestrictionTime ( void  )
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 253 of file DriverParareal.cpp.

254{
256 {
257 return 0.0; // No restriction necessary
258 }
259 else
260 {
261 // Average restriction time over niter iteration.
262 size_t niter = 20;
264 timer.Start();
265 for (size_t n = 0; n < niter; n++)
266 {
268 }
269 timer.Stop();
270 return timer.Elapsed().count() / niter;
271 }
272}

References Nektar::LibUtilities::Timer::Elapsed(), Nektar::SolverUtils::DriverParallelInTime::Interpolator(), Nektar::SolverUtils::DriverParallelInTime::m_coarseNpts, Nektar::SolverUtils::DriverParallelInTime::m_fineNpts, Nektar::SolverUtils::DriverParallelInTime::m_tmpcoarse, Nektar::SolverUtils::DriverParallelInTime::m_tmpfine, Nektar::LibUtilities::Timer::Start(), and Nektar::LibUtilities::Timer::Stop().

◆ v_Execute()

void Nektar::SolverUtils::DriverParareal::v_Execute ( std::ostream &  out = std::cout)
overrideprotectedvirtual

Virtual function for solve implementation.

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 72 of file DriverParareal.cpp.

73{
74 // Set timer.
76 NekDouble CPUtime = 0.0;
77
78 // Set time communication parameters.
79 LibUtilities::CommSharedPtr tComm = m_session->GetComm()->GetTimeComm();
80 m_numChunks = tComm->GetSize();
81 m_chunkRank = tComm->GetRank();
82
83 // Get and assert parameters from session file.
86
87 // Print solver info.
90
91 // Initialization.
92 InitialiseEqSystem(false);
95
96 // Allocate storage for Parareal solver.
97 Array<OneD, Array<OneD, NekDouble>> solutionCoarseCurr(m_nVar);
98 Array<OneD, Array<OneD, NekDouble>> solutionCoarsePrev(m_nVar);
99 Array<OneD, Array<OneD, NekDouble>> ic(m_nVar);
100 Array<OneD, Array<OneD, NekDouble>> solution(m_nVar);
101 for (size_t i = 0; i < m_nVar; ++i)
102 {
103 solutionCoarseCurr[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
104 solutionCoarsePrev[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
105 ic[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
106 solution[i] = Array<OneD, NekDouble>(m_fineNpts, 0.0);
107 }
108
109 // Get initial condition from fields.
111
112 // Start iteration windows.
113 tComm->Block();
118 for (size_t w = 0; w < m_numWindowsPIT; w++)
119 {
120 timer.Start();
121
122 // Initialize time for the current window.
124
125 // Print window number.
126 PrintHeaderTitle1((boost::format("WINDOWS #%1%") % (w + 1)).str());
127
128 // Run coarse solver.
129 if (m_chunkRank > 0)
130 {
133 }
134 RunCoarseSolve(m_time, m_coarseSteps, ic, solutionCoarsePrev);
135 CopySolutionVector(solutionCoarsePrev, solution);
136
137 // Update fields with solution.
138 CopyToFinePhysField(solution);
139
140 // Compute exact solution, if necessary.
141 if (m_exactSolution)
142 {
144 }
145
146 // Solution convergence monitoring.
147 timer.Stop();
148 CPUtime += timer.Elapsed().count();
149 PrintHeaderTitle2((boost::format("ITERATION %1%") % 0).str());
151 timer.Start();
152
153 // Start Parareal iteration.
154 size_t k = 0;
155 size_t kmax = 0;
156 int convergenceCurr = false;
157 int convergencePrev = (m_chunkRank == 0);
158 while (k < m_iterMaxPIT && !convergenceCurr)
159 {
160 // Use previous parareal solution as "exact solution", if necessary.
161 if (!m_exactSolution)
162 {
164 }
165
166 // Calculate fine solution (parallel-in-time).
167 RunFineSolve(m_time, m_fineSteps, k, w, ic, solution);
168
169 // Receive coarse solution from previous processor.
170 RecvInitialConditionFromPreviousProc(ic, convergencePrev);
171
172 // Calculate coarse solution (serial-in-time).
173 RunCoarseSolve(m_time, m_coarseSteps, ic, solutionCoarseCurr);
174
175 // Calculate corrected solution.
176 PararealCorrection(solutionCoarseCurr, solutionCoarsePrev,
177 solution);
178
179 // Save current coarse solution.
180 CopySolutionVector(solutionCoarseCurr, solutionCoarsePrev);
181
182 // Update fields with corrected solution.
183 CopyToFinePhysField(solution);
184
185 // Solution convergence monitoring.
186 timer.Stop();
187 CPUtime += timer.Elapsed().count();
188 PrintHeaderTitle2((boost::format("ITERATION %1%") % (k + 1)).str());
190 timer.Start();
191
192 // Check convergence of L2 error for each time chunk.
193 if ((vL2ErrorMax() < m_tolerPIT && convergencePrev) ||
194 m_chunkRank == k)
195 {
196 convergenceCurr = true;
197 }
198
199 // Send coarse solution to next processor.
200 SendSolutionToNextProc(solution, convergenceCurr);
201
202 // Increment index.
203 k++;
204 kmax = k;
205 }
206 timer.Stop();
207
208 // Copy converged check points.
209 CopyConvergedCheckPoints(w, k, kmax);
210
211 // Update solution before printing solution.
212 UpdateSolution(solution);
213
214 // Print solution files.
216
217 // Windowing.
218 if (w != m_numWindowsPIT - 1)
219 {
220 ApplyWindowing(solution, ic);
221 }
222 }
223
224 // Post-processing.
225 tComm->Block();
226 PrintHeaderTitle1("SUMMARY");
230}
NekDouble m_totalTime
Total time integration interval.
void SendSolutionToNextProc(Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
size_t m_iterMaxPIT
Maximum number of parallel-in-time iteration.
void CopyToFinePhysField(const Array< OneD, const Array< OneD, NekDouble > > &in)
void RecvInitialConditionFromPreviousProc(Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
void PrintHeaderTitle1(const std::string &title)
NekDouble m_tolerPIT
ParallelInTime tolerance.
void PrintCoarseSolverInfo(std::ostream &out=std::cout)
void PrintFineSolverInfo(std::ostream &out=std::cout)
bool m_exactSolution
Using exact solution to compute error norms.
void SolutionConvergenceMonitoring(const NekDouble &time)
Array< OneD, Array< OneD, NekDouble > > m_exactsoln
void SolutionConvergenceSummary(const NekDouble &time)
void UpdateSolution(const Array< OneD, const Array< OneD, NekDouble > > &in)
void CopySolutionVector(const Array< OneD, const Array< OneD, NekDouble > > &in, Array< OneD, Array< OneD, NekDouble > > &out)
void CopyConvergedCheckPoints(const size_t w, const size_t k, size_t kmax)
void ApplyWindowing(const Array< OneD, const Array< OneD, NekDouble > > &in, Array< OneD, Array< OneD, NekDouble > > &out)
void PararealCorrection(const Array< OneD, const Array< OneD, NekDouble > > &coarse_new, const Array< OneD, const Array< OneD, NekDouble > > &coarse_old, Array< OneD, Array< OneD, NekDouble > > &fine)
void RunCoarseSolve(const NekDouble time, const size_t nstep, const Array< OneD, const Array< OneD, NekDouble > > &input, Array< OneD, Array< OneD, NekDouble > > &output)

References Nektar::SolverUtils::DriverParallelInTime::AllocateMemory(), ApplyWindowing(), AssertParameters(), CopyConvergedCheckPoints(), Nektar::SolverUtils::DriverParallelInTime::CopyFromFinePhysField(), Nektar::SolverUtils::DriverParallelInTime::CopySolutionVector(), Nektar::SolverUtils::DriverParallelInTime::CopyToFinePhysField(), Nektar::LibUtilities::Timer::Elapsed(), Nektar::SolverUtils::DriverParallelInTime::EvaluateExactSolution(), CellMLToNektar.pycml::format, Nektar::SolverUtils::DriverParallelInTime::GetParametersFromSession(), Nektar::SolverUtils::DriverParallelInTime::InitialiseEqSystem(), Nektar::SolverUtils::DriverParallelInTime::InitialiseInterpolationField(), Nektar::SolverUtils::DriverParallelInTime::m_chunkRank, Nektar::SolverUtils::DriverParallelInTime::m_chunkTime, Nektar::SolverUtils::DriverParallelInTime::m_coarseSteps, Nektar::SolverUtils::DriverParallelInTime::m_exactsoln, Nektar::SolverUtils::DriverParallelInTime::m_exactSolution, Nektar::SolverUtils::DriverParallelInTime::m_fineNpts, Nektar::SolverUtils::DriverParallelInTime::m_fineSteps, Nektar::SolverUtils::DriverParallelInTime::m_fineTimeStep, Nektar::SolverUtils::DriverParallelInTime::m_iterMaxPIT, Nektar::SolverUtils::DriverParallelInTime::m_numChunks, Nektar::SolverUtils::DriverParallelInTime::m_numWindowsPIT, Nektar::SolverUtils::DriverParallelInTime::m_nVar, Nektar::SolverUtils::Driver::m_session, Nektar::SolverUtils::DriverParallelInTime::m_time, Nektar::SolverUtils::DriverParallelInTime::m_tolerPIT, Nektar::SolverUtils::DriverParallelInTime::m_totalTime, PararealCorrection(), Nektar::SolverUtils::DriverParallelInTime::PrintCoarseSolverInfo(), Nektar::SolverUtils::DriverParallelInTime::PrintFineSolverInfo(), Nektar::SolverUtils::DriverParallelInTime::PrintHeaderTitle1(), Nektar::SolverUtils::DriverParallelInTime::PrintHeaderTitle2(), PrintSolutionFile(), Nektar::SolverUtils::DriverParallelInTime::RecvInitialConditionFromPreviousProc(), RunCoarseSolve(), RunFineSolve(), Nektar::SolverUtils::DriverParallelInTime::SendSolutionToNextProc(), Nektar::SolverUtils::DriverParallelInTime::SolutionConvergenceMonitoring(), Nektar::SolverUtils::DriverParallelInTime::SolutionConvergenceSummary(), Nektar::SolverUtils::DriverParallelInTime::SpeedUpAnalysis(), Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), Nektar::SolverUtils::DriverParallelInTime::UpdateSolution(), Nektar::SolverUtils::DriverParallelInTime::vL2ErrorMax(), and Nektar::UnitTests::w().

◆ v_InitObject()

void Nektar::SolverUtils::DriverParareal::v_InitObject ( std::ostream &  out = std::cout)
overrideprotectedvirtual

Virtual function for initialisation implementation.

Reimplemented from Nektar::SolverUtils::DriverParallelInTime.

Definition at line 64 of file DriverParareal.cpp.

65{
67}
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.

References Nektar::SolverUtils::DriverParallelInTime::v_InitObject().

Friends And Related Function Documentation

◆ MemoryManager< DriverParareal >

friend class MemoryManager< DriverParareal >
friend

Definition at line 1 of file DriverParareal.h.

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::DriverParareal::className
static
Initial value:
=
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:67

Name of the class.

Definition at line 63 of file DriverParareal.h.

◆ driverLookupId

std::string Nektar::SolverUtils::DriverParareal::driverLookupId
staticprotected
Initial value:
=
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.

Definition at line 101 of file DriverParareal.h.