TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Fermeture_Thermo_base.h
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#ifndef Fermeture_Thermo_base_included
17#define Fermeture_Thermo_base_included
18
19#include <Objet_U.h>
20#include <Param.h>
21#include <Champ_Fonc_base.h>
22#include <Potentiel_Chimique_base.h>
23#include <Table.h>
24
25/*! @brief classe Fermeture_Thermo_base
26 *
27 * Classe de base des fermetures thermodynamiques, c'est-à-dire des modèles de
28 * potentiels chimiques choisis pour la forme de l'énergie libre de Gibbs.
29 *
30 * @sa Equation_base
31 */
33{
34
35 Declare_base_sans_constructeur(Fermeture_Thermo_base);
36
37public:
38
40
41 // Mobilité (dégénérée ou non)
42 DoubleTab mobilite_func_c_cst(const DoubleTab&) const;
43 DoubleTab mobilite_func_c_defaut(const DoubleTab&) const;
44 DoubleTab mobilite_func_c_general(const DoubleTab&) const;
45 DoubleTab mobilite_func_auto_diffusion(const DoubleTab&) const;
46
47 DoubleTab mobilite(const DoubleTab& d) const { return (this->*mobilite_func_c)(d); } // Renvoie le champ entier sur le domaine sous forme de DoubleTab
48 DoubleTab (Fermeture_Thermo_base::*mobilite_func_c)(const DoubleTab&) const;
49
50 // coefficient Kappa
51 inline DoubleVect kappa() const { return kappa_i_; }
52
53 // Potentiel chimique
54 inline Potentiel_Chimique_base& potentiel_chimique() { return mu_.valeur(); }
55 inline const Potentiel_Chimique_base& potentiel_chimique() const { return mu_.valeur(); }
56
57 // coefficient Beta
58 inline DoubleVect beta() const { return beta_; }
59
60 inline int nb_parametres_d_ordre() const { return nb_parametres_d_ordre_; } // On appelle ce paramètre nb_equations_ et non nb_phases, car il correspond à
62 inline double mult_mobilite() const { return mult_mobilite_; }
63
64 inline double molarVolume() const { return molarVolume_; }
65 inline double temperature() const { return temperature_; }
66
67protected :
68
70
71 DoubleVect mob_i_, kappa_i_, beta_;
72
74
76
79 double mult_mobilite_ = -123.;
80
81 double kappa_ref_ = -123., angle_kappa_ = -123.;
82 double diagonal_coeff_ = -123.;
83 double temperature_ = -123., molarVolume_ = -123.;
84
86
87};
88
89inline DoubleTab Fermeture_Thermo_base::mobilite_func_c_cst(const DoubleTab& c) const
90{
91 DoubleTab mobiliteMatrix_tab(c.dimension(0), nb_parametres_d_ordre_*nb_parametres_d_ordre_);
92 // Cerr << "[Closure] Mobility: Constant function is used." << finl;
93 // Cerr << "[Closure] Concentration field is sized " << c.dimension(0) << " x " << c.line_size() << finl;
94 for (int i = 0; i < c.dimension(0); i++)
95 for (int j = 0; j < nb_parametres_d_ordre_*nb_parametres_d_ordre_; j++)
96 mobiliteMatrix_tab(i, j) = mult_mobilite_ * mob_i_(j);
97 return mobiliteMatrix_tab;
98}
99
100inline DoubleTab Fermeture_Thermo_base::mobilite_func_c_defaut(const DoubleTab& c) const
101{
102 assert(c.line_size() == nb_parametres_d_ordre_);
103 DoubleTab mobiliteMatrix_tab(c.dimension(0), nb_parametres_d_ordre_*nb_parametres_d_ordre_);
104 // Cerr << "Mobility: Constant function is used." << finl;
105 for (int i = 0; i < c.dimension(0); i++)
106 for (int j = 0; j < nb_parametres_d_ordre_; j++)
107 for (int k = 0; k < nb_parametres_d_ordre_; k++)
108 mobiliteMatrix_tab(i, k+nb_parametres_d_ordre_*j) = std::max(mult_mobilite_ * mob_i_(k+nb_parametres_d_ordre_*j) * c(i, k) * (1.0 - c(i, k)), 0.);
109 return mobiliteMatrix_tab;
110}
111
112inline DoubleTab Fermeture_Thermo_base::mobilite_func_c_general(const DoubleTab& c) const
113{
114 assert(c.line_size() == 1);
115 DoubleTab mobiliteMatrix_tab(c.dimension(0), 1);
116 Cerr << "Mobility: General form is used." << finl;
117 for (int i = 0; i < c.dimension(0); i++)
118 mobiliteMatrix_tab(i, 0) = std::max(mult_mobilite_ * mob_i_(0) * mobilite_forme_expr_.val(c(i, 0), 0), 0.);
119 return mobiliteMatrix_tab;
120}
121
122inline DoubleTab Fermeture_Thermo_base::mobilite_func_auto_diffusion(const DoubleTab& c) const
123{
124 Cerr << "Mobility: Auto-diffusion is used." << finl;
125 DoubleTab temp_c(c.dimension(0), c.line_size() + 1);
126 DoubleTab temp_mobilite(c.dimension(0), nb_parametres_d_ordre_, nb_parametres_d_ordre_); //define temp to avoid resize here
127 DoubleTab mobiliteMat = temp_mobilite;
128 mobiliteMat = 0;
129 DoubleTab mobilite_ij(temp_mobilite);
130 DoubleTab somme_c(c.dimension(0));
131 somme_c = 0;
132 DoubleTab mobiliteMatrix_tab(c.dimension(0), nb_parametres_d_ordre_ * nb_parametres_d_ordre_);
133
134 // creation d'un tableau temp_c qui contiendra toutes les concentrations des n composants non pas les n-1 seulements (n-1 eqs).
135 //La derniere colonne correspondra a 1-somme sur (n-1) des concentrations
136
137 for (int l = 0; l < c.dimension(0); l++)
138 for (int k = 0; k < c.line_size(); k++)
139 {
140 temp_c(l, k) = c(l, k);
141 somme_c(l) += c(l, k);
142 temp_c(l, c.line_size()) = 1.0 - somme_c(l);
143 }
144
145 // calcul de la mobilite mobilite dans un doubleTab (n1,n2,n3)
146 for (int k = 0; k < nb_parametres_d_ordre_ + 1; k++)
147 {
148 for (int j = 0; j < nb_parametres_d_ordre_; j++)
149 for (int i = 0; i < nb_parametres_d_ordre_; i++)
150 for (int l = 0; l < c.dimension(0); l++)
151 {
152 if (j == k)
153 mobilite_ij(l, i, j) = 1 - temp_c(l, j);
154 else
155 mobilite_ij(l, i, j) = -temp_c(l, j);
156 if (i == k)
157 mobilite_ij(l, i, j) *= 1 - temp_c(l, i);
158 else
159 mobilite_ij(l, i, j) *= -temp_c(l, i);
160
161 mobilite_ij(l, i, j) *= temp_c(l, k) * coeff_auto_diffusion_(k);
162 }
163 mobiliteMat += mobilite_ij;
164 }
165
166 //retour vers un DoubleTab (n1,n2)
167 for (int l = 0; l < c.dimension(0); l++)
168 for (int j = 0; j < nb_parametres_d_ordre_; j++)
169 for (int i = 0; i < nb_parametres_d_ordre_; i++)
170 mobiliteMatrix_tab(l, i + nb_parametres_d_ordre_ * j) = mobiliteMat(l, i, j);
171
172 mobiliteMatrix_tab *= molarVolume_ * 8.314 * temperature_;
173
174 return mobiliteMatrix_tab;
175}
176
177#endif /* Fermeture_Thermo_base_included */
DoubleTab mobilite_func_auto_diffusion(const DoubleTab &) const
DoubleTab mobilite_func_c_defaut(const DoubleTab &) const
DoubleTab mobilite_func_c_cst(const DoubleTab &) const
Potentiel_Chimique_base & potentiel_chimique()
DoubleTab mobilite(const DoubleTab &d) const
const Potentiel_Chimique_base & potentiel_chimique() const
OWN_PTR(Potentiel_Chimique_base) mu_
DoubleTab(Fermeture_Thermo_base::* mobilite_func_c)(const DoubleTab &) const
DoubleTab mobilite_func_c_general(const DoubleTab &) const
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67
Definition Table.h:29