TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTChamp_Morceaux_generique.tpp
1/****************************************************************************
2* Copyright (c) 2026, 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 TRUSTChamp_Morceaux_generique_TPP_included
17#define TRUSTChamp_Morceaux_generique_TPP_included
18
19#include <Sous_Domaine.h>
20#include <Champ_Generique_base.h>
21#include <ParserView.h>
22
23template<Champ_Morceaux_Type _TYPE_>
25{
26 static constexpr bool IS_FONC = (_TYPE_ == Champ_Morceaux_Type::FONC);
27
28 if (!IS_FONC) not_implemented_champ_<void>(__func__);
29
30 if (sub_type(Champ_Uniforme, ch)) valeurs() = ch.valeurs()(0, 0);
31 else valeurs() = ch.valeurs();
32
33 return *this;
34}
36/*! @brief Returns the value of the field at the point specified by its coordinates.
37 *
38 * @param (DoubleVect& positions) the coordinates of the computation point
39 * @param (DoubleVect& valeurs) the value of the field at the specified point
40 */
41template<Champ_Morceaux_Type _TYPE_>
42DoubleVect& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_a(const DoubleVect& positions, DoubleVect& tab_valeurs) const
44 const Domaine& le_dom = mon_domaine;
45 IntVect le_poly(1);
46 le_dom.chercher_elements(positions, le_poly);
47 return valeur_a_elem(positions, tab_valeurs, le_poly[0]);
48}
50/*! @brief Returns the value of the field at the point specified by its coordinates, indicating that this point is located in a specified element.
51 *
52 * @param (DoubleVect&) the coordinates of the computation point
53 * @param (DoubleVect& val) the value of the field at the specified point
54 * @param (int le_poly) the element in which the computation point is located
55 */
56template<Champ_Morceaux_Type _TYPE_>
57DoubleVect& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_a_elem(const DoubleVect&, DoubleVect& val, int le_poly) const
58{
59 if (val.size() != nb_compo_) erreur_champ_(__func__);
60
61 const DoubleTab& ch = valeurs();
62 for (int k = 0; k < nb_compo_; k++) val(k) = ch(le_poly, k);
63
64 return val;
65}
66
67/*! @brief Returns the value of one component of the field at the point specified by its coordinates, indicating that this point is located in a specified element.
68 *
69 * @param (DoubleVect&) the coordinates of the computation point
70 * @param (int le_poly) the element in which the computation point is located
71 * @param (int ncomp) the index of the field component to compute
72 */
73template<Champ_Morceaux_Type _TYPE_>
74double TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_a_elem_compo(const DoubleVect&, int le_poly, int ncomp) const
75{
76 if (ncomp > nb_compo_) erreur_champ_(__func__);
77
78 const DoubleTab& ch = valeurs();
79 double val = (nb_compo_ == 1) ? ch(le_poly, 0) : ch(le_poly, ncomp);
80
81 return val;
82}
83
84/*! @brief Returns the values of the field at the points specified by their coordinates.
85 *
86 * @param (DoubleTab& positions) the array of coordinates of the computation points
87 * @param (DoubleTab& valeurs) the array of field values at the specified points
88 */
89template<Champ_Morceaux_Type _TYPE_>
90DoubleTab& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_aux(const DoubleTab& positions, DoubleTab& tab_valeurs) const
91{
92 const Domaine& le_dom = mon_domaine;
93 IntTrav les_polys;
94 le_dom.chercher_elements(positions, les_polys);
95 return valeur_aux_elems(positions, les_polys, tab_valeurs);
96}
97
98/*! @brief Returns the values of one component of the field at the points specified by their coordinates.
99 *
100 * @param (DoubleTab& positions) the array of coordinates of the computation points
101 * @param (DoubleVect& valeurs) the array of values of the field component at the specified points
102 * @param (int ncomp) the index of the field component to compute
103 */
104template<Champ_Morceaux_Type _TYPE_>
105DoubleVect& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_aux_compo(const DoubleTab& positions, DoubleVect& tab_valeurs, int ncomp) const
106{
107 const Domaine& le_dom = mon_domaine;
108 IntVect les_polys(le_dom.nb_elem());
109 le_dom.chercher_elements(positions, les_polys);
110 return valeur_aux_elems_compo(positions, les_polys, tab_valeurs, ncomp);
111}
112
113/*! @brief Returns the values of the field at the points specified by their coordinates, indicating that the computation points are located in the specified elements.
114 *
115 * @param (DoubleTab&) the array of coordinates of the computation points
116 * @param (IntVect& les_polys) the array of elements in which the computation points are located
117 * @param (DoubleTab& val) the array of field values at the specified points
118 */
119template<Champ_Morceaux_Type _TYPE_>
120DoubleTab& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_aux_elems(const DoubleTab&, const IntVect& polys, DoubleTab& tab_val) const
121{
122 if (tab_val.nb_dim() == 2)
123 {
124 assert((tab_val.dimension(0) == polys.size()) || (tab_val.dimension_tot(0) == polys.size()));
125 assert(tab_val.dimension(1) == nb_compo_);
126 }
127 else erreur_champ_(__func__); // (val.nb_dim() > 2)
128
129 tab_val = 0.;
130 CDoubleTabView ch = valeurs().view_ro();
131 CIntArrView les_polys = polys.view_ro();
132 DoubleTabView val = tab_val.view_rw();
133 int nb_compo = nb_compo_;
134 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), les_polys.size(), KOKKOS_LAMBDA(const int rang_poly)
135 {
136 int p = les_polys(rang_poly);
137 if (p != -1)
138 for (int n = 0; n < nb_compo; n++)
139 val(rang_poly, n) = ch(p, n);
140 });
141 end_gpu_timer(__KERNEL_NAME__);
142
143 return tab_val;
144}
145
146/*! @brief Returns the values of one component of the field at the points specified by their coordinates, indicating that the computation points are located in the specified elements.
147 *
148 * @param (DoubleTab&) the array of coordinates of the computation points
149 * @param (IntVect& les_polys) the array of elements in which the computation points are located
150 * @param (DoubleVect& val) the array of values of the field component at the specified points
151 * @param (int ncomp) the index of the field component to compute
152 */
153template<Champ_Morceaux_Type _TYPE_>
154DoubleVect& TRUSTChamp_Morceaux_generique<_TYPE_>::valeur_aux_elems_compo(const DoubleTab&, const IntVect& les_polys, DoubleVect& val, int ncomp) const
155{
156 assert(val.size_totale() >= les_polys.size());
157 int le_poly;
158 const DoubleTab& ch = valeurs();
159 ToDo_Kokkos("critical");
160 for (int rang_poly = 0; rang_poly < les_polys.size(); rang_poly++)
161 {
162 le_poly = les_polys(rang_poly);
163 val(rang_poly) = (le_poly == -1) ? 0 : ch(le_poly, ncomp);
164 }
165
166 return val;
167}
168
169template<Champ_Morceaux_Type _TYPE_>
171{
172 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Morceaux_Type::UNIFORME);
173
174 if (IS_UNIFORME)
175 {
177 return;
178 }
179 else
180 {
181 OWN_PTR(Champ_base) espace_stockage;
182 const Champ_base *ch = !ref_pb ? nullptr : ref_pb->has_champ(nom_champ_parametre_) ? &ref_pb->get_champ(nom_champ_parametre_) : &ref_pb->get_champ_post(nom_champ_parametre_).get_champ(espace_stockage);
183 const int nb_som_elem = mon_domaine->nb_som_elem();
184 int dim = dimension;
185 bool pb = bool(ref_pb);
186 const int max_parser_size = 200;
187 if (parser.size()>max_parser_size)
188 {
189 Cerr << "Increase max_parser_size to " << parser.size() << " TRUSTChamp_Morceaux_generique<_TYPE_>::mettre_a_jour !" << finl;
191 }
192 Kokkos::Array<ParserView, max_parser_size> psr;
193 for (int i=0; i<parser.size(); i++)
194 {
195 psr[i].set(parser[i]);
196 psr[i].parseString();
197 }
198 bool has_champ = ch != nullptr;
199 CDoubleTabView tab_ch;
200 if (has_champ) tab_ch = ch->valeurs().view_ro();
201 CDoubleTabView coord = mon_domaine->les_sommets().view_ro();
202 CIntTabView les_elems = mon_domaine->les_elems().view_ro();
203 CIntTabView parser_idx = parser_idx_.view_ro();
204 DoubleTabView tab = valeurs().view_wo();
205 const int nb_comp = (int)tab.extent(1);
206 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), mon_domaine->nb_elem_tot(), KOKKOS_LAMBDA(const int i)
207 {
208 /* xs : coordinates of the poly via barycenter of vertices -> not ideal */
209 double xs[3] = {0,0,0};
210 int nb_som = 0, s, r;
211 for (int j = 0; j < nb_som_elem && (s = les_elems(i, j)) >= 0; j++)
212 for (r = 0, nb_som++; r < dim; r++)
213 xs[r] += coord(s, r);
214 for (r = 0; r < dim; r++)
215 xs[r] /= nb_som;
216
217 /* compute each component */
218 double val = has_champ ? tab_ch(i, 0) : 0;
219 for (int k = 0; k < nb_comp; k++)
220 {
221 int idx = parser_idx(i, k);
222 int threadId = psr[idx].acquire();
223 psr[idx].setVar(0, xs[0], threadId); // x
224 psr[idx].setVar(1, xs[1], threadId); // y
225 psr[idx].setVar(2, xs[2], threadId); // z
226 psr[idx].setVar(3, time, threadId); // t
227 if (pb) psr[idx].setVar(4, val, threadId); // val
228 tab(i, k) = psr[idx].eval(threadId);
229 psr[idx].release(threadId);
230 }
231 });
232 end_gpu_timer(__KERNEL_NAME__);
233 }
234}
235
236template<Champ_Morceaux_Type _TYPE_>
241
242template<Champ_Morceaux_Type _TYPE_>
244{
245 static constexpr bool IS_FONC_TXYZ = (_TYPE_ == Champ_Morceaux_Type::FONC_TXYZ);
246 if (IS_FONC_TXYZ || read_pb_instead_of_domain)
247 {
248 ref_pb = ref_cast(Probleme_base, Interprete::objet(nom));
249 mon_domaine = ref_pb->domaine();
250 }
251 else mon_domaine = ref_cast(Domaine, Interprete::objet(nom));
252}
253
254template<Champ_Morceaux_Type _TYPE_>
256{
257 fixer_nb_comp(dim);
258 parser_idx_.resize(0, dim);
259 mon_domaine->creer_tableau_elements(parser_idx_);
260 valeurs_.resize(0, dim);
261 mon_domaine->creer_tableau_elements(valeurs_);
262}
263
264template<Champ_Morceaux_Type _TYPE_>
266{
267 Motcle motlu;
268 int k, poly;
269
270 if (nom != "{")
271 {
272 Cerr << "Error while reading a " << qsj << " . We expected a { instead of " << nom << finl;
274 }
275 is >> motlu;
276 if (motlu != Motcle("defaut"))
277 {
278 Cerr << "Error while reading a " << qsj << " . We expected defaut instead of " << nom << finl;
280 }
281
282 /* default parsers */
283 for (k = 0; k < dim; k++)
284 {
285 Parser_U psr;
286 Nom tmp;
287 is >> tmp;
288 psr.setNbVar(5);
289 psr.setString(tmp);
290 psr.addVar("x"), psr.addVar("y"), psr.addVar("z"), psr.addVar("t");
291 if (ref_pb) psr.addVar("val");
292 psr.parseString();
293
294 for (poly = 0; poly < mon_domaine->nb_elem_tot(); poly++)
295 parser_idx_(poly, k) = parser.size();
296
297 parser.add(psr);
298 }
299
300 is >> nom;
301 while (nom != Nom("}"))
302 {
303 OBS_PTR(Sous_Domaine) refssz = les_sous_domaines.add(mon_domaine->ss_domaine(nom));
304 Sous_Domaine& ssz = refssz.valeur();
305 for (k = 0; k < dim; k++)
306 {
307 Parser_U psr;
308 Nom tmp;
309 is >> tmp;
310 psr.setNbVar(5);
311 psr.setString(tmp);
312 psr.addVar("x"), psr.addVar("y"), psr.addVar("z"), psr.addVar("t");
313 if (ref_pb) psr.addVar("val");
314 psr.parseString();
315
316 for (poly = 0; poly < ssz.nb_elem_tot(); poly++)
317 parser_idx_(ssz(poly), k) = parser.size();
318
319 parser.add(psr);
320 }
321 is >> nom;
322 }
323 return is;
324}
325
326#endif /* TRUSTChamp_Morceaux_generique_TPP_included */
void mettre_a_jour(double temps) override
Time update.
virtual int initialiser(const double temps)
DOES NOTHING.
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
DoubleTab valeurs_
virtual DoubleTab & valeurs()=0
Champ_Uniforme Represents a field that is constant in space and time.
Champ_base()
Default constructor of a Champ_base.
SmallArrOfTID_t & chercher_elements(const DoubleTab &pos, SmallArrOfTID_t &elem, int reel=0) const
Searches for the elements containing the points whose coordinates are specified.
Definition Domaine.cpp:404
int_t nb_elem() const
Definition Domaine.h:131
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)
Sets the number of components of the field.
virtual int nb_comp() const
Definition Field_base.h:56
int nb_compo_
Definition Field_base.h:95
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
static int dimension
Definition Objet_U.h:94
class Parser_U Version of the Parser class, deriving from Objet_U.
Definition Parser_U.h:32
void setString(const std::string &s)
Definition Parser_U.h:194
void setNbVar(int nvar)
Definition Parser_U.h:174
void parseString()
Definition Parser_U.h:116
void addVar(const char *v)
Definition Parser_U.h:183
class Probleme_base It is a Probleme_U that is not a coupling.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
int_t nb_elem_tot() const
Entree & complete_readOn(const int dim, const Nom &qsj, Entree &is, Nom &nom)
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const override
Returns the values of one component of the field at the points specified by their coordinates,...
DoubleVect & valeur_a_elem(const DoubleVect &position, DoubleVect &valeurs, int le_poly) const override
DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const override
Returns the values of the field at the points specified by their coordinates.
const OBS_PTR(Domaine) &domaine() const
void mettre_a_jour(double temps) override
Time update.
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const override
Returns the values of the field at the points specified by their coordinates, indicating that the com...
Champ_base & affecter_(const Champ_base &ch) override
Causes an error! To be overridden by derived classes! Not a pure virtual for development convenience!
DoubleVect & valeur_aux_compo(const DoubleTab &positions, DoubleVect &valeurs, int ncomp) const override
Returns the values of one component of the field at the points specified by their coordinates.
int initialiser(const double temps) override
DOES NOTHING.
DoubleVect & valeur_a(const DoubleVect &position, DoubleVect &valeurs) const override
Returns the value of the field at the point specified by its coordinates.
double valeur_a_elem_compo(const DoubleVect &position, int le_poly, int ncomp) const override
Returns the value of one component of the field at the point specified by its coordinates,...
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
Definition TRUSTTab.h:261
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
Definition TRUSTTab.h:291
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61