TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Perte_Charge_Singuliere_VDF_Face.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 <Perte_Charge_Singuliere_VDF_Face.h>
17#include <Champ_Face_VDF.h>
18#include <Equation_base.h>
19#include <Pb_Multiphase.h>
20#include <Matrice_Morse.h>
21#include <Matrix_tools.h>
22#include <Array_tools.h>
23#include <Domaine_VDF.h>
24#include <Motcle.h>
25
26Implemente_instanciable(Perte_Charge_Singuliere_VDF_Face,"Perte_Charge_Singuliere_VDF_Face",Perte_Charge_VDF_Face);
27
29{
30 return s << que_suis_je() ;
31}
32
34{
37 if (regul_) //fichier de sortie si regulation
38 {
39 bilan().resize(3); //K deb cible
40 set_fichier(Nom("K_") + identifiant_);
41 set_description(Nom("Regulation du Ksing de la surface ") + identifiant_ + "\nt K deb cible");
42 }
43 return s;
44}
45
47{
49 // eq_masse besoin de champ_conserve !
50 if (sub_type(Pb_Multiphase, mon_equation->probleme()))
51 ref_cast(Pb_Multiphase, mon_equation->probleme()).equation_masse().init_champ_conserve();
52}
53
55{
56 const Domaine& le_domaine = equation().probleme().domaine();
57 const Domaine_VDF& domaine_VDF = ref_cast(Domaine_VDF,equation().domaine_dis());
58 int taille_bloc = domaine_VDF.nb_elem();
59 num_faces.resize(taille_bloc);
60 lire_surfaces(s,le_domaine,domaine_VDF,num_faces, sgn);
61 int nfac = num_faces.size();
62 int nfac_tot = static_cast<int>(mp_sum(num_faces.size()));
63 if (nfac_tot==0)
64 {
65 Cerr << "Erreur a la lecture des donnees de la perte de charge singuliere :" << finl;
66 Cerr << " la surface sur laquelle vous avez defini une perte de charge" << finl;
67 Cerr << " ne contient entierement aucune des faces de la geometrie " << finl;
68 exit();
69 }
70
71 if (nfac != 0)
72 {
73 int ori = domaine_VDF.orientation(num_faces[0]);
74 if (ori != direction_perte_charge())
75 {
76 Cerr << "Erreur a la lecture des donnees de la perte de charge singuliere : " << finl;
77 Cerr << " l'orientation de la surface est differente de la direction" << finl;
78 Cerr << " de la perte de charge" << finl;
79 exit();
80 }
81 }
82}
83
84
85void Perte_Charge_Singuliere_VDF_Face::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
86{
87 const std::string& nom_inco = equation().inconnue().le_nom().getString();
88 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr, mat2;
89
90 const Domaine_VDF& domaine_VDF = le_dom_VDF.valeur();
91 Stencil stencil(0, 2);
92
93 for (int f = 0; f < domaine_VDF.nb_faces(); f++)
94 stencil.append_line(f, f);
95 tableau_trier_retirer_doublons(stencil);
96 if (mat && axi)
97 {
98 Matrix_tools::allocate_morse_matrix(domaine_VDF.nb_faces_tot(), domaine_VDF.nb_faces_tot(), stencil, mat2);
99 mat->nb_colonnes() ? *mat += mat2 : *mat = mat2;
100 }
101
102}
103
104void Perte_Charge_Singuliere_VDF_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
105{
106 const std::string& nom_inco = equation().inconnue().le_nom().getString();
107 const DoubleTab& inco = semi_impl.count(nom_inco) ? semi_impl.at(nom_inco) : equation().inconnue().valeurs();
108 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
109 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
110
111 const Domaine_VDF& domaine_VDF = le_dom_VDF.valeur();
112 const DoubleVect& volumes_entrelaces = domaine_VDF.volumes_entrelaces();
113 const DoubleVect& porosite_surf = equation().milieu().porosite_face();
114 const DoubleTab& vit = la_vitesse->valeurs(),&vfd = domaine_VDF.volumes_entrelaces_dir(),
115 *alpha = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr,
116 *a_r = pbm ? &pbm->equation_masse().champ_conserve().passe() : nullptr;;
117 int ndeb_faces_int = domaine_VDF.premiere_face_int();
118
119 const int nb_faces = num_faces.size(), N = equation().inconnue().valeurs().line_size();
120 double Ck;
121 const IntTab& f_e = domaine_VDF.face_voisins();
122 DoubleTrav aar_f(N); //alpha * alpha * rho a chaque face
123
124 if (axi)
125 for (int i=0; i<nb_faces; i++)
126 {
127 const int numfa = num_faces[i];
128
129 if (pbm)
130 {
131 aar_f = 0.;
132 for (int j = 0; j < 2; j++)
133 {
134 const int e = f_e(numfa, j);
135
136 if (e < 0 ) continue;
137
138 for (int n = 0; n < N; n++)
139 aar_f(n) += vfd(numfa, j) / volumes_entrelaces(numfa) * (*a_r)(e, n) * (*alpha)(e, n);
140 }
141 }
142 else aar_f = 1.;
143
144
145 if (numfa < ndeb_faces_int)
146 Ck = -0.5*K()/le_dom_VDF->dist_norm_bord_axi(numfa);
147 else
148 Ck = -0.5*K()/le_dom_VDF->dist_norm_axi(numfa);
149 for (int n = 0; n < N; n++)
150 {
151 const double U = vit(numfa, n);
152 secmem(numfa, n) += aar_f(n) * Ck*U*std::fabs(U)*volumes_entrelaces[numfa]*porosite_surf[numfa];
153 }
154 }
155 else
156 for (int i=0; i<nb_faces; i++)
157 {
158 const int numfa = num_faces[i];
159 if (pbm)
160 {
161 aar_f = 0.;
162 for (int j = 0; j < 2; j++)
163 {
164 const int e = f_e(numfa, j);
165
166 if (e < 0 ) continue;
167
168 for (int n = 0; n < N; n++)
169 aar_f(n) += vfd(numfa, j) / volumes_entrelaces(numfa) * (*a_r)(e, n) * (*alpha)(e, n);
170 }
171 }
172 else aar_f = 1.;
173
174 if (numfa < ndeb_faces_int)
175 Ck = -0.5 * K() / le_dom_VDF->dist_norm_bord(numfa);
176 else
177 Ck = -0.5 * K() / le_dom_VDF->dist_norm(numfa);
178
179 for (int n = 0; n < N; n++)
180 {
181 const double Ud = vit(numfa, n) * porosite_surf[numfa]; // vitesse debitante
182 const double U = inco(numfa, n) * porosite_surf[numfa];
183
184 secmem(numfa,n) += aar_f(n) * Ck * U * std::fabs(Ud) * volumes_entrelaces[numfa] * porosite_surf[numfa];
185 if (mat)
186 (*mat)(N * numfa + n, N * numfa + n) -= aar_f(n) * Ck * porosite_surf[numfa] * std::fabs(Ud) * volumes_entrelaces[numfa] * porosite_surf[numfa];
187 }
188 }
189}
190
191DoubleTab& Perte_Charge_Singuliere_VDF_Face::ajouter_(const DoubleTab& inco, DoubleTab& resu) const
192{
193 const std::string& nom_inco = equation().inconnue().le_nom().getString();
194 ajouter_blocs({}, resu, {{nom_inco, inco}});
195 return resu;
196}
197
DoubleTab & passe(int i=1) override
Renvoie les valeurs du champs a l'instant t-i.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
class Domaine_VDF
Definition Domaine_VDF.h:64
int orientation(int) const override
inline DoubleVect& Domaine_VDF::porosite_face() {
int nb_faces() const
renvoie le nombre global de faces.
Definition Domaine_VF.h:471
DoubleVect & volumes_entrelaces()
Definition Domaine_VF.h:99
int nb_faces_tot() const
renvoie le nombre total de faces.
Definition Domaine_VF.h:481
const DoubleTab & volumes_entrelaces_dir() const
Definition Domaine_VF.h:102
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
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
Champ_Inc_base & champ_conserve() const
virtual const Champ_Inc_base & inconnue() const =0
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
const Nom & le_nom() const override
Renvoie le nom du champ.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
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)
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
const std::string & getString() const
Definition Nom.h:92
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
static int axi
Definition Objet_U.h:101
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
virtual Equation_base & equation_masse()
class Perte_Charge_Singuliere_VDF_Face
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl) const override
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl) const override
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
DoubleTab & ajouter_(const DoubleTab &, DoubleTab &) const override
void completer() override
Met a jour les references internes a l'objet Source_base.
void update_K(const Equation_base &eqn, double deb, DoubleVect &bilan)
double calculate_Q(const Equation_base &eqn, const IntVect &num_faces, const IntVect &sgn) const
virtual void lire_surfaces(Entree &, const Domaine &, const Domaine_dis_base &, IntVect &, IntVect &, int lire_derniere_accolade=1)
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
int direction_perte_charge() const
Renvoie la direction de perte de charge.
const Domaine & domaine() const
Renvoie le domaine 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 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 set_fichier(const Nom &)
DoubleVect & bilan()
Definition Source_base.h:88
void set_description(const Nom &nom)
Definition Source_base.h:83
virtual void completer()
Met a jour les references internes a l'objet Source_base.
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91