124 void write_formatted(
const double&, ostream& ) ;
125 void write_formatted(
const Tbl&, ostream& ) ;
133 template<
typename TyT>
135 double initial_time,
int size_i)
139 step =
new int[size] ;
140 step[0] = initial_step ;
141 for (
int j=1; j<size; j++) {
142 step[j] = UNDEF_STEP ;
145 the_time =
new double[size] ;
146 the_time[0] = initial_time ;
147 for (
int j=1; j<size; j++) {
148 the_time[j] = -1e20 ;
151 val =
new TyT*[size] ;
152 val[0] =
new TyT(initial_value) ;
153 for (
int j=1; j<size; j++) {
160 template<
typename TyT>
165 step =
new int[size] ;
166 for (
int j=0; j<size; j++) {
167 step[j] = UNDEF_STEP ;
170 the_time =
new double[size] ;
171 for (
int j=0; j<size; j++) {
172 the_time[j] = -1e20 ;
175 val =
new TyT*[size] ;
176 for (
int j=0; j<size; j++) {
184 template<
typename TyT>
187 pos_jtop(evo.pos_jtop) {
189 step =
new int[size] ;
190 for (
int j=0; j<size; j++) {
191 step[j] = evo.
step[j] ;
194 the_time =
new double[size] ;
195 for (
int j=0; j<size; j++) {
199 val =
new TyT*[size] ;
200 for (
int j=0; j<size; j++) {
201 if (evo.
val[j] != 0x0) {
202 val[j] =
new TyT( *(evo.
val[j]) ) ;
220 template<
typename TyT>
226 for (
int j=0; j<size; j++) {
227 if (val[j] != 0x0)
delete val[j] ;
241 template<
typename TyT>
244 cerr <<
"void Evolution<TyT>::operator= : not implemented yet ! \n" ;
250 template<
typename TyT>
253 if ( !(is_known(j)) ) return ;
256 int pos = position(j) ;
258 assert( val[pos] != 0x0) ;
262 step[pos] = UNDEF_STEP ;
263 the_time[pos] = -1e20 ;
265 if (pos == pos_jtop) {
267 while ( (pos_jtop>=0) && (val[pos_jtop] == 0x0) ) pos_jtop-- ;
279 template<
typename TyT>
282 assert(pos_jtop >= 0) ;
283 int jmax = step[pos_jtop] ;
285 if (j == jmax)
return pos_jtop ;
289 if ( (j>=step[0]) && (j<jmax) ) {
291 for (
int i=pos_jtop-1; i>=0; i--) {
300 cerr <<
"Evolution<TyT>::position: time step j = " <<
301 j <<
" not found !" << endl ;
308 template<
typename TyT>
311 assert( (j>=0) && (j<=pos_jtop) ) ;
312 assert( step[j] != UNDEF_STEP ) ;
316 while ( (n_pos == -1) && ( j < pos_jtop ) ) {
319 if (step[j] != UNDEF_STEP) n_pos = j ;
324 template<
typename TyT>
327 assert( (j>=0) && (j<=pos_jtop) ) ;
328 assert( step[j] != UNDEF_STEP ) ;
332 while ( (n_pos == -1) && ( j > 0 ) ) {
335 if (step[j] != UNDEF_STEP) n_pos = j ;
341 template<
typename TyT>
344 if (pos_jtop == -1)
return false ;
346 assert(pos_jtop >= 0) ;
348 int jmax = step[pos_jtop] ;
351 return ( val[pos_jtop] != 0x0 ) ;
354 if ( (j>=step[0]) && (j<jmax) ) {
356 for (
int i=pos_jtop-1; i>=0; i--) {
358 if (step[i] == j)
return ( val[i] != 0x0 ) ;
366 template<
typename TyT>
369 TyT* pval = val[position(j)] ;
370 assert(pval != 0x0) ;
376 template<
typename TyT>
379 int imin = position( j_min() ) ;
381 if ( ( t < the_time[ imin ] ) || ( t > the_time[pos_jtop] ) ) {
382 cerr <<
"Evolution<TyT>::operator()(double t, int order) : \n" 383 <<
"Requested time outside stored range!" << endl ;
386 assert ( order <= 2 ) ;
387 assert ( pos_jtop >= order ) ;
391 while ((the_time[j0] < t) && ( j0 < pos_jtop )) {
392 j0 = next_position(j0) ;
407 int j1 = ( (j0 > imin) ? previous_position(j0) : next_position(j0) ) ;
410 double x0 = the_time[j1] - t ;
411 double x1 = the_time[j0] - t ;
412 double dx = the_time[j0] - the_time[j1] ;
414 double a0 = x1 / dx ;
415 double a1 = x0 / dx ;
417 return (a0*(*val[j0]) - a1*(*val[j1])) ;
424 int j1 = ( (j0 == imin) ? next_position(j0) : previous_position(j0) ) ;
429 j2 = next_position(j1) ;
432 j2 = next_position(j0) ;
434 j2 = previous_position(j1) ;
438 double x0 = t - the_time[j0] ;
439 double x1 = t - the_time[j1] ;
440 double dx = the_time[j0] - the_time[j1] ;
442 double x2 = t - the_time[j2] ;
444 double dx0 = the_time[j1] - the_time[j2] ;
445 double dx1 = the_time[j0] - the_time[j2] ;
448 double a0 = ( x2*x1 ) / ( dx2*dx1 ) ;
449 double a1 = ( x0*x2 ) / ( dx0*dx2 ) ;
450 double a2 = ( x0*x1 ) / ( dx0*dx1 ) ;
452 return ( a0*(*val[j0]) - a1*(*val[j1]) + a2*(*val[j2]) ) ;
458 cerr <<
" Evolution<TyT>::operator()(double t, int order) : \n" << endl ;
459 cerr <<
" The case order = " << order <<
" is not implemented!" << endl ;
469 template<
typename TyT>
472 if ( t < the_time[pos_jtop] ) {
473 cerr <<
"Evolution<TyT>::extrapolate(double t, int order) : \n" 474 <<
"Requested time is inside stored range..." << endl ;
477 assert ( pos_jtop >= order ) ;
482 return *val[pos_jtop];
487 int j0 = UNDEF_STEP ;
488 for (
int i=pos_jtop-1; i>=0; i--) {
489 if (step[i] != UNDEF_STEP) {
494 assert(j0 != UNDEF_STEP) ;
497 double fac = (t - the_time[j0]) / (the_time[j1] - the_time[j0]) ;
498 return fac*(*val[j1]) + (1. - fac)*(*val[j0]) ;
504 int j1 = UNDEF_STEP ;
505 for (
int i=j2-1; i>=0; i--) {
506 if (step[i] != UNDEF_STEP) {
511 assert(j1 != UNDEF_STEP) ;
512 int j0 = UNDEF_STEP ;
513 for (
int i=j1-1; i>=0; i--) {
514 if (step[i] != UNDEF_STEP) {
519 assert(j0 != UNDEF_STEP) ;
521 double t0 = the_time[j0] ;
522 double t1 = the_time[j1] ;
523 double t2 = the_time[j2] ;
524 double t01 = t0 - t1 ;
525 double t02 = t0 - t2 ;
526 double t12 = t1 - t2 ;
528 return ((t - t1)*(t - t2)/(t01*t02))*(*val[j0])
529 - ((t - t0)*(t - t2)/(t01*t12))*(*val[j1])
530 + ((t - t0)*(t - t1)/(t02*t12))*(*val[j2]) ;
535 cerr <<
" Evolution<TyT>::extrapolate(double t, int order) : \n" << endl ;
536 cerr <<
" The case order = " << order <<
" is not implemented!" << endl ;
542 return *val[pos_jtop] ;
547 template<
typename TyT>
550 int resu = UNDEF_STEP ;
551 for (
int i=0; i<=pos_jtop; i++) {
552 if (step[i] != UNDEF_STEP) {
558 if (resu == UNDEF_STEP) {
559 cerr <<
"Evolution<TyT>::j_min() : no valid time step found !" << endl ;
566 template<
typename TyT>
569 if (pos_jtop == -1) {
570 cerr <<
"Evolution<TyT>::j_max() : no valid time step found !" << endl ;
574 assert(pos_jtop >=0) ;
575 int jmax = step[pos_jtop] ;
576 assert(jmax != UNDEF_STEP) ;
588 template<
typename TyT>
592 TyT resu (
operator[](j) ) ;
601 int pos = position(j) ;
603 assert ( step[pos-1] != UNDEF_STEP ) ;
609 double dt = the_time[pos] - the_time[pos-1] ;
611 return ( (*val[pos]) - (*val[pos-1]) ) / dt ;
618 assert ( step[pos-2] != UNDEF_STEP ) ;
619 double dt = the_time[pos] - the_time[pos-1] ;
621 double dt2 = the_time[pos-1] - the_time[pos-2] ;
622 if (fabs(dt2 -dt) > 1.e-13) {
624 "Evolution<TyT>::time_derive: the current version is" 625 <<
" valid only for \n" 626 <<
" a constant time step !" << endl ;
630 return ( 1.5* (*val[pos]) - 2.* (*val[pos-1]) + 0.5* (*val[pos-2]) ) / dt ;
637 assert ( step[pos-2] != UNDEF_STEP ) ;
638 assert ( step[pos-3] != UNDEF_STEP ) ;
639 double dt = the_time[pos] - the_time[pos-1] ;
641 double dt2 = the_time[pos-1] - the_time[pos-2] ;
642 double dt3 = the_time[pos-2] - the_time[pos-3] ;
643 if ((fabs(dt2 -dt) > 1.e-13)||(fabs(dt3 -dt2) > 1.e-13)) {
645 "Evolution<TyT>::time_derive: the current version is valid only for \n" 646 <<
" a constant time step !" << endl ;
650 return ( 11.*(*val[pos]) - 18.*(*val[pos-1]) + 9.*(*val[pos-2])
651 - 2.*(*val[pos-3])) / (6.*dt) ;
655 cerr <<
"Evolution<TyT>::time_derive: the case n = " << n
656 <<
" is not implemented !" << endl ;
663 return operator[](j) ;
673 template<
typename TyT>
676 ofstream fich(filename) ;
678 time_t temps = time(0x0) ;
680 fich <<
"# " << filename <<
" " << ctime(&temps) ;
681 fich <<
"# " << size <<
" size" <<
'\n' ;
682 fich <<
"# " << pos_jtop <<
" pos_jtop" <<
'\n' ;
683 fich <<
"# t value... \n" ;
686 fich.setf(ios::scientific) ;
688 for (
int i=0; i<=pos_jtop; i++) {
689 if (step[i] != UNDEF_STEP) {
690 fich << the_time[i] ; fich.width(23) ;
691 assert(val[i] != 0x0) ;
692 write_formatted(*(val[i]), fich) ;
TyT ** val
Array of pointers onto the values (size = size).
Evolution(const TyT &initial_value, int initial_j, double initial_time, int initial_size)
Constructor from some initial value.
int * step
Array of time step indices (size = size).
double * the_time
Array of values of t at the various time steps (size = size).