TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Op_Div_PolyMAC_CDO.cpp
1/****************************************************************************
2* Copyright (c) 2026, 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 <Check_espace_virtuel.h>
17#include <Domaine_Cl_PolyMAC_family.h>
18#include <Navier_Stokes_std.h>
19#include <Schema_Temps_base.h>
20#include <Op_Div_PolyMAC_CDO.h>
21#include <Probleme_base.h>
22#include <EcrFicPartage.h>
23#include <Matrice_Morse.h>
24#include <Matrix_tools.h>
25#include <Array_tools.h>
26#include <SFichier.h>
27#include <Debog.h>
28
29Implemente_instanciable(Op_Div_PolyMAC_CDO, "Op_Div_PolyMAC_CDO", Operateur_Div_base);
30
31Sortie& Op_Div_PolyMAC_CDO::printOn(Sortie& s) const { return s << que_suis_je(); }
32
34
35void Op_Div_PolyMAC_CDO::associer(const Domaine_dis_base& domaine_dis, const Domaine_Cl_dis_base& domaine_Cl_dis, const Champ_Inc_base&)
36{
37 le_dom_PolyMAC_CDO = ref_cast(Domaine_PolyMAC_CDO, domaine_dis);
38 le_dcl_PolyMAC_CDO = ref_cast(Domaine_Cl_PolyMAC_family, domaine_Cl_dis);
39}
40
41DoubleTab& Op_Div_PolyMAC_CDO::ajouter(const DoubleTab& vit, DoubleTab& div) const
42{
44
45 Debog::verifier("div in", div);
46 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
47 const DoubleVect& surface = domaine_PolyMAC_CDO.face_surfaces();
48 const IntTab& face_voisins = domaine_PolyMAC_CDO.face_voisins();
49 const DoubleVect& porosite_surf = equation().milieu().porosite_face();
50
51 // L'espace virtuel du tableau div n'est pas mis a jour par l'operateur,
52 // assert(invalide_espace_virtuel(div));
53 declare_espace_virtuel_invalide(div);
54 // calcul de flux bord
55
56 DoubleTab& tab_flux_bords = flux_bords_;
57 tab_flux_bords.resize(domaine_PolyMAC_CDO.nb_faces_bord(), 1);
58 tab_flux_bords = 0.;
59
60 const int premiere_face_int = domaine_PolyMAC_CDO.premiere_face_int();
61 const int nb_faces = domaine_PolyMAC_CDO.nb_faces();
62
63 for (int face = 0; face < premiere_face_int; face++)
64 {
65 const double flux = porosite_surf[face] * vit[face] * surface[face];
66 tab_flux_bords(face, 0) += flux;
67
68 const int elem1 = face_voisins(face, 0);
69 if (elem1 != -1)
70 div(elem1) += flux;
71
72 const int elem2 = face_voisins(face, 1);
73 if (elem2 != -1)
74 div(elem2) -= flux;
75 }
76
77 for (int face = premiere_face_int; face < nb_faces; face++)
78 {
79 const double flux = porosite_surf[face] * vit[face] * surface[face];
80
81 const int elem1 = face_voisins(face, 0);
82 assert(domaine_PolyMAC_CDO.oriente_normale(face, elem1) == 1);
83 div(elem1) += flux;
84
85 const int elem2 = face_voisins(face, 1);
86 div(elem2) -= flux;
87 }
89 Debog::verifier("div out", div);
90 return div;
91}
92void Op_Div_PolyMAC_CDO::contribuer_a_avec(const DoubleTab& incoo, Matrice_Morse& matrice) const
93{
95 {
97 return;
98 }
99
100 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
101 const DoubleVect& surface = domaine_PolyMAC_CDO.face_surfaces();
102 const IntTab& face_voisins = domaine_PolyMAC_CDO.face_voisins();
103 const DoubleVect& porosite_surf = equation().milieu().porosite_face();
104
105 const int nb_faces = domaine_PolyMAC_CDO.nb_faces();
106
107 for (int face = 0; face < nb_faces; face++)
108 {
109 // flux * -1 car contribuer_a_avec renvoie -d/dI
110 const double flux = -porosite_surf[face] * surface[face];
111
112 const int elem1 = face_voisins(face, 0);
113 if (elem1 != -1)
114 matrice(elem1, face) += flux;
115
116 const int elem2 = face_voisins(face, 1);
117 if (elem2 != -1)
118 matrice(elem2, face) -= flux;
119 }
120}
121
123{
125 {
127 return;
128 }
129
130 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
131 int nb_faces = domaine_PolyMAC_CDO.nb_faces();
132 int nb_faces_tot = domaine_PolyMAC_CDO.nb_faces_tot();
133 int nb_elem_tot = domaine_PolyMAC_CDO.nb_elem_tot();
134 Stencil stencyl(0, 2);
135
136 const IntTab& face_voisins = domaine_PolyMAC_CDO.face_voisins();
137
138 int nb_coef = 0;
139 for (int face = 0; face < nb_faces; face++)
140 {
141 for (int dir = 0; dir < 2; dir++)
142 {
143 const int elem = face_voisins(face, dir);
144 if (elem != -1)
145 {
146 stencyl.resize(nb_coef + 1, 2);
147 stencyl(nb_coef, 0) = elem;
148 stencyl(nb_coef, 1) = face;
149 nb_coef++;
150 }
151 }
152 }
153 tableau_trier_retirer_doublons(stencyl);
154 Matrix_tools::allocate_morse_matrix(nb_elem_tot, nb_faces_tot, stencyl, matrice);
155}
156
157DoubleTab& Op_Div_PolyMAC_CDO::calculer(const DoubleTab& vit, DoubleTab& div) const
158{
159 div = 0.;
160 return ajouter(vit, div);
161}
162
164{
165 const int impr_bord = (le_dom_PolyMAC_CDO->domaine().bords_a_imprimer().est_vide() ? 0 : 1);
167 EcrFicPartage Flux_face;
168 ouvrir_fichier_partage(Flux_face, "", impr_bord);
170 const double temps = sch.temps_courant();
171 if (je_suis_maitre())
172 Flux_div.add_col(temps);
173
174 const int nb_compo = flux_bords_.dimension(1);
175
176 // On parcours les frontieres pour sommer les flux par frontiere dans le tableau flux_bord
177 DoubleVect flux_bord(nb_compo);
178 DoubleVect bilan(nb_compo);
179 bilan = 0.;
180
181 for (int num_cl = 0; num_cl < le_dom_PolyMAC_CDO->nb_front_Cl(); num_cl++)
182 {
183 flux_bord = 0;
184 const Cond_lim& la_cl = le_dcl_PolyMAC_CDO->les_conditions_limites(num_cl);
185 const Front_VF& frontiere_dis = ref_cast(Front_VF, la_cl->frontiere_dis());
186 const int ndeb = frontiere_dis.num_premiere_face();
187 const int nfin = ndeb + frontiere_dis.nb_faces();
188 for (int face = ndeb; face < nfin; face++)
189 for (int k = 0; k < nb_compo; k++)
190 flux_bord(k) += flux_bords_(face, k);
191
192 for (int k = 0; k < nb_compo; k++)
193 flux_bord(k) = Process::mp_sum(flux_bord(k));
194
195 if (je_suis_maitre())
196 {
197 for (int k = 0; k < nb_compo; k++)
198 {
199 //Ajout pour impression sur fichiers separes
200 Flux_div.add_col(flux_bord(k));
201 bilan(k) += flux_bord(k);
202 }
203 }
204 }
205
206 if (je_suis_maitre())
207 {
208 for (int k = 0; k < nb_compo; k++)
209 Flux_div.add_col(bilan(k));
210
211 Flux_div << finl;
212 }
213
214 for (int num_cl = 0; num_cl < le_dom_PolyMAC_CDO->nb_front_Cl(); num_cl++)
215 {
216 const Frontiere_dis_base& la_fr = le_dcl_PolyMAC_CDO->les_conditions_limites(num_cl)->frontiere_dis();
217 const Cond_lim& la_cl = le_dcl_PolyMAC_CDO->les_conditions_limites(num_cl);
218 const Front_VF& frontiere_dis = ref_cast(Front_VF, la_cl->frontiere_dis());
219 int ndeb = frontiere_dis.num_premiere_face();
220 int nfin = ndeb + frontiere_dis.nb_faces();
221 if (le_dom_PolyMAC_CDO->domaine().bords_a_imprimer().contient(la_fr.le_nom()))
222 {
223 Flux_face << "# Flux par face sur " << la_fr.le_nom() << " au temps " << temps << " : " << finl;
224 for (int face = ndeb; face < nfin; face++)
225 {
226 if (dimension == 2)
227 Flux_face << "# Face a x= " << le_dom_PolyMAC_CDO->xv(face, 0) << " y= " << le_dom_PolyMAC_CDO->xv(face, 1) << " flux=";
228 else if (dimension == 3)
229 Flux_face << "# Face a x= " << le_dom_PolyMAC_CDO->xv(face, 0) << " y= " << le_dom_PolyMAC_CDO->xv(face, 1) << " z= " << le_dom_PolyMAC_CDO->xv(face, 2) << " flux=";
230 for (int k = 0; k < nb_compo; k++)
231 Flux_face << " " << flux_bords_(face, k);
232 Flux_face << finl;
233 }
234 Flux_face.syncfile();
235 }
236 }
237
238 return 1;
239}
240
241void Op_Div_PolyMAC_CDO::volumique(DoubleTab& div) const
242{
243 const Domaine_PolyMAC_CDO& domaine_PolyMAC_CDO = le_dom_PolyMAC_CDO.valeur();
244 const DoubleVect& vol = domaine_PolyMAC_CDO.volumes();
245 const int nb_elem = domaine_PolyMAC_CDO.domaine().nb_elem_tot();
246
247 for (int num_elem = 0; num_elem < nb_elem; num_elem++)
248 div(num_elem) /= vol(num_elem);
249}
Classe Champ_Inc_base.
classe Cond_lim Classe generique servant a representer n'importe quelle classe
Definition Cond_lim.h:31
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
int_t nb_elem_tot() const
Definition Domaine.h:132
classe Domaine_Cl_dis_base Les objets Domaine_Cl_dis_base representent les conditions aux limites
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
int nb_faces_tot() const
renvoie le nombre total de faces.
Definition Domaine_VF.h:481
double volumes(int i) const
Definition Domaine_VF.h:113
int oriente_normale(int f, int e) const
Definition Domaine_VF.h:194
int premiere_face_int() const
une face est interne ssi elle separe deux elements.
Definition Domaine_VF.h:463
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_faces_bord() const
renvoie le nombre de faces sur lesquelles sont appliquees les conditions limites :
Definition Domaine_VF.h:513
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
int nb_elem_tot() const
const Domaine & domaine() const
Sortie & syncfile() override
Provoque l'ecriture sur disque des donnees accumulees sur les differents processeurs depuis le dernie...
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
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
classe Frontiere_dis_base Classe representant une frontiere discretisee.
const Nom & le_nom() const override
Renvoie le nom de la frontiere geometrique.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
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)
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
static int dimension
Definition Objet_U.h:99
friend class Sortie
Definition Objet_U.h:75
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
class Op_Div_PolyMAC_CDO
DoubleTab & calculer(const DoubleTab &, DoubleTab &) const override
int impr(Sortie &os) const override
DOES NOTHING - to override in derived classes.
DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const override
void volumique(DoubleTab &) const override
void contribuer_a_avec(const DoubleTab &, Matrice_Morse &matrice) const override
DOES NOTHING - to override in derived classes.
void dimensionner(Matrice_Morse &matrice) const override
DOES NOTHING - to override in derived classes.
void associer(const Domaine_dis_base &, const Domaine_Cl_dis_base &, const Champ_Inc_base &) override
Classe Operateur_Div_base Cette classe est la base de la hierarchie des operateurs representant.
DoubleTab & ajouter(const DoubleTab &vit, DoubleTab &div) const override
virtual void contribuer_a_avec(const DoubleTab &, Matrice_Morse &) const
DOES NOTHING - to override in derived classes.
virtual int has_interface_blocs() const
DoubleTab flux_bords_
void ouvrir_fichier_partage(EcrFicPartage &, const Nom &, const int flag=1) const
Ouverture/creation d'un fichier d'impression d'un operateur A surcharger dans les classes derivees.
virtual void dimensionner(Matrice_Morse &) const
DOES NOTHING - to override in derived classes.
void ouvrir_fichier(SFichier &os, const Nom &, const int flag=1) const
Ouverture/creation d'un fichier d'impression d'un operateur A surcharger dans les classes derivees.
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86
class Schema_Temps_base
double temps_courant() const
Renvoie le temps courant.
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
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")