TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Conv_Amont_VPoly_VDF_Face.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 <Op_Conv_Amont_VPoly_VDF_Face.h>
17#include <Masse_ajoutee_base.h>
18
19Implemente_instanciable_sans_constructeur(Op_Conv_Amont_VPoly_VDF_Face,"Op_Conv_Amont_VPoly_VDF_Face",Op_Conv_Amont_VDF_Face);
20
23
24void Op_Conv_Amont_VPoly_VDF_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
25{
26 const Domaine_VDF& domaine = iter_->domaine();
27 // okok I know ... tgv
28 DoubleTab& tab_flux_bords = flux_bords();
29 tab_flux_bords.resize(domaine.nb_faces_bord(), dimension);
30 tab_flux_bords = 0.;
31
32 const Champ_Face_VDF& ch = ref_cast(Champ_Face_VDF, equation().inconnue());
33 const Conds_lim& cls = iter_->domaine_Cl().les_conditions_limites();
34 const IntTab& f_e = domaine.face_voisins(), &e_f = domaine.elem_faces(), &fcl = ch.fcl();
35 const DoubleTab& vit = ch.passe(), &vfd = domaine.volumes_entrelaces_dir();
36 const DoubleVect& fs = domaine.face_surfaces(), &pe = equation().milieu().porosite_elem(), &ve = domaine.volumes();
37
38 /* a_r : produit alpha_rho si Pb_Multiphase -> par semi_implicite, ou en recuperant le champ_conserve de l'equation de masse */
39 const std::string& nom_inco = ch.le_nom().getString();
40 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
41 const Masse_ajoutee_base *corr = pbm && pbm->has_correlation("masse_ajoutee") ? &ref_cast(Masse_ajoutee_base, pbm->get_correlation("masse_ajoutee")) : nullptr;
42 const DoubleTab& inco = semi_impl.count(nom_inco) ? semi_impl.at(nom_inco) : ch.valeurs(),
43 *a_r = !pbm ? nullptr : semi_impl.count("alpha_rho") ? &semi_impl.at("alpha_rho") : &pbm->equation_masse().champ_conserve().valeurs(),
44 *alp = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr,
45 &rho = equation().milieu().masse_volumique().passe();
46 Matrice_Morse *mat = matrices.count(nom_inco) && !semi_impl.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
47
48 int i, j, k, e = -100, eb, f, fb, fd, m, n, N = inco.line_size(), d, D = dimension, comp = !incompressible_;
49
50 DoubleTrav dfac(2, N, N), masse(N, N);
51 for (f = 0; f < domaine.nb_faces_tot(); f++)
52 {
53 const bool is_interne = (f_e(f, 0) >= 0 && f_e(f, 1) >= 0);
54 const bool is_bord = ((f_e(f, 0) >= 0 && f_e(f, 1) < 0) || (f_e(f, 0) < 0 && f_e(f, 1) >= 0));
55 const bool is_neum_or_diric = (fcl(f, 0) == 1 || fcl(f, 0) == 3);
56
57 if (is_interne || (is_bord && is_neum_or_diric))
58 {
59 // etape 1 : masse + dfac
60 if (f_e(f, 0) < 0)
61 {
62 for (i = 1, dfac = 0; i >= 0; i--)
63 {
64 //masse : diagonale
65 for (masse = 0, e = f_e(f, f_e(f, i) >= 0 ? i : !i), n = 0; n < N; n++)
66 masse(n, n) = a_r ? (*a_r)(e, n) : 1;
67
68 // masse ajoutee si correlation
69 if (corr)
70 corr->ajouter(&(*alp)(e, 0), &rho(e, 0), masse);
71
72 //contribution a dfac
73 for (n = 0; n < N; n++)
74 {
75 e = f_e(f, i);
76 eb = e;
77 for (m = 0; m < N; m++)
78 {
79 const int ind = fcl(f, 0) == 1 ? 0 : i;
80 const int ind_por = eb >= 0 ? eb : f_e(f, f_e(f, i) >= 0 ? i : !i);
81 double dd = (vit(f, m) * (i ? -1 : 1) >= 0 ? 1. : vit(f, m) ? -1. : 0.);
82
83 dfac(ind, n, m) += fs(f) * vit(f, m) * pe(ind_por) * masse(n, m) * (1. + dd) / 2;
84 }
85 }
86 }
87 }
88 else
89 {
90 for (i = 0, dfac = 0; i < 2; i++)
91 {
92 //masse : diagonale
93 for (masse = 0, e = f_e(f, f_e(f, i) >= 0 ? i : !i), n = 0; n < N; n++)
94 masse(n, n) = a_r ? (*a_r)(e, n) : 1;
95
96 // masse ajoutee si correlation
97 if (corr)
98 corr->ajouter(&(*alp)(e, 0), &rho(e, 0), masse);
99
100 //contribution a dfac
101 for (n = 0; n < N; n++)
102 {
103 e = f_e(f, i);
104 eb = e;
105 for (m = 0; m < N; m++)
106 {
107 const int ind = fcl(f, 0) == 1 ? (f_e(f, 0) >= 0 ? 0 : 1) : i;
108 const int ind_por = eb >= 0 ? eb : f_e(f, f_e(f, i) >= 0 ? i : !i);
109 double dd = (vit(f, m) * (i ? -1 : 1) >= 0 ? 1. : vit(f, m) ? -1. : 0.);
110
111 dfac(ind, n, m) += fs(f) * vit(f, m) * pe(ind_por) * masse(n, m) * (1. + dd) / 2;
112 }
113 }
114 }
115 }
116
117 // etape 2 : secmem + derivee
118 for (i = 0; i < 2; i++)
119 if ((e = f_e(f, i)) >= 0)
120 {
121 for (k = 0; k < e_f.dimension(1); k++)
122 {
123 fb = e_f(e, k);
124 if (fb >= 0 && (domaine.orientation(fb) == domaine.orientation(f)))
125 if (fb < domaine.nb_faces())
126 if (f_e(f, i == 0 ? 1 : 0) < 0 || (f_e(f, 0) >= 0 && f_e(f, 1) >= 0))
127 {
128 if (f_e(f, 0) < 0)
129 for (j = 1; j >= 0; j--) //equivalence : face fd -> face fb
130 {
131 eb = f_e(f, j), fd = (j == i ? fb : domaine.face_amont_princ(fb, j) /* face */); //element/face sources
132
133 for (n = 0; n < N; n++)
134 for (m = 0; m < N; m++)
135 if (dfac(!j, n, m))
136 {
137 // secmem
138 double fac = (i ? -1 : 1) * vfd(fb, e != f_e(fb, 0)) * dfac(!j, n, m) / ve(e);
139 if (f_e(fb, 0) < 0)
140 fac *= 0.5;
141 if (fd >= 0)
142 secmem(fb, n) -= fac * inco(fd, m); //other computed face
143 else
144 {
145 for (d = 0; d < D; d++) //CL de Dirichlet
146 {
147 if (sub_type(Dirichlet, cls[fcl(f, 1)].valeur()))
148 throw;
149 secmem(fb, n) -= 0; //fac * domaine.face_normales(fb, d) / fs(fb) * ref_cast(Dirichlet, cls[fcl(f, 1)].valeur()).val_imp(fcl(f, 2), N * d + m);
150 }
151 }
152
153 // if compressible: part v div(alpha rho v)
154 if (comp)
155 secmem(fb, n) += fac * inco(fb, m);
156
157 // derivee
158 if (mat)
159 {
160 if (fd >= 0)
161 (*mat)(N * fb + n, N * fd + m) += fac;
162 if (comp)
163 (*mat)(N * fb + n, N * fb + m) -= fac;
164 }
165 }
166 }
167 else
168 for (j = 0; j < 2; j++) //equivalence : face fd -> face fb
169 {
170 eb = f_e(f, j), fd = (j == i ? fb : domaine.face_amont_princ(fb, j) /* face */); //element/face sources
171
172 for (n = 0; n < N; n++)
173 for (m = 0; m < N; m++)
174 if (dfac(j, n, m))
175 {
176 // secmem
177 double fac = (i ? -1 : 1) * vfd(fb, e != f_e(fb, 0)) * dfac(j, n, m) / ve(e);
178 if (f_e(fb, 0) < 0)
179 fac *= 0.5;
180 if (fd >= 0)
181 secmem(fb, n) -= fac * inco(fd, m); //other computed face
182 else
183 {
184 for (d = 0; d < D; d++) //CL de Dirichlet
185 {
186 if (sub_type(Dirichlet, cls[fcl(f, 1)].valeur()))
187 throw;
188 secmem(fb, n) -= 0; //fac * domaine.face_normales(fb, d) / fs(fb) * ref_cast(Dirichlet, cls[fcl(f, 1)].valeur()).val_imp(fcl(f, 2), N * d + m);
189 }
190 }
191
192 // if compressible: part v div(alpha rho v)
193 if (comp)
194 secmem(fb, n) += fac * inco(fb, m);
195
196 // derivee
197 if (mat)
198 {
199 if (fd >= 0)
200 (*mat)(N * fb + n, N * fd + m) += fac;
201 if (comp)
202 (*mat)(N * fb + n, N * fb + m) -= fac;
203 }
204 }
205 }
206 }
207
208 }
209 }
210 }
211 }
212}
213
class Champ_Face_VDF
const IntTab & fcl() const
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & passe(int i=1)
Definition Champ_Proto.h:50
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
Dirichlet This class is the base class of the hierarchy of Dirichlet-type boundary conditions.
Definition Dirichlet.h:31
class Domaine_VDF
Definition Domaine_VDF.h:61
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
Champ_Inc_base & champ_conserve() const
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Returns the name of the field.
Added-mass correlation of the form: alpha_k rho_k Dv_k / Dt -> alpha_k rho_k Dv_k / Dt + sum_l ma(k,...
virtual void ajouter(const double *alpha, const double *rho, DoubleTab &a_r) const =0
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
const std::string & getString() const
Definition Nom.h:92
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
class Op_Conv_Amont_VDF_Face This class represents the convection operator associated with a momentum...
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
DoubleTab & flux_bords()
Multiphase thermohydraulics problem of type "3*N equations":
virtual Equation_base & equation_masse()
int has_correlation(std::string nom_correlation) const
const Correlation_base & get_correlation(std::string nom_correlation) const
Base class for output streams.
Definition Sortie.h:52
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
int line_size() const
Definition TRUSTVect.tpp:67