TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Prisme.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 <Prisme.h>
17#include <Domaine.h>
18
19// 5
20// /|
21// 3----4
22// | | |
23// | 2 |
24// |/ |
25// 0----1
26
27static int faces_sommets_prisme[5][4] =
28{
29 { 0, 1, 3, 4 },
30 { 0, 2, 3, 5 },
31 { 1, 2, 4, 5 },
32 { 0, 1, 2, -1 },
33 { 3, 4, 5, -1 }
34};
35
36
37Implemente_instanciable_32_64(Prisme_32_64,"Prisme",Elem_geom_base_32_64<_T_>);
38
39template <typename _SIZE_>
41{
42 return s;
43}
44
45template <typename _SIZE_>
47{
48 return s;
49}
50
51
52/*! @brief Reorders the vertices of the Prism.
53 *
54 * DOES NOTHING: TO BE CODED
55 *
56 */
57template <typename _SIZE_>
59{
60 Cerr << "Prisme_32_64<_SIZE_>::reordonner must be coded " << finl;
62 // to be coded: restore conforming node numbering.
63}
64
65
66/*! @brief Returns the LML name of a prism = "PRISM6".
67 *
68 * @return always equal to "PRISM6"
69 */
70template <typename _SIZE_>
72{
73 static Nom nom="PRISM6";
74 return nom;
75}
76
77
78/*! @brief DOES NOTHING: TO BE CODED; always returns 0.
79 *
80 * @brief Returns 1 if element "element" of the domain associated with this geometric element contains the point
81 * with coordinates specified by parameter "pos".
82 * Returns 0 otherwise.
83 *
84 * @param pos coordinates of the point to locate
85 * @param ielem the element index in the domain in which the point is searched.
86 * @return 1 if the point belongs to element "element", 0 otherwise
87 */
88template <typename _SIZE_>
89int Prisme_32_64<_SIZE_>::contient(const ArrOfDouble& pos, int_t ielem ) const
90{
91 // to be coded:
92 // does the prism with element number contain the point with
93 // coordinates pos?
94 // adaptation of the tetrahedron contains method
95 assert(pos.size_array()==3);
96 const Domaine_t& domaine=this->mon_dom.valeur();
97 const Domaine_t& dom=domaine;
98 double prod1,prod2,xn,yn,zn;
99 int_t som0, som1, som2, som3,som4,som5;
100
101 // First check if the sought point is not one of the
102 // vertices of the triangle
103 som0 = domaine.sommet_elem(ielem,0);
104 som1 = domaine.sommet_elem(ielem,1);
105 som2 = domaine.sommet_elem(ielem,2);
106 som3 = domaine.sommet_elem(ielem,3);
107 som4 = domaine.sommet_elem(ielem,4);
108 som5 = domaine.sommet_elem(ielem,5);
109 if( ( est_egal(dom.coord(som0,0),pos[0]) && est_egal(dom.coord(som0,1),pos[1]) && est_egal(dom.coord(som0,2),pos[2]) )
110 || (est_egal(dom.coord(som1,0),pos[0]) && est_egal(dom.coord(som1,1),pos[1]) && est_egal(dom.coord(som1,2),pos[2]))
111 || (est_egal(dom.coord(som2,0),pos[0]) && est_egal(dom.coord(som2,1),pos[1]) && est_egal(dom.coord(som2,2),pos[2]))
112 || (est_egal(dom.coord(som3,0),pos[0]) && est_egal(dom.coord(som3,1),pos[1]) && est_egal(dom.coord(som3,2),pos[2]))
113 || (est_egal(dom.coord(som4,0),pos[0]) && est_egal(dom.coord(som4,1),pos[1]) && est_egal(dom.coord(som4,2),pos[2]))
114 || (est_egal(dom.coord(som5,0),pos[0]) && est_egal(dom.coord(som5,1),pos[1]) && est_egal(dom.coord(som5,2),pos[2]))
115 )
116 return 1;
117
118 for (int j=0; j<5; j++)
119 {
120 switch(j)
121 {
122 case 0 :
123 som0 = domaine.sommet_elem(ielem,0);
124 som1 = domaine.sommet_elem(ielem,1);
125 som2 = domaine.sommet_elem(ielem,3);
126 som3 = domaine.sommet_elem(ielem,2);
127 break;
128 case 1 :
129 som0 = domaine.sommet_elem(ielem,0);
130 som1 = domaine.sommet_elem(ielem,2);
131 som2 = domaine.sommet_elem(ielem,3);
132 som3 = domaine.sommet_elem(ielem,4);
133 break;
134 case 2 :
135 som0 = domaine.sommet_elem(ielem,1);
136 som1 = domaine.sommet_elem(ielem,2);
137 som2 = domaine.sommet_elem(ielem,4);
138 som3 = domaine.sommet_elem(ielem,0);
139 break;
140 case 3 :
141 som0 = domaine.sommet_elem(ielem,0);
142 som1 = domaine.sommet_elem(ielem,1);
143 som2 = domaine.sommet_elem(ielem,2);
144 som3 = domaine.sommet_elem(ielem,3);
145 break;
146 case 4 :
147 som0 = domaine.sommet_elem(ielem,3);
148 som1 = domaine.sommet_elem(ielem,4);
149 som2 = domaine.sommet_elem(ielem,5);
150 som3 = domaine.sommet_elem(ielem,0);
151 break;
152 }
153
154 // Algorithm: vertex 3 and point M must for j=0 to 3 be on the same side
155 // as the plane formed by points som0,som1,som2.
156 // compute the normal to the plane som0,som1,som2:
157 xn = (dom.coord(som1,1)-dom.coord(som0,1))*(dom.coord(som2,2)-dom.coord(som0,2))
158 - (dom.coord(som1,2)-dom.coord(som0,2))*(dom.coord(som2,1)-dom.coord(som0,1));
159 yn = (dom.coord(som1,2)-dom.coord(som0,2))*(dom.coord(som2,0)-dom.coord(som0,0))
160 - (dom.coord(som1,0)-dom.coord(som0,0))*(dom.coord(som2,2)-dom.coord(som0,2));
161 zn = (dom.coord(som1,0)-dom.coord(som0,0))*(dom.coord(som2,1)-dom.coord(som0,1))
162 - (dom.coord(som1,1)-dom.coord(som0,1))*(dom.coord(som2,0)-dom.coord(som0,0));
163 prod1 = xn * ( dom.coord(som3,0) - dom.coord(som0,0) )
164 + yn * ( dom.coord(som3,1) - dom.coord(som0,1) )
165 + zn * ( dom.coord(som3,2) - dom.coord(som0,2) );
166 prod2 = xn * ( pos[0] - dom.coord(som0,0) )
167 + yn * ( pos[1] - dom.coord(som0,1) )
168 + zn * ( pos[2] - dom.coord(som0,2) );
169 // If the point is on the plane (prod2 nearly zero): cannot conclude...
170 if (prod1*prod2 < 0 && std::fabs(prod2)>std::fabs(prod1)*Objet_U::precision_geom) return 0;
171 }
172 return 1;
173}
174
175
176/*! @brief DOES NOTHING: TO BE CODED, always returns 0. Returns 1 if the vertices specified by parameter "pos"
177 *
178 * are the vertices of element "element" of the domain associated with
179 * the geometric element.
180 *
181 * @param (IntVect& pos) the vertex indices to compare with those of element "element"
182 * @param (int element) the index of the domain element whose vertices are to be compared
183 * @return (int) 1 if the vertices passed as parameter are those of the specified element, 0 otherwise
184 */
185template <typename _SIZE_>
187{
188 // to be coded:
190 return 0;
191}
192
193
194/*! @brief DOES NOTHING: TO BE CODED. Computes the volumes of the elements of the associated domain.
195 *
196 * @param (DoubleVect& volumes) the vector containing the volume values of the domain elements
197 */
198template <typename _SIZE_>
200{
201 const Domaine_t& domaine=this->mon_dom.valeur();
202 const IntTab_t& elem=domaine.les_elems();
203 const DoubleTab_t& coord=domaine.coord_sommets();
204 int_t size_tot = domaine.nb_elem_tot();
205 assert(volumes.size_totale()==size_tot);
206 for (int_t num_poly=0; num_poly<size_tot; num_poly++)
207 {
208 int_t i1=elem(num_poly,0),
209 i2=elem(num_poly,1),
210 i3=elem(num_poly,2),
211 i4=elem(num_poly,3),
212 i5=elem(num_poly,4),
213 i6=elem(num_poly,5);
214
215 // retrieved from MEDMEM_Formulae.hxx
216 double a1 = (coord(i2,0)-coord(i3,0))/2.0, a2 = (coord(i2,1)-coord(i3,1))/2.0, a3 = (coord(i2,2)-coord(i3,2))/2.0;
217 double b1 = (coord(i5,0)-coord(i6,0))/2.0, b2 = (coord(i5,1)-coord(i6,1))/2.0, b3 = (coord(i5,2)-coord(i6,2))/2.0;
218 double c1 = (coord(i4,0)-coord(i1,0))/2.0, c2 = (coord(i4,1)-coord(i1,1))/2.0, c3 = (coord(i4,2)-coord(i1,2))/2.0;
219 double d1 = (coord(i5,0)-coord(i2,0))/2.0, d2 = (coord(i5,1)-coord(i2,1))/2.0, d3 = (coord(i5,2)-coord(i2,2))/2.0;
220 double e1 = (coord(i6,0)-coord(i3,0))/2.0, e2 = (coord(i6,1)-coord(i3,1))/2.0, e3 = (coord(i6,2)-coord(i3,2))/2.0;
221 double f1 = (coord(i1,0)-coord(i3,0))/2.0, f2 = (coord(i1,1)-coord(i3,1))/2.0, f3 = (coord(i1,2)-coord(i3,2))/2.0;
222 double h1 = (coord(i4,0)-coord(i6,0))/2.0, h2 = (coord(i4,1)-coord(i6,1))/2.0, h3 = (coord(i4,2)-coord(i6,2))/2.0;
223
224 double A = a1*c2*f3 - a1*c3*f2 - a2*c1*f3 + a2*c3*f1 +
225 a3*c1*f2 - a3*c2*f1;
226 double B = b1*c2*h3 - b1*c3*h2 - b2*c1*h3 + b2*c3*h1 +
227 b3*c1*h2 - b3*c2*h1;
228 double C = (a1*c2*h3 + b1*c2*f3) - (a1*c3*h2 + b1*c3*f2) -
229 (a2*c1*h3 + b2*c1*f3) + (a2*c3*h1 + b2*c3*f1) +
230 (a3*c1*h2 + b3*c1*f2) - (a3*c2*h1 + b3*c2*f1);
231 double D = a1*d2*f3 - a1*d3*f2 - a2*d1*f3 + a2*d3*f1 +
232 a3*d1*f2 - a3*d2*f1;
233 double E = b1*d2*h3 - b1*d3*h2 - b2*d1*h3 + b2*d3*h1 +
234 b3*d1*h2 - b3*d2*h1;
235 double F = (a1*d2*h3 + b1*d2*f3) - (a1*d3*h2 + b1*d3*f2) -
236 (a2*d1*h3 + b2*d1*f3) + (a2*d3*h1 + b2*d3*f1) +
237 (a3*d1*h2 + b3*d1*f2) - (a3*d2*h1 + b3*d2*f1);
238 double G = a1*e2*f3 - a1*e3*f2 - a2*e1*f3 + a2*e3*f1 +
239 a3*e1*f2 - a3*e2*f1;
240 double H = b1*e2*h3 - b1*e3*h2 - b2*e1*h3 + b2*e3*h1 +
241 b3*e1*h2 - b3*e2*h1;
242 double P = (a1*e2*h3 + b1*e2*f3) - (a1*e3*h2 + b1*e3*f2) -
243 (a2*e1*h3 + b2*e1*f3) + (a2*e3*h1 + b2*e3*f1) +
244 (a3*e1*h2 + b3*e1*f2) - (a3*e2*h1 + b3*e2*f1);
245 volumes[num_poly]=std::fabs(-2.0*(2.0*(A + B + D + E + G + H) + C + F + P)/9.0);
246
247 }
248
249}
250
251/*! @brief Fills the array faces_som_local(i,j) giving, for 0 <= i < nb_faces() and 0 <= j < nb_som_face(i), the local vertex index
252 *
253 * on the element.
254 * We have 0 <= faces_sommets_locaux(i,j) < nb_som()
255 * If all faces of the element do not have the same number of vertices, the number
256 * of columns of the array is the largest number of vertices, and the unused entries
257 * of the array are set to -1.
258 * Returns 1 if all faces have the same number of elements, 0 otherwise.
259 *
260 */
261template <typename _SIZE_>
263{
264 faces_som_local.resize(5,4);
265 for (int i=0; i<5; i++)
266 for (int j=0; j<4; j++)
267 faces_som_local(i,j) = faces_sommets_prisme[i][j];
268 return 1;
269}
270
271
272template class Prisme_32_64<int>;
273#if INT_is_64_ == 2
274template class Prisme_32_64<trustIdType>;
275#endif
276
double coord(int_t i, int j) const
Definition Domaine.h:110
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
Class Prisme: represents the geometric element Prism.
Definition Prisme.h:33
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Prisme.h:43
const Nom & nom_lml() const override
Returns the LML name of a prism = "PRISM6".
Definition Prisme.cpp:71
IntTab_T< _SIZE_ > IntTab_t
Definition Prisme.h:40
void reordonner() override
Reorders the vertices of the Prism.
Definition Prisme.cpp:58
void calculer_volumes(DoubleVect_t &vols) const override
DOES NOTHING: TO BE CODED. Computes the volumes of the elements of the associated domain.
Definition Prisme.cpp:199
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Prisme.h:41
Domaine_32_64< _SIZE_ > Domaine_t
Definition Prisme.h:44
_SIZE_ int_t
Definition Prisme.h:39
int contient(const ArrOfDouble &pos, int_t elem) const override
DOES NOTHING: TO BE CODED; always returns 0.
Definition Prisme.cpp:89
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Prisme.h:42
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
Fills the array faces_som_local(i,j) giving, for 0 <= i < nb_faces() and 0 <= j < nb_som_face(i),...
Definition Prisme.cpp:262
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
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61