39 #include <boost/core/ignore_unused.hpp> 
   40 #include <boost/format.hpp> 
   68 UnsteadySystem::UnsteadySystem(
 
   86     m_session->MatchSolverInfo(
"DIFFUSIONADVANCEMENT", 
"Explicit",
 
   88     m_session->MatchSolverInfo(
"ADVECTIONADVANCEMENT", 
"Explicit",
 
   90     m_session->MatchSolverInfo(
"REACTIONADVANCEMENT", 
"Explicit",
 
   93     m_session->MatchSolverInfo(
"FLAGIMPLICITITSSTATISTICS", 
"True",
 
  103     if (
m_session->DefinesSolverInfo(
"TimeIntegrationMethod") ||
 
  138                      "Final condition not unique: " 
  139                      "fintime > 0.0 and Nsteps > 0");
 
  142                      "Timestep not unique: timestep > 0.0 & CFL > 0.0");
 
  154                      "m_CFLEnd >= m_cflSafetyFactor required");
 
  169                          x.first, 
m_session, shared_from_this(), x.second)));
 
  202         for (i = 0; i < nfields; ++i)
 
  206         nvariables = nfields;
 
  216         for (i = 0; i < nfields; ++i)
 
  229     for (i = 0; i < nvariables; ++i)
 
  245     bool doCheckTime        = 
false;
 
  248     int restartStep         = -1;
 
  262     string abortFile = 
"abort";
 
  263     if (
m_session->DefinesSolverInfo(
"CheckAbortFile"))
 
  265         abortFile = 
m_session->GetSolverInfo(
"CheckAbortFile");
 
  278             tmp_cflSafetyFactor =
 
  345             cout << 
"Steps: " << setw(8) << left << step + 1 << 
" " 
  346                  << 
"Time: " << setw(12) << left << 
m_time;
 
  350                 cout << 
" Time-step: " << setw(12) << left << 
m_timestep;
 
  354             ss << cpuTime << 
"s";
 
  355             cout << 
" CPU Time: " << setw(8) << left << ss.str() << endl;
 
  356             cpuPrevious = cpuTime;
 
  369         for (i = 0; i < nvariables; ++i)
 
  394                 if (
m_comm->GetRank() == 0)
 
  396                     cout << 
