TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
DP_Impose_PolyMAC_CDO_Face.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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_PolyMAC_CDO_Face.h>
18#include <Domaine_PolyMAC_CDO.h>
19#include <Champ_Don_base.h>
20#include <Equation_base.h>
21#include <Probleme_base.h>
22#include <Synonyme_info.h>
23#include <Pb_Multiphase.h>
24#include <Milieu_base.h>
25#include <Avanc.h>
26#include <cfloat>
27
28Implemente_instanciable(DP_Impose_PolyMAC_CDO_Face, "DP_Impose_Face_PolyMAC_CDO|DP_Impose_Face_PolyMAC_HFV", Perte_Charge_PolyMAC_CDO_Face);
29Add_synonym(DP_Impose_PolyMAC_CDO_Face, "DP_Impose_Face_PolyMAC_MPFA");
30
32
34{
37 if (!mp_max(sgn.size()))
38 {
39 Cerr << "DP_Impose_PolyMAC_CDO_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
64{
66 // eq_masse besoin de champ_conserve !
67 if (sub_type(Pb_Multiphase, mon_equation->probleme())) ref_cast(Pb_Multiphase, mon_equation->probleme()).equation_masse().init_champ_conserve();
68 bilan().resize(3 + !regul_);
69}
70
72{
73 int a_faire, special;
75 if (a_faire)
76 {
77 double temps = equation().inconnue().temps();
78 Nom ident_reg = Nom("fac_regul") + equation().probleme().le_nom() + identifiant_ + Nom(temps, "%e");
79 os << ident_reg << finl;
80 os << "constante" << finl;
81 os << fac_regul_;
82 os << flush;
83 Cerr << "Saving fac_regul at time : " << Nom(temps, "%e") << " with value " << fac_regul_ << finl;
84 }
85 return 8;//un double
86}
87
89{
90 Nom ident_reg = Nom("fac_regul") + equation().probleme().le_nom() + identifiant_ + Nom(equation().schema_temps().temps_courant(), equation().probleme().reprise_format_temps());
91 avancer_fichier(is, ident_reg);
92 is >> fac_regul_;
93 Cerr << "Resuming with the value fac_regul = " << fac_regul_ << finl;
94 return 1;
95}
96
98{
99 const Domaine& le_domaine = equation().probleme().domaine();
100 const Domaine_Poly_base& domaine_poly = ref_cast(Domaine_Poly_base,equation().domaine_dis());
101 int taille_bloc = domaine_poly.nb_elem();
102 num_faces.resize(taille_bloc);
103 lire_surfaces(s,le_domaine,domaine_poly,num_faces, sgn);
104 // int nfac_tot = mp_sum(num_faces.size());
105 int nfac_max = (int)mp_max(num_faces.size()); // not to count several (number of processes) times the same face
106
107 if(je_suis_maitre() && nfac_max == 0)
108 {
109 Cerr << "Error when defining the surface plane for the singular porosity :" << finl;
110 Cerr << "No mesh faces has been found for the surface plane." << finl;
111 Cerr << "Check the coordinate of the surface plane which should match mesh coordinates." << finl;
113 }
114
115 DoubleTrav S;
116 domaine_poly.creer_tableau_faces(S);
117 for (int i = 0; i < num_faces.size(); i++) S(num_faces(i)) = domaine_poly.face_surfaces(num_faces(i));
118 surf = mp_somme_vect(S);
119}
120
121void DP_Impose_PolyMAC_CDO_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
122{
123 const Domaine_Poly_base& domaine_poly = ref_cast(Domaine_Poly_base,equation().domaine_dis());
124 const DoubleVect& pf = equation().milieu().porosite_face(), &fs = domaine_poly.face_surfaces();
125 const DoubleTab& vit = equation().inconnue().valeurs();
126 const std::string& nom_inco = equation().inconnue().le_nom().getString();
127 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
128
129 double rho = equation().milieu().masse_volumique().valeurs()(0, 0), dp_regul = regul_ ? f_DP_.eval() * fac_regul_ : 0,
130 fac_rho = (equation().probleme().is_dilatable() || sub_type(Pb_Multiphase, equation().probleme())) ? 1.0 : 1.0 / rho;
131
132 if (regul_)
133 {
134 for (int i = 0, f; i < num_faces.size(); i++)
135 if ((f = num_faces(i)) < domaine_poly.nb_faces())
136 secmem(f) += fs(f) * pf(f) * sgn(i) * dp_regul * fac_rho;
137 }
138 else
139 {
140 //valeurs du champ de DP
141 DoubleTrav xvf(num_faces.size(), dimension), DP(num_faces.size(), 3);
142 for (int i = 0; i < num_faces.size(); i++)
143 for (int j = 0; j < dimension; j++) xvf(i, j) = domaine_poly.xv()(num_faces(i), j);
144 DP_->valeur_aux(xvf, DP);
145 for (int i = 0, f; i < num_faces.size(); i++)
146 if ((f = num_faces(i)) < domaine_poly.nb_faces())
147 {
148 secmem(f) += fs(f) * pf(f) * sgn(i) * (DP(i, 0) + DP(i, 1) * (surf * sgn(i) * vit(f) - DP(i, 2))) * fac_rho;
149 if (mat) (*mat)(f, f) -= fs(f) * pf(f) * DP(i, 1) * surf * fac_rho;
150 }
151
152 bilan()(0) = num_faces.size() ? DP(0, 0) : -DBL_MAX;
153 bilan()(1) = num_faces.size() ? DP(0, 1) / rho : -DBL_MAX;
154 bilan()(3) = num_faces.size() ? DP(0, 2) * rho : -DBL_MAX;
155 Process::mp_max_for_each(bilan()(0), bilan()(1), bilan()(3));
156 if (Process::me()) bilan() = 0; //pour eviter un sommage en sortie
157 }
158}
159
161{
164 if (regul_) return;
165
166 bilan()(2) = calculate_Q(equation(), num_faces, sgn) * (Process::me() ? 0 : 1); //pour eviter le sommage en sortie
167}
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_PolyMAC_CDO_Face
int sauvegarder(Sortie &os) const override
Sauvegarde d'un Objet_U sur un flot de sortie Methode a surcharger.
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
void completer() override
Met a jour les references internes a l'objet Source_base.
int reprendre(Entree &is) override
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
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_Poly_base
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 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.
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
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
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)
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 resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91