TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Echange_contact_PolyMAC_CDO.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 <Echange_contact_PolyMAC_CDO.h>
17#include <Champ_front_calc.h>
18#include <Probleme_base.h>
19#include <Champ_Uniforme.h>
20#include <Schema_Euler_Implicite.h>
21#include <Milieu_base.h>
22#include <Domaine_PolyMAC_CDO.h>
23#include <Equation_base.h>
24#include <Champ_Elem_PolyMAC_CDO.h>
25#include <Op_Diff_PolyMAC_CDO_Elem.h>
26
27Implemente_instanciable(Echange_contact_PolyMAC_CDO,"Paroi_Echange_contact_PolyMAC_CDO",Echange_externe_impose);
28
30{
31 return s << que_suis_je() << "\n";
32}
33
35{
36 Nom nom_bord;
37 Motcle nom_champ;
38 s >> nom_autre_pb_ >> nom_bord >> nom_champ >> h_paroi;
39 T_autre_pb_.typer("Champ_front_calc");
40 Champ_front_calc& ch=ref_cast(Champ_front_calc, T_autre_pb());
41 ch.creer(nom_autre_pb_, nom_bord, nom_champ);
42 le_champ_front.typer("Ch_front_var_instationnaire_dep");
44 return s ;
45}
46
53
55{
57 return 0;
58
60 const Equation_base& o_eqn = ch.equation();
61 const Front_VF& fvf = ref_cast(Front_VF, frontiere_dis()), o_fvf = ref_cast(Front_VF, ch.front_dis());
62 const Domaine_PolyMAC_CDO& o_domaine = ref_cast(Domaine_PolyMAC_CDO, ch.domaine_dis());
63 const IntTab& o_f_e = o_domaine.face_voisins(), &o_e_f = o_domaine.elem_faces();
64 int i, j, k, l, e, f, N = ch.nb_comp(), o_n_f = o_e_f.dimension(1);
65 //Nom nom_racc1=frontiere_dis().frontiere().le_nom();
66
67 //arrays related to the Le Potier / Mahamane stabilization (see Op_Diff_PolyMAC_CDO_Elem)
68 stab_ = ref_cast(Op_Diff_PolyMAC_CDO_Elem, o_eqn.operateur(0).l_op_base()).stab_;
69
70 h_imp_.typer("Champ_front_fonc");
71 h_imp_->fixer_nb_comp(N);
72 h_imp_->valeurs().resize(0, N);
73 fvf.frontiere().creer_tableau_faces(h_imp_->valeurs());
74
75 ch.initialiser(temps,domaine_Cl_dis().equation().inconnue());
76
78 ref_cast(Schema_Euler_Implicite, o_eqn.schema_temps()).resolution_monolithique(o_eqn.domaine_application()) : 0;
79 if (!monolithic) return 1; //rest not needed
80 o_domaine.init_m2(), o_domaine.init_virt_ef_map();
81
82 /* src(i) = (proc, j) : source de l'item i de mdv_elem_faces */
83 IntTab src(0, 2);
85 for (i = 0; i < src.dimension_tot(0); i++) src(i, 0) = Process::me(), src(i, 1) = i;
87
88 /* o_proc, o_item -> processor/item of the element, then of the other faces used in W2(f,.) for each face of the boundary */
89 DoubleTrav o_proc(0, o_n_f), o_item(0, o_n_f), proc(0, o_n_f), l_item(0, o_n_f);
90 o_domaine.creer_tableau_faces(o_proc), o_domaine.creer_tableau_faces(o_item);
92 int c_max = 1; //maximum number of items/coefficients to exchange per face
93 for (i = 0; i < o_fvf.nb_faces(); i++)
94 {
95 f = o_fvf.num_face(i), e = o_f_e(f, 0);
96 for (j = 0; j < o_n_f && o_e_f(e, j) != f; ) j++; // f = o_e_f(e, j)
97 o_proc(f, 0) = src(e, 0), o_item(f, 0) = src(e, 1); //element
98 for (k = o_domaine.w2i(o_domaine.m2d(e) + j) + 1, l = 1; k < o_domaine.w2i(o_domaine.m2d(e) + j + 1); k++, l++) //W2 hors diag
99 {
100 int idx = o_domaine.nb_elem_tot() + o_e_f(e, o_domaine.w2j(k));
101 o_proc(f, l) = src(idx, 0), o_item(f, l) = src(idx, 1);
102 }
103 for (c_max = std::max(c_max, l); l < o_n_f; l++) o_proc(f, l) = o_item(f, l) = -1; //fill remaining entries with -1
104 }
105 c_max = Process::mp_max(c_max);
106
107 //projection onto the local boundary
108 if (o_fvf.frontiere().que_suis_je() == "Raccord_distant_homogene")
109 o_fvf.frontiere().trace_face_distant(o_proc, proc), o_fvf.frontiere().trace_face_distant(o_item, l_item);
110 else o_fvf.frontiere().trace_face_local(o_proc, proc), o_fvf.frontiere().trace_face_local(o_item, l_item);
111
112 //filling
113 item.resize(fvf.nb_faces(), c_max), item = -1;
114 for (i = 0; i < fvf.nb_faces(); i++)
115 for (j = 0; j < c_max && l_item(i, j) >= 0; j++)
116 if (proc(i, j) == Process::me()) item(i, j) = (int)std::lrint(l_item(i, j)); //local item (real)
117 else
118 {
119 if (o_domaine.virt_ef_map.count({{ (int) proc(i, j), (int) l_item(i, j) }})) //local item (virtual)
120 {
121 item(i, j) = o_domaine.virt_ef_map.at({{ (int) proc(i, j), (int) l_item(i, j) }});
122 }
123 else Process::exit(Nom("Echange_contact_PolyMAC_CDO: missing item opposite face ") + Nom(fvf.num_face(i)) + " on " + fvf.le_nom() + " ! Have you used Decouper_multi?");
124 }
125
126 //coeff: 1 coefficient more than item -> the one for the face itself (placed at the beginning)
127 coeff.resize(0, 1 + item.dimension(1), N), delta_int.resize(0, N, 2),
128 fvf.frontiere().creer_tableau_faces(coeff);
129
130 if (stab_)
131 {
132 delta.resize(0, item.dimension(1), N);
133 fvf.frontiere().creer_tableau_faces(delta_int), fvf.frontiere().creer_tableau_faces(delta);
134 }
135 coeffs_a_jour_ = 0, delta_a_jour_ = (stab_ ? 1 : 0);
136 return 1;
137}
138
140{
141 if (coeffs_a_jour_) return;
142 //objects on the other side: equation, domain, unknown (prefix o_), boundary (for trace_face_distant)
144 const Domaine_PolyMAC_CDO& o_domaine = ref_cast(Domaine_PolyMAC_CDO, ch.domaine_dis());
145 const Equation_base& o_eqn = ch.equation();
146 const Op_Diff_PolyMAC_CDO_Elem& o_op_diff = ref_cast(Op_Diff_PolyMAC_CDO_Elem, o_eqn.operateur(0).l_op_base());
147 const Champ_Elem_PolyMAC_CDO& o_inc = ref_cast(Champ_Elem_PolyMAC_CDO, ch.inconnue());
148 const Front_VF& o_fvf = ref_cast(Front_VF, ch.front_dis());
149 const IntTab& e_f = o_domaine.elem_faces();
150 const DoubleVect& fs = o_domaine.face_surfaces(), &ve = o_domaine.volumes();
151
152 //"nu_faces" arrays used by the diffusion operators on each side
153 o_op_diff.update_nu(), o_op_diff.update_delta_int();
154 int ne_tot = o_domaine.nb_elem_tot(), N = ch.nb_comp();
155
156 //arrays at faces on the other side, to be transmitted via o_fr.trace_face_{distant,local}: filled only for faces of o_fr
157 o_domaine.init_m2();
158 DoubleTrav o_Text, o_Himp, o_coeff, o_delta_int, nu_ef(e_f.dimension(1), N);
159 if (monolithic) o_coeff.resize(o_domaine.nb_faces(), 1 + item.dimension(1), N), o_delta_int.resize(o_domaine.nb_faces(), N, 2);
160 else o_Text.resize(o_domaine.nb_faces(), N), o_Himp.resize(o_domaine.nb_faces(), N);
161 for (int i = 0; i < o_fvf.nb_faces(); i++)
162 {
163 int f = o_fvf.num_face(i), e = o_domaine.face_voisins(f, 0), fb, j, k, n, i_f = 0, idx;
164 for (j = 0; j < e_f.dimension(1) && (fb = e_f(e, j)) >= 0; j++)
165 if (fb == f) i_f = j; //index of face f within element e
166 o_op_diff.remplir_nu_ef(e, nu_ef);
167
168 /* build the outgoing heat flux, putting the T_f part in H_imp and the rest in T_ext */
169 for (j = o_domaine.w2i(o_domaine.m2d(e) + i_f), idx = 0; j < o_domaine.w2i(o_domaine.m2d(e) + i_f + 1); j++, idx++)
170 for (fb = e_f(e, o_domaine.w2j(j)), n = 0; n < N; n++)
171 {
172 double fac = fs(fb) / ve(e) * o_domaine.w2c(j) * nu_ef(o_domaine.w2j(j), n);
173 if (monolithic)
174 o_coeff(f, idx ? idx + 1 : 0, n) += fs(f) * fac, o_coeff(f, 1, n) -= fs(f) * fac; //cote face, cote element
175 else
176 {
177 if (f == fb) o_Himp(f, n) += fac;
178 else o_Text(f, n) -= fac * o_inc.valeurs()(ne_tot + fb, n);
179 o_Text(f, n) += fac * o_inc.valeurs()(e, n);
180 }
181 }
182 for (n = 0; stab_ && monolithic && n < N; n++)
183 for (k = 0; k < 2; k++) o_delta_int(f, n, k) = o_op_diff.delta_f_int(f, n, k);
184 for (n = 0; !monolithic && n < N; n++)
185 if (o_Himp(f, n) > 1e-10) o_Text(f, n) /= o_Himp(f, n); //convert to actual T_ext
186 for (n = 0; h_paroi < 1e9 && n < N; n++) //account for the wall thermal resistance
187 {
188 double fac = h_paroi / (h_paroi + (monolithic ? o_coeff(f, 0, n) / fs(f) : o_Himp(f, n)));
189 if (monolithic)
190 {
191 if (stab_) o_delta_int(f, n, 0) *= fac;
192 for (j = 0; j < o_coeff.dimension(1); j++) o_coeff(f, j, n) *= fac;
193 }
194 else o_Himp(f, n) *= fac;
195 }
196 }
197
198 //transmission: either via Raccord_distant_homogene, or simple copy
199 if (o_fvf.frontiere().que_suis_je() == "Raccord_distant_homogene")
200 {
201 if (monolithic) o_fvf.frontiere().trace_face_distant(o_coeff, coeff);
202 else o_fvf.frontiere().trace_face_distant(o_Text, T_ext().valeurs()), o_fvf.frontiere().trace_face_distant(o_Himp, h_imp_->valeurs());
203 if (monolithic && stab_) o_fvf.frontiere().trace_face_distant(o_delta_int, delta_int);
204 }
205 else
206 {
207 if (monolithic) o_fvf.frontiere().trace_face_local(o_coeff, coeff);
208 else o_fvf.frontiere().trace_face_local(o_Text, T_ext().valeurs()), o_fvf.frontiere().trace_face_local(o_Himp, h_imp_->valeurs());
209 if (monolithic && stab_) o_fvf.frontiere().trace_face_local(o_delta_int, delta_int);
210 }
211
212 if (monolithic) coeff.echange_espace_virtuel();
213 else T_ext().valeurs().echange_espace_virtuel(), h_imp_->valeurs().echange_espace_virtuel();
214 if (monolithic && stab_) delta_int.echange_espace_virtuel();
215 coeffs_a_jour_ = 1;
216}
217
219{
220 if (!monolithic || delta_a_jour_) return; //already done
221 const Champ_front_calc& ch=ref_cast(Champ_front_calc, T_autre_pb());
222 const Front_VF& o_fvf = ref_cast(Front_VF, ch.front_dis());
223 const Domaine_PolyMAC_CDO& o_domaine = ref_cast(Domaine_PolyMAC_CDO, ch.domaine_dis());
224 const Equation_base& o_eqn = ch.equation();
225 const Op_Diff_PolyMAC_CDO_Elem& o_op_diff = ref_cast(Op_Diff_PolyMAC_CDO_Elem, o_eqn.operateur(0).l_op_base());
226 const IntTab& e_f = o_domaine.elem_faces();
227
228 //filling
229 o_op_diff.update_delta();
230 int i, j, n, N = ch.nb_comp();
231 DoubleTrav o_delta(o_domaine.nb_faces(), item.dimension(1), N);
232 for (i = 0; i < o_fvf.nb_faces(); i++)
233 {
234 int f = o_fvf.num_face(i), fb, e = o_domaine.face_voisins(f, 0), i_f = 0, idx;
235 for (j = 0; j < e_f.dimension(1) && (fb = e_f(e, j)) >= 0; j++)
236 if (fb == f) i_f = j; //index of face f within element e
237 for (n = 0; n < N; n++) o_delta(f, 0, n) = o_op_diff.delta_e(e, n);
238 for (j = o_domaine.w2i(o_domaine.m2d(e) + i_f) + 1, idx = 1; j < o_domaine.w2i(o_domaine.m2d(e) + i_f + 1); j++, idx++) //skip the first coefficient (diagonal)
239 for (n = 0; n < N; n++) o_delta(f, idx, n) = o_op_diff.delta_f(e_f(e, o_domaine.w2j(j)), n);
240 }
241
242 //transmission
243 if (o_fvf.frontiere().que_suis_je() == "Raccord_distant_homogene") o_fvf.frontiere().trace_face_distant(o_delta, delta);
244 else o_fvf.frontiere().trace_face_local(o_delta, delta);
245 delta.echange_espace_virtuel();
246 delta_a_jour_ = 1;
247}
248
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual void associer_fr_dis_base(const Frontiere_dis_base &)
Associates a discretized boundary with the field.
virtual DoubleTab & valeurs() override
Returns the array of field values.
virtual void completer()
class Champ_front_calc Derived class of Champ_front_var representing
const Frontiere_dis_base & front_dis() const
Returns the discretized boundary corresponding to the domain on which the trace is taken.
void creer(const Nom &, const Nom &, const Motcle &)
Create the Champ_front_calc object representing the trace of an unknown field on a boundary from name...
int initialiser(double, const Champ_Inc_base &) override
Initialization at the beginning of calculation.
const Equation_base & equation() const
Returns the equation associated with the unknown whose trace is taken.
const Champ_Inc_base & inconnue() const
Returns the associated unknown field.
const Domaine_dis_base & domaine_dis() const override
Returns the discretized domain associated with the equation carrying the unknown field whose trace is...
Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the domain of discretized boundary conditions to which the object belongs.
virtual void completer()
DOES NOTHING must be overridden in derived classes.
virtual Frontiere_dis_base & frontiere_dis()
Returns the discretized boundary to which the boundary conditions apply.
std::map< std::array< int, 2 >, int > virt_ef_map
virtual const DoubleVect & face_surfaces() const
Definition Domaine_VF.h:51
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
void creer_tableau_faces(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
double volumes(int i) const
Definition Domaine_VF.h:113
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
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_elem_tot() const
void mettre_a_jour(double) override
Performs a time update of the boundary condition.
int initialiser(double temps) override
Initialization at the beginning of the calculation.
void completer() override
DOES NOTHING must be overridden in derived classes.
Classe Echange_externe_impose: This class represents the special case of the class.
int initialiser(double temps) override
Initialization at the beginning of the calculation.
virtual Champ_front_base & T_ext()
Returns the T_ext field of temperature imposed at the boundary.
void mettre_a_jour(double) override
Performs a time update of the boundary conditions.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
virtual const Operateur & operateur(int) const =0
virtual const Motcle & domaine_application() const
Returns "indeterminate" Navier_Stokes_standard for example overrides this method.
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
virtual int nb_comp() const
Definition Field_base.h:56
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_face(const int) const
Definition Front_VF.h:68
virtual void trace_face_distant(const DoubleTab &, DoubleTab &) const
virtual void trace_face_local(const DoubleTab &, DoubleTab &) const
virtual void creer_tableau_faces(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates an array with one "row" per face of this boundary.
const Frontiere & frontiere() const
Returns the associated geometric boundary.
const Nom & le_nom() const override
Returns the name of the geometric boundary.
static void creer_tableau_distribue(const MD_Vector &, Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Transforms v into a parallel array having the structure md.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
void remplir_nu_ef(int e, DoubleTab &nu_ef) const
virtual Operateur_base & l_op_base()=0
static double mp_max(double)
Definition Process.cpp:379
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
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
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")