TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Polygone.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <TRUSTList.h>
17#include <Polygone.h>
18#include <Triangle.h>
19#include <Domaine.h>
20#include <Polygon_geom_tools.h>
21#include <algorithm>
22
23Implemente_instanciable_sans_constructeur_32_64(Polygone_32_64,"Polygone",Poly_geom_base_32_64<_T_>);
24
25template <typename _SIZE_>
34
35template <typename _SIZE_>
37{
38 s<< FacesIndex_ <<finl;
39 s<< PolygonIndex_ <<finl;
40 s<< nb_som_elem_max_ <<finl;
41 s<< nb_face_elem_max_ <<finl;
42 WARN;
43 return s;
44}
45
46template <typename _SIZE_>
48{
49 s>>FacesIndex_;
50 s>>PolygonIndex_;
51 s>>nb_som_elem_max_;
52 s>>nb_face_elem_max_;
53 return s;
54}
55
56
57template <typename _SIZE_>
59{
60 const IntTab_t& les_elems = mon_dom->les_elems();
61 int_t nb_elem = les_elems.dimension_tot(0);
62 ArrOfInt_t PolygonIndex_OK(nb_elem+1);
63 PolygonIndex_OK[0]=0;
64 for (int_t ele=0; ele<nb_elem; ele++)
65 {
66 int nbf=get_nb_som_elem_max();
67 while (les_elems(ele,nbf-1)<0)
68 nbf--;
69 PolygonIndex_OK[ele+1]= PolygonIndex_OK[ele]+nbf;
70 }
71 ArrOfInt_t FacesIndex_OK(PolygonIndex_OK[nb_elem]);
72 int_t f=0;
73 for (int_t ele=0; ele<nb_elem; ele++)
74 for (int ss=0; ss<(int)(PolygonIndex_OK[ele+1]-PolygonIndex_OK[ele]); ss++) // yes, difference of long giving an int, hence the cast -> face size
75 FacesIndex_OK[f++]= les_elems(ele,ss);
76
77 assert(f==PolygonIndex_OK[nb_elem]);
78
79 FacesIndex_=FacesIndex_OK;
80 PolygonIndex_=PolygonIndex_OK;
81}
82
83/* Build a reduced version of the polytope connectivity when splitting domains in DomainCutter - this always produce
84 * a 32b object:
85 */
86template <typename _SIZE_>
87void Polygone_32_64<_SIZE_>::build_reduced(OWN_PTR(Elem_geom_base_32_64<int>)& type_elem, const ArrOfInt_t& elems_sous_part) const
88{
89 type_elem.typer("Polygone");
90 Polygone_32_64<int>& reduced = ref_cast(Polygone_32_64<int>, type_elem.valeur());
93
94 const IntTab_t& les_elems = mon_dom->les_elems();
95 ArrOfInt& Pi = reduced.PolygonIndex_, &Fi = reduced.FacesIndex_;
96 Fi.resize(0);
97
98 for (int_t i = 0; i < elems_sous_part.size_array(); i++)
99 {
100 int_t e = elems_sous_part[i];
101 for (int_t f = PolygonIndex_[e]; f < PolygonIndex_[e + 1]; f++)
102 {
103 int nf = static_cast<int>(f - PolygonIndex_[e]); // num of faces always an int
104 // The below is not necessary (contrarly to what's done for polyedrons) since get_tab_faces_sommets_locaux() below only uses Pi
105// Fi.append_array(les_elems(e, nf));
106 Fi.append_array(les_elems(e, nf) > 0 ? 1 : -1);
107 }
108 Pi.append_array(Fi.size_array()); // this is what will be used by get_tab_faces_sommets_locaux()
109 }
110}
111
112
113template <typename _SIZE_>
118
119
120template <typename _SIZE_>
122{
123 return PolygonIndex_[mon_dom->nb_elem()];
124}
125
126template <typename _SIZE_>
128{
129 if (nb_som_elem_max_>-1)
130 return nb_som_elem_max_ ;
131 else
132 return mon_dom->les_elems().dimension_int(1);
133}
134
135/*! @brief Renvoie le nom LML d'un polyedre = "POLYEDRE_"+nb_som_max.
136 *
137 * @return (Nom&) toujours egal a "PRISM6"
138 */
139template <typename _SIZE_>
141{
142 static Nom nom;
143 nom="POLYEDRE_";
145 if (dimension==3) nom="POLYGONE_";
146 if (dimension==3) n=Nom(get_nb_som_elem_max());
147 nom+=n;
148 return nom;
149}
150
151
152// ToDo a mettre dans triangle
153template <typename _SIZE_>
154int contient_triangle(const ArrOfDouble& pos, _SIZE_ som0, _SIZE_ som1, _SIZE_ som2, const TRUSTTab<double, _SIZE_>& coord)
155{
156 double prod,p0,p1,p2;
157
158 // Il faut donc determiner le sens (trigo ou anti trigo) pour la numerotation :
159 // Calcul de prod = 01 vectoriel 02 selon z
160 // prod > 0 : sens trigo
161 // prod < 0 : sens anti trigo
162 prod = (coord(som1,0)-coord(som0,0))*(coord(som2,1)-coord(som0,1))
163 - (coord(som1,1)-coord(som0,1))*(coord(som2,0)-coord(som0,0));
164 double signe;
165 if (prod >= 0)
166 signe = 1;
167 else
168 signe = -1;
169 // Calcul de p0 = 0M vectoriel 1M selon z
170 p0 = (pos[0]-coord(som0,0))*(pos[1]-coord(som1,1))
171 - (pos[1]-coord(som0,1))*(pos[0]-coord(som1,0));
172 p0 *= signe;
173 // Calcul de p1 = 1M vectoriel 2M selon z
174 p1 = (pos[0]-coord(som1,0))*(pos[1]-coord(som2,1))
175 - (pos[1]-coord(som1,1))*(pos[0]-coord(som2,0));
176 p1 *= signe;
177 // Calcul de p2 = 2M vectoriel 0M selon z
178 p2 = (pos[0]-coord(som2,0))*(pos[1]-coord(som0,1))
179 - (pos[1]-coord(som2,1))*(pos[0]-coord(som0,0));
180 p2 *= signe;
181 double epsilon=std::fabs(prod)*Objet_U::precision_geom;
182 if ((p0>-epsilon) && (p1>-epsilon) && (p2>-epsilon))
183 return 1;
184 else
185 return 0;
186}
187
188/*! @brief NE FAIT RIEN: A CODER, renvoie toujours 0.
189 *
190 * Renvoie 1 si l'element "element" du domaine associe a
191 * l'element geometrique contient le point
192 * de coordonnees specifiees par le parametre "pos".
193 * Renvoie 0 sinon.
194 *
195 * @param (DoubleVect& pos) coordonnees du point que l'on cherche a localiser
196 * @param (int element) le numero de l'element du domaine dans lequel on cherche le point.
197 * @return (int) 1 si le point de coordonnees specifiees appartient a l'element "element" 0 sinon
198 */
199template <typename _SIZE_>
200int Polygone_32_64<_SIZE_>::contient(const ArrOfDouble& pos_r, int_t num_poly ) const
201{
202 const Domaine_t& domaine=mon_dom.valeur();
203 const IntTab_t& elem=domaine.les_elems();
204 const DoubleTab_t& coord=domaine.coord_sommets();
205 //DoubleTab pos(3,dimension);
206 // on decoupe le polygone en triangle ayany tous le sommet 0.
207
208 int_t s0=elem(num_poly,0);
209 for (int s=1; s<nb_som_elem_max_-1 ; s++)
210 {
211 int_t s1=elem(num_poly,s);
212 int_t s2=elem(num_poly,s+1);
213 if (s2<0)
214 break;
215
216 if (contient_triangle(pos_r,s0,s1,s2,coord))
217 return 1;
218 }
219
220 return 0;
221}
222
223
224/*! @brief NE FAIT RIEN: A CODER, renvoie toujours 0 Renvoie 1 si les sommets specifies par le parametre "pos"
225 *
226 * sont les sommets de l'element "element" du domaine associe a
227 * l'element geometrique.
228 *
229 * @param (IntVect& pos) les numeros des sommets a comparer avec ceux de l'elements "element"
230 * @param (int element) le numero de l'element du domaine dont on veut comparer les sommets
231 * @return (int) 1 si les sommets passes en parametre sont ceux de l'element specifie, 0 sinon
232 */
233template <typename _SIZE_>
235{
236 BLOQUE;
237 return 0;
238}
239
240
241/*! @brief NE FAIT RIEN: A CODER Calcule les volumes des elements du domaine associe.
242 *
243 * @param (DoubleVect& volumes) le vecteur contenant les valeurs des des volumes des elements du domaine
244 */
245template <typename _SIZE_>
247{
248 const Domaine_t& domaine = mon_dom.valeur();
249 const IntTab_t& elem = domaine.les_elems();
250 const DoubleTab_t& coord = domaine.coord_sommets();
251 int_t size = domaine.nb_elem();
252
253 assert(volumes.size_totale()==domaine.nb_elem_tot());
254
255 for (int_t num_poly = 0; num_poly < size; num_poly++)
256 {
257 // Determine the actual number of vertices for this polygon (terminated by -1)
258 int nbsom = 0;
259 const int nbsom_max = get_nb_som_elem_max();
260 while (nbsom < nbsom_max && elem(num_poly, nbsom) >= 0) nbsom++;
261 if (nbsom < 3)
262 {
263 volumes(num_poly) = 0.;
264 continue;
265 }
266
267 const auto index_of = [&](int i) -> int_t { return elem(num_poly, i); };
268 const Polygon_geom_data geom = compute_polygon_geom(coord, dimension, nbsom, index_of, Objet_U::bidim_axi);
269
271 volumes(num_poly) = geom.area_;
272 else
273 volumes(num_poly) = 2.0 * M_PI * std::fabs(geom.moment_r_);
274 }
275
276 volumes.echange_espace_virtuel();
277 return;
278}
279
280/*! @brief remplit le tableau faces_som_local(i,j)
281 *
282 * Celui-ci donne pour 0 <= i < nb_faces() et 0 <= j < nb_som_face(i) le numero local du sommet
283 * sur l'element.
284 *
285 * On a 0 <= faces_sommets_locaux(i,j) < nb_som()
286 *
287 * Si toutes les faces de l'element n'ont pas le meme nombre de sommets, le nombre
288 * de colonnes du tableau est le plus grand nombre de sommets, et les cases inutilisees
289 * du tableau sont mises a -1
290 * On renvoie 1 si toutes les faces ont le meme nombre d'elements, 0 sinon.
291 */
292template <typename _SIZE_>
294{
295 return 0;
296}
297
298template <typename _SIZE_>
300{
301 faces_som_local.resize(nb_face_elem_max_,nb_som_face());
302 faces_som_local=-1;
303
304 // on cherche les faces de l'elt
305 int nb_face = static_cast<int>(PolygonIndex_[ele+1]-PolygonIndex_[ele]); // always within int
306
307 // [ABN] Duh?! always assume consecutive connectivity??
308 for (int fl=0; fl<nb_face-1; fl++)
309 {
310 faces_som_local(fl,0)=fl;
311 faces_som_local(fl,1)=fl+1;
312 }
313
314 // Last face:
315 int fl=nb_face-1;
316 faces_som_local(fl,0)=fl;
317 faces_som_local(fl,1)=0;
318
319 return 1;
320}
321
322// Desctiption : a partir des tableaux d'indirection FacesIndex PolygonIndex
323// on calcul les elems, nb_som_face_max_, nb_face_elem_max_ nb_som_elem_max_
324template <typename _SIZE_>
326{
328 // detremination de nbsom_max
331 int_t nelem=PolygonIndex.size_array()-1;
332 for (int_t ele=0; ele<nelem; ele++)
333 {
334 prov.vide();
335 int_t nbf=PolygonIndex[ele+1]-PolygonIndex[ele];
336 if (nbf>nb_face_elem_max_) nb_face_elem_max_=(int)nbf;
337 for (int_t f=PolygonIndex[ele]; f<PolygonIndex[ele+1]; f++)
338 prov.add_if_not(FacesIndex[f]);
339 int nbsom=prov.size();
340 if (nbsom>nb_som_elem_max_) nb_som_elem_max_=nbsom;
341 }
344 Cerr<<" Polygon information nb_som_elem_max "<< nb_som_elem_max_<<" nb_face_elem_max "<<nb_face_elem_max_<<finl;
345 les_elems.resize(nelem,nb_som_elem_max_);
346 les_elems=-1;
347 // on refait un tour pour determiiner les elems
348 for (int_t ele=0; ele<nelem; ele++)
349 {
350 prov.vide();
351 for (int_t f=PolygonIndex[ele]; f<PolygonIndex[ele+1]; f++)
352 prov.add_if_not(FacesIndex[f]);
353 int nbsom=prov.size();
354 for (int s=0; s<nbsom; s++)
355 les_elems(ele,s)=prov[s];
356 }
357 FacesIndex_=FacesIndex;
358 PolygonIndex_=PolygonIndex;
360}
361
362
363template <typename _SIZE_>
365{
366 const Domaine_t& domaine=mon_dom.valeur();
367 const IntTab_t& elem=domaine.les_elems();
368 const DoubleTab_t& coord=domaine.coord_sommets();
369 int_t nb_elem;
370 if(xp.dimension(0)==0)
371 {
372 nb_elem = mon_dom->nb_elem_tot();
373 xp.resize(nb_elem,dimension);
374 }
375 else
376 nb_elem=xp.dimension(0);
377
378 xp=0;
379 DoubleTab pos(3,dimension);
380 ArrOfDouble xpl(dimension);
381 for (int_t num_poly=0; num_poly<nb_elem; num_poly++)
382 {
383 double aire=0;
384 xpl=0;
385 int_t s0=elem(num_poly,0);
386 for (int d=0; d<dimension; d++)
387 pos(0,d)=coord(s0,d);
388 for (int s=1; s<get_nb_som_elem_max()-1 ; s++)
389 {
390 int_t s1=elem(num_poly,s);
391 int_t s2=elem(num_poly,s+1);
392 if (s2<0)
393 break;
394 for (int d=0; d<dimension; d++)
395 {
396 pos(1,d)=coord(s1,d);
397 pos(2,d)=coord(s2,d);
398 }
399 double airel = aire_triangle(pos);
400 for (int d=0; d<dimension; d++)
401 xpl[d]+=airel*(pos(0,d)+pos(1,d)+pos(2,d));
402 aire+=airel;
403 }
404 aire*=3.;
405 for (int d=0; d<dimension; d++)
406 xp(num_poly,d)=xpl[d]/(aire);
407 }
408}
409
410template <typename _SIZE_>
411void Polygone_32_64<_SIZE_>::calculer_un_centre_gravite(const int_t num_poly,DoubleVect& xp) const
412{
413 const Domaine_t& domaine=mon_dom.valeur();
414 const IntTab_t& elem=domaine.les_elems();
415 const DoubleTab_t& coord=domaine.coord_sommets();
416 xp.resize(dimension);
417
418 xp=0;
419 DoubleTab pos(3,dimension);
420 ArrOfDouble xpl(dimension);
421 {
422 double aire=0;
423 xpl=0;
424 int_t s0=elem(num_poly,0);
425 for (int d=0; d<dimension; d++)
426 pos(0,d)=coord(s0,d);
427 for (int s=1; s<nb_som_elem_max_-1 ; s++)
428 {
429 int_t s1=elem(num_poly,s);
430 int_t s2=elem(num_poly,s+1);
431 if (s2<0)
432 break;
433 for (int d=0; d<dimension; d++)
434 {
435 pos(1,d)=coord(s1,d);
436 pos(2,d)=coord(s2,d);
437 }
438 double airel = aire_triangle(pos);
439 for (int d=0; d<dimension; d++)
440 xpl[d]+=airel*(pos(0,d)+pos(1,d)+pos(2,d));
441 aire+=airel;
442 }
443 aire*=3.;
444 for (int d=0; d<dimension; d++)
445 xp(d)=xpl[d]/(aire);
446 }
447}
448
449
450
451template class Polygone_32_64<int>;
452#if INT_is_64_ == 2
453template class Polygone_32_64<trustIdType>;
454#endif
Classe Elem_geom_base Cette classe est la classe de base pour la definition d'elements.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
static double precision_geom
Definition Objet_U.h:86
static int bidim_axi
Definition Objet_U.h:102
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Base class for polyedrons and polygons. Connectivity is stored in descending mode:
Classe Polygone Cette represente l'element geometrique Polygone.
Definition Polygone.h:29
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
remplit le tableau faces_som_local(i,j)
Definition Polygone.cpp:293
_SIZE_ get_somme_nb_faces_elem() const override
Definition Polygone.cpp:121
void build_reduced(OWN_PTR(Elem_geom_base_32_64< int >)&type_elem, const ArrOfInt_t &elems_sous_part) const override
Definition Polygone.cpp:87
friend class Polygone_32_64
Definition Polygone.h:35
Domaine_32_64< _SIZE_ > Domaine_t
Definition Polygone.h:43
void calculer_un_centre_gravite(const int_t elem, DoubleVect &xp) const override
Definition Polygone.cpp:411
static int dimension
Definition Objet_U.h:99
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Definition Polygone.h:38
void calculer_centres_gravite(DoubleTab_t &xp) const override
Compute all centers of mass of all elements in the domain.
Definition Polygone.cpp:364
void calculer_volumes(DoubleVect_t &vols) const override
NE FAIT RIEN: A CODER Calcule les volumes des elements du domaine associe.
Definition Polygone.cpp:246
int get_nb_som_elem_max() const
Definition Polygone.cpp:127
int nb_som_face(int=0) const override
Renvoie le nombre maximum de sommets des faces du type specifie.
Definition Polygone.h:144
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Polygone.h:40
ArrOfInt_t PolygonIndex_
Definition Polygone.h:87
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Polygone.h:42
void affecte_connectivite_numero_global(const ArrOfInt_t &FacesIndex, const ArrOfInt_t &PolygonIndex, IntTab_t &les_elems)
Definition Polygone.cpp:325
_SIZE_ int_t
Definition Polygone.h:37
void compute_virtual_index() override
Definition Polygone.cpp:114
IntTab_T< _SIZE_ > IntTab_t
Definition Polygone.h:39
int contient(const ArrOfDouble &pos, int_t elem) const override
NE FAIT RIEN: A CODER, renvoie toujours 0.
Definition Polygone.cpp:200
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Polygone.h:41
const Nom & nom_lml() const override
Renvoie le nom LML d'un polyedre = "POLYEDRE_"+nb_som_max.
Definition Polygone.cpp:140
void rebuild_index()
Definition Polygone.cpp:58
static double mp_max(double)
Definition Process.cpp:376
Classe de base des flux de sortie.
Definition Sortie.h:52
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
void resize(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTArray.h:156
: Classe qui sert a representer une liste de reels int/double precision.
Definition TRUSTList.h:33
TRUSTList & add_if_not(_TYPE_)
Ajout d'un element a la liste ssi il n'existe pas deja.
void vide()
Vide la liste.
int size() const
Definition TRUSTList.h:68
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31
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
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")