47#include <boost/format.hpp>
94 ASSERTL0(
false,
"Unrecognised evolution operator.");
99 for (
size_t timeLevel = 0; timeLevel <
m_nTimeLevel; timeLevel++)
102 std::dynamic_pointer_cast<SolverUtils::UnsteadySystem>(
112 ASSERTL0(e == -1,
"No such class class defined.");
113 out <<
"An error occurred during driver initialisation." << std::endl;
128 std::string AdvectiveType)
132 "EqType SolverInfo tag must be defined.");
133 std::string vEquation =
m_session->DefinesSolverInfo(
"SolverType")
139 "EquationSystem '" + vEquation +
140 "' is not defined.\n"
141 "Ensure equation name is correct and module is compiled.\n");
144 m_session->SetTag(
"AdvectiveType", AdvectiveType);
145 m_session->SetTag(
"ParallelInTimeSolver",
"TimeLevel0");
150 int npx =
m_session->DefinesCmdLineArgument(
"npx")
151 ?
m_session->GetCmdLineArgument<
int>(
"npx")
153 int npy =
m_session->DefinesCmdLineArgument(
"npy")
154 ?
m_session->GetCmdLineArgument<
int>(
"npy")
156 int npz =
m_session->DefinesCmdLineArgument(
"npz")
157 ?
m_session->GetCmdLineArgument<
int>(
"npz")
159 int nsz =
m_session->DefinesCmdLineArgument(
"nsz")
160 ?
m_session->GetCmdLineArgument<
int>(
"nsz")
162 int npt =
m_session->DefinesCmdLineArgument(
"npt")
163 ?
m_session->GetCmdLineArgument<
int>(
"npt")
167 std::string npx_string = std::to_string(npx);
168 std::string npy_string = std::to_string(npy);
169 std::string npz_string = std::to_string(npz);
170 std::string nsz_string = std::to_string(nsz);
171 std::string npt_string = std::to_string(npt);
172 std::string driver_string =
"Driver=" +
m_session->GetSolverInfo(
"Driver");
175 bool useOptFile =
m_session->DefinesCmdLineArgument(
"use-opt-file");
176 std::string optfilename = useOptFile ?
m_session->GetFilenames()[0] :
"";
178 char *argv[] = {
const_cast<char *
>(
"Solver"),
179 const_cast<char *
>(
"--solverinfo"),
180 const_cast<char *
>(driver_string.c_str()),
181 const_cast<char *
>(
"--npx"),
182 const_cast<char *
>(npx_string.c_str()),
183 const_cast<char *
>(
"--npy"),
184 const_cast<char *
>(npy_string.c_str()),
185 const_cast<char *
>(
"--npz"),
186 const_cast<char *
>(npz_string.c_str()),
187 const_cast<char *
>(
"--nsz"),
188 const_cast<char *
>(nsz_string.c_str()),
189 const_cast<char *
>(
"--npt"),
190 const_cast<char *
>(npt_string.c_str()),
191 const_cast<char *
>(
"-f"),
192 const_cast<char *
>(
"--use-opt-file"),
193 const_cast<char *
>(optfilename.c_str()),
196 size_t argc = useOptFile ? 16 : 14;
199 std::vector<std::string> sessionFileNames;
200 for (
auto &filename :
m_session->GetFilenames())
203 if (filename.substr(filename.find_last_of(
".") + 1) !=
"opt")
205 sessionFileNames.push_back(filename);
210 for (
size_t timeLevel = 1; timeLevel <
m_nTimeLevel; timeLevel++)
213 argc, argv, sessionFileNames,
m_session->GetComm(), timeLevel);
220 graph->SetBndRegionOrdering(
m_graph->GetBndRegionOrdering());
223 graph->SetCompositeOrdering(
m_graph->GetCompositeOrdering());
226 ASSERTL0(session->DefinesSolverInfo(
"EqType"),
227 "EqType SolverInfo tag must be defined.");
228 auto vEquation = session->DefinesSolverInfo(
"SolverType")
229 ? session->GetSolverInfo(
"SolverType")
230 : session->GetSolverInfo(
"EqType");
235 "EquationSystem '" + vEquation +
236 "' is not defined.\n"
237 "Ensure equation name is correct and module is compiled.\n");
240 session->SetTag(
"AdvectiveType", AdvectiveType);
241 session->SetTag(
"ParallelInTimeSolver",
242 "TimeLevel" + std::to_string(timeLevel));
244 vEquation, session, graph);
266 ?
m_session->GetParameter(
"ExactSolution")
280 for (
size_t timeLevel = 0; timeLevel <
m_nTimeLevel; timeLevel++)
282 m_EqSys[timeLevel]->SetInfoSteps(0);
283 m_EqSys[timeLevel]->SetCheckpointSteps(0);
286 m_EqSys[0]->DoInitialise(
true);
289 for (
size_t timeLevel = 1; timeLevel <
m_nTimeLevel; timeLevel++)
291 m_EqSys[timeLevel]->DoInitialise(
false);
298 for (
size_t timeLevel = 0; timeLevel <
m_nTimeLevel; timeLevel++)
301 m_EqSys[timeLevel]->EquationSystem::GetTimeStep();
303 m_npts[timeLevel] =
m_EqSys[timeLevel]->EquationSystem::GetNpoints();
308 for (
size_t i = 0; i <
m_nVar; ++i)
323 for (
size_t timeLevel = 0; timeLevel <
m_nTimeLevel; timeLevel++)
325 std::cout << std::string(71,
'=') << std::endl << std::flush;
326 std::cout <<
"=========================== TIME LEVEL " +
327 std::to_string(timeLevel) +
329 "========================="
333 m_EqSys[timeLevel]->PrintSummary(out);
335 std::cout << std::endl << std::flush;
346 m_comm->GetSpaceComm()->GetRank() == 0)
348 std::cout << std::endl;
349 std::cout << std::string(43, c) << std::endl << std::flush;
350 std::cout <<
title << std::endl << std::flush;
351 std::cout << std::string(43, c) << std::endl << std::flush;
366 for (
size_t i = 0; i <
m_nVar; ++i)
394 for (
size_t i = 0; i <
m_nVar; ++i)
419 for (
size_t i = 0; i <
m_nVar; ++i)
431 for (
size_t i = 0; i <
m_nVar; ++i)
433 m_EqSys[timeLevel]->CopyFromPhysField(i, out[i]);
443 for (
size_t i = 0; i <
m_nVar; ++i)
445 m_EqSys[timeLevel]->CopyToPhysField(i, in[i]);
446 m_EqSys[timeLevel]->UpdateFields()[i]->SetPhysState(
true);
456 for (
size_t i = 0; i <
m_nVar; ++i)
460 m_EqSys[timeLevel]->CopyToPhysField(i, in[i]);
462 m_EqSys[timeLevel]->UpdateFields()[i]->FwdTrans(
463 m_EqSys[timeLevel]->UpdateFields()[i]->GetPhys(),
464 m_EqSys[timeLevel]->UpdateFields()[i]->UpdateCoeffs());
474 for (
size_t i = 0; i <
m_nVar; ++i)
504 const bool normalized)
506 for (
size_t i = 0; i <
m_nVar; ++i)
518 const bool normalized)
521 m_comm->GetSpaceComm()->GetRank() == 0)
523 for (
size_t i = 0; i <
m_nVar; ++i)
527 std::cout <<
"L2 error (variable "
528 <<
m_EqSys[timeLevel]->GetVariable(i)
531 std::cout <<
"Linf error (variable "
532 <<
m_EqSys[timeLevel]->GetVariable(i)
538 std::cout <<
"L 2 error (variable "
539 <<
m_EqSys[timeLevel]->GetVariable(i)
542 std::cout <<
"L inf error (variable "
543 <<
m_EqSys[timeLevel]->GetVariable(i)
557 for (
size_t i = 0; i <
m_nVar; ++i)
580 for (
size_t n = 0; n <= niter; n++)
589 for (
size_t i = 0; i < buffer1.size(); ++i)
597 for (
size_t i = 0; i < buffer2.size(); ++i)
599 m_comm->GetTimeComm()->Recv(0, buffer2[i]);
604 return timer.
Elapsed().count() / niter;
617 if (infield.size() != outfield.size())
622 for (
size_t n = 0; n < infield.size(); ++n)
627 if (infield[n]->GetExpSize() != outfield[n]->GetExpSize())
634 ? infield[n]->UpdatePhys()
637 ? outfield[n]->UpdatePhys()
641 if (infield[n]->GetTotPoints() == outfield[n]->GetTotPoints())
643 Vmath::Vcopy(infield[n]->GetTotPoints(), inphys, 1, outphys, 1);
648 for (
size_t i = 0; i < infield[n]->GetExpSize(); ++i)
651 auto inElmt = infield[n]->GetExp(i);
652 auto outElmt = outfield[n]->GetExp(i);
655 size_t inoffset = infield[n]->GetPhys_Offset(i);
656 size_t outoffset = outfield[n]->GetPhys_Offset(i);
660 inElmt->FwdTrans(inphys + inoffset, incoeff);
666 expPtr = std::make_shared<StdRegions::StdSegExp>(
668 inElmt->GetBasis(0)->GetBasisType(),
669 inElmt->GetBasis(0)->GetNumModes(),
670 outElmt->GetBasis(0)->GetPointsKey()));
674 expPtr = std::make_shared<StdRegions::StdQuadExp>(
676 inElmt->GetBasis(0)->GetBasisType(),
677 inElmt->GetBasis(0)->GetNumModes(),
678 outElmt->GetBasis(0)->GetPointsKey()),
680 inElmt->GetBasis(1)->GetBasisType(),
681 inElmt->GetBasis(1)->GetNumModes(),
682 outElmt->GetBasis(1)->GetPointsKey()));
686 expPtr = std::make_shared<StdRegions::StdTriExp>(
688 inElmt->GetBasis(0)->GetBasisType(),
689 inElmt->GetBasis(0)->GetNumModes(),
690 outElmt->GetBasis(0)->GetPointsKey()),
692 inElmt->GetBasis(1)->GetBasisType(),
693 inElmt->GetBasis(1)->GetNumModes(),
694 outElmt->GetBasis(1)->GetPointsKey()));
698 expPtr = std::make_shared<StdRegions::StdHexExp>(
700 inElmt->GetBasis(0)->GetBasisType(),
701 inElmt->GetBasis(0)->GetNumModes(),
702 outElmt->GetBasis(0)->GetPointsKey()),
704 inElmt->GetBasis(1)->GetBasisType(),
705 inElmt->GetBasis(1)->GetNumModes(),
706 outElmt->GetBasis(1)->GetPointsKey()),
708 inElmt->GetBasis(2)->GetBasisType(),
709 inElmt->GetBasis(2)->GetNumModes(),
710 outElmt->GetBasis(2)->GetPointsKey()));
714 expPtr = std::make_shared<StdRegions::StdPrismExp>(
716 inElmt->GetBasis(0)->GetBasisType(),
717 inElmt->GetBasis(0)->GetNumModes(),
718 outElmt->GetBasis(0)->GetPointsKey()),
720 inElmt->GetBasis(1)->GetBasisType(),
721 inElmt->GetBasis(1)->GetNumModes(),
722 outElmt->GetBasis(1)->GetPointsKey()),
724 inElmt->GetBasis(2)->GetBasisType(),
725 inElmt->GetBasis(2)->GetNumModes(),
726 outElmt->GetBasis(2)->GetPointsKey()));
730 expPtr = std::make_shared<StdRegions::StdPyrExp>(
732 inElmt->GetBasis(0)->GetBasisType(),
733 inElmt->GetBasis(0)->GetNumModes(),
734 outElmt->GetBasis(0)->GetPointsKey()),
736 inElmt->GetBasis(1)->GetBasisType(),
737 inElmt->GetBasis(1)->GetNumModes(),
738 outElmt->GetBasis(1)->GetPointsKey()),
740 inElmt->GetBasis(2)->GetBasisType(),
741 inElmt->GetBasis(2)->GetNumModes(),
742 outElmt->GetBasis(2)->GetPointsKey()));
746 expPtr = std::make_shared<StdRegions::StdTetExp>(
748 inElmt->GetBasis(0)->GetBasisType(),
749 inElmt->GetBasis(0)->GetNumModes(),
750 outElmt->GetBasis(0)->GetPointsKey()),
752 inElmt->GetBasis(1)->GetBasisType(),
753 inElmt->GetBasis(1)->GetNumModes(),
754 outElmt->GetBasis(1)->GetPointsKey()),
756 inElmt->GetBasis(2)->GetBasisType(),
757 inElmt->GetBasis(2)->GetNumModes(),
758 outElmt->GetBasis(2)->GetPointsKey()));
763 expPtr->BwdTrans(incoeff, tmp);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Describes the specification for a Basis.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
Base class for the development of solvers.
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
LibUtilities::CommSharedPtr m_comm
Communication object.
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
size_t m_numChunks
Number of time chunks.
NekDouble vL2ErrorMax(void)
Array< OneD, NekDouble > m_vL2Errors
Storage for parallel-in-time iteration.
void UpdateFieldCoeffs(const size_t timeLevel, const Array< OneD, const Array< OneD, NekDouble > > &in=NullNekDoubleArrayOfArray)
void SendToNextProc(Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
size_t m_nTimeLevel
Number of time levels.
size_t m_iterMaxPIT
Maximum number of parallel-in-time iteration.
void PrintErrorNorm(const size_t timeLevel, const bool normalized)
void SetParallelInTimeEquationSystem(std::string AdvectiveType)
Array< OneD, size_t > m_nsteps
Number of time steps for each time level.
void InitialiseEqSystem(bool turnoff_output)
SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.
Array< OneD, NekDouble > m_vLinfErrors
void EvaluateExactSolution(const size_t timeLevel, const NekDouble &time)
void GetParametersFromSession(void)
void RecvFromPreviousProc(Array< OneD, Array< OneD, NekDouble > > &array, int &convergence)
Array< OneD, std::shared_ptr< UnsteadySystem > > m_EqSys
Equation system to solve.
void PrintHeader(const std::string &title, const char c)
NekDouble m_tolerPIT
ParallelInTime tolerance.
size_t m_chunkRank
Rank in time.
void PrintSolverInfo(std::ostream &out=std::cout)
size_t m_nVar
Number of variables.
bool m_exactSolution
Using exact solution to compute error norms.
void CopyFromPhysField(const size_t timeLevel, Array< OneD, Array< OneD, NekDouble > > &out)
void CopyToPhysField(const size_t timeLevel, const Array< OneD, const Array< OneD, NekDouble > > &in)
SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout) override
Virtual function for solve implementation.
Array< OneD, size_t > m_npts
Number of dof for each time level.
Array< OneD, Array< OneD, NekDouble > > m_exactsoln
NekDouble EstimateCommunicationTime(Array< OneD, Array< OneD, NekDouble > > &buffer1, Array< OneD, Array< OneD, NekDouble > > &buffer2)
void SolutionConvergenceSummary(const size_t timeLevel)
Array< OneD, NekDouble > m_timestep
Time step for each time level.
void CopySolutionVector(const Array< OneD, const Array< OneD, NekDouble > > &in, Array< OneD, Array< OneD, NekDouble > > &out)
void UpdateErrorNorm(const size_t timeLevel, const bool normalized)
void SolutionConvergenceMonitoring(const size_t timeLevel, const size_t iter)
SOLVER_UTILS_EXPORT DriverParallelInTime(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Constructor.
void Interpolate(const Array< OneD, MultiRegions::ExpListSharedPtr > &infield, const Array< OneD, MultiRegions::ExpListSharedPtr > &outfield, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static DomainRangeShPtr NullDomainRangeShPtr
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)