TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Echange_Thermique_Volumique_Elem.cpp
1/****************************************************************************
2 * Copyright (c) 2022, 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 <Echange_Thermique_Volumique_Elem.h>
17#include <Discretisation_base.h>
18#include <Schema_Temps_base.h>
19#include <Equation_base.h>
20#include <Probleme_base.h>
21#include <Domaine_VF.h>
22#include <Param.h>
23#include <Synonyme_info.h>
24#include <Array_tools.h>
25#include <Matrix_tools.h>
26#include <Navier_Stokes_std.h>
27#include <Pb_Multiphase.h>
28#include <Flux_parietal_base.h>
29
30Implemente_instanciable(Echange_Thermique_Volumique_Elem, "Echange_Thermique_Volumique_Elem", Source_base);
31// XD echange_thermique_volumique source_base echange_thermique_volumique BRACE Source term that exchanges heat
32// XD_CONT volumetrically between two overlapping domains using interfacial area and thermal resistances.
33
34Add_synonym(Echange_Thermique_Volumique_Elem, "echange_thermique_volumique_VDF_P0_VDF");
35Add_synonym(Echange_Thermique_Volumique_Elem, "Echange_Thermique_Volumique_Elem_PolyMAC_MPFA");
36Add_synonym(Echange_Thermique_Volumique_Elem, "Echange_Thermique_Volumique_Elem_PolyMAC_HFV");
37
39
41{
42 Param param(que_suis_je());
43 param.ajouter("nom|name", &tag_, Param::REQUIRED); // XD_ADD_P chaine
44 // XD_CONT Tag used to match the source terms on both sides of the coupling.
45 param.ajouter("aire_interfaciale|interfacial_area", &Ai_, Param::REQUIRED); // XD_ADD_P field_base
46 // XD_CONT Interfacial area per cell used to compute the exchange.
47 param.ajouter("conduction_length|epaisseur_conduction", &ep_cond_); // XD_ADD_P field_base
48 // XD_CONT Conduction length (if conduction is modeled).
49 param.ajouter("conductivity|conductivite", &cond_); // XD_ADD_P field_base
50 // XD_CONT Thermal conductivity used with the conduction length (optional).
51 param.ajouter_non_std("flux_parietal|heat_flux", (this)); // XD_ADD_P flux_parietal_base
52 // XD_CONT Correlation used to compute the wall heat flux on each side of the interface.
53 param.lire_avec_accolades_depuis(s);
54
55 set_fichier(Nom("Echange_Thermique_Volumique_") + tag_);
56 set_description("Power (W)");
57 Noms col_names;
58 col_names.add("Power");
59 set_col_names(col_names);
60
61 return s;
62}
63
65{
66 if (mot == "flux_parietal" || mot == "heat_flux")
67 {
68 Correlation_base::typer_lire_correlation(flux_par_, equation().probleme(), "flux_parietal", is);
69 return 1;
70 }
71 return 1;
72}
73
75{
76 Ai_->initialiser(temps);
77 if (ep_cond_) ep_cond_->initialiser(temps);
78 /* search for the source term on the other side */
79 if (!equation().probleme().is_coupled())
80 Process::exit(que_suis_je() + " can only be used in a coupled problem!");
81 for (int i = 0; i < equation().probleme().get_pb_couple().nb_problemes(); i++)
82 {
83 Probleme_base& o_pb = ref_cast(Probleme_base, equation().probleme().get_pb_couple().probleme(i));
84 if (&o_pb != &equation().probleme())
85 for(int j = 0; j < o_pb.nombre_d_equations(); j++)
86 for (auto &so : o_pb.equation(j).sources())
87 if (sub_type(Echange_Thermique_Volumique_Elem, so.valeur()) && ref_cast(Echange_Thermique_Volumique_Elem, so.valeur()).tag_ == tag_)
88 o_ech_ = ref_cast(Echange_Thermique_Volumique_Elem, so.valeur());
89 }
90 if (!o_ech_) //pas trouve
91 Process::exit(que_suis_je() + " : could not find matching term for name " + tag_ + " in problem " + equation().probleme().le_nom() + " !");
92
93 return Source_base::initialiser(temps);
94}
95
97{
98 Ai_->mettre_a_jour(temps);
99 if (ep_cond_) ep_cond_->mettre_a_jour(temps);
100 if (cond_) cond_->mettre_a_jour(temps);
101}
102
103void Echange_Thermique_Volumique_Elem::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
104{
105 std::string nom_inc = equation().inconnue().le_nom().getString(), o_nom_inc = nom_inc + "/" + o_ech_->equation().probleme().le_nom().getString();
106 if (semi_impl.count(nom_inc)) return; //semi-implicite -> pas de derivees
107 Matrice_Morse *mat[2] = { matrices.count(nom_inc) ? matrices.at(nom_inc) : nullptr, matrices.count(o_nom_inc) ? matrices.at(o_nom_inc) : nullptr };
108 const DoubleTab *vals[2] = { &equation().inconnue().valeurs(), &o_ech_->equation().inconnue().valeurs() };
109 const Domaine_VF& dom = ref_cast(Domaine_VF, equation().domaine_dis());
110 const int ne_tot = dom.nb_elem_tot(), N = vals[0]->line_size(), M = vals[1]->line_size();
111
112 /* interfacial area per cell */
113 DoubleTab Ai(ne_tot, 1);
114 IntVect polys(ne_tot);
115 for (int e = 0; e < ne_tot; e++) polys(e) = e;
116 Ai_->valeur_aux_elems(dom.xp(), polys, Ai);
117 /* remapper matrix */
118 const std::vector<std::map<mcIdType,double>>& interp = equation().probleme().domaine().get_remapper(o_ech_->equation().probleme().domaine(), true)->getCrudeMatrix();
119
120 /* derivatives: at cells where Ai > 0 */
121 Stencil sten[2];
122 sten[0].resize(0, 2);
123 sten[1].resize(0, 2);
124 for (int e = 0; e < dom.nb_elem(); e++)
125 if (Ai(e) > 0)
126 {
127 //partie locale
128 for (int n = 0; n < N; n++)
129 for (int m = 0; m < N; m++)
130 sten[0].append_line(N * e + n, N * e + m);
131 //partie distante
132 for (auto &&kv : interp[e])
133 if (kv.second)
134 for (int o_e = (int)kv.first, n = 0; n < N; n++)
135 for (int m = 0; m < M; m++)
136 sten[1].append_line(N * e + n, M * o_e + m);
137 }
138 for (int i = 0; i < 2; i++)
139 if (mat[i])
140 {
141 tableau_trier_retirer_doublons(sten[i]);
142 Matrice_Morse mat2;
143 Matrix_tools::allocate_morse_matrix(vals[0]->size_totale(), vals[i]->size_totale(), sten[i], mat2);
144 mat[i]->nb_colonnes() ? *mat[i] += mat2 : *mat[i] = mat2;
145 }
146}
147
148void Echange_Thermique_Volumique_Elem::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
149{
150 const Probleme_base *pb[2] = { &equation().probleme(), &o_ech_->equation().probleme() };
151 std::string nom_inc = equation().inconnue().le_nom().getString(), o_nom_inc = nom_inc + "/" + pb[1]->le_nom().getString();
152 const DoubleTab& vals = semi_impl.count(nom_inc) ? semi_impl.at(nom_inc) : equation().inconnue().valeurs(),
153 &o_vals = semi_impl.count(o_nom_inc) ? semi_impl.at(o_nom_inc) : o_ech_->equation().inconnue().valeurs(), *pvals[2] = { &vals, &o_vals },
154 &lambda = equation().milieu().conductivite().passe(), &o_lambda = o_ech_->equation().milieu().conductivite().passe();
155 const Domaine_VF *dom[2] = { &ref_cast(Domaine_VF, equation().domaine_dis()), &ref_cast(Domaine_VF, o_ech_->equation().domaine_dis()) };
156 const int ne_tot = dom[0]->nb_elem_tot(), o_ne_tot = dom[1]->nb_elem_tot(), D = dimension;
157 const int N[2] = { vals.line_size(), o_vals.line_size() }, semi = int(semi_impl.count(nom_inc));
158 const int cL = lambda.dimension(0) == 1, o_cL = o_lambda.dimension(0) == 1;
159 Matrice_Morse *mat = !semi && matrices.count(nom_inc) ? matrices.at(nom_inc) : nullptr, *o_mat = !semi && matrices.count(o_nom_inc) ? matrices.at(o_nom_inc) : nullptr;
160
161 /* interfacial area per cell */
162 DoubleTrav Ai(ne_tot, 1), ep, o_ep, cond, o_cond, o_Ai(o_ne_tot, 1), v_e[2];
163 IntVect polys(ne_tot), o_polys(o_ne_tot);
164 for (int e = 0; e < ne_tot; e++) polys(e) = e;
165 for (int o_e = 0; o_e < o_ne_tot; o_e++) o_polys(o_e) = o_e;
166 Ai_->valeur_aux_elems(dom[0]->xp(), polys, Ai), o_ech_->Ai_->valeur_aux_elems(dom[1]->xp(), o_polys, o_Ai);
167 if (ep_cond_)
168 ep.resize(ne_tot, 1), ep_cond_->valeur_aux_elems(dom[0]->xp(), polys, ep);
169 if (o_ech_->ep_cond_)
170 o_ep.resize(o_ne_tot, 1), o_ech_->ep_cond_->valeur_aux_elems(dom[1]->xp(), o_polys, o_ep);
171 if (cond_)
172 cond.resize(ne_tot, 1), cond_->valeur_aux_elems(dom[0]->xp(), polys, cond);
173 if (o_ech_->cond_)
174 o_cond.resize(o_ne_tot, 1), o_ech_->cond_->valeur_aux_elems(dom[1]->xp(), o_polys, o_cond);
175 for (int i = 0; i < 2; i++)
176 {
177 auto& flux = i ? o_ech_->flux_par_ : flux_par_;
178 if (flux)
179 {
180 v_e[i].resize(0, D * N[i]);
181 dom[i]->domaine().creer_tableau_elements(v_e[i]);
182 ref_cast(Navier_Stokes_std, pb[i]->equation(0)).inconnue().valeur_aux_elems(dom[i]->xp(), i ? o_polys : polys, v_e[i]);
183 if (i) v_e[i].echange_espace_virtuel();
184 }
185 }
186
187 /* remapper matrix */
188 const std::vector<std::map<mcIdType,double>>& interp = equation().probleme().domaine().get_remapper(o_ech_->equation().probleme().domaine(), true)->getCrudeMatrix();
189 bilan().resize(N[0]), bilan() = 0;
190
191 for (int e = 0; e < dom[0]->nb_elem(); e++)
192 if (Ai(e) > 0)
193 for (auto &&kv : interp[e])
194 if (kv.second)
195 {
196 const int o_e = (int)kv.first;
197 // if (std::abs(Ai(e) - o_Ai(o_e)) > 1e-6)
198 // {
199 // Cerr << que_suis_je() + " : interfacial area inconsistency between " + dom[0]->domaine().le_nom() + "(" + Nom(Ai(e)) + ") and " + dom[1]->domaine().le_nom() + " (" + Nom(o_Ai(o_e)) + ")!";
200 // Cerr << "Positions : (" << dom[0]->xp(e, 0) << ", " << dom[0]->xp(e, 1) << ", " << dom[0]->xp(e, 2) << "), (" << dom[1]->xp(o_e, 0) << ", " << dom[1]->xp(o_e, 1) << ", " << dom[1]->xp(o_e, 2) << ")" << finl;
201 // Cerr << "Intersection : " << kv.second << finl;
202 // Process::exit();
203 // }
204 //total thermal resistivity: start with the conductive part
205 double surf = std::min(Ai(e), o_Ai(o_e)) * kv.second, hf[2] = { 0, };
206 double invh = (ep.size() ? ep(e) / (cond.size() ? cond(e) : lambda(!cL * e, 0)) : 0) + (o_ep.size() ? o_ep(o_e) / (o_cond.size() ? o_cond(o_e) : o_lambda(!o_cL * o_e, 0)) : 0);
207 //wall fluxes on each side
208 DoubleTrav f_h(2, std::max(N[0], N[1])); // f_h(i, j) : fraction of exchange with phase j on side i
209 for (int i = 0; i < 2; i++)
210 {
211 auto& flux = i ? o_ech_->flux_par_ : flux_par_;
212 if (flux)
213 {
214 const Flux_parietal_base& corr = ref_cast(Flux_parietal_base, flux.valeur());
215 const DoubleTab* alpha = sub_type(Pb_Multiphase, *pb[i]) ? &ref_cast(Pb_Multiphase, *pb[i]).equation_masse().inconnue().passe() : nullptr, &dh = pb[i]->milieu().diametre_hydraulique_elem(),
216 &press = ref_cast(Navier_Stokes_std, pb[i]->equation(0)).pression().passe(),
217 &lamb = ref_cast(Fluide_base, pb[i]->milieu()).conductivite().passe(), &mu = ref_cast(Fluide_base, pb[i]->milieu()).viscosite_dynamique().passe(),
218 &rho = pb[i]->milieu().masse_volumique().passe(), &Cp = pb[i]->milieu().capacite_calorifique().passe();
219 int Clamb = lamb.dimension(0) == 1, Cmu = mu.dimension(0) == 1, Crho = rho.dimension(0) == 1, Ccp = Cp.dimension(0) == 1, el = i ? o_e : e, nonlinear = 0;
220
223 DoubleTrav qpk(N[i]), dTf_qpk(N[i], N[i]), dTp_qpk(N[i]), qpi(N[i], N[i]), dTf_qpi(N[i], N[i], N[i]), dTp_qpi(N[i], N[i]), nv(N[i]);
224 in.N = N[i], in.D_h = dh(el), in.D_ch = dh(el), in.alpha = alpha ? &(*alpha)(el, 0) : nullptr, in.T = &(*pvals[i])(el, 0), in.p = press(el), in.v = nv.addr();
225 in.lambda = &lamb(!Clamb * el, 0), in.mu = &mu(!Cmu * el, 0), in.rho = &rho(!Crho * el, 0), in.Cp = &Cp(!Ccp * el, 0), in.Tp = 0;
226 out.qpk = &qpk, out.dTf_qpk = &dTf_qpk, out.dTp_qpk = &dTp_qpk, out.qpi = &qpi, out.dTf_qpi = &dTf_qpi, out.dTp_qpi = &dTp_qpi, out.nonlinear = &nonlinear;
227 for (int d = 0; d < D; d++)
228 for (int n = 0; n < N[i]; n++)
229 nv(n) += v_e[i](el, N[i] * d + n) * v_e[i](el, N[i] * d + n);
230 for (int n = 0; n < N[0]; n++) nv(n) = sqrt(nv[n]);
231 //call!
232 corr.qp(in, out);
233 if (nonlinear)
234 Process::exit(que_suis_je() + " : nonlinear heat flux such as " + corr.que_suis_je() + " are not implemented yet!");
235 //we are only interested in the exchange coefficients
236 for (int n = 0; n < N[i]; n++) hf[i] += -dTf_qpk(n, n);
237 for (int n = 0; n < N[i]; n++) f_h(i, n) = -dTf_qpk(n, n) / hf[i];
238 invh += 1. / hf[i];
239 }
240 else if (N[i] > 1)
241 Process::exit(que_suis_je() + " : multi-component heat flux with " + pb[i]->le_nom() + ", but no heat_flux has been defined!");
242 else f_h(i, 0) = 1;
243 }
244 //contributions
245 for (int n = 0; n < N[0]; n++)
246 {
247 for (int m = 0; m < N[0]; m++) //locales
248 {
249 double fac = surf * f_h(0, n) * (hf[0] * (f_h(0, m) - (m == n)) - f_h(0, m) / invh);
250 secmem(e, n) += fac * vals(e, m), bilan()(n) += fac * vals(e, m);
251 if (mat) (*mat)(N[0] * e + n, N[0] * e + m) -= fac;
252 }
253 for (int m = 0; m < N[1]; m++) //distantes
254 {
255 double fac = surf / invh * f_h(0, n) * f_h(1, m);
256 secmem(e, n) += fac * o_vals(o_e, m), bilan()(n) += fac * o_vals(o_e, m);
257 if (o_mat) (*o_mat)(N[0] * e + n, N[1] * o_e + m) -= fac;
258 }
259 }
260 }
261}
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & passe(int i=1)
Definition Champ_Proto.h:50
static void typer_lire_correlation(OWN_PTR(Correlation_base)&, const Probleme_base &, const Nom &, Entree &)
int nb_problemes() const
Definition Couplage_U.h:117
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
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
int nb_elem_tot() const
const Domaine & domaine() const
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void mettre_a_jour(double) override
DOES NOTHING - to override in derived classes.
int initialiser(double temps) override
Unlike the mettre_a_jour methods, the initializer methods of sources cannot depend on the outside.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
int lire_motcle_non_standard(const Motcle &mot, Entree &is) override
Reads non-simple-type parameters of an Objet_U from an input stream.
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
Sources & sources()
Returns the source terms associated with the equation.
virtual const Champ_Inc_base & inconnue() const =0
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
Base class for an incompressible fluid and its properties:
Definition Fluide_base.h:36
Base class for wall heat flux correlations of the form:
virtual void qp(const input_t &input, output_t &output) const =0
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
virtual const Champ_Don_base & capacite_calorifique() const
Returns the heat capacity of the medium (const version).
virtual const Champ_Don_base & conductivite() const
Returns the conductivity of the medium (const version).
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
DoubleTab & diametre_hydraulique_elem()
Definition Milieu_base.h:70
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
A character string (Nom) in uppercase.
Definition Motcle.h:26
Navier_Stokes_std This class carries the terms of the momentum equation.
const std::string & getString() const
Definition Nom.h:92
friend class Entree
Definition Objet_U.h:71
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 const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
@ REQUIRED
Definition Param.h:115
Multiphase thermohydraulics problem of type "3*N equations":
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
class Probleme_base It is a Probleme_U that is not a coupling.
const Domaine & domaine() const
Returns the domain associated with the problem.
const Probleme_Couple & get_pb_couple() const
virtual const Milieu_base & milieu() const
Returns the physical medium associated with the problem (const version).
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
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
Source_base A Source_base object is a term appearing on the right-hand side of an.
Definition Source_base.h:42
void set_fichier(const Nom &)
DoubleVect & bilan()
Definition Source_base.h:88
virtual int initialiser(double temps)
Unlike the mettre_a_jour methods, the initializer methods of sources cannot depend on the outside.
void set_col_names(const Noms &col_names)
Definition Source_base.h:84
void set_description(const Nom &nom)
Definition Source_base.h:83
_TYPE_ * addr()
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
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")