Debian Codegraph @

C++/Include/evolution.h

raw symbols SCIP
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
109 namespace Lorene {
110 /** Time evolution (*** under development ***). \ingroup (evol)
111 *
112 * The template class \c Evolution has been devised to store and
113 * manipulate evolving quantities of any type, for instance \c TyT = \c double
114 * or \c TyT = \c Scalar.
115 *
116 * \c Evolution is an abstract base class for classes
117 * \c Evolution_full and \c Evolution_std.
118 *
119 */
120 template<typename TyT> class Evolution {
121
122
123 // Data:
124 // -----
125
126 protected:
127 /// Maximum number of stored time steps.
128 int size ;
129
130 /// Array of time step indices (size = \c size).
131 int* step ;
132
133 /// Array of values of t at the various time steps (size = \c size).
134 double* the_time ;
135
136 /// Array of pointers onto the values (size = \c size).
137 TyT** val ;
138
139 /** Position in the arrays \c step, \c the_time and \c val
140 * of the most evolved time step.
141 */
142 int pos_jtop ;
143
144
145 // Constructors - Destructor
146 // -------------------------
147 protected:
148 /** Constructor from some initial value.
149 *
150 */
151 Evolution(const TyT& initial_value, int initial_j,
152 double initial_time, int initial_size) ;
153
154 /** Constructor without any initial value.
155 */
156 Evolution(int initial_size) ;
157
158 Evolution(const Evolution<TyT>& t_in) ; ///< Copy constructor
159
160 public:
161
162 virtual ~Evolution() ; ///< Destructor
163
164 // Mutators
165 // --------
166 public:
167 /** Sets a new value at a given time step.
168 */
169 virtual void update(const TyT& new_value, int j,
170 double time_j) = 0 ;
171
172 /** Suppresses a stored value.
173 */
174 void downdate(int j) ;
175
176 /// Assignement
177 virtual void operator=(const Evolution<TyT>& t_in) ;
178
179
180 // Accessors
181 // ---------
182 protected:
183 /** Gives the position in the arrays \c step, \c the_time and
184 * \c val corresponding to the time step j
185 */
186 int position(int j) const ;
187
188 /// Returns the next valid position (returns -1 if none is found)
189 int next_position(int i) const ;
190
191 /// Returns the previous valid position (returns -1 if none is found)
192 int previous_position(int i) const ;
193
194 public:
195 /// Returns the value at time step j
196 const TyT& operator[](int j) const ;
197
198 /// Returns the time t at time step j
199 double get_time(int j) const {return the_time[position(j)];} ;
200
201 /// Returns the value at time t, with a scheme of order \c order.
202 TyT operator()(double t, int order=2) const ;
203
204 /// Returns the member \c size
205 int get_size() const {return size; } ;
206
207 /// Returns the smaller time step j stored in \c *this
208 int j_min() const ;
209
210 /// Returns the larger time step j stored in \c *this
211 int j_max() const ;
212
213 /** Checks whether the value a given time step has been set
214 * @param j time step index
215 * @return \c true if the value at time step j is known, \c false
216 * otherwise
217 */
218 bool is_known(int j) const ;
219
220
221
222 // Computational methods
223 // ---------------------
224 /** Computes the time derivative at time step \c j by means of a
225 * n-th order scheme, from the values at steps \c j,
226 * \c j-1, ..., \c j-n.
227 *
228 * @param j [input] : value of the time step at which the time
229 * derivative is required
230 * @param n [input] : order of the time scheme (default value=2);
231 * if n=0, then the \c Evolution is considered
232 * to be stationary and a null value is returned.
233 * @return time derivative at time step \c j
234 *
235 */
236 TyT time_derive(int j, int n = 2) const ;
237
238 // Outputs
239 // -------
240
241 /** Saves \c *this in a formatted file.
242 * If \c TyT = \c double, this file is readable by 2-D plotting
243 * software (e.g. \e Xmgrace) to produce a curve of the time
244 * evolution.
245 * @param filename name of the file: this file will be created
246 * in the working directory.
247 */
248 void save(const char* filename) const ;
249
250 };
251
252
253 //---------------------------//
254 // Class Evolution_full //
255 //---------------------------//
256
257
258 /** Time evolution with full storage (*** under development ***).
259 * \ingroup (evol)
260 *
261 * The template class \c Evolution_full has been devised to store and
262 * manipulate evolving quantities of any type, for instance \c TyT = \c double
263 * or \c TyT = \c Scalar.
264 * The quantity is stored at all time steps since the beginning of the
265 * time evolution. For large objects, this might result in some memory
266 * problem. The class \c Evolution_std, which stores only a limited
267 * number of time steps, is to be prefered then.
268 *
269 */
270 template<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:
290 /** Factor by which the size \c size of the arrays
291 * \c val and \c the_time are to be multiplied when
292 * their limits have been reached.
293 */
294 int fact_resize ;
295
296 // Constructors - Destructor
297 // -------------------------
298 public:
299 /** Constructor from initial value.
300 *
301 * @param initial_value value to be stored at time step \c initial_j
302 * @param initial_j index \c j of first time step to be stored
303 * @param initial_time time t corresponding to time step \c initial_j
304 * @param fact_resize_i factor by which the size \c size of the arrays
305 * \c val and \c the_time are to be multiplied when
306 * their limits have been reached.
307 *
308 */
309 Evolution_full(const TyT& initial_value, int initial_j = 0,
310 double initial_time = 0., int fact_resize_i = 2) ;
311
312 /** Constructor without any initial value.
313 *
314 * @param fact_resize_i factor by which the size \c size of the arrays
315 * \c val and \c the_time are to be multiplied when
316 * their limits have been reached.
317 *
318 */
319 Evolution_full(int fact_resize_i = 2) ;
320
321
322 Evolution_full(const Evolution_full<TyT>& t_in) ; ///< Copy constructor
323
324 virtual ~Evolution_full() ; ///< Destructor
325
326 // Mutators
327 // --------
328 public:
329 /** Sets a new value at a given time step.
330 * If the size of the arrays of stored values
331 * (members \c step, \c the_time, \c val) is not
332 * sufficient, it is increased by multiplication by \c fact_resize.
333 */
334 virtual void update(const TyT& new_value, int j,
335 double time_j) ;
336
337 /// Assignement to another \c Evolution_full
338 virtual void operator=(const Evolution_full<TyT>& t_in) ;
339
340 /// Assignement to a generic \c Evolution
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
360 /** Time evolution with partial storage (*** under development ***).
361 * \ingroup (evol)
362 *
363 * The template class \c Evolution_std has been devised to store and
364 * manipulate evolving quantities of any type, for instance \c TyT = \c double
365 * or \c TyT = \c Scalar.
366 * The quantity is stored only for a limited number of time steps (the
367 * n last ones).
368 * For a full storage, use instead the class \c Evolution_full.
369 *
370 */
371 template<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:
390 /** Constructor from initial value.
391 *
392 * @param initial_value value to be stored at time step \c initial_j
393 * @param initial_j index \c j of first time step to be stored
394 * @param initial_time time t corresponding to time step \c initial_j
395 * @param nstored total number of time steps to be stored
396 *
397 */
398 Evolution_std(const TyT& initial_value, int nstored,
399 int initial_j = 0, double initial_time = 0.) ;
400
401 /** Constructor without any initial value.
402 *
403 * @param nstored total number of time steps to be stored
404 *
405 */
406 Evolution_std(int nstored) ;
407
408
409 Evolution_std(const Evolution_std<TyT>& t_in) ; ///< Copy constructor
410
411 virtual ~Evolution_std() ; ///< Destructor
412
413 // Mutators
414 // --------
415 /** Sets a new value at a given time step.
416 * If the size of the arrays of stored values
417 * (members \c step, \c the_time, \c val) is not
418 * sufficient, this method suppresses the oldest stored value.
419 */
420 virtual void update(const TyT& new_value, int j, double time_j) ;
421
422 /// Assignement to another \c Evolution_std
423 virtual void operator=(const Evolution_std<TyT>& t_in) ;
424
425 /// Assignement to a generic \c Evolution
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