TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTChamp_Don_generique.tpp
1/****************************************************************************
2* Copyright (c) 2024, 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_Don_generique_TPP_included
17#define TRUSTChamp_Don_generique_TPP_included
18
19template <Champ_Don_Type _TYPE_>
21{
22 const DoubleTab& tab = valeurs();
23 os << tab.size() << " ";
24 for (int i = 0; i < tab.size(); i++) os << tab(0, i);
25 return os;
26}
27
28template <Champ_Don_Type _TYPE_>
30{
31 static constexpr bool IS_TXYZ = (_TYPE_ == Champ_Don_Type::TXYZ);
32
33 if (!IS_TXYZ) /* XYZ ou LU */
35 else
36 {
38 int nb_elems = mon_domaine->nb_elem();
39 DoubleTab& mes_val = valeurs();
40 DoubleTab positions(nb_elems, dimension);
41 mettre_a_jour_positions(positions);
42 eval_fct(positions, temps(), mes_val);
43 mes_val.echange_espace_virtuel();
44 }
45}
46
47template <Champ_Don_Type _TYPE_>
48double TRUSTChamp_Don_generique<_TYPE_>::valeur_a_compo(const DoubleVect& x, int ncomp) const
49{
50 static constexpr bool IS_XYZ = (_TYPE_ == Champ_Don_Type::XYZ);
51 if (!IS_XYZ)
52 return Champ_Don_base::valeur_a_compo(x, ncomp); // simple call for TXYZ or LU !
53 else
54 {
55 if (ncomp > nb_compo_) erreur_champ_(__func__); // asking ncomp > nb_compo_ ?????
56
57 DoubleTab positions(1, dimension), val_fct(1);
58 for (int d = 0; d < dimension; d++) positions(0, d) = x(d);
59 eval_fct(positions, val_fct, ncomp);
60 return val_fct(0);
61 }
62}
63
64template <Champ_Don_Type _TYPE_>
66{
67 positions = 0.0;
68 const int nb_elems = mon_domaine->nb_elem(), D = dimension;
69 const IntTab& les_Polys = mon_domaine->les_elems();
70 for (int num_elem = 0; num_elem < nb_elems; num_elem++)
71 {
72 int nb_som = 0;
73 for (int s = 0, num_som; s < les_Polys.dimension(1); s++)
74 if ((num_som = les_Polys(num_elem, s)) >= 0)
75 {
76 for (int d = 0; d < D; d++)
77 positions(num_elem, d) += mon_domaine->coord(num_som, d);
78 nb_som++;
79 }
80 for (int d = 0; d < D; d++)
81 positions(num_elem, d) /= nb_som;
82 }
83}
84
85/*! @brief Returns the value of the field at the point specified by its coordinates.
86 *
87 * @param (DoubleVect& x) the coordinates of the computation point
88 * @param (DoubleVect& val) the value of the field at the specified point
89 */
90template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
91std::enable_if_t<T != Champ_Don_Type::LU, DoubleVect&>
92TRUSTChamp_Don_generique<_TYPE_>::valeur_a_(const DoubleVect& x, DoubleVect& val) const
93{
94 static constexpr bool IS_XYZ = (_TYPE_ == Champ_Don_Type::XYZ);
95 if (val.size() != nb_compo_) erreur_champ_(__func__); // DoubleVect val doesn't have the correct size
96
97 IS_XYZ ? eval_fct(x,val) : eval_fct(x,temps(),val);
98 return val;
99}
101template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
102std::enable_if_t<T == Champ_Don_Type::LU, DoubleVect&>
103TRUSTChamp_Don_generique<_TYPE_>::valeur_a_(const DoubleVect& x, DoubleVect& val) const
104{
105 IntVect le_poly(1);
106 mon_domaine->chercher_elements(x,le_poly);
107 return valeur_a_elem(x,val,le_poly(0));
108}
109
110/*! @brief Returns the value of the field at the point specified by its coordinates, indicating that this point is located in a specified element.
111 *
112 * @param (DoubleVect&) the coordinates of the computation point
113 * @param (DoubleVect& val) the value of the field at the specified point
114 * @param (int le_poly) the element in which the computation point is located
115 */
116template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
117std::enable_if_t<T != Champ_Don_Type::LU, DoubleVect&>
118TRUSTChamp_Don_generique<_TYPE_>::valeur_a_elem_(const DoubleVect& x, DoubleVect& val, int ) const
119{
120 return valeur_a(x,val);
121}
122
123template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
124std::enable_if_t<T == Champ_Don_Type::LU, DoubleVect&>
125TRUSTChamp_Don_generique<_TYPE_>::valeur_a_elem_(const DoubleVect& , DoubleVect& val, int le_poly) const
126{
127 if (val.size() != nb_compo_) erreur_champ_(__func__); // DoubleVect val doesn't have the correct size
128
129 const DoubleTab& ch = valeurs();
130 for (int k = 0; k < nb_compo_; k++) val(k) = ch(le_poly, k);
131
132 return val;
133}
134
135/*! @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.
136 *
137 * @param (DoubleVect&) the coordinates of the computation point
138 * @param (int le_poly) the element in which the computation point is located
139 * @param (int ncomp) the index of the field component to compute
140 */
141template <Champ_Don_Type _TYPE_> template <Champ_Don_Type T>
142std::enable_if_t<T != Champ_Don_Type::TXYZ, double> /* XYZ ou LU */
143TRUSTChamp_Don_generique<_TYPE_>::valeur_a_elem_compo_(const DoubleVect& x, int le_poly, int ncomp) const
144{
145 static constexpr bool IS_XYZ = (_TYPE_ == Champ_Don_Type::XYZ);
146 if (ncomp > nb_compo_) erreur_champ_(__func__); // asking ncomp > nb_compo_ ?????
147
148 return IS_XYZ ? valeur_a_compo(x,ncomp) : valeurs()(le_poly,ncomp) /* LU */;
149}
150
151template <Champ_Don_Type _TYPE_> template <Champ_Don_Type T>
152std::enable_if_t<T == Champ_Don_Type::TXYZ, double>
153TRUSTChamp_Don_generique<_TYPE_>::valeur_a_elem_compo_(const DoubleVect& x, int , int ncomp) const
154{
155 DoubleTab positions(1, dimension);
156 for (int d = 0; d < dimension; d++) positions(0, d) = x(d);
157
158 DoubleVect val_fct(1);
159 eval_fct(positions, temps(), val_fct, ncomp);
160
161 return val_fct(0);
162}
163
164/*! @brief Returns the values of the field at the points specified by their coordinates.
165 *
166 * @param (DoubleTab& x) the array of coordinates of the computation points
167 * @param (DoubleTab& val) the array of field values at the specified points
168 */
169template <Champ_Don_Type _TYPE_> template <Champ_Don_Type T>
170std::enable_if_t<T != Champ_Don_Type::LU, DoubleTab&>
171TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_(const DoubleTab& x, DoubleTab& val) const
172{
173 static constexpr bool IS_XYZ = (_TYPE_ == Champ_Don_Type::XYZ);
174
175 if (val.nb_dim() == 1) assert(nb_compo_ == 1);
176 else if (val.nb_dim() == 2) assert(val.dimension(1) == nb_compo_);
177 else erreur_champ_(__func__); // DoubleTab val has more than 2 entries !
178
179 IS_XYZ ? eval_fct(x,val) : eval_fct(x,temps(),val);
180 return val;
181}
182
183template <Champ_Don_Type _TYPE_> template <Champ_Don_Type T>
184std::enable_if_t<T == Champ_Don_Type::LU, DoubleTab&>
185TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_(const DoubleTab& x, DoubleTab& val) const
186{
187 IntVect les_polys(mon_domaine->nb_elem());
188 mon_domaine->chercher_elements(x,les_polys);
189 return valeur_aux_elems(x,les_polys,val); // VTABLE for Champ_som_lu
190}
191
192/*! @brief Returns the values of one component of the field at the points specified by their coordinates.
193 *
194 * @param (DoubleVect& x) the array of coordinates of the computation points
195 * @param (DoubleVect& valeurs) the array of values of the field component at the specified points
196 * @param (int ncomp) the index of the field component to compute
197 */
198template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
199std::enable_if_t<T != Champ_Don_Type::LU, DoubleVect&>
200TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_compo_(const DoubleTab& x, DoubleVect& val, int ncomp) const
201{
202 static constexpr bool IS_XYZ = (_TYPE_ == Champ_Don_Type::XYZ);
203 IS_XYZ ? eval_fct(x,val,ncomp) : eval_fct(x,temps(),val,ncomp);
204 return val;
205}
206
207template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
208std::enable_if_t<T == Champ_Don_Type::LU, DoubleVect&>
209TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_compo_(const DoubleTab& x, DoubleVect& val, int ncomp) const
210{
211 IntVect les_polys(mon_domaine->nb_elem());
212 mon_domaine->chercher_elements(x,les_polys);
213 return valeur_aux_elems_compo(x,les_polys,val,ncomp); // VTABLE for Champ_som_lu
214}
215
216/*! @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.
217 *
218 * @param (DoubleTab&) the array of coordinates of the computation points
219 * @param (IntVect& les_polys) the array of elements in which the computation points are located (unused)
220 * @param (DoubleTab& val) the array of field values at the specified points
221 */
222template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
223std::enable_if_t<T != Champ_Don_Type::LU, DoubleTab&>
224TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_elems_(const DoubleTab& x, const IntVect&, DoubleTab& val) const
225{
226 return valeur_aux(x, val);
227}
228
229template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
230std::enable_if_t<T == Champ_Don_Type::LU, DoubleTab&>
231TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_elems_(const DoubleTab&, const IntVect& les_polys, DoubleTab& val) const
232{
233 if (val.nb_dim() > 2) erreur_champ_(__func__); // DoubleTab val don't have 2 entries
234
235 int p;
236 const DoubleTab& ch = valeurs();
237 val = 0.;
238
239 for (int rang_poly = 0; rang_poly < les_polys.size(); rang_poly++)
240 if ((p = les_polys(rang_poly)) != -1)
241 for (int n = 0; n < nb_compo_; n++) val(rang_poly, n) = ch(p, n);
242
243 return val;
244}
245
246/*! @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.
247 *
248 * @param (DoubleTab& x) the array of coordinates of the computation points
249 * @param (IntVect& les_polys) the array of elements in which the computation points are located
250 * @param (DoubleVect& val) the array of values of the field component at the specified points
251 * @param (int ncomp) the index of the field component to compute
252 */
253template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
254std::enable_if_t<T != Champ_Don_Type::LU, DoubleVect&>
255TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_elems_compo_(const DoubleTab& x, const IntVect&, DoubleVect& val, int ncomp) const
256{
257 return valeur_aux_compo(x, val, ncomp);
258}
259
260template <Champ_Don_Type _TYPE_> template<Champ_Don_Type T>
261std::enable_if_t<T == Champ_Don_Type::LU, DoubleVect&>
262TRUSTChamp_Don_generique<_TYPE_>::valeur_aux_elems_compo_(const DoubleTab& , const IntVect& les_polys, DoubleVect& val, int ncomp) const
263{
264 assert(val.size_totale() >= les_polys.size());
265 const DoubleTab& ch = valeurs();
266
267 for (int rang_poly = 0; rang_poly < les_polys.size(); rang_poly++)
268 {
269 int le_poly = les_polys(rang_poly);
270 if (le_poly == -1) val(rang_poly) = 0;
271 else val(rang_poly) = ch(le_poly, ncomp);
272 }
273 return val;
274}
275
276#endif /* TRUSTChamp_Don_generique_TPP_included */
void mettre_a_jour(double temps) override
Time update.
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
virtual double changer_temps(const double t)
Sets the time at which the field is defined.
virtual double valeur_a_compo(const DoubleVect &position, int ncomp) const
Computes the point value of the component "compo" of the field at the point with coordinates pos.
int nb_compo_
Definition Field_base.h:95
static int dimension
Definition Objet_U.h:94
void eval_fct(const DoubleTab &positions, DoubleTab &val) const
Definition Parser_Eval.h:36
Base class for output streams.
Definition Sortie.h:52
void mettre_a_jour(double) override
Time update.
Sortie & printOn(Sortie &os) const override
Writes the object to an output stream. Virtual method to override.
double valeur_a_compo(const DoubleVect &position, int ncomp) const override
Computes the point value of the component "compo" of the field at the point with coordinates pos.
DoubleVect & valeur_a_elem(const DoubleVect &position, DoubleVect &vals, int le_poly) const override
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")