16#include <Schema_Temps_base.h>
17#include <EcrFicCollecte.h>
18#include <communications.h>
19#include <Probleme_base.h>
20#include <Matrice_Morse.h>
21#include <LecFicDiffuse.h>
22#include <Equation_base.h>
23#include <TRUST_2_PDI.h>
29#include <DeviceMemory.h>
30#include <Perf_counters.h>
52Schema_Temps_base::Schema_Temps_base() :
109 Cout <<
"Time step finally used to solve the next time step (taking into account facsec) : " << dt <<
" s." << finl;
114 Cerr <<
"---------------------------------------------------------" << finl;
115 Cerr <<
"Problem with the time step " << dt <<
" which is less than dt_min " <<
dt_min_ << finl;
116 Cerr <<
"Lower dt_min value or check why the time step decreases..." << finl;
117 Cerr <<
"Results are saved to provide help." << finl;
118 Cerr <<
"---------------------------------------------------------" << finl;
145 stationnaire_atteint_ = -1;
166 Cout<<
"====================================================" << finl;
167 Cout<< equation.
que_suis_je()<<
" equation is not solved."<<finl;
168 Cout<<
"====================================================" << finl;
207 double i, j, epsilon = 1.e-8;
215 statistics().begin_count(STD_COUNTERS::update_variables,statistics().get_last_opened_counter_level()+1);
227 statistics().end_count(STD_COUNTERS::update_variables);
233 progress_<< (int)100<< finl;
243 if (stationnaire_atteint_ && (
nb_pas_dt_ >= 2))
245 Cerr <<
"---------------------------------------------------------"
248 <<
" has reached the steady state"
274 mon_probleme=un_probleme;
348 param.
ajouter_non_std(
"periode_sauvegarde_securite_en_heures",(
this));
352 param.
ajouter_flag(
"disable_progress",&disable_progress_);
380 os <<
"dt " <<
dt_ << finl;
382 os <<
"tinit " <<
tinit_ << finl;
383 os <<
"tmax " <<
tmax_ << finl ;
384 os <<
"tcpumax " <<
tcpumax_ << finl ;
387 os <<
"dt_min " <<
dt_min_ << finl;
388 os <<
"dt_max " <<
dt_max_ << finl;
389 os <<
"facsec " <<
facsec_ << finl;
393 os <<
"dt_sauv " <<
dt_sauv_ << finl;
396 os <<
"dt_impr " <<
dt_impr_ << finl;
398 os <<
"stationnaire_atteint " << stationnaire_atteint_ << finl;
405 os <<
"disable_progress " << int(disable_progress_) << finl ;
406 os <<
"disable_dt_ev " << int(disable_dt_ev_) << finl ;
408 os <<
"fin " << finl;
430 Cerr<<
"Reading of data for a "<<
que_suis_je()<<
" time scheme"<<finl;
433 param.lire_avec_accolades_depuis(is);
436 Cerr<<
"dt_min has not been read or is set to 0."<<finl;
437 Cerr<<
"Assign a value strictly positive to dt_min."<<finl;
444 Cerr <<
"NO next backup, by security, because dt_sauv = " <<
dt_sauv_ << finl;
446 Cerr <<
"The next backup, by security, will take place after " <<
limite_cpu_sans_sauvegarde_/3600 <<
" hours of calculation." << finl;
467 les_mots2[0]=
"dt_std";
468 les_mots2[1]=
"dt_min";
469 les_mots2[2]=
"dt_calc";
470 les_mots2[3]=
"dt_fixe";
471 int rang2=les_mots2.
search(motlu);
488 Cerr<<
" We do not understand "<<motlu <<
"in Schema_Temps_base::lire_motcle_non_standard"<<finl;
489 Cerr<<
"keywords understood "<<les_mots2<<finl;
495 else if (mot==
"nb_pas_dt_max")
497 else if (mot==
"periode_sauvegarde_securite_en_heures")
499 else if (mot==
"tcpumax")
501 else if (mot==
"no_check_disk_space")
503 else if (mot ==
"residuals")
505 else if(mot ==
"facsec")
518 Cerr <<
"Reading of the maximum number of time steps" << finl;
525 Cerr <<
"Reading of the safety backup period in hours" << finl;
534 Cerr <<
"Reading the max cpu time allowed" << finl;
550 residuals_mots[0]=
"relative";
551 residuals_mots[1]=
"norm";
552 int res_rang=residuals_mots.
search(m);
563 Cerr<<
" We do not understand "<<m <<
"in Schema_Temps_base::lire_motcle_non_standard"<<finl;
564 Cerr<<
" keywords understood "<<residuals_mots<<finl;
582 os <<
"-------------------------------------------------------------------" << finl;
583 os <<
"We finished treating the time step number "<<
nb_pas_dt_ <<
" , for the time scheme ..." << finl
584 <<
" stable dt used = " <<
dt_ << finl
597 os <<
" Problem : " << pb.
le_nom() << finl;
598 os <<
"We treat the time step number "<<
nb_pas_dt_ << finl;
599 os <<
" dt = " <<
dt_ << finl;
607 os <<
" Problem : " << pb.
le_nom() << finl;
608 os <<
"We treat the time step number "<<
nb_pas_dt_ << finl;
609 os <<
" dt = " <<
dt_ << finl;
616 int ccc_tremain(
double*);
628 statistics().end_count(STD_COUNTERS::update_variables,0,0);
630 statistics().begin_count(STD_COUNTERS::update_variables,statistics().get_last_opened_counter_level()+1);
649 Cerr <<
"NO next backup, by security, because dt_sauv = " <<
dt_sauv_ << finl;
651 Cerr <<
"The next backup, by security, will take place after " <<
limite_cpu_sans_sauvegarde_/3600 <<
" hours of calculation." << finl;
656 temps_cpu_ecoule_ = statistics().get_time_since_last_open(STD_COUNTERS::total_execution_time);
666 double second_remain;
667 int error = ccc_tremain(&second_remain);
670 int hour_remain = (int)(second_remain/3600);
671 second_remain-=hour_remain*3600;
672 int minute_remain = (int)(second_remain/60);
673 second_remain-=minute_remain*60;
674 Cout << hour_remain <<
"h"<<minute_remain<<
"mn"<<second_remain<<
"s before job is killed on CCRT." << finl;
677 Cout <<
"Error." << finl;
703 double i, j, epsilon = 1.e-8;
758 int simple_checkpoint = ref_cast_non_const(
Probleme_base, mon_probleme.valeur()).is_sauvegarde_simple();
761 if(!simple_checkpoint)
764 Cerr <<
"WARNING ! Overwriting the first " <<
nb_sauv_max_ <<
" backups..." << finl;
773 pdi_interface.
trigger(
"time_scheme");
801 if (!get_disable_stop())
810 ficstop << stop_lu_l;
816 ficstop >> stop_lu_l;
844 double dt = std::min(
dt_max_, dt_propose);
847 bool adapt_dt_tmax =
false;
853 adapt_dt_tmax =
true;
858 adapt_dt_tmax =
true;
864 if ((dt -
dt_min_) / (dt + DMINFLOAT) < -1.e-6 && !adapt_dt_tmax)
867 Cerr <<
"---------------------------------------------------------" << finl;
868 Cerr <<
"Problem with the time step " << dt <<
" which is less than dt_min " <<
dt_min_ << finl;
869 Cerr <<
"Lower dt_min value or check why the time step decreases..." << finl;
870 Cerr <<
"Results are saved to provide help." << finl;
871 Cerr <<
"---------------------------------------------------------" << finl;
896 Cerr <<
"---------------------------------------------------------"
899 <<
" wants to stop : final time reached"
906 Cerr <<
"---------------------------------------------------------"
909 <<
" wants to stop : the maximum number of time steps reached"
916 Cerr <<
"---------------------------------------------------------"
919 <<
" wants to stop : max cpu time reached"
924 if (!get_disable_stop())
928 Cerr <<
"---------------------------------------------------------"
931 <<
" wants to stop : stop file detected"
942 return mon_probleme.valeur();
947 return mon_probleme.valeur();
973 DoubleVect& residu_equation = equation.
get_residu();
979 Cerr <<
"Error in Schema_Temps_base::update_critere_statio" << finl;
980 Cerr <<
"Array residu_equation has a null size" << finl;
982 if (
pb_base().equation(i).get_residu().size_array()==0)
985 Cerr <<
"Please, contact TRUST support." << finl;
992 residu_equation(0) = mp_max_abs_vect(tab_critere);
994 residu_equation(0) = mp_norme_vect(tab_critere);
997 Cerr <<
"Schema_Temps_base::update_critere_statio : only norm max and norm L2 are allowed to compute residuals ("
1005 mp_max_abs_tab(tab_critere, residu_equation);
1007 mp_norme_tab(tab_critere, residu_equation);
1010 Cerr <<
"Schema_Temps_base::update_critere_statio : only norm max and norm L2 are allowed to compute residuals ("
1022 for (
int i=0; i<size; i++)
1023 residu_initial_equation(i) = residu_equation(i);
1028 for (
int i=0; i<size; i++)
1029 if (residu_initial_equation(i)>0)
1030 residu_equation(i) /= residu_initial_equation(i);
1034 const double max_var = mp_max_abs_vect(equation.
inconnue().
futur());
1035 const double min_var = mp_min_abs_vect(equation.
inconnue().
futur());
1036 residu_equation /= max_var - min_var + 1e-2;
1041 double equation_residual = local_max_abs_vect(residu_equation);
1052 int precision_temps;
1054 precision_temps=std::max( precision_actuelle, (
int)(2+log10(1/std::fabs(
pas_de_temps()))+(
int)(log10(std::fabs(
temps_courant())))) );
1056 precision_temps=std::max( precision_actuelle, (
int)(2+log10(1/std::fabs(
pas_de_temps()))) );
1071 if (!progress_.is_open())
1072 progress_.ouvrir(
nom_du_cas() +
".progress");
1088 double nb_pas_avant_fin = std::min(nb_pas_selon_tmax, nb_pas_selon_nb_pas_dt_max);
1090 double dpercent = (1. - nb_pas_avant_fin /
1102 dpercent = std::max(dpercent, dpercent2);
1104 int percent = int(dpercent * 100);
1108 double seconds_to_finish = statistics().get_time_since_last_open(STD_COUNTERS::total_execution_time) * (1. - dpercent) / dpercent;
1109 int integer_limit = (int) (pow(2.0, (
double) ((
sizeof(
int) * 8) - 1)) - 1);
1110 if (seconds_to_finish < integer_limit)
1112 int h = int(seconds_to_finish / 3600);
1113 int mn = int((seconds_to_finish - 3600 * h) / 60);
1114 int s = int(seconds_to_finish - 3600 * h - 60 * mn);
1116 Cout << finl <<
"Estimated CPU time to finish the run (according to "
1117 << (nb_pas_selon_tmax < nb_pas_selon_nb_pas_dt_max ?
"tmax" :
"nb_pas_dt_max")
1119 if (seconds_to_finish < 1)
1120 Cout << seconds_to_finish <<
" s";
1122 Cout << h <<
"h" << mn <<
"mn" << s <<
"s";
1124 Cout <<
". Progress: " << (percent) << finl;
1128 progress_ << (percent) << finl;
1138static bool header_complete =
false;
1139void open_dt_ev(IOS_OPEN_MODE mode)
1141 if (!dt_ev_.is_open())
1144 dt_ev_.ouvrir(fichier, mode);
1145 dt_ev_.setf(ios::scientific);
1157 if ((
nb_pas_dt_ == 0) && ((stat(fichier, &f)) || !(
pb_base().reprise_effectuee() == 1)))
1161 open_dt_ev(ios::out);
1162 dt_ev_ <<
"# temps\t\t dt\t\t facsec\t\t residu=max|Ri|\t dt_stab\t ";
1164 open_dt_ev(ios::app);
1171 open_dt_ev(ios::app);
1176 open_dt_ev(ios::app);
1181 header_complete =
true;
1196 if (header_complete) dt_ev_ << finl;
1198 header_complete =
false;
DoubleTab & futur(int i=1) override
Returns field values at instant t+i.
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
class Equation_base The role of an equation is the calculation of one or more fields....
virtual int equation_non_resolue() const
void set_residuals(const DoubleTab &residual)
Solveur_Masse_base & solv_masse()
Returns the mass solver associated with the equation.
virtual const Champ_Inc_base & inconnue() const =0
DoubleVect & get_residu()
virtual void abortTimeStep()
Reinitialize what must be.
virtual void imprime_residu(SFichier &)
virtual DoubleTab & derivee_en_temps_inco(DoubleTab &)
Returns the time derivative of the unknown I of the equation: dI/dt = M-1*(sum(operators(I) + sources...
DoubleVect & residu_initial()
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
int disable_equation_residual() const
Domaine_dis_base & domaine_dis()
Returns the discretized domain associated with the equation.
virtual Nom expression_residu()
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
Matrice_Base class - Base class of the matrix hierarchy.
A character string (Nom) in uppercase.
An array of Motcle objects.
int search(const Motcle &t) const
class Nom: a character string for naming TRUST objects.
Base class for TRUST objects (Objet_U).
const Nom & que_suis_je() const
Returns the string identifying the class.
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Helper class to factorize the readOn method of Objet_U classes.
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
class Probleme_base It is a Probleme_U that is not a coupling.
int postraiter(int force=1) override
If force=1, performs post-processing regardless of the post-processing frequencies.
void sauver() const override
Writes to file for restart (backup).
virtual double calculer_pas_de_temps() const
Computes the value of the next time step for the problem.
virtual void mettre_a_jour(double temps)
Performs a time update of the problem.
const Schema_Temps_base & schema_temps() const
Returns the time scheme associated with the problem.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
static int node_master()
Returns 1 if on the NUMA node master processor, 0 otherwise.
static void imprimer_ram_totale(int all_process=0)
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
int seuil_statio_relatif_deconseille_
Flag to specify whether seuil_statio_ is an absolute (default) or relative value.
virtual Entree & lire_periode_sauvegarde_securite_en_heures(Entree &)
int precision_impr_
Number of significant digits for output.
int limpr() const
Returns 1 if there is a need to perform a print (cf dt_impr) Returns 0 otherwise.
virtual double computeTimeStep(bool &stop) const
int & set_stationnaire_atteint()
bool ind_nb_pas_dt_max_atteint
virtual bool isStationary() const
Returns 1 if during the last time step, the problem has not evolved.
double temps_courant() const
Returns the current time.
virtual void resetTime(double time)
Nom dt_max_str_
setting of dt_max as a function of time
virtual bool corriger_dt_calcule(double &dt) const
Corrects the computed time step passed as parameter and verifies it is not "too" small (< dt_min_).
int sauvegarder(Sortie &) const override
Saves the current time and the number of time steps to an output stream.
int nb_pas_dt_max_atteint() const
Returns 1 if (the number of time steps >= maximum number of time steps).
Parser_U dt_max_fn_
Associated Parser_U.
virtual void set_param(Param &titi) const override
int nb_sauv_
how many checkpoints have we performed so far?
double dt_
Computation time step.
virtual void ajouter_inertie(Matrice_Base &mat_morse, DoubleTab &secmem, const Equation_base &eqn) const
bool disable_progress() const
double dt_failed_
Value of a time step if it failed.
int no_error_if_not_converged_diff_impl_
virtual void associer_pb(const Probleme_base &)
void write_dt_ev(bool init)
double temps_max() const
Returns a reference to the maximum time.
double dt_max_
Maximum time step set by the user.
double mode_dt_start_
Mode for computing the initial time step - contains a double if dt_init option is used.
virtual void abortTimeStep()
double periode_cpu_sans_sauvegarde_
Default 23 hours;.
bool ind_tps_final_atteint
double limite_cpu_sans_sauvegarde_
Default 23 hours;.
int temps_final_atteint() const
Returns 1 if the final time has been reached (or exceeded).
virtual int stop() const
Returns 1 if it is necessary to stop the computation for various reasons:
Probleme_base & pb_base()
bool disable_dt_ev() const
virtual void validateTimeStep()
void imprimer_temps_courant(SFichier &) const
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
virtual int impr(Sortie &os) const
Prints the time step number, the time step value, and the current time.
int niter_max_diff_impl_
Maximum iterations for CG diffusion implicitation - Above 1000 iterations, diffusion implicit algorit...
virtual void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const Equation_base &eqn, const tabs_t &semi_impl={}) const
double pas_de_temps() const
Returns the current time step (delta_t).
int no_conv_subiteration_diff_impl_
virtual void imprimer(Sortie &os) const
Prints the time step to an output stream if appropriate.
virtual void initialize()
virtual bool initTimeStep(double dt)
virtual Entree & lire_residuals(Entree &)
int nb_sauv_max_
Max number of checkpoints that will be performed (useful for PDI backup file).
virtual int faire_un_pas_de_temps_eqn_base(Equation_base &)=0
int nb_pas_dt() const
Returns the number of time steps performed.
double dt_impr_
Output time interval.
int stop_lu() const
Returns 1 if the .stop file contains a 1, returns 0 otherwise.
double dt_min_
Minimum time step set by the user.
int reprendre(Entree &) override
Restarts (reads) the current time and the number of time steps performed from an input stream.
virtual bool iterateTimeStep(bool &converged)
Calculate the U(n+1) unknown for each equation (if solved) of the problem with the selected time sche...
virtual int mettre_a_jour()
Updates the current time (t+=dt) and the number of time steps performed (nb_pas_dt_++).
double dt_stab_
Stability time step.
virtual Entree & lire_temps_cpu_max(Entree &)
virtual void mettre_a_jour_dt_stab()
int temps_cpu_max_atteint() const
virtual Entree & lire_nb_pas_dt_max(Entree &)
Reads the maximum number of time steps.
int nb_pas_dt_max() const
Returns a reference to the maximum number of time steps.
double seuil_diff_impl_
Threshold for implicit treatment of diffusion by CG.
void update_critere_statio(const DoubleTab &tab_critere, Equation_base &equation)
Updates stationnaire_atteint_ and residu_ (criterion: residu_ < seuil_statio_).
bool ind_temps_cpu_max_atteint
void write_progress(bool init)
Writes the .progress file (estimated remaining CPU time).
void finir() const
Closes the .dt_ev file.
virtual Matrice_Base & ajouter_masse(double dt, Matrice_Base &matrice, int penalisation=1) const
virtual void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, double dt, const tabs_t &semi_impl, int resoudre_en_increments) const
virtual int get_precision()
void precision(int pre) override
Base class for output streams.
_SIZE_ size_array() const
TRUST_2_PDI Encapsulation of PDI methods (library used for IO operations). See the website pdi....
void stop_sharing_last_variable()
static int is_PDI_checkpoint()
void TRUST_start_sharing(const std::string &name, const void *data)
void trigger(const std::string &event)