TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Terme_Puissance_Thermique_Echange_Impose_Elem_base.cpp
1/****************************************************************************
2 * Copyright (c) 2022, 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 <Terme_Puissance_Thermique_Echange_Impose_Elem_base.h>
17#include <Discretisation_base.h>
18#include <Schema_Temps_base.h>
19#include <Equation_base.h>
20#include <Probleme_base.h>
21#include <Champ_Don_base.h>
22#include <Domaine_VF.h>
23#include <Param.h>
24
25Implemente_base(Terme_Puissance_Thermique_Echange_Impose_Elem_base, "Terme_Puissance_Thermique_Echange_Impose_Elem_base", Source_base);
26
27// XD terme_puissance_thermique_echange_impose source_base terme_puissance_thermique_echange_impose BRACE Source term to
28// XD_CONT impose thermal power according to formula : P = himp * (T - Text). Where T is the Trust temperature, Text is
29// XD_CONT the outside temperature with which energy is exchanged via an exchange coefficient himp
30// XD attr himp field_base himp REQ the exchange coefficient
31// XD attr Text field_base Text REQ the outside temperature
32// XD attr PID_controler_on_targer_power bloc_lecture PID_controler_on_targer_power OPT PID_controler_on_targer_power
33// XD_CONT bloc with parameters target_power (required), Kp, Ki and Kd (at least one of them should be provided)
34
36
38{
39 Param param(que_suis_je());
40 param.ajouter("himp", &himp_, Param::REQUIRED);
41 param.ajouter("Text", &Text_, Param::REQUIRED);
42 param.ajouter_non_std("PID_controler_on_targer_power", (this));
43 param.lire_avec_accolades_depuis(s);
44 set_fichier("Terme_Puissance_Thermique_Echange_Impose");
45 set_description("Power (W)");
46 Noms col_names;
47 col_names.add("Power");
48 col_names.add("DT_regul");
49 set_col_names(col_names);
50 return s;
51}
52
54{
55 if (mot == "PID_controler_on_targer_power")
56 {
57 regul_ = 1;
58 Nom pow_str, Kp_str = "0", Ki_str = "0", Kd_str = "0";
59 Param param("PID_controler_on_targer_power");
60 param.ajouter("target_power", &pow_str, Param::REQUIRED);
61 param.ajouter("Kp", &Kp_str);
62 param.ajouter("Ki", &Ki_str);
63 param.ajouter("Kd", &Kd_str);
64 param.lire_avec_accolades(is);
65 // check that at least one coefficient is read
66 if (Kp_str == "0" && Ki_str == "0" && Kd_str == "0")
67 {
68 Cerr << "PID controler : you should provide at least one coefficient among Kp, Ki and Kd!" << finl;
70 }
71 pow_cible_.setNbVar(1), Kp_.setNbVar(1), Ki_.setNbVar(1), Kd_.setNbVar(1);
72 pow_cible_.setString(pow_str), Kp_.setString(Kp_str), Ki_.setString(Ki_str), Kd_.setString(Kd_str);
73 pow_cible_.addVar("t"), Kp_.addVar("t"), Ki_.addVar("t"), Kd_.addVar("t");
74 pow_cible_.parseString(), Kp_.parseString(), Ki_.parseString(), Kd_.parseString();
75 return 1;
76 }
77 return 1;
78}
79
81{
82 const Domaine_VF& domaine = le_dom.valeur();
83 const DoubleVect& volumes = domaine.volumes();
84 const DoubleTab& himp = himp_->valeurs();
85 const DoubleTab& Text = Text_->valeurs();
86 const DoubleTab& T = equation().inconnue().valeurs();
87 int nb_elem = le_dom->nb_elem(), c_h = himp.dimension(0) == 1, c_T = Text.dimension(0) == 1, n, N = T.line_size();
88
89 bilan().resize(N + 1), bilan() = 0;
90
91 for (int e = 0; e < nb_elem; e++)
92 for (n = 0; n < N; n++)
93 bilan()(n) += himp(!c_h * e, n) * volumes(e) * (DT_regul_ + Text(!c_T * e, n) - T(e, n));
94
95 if (regul_) pid_process();
96 //pour le fichier de suivi : seulement sur le maitre, car Source_base::imprimer() fait une somme sur les procs
97 if (!Process::me()) bilan()(N) = DT_regul_;
98
99 himp_->mettre_a_jour(temps);
100 Text_->mettre_a_jour(temps);
101}
102
104{
105 const double ptot = mp_somme_vect(bilan()),t = equation().probleme().schema_temps().temps_courant(), dt = equation().probleme().schema_temps().pas_de_temps();
106 pow_cible_.setVar(0, t), Ki_.setVar(0, t);
107 const double pow_cible = pow_cible_.eval(), Kp = Kp_.eval(), Ki = Ki_.eval(), Kd = Kd_.eval(), error = (ptot - pow_cible) / pow_cible;
108 if (dt < equation().probleme().schema_temps().pas_temps_min())
109 {
110 p_error = error;
111 return; // dt vaut 0 a l'initialisation
112 }
113 DT_regul_ += Kp * error + dt * Ki * error + Kd * (error - p_error) / dt;
114 p_error = error;
115}
116
118{
119 le_dom = ref_cast(Domaine_VF, domaine_dis);
120 le_dom_Cl = ref_cast(Domaine_Cl_dis_base, domaine_Cl_dis);
121}
122
123void Terme_Puissance_Thermique_Echange_Impose_Elem_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
124{
125 const Domaine_VF& domaine = le_dom.valeur();
126 const DoubleVect& volumes = domaine.volumes();
127 const DoubleTab& himp = himp_->valeurs();
128 const DoubleTab& Text = Text_->valeurs();
129 const DoubleTab& T = equation().inconnue().valeurs();
130 int nb_elem = le_dom->nb_elem(), c_h = himp.dimension(0) == 1, c_T = Text.dimension(0) == 1, n, N = T.line_size();
131 const std::string& nom_inco = equation().inconnue().le_nom().getString();
132 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
133
134 for (int e = 0; e < nb_elem; e++)
135 for (n = 0; n < N; n++)
136 {
137 secmem(e, n) -= volumes(e) * himp(!c_h * e, n) * (T(e, n) - DT_regul_ - Text(!c_T * e, n));
138 if (mat)
139 (*mat)(N * e + n, N * e + n) += volumes(e) * himp(!c_h * e, n);
140 }
141}
142
144{
145 Nom nom_Himp = himp_->le_nom() != "??" ? himp_->le_nom() : "Himp";
146 equation().discretisation().nommer_completer_champ_physique(equation().domaine_dis(), nom_Himp, "", himp_.valeur(), equation().probleme());
147 Nom nom_Text = Text_->le_nom() != "??" ? Text_->le_nom() : "Text";
148 equation().discretisation().nommer_completer_champ_physique(equation().domaine_dis(), nom_Text, "", Text_.valeur(), equation().probleme());
149 himp_->initialiser(temps);
150 Text_->initialiser(temps);
151 return Source_base::initialiser(temps);
152}
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
void nommer_completer_champ_physique(const Domaine_dis_base &domaine_vdf, const Nom &nom_champ, const Nom &unite, Champ_base &champ, const Probleme_base &pbi) const
classe Domaine_Cl_dis_base Les objets Domaine_Cl_dis_base representent les conditions aux limites
class Domaine_VF
Definition Domaine_VF.h:44
double volumes(int i) const
Definition Domaine_VF.h:113
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Discretisation_base & discretisation() const
Renvoie la discretisation associee a l'equation.
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.
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
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
const std::string & getString() const
Definition Nom.h:92
const Nom & le_nom() const override
Renvoie *this;.
Definition Nom.cpp:563
friend class Entree
Definition Objet_U.h:76
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
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.
Classe de base des flux de sortie.
Definition Sortie.h:52
classe Source_base Un objet Source_base est un terme apparaissant au second membre d'une
Definition Source_base.h:42
void set_fichier(const Nom &)
DoubleVect & bilan()
Definition Source_base.h:88
virtual int initialiser(double temps)
Contrairement aux methodes mettre_a_jour, les methodes initialiser des sources ne peuvent pas dependr...
void set_col_names(const Noms &col_names)
Definition Source_base.h:84
void set_description(const Nom &nom)
Definition Source_base.h:83
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
int lire_motcle_non_standard(const Motcle &mot, Entree &is) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
int initialiser(double temps) override
Contrairement aux methodes mettre_a_jour, les methodes initialiser des sources ne peuvent pas dependr...
void mettre_a_jour(double) override
DOES NOTHING - to override in derived classes.
void associer_domaines(const Domaine_dis_base &, const Domaine_Cl_dis_base &) override