This file is indexed.

/usr/include/lorene/C++/Include/Template/evolution.C is in liblorene-dev 0.0.0~cvs20161116+dfsg-1ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/*
 *  Methods of template class Evolution
 *
 *    (see file evolution.h for documentation).
 *
 */

/*
 *   Copyright (c) 2004  Eric Gourgoulhon & Jerome Novak
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License version 2
 *   as published by the Free Software Foundation.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 * $Id: evolution.C,v 1.18 2014/10/13 08:52:38 j_novak Exp $
 * $Log: evolution.C,v $
 * Revision 1.18  2014/10/13 08:52:38  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.17  2014/03/27 16:59:41  j_novak
 * Added methods next_position(int) and previous_position(int). Changed (corrected + simplified) the interpolation method.
 *
 * Revision 1.16  2013/07/19 15:50:24  j_novak
 * Implementation of the interpolation function for Evolution, with order=0, 1 or 2.
 *
 * Revision 1.15  2008/09/19 13:24:29  j_novak
 * Added the third-order scheme for the time derivativre computation.
 *
 * Revision 1.14  2004/05/14 08:51:01  p_grandclement
 * *** empty log message ***
 *
 * Revision 1.13  2004/05/14 08:41:05  e_gourgoulhon
 * Added declaration "class Tbl ;" before the declarations of
 * write_formatted.
 *
 * Revision 1.12  2004/05/13 21:30:32  e_gourgoulhon
 * Use of function write_formatted in method save( ).
 *
 * Revision 1.11  2004/05/11 20:12:49  e_gourgoulhon
 * Added methods j_min, j_max and save.
 *
 * Revision 1.10  2004/05/03 15:23:22  e_gourgoulhon
 * Method downdate: changed the order of conditions (pos_jtop>=0)
 * and (val[pos_jtop] == 0x0) in the while(...) test.
 *
 * Revision 1.9  2004/03/31 20:24:04  e_gourgoulhon
 * Method time_derive: result object created by the copy constructor of
 * class TyT, since the arithmetics may not return an object of exactly
 * class TyT.
 *
 * Revision 1.8  2004/03/26 13:31:09  j_novak
 * Definition of the macro UNDEF_STEP for non-defined time-steps.
 * Changes in the way the time derivative is calculated.
 *
 * Revision 1.7  2004/03/26 08:22:13  e_gourgoulhon
 * *** Full reorganization of class Evolution ***
 * Introduction of the notion of absoluteuniversal time steps,
 * stored in the new array 'step'.
 * The new function position(int j) makes a correspondence
 * between a universal time step j and the position in the
 * arrays step, the_time and val.
 * Only method update is now virtual.
 * Methods operator[], position, is_known, downdate belong to
 * the base class.
 *
 * Revision 1.6  2004/03/24 14:55:47  e_gourgoulhon
 * Added method last_value().
 *
 * Revision 1.5  2004/03/23 14:50:41  e_gourgoulhon
 * Added methods is_updated, downdate, get_jlast, get_size,
 * as well as constructors without any initial value.
 * Formatted documentation for Doxygen.
 *
 * Revision 1.4  2004/03/06 21:13:15  e_gourgoulhon
 * Added time derivation (method time_derive).
 *
 * Revision 1.3  2004/02/17 22:13:34  e_gourgoulhon
 * Suppressed declaration of global char[] evolution_C = ...
 *
 * Revision 1.2  2004/02/15 21:55:33  e_gourgoulhon
 * Introduced derived classes Evolution_full and Evolution_std.
 * Evolution is now an abstract base class.
 *
 * Revision 1.1  2004/02/13 15:53:20  e_gourgoulhon
 * New (template) class for time evolution.
 *
 *
 * $Header: /cvsroot/Lorene/C++/Include/Template/evolution.C,v 1.18 2014/10/13 08:52:38 j_novak Exp $
 *
 */

// C++ headers
#include "headcpp.h" 

// C headers
#include <cstdlib>
#include <cassert>
#include <cmath>

namespace Lorene {
class Tbl ;

void write_formatted(const double&, ostream& ) ; 
void write_formatted(const Tbl&, ostream& ) ; 


