117void write_formatted(
const double&, ostream& ) ;
118void write_formatted(
const Tbl&, ostream& ) ;
126template<
typename TyT>
128 double initial_time,
int size_i)
133 step[0] = initial_step ;
134 for (
int j=1; j<
size; j++) {
135 step[j] = UNDEF_STEP ;
140 for (
int j=1; j<
size; j++) {
145 val[0] =
new TyT(initial_value) ;
146 for (
int j=1; j<
size; j++) {
153template<
typename TyT>
159 for (
int j=0; j<
size; j++) {
160 step[j] = UNDEF_STEP ;
164 for (
int j=0; j<
size; j++) {
169 for (
int j=0; j<
size; j++) {
177template<
typename TyT>
183 for (
int j=0; j<
size; j++) {
188 for (
int j=0; j<
size; j++) {
193 for (
int j=0; j<
size; j++) {
194 if (evo.
val[j] != 0x0) {
195 val[j] =
new TyT( *(evo.
val[j]) ) ;
213template<
typename TyT>
219 for (
int j=0; j<
size; j++) {
220 if (
val[j] != 0x0)
delete val[j] ;
234template<
typename TyT>
237 cerr <<
"void Evolution<TyT>::operator= : not implemented yet ! \n" ;
243template<
typename TyT>
251 assert(
val[pos] != 0x0) ;
255 step[pos] = UNDEF_STEP ;
272template<
typename TyT>
282 if ( (j>=
step[0]) && (j<jmax) ) {
293 cerr <<
"Evolution<TyT>::position: time step j = " <<
294 j <<
" not found !" << endl ;
301template<
typename TyT>
305 assert(
step[j] != UNDEF_STEP ) ;
309 while ( (n_pos == -1) && ( j <
pos_jtop ) ) {
312 if (
step[j] != UNDEF_STEP) n_pos = j ;
317template<
typename TyT>
321 assert(
step[j] != UNDEF_STEP ) ;
325 while ( (n_pos == -1) && ( j > 0 ) ) {
328 if (
step[j] != UNDEF_STEP) n_pos = j ;
334template<
typename TyT>
347 if ( (j>=
step[0]) && (j<jmax) ) {
351 if (
step[i] == j)
return (
val[i] != 0x0 ) ;
359template<
typename TyT>
363 assert(pval != 0x0) ;
369template<
typename TyT>
375 cerr <<
"Evolution<TyT>::operator()(double t, int order) : \n"
376 <<
"Requested time outside stored range!" << endl ;
379 assert ( order <= 2 ) ;
407 double a0 = x1 / dx ;
408 double a1 = x0 / dx ;
410 return (a0*(*
val[j0]) - a1*(*
val[j1])) ;
441 double a0 = ( x2*x1 ) / ( dx2*dx1 ) ;
442 double a1 = ( x0*x2 ) / ( dx0*dx2 ) ;
443 double a2 = ( x0*x1 ) / ( dx0*dx1 ) ;
445 return ( a0*(*
val[j0]) - a1*(*
val[j1]) + a2*(*
val[j2]) ) ;
451 cerr <<
" Evolution<TyT>::operator()(double t, int order) : \n" << endl ;
452 cerr <<
" The case order = " << order <<
" is not implemented!" << endl ;
462template<
typename TyT>
465 int resu = UNDEF_STEP ;
467 if (
step[i] != UNDEF_STEP) {
473 if (resu == UNDEF_STEP) {
474 cerr <<
"Evolution<TyT>::j_min() : no valid time step found !" << endl ;
481template<
typename TyT>
485 cerr <<
"Evolution<TyT>::j_max() : no valid time step found !" << endl ;
491 assert(jmax != UNDEF_STEP) ;
503template<
typename TyT>
507 TyT resu (
operator[](j) ) ;
518 assert (
step[pos-1] != UNDEF_STEP ) ;
526 return ( (*
val[pos]) - (*
val[pos-1]) ) / dt ;
533 assert (
step[pos-2] != UNDEF_STEP ) ;
537 if (fabs(dt2 -dt) > 1.e-13) {
539 "Evolution<TyT>::time_derive: the current version is"
540 <<
" valid only for \n"
541 <<
" a constant time step !" << endl ;
545 return ( 1.5* (*
val[pos]) - 2.* (*
val[pos-1]) + 0.5* (*
val[pos-2]) ) / dt ;
552 assert (
step[pos-2] != UNDEF_STEP ) ;
553 assert (
step[pos-3] != UNDEF_STEP ) ;
558 if ((fabs(dt2 -dt) > 1.e-13)||(fabs(dt3 -dt2) > 1.e-13)) {
560 "Evolution<TyT>::time_derive: the current version is valid only for \n"
561 <<
" a constant time step !" << endl ;
565 return ( 11.*(*
val[pos]) - 18.*(*
val[pos-1]) + 9.*(*
val[pos-2])
566 - 2.*(*
val[pos-3])) / (6.*dt) ;
570 cerr <<
"Evolution<TyT>::time_derive: the case n = " << n
571 <<
" is not implemented !" << endl ;
588template<
typename TyT>
591 ofstream fich(filename) ;
593 time_t temps = time(0x0) ;
595 fich <<
"# " << filename <<
" " << ctime(&temps) ;
596 fich <<
"# " <<
size <<
" size" <<
'\n' ;
597 fich <<
"# " <<
pos_jtop <<
" pos_jtop" <<
'\n' ;
598 fich <<
"# t value... \n" ;
601 fich.setf(ios::scientific) ;
604 if (
step[i] != UNDEF_STEP) {
605 fich <<
the_time[i] ; fich.width(23) ;
606 assert(
val[i] != 0x0) ;
607 write_formatted(*(
val[i]), fich) ;
void downdate(int j)
Suppresses a stored value.
void save(const char *filename) const
Saves *this in a formatted file.
Evolution(const TyT &initial_value, int initial_j, double initial_time, int initial_size)
Constructor from some initial value.
const TyT & operator[](int j) const
Returns the value at time step j.
int j_max() const
Returns the larger time step j stored in *this.
int next_position(int i) const
Returns the next valid position (returns -1 if none is found).
TyT time_derive(int j, int n=2) const
Computes the time derivative at time step j by means of a n-th order scheme, from the values at steps...
TyT ** val
Array of pointers onto the values (size = size).
TyT operator()(double t, int order=2) const
Returns the value at time t, with a scheme of order order.
int size
Maximum number of stored time steps.
virtual ~Evolution()
Destructor.
int * step
Array of time step indices (size = size).
int pos_jtop
Position in the arrays step, the_time and val of the most evolved time step.
int j_min() const
Returns the smaller time step j stored in *this.
double * the_time
Array of values of t at the various time steps (size = size).
int position(int j) const
bool is_known(int j) const
Checks whether the value a given time step has been set.
virtual void operator=(const Evolution< TyT > &t_in)
Assignement.
int previous_position(int i) const
Returns the previous valid position (returns -1 if none is found).