TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Face_PolyMAC_HFV.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 <Op_Diff_PolyMAC_HFV_base.h>
17#include <Champ_Face_PolyMAC_HFV.h>
18#include <Linear_algebra_tools_impl.h>
19#include <Domaine_PolyMAC_HFV.h>
20#include <Connectivite_som_elem.h>
21#include <Champ_Fonc_reprise.h>
22#include <Schema_Temps_base.h>
23#include <MD_Vector_base.h>
24#include <Champ_Uniforme.h>
25#include <TRUSTTab_parts.h>
26#include <Pb_Multiphase.h>
27#include <Equation_base.h>
28#include <Matrix_tools.h>
29#include <Domaine_VF.h>
30#include <Operateur.h>
31#include <Symetrie.h>
32#include <EChaine.h>
33#include <Domaine.h>
34#include <array>
35#include <cmath>
36
37Implemente_instanciable(Champ_Face_PolyMAC_HFV,"Champ_Face_PolyMAC_HFV", Champ_Face_PolyMAC_CDO) ;
38
39Sortie& Champ_Face_PolyMAC_HFV::printOn(Sortie& os) const { return os << que_suis_je() << " " << le_nom(); }
40
42
44{
45 // j'utilise le meme genre de code que dans Champ_Fonc_P0_base sauf que je recupere le nombre de faces au lieu du nombre d'elements
46 // je suis tout de meme etonne du code utilise dans Champ_Fonc_P0_base::fixer_nb_valeurs_nodales() pour recuperer le domaine discrete...
47
48 assert(n == domaine_PolyMAC_HFV().nb_faces() || n < 0); //on accepte a la fois les conventions VEF et VDF
49
50 // Probleme: nb_comp vaut 2 mais on ne veut qu'une dimension !!!
51 // HACK :
52 const int old_nb_compo = nb_compo_;
54
56 nb_compo_ = old_nb_compo;
57 return n;
58}
59
61{
62 for (int n = 0; n < nb_valeurs_temporelles(); n++)
63 if (futur(n).size_reelle_ok())
64 {
65 DoubleTab& vals = futur(n);
66 vals.set_md_vector(MD_Vector()); //on enleve le MD_Vector...
67 vals.resize_dim0(domaine_PolyMAC_HFV().mdv_faces_aretes->get_nb_items_tot()); //...on dimensionne a la bonne taille...
68 vals.set_md_vector(domaine_PolyMAC_HFV().mdv_faces_aretes); //...et on remet le bon MD_Vector
69 }
70}
71
73{
74 if (! via_ch_fonc_reprise()) return Champ_Inc_base::reprendre(fich); /* ie: resume last time ! */
75
76 const Pb_Multiphase * pbm = mon_equation_non_nul() ? (sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr) : nullptr;
77 if (pbm) return Champ_Inc_base::reprendre(fich);
78
79 // sinon on fait ca ...
81 return Champ_Inc_base::reprendre(fich);
82}
83
84/* vitesse aux elements */
85void Champ_Face_PolyMAC_HFV::interp_ve(const DoubleTab& inco, DoubleTab& val, bool is_vit) const
86{
88 const DoubleTab& xv = domaine.xv(), &xp = domaine.xp();
89 const DoubleVect& fs = domaine.face_surfaces(), *ppf = mon_equation_non_nul() ? &equation().milieu().porosite_face() : nullptr, *ppe = ppf ? &equation().milieu().porosite_elem() : nullptr, &ve = domaine.volumes();
90 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
91 int e, f, j, r;
92
93 val = 0;
94 for (e = 0; e < val.dimension(0); e++)
95 for (j = 0; j < e_f.dimension(1) && (f = e_f(e, j)) >= 0; j++)
96 {
97 const double coef = is_vit && ppf ? (*ppf)(f) / (*ppe)(e) : 1.0;
98 for (r = 0; r < dimension; r++) val(e, r) += fs(f) / ve(e) * (xv(f, r) - xp(e, r)) * (e == f_e(f, 0) ? 1 : -1) * inco(f) * coef;
99 }
100}
101
102/* vitesse aux elements sur une liste d'elements */
103void Champ_Face_PolyMAC_HFV::interp_ve(const DoubleTab& inco, const IntVect& les_polys, DoubleTab& val, bool is_vit) const
104{
106 const DoubleTab& xv = domaine.xv(), &xp = domaine.xp();
107 const DoubleVect& fs = domaine.face_surfaces(), *ppf = mon_equation_non_nul() ? &equation().milieu().porosite_face() : nullptr, *ppe = ppf ? &equation().milieu().porosite_elem() : nullptr, &ve = domaine.volumes();
108 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
109 int e, f, j, d, D = dimension, n, N = inco.line_size();
110 assert(ve.line_size() == N * D);
111
112 for (int poly = 0; poly < les_polys.size(); poly++)
113 if ((e = les_polys(poly)) != -1)
114 {
115 for (n = 0; n < N * D; n++) val(e, n) = 0;
116 for (j = 0; j < e_f.dimension(1) && (f = e_f(e, j)) >= 0; j++)
117 {
118 const double coef = is_vit && ppf ? (*ppf)(f) / (*ppe)(e) : 1.0;
119 for (d = 0; d < D; d++)
120 for (n = 0; n < N; n++) val(e, N * d + n) += fs(f) / ve(e) * (xv(f, d) - xp(e, d)) * (e == f_e(f, 0) ? 1 : -1) * inco(f, n) * coef;
121 }
122 }
123}
124
125DoubleTab& Champ_Face_PolyMAC_HFV::valeur_aux_faces(DoubleTab& val) const
126{
127 const Champ_base& cha=le_champ();
128 int nb_compo=cha.nb_comp(), n, N = cha.valeurs().line_size(), d, D = dimension;
129
130 if (nb_compo == 1)
131 Process::exit("TRUST error in Champ_Face_PolyMAC_HFV::valeur_aux_faces : A scalar field cannot be of Champ_Face type !");
132
134 val.resize(domaine.nb_faces(), N * D);
135
136 for (int f = 0; f < domaine.nb_faces(); f++)
137 for (d = 0; d < D; d++)
138 for (n = 0; n < N; n++) val(f, N * d + n) = cha.valeurs()(f, n) * domaine.face_normales(f, d) / domaine.face_surfaces(f);
139 return val;
140}
141
142DoubleTab& Champ_Face_PolyMAC_HFV::trace(const Frontiere_dis_base& fr, DoubleTab& x, double t, int distant) const
143{
144 assert(distant == 0);
145 const bool vectoriel = (le_champ().nb_comp() > 1);
146 const DoubleTab& val = valeurs(t);
147 int n, N = val.line_size(), d, D = dimension, dim = vectoriel ? D : 1;
148 const Front_VF& fr_vf = ref_cast(Front_VF, fr);
149 const IntTab& face_voisins = domaine_PolyMAC_HFV().face_voisins();
150 DoubleTrav ve(0, N * D);
151 if (vectoriel)
152 {
154 interp_ve(val, ve);
155 }
156
157 for (int i = 0; i < fr_vf.nb_faces(); i++)
158 {
159 const int face = fr_vf.num_premiere_face() + i;
160 for (int dir = 0; dir < 2; dir++)
161 {
162 const int elem = face_voisins(face, dir);
163 if (elem != -1)
164 {
165 for (d = 0; d < dim; d++)
166 for (n = 0; n < N; n++) x(i, N * d + n) = vectoriel ? ve(elem, N * d + n) : val(face, n);
167 }
168 }
169 }
170
171 return x;
172}
173
175{
176 return domaine_PolyMAC_HFV().nb_faces(); //on ignore les variables auxiliaires
177}
virtual Champ_base & le_champ()
: class Champ_Face_PolyMAC_HFV
void interp_ve(const DoubleTab &inco, DoubleTab &val, bool is_vit=true) const override
int fixer_nb_valeurs_nodales(int n) override
int nb_valeurs_nodales() const override
int reprendre(Entree &fich) override
Reprise d'un Objet_U sur un flot d'entree Methode a surcharger.
DoubleTab & trace(const Frontiere_dis_base &, DoubleTab &, double, int distant) const override
Calcule la trace d'un champ sur une frontiere au temps tps.
const Domaine_PolyMAC_HFV & domaine_PolyMAC_HFV() const
DoubleTab & valeur_aux_faces(DoubleTab &result) const override
renvoie la valeur du champ aux faces
const Domaine & domaine() const
virtual void creer_tableau_distribue(const MD_Vector &, RESIZE_OPTIONS=RESIZE_OPTIONS::COPY_INIT)
DoubleTab & futur(int i=1) override
Renvoie les valeurs du champs a l'instant t+i.
virtual int nb_valeurs_temporelles() const
Renvoie le nombre de valeurs temporelles actuellement conservees.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
int reprendre(Entree &) override
Lecture d'un champ inconnue a partir d'un flot d'entree en vue d'une reprise.
bool via_ch_fonc_reprise() const
virtual DoubleTab & valeurs()=0
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
creation d'un tableau parallele de valeurs aux elements.
Definition Domaine.cpp:851
int nb_faces() const
renvoie le nombre global de faces.
Definition Domaine_VF.h:471
int face_voisins(int num_face, int i) const
renvoie l'element voisin de numface dans la direction i.
Definition Domaine_VF.h:418
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
const Nom & le_nom() const override
Renvoie le nom du champ.
virtual int nb_comp() const
Definition Field_base.h:56
int nb_compo_
Definition Field_base.h:95
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
classe Frontiere_dis_base Classe representant une frontiere discretisee.
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
DoubleVect & porosite_face()
Definition Milieu_base.h:62
int mon_equation_non_nul() const
Definition MorEqn.h:85
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
static int dimension
Definition Objet_U.h:99
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 Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
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
void set_md_vector(const MD_Vector &) override
Definition TRUSTTab.tpp:673
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
void resize_dim0(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:459
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67