TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_P0_VDF.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <LecFicDiffuse.h>
17#include <Champ_P0_VDF.h>
18#include <Domaine_VDF.h>
19
20Implemente_instanciable(Champ_P0_VDF,"Champ_P0_VDF",Champ_Inc_P0_base);
21
22Sortie& Champ_P0_VDF::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
23Entree& Champ_P0_VDF::readOn(Entree& s) { return s ; }
24
26{
27 return ref_cast(Domaine_VDF, le_dom_VF.valeur());
28}
29
30DoubleTab& Champ_P0_VDF::remplir_coord_noeuds(DoubleTab& positions) const
31{
32 const Domaine_VDF& domaine_vdf = ref_cast(Domaine_VDF, domaine_dis_base());
33 const DoubleTab& xp = domaine_vdf.xp();
34 int nb_poly = domaine_vdf.nb_elem();
35 if ((xp.dimension(0) == nb_poly) && (xp.dimension(1) == dimension))
36 positions.ref(xp);
37 else
38 {
39 const Domaine& domaine = domaine_vdf.domaine();
40 positions.resize(nb_poly, dimension);
41 domaine.calculer_centres_gravite(positions);
42 }
43 return positions;
44}
45
46/*! @brief Returns the P0-average of the field, i.e. the sum, divided by the total domain volume,
47 *
48 * @brief of the piecewise-constant values multiplied by the element volumes.
49 *
50 * @param porosite_elem Porosity at elements.
51 * @return Average value vector.
52 */
53DoubleVect Champ_P0_VDF::moyenne(const DoubleVect& porosite_elem) const
54{
55 const DoubleVect& volumes = domaine_VDF().volumes();
56 const DoubleTab& val = valeurs();
57
58 int k, nb_compo = nb_comp();
59 DoubleVect moy(nb_compo);
60 moy = 0;
61 double coef, sum_vol = 0;
62
63 for (int num_elem = 0; num_elem < domaine_VDF().nb_elem(); num_elem++)
64 {
65 coef = porosite_elem(num_elem) * volumes(num_elem);
66 for (k = 0; k < nb_compo; k++)
67 moy[k] += val(num_elem, k) * coef;
68 sum_vol += coef;
69 }
70
71 moy /= sum_vol;
72 return moy;
73}
74
75/*! @brief Computes the P0-average of the k-th component of the field.
76 *
77 * @param porosite_elem Porosity at elements.
78 * @param ncomp Component index.
79 * @return Average value of the component.
80 */
81double Champ_P0_VDF::moyenne(const DoubleVect& porosite_elem, int ncomp) const
82{
83 const DoubleVect& volumes = domaine_VDF().volumes();
84 const DoubleTab& val = valeurs();
85
86 double moy = 0;
87 double coef, sum_vol = 0;
88
89 for (int num_elem = 0; num_elem < domaine_VDF().nb_elem(); num_elem++)
90 {
91 coef = porosite_elem(num_elem) * volumes(num_elem);
92 moy += val(num_elem, ncomp) * coef;
93 sum_vol += coef;
94 }
95 moy /= sum_vol;
96 return moy;
97}
98
99/*! @brief Writes the field in IJK format.
100 *
101 * @param os Output stream.
102 * @param ncomp Component index to print.
103 * @return 1 on success.
104 */
105int Champ_P0_VDF::imprime(Sortie& os, int ncomp) const
106{
107 // valeur_au_ijk(xi,yj,zk,valeurs,ncomp);
108 // principle: create a point array depending on whether the field is element-based or face-based
109 // with a grid built from xi,yj,zk read from a file
110 // sub_type(Champ_P0, *this): grid built from (xi+xi+1)/2, etc...
111 // Otherwise: grid built from xi, xi+1, etc...
112 // Loop over ni,nj,nk
113 // K=
114 // I=1 I=2 I=3 I=4
115 // J=10 Vij
116 // J=9
117 // ...
118 int ni,nj,nk=-1;
119 int ii,jj,k;
120 int np,elem;
121 int cmax=7;
122 DoubleVect xi,yj,zk;
123 DoubleTab Grille;
124 //Reading xi,yj,zk from a .xiyjzk file
125 Nom nomfic(nom_du_cas());
126 nomfic+=".xiyjzk";
127 LecFicDiffuse ficijk(nomfic);
128 ficijk >> xi;
129 ni=xi.size();
130 ficijk >> yj;
131 nj=yj.size();
132 if (dimension==3)
133 {
134 ficijk >> zk;
135 nk=zk.size();
136 }
137 if (ncomp == 1)
138 {
139 if (dimension==3)
140 {
141 // Grid ordered at element centers
142 np=(ni-1)*(nj-1)*(nk-1);
143 Grille.resize(np,dimension);
144 for(k=0; k<nk-1; k++)
145 for(ii=0; ii<ni-1; ii++)
146 for(jj=0; jj<nj-1; jj++)
147 {
148 elem=jj+(nj-1)*(ii+k*(ni-1));
149 Grille(elem,0)=0.5*(xi(ii)+xi(ii+1));
150 Grille(elem,1)=0.5*(yj(jj)+yj(jj+1));
151 Grille(elem,2)=0.5*(zk(k)+zk(k+1));
152 }
153 DoubleTab tab_valeurs(np, nb_compo_);
154 valeur_aux(Grille, tab_valeurs);
155 for(k=0; k<nk-1; k++)
156 {
157 os << finl;
158 os << "Coupe a K= " << k << finl;
159 int n1=0,n2=0;
160 while (n2<ni-1)
161 {
162 n1=n2;
163 n2=std::min(ni-1,n2+cmax);
164 os << finl;
165 os << "I= ";
166 for(int i=n1; i<n2; i++)
167 os << i << " ";
168 os << finl;
169 for(int j=nj-2; j>-1; j--)
170 {
171 os << "J= " << j << " ";
172 for(int i=n1; i<n2; i++)
173 {
174 elem=j+(nj-1)*(i+k*(ni-1));
175 os << tab_valeurs(elem,0) << " ";
176 }
177 os << finl;
178 }
179 }
180 }
181 }
182 else if (dimension==2)
183 {
184 np=(ni-1)*(nj-1);
185 Grille.resize(np,dimension);
186 for(ii=0; ii<ni-1; ii++)
187 for(jj=0; jj<nj-1; jj++)
188 {
189 elem=jj+(nj-1)*ii;
190 Grille(elem,0)=0.5*(xi(ii)+xi(ii+1));
191 Grille(elem,1)=0.5*(yj(jj)+yj(jj+1));
192 }
193 DoubleTab tab_valeurs(np, nb_compo_);
194 valeur_aux(Grille, tab_valeurs);
195 int n1=0,n2=0;
196 while (n2<ni-1)
197 {
198 n1=n2;
199 n2=std::min(ni-1,n2+cmax);
200 os << finl;
201 os << "I= ";
202 for(int i=n1; i<n2; i++)
203 os << i << " ";
204 os << finl;
205 for(int j=nj-2; j>-1; j--)
206 {
207 os << "J= " << j << " ";
208 for(int i=n1; i<n2; i++)
209 {
210 elem=j+(nj-1)*i;
211 os << tab_valeurs(elem,0) << " ";
212 }
213 os << finl;
214 }
215 }
216 }
217 }
218 else
219 {
220 Cerr << "Champ_P0_VDF::imprime_P0_VDF with nb_compo_>1 not implemented." << finl;
221 exit();
222 }
223 return 1;
224}
225
226/*! @brief Computes the spatial integral of one component of the field over the corresponding domain.
227 *
228 * @param ncomp Index of the component to integrate in space.
229 * @return Value of the integral.
230 */
231double Champ_P0_VDF::integrale_espace(int ncomp) const
232{
233 double integr = 0.;
234 const DoubleVect& volumes = domaine_VDF().volumes();
235 int nb_elem = domaine_VDF().nb_elem();
236 int elem;
237 const DoubleTab& val = valeurs();
238 assert(ncomp < val.line_size());
239
240 for (elem = 0; elem < nb_elem; elem++)
241 integr += val(elem, ncomp) * volumes(elem);
242
243 return integr;
244}
: class Champ_Inc_P0_base
const Domaine & domaine() const
const Domaine_dis_base & domaine_dis_base() const override
DoubleTab & valeurs() override
Returns the array of field values at the current time.
DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const override
Computes the values of the unknown field at the specified positions.
class Champ_P0_VDF Class representing a P0 discrete field per element associated with a discretized d...
DoubleTab & remplir_coord_noeuds(DoubleTab &) const override
int imprime(Sortie &os, int nb_compo_) const override
Writes the field in IJK format.
DoubleVect moyenne(const DoubleVect &porosite_elem) const
Returns the P0-average of the field, i.e. the sum, divided by the total domain volume,...
const Domaine_VDF & domaine_VDF() const
double integrale_espace(int ncomp) const override
Computes the spatial integral of one component of the field over the corresponding domain.
class Domaine_VDF
Definition Domaine_VDF.h:61
double volumes(int i) const
Definition Domaine_VF.h:113
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
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 implements the operators and virtual methods of the EFichier class as follows: The file to...
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
Definition Objet_U.cpp:145
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
virtual void ref(const TRUSTTab &)
Definition TRUSTTab.tpp:308
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67