TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Terme_Source_Solide_SWIFT_VDF.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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_Source_Solide_SWIFT_VDF.h>
17#include <math.h>
18#include <Champ_Uniforme.h>
19#include <Domaine_VDF.h>
20#include <Conduction.h>
21#include <Interprete.h>
22#include <Probleme_base.h>
23#include <Milieu_base.h>
24
25Implemente_instanciable(Terme_Source_Solide_SWIFT_VDF,"Solide_SWIFT_VDF_P0_VDF",Source_base);
26
28{
29 return s << que_suis_je() ;
30}
31
33{
34 int i,compteur = 0;
35 Motcle motlu;
36 Cerr << " ######### Warning ! #########" << finl;
37 Cerr << " For the moment, this forcing term is only available" << finl;
38 Cerr << " for recovering identical solid meshes." << finl;
39 Cerr << " If otherwise, it will produce a beautiful core-dump..." << finl;
40
41 for(i=0 ; i<3 ; i++)
42 {
43 is >> motlu;
44
45 if(motlu == "TAU")
46 {
47 compteur++;
48 is >> tau;
49 if(tau==0)
50 {
51 Cerr << "TAU can not be equal to 0." << finl;
52 exit();
53 }
54 Cerr << "Characteristic time TAU is : " << tau << finl;
55 }
56 else if(motlu == "pb_swift")
57 {
58 compteur++;
59 Nom swift;
60 is >> swift;
61 pb_swift=ref_cast(Probleme_base, Interprete::objet(swift));
62 Cerr << "pb_swift is: " << pb_swift->le_nom() << finl;
63 }
64 else if(motlu == "pb_corse")
65 {
66 compteur++;
67 Nom corse;
68 is >> corse;
69 pb_corse=ref_cast(Probleme_base, Interprete::objet(corse));
70 Cerr << "pb_coarse is: " << pb_corse->le_nom() << finl;
71 }
72 else
73 {
74 Cerr << "An argument of Terme_Source_Solide_SWIFT_VDF is not correct !" << finl;
75 exit();
76 }
77 }
78 if(compteur != 3)
79 {
80 Cerr << "The forcing term for the mean solid temperature field with the SWIFT method needs 3 arguments" << finl;
81 Cerr << "Syntax : " << finl;
82 Cerr << "Solide_SWIFT SWIFT pb_sol_SWIFT COARSE pb_sol_coarse TAU tau " << finl;
83 exit();
84 }
85
86
87 // On recupere les equations de conduction des deux domaines (SWIFT et grossier)
88 int flag=0;
89 for(i=0; i<pb_swift->nombre_d_equations(); i++)
90 {
91 if(sub_type(Conduction,pb_swift->equation(i)))
92 {
93 eq_swift = ref_cast(Conduction,pb_swift->equation(i));
94 flag=1;
95 }
96 }
97 if (flag==0)
98 {
99 Cerr << "Error : The Conduction equation was not found...!" << finl;
100 Cerr << "for the SWIFT solid forcing term (in pb_swift)." << finl;
101 exit();
102 }
103
104 flag=0;
105 for(i=0; i<pb_corse->nombre_d_equations(); i++)
106 {
107 if(sub_type(Conduction,pb_corse->equation(i)))
108 {
109 eq_corse = ref_cast(Conduction,pb_corse->equation(i));
110 flag=1;
111 }
112 }
113 if (flag==0)
114 {
115 Cerr << "Error : The Conduction equation was not found...!" << finl;
116 Cerr << "for the SWIFT solid forcing term (in pb_coarse)." << finl;
117 exit();
118 }
119
122
123 // Calcul du tableau de correspondance entre un element de Tmoy_swift et l'element de Tmoy_corse correspondant
124 // pour calculer le terme de forcage.
126
127 return is;
128
129}
130
132{
133}
134
138
139void Terme_Source_Solide_SWIFT_VDF::init_calcul_moyenne(const Conduction& my_eqn, DoubleVect& Y, IntVect& corresp, IntVect& compt)
140{
141 int num_elem, j, indic, trouve;
142 double y;
143
144 const Domaine_dis_base& zdisbase = my_eqn.inconnue().domaine_dis_base();
145 const Domaine_VDF& domaine_VDF = ref_cast(Domaine_VDF, zdisbase);
146 const DoubleTab& xp = domaine_VDF.xp();
147
148 int nb_elems = domaine_VDF.domaine().nb_elem();
149 int nb_faces_x = domaine_VDF.nb_faces_X();
150 int nb_faces_z = domaine_VDF.nb_faces_Z();
151
152 int Nx = nb_elems / (nb_faces_x - nb_elems);
153 int Nz = nb_elems / (nb_faces_z - nb_elems);
154 int Ny = nb_elems / Nx / Nz;
155
156 Y.resize(Ny);
157 compt.resize(Ny);
158 corresp.resize(nb_elems);
159
160 Y = -100.;
161 compt = 0;
162 corresp = -1;
163
164 j = 0;
165 indic = 0;
166 for (num_elem = 0; num_elem < nb_elems; num_elem++)
167 {
168 y = xp(num_elem, 1);
169 trouve = 0;
170 for (j = 0; j < indic + 1; j++)
171 {
172 if (std::fabs(y - Y[j]) <= 1e-8)
173 {
174 corresp[num_elem] = j;
175 compt[j]++;
176 j = indic + 1;
177 trouve = 1;
178 break;
179 }
180 }
181 if (trouve == 0)
182 {
183 corresp[num_elem] = indic;
184 Y[indic] = y;
185 compt[indic]++;
186 indic++;
187 }
188 }
189}
190
192{
193 int t_S = Y_swift.size();
194 int t_C = Y_corse.size();
195 corresp_SC.resize(t_S);
196
197 for (int j = 0; j < t_S; j++)
198 {
199 int burk = 1;
200 for (int i = 0; i < t_C; i++)
201 {
202 if (std::fabs(Y_swift[j] - Y_corse[i]) <= 1e-8)
203 {
204 burk = 0;
205 corresp_SC[j] = i;
206 }
207 }
208 if (burk)
209 {
210 Cerr << "## ACHTUNG !!! On n'a pas trouve l'equivalence entre" << finl;
211 Cerr << "## les deux domaines au niveau des Y !" << finl;
212 }
213 }
214}
215
216void Terme_Source_Solide_SWIFT_VDF::calcul_moyenne(const Conduction& my_eqn, DoubleVect& T_moy, const IntVect& corresp, const IntVect& compt) const
217{
218 const Domaine_dis_base& zdisbase = my_eqn.inconnue().domaine_dis_base();
219 const Domaine_VDF& domaine_VDF = ref_cast(Domaine_VDF, zdisbase);
220 const DoubleTab& Temp = my_eqn.inconnue().valeurs();
221
222 int nb_elems = domaine_VDF.domaine().nb_elem();
223 int nb_faces_x = domaine_VDF.nb_faces_X();
224 int nb_faces_z = domaine_VDF.nb_faces_Z();
225
226 int Nx = nb_elems / (nb_faces_x - nb_elems);
227 int Nz = nb_elems / (nb_faces_z - nb_elems);
228 int Ny = nb_elems / Nx / Nz;
229
230 int j = 0;
231 T_moy.resize(Ny);
232 T_moy = 0.;
233
234 for (j = 0; j < nb_elems; j++)
235 T_moy[corresp[j]] += Temp[j];
236 for (j = 0; j < Ny; j++)
237 T_moy[j] /= compt[j];
238}
239
240void Terme_Source_Solide_SWIFT_VDF::ajouter_blocs(matrices_t matrices, DoubleTab& resu, const tabs_t& semi_impl) const
241{
242
243 const Domaine_dis_base& zdisbase = eq_swift->inconnue().domaine_dis_base();
244 const Domaine_VDF& domaine_VDF = ref_cast(Domaine_VDF, zdisbase);
245 int nb_elems = domaine_VDF.nb_elem();
246 const DoubleVect& volume = domaine_VDF.volumes();
247
248 DoubleVect Tmoy_swift; // Profils de temperature moyenne.
249 DoubleVect Tmoy_corse;
250
251 // On calcule les profils de temperature moyenne dans les deux solides.
252 calcul_moyenne(eq_swift.valeur(), Tmoy_swift, corresp_swift, compt_swift);
253 calcul_moyenne(eq_corse.valeur(), Tmoy_corse, corresp_corse, compt_corse);
254
255 for (int num_elem = 0; num_elem < nb_elems; num_elem++)
256 {
257 resu(num_elem) += volume(num_elem) * (Tmoy_corse(corresp_SC[corresp_swift[num_elem]]) - Tmoy_swift(corresp_swift[num_elem])) / tau;
258 }
259
260}
261
262DoubleTab& Terme_Source_Solide_SWIFT_VDF::calculer(DoubleTab& resu) const
263{
264 resu = 0;
265 return ajouter(resu);
266}
const Domaine_dis_base & domaine_dis_base() const override
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
Classe Conduction Cette classe represente l'equation d'evolution.
Definition Conduction.h:41
const Champ_Inc_base & inconnue() const override
Renvoie le champ inconnue de l'equation, i. e. la temperature. (version const).
Definition Conduction.h:99
int_t nb_elem() const
Definition Domaine.h:131
classe Domaine_Cl_dis_base Les objets Domaine_Cl_dis_base representent les conditions aux limites
class Domaine_VDF
Definition Domaine_VDF.h:64
int nb_faces_Z() const
int nb_faces_X() const
double volumes(int i) const
Definition Domaine_VF.h:113
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
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
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
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
virtual DoubleTab & ajouter(DoubleTab &) const
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
void calcul_moyenne(const Conduction &my_eqn, DoubleVect &T_moy, const IntVect &corresp, const IntVect &compt) const
DoubleTab & calculer(DoubleTab &) const override
void init_calcul_moyenne(const Conduction &my_eqn, DoubleVect &Y, IntVect &corresp, IntVect &compt)
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl) const override
void associer_domaines(const Domaine_dis_base &, const Domaine_Cl_dis_base &) override
void associer_pb(const Probleme_base &) override