TRUST 1.9.8
HPC thermohydraulic platform
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 renvoie la moyenne du champ au sens P0 i.
47 *
48 * e la somme, divisee par le volume total du domaine, des valeurs constantes par element
49 * multipliees par les volumes des elements
50 *
51 */
52DoubleVect Champ_P0_VDF::moyenne(const DoubleVect& porosite_elem) const
53{
54 const DoubleVect& volumes = domaine_VDF().volumes();
55 const DoubleTab& val = valeurs();
56
57 int k, nb_compo = nb_comp();
58 DoubleVect moy(nb_compo);
59 moy = 0;
60 double coef, sum_vol = 0;
61
62 for (int num_elem = 0; num_elem < domaine_VDF().nb_elem(); num_elem++)
63 {
64 coef = porosite_elem(num_elem) * volumes(num_elem);
65 for (k = 0; k < nb_compo; k++)
66 moy[k] += val(num_elem, k) * coef;
67 sum_vol += coef;
68 }
69
70 moy /= sum_vol;
71 return moy;
72}
73
74/*! @brief Cette fonction effectue le calcul de la moyenne au sens P0 de la kieme composante du champ
75 *
76 */
77double Champ_P0_VDF::moyenne(const DoubleVect& porosite_elem, int ncomp) const
78{
79 const DoubleVect& volumes = domaine_VDF().volumes();
80 const DoubleTab& val = valeurs();
81
82 double moy = 0;
83 double coef, sum_vol = 0;
84
85 for (int num_elem = 0; num_elem < domaine_VDF().nb_elem(); num_elem++)
86 {
87 coef = porosite_elem(num_elem) * volumes(num_elem);
88 moy += val(num_elem, ncomp) * coef;
89 sum_vol += coef;
90 }
91 moy /= sum_vol;
92 return moy;
93}
94
95/*! @brief Ecrit le champ sous la forme IJK
96 *
97 */
98int Champ_P0_VDF::imprime(Sortie& os, int ncomp) const
99{
100 // valeur_au_ijk(xi,yj,zk,valeurs,ncomp);
101 // principe : creer un tableau points avec selon si champ_elem ou champ_faces
102 // une grille construite a partie de xi,yj,zk lu dans un fichier
103 // sub_type(Champ_P0, *this) : grille construite a partir de (xi+xi+1)/2,etc...
104 // Sinon : grille construite a partir de xi,xi+1,etc...
105 // Boucle sur ni,nj,nk
106 // K=
107 // I=1 I=2 I=3 I=4
108 // J=10 Vij
109 // J=9
110 // ...
111 int ni,nj,nk=-1;
112 int ii,jj,k;
113 int np,elem;
114 int cmax=7;
115 DoubleVect xi,yj,zk;
116 DoubleTab Grille;
117 //Lecture de xi,yj,zk dans un fichier .xiyjzk
118 Nom nomfic(nom_du_cas());
119 nomfic+=".xiyjzk";
120 LecFicDiffuse ficijk(nomfic);
121 ficijk >> xi;
122 ni=xi.size();
123 ficijk >> yj;
124 nj=yj.size();
125 if (dimension==3)
126 {
127 ficijk >> zk;
128 nk=zk.size();
129 }
130 if (ncomp == 1)
131 {
132 if (dimension==3)
133 {
134 // Grille ordonnee sur les centres des elements
135 np=(ni-1)*(nj-1)*(nk-1);
136 Grille.resize(np,dimension);
137 for(k=0; k<nk-1; k++)
138 for(ii=0; ii<ni-1; ii++)
139 for(jj=0; jj<nj-1; jj++)
140 {
141 elem=jj+(nj-1)*(ii+k*(ni-1));
142 Grille(elem,0)=0.5*(xi(ii)+xi(ii+1));
143 Grille(elem,1)=0.5*(yj(jj)+yj(jj+1));
144 Grille(elem,2)=0.5*(zk(k)+zk(k+1));
145 }
146 DoubleTab tab_valeurs(np, nb_compo_);
147 valeur_aux(Grille, tab_valeurs);
148 for(k=0; k<nk-1; k++)
149 {
150 os << finl;
151 os << "Coupe a K= " << k << finl;
152 int n1=0,n2=0;
153 while (n2<ni-1)
154 {
155 n1=n2;
156 n2=std::min(ni-1,n2+cmax);
157 os << finl;
158 os << "I= ";
159 for(int i=n1; i<n2; i++)
160 os << i << " ";
161 os << finl;
162 for(int j=nj-2; j>-1; j--)
163 {
164 os << "J= " << j << " ";
165 for(int i=n1; i<n2; i++)
166 {
167 elem=j+(nj-1)*(i+k*(ni-1));
168 os << tab_valeurs(elem,0) << " ";
169 }
170 os << finl;
171 }
172 }
173 }
174 }
175 else if (dimension==2)
176 {
177 np=(ni-1)*(nj-1);
178 Grille.resize(np,dimension);
179 for(ii=0; ii<ni-1; ii++)
180 for(jj=0; jj<nj-1; jj++)
181 {
182 elem=jj+(nj-1)*ii;
183 Grille(elem,0)=0.5*(xi(ii)+xi(ii+1));
184 Grille(elem,1)=0.5*(yj(jj)+yj(jj+1));
185 }
186 DoubleTab tab_valeurs(np, nb_compo_);
187 valeur_aux(Grille, tab_valeurs);
188 int n1=0,n2=0;
189 while (n2<ni-1)
190 {
191 n1=n2;
192 n2=std::min(ni-1,n2+cmax);
193 os << finl;
194 os << "I= ";
195 for(int i=n1; i<n2; i++)
196 os << i << " ";
197 os << finl;
198 for(int j=nj-2; j>-1; j--)
199 {
200 os << "J= " << j << " ";
201 for(int i=n1; i<n2; i++)
202 {
203 elem=j+(nj-1)*i;
204 os << tab_valeurs(elem,0) << " ";
205 }
206 os << finl;
207 }
208 }
209 }
210 }
211 else
212 {
213 Cerr << "Champ_P0_VDF::imprime_P0_VDF avec nb_compo_>1 non code." << finl;
214 exit();
215 }
216 return 1;
217}
218
219/*! @brief Appel a l'objet sous-jacent calcule l'integrale de l'une des composantes
220 *
221 * du champ sur le domaine qui lui correspond
222 *
223 * @param (int ncomp) le numero de la composante integree en espace
224 * @return (double) valeur de l'integrale
225 */
226double Champ_P0_VDF::integrale_espace(int ncomp) const
227{
228 double integr = 0.;
229 const DoubleVect& volumes = domaine_VDF().volumes();
230 int nb_elem = domaine_VDF().nb_elem();
231 int elem;
232 const DoubleTab& val = valeurs();
233 assert(ncomp < val.line_size());
234
235 for (elem = 0; elem < nb_elem; elem++)
236 integr += val(elem, ncomp) * volumes(elem);
237
238 return integr;
239}
: class Champ_Inc_P0_base
const Domaine & domaine() const
const Domaine_dis_base & domaine_dis_base() const override
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const override
Calcule les valeurs du champs inconnue aux positions specifiees.
classe Champ_P0_VDF Classe qui represente un champ discret P0 par element associe a un domaine discre...
DoubleTab & remplir_coord_noeuds(DoubleTab &) const override
int imprime(Sortie &os, int nb_compo_) const override
Ecrit le champ sous la forme IJK.
DoubleVect moyenne(const DoubleVect &porosite_elem) const
renvoie la moyenne du champ au sens P0 i.
const Domaine_VDF & domaine_VDF() const
double integrale_espace(int ncomp) const override
Appel a l'objet sous-jacent calcule l'integrale de l'une des composantes.
class Domaine_VDF
Definition Domaine_VDF.h:64
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
Renvoie le nom du champ.
virtual int nb_comp() const
Definition Field_base.h:56
int nb_compo_
Definition Field_base.h:95
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
Definition Objet_U.cpp:146
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
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