TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Iterateur_VDF_Elem_FT_TCL.tpp
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#ifndef Iterateur_VDF_Elem_FT_TCL_TPP_included
17#define Iterateur_VDF_Elem_FT_TCL_TPP_included
18
19#include <Convection_Diffusion_Temperature_FT_Disc.h>
20#include <Transport_Interfaces_FT_Disc.h>
21#include <Triple_Line_Model_FT_Disc.h>
22#include <Probleme_FT_Disc_gen.h>
23
24/*
25 * XXX XXX XXX
26 * Elie Saikali : NOTA BENE : fichier surcharger dans trio pour le FT, TCL model
27 */
28
29#define TCL_MODEL 1
30
31template<class _TYPE_> template<typename Type_Double>
32inline void Iterateur_VDF_Elem<_TYPE_>::fill_flux_tables_(const int face, const int ncomp, const double coeff, const Type_Double& flux, DoubleTab& resu) const
33{
34 DoubleTab& flux_bords = op_base->flux_bords();
35 const int elem1 = elem(face, 0), elem2 = elem(face, 1);
36
37#if TCL_MODEL
38 const Equation_base& eq = op_base->equation();
40 {
42 Transport_Interfaces_FT_Disc& eq_interface = eq_typee.eq_interface();
43 const DoubleTab& indicatrice = eq_interface.get_indicatrice().valeurs();
44 if (elem1 > -1)
45 for (int k = 0; k < ncomp; k++)
46 {
47 resu(elem1, k) += coeff * flux[k];
48 flux_bords(face, k) += coeff * flux[k];
49 if ((indicatrice(elem1) != 0.) && (indicatrice(elem1) != 1.))
50 {
51 Cerr << "echange_externe_impose face-no= " << face << " elem1= " << elem1 << " flux= " << flux(k) << finl;
52 // Energy is not resolved in elem0 (mixed-cell)
53 eq_typee.mixed_elems().append_array(elem1);
54 eq_typee.lost_fluxes().append_array(flux(k));
55 }
56
57 }
58 if (elem2 > -1)
59 for (int k = 0; k < ncomp; k++)
60 {
61 resu(elem2, k) -= coeff * flux[k];
62 flux_bords(face, k) -= coeff * flux[k];
63
64 if ((indicatrice(elem2) != 0.) && (indicatrice(elem2) != 1.))
65 {
66 Cerr << "echange_externe_impose face-no= " << face << " elem2= " << elem2 << " flux= " << flux(k) << finl;
67 // Energy is not resolved in elem1 (mixed-cell)
68 eq_typee.mixed_elems().append_array(elem2);
69 eq_typee.lost_fluxes().append_array(-flux(k)); // see convention above, the flux should be taken with "-" for elems 1!
70 }
71 }
72 }
73 else
74 {
75 if (elem1 > -1)
76 for (int k = 0; k < ncomp; k++)
77 {
78 resu(elem1, k) += coeff * flux[k];
79 flux_bords(face, k) += coeff * flux[k];
80 }
81 if (elem2 > -1)
82 for (int k = 0; k < ncomp; k++)
83 {
84 resu(elem2, k) -= coeff * flux[k];
85 flux_bords(face, k) -= coeff * flux[k];
86 }
87 }
88
89#else
90 if (elem1 > -1)
91 for (int k = 0; k < ncomp; k++)
92 {
93 resu(elem1, k) += coeff * flux[k];
94 flux_bords(face, k) += coeff * flux[k];
95 }
96 if (elem2 > -1)
97 for (int k = 0; k < ncomp; k++)
98 {
99 resu(elem2, k) -= coeff * flux[k];
100 flux_bords(face, k) -= coeff * flux[k];
101 }
102#endif
103}
104
105template<class _TYPE_> template<typename Type_Double>
106bool Iterateur_VDF_Elem<_TYPE_>::ajouter_blocs_bords_echange_ext_FT_TCL(const Echange_externe_impose& cl, const int ndeb, const int nfin, const int num_cl, const int N, const Front_VF& frontiere_dis,
107 matrices_t mats, DoubleTab& resu, const tabs_t& semi_impl) const
108{
109 const DoubleTab& donnee = semi_impl.count(nom_ch_inco_) ? semi_impl.at(nom_ch_inco_) : le_champ_convecte_ou_inc->valeurs();
110 Type_Double flux(N), aii(N), ajj(N), aef(N);
111 int boundary_index = -1;
112 if (le_dom->front_VF(num_cl).le_nom() == frontiere_dis.le_nom())
113 boundary_index = num_cl;
114
115 int e;
116 int Mv = le_ch_v ? le_ch_v->valeurs().line_size() : N;
117
118#if TCL_MODEL
119 const IntTab& face_voisins = le_dom->face_voisins();
120 const Probleme_base& pb_gen = op_base->equation().probleme();
121 const Equation_base& eq = op_base->equation();
122 const Probleme_FT_Disc_gen *pbft = dynamic_cast<const Probleme_FT_Disc_gen*>(&pb_gen);
123 const Triple_Line_Model_FT_Disc *tcl = pbft ? &pbft->tcl() : nullptr;
124 const int k = 0; // component of the variable (which is a scalar)
125#endif
126
127 for (int face = ndeb; face < nfin; face++)
128 {
129 const int local_face = le_dom->front_VF(boundary_index).num_local_face(face);
130 flux_evaluateur.flux_face(donnee, boundary_index, face, local_face, cl, ndeb, flux);
131#if TCL_MODEL
132 if (sub_type(Convection_Diffusion_Temperature_FT_Disc, eq) && tcl && tcl->is_activated())
133 {
134 // The model contribution has been computed before, and stored.
135 // And then, it can be simply accessed in const mode here.
136 // Cerr << "TCL is activated in flux iterator, we modify the contribution" << finl;
137 // get the CL contributions:
138 // HACK: dirty code, Where is my IT guy?
139 // I would need to move these reference to tables before the loop "for" to avoid making them
140 // so many times but I don't know how to proceed as "tcl" is only defined if sub_types are true.
141 // Or is it? Maybe it works in any case if any pb can have an empty tcl model as an embedded object...
142 const ArrOfInt& elems_with_CL_contrib = tcl->elems();
143 const ArrOfInt& boundary_faces = tcl->boundary_faces();
144 const ArrOfDouble& Q_from_CL = tcl->Q();
145 //tcl.compute_TCL_fluxes_in_all_boundary_cells(elems_with_CL_contrib, mpoint_from_CL, Q_from_CL);
146 const double sign = (face_voisins(face, 0) == -1) ? -1. : 1.;
147 const int nb_contact_line_contribution = Q_from_CL.size_array();
148 int nb_contrib = 0;
149 for (int idx = 0; idx < nb_contact_line_contribution; idx++)
150 {
151 const int elemi = elems_with_CL_contrib[idx];
152 const int facei = boundary_faces[idx];
153 const int elem_bord_with_facei = face_voisins(facei, 0)+face_voisins(facei, 1) +1;
154 if (facei == face)
155 {
156 // The corresponding contribution should be assigned to the face
157 nb_contrib++;
158 const double TCL_wall_flux = Q_from_CL[idx];
159 // val should be : -rho*Cp * flux(W)
160 // probably because the whole energy equation is written with rhoCp somewhere...
161 // and the sign should be negative for incoming flux (towards the fluid) by convention.
162 const double val = sign*TCL_wall_flux;
163 Cerr << "GB face: " << face << " former-flux = " << flux[k];
164 if (nb_contrib == 1)
165 {
166 flux[k] = val; // To erase the standard calculation without the model and replace it
167 // by part of the model
168 }
169 else
170 {
171 // If it's not the first contribution, it should be '+='
172 flux[k] += val;
173 }
174 Cerr << " new-flux = " << flux[k] << " [contrib #" << nb_contrib << "]" << finl;
175 if (elem_bord_with_facei != elemi)
176 {
177 // In this case, the flux is meso-region from a cell not adjacent to the wall.
178 // So what? Does it really matter?
179 // I believe that the fact that we take the interfacial flux from elemi and apply it at the wall
180 // face that is a boundary to elem_of_facei is not really an issue.
181 }
182 }
183 }
184 }
185#endif
186 fill_flux_tables_(face, N, 1.0 /* coeff */, flux, resu);
187 }
188
189 Matrice_Morse *m_vit = (mats.count("vitesse") && is_convective_op()) ? mats.at("vitesse") : nullptr, *mat = (!is_pb_multiphase() && mats.count(nom_ch_inco_)) ? mats.at(nom_ch_inco_) : nullptr;
190 VectorDeriv d_cc;
191 fill_derivee_cc(mats, semi_impl, d_cc);
192
193 //derivees : vitesse
194 if (m_vit)
195 {
196 DoubleTab val_b = use_base_val_b_ ? le_champ_convecte_ou_inc->Champ_base::valeur_aux_bords() : le_champ_convecte_ou_inc->valeur_aux_bords();
197 for (int face = ndeb; face < nfin; face++)
198 {
199 const int local_face = le_dom->front_VF(boundary_index).num_local_face(face);
200 flux_evaluateur.coeffs_face_bloc_vitesse(donnee, val_b, boundary_index, face, local_face, cl, ndeb, aef);
201
202 for (int i = 0; i < 2; i++)
203 if ((e = elem(face, i)) >= 0)
204 for (int n = 0, m = 0; n < N; n++, m += (Mv > 1)) (*m_vit)(N * e + n, Mv * face + m) += (i ? -1.0 : 1.0) * aef(n);
205 }
206 }
207
208 //derivees : champ convecte
209 if (mat || d_cc.size() > 0)
210 for (int face = ndeb; face < nfin; face++)
211 {
212 const int local_face = le_dom->front_VF(boundary_index).num_local_face(face);
213 flux_evaluateur.coeffs_face(donnee, boundary_index, face, local_face, ndeb, cl, aii, ajj);
214 fill_coeffs_matrices(face, aii, ajj, mat, d_cc); // XXX : Attention Yannick pour d_cc c'est pas tout a fait comme avant ... N et M ...
215 }
216
217 return true; /* XXX ATTENTION : true dans trio ... */
218}
219
220#endif /* Iterateur_VDF_Elem_FT_TCL_TPP_included */
virtual DoubleTab & valeurs()=0
Classe Echange_externe_impose: Cette classe represente le cas particulier de la classe.
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
class Front_VF
Definition Front_VF.h:36
const Nom & le_nom() const override
Renvoie le nom de la frontiere geometrique.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
const Triple_Line_Model_FT_Disc & tcl() const
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
virtual const Equation_base & equation(int) const =0
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
const Champ_base & get_indicatrice() override
getter champ variables_internes_->indicatrice_cache a partir de la position des interfaces.