TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Diff_VDF_Elem_base.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 <Op_Diff_VDF_Elem_base.h>
17#include <Echange_contact_VDF.h>
18#include <Champ_P0_VDF.h>
19#include <Matrix_tools.h>
20#include <Array_tools.h>
21#include <Perf_counters.h>
22
23Implemente_base_sans_constructeur(Op_Diff_VDF_Elem_base,"Op_Diff_VDF_Elem_base",Op_Diff_VDF_base);
24
25Sortie& Op_Diff_VDF_Elem_base::printOn(Sortie& s ) const { return s << que_suis_je() ; }
27
29{
30 // Computation of the stability time step:
31 //
32 // - The diffusivity is uniform, therefore:
33 //
34 // dt_stab = 1/(2*diffusivite*Max(coef(elem)))
35 //
36 // where:
37 // coef = 1/(dx*dx) + 1/(dy*dy) + 1/(dz*dz)
38 //
39 // i ranging over all mesh elements
40 //
41 // Note: we do not sweep all elements since the max of coeff is reached
42 // on the element that simultaneously realizes the min of dx, dy and dz
43 double dt_stab = DMAXFLOAT;
44 const Domaine_VDF& domaine_VDF = iter_->domaine();
46
48 {
49 double alpha = -123.;
50 if (equation().diffusion_multi_scalaire())
51 {
52 const int nb_comp = static_cast<int>(std::sqrt(diffu.line_size()));
53 std::vector<double> diff_vect(nb_comp);
54
55 for (int i = 0; i < nb_comp; i++)
56 for (int j = 0; j < nb_comp; j++)
57 diff_vect[i] += std::abs(diffu(0, nb_comp * i + j));
58
59 alpha = *std::max_element(diff_vect.begin(), diff_vect.end());
60 }
61 else
62 {
63 // GF le max permet de traiter le multi_inco
64 alpha = max_array(diffu);
65 }
66
67 double coef = 1 / (domaine_VDF.h_x() * domaine_VDF.h_x()) + 1 / (domaine_VDF.h_y() * domaine_VDF.h_y());
68
69 if (dimension == 3)
70 coef += 1 / (domaine_VDF.h_z() * domaine_VDF.h_z());
71
72 if (alpha == 0)
73 dt_stab = DMAXFLOAT;
74 else
75 dt_stab = 0.5 / (alpha * coef);
76
77 return Process::mp_min(dt_stab);
78 }
79
80 if (equation().diffusion_multi_scalaire())
81 return 1e30;
82
83 return Op_Diff_VDF_base::calculer_dt_stab_(domaine_VDF);
84}
85
86void Op_Diff_VDF_Elem_base::contribuer_termes_croises(const DoubleTab& inco, const Probleme_base& autre_pb, const DoubleTab& autre_inco, Matrice_Morse& matrice) const
87{
88 const Domaine_VDF& domaine = iter_->domaine();
89 const IntTab& f_e = domaine.face_voisins();
90 const Domaine_Cl_VDF& zcl = iter_->domaine_Cl();
91 int l;
92
93 // loop over boundary conditions to find a wall contact
94 for (int i = 0; i < domaine.nb_front_Cl(); i++)
95 {
96 const Cond_lim& la_cl = zcl.les_conditions_limites(i);
97 if (!la_cl->que_suis_je().debute_par("Paroi_Echange_contact")) continue; //not an Echange_contact
98 const Echange_contact_VDF& cl = ref_cast(Echange_contact_VDF, la_cl.valeur());
99 if (cl.nom_autre_pb() != autre_pb.le_nom()) continue; //not our problem
100
101 std::map<int, std::pair<int, int>> f2e;
102 const Front_VF& fvf = ref_cast(Front_VF, cl.frontiere_dis());
103 for (int j = 0; j < cl.item.dimension(0); j++)
104 if ((l = cl.item(j)) >= 0)
105 {
106 int f = fvf.num_face(j);
107 int e = f_e(f, 0) == -1 ? f_e(f, 1) : f_e(f, 0);
108 f2e[f] = std::make_pair(e, l);
109 }
110 iter_->ajouter_contribution_autre_pb(inco, matrice, la_cl, f2e);
111 }
112}
113
114void Op_Diff_VDF_Elem_base::dimensionner_termes_croises(Matrice_Morse& matrice, const Probleme_base& autre_pb, int nl, int nc) const
115{
116 const Champ_P0_VDF& ch = ref_cast(Champ_P0_VDF, equation().inconnue());
117 const Domaine_VDF& domaine = iter_->domaine();
118 const IntTab& f_e = domaine.face_voisins();
119 const Conds_lim& cls = iter_->domaine_Cl().les_conditions_limites();
120 int i, j, l, f, n, N = ch.valeurs().line_size();
121
122 Stencil stencil(0, 2);
123
124 for (i = 0; i < cls.size(); i++)
125 if (sub_type(Echange_contact_VDF, cls[i].valeur()))
126 {
127 const Echange_contact_VDF& cl = ref_cast(Echange_contact_VDF, cls[i].valeur());
128 if (cl.nom_autre_pb() != autre_pb.le_nom()) continue; //not our problem
129
130 /* stencil */
131 const Front_VF& fvf = ref_cast(Front_VF, cl.frontiere_dis());
132 for (j = 0; j < cl.item.dimension(0); j++)
133 if ((l = cl.item(j)) >= 0)
134 {
135 f = fvf.num_face(j);
136 int e = f_e(f, 0) == -1 ? f_e(f, 1) : f_e(f, 0);
137 for (n = 0; n < N; n++) stencil.append_line(N * e + n, N * l + n);
138 }
139 }
140
141 tableau_trier_retirer_doublons(stencil);
142 Matrix_tools::allocate_morse_matrix(nl, nc, stencil, matrice);
143}
144
145void Op_Diff_VDF_Elem_base::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
146{
147 const std::string nom_inco = equation().inconnue().le_nom().getString();
148 if (semi_impl.count(nom_inco)) return; //semi-implicit -> nothing to dimension
149
151 int n_ext = (int)op_ext.size(); //for monolithic thermics
152
153 std::vector<Matrice_Morse *> mat(n_ext);
154 std::vector<int> N(n_ext); //number of components per problem in op_ext
155 for (int i = 0; i < n_ext; i++)
156 {
157 N[i] = op_ext[i]->equation().inconnue().valeurs().line_size();
158
159 std::string nom_mat = i ? nom_inco + "/" + op_ext[i]->equation().probleme().le_nom().getString() : nom_inco;
160 mat[i] = matrices.count(nom_mat) ? matrices.at(nom_mat) : nullptr;
161 if(!mat[i]) continue;
162 Matrice_Morse mat2;
163 if(i==0) Op_VDF_Elem::dimensionner(iter_->domaine(), iter_->domaine_Cl(), mat2, equation().diffusion_multi_scalaire());
164 else
165 {
166 int nl = N[0] * iter_->domaine().nb_elem_tot();
167 int nc = N[i] * op_ext[i]->equation().domaine_dis().nb_elem_tot();
168 dimensionner_termes_croises(mat2, op_ext[i]->equation().probleme(),nl, nc);
169 }
170 mat[i]->nb_colonnes() ? *mat[i] += mat2 : *mat[i] = mat2;
171 }
172}
173
174void Op_Diff_VDF_Elem_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
175{
177
178 // Start with the local operator; i.e. *this!
179 iter_->ajouter_blocs(matrices, secmem, semi_impl);
180
181 // Add extra terms if axisymmetric ...
182 Op_Diff_VDF_base::ajoute_terme_pour_axi(matrices, secmem, semi_impl);
183
184 // Add contribution if monolithic
185 if ((int) op_ext.size() > 1) ajouter_blocs_pour_monolithique(matrices, secmem, semi_impl);
186}
187
188void Op_Diff_VDF_Elem_base::ajouter_blocs_pour_monolithique(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
189{
190 const std::string& nom_inco = equation().inconnue().le_nom().getString();
191 int n_ext = (int)op_ext.size() - 1; // for monolithic thermics, -1 because 1st (i.e. *this) is already handled via ajouter_blocs
192 std::vector<Matrice_Morse *> mat(n_ext);
193 std::vector<const DoubleTab *> inco(n_ext); //unknowns
194
195 for (int i = 0; i < n_ext; i++)
196 {
197 std::string nom_mat = nom_inco + "/" + op_ext[i + 1]->equation().probleme().le_nom().getString();
198 mat[i] = matrices.count(nom_mat) ? matrices.at(nom_mat) : nullptr;
199 if(mat[i])
200 {
201 inco[i] = semi_impl.count(nom_mat) ? &semi_impl.at(nom_mat) : &op_ext[i + 1]->equation().inconnue().valeurs();
202 contribuer_termes_croises(*inco[i], op_ext[i + 1]->equation().probleme(), op_ext[i + 1]->equation().inconnue().valeurs(), *mat[i]);
203 }
204 }
205}
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Champ_P0_VDF Class representing a P0 discrete field per element associated with a discretized d...
virtual DoubleTab & valeurs()=0
Champ_Uniforme Represents a field that is constant in space and time.
virtual Frontiere_dis_base & frontiere_dis()
Returns the discretized boundary to which the boundary conditions apply.
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
class Domaine_Cl_VDF
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_VDF
Definition Domaine_VDF.h:61
double h_y() const
double h_x() const
double h_z() const
const Domaine & domaine() const
const Nom & nom_autre_pb() const
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
const Nom & le_nom() const override
Returns the name of the field.
class Front_VF
Definition Front_VF.h:36
int num_face(const int) const
Definition Front_VF.h:68
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
const std::string & getString() const
Definition Nom.h:92
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Op_Diff_VDF_Elem_base This class represents the diffusion operator associated with a transport ...
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl) const override
void contribuer_termes_croises(const DoubleTab &inco, const Probleme_base &autre_pb, const DoubleTab &autre_inco, Matrice_Morse &matrice) const override
void dimensionner_termes_croises(Matrice_Morse &, const Probleme_base &autre_pb, int nl, int nc) const override
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl) const override
double calculer_dt_stab() const override
Computes dt_stab.
class Op_Diff_VDF_base Classe de base des operateurs de diffusion VDF
double calculer_dt_stab_(const Domaine_VDF &zone_VDF) const
void init_op_ext() const override
void ajoute_terme_pour_axi(matrices_t, DoubleTab &, const tabs_t &) const
void dimensionner(const Domaine_VDF &, const Domaine_Cl_VDF &, Matrice_Morse &, const bool) const
std::vector< const Operateur_Diff_base * > op_ext
virtual const Champ_base & diffusivite() const =0
virtual const Champ_base & diffusivite_pour_pas_de_temps() const
Returns the field corresponding to the true diffusivity of the medium used for the time step computat...
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
class Probleme_base It is a Probleme_U that is not a coupling.
static double mp_min(double)
Definition Process.cpp:391
Base class for output streams.
Definition Sortie.h:52
virtual int has_champ_masse_volumique() const
Returns 1 if the density field has been associated, 0 otherwise.
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67