                    //-------------------------//
                    //      Constructors       //
                    //-------------------------//

                    
template<typename TyT> 
Evolution<TyT>::Evolution(const TyT& initial_value, int initial_step,
                          double initial_time, int size_i)
      : size(size_i),
        pos_jtop(0) {

    step = new int[size] ; 
    step[0] = initial_step ; 
    for (int j=1; j<size; j++) {
        step[j] = UNDEF_STEP ; 
    }
    
    the_time = new double[size] ; 
    the_time[0] = initial_time ; 
    for (int j=1; j<size; j++) {
        the_time[j] = -1e20 ; 
    }
    
    val = new TyT*[size] ; 
    val[0] = new TyT(initial_value) ; 
    for (int j=1; j<size; j++) {
        val[j] = 0x0 ; 
    }
        
}                    

                    
template<typename TyT> 
Evolution<TyT>::Evolution(int size_i)
      : size(size_i),
        pos_jtop(-1) {

    step = new int[size] ; 
    for (int j=0; j<size; j++) {
        step[j] = UNDEF_STEP ; 
    }
    
    the_time = new double[size] ; 
    for (int j=0; j<size; j++) {
        the_time[j] = -1e20 ; 
    }
    
    val = new TyT*[size] ; 
    for (int j=0; j<size; j++) {
        val[j] = 0x0 ; 
    }    
    
}                    
                    


template<typename TyT> 
Evolution<TyT>::Evolution(const Evolution<TyT>& evo)
      : size(evo.size),
        pos_jtop(evo.pos_jtop) {

    step = new int[size] ; 
    for (int j=0; j<size; j++) {
        step[j] = evo.step[j] ; 
    }
    
    the_time = new double[size] ; 
    for (int j=0; j<size; j++) {
        the_time[j] = evo.the_time[j] ; 
    }
    
    val = new TyT*[size] ; 
    for (int j=0; j<size; j++) {
        if (evo.val[j] != 0x0) {
            val[j] = new TyT( *(evo.val[j]) ) ; 
        }
        else {
            val[j] = 0x0 ; 
        }
    }
    
    
}                    
                    

                    
                    
                    //-----------------------//
                    //      Destructor       //
                    //-----------------------//

                    
template<typename TyT> 
Evolution<TyT>::~Evolution(){

    delete [] step ; 
    delete [] the_time ; 

    for (int j=0; j<size; j++) {
        if (val[j] != 0x0) delete val[j] ; 
    }
    
    delete [] val ;
    
}
                    
                    

                    //-----------------------//
                    //      Mutators         //
                    //-----------------------//

                    
template<typename TyT> 
void Evolution<TyT>::operator=(const Evolution<TyT>& ) {

    cerr << "void Evolution<TyT>::operator= : not implemented yet ! \n" ; 
    abort() ; 

}


template<typename TyT> 
void Evolution<TyT>::downdate(int j) {

    if ( !(is_known(j)) ) return ;  // a never updated step cannot
                                    // be downdated
    
    int pos = position(j) ; 
    
    assert( val[pos] != 0x0) ; 

    delete val[pos] ; 
    val[pos] = 0x0 ; 
    step[pos] = UNDEF_STEP ; 
    the_time[pos] = -1e20 ; 

    if (pos == pos_jtop) {  // pos_jtop must be decreased
        pos_jtop-- ; 
        while ( (pos_jtop>=0) && (val[pos_jtop] == 0x0) ) pos_jtop-- ;
    }
    
}


                    
                    
