TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
FixedVector.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#ifndef FixedVector_included
16#define FixedVector_included
17
18#include <assert.h>
19
20class Domaine_IJK;
21
22// Generic vector of fixed size
23template<class T, int N>
25{
26public:
28 FixedVector(int i, int j, int k) { }
29
30 static int size()
31 {
32 return N;
33 }
34 T& operator[](int i)
35 {
36 assert(i>=0 && i<N);
37 return data_[i];
38 }
39 const T& operator[](int i) const
40 {
41 assert(i>=0 && i<N);
42 return data_[i];
43 }
45 {
46 for (int i = 0; i < N; i++)
47 data_[i].echange_espace_virtuel(data_[i].ghost());
48 }
49 const Domaine_IJK& get_domaine() const
50 {
51 return data_[0].get_domaine();
52 }
53protected:
54 T data_[N];
55};
56
57template<>
58inline FixedVector<int,3>::FixedVector(int i, int j, int k)
59{
60 data_[0] = i;
61 data_[1] = j;
62 data_[2] = k;
63}
64
65
66template<class T, int N>
67inline FixedVector<T,N> operator-(const FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
68{
70 for (int i = 0; i < N; i++)
71 resu[i] = v1[i] - v2[i];
72 return resu;
73}
74
75template<class T, int N>
76inline FixedVector<T,N> operator+(const FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
77{
79 for (int i = 0; i < N; i++)
80 resu[i] = v1[i] + v2[i];
81 return resu;
82}
83
84template<class T, int N>
85inline FixedVector<T,N> operator*(const FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
86{
88 for (int i = 0; i < N; i++)
89 resu[i] = v1[i] * v2[i];
90 return resu;
91}
92
93template<class T, int N>
94inline FixedVector<T,N> operator*(const FixedVector<T,N>& v1, const T& x)
95{
97 for (int i = 0; i < N; i++)
98 resu[i] = v1[i] * x;
99 return resu;
100}
101
102template<class T, int N>
103inline const FixedVector<T,N>& operator*=(FixedVector<T,N>& v1, const T& x)
104{
105 for (int i = 0; i < N; i++)
106 v1[i] *= x;
107 return v1;
108}
109
110//GAB 02 dec 2020 : on definit le produit_scalaire
111// /!\ ATTENTION les deux fixed vectors doivent etre du meme type T !!
112// /!\ On a fait la surcharge pour un IJK_FT_double : on peut faire le
113// le prod scal pour un IJK_FT_double du coup
114template<class T, int N>
115inline const T& produit_scalaire(FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
116{
117 T resu;
118 for (int i = 0; i < N; i++)
119 resu += v1[i] * v2[i];
120 return resu;
121}
122
123template<class T, int N>
124inline const FixedVector<T,N>& produit_scalaire(FixedVector<T,N>& v1, const FixedVector<T,1>& v2)
125{
126 FixedVector<T,N> resu;
127 for (int i = 0; i < N; i++)
128 resu += v1[i] * v2[0];
129 return resu;
130}
131
132
133template<class T, int N>
134inline const FixedVector<T,N>& produit_scalaire(FixedVector<T,N>& v1, const double v2)
135{
136 FixedVector<T,N> resu;
137 for (int i = 0; i < N; i++)
138 resu += v1[i] * v2;
139 return resu;
140}
141////////////////////////////////////////////////////////////////////////////////
142
143
144template<class T, int N>
145inline const FixedVector<T,N>& operator-=(FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
146{
147 for (int i = 0; i < N; i++)
148 v1[i] -= v2[i];
149 return v1;
150}
151
152template<class T, int N>
153inline const FixedVector<T,N>& operator+=(FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
154{
155 for (int i = 0; i < N; i++)
156 v1[i] += v2[i];
157 return v1;
158}
159
160template<class T, int N, int M>
161inline FixedVector<FixedVector<T,N>,M> operator*(const FixedVector<FixedVector<T,N>,M>& m, const T& v)
162{
164 for (int j = 0; j < M; j++)
165 for (int i = 0; i < N; i++)
166 resu[j][i] = m[j][i] * v;
167 return resu;
168}
169
170template<class T, int N, int M>
171inline FixedVector<FixedVector<T,N>,M> operator+(const FixedVector<FixedVector<T,N>,M>& mm1,
172 const FixedVector<FixedVector<T,N>,M>& mm2)
173{
175 for (int j = 0; j < M; j++)
176 for (int i = 0; i < N; i++)
177 resu[j][i] = mm1[j][i] + mm2[j][i];
178 return resu;
179}
180
181
182// GAB SURCHARGE OPERATEURS
183//template<class T, int N>
184//inline FixedVector<T,N>& operator=(FixedVector<T,N>& v1, const FixedVector<T,N>& v2)
185//{
186// for (int i = 0; i < N; i++)
187// {
188// v1[i] = v2[i];
189// }
190// return v1;
191//}
192////////////////////////////////////////////////////////////////////////////////
193
194#endif
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
const T & operator[](int i) const
Definition FixedVector.h:39
static int size()
Definition FixedVector.h:30
FixedVector(int i, int j, int k)
Definition FixedVector.h:28
const Domaine_IJK & get_domaine() const
Definition FixedVector.h:49
T & operator[](int i)
Definition FixedVector.h:34
void echange_espace_virtuel()
Definition FixedVector.h:44