TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Rectangle.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 <Rectangle.h>
17#include <Domaine.h>
18
19static int faces_sommets_rectangle[4][2] =
20{
21 { 0, 2 },
22 { 0, 1 },
23 { 1, 3 },
24 { 2, 3 }
25};
26
27Implemente_instanciable_32_64(Rectangle_32_64,"Rectangle",Elem_geom_base_32_64<_T_>);
28
29template <typename _SIZE_>
31{
32 return s;
33}
34
35template <typename _SIZE_>
37{
38 return s;
39}
40
41/*! @brief Reorders the vertices of the rectangle.
42 *
43 */
44template <typename _SIZE_>
46{
47 if (reordonner_elem()==-1)
48 {
49 Cerr << "It is expected to treat rectangles but" << finl;
50 Cerr << "one of the elements is not rectangle!" << finl;
51 Cerr << "Check your mesh." << finl;
53 }
54}
55
56/*! @brief Reorders and verifies that the elements are indeed rectangles.
57 */
58template <typename _SIZE_>
60{
61 Domaine_t& domaine=mon_dom.valeur();
62 const Domaine_t& dom=domaine;
63 IntTab_t& elem=domaine.les_elems();
64
65 SmallArrOfTID_t S(4);
66 SmallArrOfTID_t NS(4);
67 DoubleTab co(4,2);
68 int i,j;
69 double xmin, ymin;
70 const int_t nb_elem=domaine.nb_elem();
71 for (int_t num_poly=0; num_poly<nb_elem; num_poly++)
72 {
73 NS=-1;
74 for(i=0; i<4; i++)
75 {
76 S[i] = elem(num_poly,i);
77 for(j=0; j<2; j++)
78 co(i,j) = dom.coord(S[i], j);
79 }
80
81 xmin=std::min(co(0, 0), co(1, 0));
82 xmin=std::min(xmin, co(2, 0));
83 ymin=std::min(co(0, 1), co(1, 1));
84 ymin=std::min(ymin, co(2, 1));
85
86 for(i=0; i<4; i++)
87 if ( est_egal(co(i, 0),xmin) && est_egal(co(i, 1),ymin))
88 NS[0]=S[i];
89 for(i=0; i<4; i++)
90 if ( !est_egal(co(i, 0),xmin) && est_egal(co(i, 1),ymin))
91 NS[1]=S[i];
92 for(i=0; i<4; i++)
93 if ( est_egal(co(i, 0),xmin) && !est_egal(co(i, 1),ymin))
94 NS[2]=S[i];
95 for(i=0; i<4; i++)
96 if ( !est_egal(co(i, 0),xmin) && !est_egal(co(i, 1),ymin))
97 NS[3]=S[i];
98
99 // If a vertex is -1, this is not a Rectangle!
100 if (min_array(NS)==-1)
101 {
102 Cerr << "The element " << num_poly << " is not a rectangle." << finl;
103 return -1;
104 }
105 // Otherwise fill elem
106 for(i=0; i<4; i++)
107 elem(num_poly, i)=NS[i];
108 }
109 return 0;
110}
111
112/*! @brief Returns the LML name of a rectangle = "VOXEL8".
113 *
114 * @return (Nom&) always equal to "VOXEL8"
115 */
116template <typename _SIZE_>
118{
119 static Nom nom="VOXEL8";
120 if (dimension==3) nom="QUADRANGLE_3D";
121 return nom;
122}
123
124
125/*! @brief Returns 1 if element ielem of the domain associated with the geometric element contains the point
126 *
127 * with coordinates specified by parameter "pos".
128 * Returns 0 otherwise.
129 *
130 * @param (DoubleVect& pos) coordinates of the point to locate
131 * @param (int ielem) the index of the domain element in which the point is searched.
132 * @return (int) 1 if the point with specified coordinates belongs to element ielem, 0 otherwise
133 */
134template <typename _SIZE_>
135int Rectangle_32_64<_SIZE_>::contient(const ArrOfDouble& pos, int_t element ) const
136{
137 assert(pos.size_array()==2);
138 const Domaine_t& dom=mon_dom.valeur();
139 int_t som0 = dom.sommet_elem(element,0),
140 som3 = dom.sommet_elem(element,3);
141 if ( inf_ou_egal(dom.coord(som0,0),pos[0]) && inf_ou_egal(pos[0],dom.coord(som3,0))
142 && inf_ou_egal(dom.coord(som0,1),pos[1]) && inf_ou_egal(pos[1],dom.coord(som3,1)) )
143 return 1;
144 else
145 return 0;
146}
147
148/*! @brief Returns 1 if the vertices specified by parameter "pos" are the vertices of element "element" of the domain associated with
149 *
150 * the geometric element.
151 *
152 * @param (IntVect& pos) the vertex indices to compare with those of element "element"
153 * @param (int element) the index of the domain element whose vertices are to be compared
154 * @return (int) 1 if the vertices passed as parameter are those of the specified element, 0 otherwise
155 */
156template <typename _SIZE_>
158{
159 const Domaine_t& domaine=mon_dom.valeur();
160 if((domaine.sommet_elem(element,0)==som[0])&&
161 (domaine.sommet_elem(element,1)==som[1])&&
162 (domaine.sommet_elem(element,2)==som[2])&&
163 (domaine.sommet_elem(element,3)==som[3]))
164 return 1;
165 else
166 return 0;
167}
168
169
170/*! @brief Computes the volumes of the elements of the associated domain.
171 *
172 * @param (DoubleVect& volumes) the vector containing the volume values of the domain elements
173 */
174template <typename _SIZE_>
176{
177 if (dimension==3)
178 {
179 Cerr << "Rectangle_32_64<_SIZE_>::calculer_volumes is not supported for 3D yet." << finl;
181 }
182 const Domaine_t& dom=mon_dom.valeur();
183 double dx,dy;
184 int_t S1,S2,S3;
185
186 int_t size_tot = dom.nb_elem_tot();
187 assert(volumes.size_totale()==size_tot);
188 for (int_t num_poly=0; num_poly<size_tot; num_poly++)
189 {
190 S1 = dom.sommet_elem(num_poly,0);
191 S2 = dom.sommet_elem(num_poly,1);
192 S3 = dom.sommet_elem(num_poly,2);
193 dx = dom.coord(S2,0) - dom.coord(S1,0);
194 dy = dom.coord(S3,1) - dom.coord(S1,1);
195 volumes[num_poly]= dx*dy;
196 }
197}
198
199
200/*! @brief Computes the normals to the faces of the elements of the associated domain.
201 *
202 * @param (IntTab& face_sommets) the vertex indices of the faces in the vertex list of the associated domain
203 * @param (DoubleTab& face_normales)
204 */
205template <typename _SIZE_>
206void Rectangle_32_64<_SIZE_>::calculer_normales(const IntTab_t& Face_sommets, DoubleTab_t& face_normales) const
207{
208 const Domaine_t& domaine_geom = mon_dom.valeur();
209 const DoubleTab_t& les_coords = domaine_geom.coord_sommets();
210 int_t nbfaces = Face_sommets.dimension(0);
211 double x1,y1;
212 int_t n0,n1;
213 for (int_t numface=0; numface<nbfaces; numface++)
214 {
215 n0 = Face_sommets(numface,0);
216 n1 = Face_sommets(numface,1);
217 x1 = les_coords(n0,0) - les_coords(n1,0);
218 y1 = les_coords(n0,1) - les_coords(n1,1);
219 face_normales(numface,0) = -y1;
220 face_normales(numface,1) = x1;
221 }
222}
223
224/*! @brief voir ElemGeomBase::get_tab_faces_sommets_locaux
225 *
226 */
227template <typename _SIZE_>
229{
230 faces_som_local.resize(4,2);
231 for (int i=0; i<4; i++)
232 for (int j=0; j<2; j++)
233 faces_som_local(i,j) = faces_sommets_rectangle[i][j];
234 return 1;
235}
236
237
238template class Rectangle_32_64<int>;
239#if INT_is_64_ == 2
240template class Rectangle_32_64<trustIdType>;
241#endif
242
int_t nb_elem_tot() const
Definition Domaine.h:132
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
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
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
Rectangle class — represents the rectangular geometric element.
Definition Rectangle.h:31
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Rectangle.h:39
void calculer_normales(const IntTab_t &faces_sommets, DoubleTab_t &face_normales) const override
Computes the normals to the faces of the elements of the associated domain.
const Nom & nom_lml() const override
Returns the LML name of a rectangle = "VOXEL8".
static int dimension
Definition Objet_U.h:94
void calculer_volumes(DoubleVect_t &vols) const override
Computes the volumes of the elements of the associated domain.
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
voir ElemGeomBase::get_tab_faces_sommets_locaux
int reordonner_elem()
Reorders and verifies that the elements are indeed rectangles.
Definition Rectangle.cpp:59
int contient(const ArrOfDouble &pos, int_t elem) const override
Returns 1 if element ielem of the domain associated with the geometric element contains the point.
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Rectangle.h:38
Domaine_32_64< _SIZE_ > Domaine_t
Definition Rectangle.h:41
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Rectangle.h:40
void reordonner() override
Reorders the vertices of the rectangle.
Definition Rectangle.cpp:45
IntTab_T< _SIZE_ > IntTab_t
Definition Rectangle.h:37
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