"Reached Steady State to tolerance " 
  407             for (i = 0; i < nvariables; ++i)
 
  409                 if (
Vmath::Nnan(fields[i].size(), fields[i], 1) > 0)
 
  417             if (
m_session->GetComm()->GetRank() == 0)
 
  419                 if (boost::filesystem::exists(abortFile))
 
  421                     boost::filesystem::remove(abortFile);
 
  426             m_session->GetComm()->AllReduce(abortFlags,
 
  429             ASSERTL0(!abortFlags[0], 
"NaN found during time integration.");
 
  439             totFilterTime += elapsed;
 
  442             if (
m_session->GetComm()->GetRank() == 0 &&
 
  444                 m_session->DefinesCmdLineArgument(
"verbose"))
 
  447                 s0 << x.first << 
":";
 
  449                 s1 << elapsed << 
"s";
 
  451                 s2 << elapsed / cpuPrevious * 100 << 
"%";
 
  452                 cout << 
"CPU time for filter " << setw(25) << left << s0.str()
 
  453                      << setw(12) << left << s1.str() << endl
 
  454                      << 
"\t Percentage of time integration:     " << setw(10)
 
  455                      << left << s2.str() << endl;
 
  460         if (
m_session->GetComm()->GetRank() == 0 &&
 
  464             ss << totFilterTime << 
"s";
 
  465             cout << 
"Total filters CPU Time:\t\t\t     " << setw(10) << left
 
  475                 vector<bool> transformed(nfields, 
false);
 
  476                 for (i = 0; i < nfields; i++)
 
  484                         transformed[i] = 
true;
 
  489                 for (i = 0; i < nfields; i++)
 
  514     if (
m_session->GetComm()->GetRank() == 0)
 
  522         if (
m_session->GetSolverInfo(
"Driver") != 
"SteadyState")
 
  524             cout << 
"Time-integration  : " << intTime << 
"s" << endl;
 
  529             cout << 
"-------------------------------------------" << endl
 
  533                  << 
"-------------------------------------------" << endl;
 
  540         for (i = 0; i < nfields; i++)
 
  553         for (i = 0; i < nvariables; ++i)
 
  597     if (
m_session->GetSolverInfo(
"EQTYPE") ==
 
  598         "SteadyAdvectionDiffusionReaction")
 
  625     outfile.open(
"solution1D.txt");
 
  628         outfile << scientific << setw(17) << setprecision(16) << x[i] << 
"  " 
  629                 << solution1D[0][i] << endl;
 
  631     outfile << endl << endl;
 
  637     if (
m_session->DefinesFunction(
"InitialConditions"))
 
  639         for (
int i = 0; i < 
m_fields.size(); ++i)
 
  643             vType = 
m_session->GetFunctionType(
"InitialConditions",
 
  648                 std::string filename = 
m_session->GetFunctionFilename(
 
  649                     "InitialConditions", 
m_session->GetVariable(i));
 
  651                 fs::path pfilename(filename);
 
  654                 if (fs::is_directory(pfilename))
 
  656                     fs::path metafile(
"Info.xml");
 
  657                     fs::path fullpath = pfilename / metafile;
 
  670                         time = boost::lexical_cast<NekDouble>(iter->second);
 
  676                         nchk = boost::lexical_cast<NekDouble>(iter->second);
 
  684     if (
m_session->DefinesCmdLineArgument(
"set-start-time"))
 
  686         time = boost::lexical_cast<NekDouble>(
 
  687             m_session->GetCmdLineArgument<std::string>(
"set-start-time")
 
  690     if (
m_session->DefinesCmdLineArgument(
"set-start-chknumber"))
 
  692         nchk = boost::lexical_cast<int>(
 
  693             m_session->GetCmdLineArgument<std::string>(
"set-start-chknumber"));
 
  696              "Starting time and checkpoint number should be >= 0");
 
  722     boost::ignore_unused(inarray);
 
  729     boost::ignore_unused(step);
 
  735     boost::ignore_unused(step);
 
  743     int phystot = 
m_fields[0]->GetTotPoints();
 
  744     int nvel    = vel.size();
 
  749     Vmath::Vmul(phystot, vel[0], 1, vel[0], 1, varcoeff, 1);
 
  750     for (
int n = 1; n < nvel; ++n)
 
  752         Vmath::Vvtvp(phystot, vel[n], 1, vel[n], 1, varcoeff, 1, varcoeff, 1);
 
  756     for (
int i = 0; i < 
m_fields[0]->GetNumElmts(); ++i)
 
  758         int offset = 
m_fields[0]->GetPhys_Offset(i);
 
  759         int nq     = 
m_fields[0]->GetExp(i)->GetTotPoints();
 
  764         for (
int n = 0; n < 
m_fields[0]->GetExp(i)->GetNumBases(); ++n)
 
  766             nmodes = max(nmodes, 
m_fields[0]->GetExp(i)->GetBasisNumModes(n));
 
  772         Vmath::Smul(nq, h, varcoeff + offset, 1, tmp = varcoeff + offset, 1);
 
  783         const int nPoints = 
m_fields[0]->GetTotPoints();
 
  787         for (
int i = 0; i < 
m_fields.size(); ++i)
 
  794         if (
m_comm->GetRank() == 0)
 
  797                 m_session->GetSessionName() + std::string(
".resd");
 
  799             m_errFile << setw(26) << left << 
"# Time";
 
  801             m_errFile << setw(26) << left << 
"CPU_Time";
 
  805             for (
int i = 0; i < 
m_fields.size(); ++i)
 
  827     const int nFields = 
m_fields.size();
 
  834     if (
m_comm->GetRank() == 0 &&
 
  842         int stepp = step + 1;
 
  847         for (
int i = 0; i < nFields; ++i)
 
  858     if (
m_session->DefinesCmdLineArgument(
"verbose") &&
 
  861         cout << 
"-- Maximum L^2 residual: " << maxL2 << endl;
 
  869     for (
int i = 0; i < 
m_fields.size(); ++i)
 
  883     boost::ignore_unused(step);
 
  885     const int nFields = 
m_fields.size();
 
  892     for (
int i = 0; i < nFields; ++i)
 
  910     for (
int i = 0; i < nFields; ++i)
 
  912         reference[i] = (reference[i] == 0) ? 1 : reference[i];
 
  913         L2[i]        = 
sqrt(residual[i] / reference[i]);
 
  919         "set-start-time", 
"", 
"Set the starting time of the simulation.");
 
  923         "set-start-chknumber", 
"",
 
  924         "Set the starting number of the checkpoint file.");
 
#define ASSERTL0(condition, msg)
 
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
 
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
 
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
 
static std::string RegisterCmdLineArgument(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line argument with the session reader.
 
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
 
A base class for describing how to solve specific equations.
 
int m_spacedim
Spatial dimension (>= expansion dim).
 
LibUtilities::CommSharedPtr m_comm
Communicator.
 
NekDouble m_timestep
Time step size.
 
NekDouble m_time
Current time of simulation.
 
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
 
NekDouble m_fintime
Finish time of the simulation.
 
NekDouble m_lastCheckTime
 
SOLVER_UTILS_EXPORT void Checkpoint_Output(const int n)
Write checkpoint file of m_fields.
 
NekDouble m_checktime
Time between checkpoints.
 
SOLVER_UTILS_EXPORT NekDouble GetTimeStep()
 
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareFeld=true)
Initialisation object for EquationSystem.
 
NekDouble m_timestepMax
Time step size.
 
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
 
int m_initialStep
Number of the step where the simulation should begin.
 
enum HomogeneousType m_HomogeneousType
 
SOLVER_UTILS_EXPORT int GetNpoints()
 
int m_nchk
Number of checkpoints written so far.
 
NekDouble m_TimeIncrementFactor
 
int m_steps
Number of steps to take.
 
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Map to identify relevant solver info to dump in output fields.
 
SOLVER_UTILS_EXPORT void SetBoundaryConditions(NekDouble time)
Evaluates the boundary conditions at the given time.
 
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &l)
Virtual function for generating summary information.
 
int m_checksteps
Number of steps between checkpoints.
 
SOLVER_UTILS_EXPORT void SetInitialConditions(NekDouble initialtime=0.0, bool dumpInitialConditions=true, const int domain=0)
Initialise the data in the dependent fields.
 
SOLVER_UTILS_EXPORT int GetTotPoints()
 
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
 
NekDouble m_CFLGrowth
CFL growth rate.
 
bool m_explicitReaction
Indicates if explicit or implicit treatment of reaction is used.
 
virtual SOLVER_UTILS_EXPORT void v_DoInitialise()
Sets up initial conditions.
 
Array< OneD, Array< OneD, NekDouble > > m_previousSolution
Storage for previous solution for steady-state check.
 
virtual SOLVER_UTILS_EXPORT void v_DoSolve()
Solves an unsteady problem.
 
bool m_CalcPhysicalAV
flag to update artificial viscosity
 
std::vector< std::pair< std::string, FilterSharedPtr > > m_filters
 
static std::string cmdSetStartTime
 
NekDouble m_cflSafetyFactor
CFL safety factor (comprise between 0 to 1).
 
LibUtilities::TimeIntegrationSchemeSharedPtr m_intScheme
Wrapper to the time integration scheme.
 
virtual SOLVER_UTILS_EXPORT ~UnsteadySystem()
Destructor.
 
NekDouble m_filterTimeWarning
Number of time steps between outputting status information.
 
NekDouble m_steadyStateTol
Tolerance to which steady state should be evaluated at.
 
int m_abortSteps
Number of steps between checks for abort conditions.
 
bool m_explicitAdvection
Indicates if explicit or implicit treatment of advection is used.
 
SOLVER_UTILS_EXPORT NekDouble MaxTimeStepEstimator()
Get the maximum timestep estimator for cfl control.
 
bool m_explicitDiffusion
Indicates if explicit or implicit treatment of diffusion is used.
 
virtual SOLVER_UTILS_EXPORT NekDouble v_GetTimeStep(const Array< OneD, const Array< OneD, NekDouble >> &inarray)
Return the timestep to be used for the next step in the time-marching loop.
 
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true)
Init object for UnsteadySystem class.
 
virtual SOLVER_UTILS_EXPORT bool v_RequireFwdTrans()
 
bool CheckSteadyState(int step)
Calculate whether the system has reached a steady state by observing residuals to a user-defined tole...
 
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
 
NekDouble m_CFLEnd
maximun cfl in cfl growth
 
SOLVER_UTILS_EXPORT void SVVVarDiffCoeff(const Array< OneD, Array< OneD, NekDouble >> vel, StdRegions::VarCoeffMap &varCoeffMap)
Evaluate the SVV diffusion coefficient according to Moura's paper where it should proportional to h t...
 
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &s)
Print a summary of time stepping parameters.
 
