TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
DP_Impose.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 <Schema_Temps_base.h>
17#include <Probleme_base.h>
18#include <Equation_base.h>
19#include <DP_Impose.h>
20#include <Param.h>
21
22/*! @brief Lit les specifications d'un Delta P impose a partir d'un flot d'entree.
23 *
24 * @param (Entree& is) un flot d'entree
25 * @return (Entree&) le flot d'entree modifie
26 * @throws pas un champ
27 */
28
29// XD type_perte_charge_deriv objet_lecture type_perte_charge_deriv INHERITS_BRACE not_set
30
31// XD type_perte_charge_dp type_perte_charge_deriv dp NO_BRACE DP field should have 3 components defining dp, dDP/dQ, Q0
32// XD attr dp_field field_base dp_field REQ the parameters of the previous formula (DP = dp + dDP/dQ * (Q - Q0)):
33// XD_CONT uniform_field 3 dp dDP/dQ Q0 where Q0 is a mass flow rate (kg/s).
34
35// XD type_perte_charge_dp_regul type_perte_charge_deriv dp_regul BRACE Keyword used to regulate the DP value in order
36// XD_CONT to match a target flow rate. Syntax : dp_regul { DP0 d deb d eps e }
37// XD attr DP0 chaine DP0 REQ Reference pressure drop value (possibly time‑dependent)
38// XD attr deb chaine deb REQ target flow rate in kg/s
39// XD attr alpha chaine alpha REQ alpha string
40
41
42// XD DP_Impose source_base DP_Impose NO_BRACE Source term to impose a pressure difference according to the formula : DP
43// XD_CONT = dp + dDP/dQ * (Q - Q0)
44// XD attr aco chaine(into=["{"]) aco REQ Opening curly bracket.
45// XD attr dp_type type_perte_charge_deriv dp_type REQ mass flow rate (kg/s).
46// XD attr surface chaine(into=["surface"]) surface REQ not_set
47// XD attr bloc_surface bloc_lecture bloc_surface REQ Three syntaxes are possible for the surface definition block: NL2
48// XD_CONT For VDF and VEF: { X|Y|Z = location subzone_name } NL2 Only for VEF: { Surface surface_name }. NL2 For
49// XD_CONT PolyMAC_CDO { Surface surface_name Orientation champ_uniforme }.
50// XD attr acof chaine(into=["}"]) acof REQ Closing curly bracket.
52{
53 Motcle acc_ouverte("{");
54 Motcle motlu;
55 is >> motlu;
56 if (motlu != acc_ouverte)
57 {
58 Cerr << "On attendait le mot cle" << acc_ouverte << " a la place de " << motlu << finl;
60 }
61 is >> motlu;
62 regul_ = 0;
63 if (motlu == "dp")
64 is >> DP_;
65 else if (motlu == "dp_regul")
66 {
67 regul_ = 1;
68 Nom alpha_str, deb_str, dp_str;
69 Param param("dp_regul");
70 param.ajouter("DP0", &dp_str, Param::REQUIRED);
71 param.ajouter("deb", &deb_str, Param::REQUIRED);
72 param.ajouter("alpha", &alpha_str, Param::REQUIRED);
73 param.lire_avec_accolades(is);
74 f_DP_.setNbVar(1), deb_cible_.setNbVar(1), alpha_.setNbVar(1);
75 f_DP_.setString(dp_str), deb_cible_.setString(deb_str), alpha_.setString(alpha_str);
76 f_DP_.addVar("t"), deb_cible_.addVar("t"), alpha_.addVar("t");
77 f_DP_.parseString(), deb_cible_.parseString(), alpha_.parseString();
78 }
79 else
80 {
81 Cerr << "On attendait le mot cle dp ou dp_regul a la place de " << motlu << finl;
83 }
84 return is;
85}
86
87void DP_Impose::mettre_a_jour(double temps)
88{
89 if (regul_) return;
90 DP_->mettre_a_jour(temps);
91}
92
93void DP_Impose::update_dp_regul(const Equation_base& eqn, double deb, DoubleVect& bilan)
94{
95 if (!regul_) return;
96 double t = eqn.probleme().schema_temps().temps_courant(), dt = eqn.probleme().schema_temps().pas_de_temps();
97 f_DP_.setVar(0, t), deb_cible_.setVar(0, t), alpha_.setVar(0, t);
98 double deb_cible = deb_cible_.eval();
99 if (std::abs(deb_cible) > 1e-10)
100 {
101 const double eps = alpha_.eval(), error = (deb - deb_cible) / deb_cible;
102 fac_regul_ -= dt * eps * error;
103 }
104
105 //pour le fichier de suivi : seulement sur le maitre, car Source_base::imprimer() fait une somme sur les procs
106 if (!Process::me()) bilan(0) = f_DP_.eval() * fac_regul_, bilan(1) = deb, bilan(2) = deb_cible;
107}
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 defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
int lire_avec_accolades(Entree &is)
Alias of lire_avec_accolades_depuis.
Definition Param.h:577
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
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
double temps_courant() const
Renvoie le temps courant.
double pas_de_temps() const
Renvoie le pas de temps (delta_t) courant.