TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Triangle.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <Triangle.h>
17#include <Domaine.h>
18
19Implemente_instanciable_32_64(Triangle_32_64,"Triangle",Elem_geom_base_32_64<_T_>);
20
21/*! @brief Faces of the reference triangle: 3 faces of two vertices each.
22 *
23 * Face i is the face opposite to vertex i
24 * (see get_tab_faces_sommets_locaux).
25 *
26 */
27static int faces_sommets_triangle[3][2] =
28{
29 { 1, 2 },
30 { 2, 0 },
31 { 0, 1 }
32};
33
34template <typename _SIZE_>
36{
37 return s;
38}
39
40template <typename _SIZE_>
42{
43 return s;
44}
45
46
47/*! @brief Returns the LML name of a triangle = "PRISM6".
48 *
49 * @return Always equal to "PRISM6" (or "TRIANGLE_3D" in 3D).
50 */
51template <typename _SIZE_>
53{
54 static Nom nom="PRISM6";
55 if (dimension==3) nom="TRIANGLE_3D";
56 return nom;
57}
58
59
60/*! @brief Returns 1 if element "ielem" of the domain associated with this geometric element contains the point
61 *
62 * with coordinates specified by "pos". Returns 0 otherwise.
63 *
64 * @param pos Coordinates of the point to locate.
65 * @param ielem Index of the domain element in which to search for the point.
66 * @return 1 if the point belongs to element "ielem", 0 otherwise.
67 */
68template <typename _SIZE_>
69int Triangle_32_64<_SIZE_>::contient(const ArrOfDouble& pos, int_t ielem) const
70{
71 assert(pos.size_array()==2);
72 const Domaine_t& dom=this->mon_dom.valeur();
73 assert(ielem<dom.nb_elem_tot());
74 int_t som0 = dom.sommet_elem(ielem,0);
75 int_t som1 = dom.sommet_elem(ielem,1);
76 int_t som2 = dom.sommet_elem(ielem,2);
77 assert((som0>=0) && (som0<dom.nb_som_tot()));
78 assert((som1>=0) && (som1<dom.nb_som_tot()));
79 assert((som2>=0) && (som2<dom.nb_som_tot()));
80 double prod,p0,p1,p2;
81
82 // First check if the point is one of the triangle vertices.
83 // GF: this test is removed to be consistent with Tetraedre::contient and to avoid issues in Champ_implementation_P1::form_function, which does not have this test.
84 /*
85 if( (est_egal(dom.coord(som0,0),pos(0)) && est_egal(dom.coord(som0,1),pos(1)))
86 || (est_egal(dom.coord(som1,0),pos(0)) && est_egal(dom.coord(som1,1),pos(1)))
87 || (est_egal(dom.coord(som2,0),pos(0)) && est_egal(dom.coord(som2,1),pos(1))) )
88 return 1;
89
90 */
91 // Note: vertices are stored in arbitrary order.
92 // Determine the orientation (counter-clockwise or clockwise) for the vertex numbering:
93 // Compute prod = 01 cross 02 along z
94 // prod > 0 : counter-clockwise
95 // prod < 0 : clockwise
96 prod = (dom.coord(som1,0)-dom.coord(som0,0))*(dom.coord(som2,1)-dom.coord(som0,1))
97 - (dom.coord(som1,1)-dom.coord(som0,1))*(dom.coord(som2,0)-dom.coord(som0,0));
98 double signe;
99 if (prod >= 0)
100 signe = 1;
101 else
102 signe = -1;
103 // Compute p0 = 0M cross 1M along z
104 p0 = (pos[0]-dom.coord(som0,0))*(pos[1]-dom.coord(som1,1))
105 - (pos[1]-dom.coord(som0,1))*(pos[0]-dom.coord(som1,0));
106 p0 *= signe;
107 // Compute p1 = 1M cross 2M along z
108 p1 = (pos[0]-dom.coord(som1,0))*(pos[1]-dom.coord(som2,1))
109 - (pos[1]-dom.coord(som1,1))*(pos[0]-dom.coord(som2,0));
110 p1 *= signe;
111 // Compute p2 = 2M cross 0M along z
112 p2 = (pos[0]-dom.coord(som2,0))*(pos[1]-dom.coord(som0,1))
113 - (pos[1]-dom.coord(som2,1))*(pos[0]-dom.coord(som0,0));
114 p2 *= signe;
115 double epsilon=std::fabs(prod)*Objet_U::precision_geom;
116 if ((p0>-epsilon) && (p1>-epsilon) && (p2>-epsilon))
117 return 1;
118 else
119 return 0;
120}
121
122
123/*! @brief Returns 1 if the vertices specified by "som" are the vertices of element "element"
124 *
125 * in the domain associated with this geometric element. Returns 0 otherwise.
126 *
127 * @param som Vertex indices to compare with those of element "element".
128 * @param element Index of the domain element whose vertices are to be compared.
129 * @return 1 if the specified vertices are those of the given element, 0 otherwise.
130 */
131template <typename _SIZE_>
133{
134 const Domaine_t& domaine=this->mon_dom.valeur();
135 if((domaine.sommet_elem(element,0)==som[0])&&
136 (domaine.sommet_elem(element,1)==som[1])&&
137 (domaine.sommet_elem(element,2)==som[2]))
138 return 1;
139 else
140 return 0;
141}
142
143/*! @brief Computes the volumes (areas) of the elements of the associated domain.
144 *
145 * @param volumes Vector to fill with the volumes of domain elements.
146 */
147template <typename _SIZE_>
149{
150 const Domaine_t& domaine=this->mon_dom.valeur();
151 const DoubleTab_t& coord = domaine.coord_sommets();
152 DoubleTab pos(3,dimension);
153 int_t size_tot = domaine.nb_elem_tot();
154 assert(volumes.size_totale()==size_tot);
155 for (int_t num_poly=0; num_poly<size_tot; num_poly++)
156 {
157 for (int i=0; i<3; i++)
158 {
159 int_t Si = domaine.sommet_elem(num_poly,i);
160 for (int j=0; j<dimension; j++)
161 pos(i,j) = coord(Si,j);
162 }
163 volumes[num_poly] = aire_triangle(pos);
164 }
165}
166
167/*! @brief Computes the face normals of the elements of the associated domain.
168 *
169 * @param Face_sommets Vertex indices of the faces in the domain vertex list.
170 * @param face_normales Output array to fill with face normals.
171 */
172template <typename _SIZE_>
173void Triangle_32_64<_SIZE_>::calculer_normales(const IntTab_t& Face_sommets, DoubleTab_t& face_normales) const
174{
175 const Domaine_t& domaine_geom = this->mon_dom.valeur();
176 const DoubleTab_t& les_coords = domaine_geom.coord_sommets();
177 int_t nbfaces = Face_sommets.dimension(0);
178 double x1,y1;
179 int_t n0,n1;
180 for (int_t numface=0; numface<nbfaces; numface++)
181 {
182 n0 = Face_sommets(numface,0);
183 n1 = Face_sommets(numface,1);
184 x1 = les_coords(n0,0)-les_coords(n1,0);
185 y1 = les_coords(n0,1)-les_coords(n1,1);
186 face_normales(numface,0) = -y1;
187 face_normales(numface,1) = x1;
188 }
189}
190
191/*! @brief See ElemGeomBase::get_tab_faces_sommets_locaux.
192 *
193 */
194template <typename _SIZE_>
196{
197 faces_som_local.resize(3,2);
198 for (int i=0; i<3; i++)
199 for (int j=0; j<2; j++)
200 faces_som_local(i,j) = faces_sommets_triangle[i][j];
201 return 1;
202}
203
204
205template class Triangle_32_64<int>;
206#if INT_is_64_ == 2
207template class Triangle_32_64<trustIdType>;
208#endif
209
int_t nb_elem_tot() const
Definition Domaine.h:132
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
int_t nb_som_tot() const
Returns the total number of vertices of the domain i.e. the number of real and virtual vertices on th...
Definition Domaine.h:123
double coord(int_t i, int j) const
Definition Domaine.h:110
int_t sommet_elem(int_t i, int j) const
Returns the (global) number of the j-th vertex of the i-th element.
Definition Domaine.h:136
Class Elem_geom_base This class is the base class for the definition of elements.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static double precision_geom
Definition Objet_U.h:81
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
Class Triangle: represents the geometric element Triangle.
Definition Triangle.h:31
Domaine_32_64< _SIZE_ > Domaine_t
Definition Triangle.h:42
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Triangle.h:39
IntTab_T< _SIZE_ > IntTab_t
Definition Triangle.h:38
static int dimension
Definition Objet_U.h:94
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
See ElemGeomBase::get_tab_faces_sommets_locaux.
Definition Triangle.cpp:195
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Triangle.h:40
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Triangle.h:41
void calculer_normales(const IntTab_t &faces_sommets, DoubleTab_t &face_normales) const override
Computes the face normals of the elements of the associated domain.
Definition Triangle.cpp:173
void calculer_volumes(DoubleVect_t &vols) const override
Computes the volumes (areas) of the elements of the associated domain.
Definition Triangle.cpp:148
_SIZE_ int_t
Definition Triangle.h:37
int contient(const ArrOfDouble &pos, int_t elem) const override
Returns 1 if element "ielem" of the domain associated with this geometric element contains the point.
Definition Triangle.cpp:69
const Nom & nom_lml() const override
Returns the LML name of a triangle = "PRISM6".
Definition Triangle.cpp:52