                        //------------//
                        // Accessors  //
                        //------------//

template<typename TyT> 
int Evolution<TyT>::position(int j) const {
    
    assert(pos_jtop >= 0) ; 
    int jmax = step[pos_jtop] ; 
    
    if (j == jmax) return pos_jtop ;   // for efficiency purpose
    
    int pos = - 1 ; 

    if ( (j>=step[0]) && (j<jmax) ) {

        for (int i=pos_jtop-1; i>=0; i--) {  // cas i=pos_jtop treated above
            if (step[i] == j) {
                pos = i ;
                break ; 
            }
        }
    }
    
    if (pos == -1) {
        cerr << "Evolution<TyT>::position: time step j = " <<
            j << " not found !" << endl ; 
        abort() ; 
    }
    
    return pos ; 
}
   
template<typename TyT> 
int Evolution<TyT>::next_position(int j) const {

  assert( (j>=0) && (j<=pos_jtop) ) ;
  assert( step[j] != UNDEF_STEP ) ;

  int n_pos = -1 ;

  while ( (n_pos == -1) && ( j < pos_jtop ) ) {
    
    j++ ;
    if (step[j] != UNDEF_STEP) n_pos = j ;
  }
  return n_pos ;
}

template<typename TyT> 
int Evolution<TyT>::previous_position(int j) const {              
                    
  assert( (j>=0) && (j<=pos_jtop) ) ;
  assert( step[j] != UNDEF_STEP ) ;

  int n_pos = -1 ;

  while ( (n_pos == -1) && ( j > 0 ) ) {
    
    j-- ;
    if (step[j] != UNDEF_STEP) n_pos = j ;
  }
  return n_pos ;
}


template<typename TyT> 
bool Evolution<TyT>::is_known(int j) const {

    if (pos_jtop == -1) return false ; 
    
    assert(pos_jtop >= 0) ; 
    
    int jmax = step[pos_jtop] ; 
    
    if (j == jmax) {
        return ( val[pos_jtop] != 0x0 ) ; 
    }

    if ( (j>=step[0]) && (j<jmax) ) {

        for (int i=pos_jtop-1; i>=0; i--) {  // cas i=pos_jtop treated above

            if (step[i] == j) return ( val[i] != 0x0 ) ; 
        }
    }
    
    return false ; 
}                  
                    

template<typename TyT> 
const TyT& Evolution<TyT>::operator[](int j) const {

    TyT* pval = val[position(j)] ; 
    assert(pval != 0x0) ; 
    return *pval ; 

}


template<typename TyT> 
TyT Evolution<TyT>::operator()(double t, int order) const {

  int imin = position( j_min() ) ;

  if ( ( t < the_time[ imin ] ) || ( t > the_time[pos_jtop] ) ) {
    cerr << "Evolution<TyT>::operator()(double t, int order) : \n"
	 << "Requested time outside stored range!" << endl ;
    abort() ;
  }
  assert ( order <= 2 ) ;
  assert ( pos_jtop > order ) ;

  int j0 = imin ;

  while ((the_time[j0] < t) && ( j0 < pos_jtop )) {
    j0 = next_position(j0) ;
    assert( j0 != -1 ) ;
  }

  switch (order) {

  case 0: {

    return (*val[j0]) ;

    break ;
  }
    
  case 1: {
    
    int j1 = ( (j0 > imin) ? previous_position(j0) : next_position(j0) ) ;
    assert( j1 != -1) ;

    double x0 = the_time[j1] - t ;
    double x1 = the_time[j0] - t ;
    double dx = the_time[j0] - the_time[j1] ;
    
    double a0 = x1 / dx ;
    double a1 = x0 / dx ;

    return (a0*(*val[j0]) - a1*(*val[j1])) ;

    break ;
  }

  case 2: {

    int j1 = ( (j0 == imin) ? next_position(j0) : previous_position(j0) ) ;
    assert( j1 != -1) ;

    int j2 = -1 ;
    if (j0 == imin) 
      j2 = next_position(j1) ;
    else {
      if (j1 == imin) 
	j2 = next_position(j0) ;
      else
	j2 = previous_position(j1) ;
    }
    assert (j2 != -1 ) ;

    double x0 = t - the_time[j0] ;
    double x1 = t - the_time[j1] ;
    double dx = the_time[j0] - the_time[j1] ;
    
    double x2 = t - the_time[j2] ;

    double dx0 = the_time[j1] - the_time[j2] ;
    double dx1 = the_time[j0] - the_time[j2] ;
    double dx2 = dx ;

    double a0 = ( x2*x1 ) / ( dx2*dx1 ) ;
    double a1 = ( x0*x2 ) / ( dx0*dx2 ) ;
    double a2 = ( x0*x1 ) / ( dx0*dx1 ) ;

    return ( a0*(*val[j0]) - a1*(*val[j1]) + a2*(*val[j2]) ) ;

    break ;
  }

  default: {
    cerr << " Evolution<TyT>::operator()(double t, int order) : \n" << endl ;
    cerr << " The case order = " << order << " is not implemented!" << endl ;
    abort() ;
    break ;
  }
  }

  return *val[j0] ;

}                  
 
template<typename TyT> 
int Evolution<TyT>::j_min() const {

    int resu = UNDEF_STEP ; 
    for (int i=0; i<=pos_jtop; i++) {
        if (step[i] != UNDEF_STEP) {
            resu = step[i] ; 
            break ; 
        }
    }
    
    if (resu == UNDEF_STEP) {
        cerr << "Evolution<TyT>::j_min() : no valid time step found !" << endl ; 
        abort() ; 
    }
    
    return resu ; 
}

template<typename TyT> 
int Evolution<TyT>::j_max() const {
    
    if (pos_jtop == -1) {
        cerr << "Evolution<TyT>::j_max() : no valid time step found !" << endl ; 
        abort() ; 
    }
    
    assert(pos_jtop >=0) ; 
    int jmax = step[pos_jtop] ; 
    assert(jmax != UNDEF_STEP) ; 
    return jmax ; 
}





