TrioCFD 1.9.9_beta
TrioCFD documentation
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 Reads the specifications of an imposed Delta P from an input stream.
23 *
24 * @param is an input stream
25 * @return the modified input stream
26 * @throws not a field
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 << "We expected the keyword" << acc_ouverte << " instead of " << 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 << "We expected the keyword dp or dp_regul instead of " << 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 //for the monitoring file: only on the master, because Source_base::imprimer() sums over all processes
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 &)
Reads the specifications of an imposed Delta P from an input stream.
Definition DP_Impose.cpp:51
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
Probleme_base & probleme()
Returns the problem associated with the equation.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
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
Returns the time scheme associated with the problem.
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
double temps_courant() const
Returns the current time.
double pas_de_temps() const
Returns the current time step (delta_t).