TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUSTChamp_Divers_generique.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 TRUSTChamp_Divers_generique_included
17#define TRUSTChamp_Divers_generique_included
18
19#include <Champ_Don_base.h>
20
21enum class Champ_Divers_Type { INUTILE , UNIFORME , CANAL };
22
23template <Champ_Divers_Type _TYPE_>
25{
26public:
28 {
29 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME), IS_CANAL = (_TYPE_ == Champ_Divers_Type::CANAL);
30 if (IS_UNIFORME) return Champ_Don_base::affecter(ch);
31 if (IS_CANAL) Champ_base::affecter_erreur();
32
33 return *this;
34 }
35
36 DoubleVect& valeur_a(const DoubleVect&, DoubleVect& tab_valeurs) const override
37 {
38 assert (_TYPE_ != Champ_Divers_Type::CANAL);
39 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
40 if (IS_UNIFORME)
41 {
42 for (int j = 0; j < nb_comp(); j++) tab_valeurs(j) = valeurs_(0, j);
43 return tab_valeurs;
44 }
45 else
46 return not_implemented_champ_<DoubleVect&>(__func__); /* Cas INUTILE : methode sur-chargee pour CANAL */
47 }
48
49 double valeur_a_compo(const DoubleVect& x, int ncomp) const override
50 {
51 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME), IS_CANAL = (_TYPE_ == Champ_Divers_Type::CANAL);
52 if (IS_UNIFORME) return valeurs_(0,ncomp);
53 else if (IS_CANAL) return Champ_Don_base::valeur_a_compo(x,ncomp);
54 else return not_implemented_champ_<double>(__func__); /* INUTILE */
55 }
56
57 DoubleVect& valeur_a_elem(const DoubleVect& positions, DoubleVect& tab_valeurs, int) const override
58 {
59 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME), IS_CANAL = (_TYPE_ == Champ_Divers_Type::CANAL);
60 if (IS_UNIFORME)
61 {
62 for (int j = 0; j < nb_comp(); j++) tab_valeurs(j) = valeurs_(0, j);
63 return tab_valeurs;
64 }
65
66 else if (IS_CANAL) return valeur_a(positions, tab_valeurs); // from VTABLE
67
68 else return not_implemented_champ_<DoubleVect&>(__func__); /* INUTILE */
69 }
70
71 double valeur_a_elem_compo(const DoubleVect&, int, int ncomp) const override
72 {
73 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
74 return IS_UNIFORME ? valeurs_(0,ncomp) : not_implemented_champ_<double>(__func__); /* methode sur-chargee pour CANAL */
75 }
76
77 DoubleTab& valeur_aux(const DoubleTab& , DoubleTab& tab_valeurs) const override
78 {
79 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
80 if (IS_UNIFORME)
81 {
82 int size = tab_valeurs.dimension_tot(0); // GF dimension_tot pour que la ligne soit valide pour les champs P1B
83 int nb_comp = tab_valeurs.line_size();
84 bool kernelOnDevice = tab_valeurs.checkDataOnDevice();
85 if (kernelOnDevice)
86 {
87#ifdef KOKKOS
88 CDoubleTabView valeurs = valeurs_.view_ro();
89 DoubleTabView tab_valeurs_v = tab_valeurs.view_rw();
90 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {size, nb_comp }),
91 KOKKOS_LAMBDA(const int i, const int j)
92 {
93 tab_valeurs_v(i, j) = valeurs(0, j);
94 });
95 end_gpu_timer(__KERNEL_NAME__, kernelOnDevice);
96#endif
97 }
98 else
99 {
100 for (int i = 0; i < size; i++)
101 for (int j = 0; j < nb_comp; j++)
102 tab_valeurs(i, j) = valeurs_(0, j);
103 }
104 return tab_valeurs;
105 }
106 else
107 return not_implemented_champ_<DoubleTab&>(__func__); // voir classes filles ...
108 }
109
110 DoubleVect& valeur_aux_compo(const DoubleTab&, DoubleVect& tab_valeurs, int ncomp) const override
111 {
112 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
113 if (IS_UNIFORME) return tab_valeurs = valeurs_(0, ncomp);
114 else return not_implemented_champ_<DoubleVect&>(__func__); // BOOM
115 }
116
117 DoubleTab& valeur_aux_elems(const DoubleTab& positions, const IntVect&, DoubleTab& tab_valeurs) const override
118 {
119 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
120 if (IS_UNIFORME)
121 {
122 int size = tab_valeurs.dimension(0);
123 int nb_comp = tab_valeurs.line_size();
124 bool kernelOnDevice = tab_valeurs.checkDataOnDevice();
125 if (kernelOnDevice)
126 {
127#ifdef KOKKOS
128 CDoubleTabView valeurs = valeurs_.view_ro();
129 DoubleTabView tab_valeurs_v = tab_valeurs.view_rw();
130 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {size, nb_comp}),
131 KOKKOS_LAMBDA(const int i, const int j)
132 {
133 tab_valeurs_v(i, j) = valeurs(0, j);
134 });
135 end_gpu_timer(__KERNEL_NAME__, kernelOnDevice);
136#endif
137 }
138 else
139 {
140 for (int i = 0; i < size; i++)
141 for (int j = 0; j < nb_comp; j++)
142 tab_valeurs(i, j) = valeurs_(0, j);
143 }
144 return tab_valeurs;
145 }
146
147 else return valeur_aux(positions, tab_valeurs); // from VTABLE
148 }
149
150 DoubleVect& valeur_aux_elems_compo(const DoubleTab& positions, const IntVect&, DoubleVect& tab_valeurs, int ncomp) const override
151 {
152 static constexpr bool IS_UNIFORME = (_TYPE_ == Champ_Divers_Type::UNIFORME);
153 if (IS_UNIFORME) return tab_valeurs = valeurs_(0, ncomp);
154
155 else return valeur_aux_compo(positions, tab_valeurs, ncomp); // from VTABLE
156 }
157};
158
159#endif /* TRUSTChamp_Divers_generique_included */
classe Champ_Don_base classe de base des Champs donnes (non calcules)
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
DoubleTab valeurs_
Champ_base()
Constructeur par defaut d'un Champ_base.
Champ_base & affecter(const Champ_base &)
Affecter un champ dans un autre.
void affecter_erreur()
virtual double valeur_a_compo(const DoubleVect &position, int ncomp) const
Calcule la valeur ponctuelle de la composante "compo" du champ au point de coordonnees pos.
virtual int nb_comp() const
Definition Field_base.h:56
DoubleVect & valeur_a_elem(const DoubleVect &positions, DoubleVect &tab_valeurs, int) const override
provoque une erreur ! doit etre surchargee par les classes derivees
Champ_base & affecter(const Champ_base &ch)
DoubleVect & valeur_aux_compo(const DoubleTab &, DoubleVect &tab_valeurs, int ncomp) const override
Idem que valeur_aux(const DoubleTab &, DoubleTab &), mais calcule uniquement la composante compo du c...
DoubleTab & valeur_aux(const DoubleTab &, DoubleTab &tab_valeurs) const override
Provoque une erreur ! Doit etre surchargee par les classes derivees.
DoubleVect & valeur_a(const DoubleVect &, DoubleVect &tab_valeurs) const override
Calcule les "valeurs" du champ au point de coordonnees "pos".
double valeur_a_elem_compo(const DoubleVect &, int, int ncomp) const override
provoque une erreur ! doit etre surchargee par les classes derivees
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &, DoubleTab &tab_valeurs) const override
provoque une erreur ! doit etre surchargee par les classes derivees
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &, DoubleVect &tab_valeurs, int ncomp) const override
provoque une erreur ! doit etre surchargee par les classes derivees
double valeur_a_compo(const DoubleVect &x, int ncomp) const override
Calcule la valeur ponctuelle de la composante "compo" du champ au point de coordonnees pos.
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
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
int line_size() const
Definition TRUSTVect.tpp:67