TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
IJK_Field_vector.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 IJK_Field_vector_included
16#define IJK_Field_vector_included
17
18#include <assert.h>
19#include <FixedVector.h>
20#include <IJK_Field.h>
21#include <Field_base.h>
22#include <Noms.h>
23#include <Champ_Generique_base.h> // For Entity
24
25/*! @brief The class IJK_Field_vector is a fixed array of polymorphic IJK fields.
26 *
27 * For example, the velocity is a fixed vector with 3 components.
28 * Each component is a (smart) pointer, thus allowing any derived class of IJK_Field_template to be used (this is used for example in cut-cell methods).
29 *
30 * The bracket '[]' operator allows the direct retrieval of a reference to one of the components.
31 *
32 * The function IJK_Navier_stokes_tools.h::allocate_velocity() gives an example on how the object is instanciated:
33 *
34 * // Construction of the IJK_Field_template objects
35 * v.get_ptr(0) = std::make_shared<IJK_Field_template<T,TRUSTArray<T>>>();
36 * v.get_ptr(1) = std::make_shared<IJK_Field_template<T,TRUSTArray<T>>>();
37 * v.get_ptr(2) = std::make_shared<IJK_Field_template<T,TRUSTArray<T>>>();
38 *
39 * // Allocation of the fields
40 * v[0].allocate(s, Domaine_IJK::FACES_I, ghost);
41 * v[1].allocate(s, Domaine_IJK::FACES_J, ghost);
42 * v[2].allocate(s, Domaine_IJK::FACES_K, ghost);
43 *
44 * The class inherits from Field_base and a IJK_Field_vector can thus be named.
45 * It has a default Nature of 'vectoriel'.
46 */
47template<class T, int N>
48class IJK_Field_vector : public FixedVector<std::shared_ptr<IJK_Field_template<T,TRUSTArray<T>>>, N>, public Field_base
49{
50public:
51 // The mess of Objet_U .....
52 inline unsigned taille_memoire() const override { throw; }
53 inline int duplique() const override
54 {
55 IJK_Field_vector* xxx = new IJK_Field_vector(*this);
56 if(!xxx) Process::exit("Not enough memory ");
57 return xxx->numero();
58 }
59 Sortie& printOn(Sortie& os) const override { return os; }
60 Entree& readOn(Entree& is) override { return is; }
61 //
62
64 {
65 nature_ = Nature_du_champ::vectoriel;
66 nb_compo_ = N;
67 loc_ = Entity::ELEMENT;
68 }
69
70 void nommer(const Nom& nam) override
71 {
73 const char *compos[] = {"_X", "_Y", "_Z"};
74 this->fixer_nb_comp(N);
75 Noms compos2(N);
76 for (int i=0; i<N; i++)
77 {
78 const Nom nom_compo = nam + Nom(compos[i]);
79 compos2[i] = nom_compo;
80 this->data_[i]->nommer(nom_compo);
81 }
82 this->fixer_noms_compo(compos2);
83 }
84
85 void add_synonymous(const Nom& nam) override
86 {
88 const char *compos[] = {"_X", "_Y", "_Z"};
89 for (int i=0; i<N; i++)
90 this->data_[i]->add_synonymous(nam + Nom(compos[i]));
91 }
92
93 Entity& localisation() { return loc_; }
94 const Entity& localisation() const { return loc_; }
95
97 {
98 assert(i>=0 && i<N);
99 return *this->data_[i];
100 }
101
103 {
104 assert(i>=0 && i<N);
105 return *this->data_[i];
106 }
107
108 std::shared_ptr<IJK_Field_template<T,TRUSTArray<T>>>& get_ptr(int i)
109 {
110 assert(i>=0 && i<N);
111 return this->data_[i];
112 }
113
114 const std::shared_ptr<IJK_Field_template<T,TRUSTArray<T>>>& get_ptr(int i) const
115 {
116 assert(i>=0 && i<N);
117 return this->data_[i];
118 }
119
121 {
122 for (int i = 0; i < N; i++)
123 this->data_[i]->echange_espace_virtuel(this->data_[i]->ghost());
124 }
125
127 {
128 return this->data_[0]->get_domaine();
129 }
130
131private:
132 Entity loc_;
133};
134
135template<class T, int N>
137{
139 for (int i = 0; i < N; i++)
140 resu[i] = v1[i] - v2[i];
141 return resu;
142}
143
144template<class T, int N>
146{
148 for (int i = 0; i < N; i++)
149 resu[i] = v1[i] + v2[i];
150 return resu;
151}
152
153template<class T, int N>
155{
157 for (int i = 0; i < N; i++)
158 resu[i] = v1[i] * v2[i];
159 return resu;
160}
161
162template<class T, int N>
164{
166 for (int i = 0; i < N; i++)
167 resu[i] = v1[i] * x;
168 return resu;
169}
170
171template<class T, int N>
173{
174 for (int i = 0; i < N; i++)
175 v1[i] *= x;
176 return v1;
177}
178
179template<class T, int N>
181{
183 for (int i = 0; i < N; i++)
184 resu += v1[i] * v2[i];
185 return resu;
186}
187
188template<class T, int N>
190{
192 for (int i = 0; i < N; i++)
193 resu += v1[i] * v2[0];
194 return resu;
195}
196
197
198template<class T, int N>
199inline const IJK_Field_vector<double, N>& produit_scalaire(IJK_Field_vector<double, N>& v1, const double v2)
200{
202 for (int i = 0; i < N; i++)
203 resu += v1[i] * v2;
204 return resu;
205}
206
207
208template<class T, int N>
210{
211 for (int i = 0; i < N; i++)
212 v1[i] -= v2[i];
213 return v1;
214}
215
216template<class T, int N>
218{
219 for (int i = 0; i < N; i++)
220 v1[i] += v2[i];
221 return v1;
222}
223
224using IJK_Field_vector3_double = IJK_Field_vector<double, 3>;
225using IJK_Field_vector3_int = IJK_Field_vector<int, 3>;
226
227#endif
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
void nommer(const Nom &) override
Donne un nom au champ.
const Nom & nom_compo(int) const
Renvoie le nom de la ieme composante du champ.
virtual const Noms & fixer_noms_compo(const Noms &)
Fixe le nom des composantes du champ.
virtual void add_synonymous(const Nom &nom)
Definition Field_base.h:53
int nb_compo_
Definition Field_base.h:95
Nature_du_champ nature_
Definition Field_base.h:96
std::shared_ptr< IJK_Field_template< double, TRUSTArray< double > > > data_[N]
Definition FixedVector.h:54
: This class is an IJK_Field_local with parallel informations.
The class IJK_Field_vector is a fixed array of polymorphic IJK fields.
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
const IJK_Field_template< T, TRUSTArray< T > > & operator[](int i) const
void add_synonymous(const Nom &nam) override
std::shared_ptr< IJK_Field_template< T, TRUSTArray< T > > > & get_ptr(int i)
Entity & localisation()
IJK_Field_template< T, TRUSTArray< T > > & operator[](int i)
const Domaine_IJK & get_domaine() const
const Entity & localisation() const
unsigned taille_memoire() const override
void nommer(const Nom &nam) override
Donne un nom au champ.
Entree & readOn(Entree &is) override
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
const std::shared_ptr< IJK_Field_template< T, TRUSTArray< T > > > & get_ptr(int i) const
int duplique() const override
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
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
Represents a an array of int/int64/double/... values.
Definition TRUSTArray.h:81