void InitializeSteadyState()
 
virtual SOLVER_UTILS_EXPORT void v_SteadyStateResidual(int step, Array< OneD, NekDouble > &L2)
 
bool m_flagImplicitSolver
 
virtual SOLVER_UTILS_EXPORT bool v_PreIntegrate(int step)
 
SOLVER_UTILS_EXPORT void CheckForRestartTime(NekDouble &time, int &nchk)
 
NekDouble m_steadyStateRes
 
SOLVER_UTILS_EXPORT void SteadyStateResidual(int step, Array< OneD, NekDouble > &L2)
 
static std::string cmdSetStartChkNum
 
NekDouble m_steadyStateRes0
 
std::vector< int > m_intVariables
 
bool m_flagUpdatePreconMat
 
int m_steadyStateSteps
Check for steady state at step interval.
 
virtual SOLVER_UTILS_EXPORT bool UpdateTimeStepCheck()
 
int m_filtersInfosteps
Number of time steps between outputting filters information.
 
virtual SOLVER_UTILS_EXPORT void v_AppendOutput1D(Array< OneD, Array< OneD, NekDouble >> &solution1D)
Print the solution at each solution point in a txt file.
 
int m_infosteps
Number of time steps between outputting status information.
 
bool m_homoInitialFwd
Flag to determine if simulation should start in homogeneous forward transformed state.
 
bool m_flagImplicitItsStatistics
 
TimeIntegrationSchemeFactory & GetTimeIntegrationSchemeFactory()
 
std::shared_ptr< FieldIO > FieldIOSharedPtr
 
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
 
std::shared_ptr< SessionReader > SessionReaderSharedPtr
 
static FieldMetaDataMap NullFieldMetaDataMap
 
static const NekDouble kNekZeroTol
 
std::vector< std::pair< std::string, std::string > > SummaryList
 
FilterFactory & GetFilterFactory()
 
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
 
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
 
std::map< StdRegions::VarCoeffType, Array< OneD, NekDouble > > VarCoeffMap
 
The above copyright notice and this permission notice shall be included.
 
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
 
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
 
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
 
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
 
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
 
int Nnan(int n, const T *x, const int incx)
Return number of NaN elements of x.
 
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
 
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
 
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.
 
scalarT< T > sqrt(scalarT< T > in)
 
std::vector< NekDouble > freeParams