TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Roue.cpp
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <TRUSTTab.h>
17#include <Roue.h>
18
19// NOTE: OF 19/6/98
20// No Doxygen comments for Roue_Ptr — it is not a class.
21
22/*! @brief
23 *
24 */
26{
27}
28
29
30/*! @brief Copy constructor.
31 *
32 * Copies the entire wheel. Useful for copy constructors of fields.
33 * (This constructor is called when doing OWN_PTR(Champ_base) = another field;
34 * the previous version copied the reference, leading to a crash at destruction.)
35 *
36 * @param x The Roue_ptr to copy.
37 */
39{
40 ptr=new Roue(x.valeur());
41}
42
43/*! @brief Copy assignment operator.
44 *
45 * Copies the entire wheel.
46 *
47 * @param x The Roue_ptr to copy.
48 * @return Reference to the modified Roue_ptr.
49 */
51{
52 Cerr << "We pass through Roue_ptr=Roue_ptr" << finl;
53 assert(0);
54 ptr=new Roue(x.valeur());
55 return *this;
56}
57
58/*! @brief
59 *
60 */
62{
63}
64
65/*! @brief
66 *
67 */
69{
70 if(ptr)
71 {
72 delete ptr;
73 ptr=0;
74 }
75}
76
77/*! @brief
78 *
79 */
81{
82 return ptr->futur(i);
83}
84
85
86/*! @brief
87 *
88 */
89const Roue& Roue_ptr::operator[](int i) const
90{
91 return ptr->futur(i);
92}
93
94
95/*! @brief Default constructor. Builds a wheel with a single slot at time t=0.
96 *
97 */
98Roue::Roue() : temps_(0), nb_cases_(1), valeurs_(), passe_(this), futur_(this)
99{
100}
101
102
103/*! @brief Copy constructor. Copies the time, values, and values of future wheels.
104 *
105 * @param roue The Roue to copy.
106 */
107Roue::Roue(const Roue& roue) : temps_(roue.temps_), nb_cases_(1), valeurs_(roue.valeurs_), passe_(this), futur_(this)
108{
109 fixer_nb_cases(roue.nb_cases_);
110 for(int i=1; i<nb_cases_; i++)
111 {
112 futur(i).valeurs_ = roue.futur(i).valeurs_;
113 // abort();
114 }
115}
116
117
118/*! @brief Destructor.
119 *
120 */
122{
123 supprimer_case(nb_cases_);
124 assert(nb_cases_==1);
125 assert(futur_.ptr==this);
126 assert(passe_.ptr==this);
127 assert(valeurs_.size()==0);
128 futur_.ptr=passe_.ptr=0;
129}
130
131/*! @brief Returns the Roue corresponding to the i-th future slot.
132 *
133 * @param i Index of the future slot.
134 * @return Reference to the i-th future Roue.
135 */
136const Roue& Roue::futur(int i) const
137{
138 assert(i>=0);
139 assert(i<=nb_cases_);
140 if(i==0)
141 return *this;
142 else
143 return futur_->futur(--i);
144}
145
146
147/*! @brief Returns the Roue corresponding to the i-th future slot.
148 *
149 * @param i Index of the future slot.
150 * @return Reference to the i-th future Roue.
151 */
153{
154 assert(i>=0);
155 assert(i<=nb_cases_);
156 if(i==0)
157 return *this;
158 else
159 return futur_->futur(--i);
160}
161
162
163/*! @brief Returns the Roue corresponding to the i-th past slot.
164 *
165 * @param i Index of the past slot.
166 * @return Reference to the i-th past Roue.
167 */
168const Roue& Roue::passe(int i) const
169{
170 assert(i>=0);
171 assert(i<=nb_cases_);
172 if(i==0)
173 return *this;
174 else
175 return passe_->passe(--i);
176}
177
178
179/*! @brief Returns the Roue corresponding to the i-th past slot.
180 *
181 * @param i Index of the past slot.
182 * @return Reference to the i-th past Roue.
183 */
185{
186 assert(i>=0);
187 assert(i<=nb_cases_);
188 if(i==0)
189 return*this;
190 else
191 return passe_->passe(--i);
192}
193
194// Roue::Roue(const Roue& roue) : passe_(roue.passe_),
195// futur_(roue.passe_), temps_(roue.temps_)
196// {
197// valeurs_.ref(roue.valeurs_);
198// }
199
200
201/*! @brief Resizes (1D) the values of the Roue and its future wheels.
202 *
203 * @param nb_val Number of values.
204 */
205void Roue::dimensionner(int nb_val)
206{
207 if (valeurs_.size() != nb_val )
208 {
209 valeurs_.resize(nb_val);
210 for(int j=1; j<nb_cases_; j++)
211 futur(j).valeurs_.resize(nb_val);
212 }
213}
214
215
216/*! @brief Resizes (2D) the values of the Roue and its future wheels.
217 *
218 * @param nb_val First dimension of the values.
219 * @param nb_comp Second dimension (number of components) of the values.
220 */
221void Roue::dimensionner(int nb_val, int nb_comp)
222{
223 if ((valeurs_.size() != nb_val*nb_comp )||(valeurs_.nb_dim()!=2) || (nb_comp!=valeurs_.dimension(1)))
224 {
225 valeurs_.resize(nb_val, nb_comp);
226 for(int j=1; j<nb_cases_; j++)
227 futur(j).valeurs_.resize(nb_val, nb_comp);
228 }
229}
230
231
232/*! @brief Changes the number of slots in the Roue.
233 *
234 * @param nb_case The new number of slots.
235 * @return The new number of slots.
236 */
237int Roue::fixer_nb_cases(int nb_case)
238{
239 if(nb_case==nb_cases_)
240 return nb_cases_;
241 int nb_case_a_ajouter=nb_case-nb_cases_;
242 if(nb_case_a_ajouter>0)
243 ajouter_case(nb_case_a_ajouter);
244 else
245 supprimer_case(-nb_case_a_ajouter);
246 return nb_cases_;
247}
248
249
250/*! @brief Adds n slots to the Roue.
251 *
252 * @param n Number of slots to add.
253 */
255{
256 for (int n_to_add = 0; n_to_add < n; n_to_add++)
257 {
258 Roue * old_futur = futur_.ptr;
259 Roue * new_futur = new Roue;
260 this ->futur_.ptr = new_futur;
261 old_futur->passe_.ptr = new_futur;
262 new_futur->futur_.ptr = old_futur;
263 new_futur->passe_.ptr = this;
264 // Update nb_cases_ for all slots:
265 {
266 const int new_nb_cases = nb_cases_ + 1;
267 Roue * ptr_roue = this;
268 for(int i = 0; i < new_nb_cases; i++, ptr_roue = ptr_roue->futur_.ptr)
269 ptr_roue->nb_cases_ = new_nb_cases;
270 }
271 }
272}
273
274/*! @brief Removes n slots from the Roue.
275 *
276 * @param n Number of slots to remove.
277 */
279{
280 for (int n_to_kill = 0; n_to_kill < n; n_to_kill++)
281 {
282 if (nb_cases_ == 1)
283 {
284 assert(futur_.ptr == this);
285 assert(passe_.ptr == this);
286 valeurs_.reset();
287 temps_=0;
288 }
289 else
290 {
291 // Save the future-of-future:
292 Roue * new_futur = futur_->futur_.ptr;
293 // Destroy the future slot:
294 {
295 Roue * to_kill = futur_.ptr;
296 to_kill->nb_cases_ = 1;
297 to_kill->futur_.ptr = to_kill->passe_.ptr = to_kill;
298 delete to_kill;
299 }
300 // Close the linked list:
301 new_futur->passe_.ptr = this;
302 futur_.ptr = new_futur;
303
304 const int new_nb_cases = nb_cases_ - 1;
305 if(new_nb_cases == 1)
306 passe_.ptr=this;
307
308 // Update nb_cases_ for all slots:
309 {
310 Roue * ptr_roue = this;
311 for(int i = 0; i < new_nb_cases; i++, ptr_roue = ptr_roue->futur_.ptr)
312 ptr_roue->nb_cases_ = new_nb_cases;
313 }
314 }
315 }
316}
317
318
319/*! @brief Assignment operator for a Roue. Copies the time, values, number of slots, and future slot values.
320 *
321 * @param roue The Roue to copy.
322 * @return Reference to the modified Roue.
323 */
325{
326 temps_ = roue.temps_;
327 valeurs_ = roue.valeurs_;
328 fixer_nb_cases(roue.nb_cases_);
329 for(int i=1; i<nb_cases_; i++)
330 {
331 futur(i).valeurs_ = roue.futur(i).valeurs_;
332 // abort();
333 }
334 return *this;
335}
336
Roue class used in Champ_Inc_Base.
Definition Roue.h:86
int fixer_nb_cases(int)
Changes the number of slots in the Roue.
Definition Roue.cpp:237
~Roue()
Destructor.
Definition Roue.cpp:121
Roue & operator=(const Roue &)
Assignment operator for a Roue. Copies the time, values, number of slots, and future slot values.
Definition Roue.cpp:324
void ajouter_case(int n=1)
Adds n slots to the Roue.
Definition Roue.cpp:254
const Roue & futur(int i=1) const
Returns the Roue corresponding to the i-th future slot.
Definition Roue.cpp:136
void dimensionner(int nb_val)
Resizes (1D) the values of the Roue and its future wheels.
Definition Roue.cpp:205
void supprimer_case(int n=1)
Removes n slots from the Roue.
Definition Roue.cpp:278
Roue()
Default constructor. Builds a wheel with a single slot at time t=0.
Definition Roue.cpp:98
const Roue & passe(int i=1) const
Returns the Roue corresponding to the i-th past slot.
Definition Roue.cpp:168
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
Roue & valeur()
Definition Roue.h:45
Roue & operator[](int i)
Definition Roue.cpp:80
Roue_ptr()
Definition Roue.cpp:25
~Roue_ptr()
Definition Roue.cpp:68
Roue * ptr
Definition Roue.h:44
Roue_ptr(const Roue_ptr &)
Copy constructor.
Definition Roue.cpp:38
Roue_ptr & operator=(const Roue_ptr &x)
Copy assignment operator.
Definition Roue.cpp:50