TRUST 1.9.8
HPC thermohydraulic platform
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 //tableaux lies a la stabilisation de Le Potier / Mahamane (cf. 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; //pas besoin du reste
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 -> processeur/item de l'element, puis des autres faces utilisees dans W2(f,.) pour chaque face de la frontiere */
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; //nombre max d'items/coeffs a echanger par 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; //on finit avec des -1
104 }
105 c_max = Process::mp_max(c_max);
106
107 //projection sur la frontiere locale
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 //remplissage
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)); //item local (reel)
117 else
118 {
119 if (o_domaine.virt_ef_map.count({{ (int) proc(i, j), (int) l_item(i, j) }})) //item local (virtuel)
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 coeff de plus que item -> celui de la face elle-meme (mis au debut)
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 //objets de l'autre cote : equation, domaine, inconnue (prefix o_), frontiere (pour faire 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 //tableaux "nu_faces" utilises par les operateurs de diffusion de chaque cote
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 //tableaux aux faces de l'autre cote, a transmettre par o_fr.trace_face_{distant,local} : on ne les remplit que sur les faces de 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; //numero de la face f dans l'element e
166 o_op_diff.remplir_nu_ef(e, nu_ef);
167
168 /* construction du flux de chaleur sortant, en mettant la partie en T_f dans H_imp et le reste dans 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); //passage au vrai T_ext
186 for (n = 0; h_paroi < 1e9 && n < N; n++) //prise en compte de la resistance de la paroi
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 : soit par Raccord_distant_homogene, soit copie simple
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; //deja fait
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 //remplissage
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; //numero de la face f dans l'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++) //on saute le premier coeff (diagonale)
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
Renvoie le tableau des valeurs du champ au temps courant.
virtual void associer_fr_dis_base(const Frontiere_dis_base &)
Associe une frontiere discretisee au champ.
virtual DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ.
virtual void completer()
classe Champ_front_calc Classe derivee de Champ_front_var qui represente les
const Frontiere_dis_base & front_dis() const
Renvoie la frontiere discretisee correspondante au domaine sur lequel prend la trace.
void creer(const Nom &, const Nom &, const Motcle &)
Cree l'objet Champ_front_calc representant la trace d'un champ inconnue sur une frontiere a partir de...
int initialiser(double, const Champ_Inc_base &) override
Initialisation en debut de calcul.
const Equation_base & equation() const
Renvoie l'equation associee a l'inconnue dont on prend la trace.
const Champ_Inc_base & inconnue() const
Renvoie le champ inconnue associe.
const Domaine_dis_base & domaine_dis() const override
Renvoie le domaine discretise associe a l'equation qui porte le champ inconnue dont on prend la trace...
Domaine_Cl_dis_base & domaine_Cl_dis()
Renvoie le domaine des conditions aux limites discretisee dont l'objet fait partie.
virtual void completer()
NE FAIT RIEN A surcharger dans les classes derivees.
virtual Frontiere_dis_base & frontiere_dis()
Renvoie la frontiere discretisee a laquelle les conditions aux limites s'appliquent.
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
renvoie le nombre global de 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
renvoie le numero de le ieme face de la maille num_elem la facon dont ces faces sont numerotees est
Definition Domaine_VF.h:543
int face_voisins(int num_face, int i) const
renvoie l'element voisin de numface dans la direction i.
Definition Domaine_VF.h:418
int nb_elem_tot() const
void mettre_a_jour(double) override
Effectue une mise a jour en temps de la condition aux limites.
int initialiser(double temps) override
Initialisation en debut de calcul.
void completer() override
NE FAIT RIEN A surcharger dans les classes derivees.
Classe Echange_externe_impose: Cette classe represente le cas particulier de la classe.
int initialiser(double temps) override
Initialisation en debut de calcul.
virtual Champ_front_base & T_ext()
Renvoie le champ T_ext de temperature imposee a la frontiere.
void mettre_a_jour(double) override
Effectue une mise a jour en temps des conditions aux limites.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
Schema_Temps_base & schema_temps()
Renvoie le schema en temps associe a l'equation.
virtual const Operateur & operateur(int) const =0
virtual const Motcle & domaine_application() const
Renvoie "indetermine" Navier_Stokes_standard par exemple surcharge cette methode.
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
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
Cree un tableau ayant une "ligne" par face de cette frontiere Voir MD_Vector_tools::creer_tableau_dis...
const Frontiere & frontiere() const
Renvoie la frontiere geometrique associee.
const Nom & le_nom() const override
Renvoie le nom de la frontiere geometrique.
static void creer_tableau_distribue(const MD_Vector &, Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
transforme v en un tableau parallele ayant la structure md.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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:376
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
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")