TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUSTTrav.h
1/****************************************************************************
2* Copyright (c) 2025, 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#ifndef TRUSTTrav_included
17#define TRUSTTrav_included
18
19#include <TRUSTTab.h>
20
21/*! @brief Temporary multidimensional array ('tableau de travail')
22 *
23 * Exactly the same as a TRUSTTab with a custom memory pool management allowing re-using previously allocated blocks
24 * See implementation in TRUSTTravPool class.
25 *
26 * 64 bits version is not defined, as those should be only used inside the timestepping algorithm.
27 */
28template<typename _TYPE_>
29class TRUSTTrav : public TRUSTTab<_TYPE_, int>
30{
31protected:
32 inline unsigned taille_memoire() const override { throw; }
33 inline Sortie& printOn(Sortie& os) const override { return TRUSTTab<_TYPE_,int>::printOn(os); }
34 inline Entree& readOn(Entree& is) override { return TRUSTTab<_TYPE_,int>::readOn(is); }
35
36 inline int duplique() const override
37 {
38 TRUSTTrav* xxx = new TRUSTTrav(*this);
39 if(!xxx)
40 {
41 Cerr << "Not enough memory " << finl;
43 }
44 return xxx->numero();
45 }
46
47public:
48 inline TRUSTTrav()
49 {
50 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
51 }
52
53 inline TRUSTTrav(int n)
54 {
55 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
57 }
58
59 inline TRUSTTrav(int n1, int n2)
60 {
61 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
63 }
64
65 inline TRUSTTrav(int n1, int n2, int n3)
66 {
67 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
69 }
70
71 inline TRUSTTrav(int n1, int n2, int n3, int n4)
72 {
73 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
74 TRUSTTab<_TYPE_,int>::resize(n1, n2, n3, n4);
75 }
76
77 // Constructeur par copie depuis Vect
78 // ATTENTION: construit un tableau de meme taill et de meme structure (espaces virtuels), mais initialise avec TYPE_ZERO !!!
80 {
81 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
83 TRUSTTab<_TYPE_,int>::resize(tab.size_array(), RESIZE_OPTIONS::NOCOPY_NOINIT);
85 // Important! Even with default std::vector<> allocation to 0 in TRUSTArray, Trav re-uses previous blocks
86 // which might not be zero, so we enforce it:
88 }
89
90 // Constructeur par copie depuis Tab
91 // ATTENTION: construit un tableau de meme taill et de meme structure (espaces virtuels), mais initialise avec TYPE_ZERO !!!
93 {
94 TRUSTTab<_TYPE_,int>::set_mem_storage(STORAGE::TEMP_STORAGE);
95 TRUSTTab<_TYPE_,int>::copy(tab, RESIZE_OPTIONS::NOCOPY_NOINIT);
96 // Important! Even with default std::vector<> allocation to 0 in TRUSTArray, Trav re-uses previous blocks
97 // which might not be zero, so we enforce it:
99 }
100
101 // Constructeur par copie depuis Trav
102 // ATTENTION: construit un tableau de meme taill et de meme structure (espaces virtuels), mais initialise avec TYPE_ZERO !!!
103 inline TRUSTTrav(const TRUSTTrav& tab) :
104 // Force invocation of previous ctor on TRUSTTab<> since nothing new here (but this ctor must exist since 'operator=()' is coded)
105 TRUSTTrav<_TYPE_>((const TRUSTTab<_TYPE_,int>&)tab)
106 { }
107
108 // Operateurs copie
109
110 // Operateur copie (on ne veut pas l'operateur par defaut)
111 inline TRUSTTrav& operator=(const TRUSTTrav& tab)
112 {
114 return *this;
115 }
116
117 // Operateur copie d'un tableau (copie structure ET contenu)
119 {
120 // ATTENTION: note aux programmeurs
121 // La declaration de cet operateur est indispensable, sinon
122 // IntTab b;
123 // IntTrav a;
124 // a = b
125 // est traduit en
126 // IntTrav tmp(b); // copie la structure mais met les valeurs a TYPE_ZERO
127 // a.operator=(tmp);
129 return *this;
130 }
131
132 // Operateur copie d'un tableau (copie structure ET contenu)
134 {
135 // ATTENTION: note aux programmeurs ...
137 return *this;
138 }
139
140 // Comme on surcharge l'operateur copie, il faut redefinir celui-la aussi.
141 inline TRUSTTrav& operator=(_TYPE_ d)
142 {
144 return *this;
145 }
146
147private:
148 static constexpr _TYPE_ TYPE_ZERO = (_TYPE_)0;
149
150 /* APPELS INTERDITS : very in-efficient on Trvas, should use tabs */
151 void append_line(_TYPE_);
152 void append_line(_TYPE_, _TYPE_);
153 void append_line(_TYPE_, _TYPE_, _TYPE_);
154 void append_line(_TYPE_, _TYPE_, _TYPE_, _TYPE_);
155};
156
157using DoubleTrav = TRUSTTrav<double>;
158using FloatTrav = TRUSTTrav<float>;
159using IntTrav = TRUSTTrav<int>;
160
161#endif /* TRUSTTrav_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
int numero() const
Renvoie l'indice de l'objet dans Memoire::data.
Definition Objet_U.cpp:268
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ size_array() const
void set_mem_storage(const STORAGE storage)
void set_md_vector(const MD_Vector &) override
Definition TRUSTTab.tpp:673
friend class TRUSTTab
Definition TRUSTTab.h:112
Sortie & printOn(Sortie &os) const override
ecriture d'un tableau sequentiel (idem que TRUSTVect::printOn() on ne sait pas quoi faire de pertinen...
Definition TRUSTTab.h:45
Entree & readOn(Entree &is) override
lecture d'un tableau sequentiel
Definition TRUSTTab.h:68
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
void copy(const TRUSTTab &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:622
TRUSTTab & operator=(const TRUSTTab &)
Definition TRUSTTab.tpp:578
Temporary multidimensional array ('tableau de travail').
Definition TRUSTTrav.h:30
TRUSTTrav & operator=(const TRUSTTrav &tab)
Definition TRUSTTrav.h:111
TRUSTTrav(const TRUSTVect< _TYPE_, int > &tab)
Definition TRUSTTrav.h:79
int duplique() const override
Definition TRUSTTrav.h:36
TRUSTTrav(int n1, int n2, int n3, int n4)
Definition TRUSTTrav.h:71
Entree & readOn(Entree &is) override
lecture d'un tableau sequentiel
Definition TRUSTTrav.h:34
unsigned taille_memoire() const override
Definition TRUSTTrav.h:32
TRUSTTrav(const TRUSTTab< _TYPE_, int > &tab)
Definition TRUSTTrav.h:92
TRUSTTrav & operator=(_TYPE_ d)
Definition TRUSTTrav.h:141
TRUSTTrav(int n)
Definition TRUSTTrav.h:53
TRUSTTrav(int n1, int n2, int n3)
Definition TRUSTTrav.h:65
TRUSTTrav & operator=(const TRUSTTab< _TYPE_, int > &tab)
Definition TRUSTTrav.h:118
TRUSTTrav(const TRUSTTrav &tab)
Definition TRUSTTrav.h:103
TRUSTTrav & operator=(const TRUSTVect< _TYPE_, int > &tab)
Definition TRUSTTrav.h:133
Sortie & printOn(Sortie &os) const override
ecriture d'un tableau sequentiel (idem que TRUSTVect::printOn() on ne sait pas quoi faire de pertinen...
Definition TRUSTTrav.h:33
TRUSTTrav(int n1, int n2)
Definition TRUSTTrav.h:59
int line_size() const
Definition TRUSTVect.tpp:67
void set_line_size_(int n)
Definition TRUSTVect.tpp:78
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123