LORENE
evolution_full.C
1/*
2 * Methods of template class Evolution_full
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_full.C,v 1.10 2014/10/13 08:52:38 j_novak Exp $
30 * $Log: evolution_full.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:46:16 f_limousin
38 * Implement the function operator=(const Evolution_full<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:01 e_gourgoulhon
67 * Method update: initialization of extended part of arrays val and the_time.
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 *
75 * $Header: /cvsroot/Lorene/C++/Include/Template/evolution_full.C,v 1.10 2014/10/13 08:52:38 j_novak Exp $
76 *
77 */
78
79// C++ headers
80#include "headcpp.h"
81
82// C headers
83#include <cstdlib>
84#include <cassert>
85
86
87namespace Lorene {
88
89 //-------------------------//
90 // Constructors //
91 //-------------------------//
92
93
94template<typename TyT>
95Evolution_full<TyT>::Evolution_full(const TyT& initial_value, int initial_j,
96 double initial_time, int fact_resize_i)
97 : Evolution<TyT>(initial_value, initial_j, initial_time, 100),
98 fact_resize(fact_resize_i)
99{ }
100
101
102template<typename TyT>
104 : Evolution<TyT>(100),
105 fact_resize(fact_resize_i)
106{ }
107
108
109template<typename TyT>
111 : Evolution<TyT>(evo),
112 fact_resize(evo.fact_resize)
113{ }
114
115
116
117 //-----------------------//
118 // Destructor //
119 //-----------------------//
120
121
122template<typename TyT>
124
125
126 //-----------------------//
127 // Mutators //
128 //-----------------------//
129
130
131template<typename TyT>
133
134 size = evo.size ;
135 pos_jtop = evo.pos_jtop ;
136
137 for (int j=0; j<size; j++) {
138 step[j] = evo.step[j] ;
139 }
140
141 for (int j=0; j<size; j++) {
142 the_time[j] = evo.the_time[j] ;
143 }
144
145
146 for (int j=0; j<size; j++) {
147 if (val[j] != 0x0) {
148 delete val[j] ;
149 val[j] = 0x0 ;
150 }
151 }
152
153 for (int j=0; j<size; j++) {
154 if (evo.val[j] != 0x0) {
155 val[j] = new TyT( *(evo.val[j]) ) ;
156 }
157 else {
158 val[j] = 0x0 ;
159 }
160 }
161
162 fact_resize = evo.fact_resize ;
163}
164
165template<typename TyT>
167
168 cerr << "void Evolution_full<TyT>::operator= : not implemented yet ! \n" ;
169 abort() ;
170
171}
172
173
174
175template<typename TyT>
176void Evolution_full<TyT>::update(const TyT& new_value, int j,
177 double time_j) {
178
179
180 if (is_known(j)) { // Case of a time step already stored
181 //-----------------------------------
182 int pos = position(j) ;
183 assert( fabs(the_time[pos] - time_j) < 1.e-14 ) ;
184 assert( val[pos] != &new_value ) ; // to avoid self assignment
185 delete val[pos] ;
186 val[pos] = new TyT(new_value) ;
187 }
188 else { // Storage of a new time step
189 //---------------------------
190 if ( (pos_jtop != -1) && (j < step[pos_jtop]) ) {
191 cerr <<
192 "Evolution_full<TyT>::update : the time step j = "
193 << j << " must be in the future\n"
194 << " of the last stored time step (" << step[pos_jtop] << ") !"
195 << endl ;
196 abort() ;
197 }
198
199 pos_jtop++ ;
200
201 if (pos_jtop == size) { // re-organization of arrays step, the_time
202 // and val is necessary
203
204 int size_new = fact_resize * size ;
205
206 int* step_new = new int[size_new] ;
207 for (int i=0; i<size; i++) {
208 step_new[i] = step[i] ;
209 }
210 for (int i=size; i<size_new; i++) {
211 step_new[i] = UNDEF_STEP ;
212 }
213
214 double* the_time_new = new double[size_new] ;
215 for (int i=0; i<size; i++) {
216 the_time_new[i] = the_time[i] ;
217 }
218 for (int i=size; i<size_new; i++) {
219 the_time_new[i] = -1e20 ;
220 }
221
222 TyT** val_new = new TyT*[size_new] ;
223 for (int i=0; i<size; i++) {
224 val_new[i] = val[i] ;
225 }
226 for (int i=size; i<size_new; i++) {
227 val_new[i] = 0x0 ;
228 }
229
230 size = size_new ;
231 delete [] step ;
232 step = step_new ;
233 delete [] the_time ;
234 the_time = the_time_new ;
235 delete [] val ;
236 val = val_new ;
237
238 }
239 else {
240 assert( pos_jtop < size ) ;
241 assert( val[pos_jtop] == 0x0 ) ;
242 }
243
244 step[pos_jtop] = j ;
245 the_time[pos_jtop] = time_j ;
246 val[pos_jtop] = new TyT( new_value ) ;
247 }
248}
249
250
251
252
253
254}
Time evolution with full storage (*** under development ***).
Definition evolution.h:270
Evolution_full(const TyT &initial_value, int initial_j=0, double initial_time=0., int fact_resize_i=2)
Constructor from initial value.
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 (*** 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