TrioCFD 1.9.9_beta
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 // use the same kind of code as in Champ_Fonc_P0_base, but retrieve the number of faces instead of the number of elements
46 // note: the code used in Champ_Fonc_P0_base::fixer_nb_valeurs_nodales() to retrieve the discrete domain is somewhat surprising...
47
48 assert(n == domaine_PolyMAC_HFV().nb_faces() || n < 0); //accept both VEF and VDF conventions
49
50 // Problem: nb_comp equals 2 but we only want one 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()); //remove the MD_Vector...
67 vals.resize_dim0(domaine_PolyMAC_HFV().mdv_faces_aretes->get_nb_items_tot()); //...resize to the correct size...
68 vals.set_md_vector(domaine_PolyMAC_HFV().mdv_faces_aretes); //...and restore the correct 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 // otherwise do this ...
81 return Champ_Inc_base::reprendre(fich);
82}
83
84/* velocity at 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/* velocity at elements over a list of 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(); //ignore auxiliary variables
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
Restores an Objet_U from an input stream. Virtual method to override.
DoubleTab & trace(const Frontiere_dis_base &, DoubleTab &, double, int distant) const override
Computes the trace of a field on a boundary at time tps.
const Domaine_PolyMAC_HFV & domaine_PolyMAC_HFV() const
DoubleTab & valeur_aux_faces(DoubleTab &result) const override
Returns the field value at the 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
Returns field values at instant t+i.
virtual int nb_valeurs_temporelles() const
Returns the number of temporal values currently kept.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
int reprendre(Entree &) override
Reads an unknown field from an input stream for a restart.
bool via_ch_fonc_reprise() const
virtual DoubleTab & valeurs()=0
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates a parallel array of values at elements.
Definition Domaine.cpp:850
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in 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
Returns the name of the field.
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
class Frontiere_dis_base Class representing a discretized boundary.
: This class is an OWN_PTR but the pointed object is shared among multiple
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
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
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
Multiphase thermohydraulics problem of type "3*N equations":
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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