TrioCFD 1.9.9_beta
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 //output file
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 needs 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;//one 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 //values of the DP field
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; //to avoid summing twice in output
157 }
158}
159
161{
164 if (regul_) return;
165
166 bilan()(2) = calculate_Q(equation(), num_faces, sgn) * (Process::me() ? 0 : 1); //to avoid summing twice in output
167}
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & valeurs()=0
double temps() const
Returns the time of the field.
class DP_Impose_PolyMAC_CDO_Face
int sauvegarder(Sortie &os) const override
Saves an Objet_U to an output stream. Virtual method to override.
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
void completer() override
Updates internal references of the Source_base object.
int reprendre(Entree &is) override
Restores an Objet_U from an input stream. Virtual method to override.
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 &)
Reads the specifications of an imposed Delta P from an input stream.
Definition DP_Impose.cpp:51
class Domaine_Poly_base
virtual const DoubleVect & face_surfaces() const
Definition Domaine_VF.h:51
int nb_faces() const
Returns the total number of 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)
Indicates whether the special format was requested in active writing by xyz save.
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()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
friend class Entree
Definition Objet_U.h:71
static int dimension
Definition Objet_U.h:94
friend class Sortie
Definition Objet_U.h:70
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Multiphase thermohydraulics problem of type "3*N equations":
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
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
bool is_dilatable() const
const Domaine & domaine() const
Returns the domain associated with the problem.
static double mp_max(double)
Definition Process.cpp:379
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:245
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
Base class for output streams.
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()
Updates internal references of the Source_base object.
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91