TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
ALE_MetricsUpdater.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 <ALE_MetricsUpdater.h>
17#include <Domaine_ALE.h>
18#include <Objet_U.h>
19#include <Domaine_VF.h>
20#include <Domaine_VEF.h>
21#include <Domaine_EF.h>
22#include <Domaine_Poly_base.h>
23#include <Domaine_Cl_VEF.h>
24#include <Elem_VEF_base.h>
25#include <Elem_EF_base.h>
26#include <Faces.h>
27#include <CL_Types_include.h>
28#include <Probleme_base.h>
29#include <Process.h>
30
32 Probleme_base& pb, Domaine_ALE& dom)
33{
34 Domaine_VF& le_dom_VF = ref_cast(Domaine_VF, le_domaine_dis);
35
36 // Update boundary surface domains and any extracted-surface sub-domain
37 dom.creer_mes_domaines_frontieres(le_dom_VF);
39
40 // Recompute cell volumes and centroids
41 le_dom_VF.volumes() = 0.;
42 dom.calculer_volumes(le_dom_VF.volumes(), le_dom_VF.inverse_volumes());
43 le_dom_VF.xp() = 0;
44 dom.calculer_centres_gravite(le_dom_VF.xp());
45
46 // Recompute face centroids.
47 DoubleTab& xv = le_dom_VF.xv();
48 xv.reset();
49 Faces::Calculer_centres_gravite(xv, dom.type_elem()->type_face(),
50 dom.les_sommets(), le_dom_VF.face_sommets());
51
52 // Dispatch to discretization-specific update
53 if (sub_type(Domaine_VEF, le_dom_VF))
54 update_VEF(pb, dom);
55 else if (sub_type(Domaine_EF, le_dom_VF))
56 update_EF(pb, dom);
57 else if (sub_type(Domaine_Poly_base, le_dom_VF))
58 update_PolyMAC(pb, dom);
59 else
60 {
61 Cerr << "ALE_MetricsUpdater: Discretization not recognized by ALE!" << finl;
63 }
64}
65
66void ALE_MetricsUpdater::update_VEF(Probleme_base& pb, Domaine_ALE& dom)
67{
68 Domaine_VEF& le_dom_VEF = ref_cast(Domaine_VEF, pb.domaine_dis());
69
70 DoubleTab& normales = le_dom_VEF.face_normales();
71 //auto& facette_normales_ = le_dom_VEF.facette_normales();
72 IntVect& rang_elem_non_standard = le_dom_VEF.rang_elem_non_std();
73 le_dom_VEF.volumes_entrelaces() = 0;
74 le_dom_VEF.calculer_volumes_entrelaces();
75
76 const IntTab& face_sommets = le_dom_VEF.face_sommets();
77 const int nb_faces_tot = face_sommets.dimension_tot(0);
78 le_dom_VEF.calculer_h_carre();
79 const Elem_VEF_base& type_elem = le_dom_VEF.type_elem();
80
81 // Recompute outward face normals
82 type_elem.creer_face_normales(normales, face_sommets, le_dom_VEF.face_voisins(), le_dom_VEF.elem_faces(), dom);
83
84 // Fix orientation of periodic normals.
85 // After the first call to Domain_VEF::modifier_pour_Cl, periodic face neighbors
86 // are no longer -1, so modifier_pour_Cl cannot be reused.
87 // We manually enforce: normales(faassociee, k) == normales(face, k).
88 IntVect fait(nb_faces_tot);
89 fait = 0;
90 int dimension=Objet_U::dimension;
91 const Domaine_Cl_VEF& domaine_Cl_VEF = ref_cast(Domaine_Cl_VEF,
92 pb.equation(0).domaine_Cl_dis());
93 for (int n_bord = 0; n_bord < le_dom_VEF.nb_front_Cl(); n_bord++)
94 {
95 const Cond_lim& la_cl = domaine_Cl_VEF.les_conditions_limites(n_bord);
96 if (sub_type(Periodique, la_cl.valeur()))
97 {
98 const Periodique& la_cl_period = ref_cast(Periodique, la_cl.valeur());
99 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
100 const int nfin = le_bord.nb_faces_tot();
101 for (int num_face = 0; num_face < nfin; num_face++)
102 {
103 int face = le_bord.num_face(num_face);
104 if (fait(face) == 0)
105 {
106 int faassociee = le_bord.num_face(la_cl_period.face_associee(num_face));
107 fait(face) = 1;
108 fait(faassociee) = 1;
109 for (int k = 0; k < dimension; k++)
110 normales(faassociee, k) = normales(face, k);
111 }
112 }
113 }
114 }
115
116 type_elem.creer_facette_normales(le_dom_VEF, rang_elem_non_standard);
117
118 // Recompute Cl-specific entrelaced volumes and facette normals for every equation
119 const int nb_eqn = pb.nombre_d_equations();
120 for (int num_eq = 0; num_eq < nb_eqn; num_eq++)
121 {
122 Domaine_Cl_VEF& la_zcl_VEF = ref_cast(Domaine_Cl_VEF,
123 pb.equation(num_eq).domaine_Cl_dis());
124 la_zcl_VEF.remplir_volumes_entrelaces_Cl(le_dom_VEF);
125 la_zcl_VEF.remplir_normales_facettes_Cl(le_dom_VEF);
126 }
127
128 update_face_surfaces_from_normal_vectors(dom);
129}
130
131
132void ALE_MetricsUpdater::update_EF(Probleme_base& pb, Domaine_ALE& dom)
133{
134 // Currently a no-op (placeholder for future implementation)
135 return;
136
137 Domaine_EF& le_dom_ef = ref_cast(Domaine_EF, pb.domaine_dis());
138 const int nb_faces_tot = le_dom_ef.nb_faces_tot();
139 DoubleTab& normales = le_dom_ef.face_normales();
140 const Elem_EF_base& type_elem = le_dom_ef.type_elem();
141 normales = 0.;
142 for (int num_face = 0; num_face < nb_faces_tot; num_face++)
143 type_elem.normale(num_face, normales, le_dom_ef.face_sommets(),
144 le_dom_ef.face_voisins(), le_dom_ef.elem_faces(), dom);
145
146 le_dom_ef.calculer_volumes_entrelaces();
148 le_dom_ef.calculer_h_carre();
149 le_dom_ef.calculer_Bij();
150}
151
152
153void ALE_MetricsUpdater::update_PolyMAC(Probleme_base& pb, Domaine_ALE& dom)
154{
155 Domaine_Poly_base& le_dom_poly = ref_cast(Domaine_Poly_base, pb.domaine_dis());
156 le_dom_poly.fill_normales();
157 le_dom_poly.volumes_entrelaces() = 0;
158 le_dom_poly.calculer_volumes_entrelaces();
159 update_face_surfaces_from_normal_vectors(dom);
160 le_dom_poly.recalculer_xv();
161}
162
163
164void ALE_MetricsUpdater::update_face_surfaces_from_normal_vectors(Domaine_ALE& dom)
165{
166 // Recompute scalar face surfaces as ||face_normales||.
167 Domaine_VF& le_dom_VF = ref_cast(Domaine_VF, dom.getEquation().probleme().domaine_dis());
168 const int nf_tot = le_dom_VF.nb_faces_tot();
169 int dimension=Objet_U::dimension;
170 DoubleVect fs(nf_tot);
171 for (int i = 0; i < nf_tot; i++)
172 {
173 double surf = 0.;
174 for (int k = 0; k < dimension; k++)
175 surf += le_dom_VF.face_normales(i, k) * le_dom_VF.face_normales(i, k);
176 fs(i) = sqrt(surf);
177 }
178 le_dom_VF.calculer_face_surfaces(fs);
179}
void update(Domaine_dis_base &le_domaine_dis, Probleme_base &pb, Domaine_ALE &dom)
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
void creer_mes_domaines_frontieres(const Domaine_VF &domaine_vf)
Definition Domaine.cpp:2172
void calculer_centres_gravite(DoubleTab_t &xp) const
Calculates the centers of gravity of the domain elements.
Definition Domaine.h:503
virtual void calculer_volumes(DoubleVect_t &volumes, DoubleVect_t &inv_volumes) const
Computes the volumes of the domain elements.
Definition Domaine.cpp:763
DoubleTab_t & les_sommets()
Definition Domaine.h:113
void update_coord_dom_extrait_surface()
Equation_base & getEquation()
virtual void remplir_volumes_entrelaces_Cl(const Domaine_VEF &)
Called by completer(): fills type_elem_Cl_ and volumes_entrelaces_Cl_.
void remplir_normales_facettes_Cl(const Domaine_VEF &)
Called by completer(): fills normales_facettes_Cl_ and vecteur_face_facette_Cl_.
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_EF
Definition Domaine_EF.h:56
void calculer_volumes_sommets(const Domaine_Cl_dis_base &zcl)
void calculer_h_carre()
const Elem_EF_base & type_elem() const
Definition Domaine_EF.h:64
void calculer_volumes_entrelaces()
virtual void calculer_Bij(DoubleTab &bij_)
class Domaine_Poly_base
virtual void calculer_volumes_entrelaces()
class Domaine_VEF
Definition Domaine_VEF.h:53
IntVect & rang_elem_non_std()
Definition Domaine_VEF.h:85
void calculer_volumes_entrelaces()
void calculer_h_carre()
const Elem_VEF_base & type_elem() const
Definition Domaine_VEF.h:74
class Domaine_VF
Definition Domaine_VF.h:44
DoubleVect & volumes_entrelaces()
Definition Domaine_VF.h:99
int nb_faces_tot() const
Returns the total number of faces.
Definition Domaine_VF.h:481
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
double volumes(int i) const
Definition Domaine_VF.h:113
int face_sommets(int i, int j) const
Returns the index of the i-th vertex of face num_face.
Definition Domaine_VF.h:582
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
void calculer_face_surfaces(const DoubleVect &surfaces)
Definition Domaine_VF.h:50
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
double inverse_volumes(int i) const
Definition Domaine_VF.h:114
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
int nb_front_Cl() const
virtual void normale(int, DoubleTab &, const IntTab &, const IntTab &, const IntTab &, const Domaine &) const =0
virtual void creer_face_normales(DoubleTab &, const IntTab &, const IntTab &, const IntTab &, const Domaine &) const =0
virtual void creer_facette_normales(const Domaine_VEF &, const IntVect &) const =0
virtual Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the discretized boundary condition domain associated with the equation.
Probleme_base & probleme()
Returns the problem associated with the equation.
static void Calculer_centres_gravite(DoubleTab_t &xv, Type_Face type_face_, const DoubleTab_t &coord, const IntTab_t &sommet)
class Front_VF
Definition Front_VF.h:36
int nb_faces_tot() const
Definition Front_VF.h:58
int num_face(const int) const
Definition Front_VF.h:68
static int dimension
Definition Objet_U.h:94
class Periodique This class represents a periodic boundary condition.
Definition Periodique.h:31
int face_associee(int i) const
Definition Periodique.h:35
class Probleme_base It is a Probleme_U that is not a coupling.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
const Domaine_dis_base & domaine_dis() const
Returns the discretized domain associated with the problem (const version).
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
void reset() override
Definition TRUSTTab.tpp:362
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160