TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Milieu_Elasticite.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 <Milieu_Elasticite.h>
17#include <Discretisation_base.h>
18#include <Schema_Temps_base.h>
19#include <Probleme_base.h>
20#include <Domaine_dis_base.h>
21#include <Champ_Uniforme.h>
22#include <Process.h>
23#include <Param.h>
24
25Implemente_instanciable(Milieu_Elasticite,"Milieu_Elasticite",Milieu_base);
26// XD Milieu_Elasticite milieu_base Milieu_Elasticite INHERITS_BRACE Milieu_Elasticite.
27// XD attr rho field_base rho OPT Density (kg.m-3).
28// XD attr E field_base E OPT Field E
29// XD attr nu field_base nu OPT Field nu.
30// XD attr alpha field_base alpha OPT Coeff dilatation.
31
33
35{
37 ensure_rho_field();
39 return is;
40}
41
43{
45 param.ajouter("E", &ch_E_, Param::REQUIRED);
46 param.ajouter("nu", &ch_nu_, Param::REQUIRED);
47 param.ajouter("alpha", &ch_coeff_dilatation_th_);
48}
49
51{
53
54 if (!ch_lambda_lame_)
55 {
56 ch_lambda_lame_ = ch_E_;
57 ch_lambda_lame_->nommer("lambda_lame");
58 }
59 if (!ch_mu_)
60 {
61 ch_mu_ = ch_E_;
62 ch_mu_->nommer("mu_lame");
63 }
64 if (!ch_K_)
65 {
66 ch_K_ = ch_E_;
67 ch_K_->nommer("bulk_modulus");
68 }
69}
70
72{
74 if (!zdb_) zdb_ = pb.domaine_dis();
75
76 const Domaine_dis_base& domaine_dis = pb.domaine_dis();
77 const int nc = pb.equation(0).inconnue().nb_valeurs_temporelles();
78
79 dis.nommer_completer_champ_physique(domaine_dis, "module_de_Young", "Pa", ch_E_.valeur(), pb);
80 dis.nommer_completer_champ_physique(domaine_dis, "coefficient_de_Poisson", "", ch_nu_.valeur(), pb);
81 dis.nommer_completer_champ_physique(domaine_dis, "lambda_lame", "Pa", ch_lambda_lame_.valeur(), pb);
82 dis.nommer_completer_champ_physique(domaine_dis, "mu_lame", "Pa", ch_mu_.valeur(), pb);
83 dis.nommer_completer_champ_physique(domaine_dis, "module_volumique", "Pa", ch_K_.valeur(), pb);
84 dis.discretiser_champ("champ_elem", domaine_dis, "masse_volumique_lagrangienne", "kg/m^3", 1, nc, pb.schema_temps().temps_courant(), ch_rho_lag_);
85 if (ch_coeff_dilatation_th_)
86 dis.nommer_completer_champ_physique(domaine_dis, "coeff_dilatation_thermique", "K-1", ch_coeff_dilatation_th_.valeur(), pb);
87
88 ch_rho_lag_->associer_eqn(pb.equation(0));
89
90 champs_compris_.ajoute_champ(ch_E_.valeur());
91 champs_compris_.ajoute_champ(ch_nu_.valeur());
92 champs_compris_.ajoute_champ(ch_lambda_lame_.valeur());
93 champs_compris_.ajoute_champ(ch_mu_.valeur());
94 champs_compris_.ajoute_champ(ch_K_.valeur());
95 champs_compris_.ajoute_champ(ch_rho_lag_.valeur());
96 if (ch_coeff_dilatation_th_)
97 champs_compris_.ajoute_champ(ch_coeff_dilatation_th_.valeur());
98
99 eq_ = pb.equation(0);
100}
101
102int Milieu_Elasticite::initialiser(const double temps)
103{
104 const int ok = Milieu_base::initialiser(temps);
105
106 ch_E_->initialiser(temps);
107 ch_nu_->initialiser(temps);
108 ch_lambda_lame_->initialiser(temps);
109 ch_mu_->initialiser(temps);
110 ch_K_->initialiser(temps);
111 if (ch_coeff_dilatation_th_) ch_coeff_dilatation_th_->initialiser(temps);
112 ch_rho_lag_->passe() = ch_rho_->valeurs()(0, 0);
113 ch_rho_lag_->valeurs() = ch_rho_->valeurs()(0, 0);
114 ch_rho_lag_->mettre_a_jour(temps);
115 update_fields(temps, false);
116
117 return ok;
118}
119
121{
122 if (!eq_) throw;
123 const Schema_Temps_base& sch = eq_->schema_temps(); //on recupere le schema en temps par la 1ere equation
124
125 for (int i = 1; i <= sch.nb_valeurs_futures(); i++)
126 {
127 ch_rho_lag_->changer_temps_futur(sch.temps_futur(i), i);
128 ch_rho_lag_->futur(i) = ch_rho_lag_->valeurs();
129 }
130 return true;
131}
132
134{
135 if (!ch_E_ || !ch_nu_ || !ch_lambda_lame_ || !ch_mu_ || !ch_K_)
136 {
137 Cerr << que_suis_je() << " cannot update without E, nu, lambda, mu or K fields." << finl;
139 }
140
142
143 ch_E_->mettre_a_jour(temps);
144 ch_nu_->mettre_a_jour(temps);
145 if (ch_coeff_dilatation_th_) ch_coeff_dilatation_th_->mettre_a_jour(temps);
146
147 ch_lambda_lame_->changer_temps(temps);
148 ch_mu_->changer_temps(temps);
149 ch_K_->changer_temps(temps);
150 ch_rho_lag_->mettre_a_jour(temps);
151
152 update_fields(temps, false);
153}
154
156{
158
159 if (ch_E_->valeurs()(0,0) <= 0.)
160 {
161 message += "The Young modulus must be strictly positive.\n";
162 err = 1;
163 }
164
165 const double nu_val = ch_nu_->valeurs()(0,0);
166 if (nu_val <= -1.0 || nu_val >= 0.5)
167 {
168 message += "The Poisson ratio must belong to (-1, 0.5).\n";
169 err = 1;
170 }
171
172 if (ch_rho_->valeurs()(0,0) <= 0.)
173 {
174 Cerr << que_suis_je() << " expects rho > 0 but received " << ch_rho_->valeurs()(0,0) << finl;
176 }
177}
178
179void Milieu_Elasticite::ensure_rho_field()
180{
181 if (!ch_rho_)
182 {
183 Cerr << que_suis_je() << " requires a rho field to be specified." << finl;
185 }
186 if (!sub_type(Champ_Uniforme, ch_rho_.valeur()))
187 {
188 Cerr << que_suis_je() << " currently expects rho to be provided as Champ_Uniforme." << finl;
190 }
191
192 if (ch_rho_->valeurs().size_totale() == 0)
193 {
194 Cerr << que_suis_je() << " received an empty rho field." << finl;
196 }
197
198 if (ch_rho_->nb_comp() != 1)
199 {
200 Cerr << que_suis_je() << " expects rho to be a scalar field." << finl;
202 }
203}
204
205void Milieu_Elasticite::update_fields(double temps, bool update_rho)
206{
207 const double E_val = ch_E_->valeurs()(0, 0);
208 const double nu_val = ch_nu_->valeurs()(0, 0);
209 const double denom_mu = 2. * (1. + nu_val);
210 const double denom_lambda = (1. + nu_val) * (1. - 2. * nu_val);
211 const double denom_K = 3. * (1. - 2. * nu_val);
212
213 if (denom_mu == 0. || denom_lambda == 0. || denom_K == 0.)
214 {
215 Cerr << que_suis_je() << " cannot compute elastic constants with nu=" << nu_val << finl;
217 }
218
219 ch_mu_->valeurs() = E_val / denom_mu;
220 ch_lambda_lame_->valeurs() = E_val * nu_val / denom_lambda;
221 ch_K_->valeurs() = E_val / denom_K;
222
223 if (update_rho)
224 {
225 Cerr << "Updating rho_lagrangien field based on current volume scaling at time " << temps << finl;
226 ch_rho_lag_->valeurs() = ch_rho_lag_->passe();
227 zdb_->domaine().apply_old_to_new_volume_scaling(ch_rho_lag_->valeurs(), zdb_.valeur());
228 const Schema_Temps_base& sch = eq_->schema_temps(); //on recupere le schema en temps par la 1ere equation
229 for (int i = 1; i <= sch.nb_valeurs_futures(); i++)
230 ch_rho_lag_->futur(i) = ch_rho_lag_->valeurs();
231 }
232}
virtual int nb_valeurs_temporelles() const
Renvoie le nombre de valeurs temporelles actuellement conservees.
classe Discretisation_base Cette classe represente un schema de discretisation en espace,...
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
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
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
virtual const Champ_Inc_base & inconnue() const =0
Isotropic small-strain linear elastic medium.
void discretiser(const Probleme_base &pb, const Discretisation_base &dis) override
void set_param(Param &param) const override
int initialiser(const double temps) override
void mettre_a_jour(double temps) override
void verifier_coherence_champs(int &err, Nom &message) override
void creer_champs_non_lus() override
void update_fields(double temps, bool)
bool initTimeStep(double dt) override
classe Milieu_base Cette classe est la base de la hierarchie des milieux (physiques)
Definition Milieu_base.h:50
virtual int initialiser(const double temps)
virtual void creer_champs_non_lus()
virtual void mettre_a_jour(double temps)
virtual void discretiser(const Probleme_base &pb, const Discretisation_base &dis)
virtual void verifier_coherence_champs(int &err, Nom &message)
Champs_compris champs_compris_
virtual void set_param(Param &param) const override
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
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
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
virtual const Equation_base & equation(int) const =0
const Domaine_dis_base & domaine_dis() const
Renvoie le domaine discretise associe au probleme.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
class Schema_Temps_base
double temps_courant() const
Renvoie le temps courant.
virtual double temps_futur(int i) const =0
virtual int nb_valeurs_futures() const =0
Classe de base des flux de sortie.
Definition Sortie.h:52