16#ifndef TRUSTChamp_Morceaux_generique_TPP_included
17#define TRUSTChamp_Morceaux_generique_TPP_included
19#include <Sous_Domaine.h>
20#include <Champ_Generique_base.h>
21#include <ParserView.h>
23template<Champ_Morceaux_Type _TYPE_>
26 static constexpr bool IS_FONC = (_TYPE_ == Champ_Morceaux_Type::FONC);
28 if (!IS_FONC) not_implemented_champ_<void>(__func__);
41template<Champ_Morceaux_Type _TYPE_>
44 const Domaine& le_dom = mon_domaine;
56template<Champ_Morceaux_Type _TYPE_>
61 const DoubleTab& ch =
valeurs();
62 for (
int k = 0; k <
nb_compo_; k++) val(k) = ch(le_poly, k);
73template<Champ_Morceaux_Type _TYPE_>
76 if (ncomp >
nb_compo_) erreur_champ_(__func__);
78 const DoubleTab& ch =
valeurs();
79 double val = (
nb_compo_ == 1) ? ch(le_poly, 0) : ch(le_poly, ncomp);
89template<Champ_Morceaux_Type _TYPE_>
92 const Domaine& le_dom = mon_domaine;
104template<Champ_Morceaux_Type _TYPE_>
107 const Domaine& le_dom = mon_domaine;
108 IntVect les_polys(le_dom.
nb_elem());
119template<Champ_Morceaux_Type _TYPE_>
122 if (tab_val.
nb_dim() == 2)
127 else erreur_champ_(__func__);
130 CDoubleTabView ch =
valeurs().view_ro();
131 CIntArrView les_polys = polys.view_ro();
132 DoubleTabView val = tab_val.
view_rw();
134 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), les_polys.size(), KOKKOS_LAMBDA(
const int rang_poly)
136 int p = les_polys(rang_poly);
138 for (
int n = 0; n < nb_compo; n++)
139 val(rang_poly, n) = ch(p, n);
141 end_gpu_timer(__KERNEL_NAME__);
153template<Champ_Morceaux_Type _TYPE_>
158 const DoubleTab& ch =
valeurs();
159 ToDo_Kokkos(
"critical");
160 for (
int rang_poly = 0; rang_poly < les_polys.
size(); rang_poly++)
162 le_poly = les_polys(rang_poly);
163 val(rang_poly) = (le_poly == -1) ? 0 : ch(le_poly, ncomp);
169template<Champ_Morceaux_Type _TYPE_>
172 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Morceaux_Type::UNIFORME);
183 const int nb_som_elem = mon_domaine->nb_som_elem();
185 bool pb = bool(ref_pb);
186 const int max_parser_size = 200;
187 if (parser.size()>max_parser_size)
189 Cerr <<
"Increase max_parser_size to " << parser.size() <<
" TRUSTChamp_Morceaux_generique<_TYPE_>::mettre_a_jour !" << finl;
192 Kokkos::Array<ParserView, max_parser_size> psr;
193 for (
int i=0; i<parser.size(); i++)
195 psr[i].set(parser[i]);
196 psr[i].parseString();
198 bool has_champ = ch !=
nullptr;
199 CDoubleTabView tab_ch;
201 CDoubleTabView coord = mon_domaine->les_sommets().view_ro();
202 CIntTabView les_elems = mon_domaine->les_elems().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)
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++)
218 double val = has_champ ? tab_ch(i, 0) : 0;
219 for (
int k = 0; k <
nb_comp; k++)
221 int idx = parser_idx(i, k);
222 int threadId = psr[idx].acquire();
223 psr[idx].setVar(0, xs[0], threadId);
224 psr[idx].setVar(1, xs[1], threadId);
225 psr[idx].setVar(2, xs[2], threadId);
226 psr[idx].setVar(3, time, threadId);
227 if (pb) psr[idx].setVar(4, val, threadId);
228 tab(i, k) = psr[idx].eval(threadId);
229 psr[idx].release(threadId);
232 end_gpu_timer(__KERNEL_NAME__);
236template<Champ_Morceaux_Type _TYPE_>
242template<Champ_Morceaux_Type _TYPE_>
245 static constexpr bool IS_FONC_TXYZ = (_TYPE_ == Champ_Morceaux_Type::FONC_TXYZ);
249 mon_domaine = ref_pb->domaine();
254template<Champ_Morceaux_Type _TYPE_>
261 mon_domaine->creer_tableau_elements(
valeurs_);
264template<Champ_Morceaux_Type _TYPE_>
272 Cerr <<
"Error while reading a " << qsj <<
" . We expected a { instead of " << nom << finl;
276 if (motlu !=
Motcle(
"defaut"))
278 Cerr <<
"Error while reading a " << qsj <<
" . We expected defaut instead of " << nom << finl;
283 for (k = 0; k < dim; k++)
291 if (ref_pb) psr.
addVar(
"val");
294 for (poly = 0; poly < mon_domaine->nb_elem_tot(); poly++)
301 while (nom !=
Nom(
"}"))
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++)
313 if (ref_pb) psr.
addVar(
"val");
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.
virtual DoubleTab & valeurs()=0
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.
Class defining operators and methods for all reading operation in an input flow (file,...
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
virtual int nb_comp() const
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.
class Nom: a character string for naming TRUST objects.
class Parser_U Version of the Parser class, deriving from Objet_U.
void setString(const std::string &s)
void addVar(const char *v)
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.
int_t nb_elem_tot() const
void interprete_get_domaine(const Nom &nom)
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,...
void creer_tabs(const int)
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
bool read_pb_instead_of_domain
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,...
_SIZE_ dimension_tot(int) const override
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
_SIZE_ dimension(int d) const
_SIZE_ size_totale() const