TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_Face_PolyMAC_CDO.cpp
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#include <Champ_Fonc_Face_PolyMAC_CDO.h>
17#include <Domaine_PolyMAC_CDO.h>
18#include <Champ_Uniforme.h>
19#include <TRUSTTab.h>
20#include <Domaine.h>
21
22Implemente_instanciable(Champ_Fonc_Face_PolyMAC_CDO,"Champ_Fonc_Face_PolyMAC_CDO",Champ_Fonc_base);
23
24Sortie& Champ_Fonc_Face_PolyMAC_CDO::printOn(Sortie& os) const { return os << que_suis_je() << " " << le_nom(); }
25
27
29{
30 // use the same kind of code as in Champ_Fonc_P0_base, but retrieve the number of faces instead of the number of elements
31 // note: the code used in Champ_Fonc_P0_base::fixer_nb_valeurs_nodales() to retrieve the discrete domain is somewhat surprising...
32 const Champ_Fonc_base& self = ref_cast(Champ_Fonc_base, *this);
33 const Domaine_VF& le_dom_vf = ref_cast(Domaine_VF, self.domaine_dis_base());
34
35 assert(n == le_dom_vf.nb_faces());
36
37 const MD_Vector& md = le_dom_vf.md_vector_faces();
38 // Problem: nb_comp equals 2 but we only want one dimension !!!
39 // HACK:
40 int old_nb_compo = nb_compo_;
42
44 nb_compo_ = old_nb_compo;
45 return n;
46
47}
49{
50 const DoubleTab& v = ch.valeurs();
51 DoubleTab& val = valeurs();
52 const Domaine_VF& domaine_PolyMAC_CDO = ref_cast(Domaine_VF, le_dom_VF.valeur());
53 int nb_faces = domaine_PolyMAC_CDO.nb_faces();
54 const DoubleVect& surface = domaine_PolyMAC_CDO.face_surfaces();
55 const DoubleTab& normales = domaine_PolyMAC_CDO.face_normales();
56
57 if (sub_type(Champ_Uniforme, ch))
58 {
59 for (int num_face = 0; num_face < nb_faces; num_face++)
60 {
61 double vn = 0;
62 for (int dir = 0; dir < dimension; dir++)
63 vn += v(0, dir) * normales(num_face, dir);
64
65 vn /= surface(num_face);
66 val(num_face) = vn;
67 }
68 }
69 else if (nb_compo_ == dimension)
70 {
71 const DoubleTab& xv = domaine_PolyMAC_CDO.xv();
72 DoubleTab eval(val.dimension_tot(0), dimension);
73 ch.valeur_aux(xv, eval);
74 for (int num_face = 0; num_face < nb_faces; num_face++)
75 {
76 double vn = 0;
77 for (int dir = 0; dir < dimension; dir++)
78 vn += eval(num_face, dir) * normales(num_face, dir);
79
80 vn /= surface(num_face);
81 val(num_face) = vn;
82 }
83 }
84 else if (nb_compo_ == 1)
85 {
86 const DoubleTab& xv = domaine_PolyMAC_CDO.xv();
87 ch.valeur_aux(xv, val);
88 }
89 else
90 abort();
91 return *this;
92}
93
94DoubleVect& Champ_Fonc_Face_PolyMAC_CDO::valeur_a_elem(const DoubleVect& position, DoubleVect& result, int poly) const
95{
96 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
97 throw;
98}
99
100double Champ_Fonc_Face_PolyMAC_CDO::valeur_a_elem_compo(const DoubleVect& position, int poly, int ncomp) const
101{
102 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
103 throw;
104}
105
106
107void Champ_Fonc_Face_PolyMAC_CDO::interp_valeurs_elem(const DoubleTab& inco, DoubleTab& val) const
108{
110 const DoubleTab& xv = domaine.xv(), &xp = domaine.xp();
111 const DoubleVect& fs = domaine.face_surfaces(), &ve = domaine.volumes();
112 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
113 int e, f, j, d, D = dimension, n, N = inco.line_size();
114 assert(val.line_size() == N * D);
115
116 val = 0;
117 for (e = 0; e < val.dimension(0); e++)
118 {
119 for (n = 0; n < N * D; n++) val(e, n) = 0;
120 for (j = 0; j < e_f.dimension(1) && (f = e_f(e, j)) >= 0; j++)
121 for (d = 0; d < D; d++)
122 for (n = 0; n < N; n++)
123 val(e, N * d + n) += fs(f) / ve(e) * (xv(f, d) - xp(e, d)) * (e == f_e(f, 0) ? 1 : -1) * (inco.nb_dim() == 1 ? inco(f) : inco(f, n));
124 }
125}
126
127DoubleTab& Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_elems(const DoubleTab& positions,
128 const IntVect& les_polys,
129 DoubleTab& val) const
130{
131 const Champ_base& cha=le_champ();
132 const Domaine_PolyMAC_CDO& domaine_VF = ref_cast(Domaine_PolyMAC_CDO, domaine_vf());
133 int nb_compo=cha.nb_comp(), N = cha.valeurs().line_size(), D = dimension, nf_tot = domaine_VF.nb_faces_tot();
134 assert(val.line_size() == nb_compo );
135 // XXX : TODO Check this assert (positions and not val)
136 assert((positions.dimension(0) == les_polys.size())||(positions.dimension_tot(0) == les_polys.size()));
137 assert((val.dimension(0) == les_polys.size())||(val.dimension_tot(0) == les_polys.size()));
138 assert((cha.valeurs().dimension_tot(0)==nf_tot+D*domaine_VF.nb_elem_tot())||(cha.valeurs().dimension_tot(0)==nf_tot));
139
140 if (val.nb_dim() > 2) Process::exit(que_suis_je() + "Le DoubleTab val a plus de 2 entrees");
141 if (nb_compo == 1) Process::exit("TRUST error in Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_elems : A scalar field cannot be of Champ_Face type !");
142
143 DoubleTab ve(0, N * D);
144
145 if (cha.valeurs().dimension_tot(0)==nf_tot)
146 {
147 domaine_VF.domaine().creer_tableau_elements(ve);
148 interp_valeurs_elem(cha.valeurs(), ve);
149 for (int p = 0; p < les_polys.size(); p++)
150 for (int r = 0, e = les_polys(p); e < domaine_VF.nb_elem() && r < N * D; r++)
151 val(p, r) = (e==-1) ? 0. : ve(e, r);
152 }
153 else if (cha.valeurs().dimension_tot(0)==nf_tot+D*domaine_VF.nb_elem_tot())
154 for (int p = 0; p < les_polys.size(); p++)
155 for (int e = les_polys(p), d = 0; e < domaine_VF.nb_elem() && d < D; d++)
156 for (int n = 0; n < N; n++)
157 val(p, N * d + n) = cha.valeurs()(nf_tot + D * e + d, n);
158 else Process::exit("TRUST error in Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_elems : curious number of faces !");
159
160 return val;
161}
162
163DoubleTab& Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_faces(DoubleTab& val) const
164{
165 const Champ_base& cha=le_champ();
166 int nb_compo=cha.nb_comp(), n, N = cha.valeurs().line_size(), d, D = dimension;
167
168 if (nb_compo == 1) Process::exit("TRUST error in Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_faces : A scalar field cannot be of Champ_Face type !");
169
170 const Domaine_VF& domaine = domaine_vf();
171 val.resize(domaine.nb_faces(), N * D);
172
173 for (int f = 0; f < domaine.nb_faces(); f++)
174 for (d = 0; d < D; d++)
175 for (n = 0; n < N; n++) val(f, N * d + n) = cha.valeurs()(f, n) * domaine.face_normales(f, d) / domaine.face_surfaces(f);
176 return val;
177}
178
179DoubleVect& Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_elems_compo(const DoubleTab& positions, const IntVect& les_polys, DoubleVect& val, int ncomp) const
180{
181 const Champ_base& cha=le_champ();
182 int nb_compo=cha.nb_comp();
183 const Domaine_PolyMAC_CDO& domaine_VF = ref_cast(Domaine_PolyMAC_CDO,domaine_vf());
184 // const Domaine& domaine_geom = domaine_VDF.domaine();
185 const DoubleTab& normales = domaine_VF.face_normales();
186 // const DoubleVect& surfaces = domaine_VF.face_surfaces();
187 const IntTab& elem_faces = domaine_VF.elem_faces();
188
189 const DoubleTab& ch = cha.valeurs();
190
191 if (nb_compo == 1)
192 {
193 Cerr<<"Champ_Face_implementation::valeur_aux_elems"<<finl;
194 Cerr <<"A scalar field cannot be of Champ_Face type." << finl;
196 }
197 else // (nb_compo != 1)
198 {
199 ArrOfDouble s(nb_compo);
200 for(int rang_poly=0; rang_poly<les_polys.size(); rang_poly++)
201 {
202 int le_poly=les_polys(rang_poly);
203 if (le_poly == -1)
204 val(rang_poly) = 0;
205 else
206 {
207 double vale=0;
208 s=0;
209 int nb_faces_elem_max=elem_faces.dimension(1);
210 for (int nf=0; nf<nb_faces_elem_max; nf++)
211 {
212 int face=elem_faces(le_poly,nf);
213 if(face<0)
214 break;
215 else
216 {
217 vale += ch(face) * std::fabs(normales(face, ncomp));
218 s[ncomp] += std::fabs(normales(face, ncomp));
219 }
220 }
221 val(rang_poly)=vale/s[ncomp];
222 }
223 }
224 }
225 return val;
226}
227
228DoubleTab& Champ_Fonc_Face_PolyMAC_CDO::remplir_coord_noeuds(DoubleTab& positions) const
229{
230 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
231 throw;
232}
233
234int Champ_Fonc_Face_PolyMAC_CDO::remplir_coord_noeuds_et_polys(DoubleTab& positions, IntVect& polys) const
235{
236 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
237 throw;
238}
239
240DoubleTab& Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_sommets(const Domaine& domain, DoubleTab& result) const
241{
242 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
243 throw;
244}
245
246DoubleVect& Champ_Fonc_Face_PolyMAC_CDO::valeur_aux_sommets_compo(const Domaine& domain, DoubleVect& result, int ncomp) const
247{
248 Cerr << "Champ_Fonc_Face_PolyMAC_CDO::" <<__func__ << " is not coded !" << finl;
249 throw;
250}
251
253{
254 return Champ_Fonc_base::mettre_a_jour(un_temps);
255}
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &polys, DoubleTab &result) const override
Causes an error! Must be overridden by derived classes.
DoubleVect & valeur_a_elem(const DoubleVect &position, DoubleVect &result, int poly) const override
Causes an error! Must be overridden by derived classes.
DoubleTab & valeur_aux_faces(DoubleTab &val) const override
Returns the field value at the faces.
void mettre_a_jour(double) override
Time update of the field.
DoubleTab & valeur_aux_sommets(const Domaine &domain, DoubleTab &result) const override
Returns the values at the vertices of the Domain dom.
int remplir_coord_noeuds_et_polys(DoubleTab &positions, IntVect &polys) const override
DOES NOTHING TO override in derived classes.
Champ_base & affecter_(const Champ_base &) override
Assigns a Champ_base to a Champ_Fonc_base.
void interp_valeurs_elem(const DoubleTab &tab_ch, DoubleTab &val) const
double valeur_a_elem_compo(const DoubleVect &position, int poly, int ncomp) const override
Causes an error! Must be overridden by derived classes.
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &polys, DoubleVect &result, int ncomp) const override
Causes an error! Must be overridden by derived classes.
int fixer_nb_valeurs_nodales(int n) override
Sets the number of degrees of freedom per component.
DoubleVect & valeur_aux_sommets_compo(const Domaine &domain, DoubleVect &result, int ncomp) const override
Returns the compo-th value at the vertices of dom.
DoubleTab & remplir_coord_noeuds(DoubleTab &positions) const override
DOES NOTHING TO override in derived classes.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
virtual const Domaine & domaine() const
virtual const Domaine_VF & domaine_vf() const
void mettre_a_jour(double temps) override
Time update of the field.
virtual void creer_tableau_distribue(const MD_Vector &, RESIZE_OPTIONS=RESIZE_OPTIONS::COPY_INIT)
const Domaine_dis_base & domaine_dis_base() const override
virtual DoubleTab & valeurs()=0
Champ_Uniforme Represents a field that is constant in space and time.
Champ_base()
Default constructor of a Champ_base.
virtual DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const
Causes an error! Must be overridden by derived classes.
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates a parallel array of values at elements.
Definition Domaine.cpp:850
class Domaine_VF
Definition Domaine_VF.h:44
virtual const DoubleVect & face_surfaces() const
Definition Domaine_VF.h:51
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
const MD_Vector & md_vector_faces() const
Definition Domaine_VF.h:158
int nb_faces_tot() const
Returns the total number of faces.
Definition Domaine_VF.h:481
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
int nb_elem_tot() const
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Nom & le_nom() const override
Returns the name of the field.
virtual int nb_comp() const
Definition Field_base.h:56
int nb_compo_
Definition Field_base.h:95
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67