TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Elem_geom_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 <Elem_geom_base.h>
17#include <Domaine.h>
18
19Implemente_base_32_64(Elem_geom_base_32_64,"Elem_geom_base",Objet_U);
20
21/*! @brief Does nothing.
22 *
23 * @param s An output stream.
24 * @return The output stream.
25 */
26template<class _SIZE_>
28{
29 return s;
30}
31
32/*! @brief Does nothing.
33 *
34 * @param s An input stream.
35 * @return The input stream.
36 */
37template<class _SIZE_>
39{
40 return s;
41}
42
43
44/*! @brief Returns the face parameter if the specified face type matches that of the geometric element.
45 *
46 * @param face Face index.
47 * @param type A face type.
48 * @throws Bad face type specified.
49 */
50template <typename _SIZE_>
51int Elem_geom_base_32_64<_SIZE_>::num_face(int face, Type_Face& type) const
52{
53 assert(type==type_face());
54 return face;
55}
56
57/*! @brief Creates the faces of the specified geometric element of the domain using the given face type.
58 *
59 * @param les_faces Faces object to fill.
60 * @param num_elem Index of the element whose faces are to be created.
61 * @param type Face type to create.
62 */
63template <typename _SIZE_>
65 _SIZE_ num_elem,
66 Type_Face type) const
67{
68 int type_id=0;
69 for(; ((type_id<nb_type_face())
70 &&(type!=type_face(type_id))); type_id++)
71 ;
72 const IntTab_t& les_Polys = mon_dom->les_elems();
73 assert(les_Polys.dimension_tot(0) > num_elem);
74 int face, i;
75 les_faces.dimensionner(nb_faces(type_id));
76 les_faces.associer_domaine(mon_dom.valeur());
77
78 for(face=0; face<nb_faces(type_id); face++)
79 {
80 int face_id=num_face(face, type);
81 for (i=0; i<nb_som_face(type_id); i++)
82 les_faces.sommet(face_id,i) = les_Polys(num_elem,face_sommet(face_id, i));
83 les_faces.completer(face_id, num_elem);
84 }
85}
86
87
88/*! @brief Computes the centers of mass of all elements in the domain associated with this geometric element.
89 *
90 * @param tab_xp Array to fill with the coordinates of the centers of mass.
91 */
92template <typename _SIZE_>
94{
95 int_t nb_elem;
96 if(tab_xp.dimension(0)==0)
97 {
98 nb_elem = mon_dom->nb_elem_tot();
99 tab_xp.resize(nb_elem,dimension);
100 }
101 else
102 nb_elem=tab_xp.dimension(0);
103
104 int nb_som_elem = nb_som();
105 int dim = Objet_U::dimension;
106 // ToDo create a type in View_Types.h ?
107 ConstView<_SIZE_,2> les_Polys = mon_dom->les_elems().view_ro();
108 //CIntTabView les_Polys = mon_dom->les_elems().view_ro();
109 CDoubleTabView coord = mon_dom->coord_sommets().view_ro();
110 DoubleTabView xp = tab_xp.view_wo();
111 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), nb_elem, KOKKOS_LAMBDA(const int_t num_elem)
112 {
113 for (int i = 0; i < dim; i++)
114 xp(num_elem, i) = 0;
115 int nb_som_reel = nb_som_elem;
116 while (les_Polys(num_elem, nb_som_reel - 1) == -1) nb_som_reel--;
117 for (int s = 0; s < nb_som_reel; s++)
118 {
119 int_t num_som = les_Polys(num_elem, s);
120 for (int i = 0; i < dim; i++)
121 xp(num_elem, i) += coord(num_som, i) / nb_som_reel;
122 }
123 });
124 end_gpu_timer(__KERNEL_NAME__);
125}
126
127/*! @brief Exits with an error. This method is not pure virtual for convenience.
128 *
129 * @param faces_sommets Vertex indices of the faces.
130 * @param face_normales Array to fill with face normals.
131 */
132template <typename _SIZE_>
133void Elem_geom_base_32_64<_SIZE_>::calculer_normales(const IntTab_t& faces_sommets , DoubleTab_t& face_normales) const
134{
135 Cerr << "calculer_normales method is not coded for an element " << finl;
136 Cerr << "of type que_suis_je() " << finl;
137 exit();
138}
139
140/*! @brief Returns the number of face types of the geometric element.
141 *
142 * For example, a prism (class Prisme) has 2 face types: triangle and quadrangle.
143 *
144 * @return Always returns 1 for this base implementation.
145 */
146template <typename _SIZE_>
148{
149 return 1;
150}
151
152/*! @brief Fills faces_som_local(i,j) giving for 0 <= i < nb_faces() and 0 <= j < nb_som_face(i) the local vertex index on the element.
153 *
154 * We have 0 <= faces_sommets_locaux(i,j) < nb_som().
155 * If faces do not all have the same number of vertices, the number of columns equals the maximum,
156 * and unused entries are set to -1.
157 * Returns 1 if all faces have the same number of vertices, 0 otherwise.
158 *
159 * @param faces_som_local Table to fill with local face-vertex indices.
160 * @return 1 if all faces have the same vertex count, 0 otherwise.
161 */
162template <typename _SIZE_>
164{
165 Cerr << "Elem_geom_base::faces_sommets_locaux : error.\n"
166 << " Method not implemented for the object "
167 << que_suis_je() << finl;
168 exit();
169 return 0;
170}
171
172/*! @brief Same as Elem_geom_base::get_tab_faces_sommets_locaux but for edges: aretes_som_local.
173 *
174 * aretes_som_local.dimension(0) = number of edges on the reference element.
175 * aretes_som_local.dimension(1) = 2 (number of vertices per edge).
176 * aretes_som_local(i,j) = index of a vertex of the element (0 <= n < nb_vertices_per_element).
177 *
178 * @param aretes_som_local Table to fill with local edge-vertex indices.
179 */
180template <typename _SIZE_>
182{
183 Cerr << "Elem_geom_base::aretes_sommets_locaux : error.\n"
184 << " Method not implemented for the object "
185 << que_suis_je() << finl;
186 exit();
187}
188
189
190template class Elem_geom_base_32_64<int>;
191#if INT_is_64_ == 2
193#endif
194
Class Elem_geom_base This class is the base class for the definition of elements.
virtual int face_sommet(int i, int j) const =0
Returns the number of the j-th vertex of the i-th face of the element.
virtual void calculer_normales(const IntTab_t &faces_sommets, DoubleTab_t &face_normales) const
Exits with an error. This method is not pure virtual for convenience.
Faces_32_64< _SIZE_ > Faces_t
virtual int num_face(int face, Type_Face &type) const
Returns the face parameter if the specified face type matches that of the geometric element.
virtual void calculer_centres_gravite(DoubleTab_t &) const
Compute all centers of mass of all elements in the domain.
DoubleTab_T< _SIZE_ > DoubleTab_t
virtual Type_Face type_face(int face_typ=0) const =0
Type of the face of the element - face_typ < nb_type_face().
virtual void creer_faces_elem(Faces_t &, int_t, Type_Face) const
Creates the faces of the specified geometric element of the domain using the given face type.
virtual int nb_type_face() const
Nb of face types of the elemnt (for example 2 for a prism).
virtual int nb_som_face(int=0) const =0
Nb of vertices for one face of the element.
virtual int nb_faces(int=0) const =0
Nb of faces for the element.
virtual int nb_som() const =0
Nb of vertices for the element.
IntTab_T< _SIZE_ > IntTab_t
virtual void get_tab_aretes_sommets_locaux(IntTab &aretes_som_local) const
Same as Elem_geom_base::get_tab_faces_sommets_locaux but for edges: aretes_som_local.
virtual int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const
Fills faces_som_local(i,j) giving for 0 <= i < nb_faces() and 0 <= j < nb_som_face(i) the local verte...
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void associer_domaine(const Domaine_t &z)
Definition Faces.h:94
void completer(int_t face, int_t num_elem)
Completes the specified face: updates its neighbors.
Definition Faces.cpp:458
int_t dimensionner(int_t)
(Re-)sizes the faces. The neighbors are resized accordingly.
Definition Faces.cpp:336
int_t sommet(int_t, int) const
Returns the number of the j-th vertex of the i-th face.
Definition Faces.h:130
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
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
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
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_wo()
Definition TRUSTTab.h:276
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133