LORENE
evolution_std.C
1/*
2 * Methods of template class Evolution_std
3 *
4 * (see file evolution.h for documentation).
5 *
6 */
7
8/*
9 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28/*
29 * $Id: evolution_std.C,v 1.10 2014/10/13 08:52:38 j_novak Exp $
30 * $Log: evolution_std.C,v $
31 * Revision 1.10 2014/10/13 08:52:38 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.9 2014/10/06 15:12:51 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.8 2005/01/11 12:48:46 f_limousin
38 * Implement the function operator=(const Evolution_std<TyT>& ).
39 *
40 * Revision 1.7 2004/05/31 09:06:12 e_gourgoulhon
41 * Added protection against self-assignement in method update.
42 *
43 * Revision 1.6 2004/03/26 13:31:09 j_novak
44 * Definition of the macro UNDEF_STEP for non-defined time-steps.
45 * Changes in the way the time derivative is calculated.
46 *
47 * Revision 1.5 2004/03/26 08:22:13 e_gourgoulhon
48 * *** Full reorganization of class Evolution ***
49 * Introduction of the notion of absoluteuniversal time steps,
50 * stored in the new array 'step'.
51 * The new function position(int j) makes a correspondence
52 * between a universal time step j and the position in the
53 * arrays step, the_time and val.
54 * Only method update is now virtual.
55 * Methods operator[], position, is_known, downdate belong to
56 * the base class.
57 *
58 * Revision 1.4 2004/03/23 14:50:41 e_gourgoulhon
59 * Added methods is_updated, downdate, get_jlast, get_size,
60 * as well as constructors without any initial value.
61 * Formatted documentation for Doxygen.
62 *
63 * Revision 1.3 2004/02/17 22:13:34 e_gourgoulhon
64 * Suppressed declaration of global char[] evolution_C = ...
65 *
66 * Revision 1.2 2004/02/16 12:37:34 e_gourgoulhon
67 * Added an assert in method update.
68 *
69 * Revision 1.1 2004/02/15 21:55:33 e_gourgoulhon
70 * Introduced derived classes Evolution_full and Evolution_std.
71 * Evolution is now an abstract base class.
72 *
73 *
74 * $Header: /cvsroot/Lorene/C++/Include/Template/evolution_std.C,v 1.10 2014/10/13 08:52:38 j_novak Exp $
75 *
76 */
77
78// C++ headers
79#include "headcpp.h"
80
81// C headers
82#include <cstdlib>
83#include <cassert>
84
85namespace Lorene {
86
87 //-------------------------//
88 // Constructors //
89 //-------------------------//
90
91
92template<typename TyT>
93Evolution_std<TyT>::Evolution_std(const TyT& initial_value, int nstored,
94 int initial_j, double initial_time)
95 : Evolution<TyT>(initial_value, initial_j, initial_time, nstored)
96{ }
97
98
99template<typename TyT>
101 : Evolution<TyT>(nstored)
102{ }
103
104
105template<typename TyT>
109
110
111
112
113 //-----------------------//
114 // Destructor //
115 //-----------------------//
116
117
118template<typename TyT>
120
121
122
123 //-----------------------//
124 // Mutators //
125 //-----------------------//
126
127
128template<typename TyT>
130
131 size = evo.size ;
132 pos_jtop = evo.pos_jtop ;
133
134 for (int j=0; j<size; j++) {
135 step[j] = evo.step[j] ;
136 }
137
138 for (int j=0; j<size; j++) {
139 the_time[j] = evo.the_time[j] ;
140 }
141
142
143 for (int j=0; j<size; j++) {
144 if (val[j] != 0x0) {
145 delete val[j] ;
146 val[j] = 0x0 ;
147 }
148 }
149
150 for (int j=0; j<size; j++) {
151 if (evo.val[j] != 0x0) {
152 val[j] = new TyT( *(evo.val[j]) ) ;
153 }
154 else {
155 val[j] = 0x0 ;
156 }
157 }
158}
159
160template<typename TyT>
162
163 cerr << "void Evolution_std<TyT>::operator= : not implemented yet ! \n" ;
164 abort() ;
165
166}
167
168
169
170template<typename TyT>
171void Evolution_std<TyT>::update(const TyT& new_value, int j, double time_j) {
172
173
174 if (is_known(j)) { // Case of a time step already stored
175 //-----------------------------------
176 int pos = position(j) ;
177 assert( fabs(the_time[pos] - time_j) < 1.e-14 ) ;
178 assert( val[pos] != &new_value ) ; // to avoid self assignment
179 delete val[pos] ;
180 val[pos] = new TyT(new_value) ;
181 }
182 else { // Storage of a new time step
183 //---------------------------
184
185 if ( (pos_jtop != -1) && (j < step[pos_jtop]) ) {
186 cerr <<
187 "Evolution_std<TyT>::update : the time step j = "
188 << j << " must be in the future\n"
189 << " of the last stored time step (" << step[pos_jtop] << ") !"
190 << endl ;
191 abort() ;
192 }
193
194 pos_jtop++ ;
195
196 if (pos_jtop == size) { // re-organization of arrays step, the_time
197 // and val is necessary
198
199 if ( val[0] != 0x0 ) delete val[0] ;
200
201 for (int i=0; i<size-1; i++) {
202 step[i] = step[i+1] ;
203 the_time[i] = the_time[i+1] ;
204 val[i] = val[i+1] ;
205 }
206
207 pos_jtop-- ; // pos_jtop = size-1
208
209 }
210 else {
211 assert( pos_jtop < size ) ;
212 assert( val[pos_jtop] == 0x0 ) ;
213 }
214
215 step[pos_jtop] = j ;
216 the_time[pos_jtop] = time_j ;
217 val[pos_jtop] = new TyT( new_value ) ;
218 }
219
220}
221
222
223
224}
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.
Evolution_std(const TyT &initial_value, int nstored, int initial_j=0, double initial_time=0.)
Constructor from initial value.
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
TyT ** val
Array of pointers onto the values (size = size).
Definition evolution.h:137
int size
Maximum number of stored time steps.
Definition evolution.h:128
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
double * the_time
Array of values of t at the various time steps (size = size).
Definition evolution.h:134
Lorene prototypes.
Definition app_hor.h:64