LORENE
evolution.h
1/*
2 * Definition of Lorene template classes Evolution, Evolution_full
3 * and Evolution_std
4 *
5 */
6
7/*
8 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28#ifndef __EVOLUTION_H_
29#define __EVOLUTION_H_
30
31/*
32 * $Id: evolution.h,v 1.15 2014/10/13 08:52:34 j_novak Exp $
33 * $Log: evolution.h,v $
34 * Revision 1.15 2014/10/13 08:52:34 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.14 2014/03/27 16:59:41 j_novak
38 * Added methods next_position(int) and previous_position(int). Changed (corrected + simplified) the interpolation method.
39 *
40 * Revision 1.13 2013/07/19 15:50:24 j_novak
41 * Implementation of the interpolation function for Evolution, with order=0, 1 or 2.
42 *
43 * Revision 1.12 2004/11/26 09:28:50 p_grandclement
44 * using in Derived templates are now public
45 *
46 * Revision 1.11 2004/11/25 07:53:53 e_gourgoulhon
47 * Added directives
48 * using Evolution<TyT>::...
49 * to comply with g++ 3.4.
50 *
51 * Revision 1.10 2004/05/11 20:11:49 e_gourgoulhon
52 * Class Evolution:
53 * -- suppressed method get_jtop()
54 * -- added methods j_min(), j_max() and save().
55 *
56 * Revision 1.9 2004/03/26 13:31:08 j_novak
57 * Definition of the macro UNDEF_STEP for non-defined time-steps.
58 * Changes in the way the time derivative is calculated.
59 *
60 * Revision 1.8 2004/03/26 08:22:12 e_gourgoulhon
61 * *** Full reorganization of class Evolution ***
62 * Introduction of the notion of absoluteuniversal time steps,
63 * stored in the new array 'step'.
64 * The new function position(int j) makes a correspondence
65 * between a universal time step j and the position in the
66 * arrays step, the_time and val.
67 * Only method update is now virtual.
68 * Methods operator[], position, is_known, downdate belong to
69 * the base class.
70 *
71 * Revision 1.7 2004/03/24 14:55:46 e_gourgoulhon
72 * Added method last_value().
73 *
74 * Revision 1.6 2004/03/23 14:50:40 e_gourgoulhon
75 * Added methods is_updated, downdate, get_jlast, get_size,
76 * as well as constructors without any initial value.
77 * Formatted documentation for Doxygen.
78 *
79 * Revision 1.5 2004/03/06 21:13:13 e_gourgoulhon
80 * Added time derivation (method time_derive).
81 *
82 * Revision 1.4 2004/02/16 17:37:17 j_novak
83 * Arguments named for doc++.
84 *
85 * Revision 1.3 2004/02/16 10:36:03 e_gourgoulhon
86 * Replaced " = 0x0" by " = 0" in the declaration of pure virtual functions.
87 *
88 * Revision 1.2 2004/02/15 21:55:32 e_gourgoulhon
89 * Introduced derived classes Evolution_full and Evolution_std.
90 * Evolution is now an abstract base class.
91 *
92 * Revision 1.1 2004/02/13 15:53:20 e_gourgoulhon
93 * New (template) class for time evolution.
94 *
95 *
96 *
97 *
98 * $Header: /cvsroot/Lorene/C++/Include/evolution.h,v 1.15 2014/10/13 08:52:34 j_novak Exp $
99 *
100 */
101
102#define UNDEF_STEP -100000
103
104 //---------------------------//
105 // Class Evolution //
106 //---------------------------//
107
108
109namespace Lorene {
120template<typename TyT> class Evolution {
121
122
123 // Data:
124 // -----
125
126 protected:
128 int size ;
129
131 int* step ;
132
134 double* the_time ;
135
137 TyT** val ;
138
142 int pos_jtop ;
143
144
145 // Constructors - Destructor
146 // -------------------------
147 protected:
151 Evolution(const TyT& initial_value, int initial_j,
152 double initial_time, int initial_size) ;
153
156 Evolution(int initial_size) ;
157
158 Evolution(const Evolution<TyT>& t_in) ;
159
160 public:
161
162 virtual ~Evolution() ;
163
164 // Mutators
165 // --------
166 public:
169 virtual void update(const TyT& new_value, int j,
170 double time_j) = 0 ;
171
174 void downdate(int j) ;
175
177 virtual void operator=(const Evolution<TyT>& t_in) ;
178
179
180 // Accessors
181 // ---------
182 protected:
186 int position(int j) const ;
187
189 int next_position(int i) const ;
190
192 int previous_position(int i) const ;
193
194 public:
196 const TyT& operator[](int j) const ;
197
199 double get_time(int j) const {return the_time[position(j)];} ;
200
202 TyT operator()(double t, int order=2) const ;
203
205 int get_size() const {return size; } ;
206
208 int j_min() const ;
209
211 int j_max() const ;
212
218 bool is_known(int j) const ;
219
220
221
222 // Computational methods
223 // ---------------------
236 TyT time_derive(int j, int n = 2) const ;
237
238 // Outputs
239 // -------
240
248 void save(const char* filename) const ;
249
250};
251
252
253 //---------------------------//
254 // Class Evolution_full //
255 //---------------------------//
256
257
270template<typename TyT> class Evolution_full : public Evolution<TyT> {
271
272 public:
273 using Evolution<TyT>::size ;
274 using Evolution<TyT>::step ;
275 using Evolution<TyT>::the_time ;
276 using Evolution<TyT>::val ;
277 using Evolution<TyT>::pos_jtop ;
278 using Evolution<TyT>::downdate ;
279 using Evolution<TyT>::position ;
280 using Evolution<TyT>::get_time ;
281 using Evolution<TyT>::get_size ;
282 using Evolution<TyT>::j_min ;
283 using Evolution<TyT>::j_max ;
284 using Evolution<TyT>::is_known ;
285
286 // Data:
287 // -----
288
289 private:
295
296 // Constructors - Destructor
297 // -------------------------
298 public:
309 Evolution_full(const TyT& initial_value, int initial_j = 0,
310 double initial_time = 0., int fact_resize_i = 2) ;
311
319 Evolution_full(int fact_resize_i = 2) ;
320
321
322 Evolution_full(const Evolution_full<TyT>& t_in) ;
323
324 virtual ~Evolution_full() ;
325
326 // Mutators
327 // --------
328 public:
334 virtual void update(const TyT& new_value, int j,
335 double time_j) ;
336
338 virtual void operator=(const Evolution_full<TyT>& t_in) ;
339
341 virtual void operator=(const Evolution<TyT>& t_in) ;
342
343
344 // Accessors
345 // ---------
346
347 // Outputs
348 // -------
349
350
351
352};
353
354
355 //---------------------------//
356 // Class Evolution_std //
357 //---------------------------//
358
359
371template<typename TyT> class Evolution_std : public Evolution<TyT> {
372
373 public:
374 using Evolution<TyT>::size ;
375 using Evolution<TyT>::step ;
376 using Evolution<TyT>::the_time ;
377 using Evolution<TyT>::val ;
378 using Evolution<TyT>::pos_jtop ;
379 using Evolution<TyT>::downdate ;
380 using Evolution<TyT>::position ;
381 using Evolution<TyT>::get_time ;
382 using Evolution<TyT>::get_size ;
383 using Evolution<TyT>::j_min ;
384 using Evolution<TyT>::j_max ;
385 using Evolution<TyT>::is_known ;
386
387 // Constructors - Destructor
388 // -------------------------
389 public:
398 Evolution_std(const TyT& initial_value, int nstored,
399 int initial_j = 0, double initial_time = 0.) ;
400
406 Evolution_std(int nstored) ;
407
408
409 Evolution_std(const Evolution_std<TyT>& t_in) ;
410
411 virtual ~Evolution_std() ;
412
413 // Mutators
414 // --------
420 virtual void update(const TyT& new_value, int j, double time_j) ;
421
423 virtual void operator=(const Evolution_std<TyT>& t_in) ;
424
426 virtual void operator=(const Evolution<TyT>& t_in) ;
427
428 // Accessors
429 // ---------
430
431 // Outputs
432 // -------
433
434
435
436};
437
438}
439
440#include "Template/evolution.C"
441#include "Template/evolution_full.C"
442#include "Template/evolution_std.C"
443
444#endif
445
Time evolution with full storage (*** under development ***).
Definition evolution.h:270
virtual void update(const TyT &new_value, int j, double time_j)
Sets a new value at a given time step.
virtual void operator=(const Evolution_full< TyT > &t_in)
Assignement to another Evolution_full.
int fact_resize
Factor by which the size size of the arrays val and the_time are to be multiplied when their limits h...
Definition evolution.h:294
virtual ~Evolution_full()
Destructor.
Time evolution with partial storage (*** under development ***).
Definition evolution.h:371
virtual void operator=(const Evolution_std< TyT > &t_in)
Assignement to another Evolution_std.
virtual ~Evolution_std()
Destructor.
virtual void update(const TyT &new_value, int j, double time_j)
Sets a new value at a given time step.
Time evolution (*** under development ***).
Definition evolution.h:120
int get_size() const
Returns the member size.
Definition evolution.h:205
void downdate(int j)
Suppresses a stored value.
Definition evolution.C:244
void save(const char *filename) const
Saves *this in a formatted file.
Definition evolution.C:589
const TyT & operator[](int j) const
Returns the value at time step j.
Definition evolution.C:360
int j_max() const
Returns the larger time step j stored in *this.
Definition evolution.C:482
int next_position(int i) const
Returns the next valid position (returns -1 if none is found)
Definition evolution.C:302
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...
Definition evolution.C:504
double get_time(int j) const
Returns the time t at time step j.
Definition evolution.h:199
TyT ** val
Array of pointers onto the values (size = size).
Definition evolution.h:137
TyT operator()(double t, int order=2) const
Returns the value at time t, with a scheme of order order.
Definition evolution.C:370
int size
Maximum number of stored time steps.
Definition evolution.h:128
virtual ~Evolution()
Destructor.
Definition evolution.C:214
int * step
Array of time step indices (size = size).
Definition evolution.h:131
int pos_jtop
Position in the arrays step, the_time and val of the most evolved time step.
Definition evolution.h:142
int j_min() const
Returns the smaller time step j stored in *this.
Definition evolution.C:463
double * the_time
Array of values of t at the various time steps (size = size).
Definition evolution.h:134
virtual void update(const TyT &new_value, int j, double time_j)=0
Sets a new value at a given time step.
int position(int j) const
Gives the position in the arrays step, the_time and val corresponding to the time step j.
Definition evolution.C:273
bool is_known(int j) const
Checks whether the value a given time step has been set.
Definition evolution.C:335
virtual void operator=(const Evolution< TyT > &t_in)
Assignement.
Definition evolution.C:235
int previous_position(int i) const
Returns the previous valid position (returns -1 if none is found)
Definition evolution.C:318
Lorene prototypes.
Definition app_hor.h:64