TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
EDO_Pression_th_VEF.cpp
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#include <Loi_Etat_Multi_GP_WC.h>
17#include <Loi_Etat_Multi_GP_QC.h>
18#include <EDO_Pression_th_VEF.h>
19#include <Domaine_VEF.h>
20#include <Periodique.h>
21#include <Champ_P1NC.h>
22
23Implemente_base(EDO_Pression_th_VEF, "EDO_Pression_th_VEF", EDO_Pression_th_base);
24
26
28
30{
31 if (!ref_cast(Domaine_VEF,le_dom.valeur()).get_alphaE())
32 {
33 Cerr << "The quasi-compressible model does not yet work with this discretization." << finl;
34 Cerr << "In VEF, the discretization must have P0 support. Use P1Bulle or P0P1." << finl;
36 }
37
39}
40
41void EDO_Pression_th_VEF::calculer_grad(const DoubleTab& inco, DoubleTab& grad)
42{
43 assert(0);
44 const Domaine_VEF& dom = ref_cast(Domaine_VEF, le_dom.valeur());
45 const IntTab& face_voisins = dom.face_voisins();
46 const DoubleTab& face_normales = dom.face_normales();
47 const DoubleVect& volumes_entrelaces = dom.volumes_entrelaces();
48 const DoubleVect& volumes_entrelaces_Cl = ref_cast(Domaine_Cl_VEF,le_dom_Cl.valeur()).volumes_entrelaces_Cl();
49
50 double diff;
51 int face, comp1;
52
53 // Gradient of a scalar field located at element centers
54 // Initialize grad to zero
55 grad = 0;
56 if (1 == 1)
57 {
58 int elem1, elem2;
59 // Process joint faces:
60 for (face = 0; face < dom.nb_faces_joint(); face++)
61 {
62 elem1 = face_voisins(face, 0);
63 if (elem1 == -1)
64 elem1 = face_voisins(face, 1);
65 diff = -inco[elem1];
66 for (comp1 = 0; comp1 < dimension; comp1++)
67 grad(face, comp1) = diff * face_normales(face, comp1);
68 }
69
70 // Process boundary conditions
71 // Only the Periodique boundary condition type modifies the gradient
72 for (int n_bord = 0; n_bord < dom.nb_front_Cl(); n_bord++)
73 {
74 const Cond_lim& la_cl = le_dom_Cl->les_conditions_limites(n_bord);
75 if (sub_type(Periodique, la_cl.valeur()))
76 {
77 // const Periodique& la_cl_perio = (Periodique&) la_cl.valeur();
78 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
79 int num1 = le_bord.num_premiere_face();
80 int num2 = num1 + le_bord.nb_faces();
81 for (face = num1; face < num2; face++)
82 {
83 elem1 = face_voisins(face, 0);
84 elem2 = face_voisins(face, 1);
85 diff = inco[elem2] - inco[elem1];
86 for (int comp2 = 0; comp2 < dimension; comp2++)
87 grad(face, comp2) = diff * face_normales(face, comp2);
88 }
89 }
90 }
91
92 // Process internal faces
93 // Cerr << "Internal faces." << finl;
94 for (face = dom.premiere_face_int(); face < dom.nb_faces(); face++)
95 {
96 elem1 = face_voisins(face, 0);
97 elem2 = face_voisins(face, 1);
98 diff = inco[elem2] - inco[elem1];
99 for (int comp = 0; comp < dimension; comp++)
100 grad(face, comp) = diff * face_normales(face, comp);
101 }
102 // Divide by the volume!!!
103 int premiere_fac_std = dom.premiere_face_std();
104 for (face = 0; face < premiere_fac_std; face++)
105 {
106 if (volumes_entrelaces_Cl(face) != 0)
107 for (int comp = 0; comp < dimension; comp++)
108 grad(face, comp) /= volumes_entrelaces_Cl(face);
109 else
110 for (int comp = 0; comp < dimension; comp++)
111 grad(face, comp) = 0.;
112 }
113 for (face = premiere_fac_std; face < dom.nb_faces(); face++)
114 {
115 for (int comp = 0; comp < dimension; comp++)
116 grad(face, comp) /= volumes_entrelaces(face);
117 }
118 }
119 else
120 {
121 if (Objet_U::dimension == 2)
122 {
123 int elem, nb_som = dom.domaine().nb_som();
124 int som, nsom, nse = dom.domaine().nb_som_elem();
125 const IntTab& som_elem = dom.domaine().les_elems();
126 int s0, s1, elem0, elem1;
127 const IntTab& face_sommets = dom.face_sommets();
128 const DoubleTab& coord_sommets = dom.domaine().coord_sommets();
129 const DoubleTab& xp = dom.xp();
130 // const DoubleTab& xv = dom.xv();
131 DoubleTab incosom(nb_som);
132 DoubleTab volsom(nb_som);
133 incosom = 0;
134 volsom = 0;
135 double v, inc;
136 // compute P at vertices
137 for (elem = 0; elem < dom.nb_elem(); elem++)
138 {
139 v = dom.volumes(elem);
140 inc = inco[elem];
141 for (som = 0; som < nse; som++)
142 {
143 nsom = som_elem(elem, som);
144 incosom(nsom) += v * inc;
145 volsom(nsom) += v;
146 }
147 }
148 for (nsom = 0; nsom < nb_som; nsom++)
149 {
150 incosom(nsom) /= volsom(nsom);
151 }
152 double xs0, ys0, xs1, ys1, xe0, ye0, xe1, ye1, ds, de;
153 // boundary faces
154 for (int n_bord = 0; n_bord < dom.nb_front_Cl(); n_bord++)
155 {
156 const Cond_lim& la_cl = le_dom_Cl->les_conditions_limites(n_bord);
157
158 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
159 int num1 = le_bord.num_premiere_face();
160 int num2 = num1 + le_bord.nb_faces();
161 for (face = num1; face < num2; face++)
162 {
163 s0 = face_sommets(face, 0);
164 s1 = face_sommets(face, 1);
165 xs0 = coord_sommets(s0, 0);
166 ys0 = coord_sommets(s0, 1);
167 xs1 = coord_sommets(s1, 0);
168 ys1 = coord_sommets(s1, 1);
169 v = volumes_entrelaces(face);
170 ds = (incosom(s1) - incosom(s0)) / ((xs1 - xs0) * (xs1 - xs0) + (ys1 - ys0) * (ys1 - ys0));
171 grad(face, 0) = v * (ds * (xs1 - xs0));
172 grad(face, 1) = v * (ds * (ys1 - ys0));
173 }
174 }
175
176 // internal faces
177 for (face = dom.premiere_face_int(); face < dom.nb_faces(); face++)
178 {
179 s0 = face_sommets(face, 0);
180 s1 = face_sommets(face, 1);
181 elem0 = face_voisins(face, 0);
182 elem1 = face_voisins(face, 1);
183 xs0 = coord_sommets(s0, 0);
184 ys0 = coord_sommets(s0, 1);
185 xs1 = coord_sommets(s1, 0);
186 ys1 = coord_sommets(s1, 1);
187 xe0 = xp(elem0, 0);
188 ye0 = xp(elem0, 1);
189 xe1 = xp(elem1, 0);
190 ye1 = xp(elem1, 1);
191 v = volumes_entrelaces(face);
192 ds = (incosom(s1) - incosom(s0)) / ((xs1 - xs0) * (xs1 - xs0) + (ys1 - ys0) * (ys1 - ys0));
193 de = (inco(elem1) - inco(elem0)) / ((xe1 - xe0) * (xe1 - xe0) + (ye1 - ye0) * (ye1 - ye0));
194 grad(face, 0) = v * (ds * (xs1 - xs0) + de * (xe1 - xe0));
195 grad(face, 1) = v * (ds * (ys1 - ys0) + de * (ye1 - ye0));
196 }
197 }
198 else
199 Cerr << "WARNING: gradient of inco incorrectly computed in 3D" << finl;
200 }
201}
202
203double EDO_Pression_th_VEF::masse_totale(double P, const DoubleTab& T)
204{
205 const Domaine_VEF& dom = ref_cast(Domaine_VEF, le_dom.valeur());
206 int nb_faces = dom.nb_faces();
207
208 // assert(tab.dimension(0)==nb_faces);
209 const Loi_Etat_base& loi_ = ref_cast(Loi_Etat_base, le_fluide_->loi_etat().valeur());
210
211 DoubleVect tmp;
212 tmp.copy(T, RESIZE_OPTIONS::NOCOPY_NOINIT); // just copy the structure
213 if (!sub_type(Loi_Etat_Multi_GP_QC, loi_))
214 {
215 for (int i = 0; i < nb_faces; i++)
216 tmp[i] = loi_.calculer_masse_volumique(P, T[i]);
217 }
218 else
219 {
220 const Loi_Etat_Multi_GP_QC& loi_mel_GP = ref_cast(Loi_Etat_Multi_GP_QC, loi_);
221 const DoubleTab& Masse_mol_mel = loi_mel_GP.masse_molaire();
222 for (int i = 0; i < nb_faces; i++)
223 {
224 double r = 8.3143 / Masse_mol_mel[i];
225 tmp[i] = loi_mel_GP.calculer_masse_volumique(P, T[i], r);
226 }
227 }
228 const double M = Champ_P1NC::calculer_integrale_volumique(dom, tmp, FAUX_EN_PERIO);
229 return M;
230}
231
232double EDO_Pression_th_VEF::masse_totale(const DoubleTab& P, const DoubleTab& T)
233{
234 const Domaine_VEF& dom = ref_cast(Domaine_VEF, le_dom.valeur());
235 int nb_faces = dom.nb_faces();
236
237 assert(P.dimension(0) == T.dimension(0));
238 const Loi_Etat_base& loi_ = ref_cast(Loi_Etat_base, le_fluide_->loi_etat().valeur());
239
240 DoubleVect tmp;
241 tmp.copy(T, RESIZE_OPTIONS::NOCOPY_NOINIT); // just copy the structure
242 if (!sub_type(Loi_Etat_Multi_GP_WC, loi_))
243 {
244 for (int i = 0; i < nb_faces; i++)
245 tmp[i] = loi_.calculer_masse_volumique(P(i), T(i));
246 }
247 else
248 {
249 const Loi_Etat_Multi_GP_WC& loi_mel_GP = ref_cast(Loi_Etat_Multi_GP_WC, loi_);
250 const DoubleTab& Masse_mol_mel = loi_mel_GP.masse_molaire();
251 for (int i = 0; i < nb_faces; i++)
252 {
253 double r = 8.3143 / Masse_mol_mel[i];
254 tmp[i] = loi_mel_GP.calculer_masse_volumique(P(i), T(i), r);
255 }
256 }
257 const double M = Champ_P1NC::calculer_integrale_volumique(dom, tmp, FAUX_EN_PERIO);
258 return M;
259}
static double calculer_integrale_volumique(const Domaine_VEF &, const DoubleVect &, Ok_Perio ok)
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
int nb_som_elem() const
Returns the number of vertices of the geometric elements that make up the domain.
Definition Domaine.h:474
IntTab_t & les_elems()
Definition Domaine.h:129
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
int_t nb_som() const
Returns the number of vertices of the domain.
Definition Domaine.h:121
class Domaine_VEF
Definition Domaine_VEF.h:53
int nb_faces_joint() const
Definition Domaine_VEF.h:76
int premiere_face_std() const
Definition Domaine_VEF.h:79
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
DoubleVect & volumes_entrelaces()
Definition Domaine_VF.h:99
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double volumes(int i) const
Definition Domaine_VF.h:113
int face_sommets(int i, int j) const
Returns the index of the i-th vertex of face num_face.
Definition Domaine_VF.h:582
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
int premiere_face_int() const
A face is internal if and only if it separates two elements.
Definition Domaine_VF.h:463
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
int nb_front_Cl() const
const Domaine & domaine() const
class EDO_Pression_th_VEF This class represents the ODE on the pressure associated with the computati...
void calculer_grad(const DoubleTab &, DoubleTab &)
double masse_totale(double P, const DoubleTab &T) override
Base class of the ODE hierarchy for thermodynamic pressure associated with the scheme resolution for ...
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
State law class for a mixture of ideal gases in the quasi-compressible (QC) framework.
void calculer_masse_volumique() override
Recomputes the density.
State law class for a mixture of ideal gases in the weakly compressible (WC) framework.
void calculer_masse_volumique() override
Recomputes the density.
const DoubleTab & masse_molaire() const
Base class for the state law hierarchy defining a dilatable fluid.
virtual void calculer_masse_volumique()
Recomputes the density (masse volumique).
static int dimension
Definition Objet_U.h:94
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
class Periodique This class represents a periodic boundary condition.
Definition Periodique.h:31
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
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
void copy(const TRUSTArray< _TYPE_, _SIZE_ > &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)