TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
DP_Impose_VEF_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 <EcritureLectureSpecial.h>
17#include <DP_Impose_VEF_Face.h>
18#include <Champ_Don_base.h>
19#include <Equation_base.h>
20#include <Probleme_base.h>
21#include <Synonyme_info.h>
22#include <Matrix_tools.h>
23#include <Array_tools.h>
24#include <Milieu_base.h>
25#include <Domaine_VEF.h>
26#include <Avanc.h>
27#include <cfloat>
28
29Implemente_instanciable(DP_Impose_VEF_Face, "DP_Impose_VEF_P1NC", Perte_Charge_VEF_Face);
30
31Sortie& DP_Impose_VEF_Face::printOn(Sortie& s) const { return s << que_suis_je(); }
32
34{
37 if (!mp_max(sgn.size()))
38 {
39 Cerr << "DP_Impose_VEF_Face: champ d'orientation non renseigne!" << finl;
41 }
42 //fichier de sortie
43 set_fichier(Nom("DP_") + identifiant_);
44 set_description(Nom("DP impose sur la surface ") + identifiant_);
45 Noms col_names;
46 if (regul_)
47 {
48 col_names.add("DP");
49 col_names.add("Flow_rate");
50 col_names.add("Target_Flow_rate");
51 }
52 else
53 {
54 col_names.add("DP");
55 col_names.add("dDP/dQ");
56 col_names.add("Q");
57 col_names.add("Q0");
58 }
59 set_col_names(col_names);
60 return s;
61}
62
68
70{
71 int a_faire, special;
73 if (a_faire)
74 {
75 double temps = equation().inconnue().temps();
76 Nom ident_reg = Nom("fac_regul") + equation().probleme().le_nom() + identifiant_ + Nom(temps, "%e");
77 os << ident_reg << finl;
78 os << "constante" << finl;
79 os << fac_regul_;
80 os << flush;
81 Cerr << "Saving fac_regul at time : " << Nom(temps, "%e") << " with value " << fac_regul_ << finl;
82 }
83 return 8;//un double
84}
85
87{
88 Nom ident_reg = Nom("fac_regul") + equation().probleme().le_nom() + identifiant_ + Nom(equation().schema_temps().temps_courant(), equation().probleme().reprise_format_temps());
89 avancer_fichier(is, ident_reg);
90 is >> fac_regul_;
91 Cerr << "Resuming with the value fac_regul = " << fac_regul_ << finl;
92 return 1;
93}
94
96{
97 const Domaine& le_domaine = equation().probleme().domaine();
98 const Domaine_VEF& dom = ref_cast(Domaine_VEF, equation().domaine_dis());
99 int taille_bloc = dom.nb_elem();
100 num_faces.resize(taille_bloc);
101 lire_surfaces(s,le_domaine,dom,num_faces, sgn);
102 // int nfac_tot = mp_sum(num_faces.size());
103 int nfac_max = (int)mp_max(num_faces.size()); // not to count several (number of processes) times the same face
104
105 if(je_suis_maitre() && nfac_max == 0)
106 {
107 Cerr << "Error when defining the surface plane for the singular porosity :" << finl;
108 Cerr << "No mesh faces has been found for the surface plane." << finl;
109 Cerr << "Check the coordinate of the surface plane which should match mesh coordinates." << finl;
111 }
112
113 DoubleTrav S;
114 dom.creer_tableau_faces(S);
115 for (int i = 0; i < num_faces.size(); i++) S(num_faces(i)) = dom.face_surfaces(num_faces(i));
116 surf = mp_somme_vect(S);
117}
118
120{
123 if (regul_) return;
124
125 bilan()(2) = calculate_Q(equation(), num_faces, sgn) * (Process::me() ? 0 : 1); //pour eviter le sommage en sortie
126}
127
128void DP_Impose_VEF_Face::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
129{
130 const Domaine_VEF& dom = ref_cast(Domaine_VEF, equation().domaine_dis());
131
132 const std::string& nom_inco = equation().inconnue().le_nom().getString();
133 Matrice_Morse& mat = *matrices.at(nom_inco), mat2;
134
135 Stencil sten(0, 2);
136
137 int i, f, d, db, D = dimension, n, N = equation().inconnue().valeurs().line_size() / D, nf_tot = dom.nb_faces_tot();
138 for (i = 0; i < num_faces.size(); i++)
139 if ((f = num_faces(i)) < dom.nb_faces())
140 for (d = 0; d < D; d++)
141 for (db = 0; db < D; db++)
142 for (n = 0; n < N; n++)
143 sten.append_line(N * (D * f + d) + n, N * (D * f + db) + n);
144
145 tableau_trier_retirer_doublons(sten);
146 Matrix_tools::allocate_morse_matrix(N * D * nf_tot, N * D * nf_tot, sten, mat2);
147 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
148}
149
150void DP_Impose_VEF_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
151{
152 const Domaine_VEF& dom = ref_cast(Domaine_VEF, equation().domaine_dis());
153 const DoubleVect& pf = equation().milieu().porosite_face(), &fs = dom.face_surfaces();
154 const DoubleTab& vit = equation().inconnue().valeurs(), &nf = dom.face_normales();
155 const std::string& nom_inco = equation().inconnue().le_nom().getString();
156 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
157 const int D = dimension, N = vit.line_size() / D;
158
159 double rho = equation().milieu().masse_volumique().valeurs()(0, 0), dp_regul = regul_ ? f_DP_.eval() * fac_regul_ : 0,
160 fac_rho = equation().probleme().is_dilatable() ? 1.0 : 1.0 / rho;
161
162 if (regul_)
163 {
164 for (int i = 0, f; i < num_faces.size(); i++)
165 if ((f = num_faces(i)) < dom.nb_faces())
166 for (int d = 0; d < D; d++)
167 secmem(f, d) += nf(f, d) * pf(f) * sgn(i) * dp_regul * fac_rho;
168 }
169 else
170 {
171 DoubleTrav xvf(num_faces.size(), dimension), DP(num_faces.size(), 3), vn(N);
172 for (int i = 0; i < num_faces.size(); i++)
173 for (int j = 0; j < dimension; j++)
174 xvf(i, j) = dom.xv()(num_faces(i), j);
175 DP_->valeur_aux(xvf, DP);
176
177 for (int i = 0, f; i < num_faces.size(); i++)
178 if ((f = num_faces(i)) < dom.nb_faces())
179 {
180 vn = 0;
181 for (int d = 0; d < D; d++)
182 for (int n = 0; n < N; n++)
183 vn(n) += nf(f, d) * vit(f, N * d + n) / fs(f);
184
185 for (int d = 0; d < D; d++)
186 for (int n = 0; n < N; n++)
187 secmem(f, N * d + n) += nf(f, d) * pf(f) * sgn(i) * (DP(i, 0) + DP(i, 1) * (surf * sgn(i) * vn(n) - DP(i, 2))) * fac_rho;
188 if (mat)
189 for (int d = 0; d < D; d++)
190 for (int db = 0; db < D; db++)
191 for (int n = 0; n < N; n++)
192 (*mat)(N * (D * f + d) + n, N * (D * f + db) + n) -= nf(f, d) * nf(f, db) / fs(f) * pf(f) * DP(i, 1) * surf * fac_rho;
193 }
194
195 bilan()(0) = num_faces.size() ? DP(0, 0) : -DBL_MAX;
196 bilan()(1) = num_faces.size() ? DP(0, 1) / rho : -DBL_MAX;
197 bilan()(3) = num_faces.size() ? DP(0, 2) * rho : -DBL_MAX;
198 Process::mp_max_for_each(bilan()(0), bilan()(1), bilan()(3));
199 if (Process::me())
200 bilan() = 0; //pour eviter un sommage en sortie
201 }
202}
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
virtual DoubleTab & valeurs()=0
double temps() const
Renvoie le temps du champ.
class DP_Impose_VEF_Face
int reprendre(Entree &is) override
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void completer() override
Met a jour les references internes a l'objet Source_base.
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
int sauvegarder(Sortie &os) const override
Sauvegarde d'un Objet_U sur un flot de sortie Methode a surcharger.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
void remplir_num_faces(Entree &)
double fac_regul_
Definition DP_Impose.h:40
void update_dp_regul(const Equation_base &eqn, double deb, DoubleVect &bilan)
Definition DP_Impose.cpp:93
Parser_U f_DP_
Definition DP_Impose.h:39
void mettre_a_jour(double temps)
Definition DP_Impose.cpp:87
Entree & lire_donnees(Entree &)
Lit les specifications d'un Delta P impose a partir d'un flot d'entree.
Definition DP_Impose.cpp:51
class Domaine_VEF
Definition Domaine_VEF.h:54
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
void creer_tableau_faces(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
static int is_ecriture_special(int &special, int &a_faire)
indique si le format special a ete demande en lecture active par sauvegarde xyz .
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
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)
virtual const Champ_base & masse_volumique() const
Renvoie la masse volumique du milieu.
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
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
friend class Entree
Definition Objet_U.h:76
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
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)
class Perte_Charge_VEF_Face
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Probleme_U.h:109
bool is_dilatable() const
const Domaine & domaine() const
Renvoie le domaine associe au probleme.
static double mp_max(double)
Definition Process.cpp:376
static void mp_max_for_each(T &arg1, T &arg2)
C++14 compatible mp_max_for_each: combine multiple mp_max calls into one collective operation.
Definition Process.cpp:244
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
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
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_col_names(const Noms &col_names)
Definition Source_base.h:84
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