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.11 2024/01/26 17:44:25 g_servignat Exp $
30  * $Log: evolution_std.C,v $
31  * Revision 1.11 2024/01/26 17:44:25 g_servignat
32  * Updated the Pseudopolytrope_1D class to be consistent with the paper (i.e. with a GPP in the middle)
33  *
34  * Revision 1.10 2014/10/13 08:52:38 j_novak
35  * Lorene classes and functions now belong to the namespace Lorene.
36  *
37  * Revision 1.9 2014/10/06 15:12:51 j_novak
38  * Modified #include directives to use c++ syntax.
39  *
40  * Revision 1.8 2005/01/11 12:48:46 f_limousin
41  * Implement the function operator=(const Evolution_std<TyT>& ).
42  *
43  * Revision 1.7 2004/05/31 09:06:12 e_gourgoulhon
44  * Added protection against self-assignement in method update.
45  *
46  * Revision 1.6 2004/03/26 13:31:09 j_novak
47  * Definition of the macro UNDEF_STEP for non-defined time-steps.
48  * Changes in the way the time derivative is calculated.
49  *
50  * Revision 1.5 2004/03/26 08:22:13 e_gourgoulhon
51  * *** Full reorganization of class Evolution ***
52  * Introduction of the notion of absoluteuniversal time steps,
53  * stored in the new array 'step'.
54  * The new function position(int j) makes a correspondence
55  * between a universal time step j and the position in the
56  * arrays step, the_time and val.
57  * Only method update is now virtual.
58  * Methods operator[], position, is_known, downdate belong to
59  * the base class.
60  *
61  * Revision 1.4 2004/03/23 14:50:41 e_gourgoulhon
62  * Added methods is_updated, downdate, get_jlast, get_size,
63  * as well as constructors without any initial value.
64  * Formatted documentation for Doxygen.
65  *
66  * Revision 1.3 2004/02/17 22:13:34 e_gourgoulhon
67  * Suppressed declaration of global char[] evolution_C = ...
68  *
69  * Revision 1.2 2004/02/16 12:37:34 e_gourgoulhon
70  * Added an assert in method update.
71  *
72  * Revision 1.1 2004/02/15 21:55:33 e_gourgoulhon
73  * Introduced derived classes Evolution_full and Evolution_std.
74  * Evolution is now an abstract base class.
75  *
76  *
77  * $Header: /cvsroot/Lorene/C++/Include/Template/evolution_std.C,v 1.11 2024/01/26 17:44:25 g_servignat Exp $
78  *
79  */
80 
81 // C++ headers
82 #include "headcpp.h"
83 
84 // C headers
85 #include <cstdlib>
86 #include <cassert>
87 
88 namespace Lorene {
89 
90  //-------------------------//
91  // Constructors //
92  //-------------------------//
93 
94 
95 template<typename TyT>
96 Evolution_std<TyT>::Evolution_std(const TyT& initial_value, int nstored,
97  int initial_j, double initial_time)
98  : Evolution<TyT>(initial_value, initial_j, initial_time, nstored)
99 { }
100 
101 
102 template<typename TyT>
104  : Evolution<TyT>(nstored)
105 { }
106 
107 
108 template<typename TyT>
110  : Evolution<TyT>(evo)
111 { }
112 
113 
114 
115 
116  //-----------------------//
117  // Destructor //
118  //-----------------------//
119 
120 
121 template<typename TyT>
123 
124 
125 
126  //-----------------------//
127  // Mutators //
128  //-----------------------//
129 
130 
131 template<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 
163 template<typename TyT>
165 
166  cerr << "void Evolution_std<TyT>::operator= : not implemented yet ! \n" ;
167  abort() ;
168 
169 }
170 
171 
172 
173 template<typename TyT>
174 void Evolution_std<TyT>::update(const TyT& new_value, int j, double time_j) {
175 
176 
177  if (is_known(j)) { // Case of a time step already stored
178  //-----------------------------------
179  int pos = position(j) ;
180  assert( fabs(the_time[pos] - time_j) < 1.e-14 ) ;
181  assert( val[pos] != &new_value ) ; // to avoid self assignment
182  delete val[pos] ;
183  val[pos] = new TyT(new_value) ;
184  }
185  else { // Storage of a new time step
186  //---------------------------
187 
188  if ( (pos_jtop != -1) && (j < step[pos_jtop]) ) {
189  cerr <<
190  "Evolution_std<TyT>::update : the time step j = "
191  << j << " must be in the future\n"
192  << " of the last stored time step (" << step[pos_jtop] << ") !"
193  << endl ;
194  abort() ;
195  }
196 
197  pos_jtop++ ;
198 
199  if (pos_jtop == size) { // re-organization of arrays step, the_time
200  // and val is necessary
201 
202  if ( val[0] != 0x0 ) delete val[0] ;
203 
204  for (int i=0; i<size-1; i++) {
205  step[i] = step[i+1] ;
206  the_time[i] = the_time[i+1] ;
207  val[i] = val[i+1] ;
208  }
209 
210  pos_jtop-- ; // pos_jtop = size-1
211 
212  }
213  else {
214  assert( pos_jtop < size ) ;
215  assert( val[pos_jtop] == 0x0 ) ;
216  }
217 
218  step[pos_jtop] = j ;
219  the_time[pos_jtop] = time_j ;
220  val[pos_jtop] = new TyT( new_value ) ;
221  }
222 
223 }
224 
225 
226 
227 }
Evolution_std(const TyT &initial_value, int nstored, int initial_j=0, double initial_time=0.)
Constructor from initial value.
Definition: evolution_std.C:96
Lorene prototypes.
Definition: app_hor.h:67
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 pos_jtop
Position in the arrays step, the_time and val of the most evolved time step.
Definition: evolution.h:142
Time evolution with partial storage (*** under development ***).
Definition: evolution.h:371
int * step
Array of time step indices (size = size).
Definition: evolution.h:131
double * the_time
Array of values of t at the various time steps (size = size).
Definition: evolution.h:134
Time evolution (*** under development ***).
Definition: evolution.h:120