                    //-----------------------//
                    //   Time derivative     //
                    //-----------------------//

template<typename TyT> 
TyT Evolution<TyT>::time_derive(int j, int n) const {

  if (n == 0) { 
    TyT resu ( operator[](j) ) ;
    resu = 0 * resu ;

    return resu ;

  }
  
  else { 
    
    int pos = position(j) ;
    assert ( pos > 0 ) ;
    assert ( step[pos-1] != UNDEF_STEP ) ;

    switch (n) {
    
        case 1 : {

            double dt = the_time[pos] - the_time[pos-1] ; 

            return ( (*val[pos]) - (*val[pos-1]) ) / dt  ;
            break ;
        } 
           
        case 2 : {
	  
	  assert ( pos > 1 ) ;
	  assert ( step[pos-2] != UNDEF_STEP ) ;
	  double dt = the_time[pos] - the_time[pos-1] ;
#ifndef NDEBUG
	  double dt2 = the_time[pos-1] - the_time[pos-2] ;
	  if (fabs(dt2 -dt) > 1.e-13) {
	      cerr << 
		  "Evolution<TyT>::time_derive: the current version is"
		   << " valid only for \n"
		   << " a constant time step !" << endl ; 
	      abort() ;
	  }
#endif
	  return ( 1.5* (*val[pos]) - 2.* (*val[pos-1]) + 0.5* (*val[pos-2]) ) / dt ;  
	  break ;
        } 
	    
        case 3 : {
	    
	    assert ( pos > 2 ) ;
	    assert ( step[pos-2] != UNDEF_STEP ) ;
	    assert ( step[pos-3] != UNDEF_STEP ) ;
	    double dt = the_time[pos] - the_time[pos-1] ;
#ifndef NDEBUG
	    double dt2 = the_time[pos-1] - the_time[pos-2] ;
	    double dt3 = the_time[pos-2] - the_time[pos-3] ;
            if ((fabs(dt2 -dt) > 1.e-13)||(fabs(dt3 -dt2) > 1.e-13)) {
                cerr << 
  "Evolution<TyT>::time_derive: the current version is  valid only for \n"
    << " a constant time step !" << endl ; 
                abort() ;
            }
#endif
	    return ( 11.*(*val[pos]) - 18.*(*val[pos-1]) + 9.*(*val[pos-2])
		     - 2.*(*val[pos-3])) / (6.*dt) ;
	    break ;
	}
        default : {
            cerr << "Evolution<TyT>::time_derive: the case n = " << n 
                 << "  is not implemented !" << endl ; 
            abort() ;
            break ;
        }    
    }

  }
  return operator[](j) ;
}                    
 
                   

                    //-----------------------//
                    //        Outputs        //
                    //-----------------------//

                   
template<typename TyT> 
void Evolution<TyT>::save(const char* filename) const {

    ofstream fich(filename) ; 

    time_t temps = time(0x0) ; 
    
    fich << "# " << filename << "    " << ctime(&temps) ; 
    fich << "# " << size << "  size" << '\n' ; 
    fich << "# " << pos_jtop << "  pos_jtop" << '\n' ; 
    fich << "#         t                  value...                   \n" ; 
    
    fich.precision(14) ; 
    fich.setf(ios::scientific) ; 
    fich.width(20) ; 
    for (int i=0; i<=pos_jtop; i++) {
        if (step[i] != UNDEF_STEP) {
            fich << the_time[i] ; fich.width(23) ; 
            assert(val[i] != 0x0) ;
            write_formatted(*(val[i]), fich) ;  
            fich << '\n' ; 
        }
    }
        
    fich.close() ; 
}


















}