TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Octree.h
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#ifndef Octree_included
17#define Octree_included
18
19#include <TRUSTTabs_forward.h>
20#include <TRUST_Ref.h>
21#include <TRUSTTab.h>
22
23#include <Domaine_forward.h>
24
25// TODO should be a class enum
26#define GaucheArriereBas 0
27#define DroitArriereBas 1
28#define GaucheAvantBas 2
29#define DroitAvantBas 3
30#define GaucheArriereHaut 4
31#define DroitArriereHaut 5
32#define GaucheAvantHaut 6
33#define DroitAvantHaut 7
34
35/*! @brief Struct OctreeLoc
36 *
37 * @sa Octree
38 */
40{
41 double xmin, xmax, ymin, ymax, zmin, zmax;
42 void construire(const OctreeLoc& loc, int i);
43 void construire(const OctreeLoc& loc, int i, double xmil, double ymil, double zmil);
44 int direction(double x, double y, double z) const;
45};
46
47
48/*! @brief Classe Octree
49 *
50 * @sa OctreeLoc OctreeRoot OctreeFloor
51 */
52template <typename _SIZE_>
54{
55public :
56 using int_t = _SIZE_;
57 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
58 using SmallArrOfTID_t = SmallArrOfTID_T<_SIZE_>;
59 using IntTab_t = IntTab_T<_SIZE_>;
60 using DoubleTab_t = DoubleTab_T<_SIZE_>;
62
65
66 Octree_32_64() : les_octrees(nullptr), pere(nullptr) {}
67 virtual ~Octree_32_64() { detruire(); }
68 Octree_32_64(int n, Octree_32_64* mon_pere, const ArrOfInt_t& val, const OctreeLoc& loc) : les_octrees(nullptr), pere(nullptr) { construire(n, val, loc, mon_pere); }
69 virtual int_t rang_elem_loc(const OctreeLoc&, double x, double y=0, double z=0) const;
70 virtual int_t rang_elem_depuis_loc(const OctreeLoc&, int_t prems, double x, double y=0, double z=0) const;
71
72 virtual const Domaine_t& domaine() const { return pere->domaine(); }
73 void construire(int, const ArrOfInt_t&, const OctreeLoc&, Octree_t* p=0);
74 int niveau() const;
75 virtual int_t taille() const; // taille memoire
76 static int nombre_d_octrees() { return 1 << Objet_U::dimension; /* = 2**O_U::dimension */ }
77
78 virtual Sortie& printOn(Sortie& is) const;
79 virtual Entree& readOn(Entree& is) { return is; }
80
81protected :
82 void detruire();
83 void ranger_elem_1D(ArrOfInt& oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t& coords_som, const IntTab_t& les_elems,
84 SmallArrOfTID_t& compteur, Vect_IntTab_t& sous_tab, double xmil);
85 void ranger_elem_2D(ArrOfInt& oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t& coords_som, const IntTab_t& les_elems,
86 SmallArrOfTID_t& compteur, Vect_IntTab_t& sous_tab, double xmil, double ymil);
87 void ranger_elem_3D(ArrOfInt& oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t& coords_som, const IntTab_t& les_elems,
88 SmallArrOfTID_t& compteur, Vect_IntTab_t& sous_tab, double xmil, double ymil, double zmil);
89 double get_epsilon() const { return domaine().epsilon(); }
90
93};
94
95
96/*! @brief Classe OctreeRoot
97 *
98 * @sa OctreeLoc Octree OctreeFloor
99 */
100template <typename _SIZE_>
101class OctreeRoot_32_64 : public Objet_U, public Octree_32_64<_SIZE_>
102{
103 Declare_instanciable_sans_constructeur_32_64(OctreeRoot_32_64);
104
105public :
106 using int_t = _SIZE_;
107 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
108 using IntTab_t = IntTab_T<_SIZE_>;
109 using SmallArrOfTID_t = SmallArrOfTID_T<_SIZE_>;
110 using DoubleTab_t = DoubleTab_T<_SIZE_>;
113
116 {
118 construire();
119 }
120
122 {
123 if(oc.construit())
124 {
125 associer_Domaine(oc.domaine());
126 construire();
127 }
128 else
129 valid_=0;
130 }
131
132 int_t rang_sommet(double x, double y=0, double z=0) const;
133 int_t rang_arete(double x, double y=0, double z=0) const;
134 int_t rang_elem(double x, double y=0, double z=0) const;
135 int_t rang_elem_depuis(int_t prems, double x, double y=0, double z=0) const;
136 int_t rang_elem_depuis(const DoubleTab& positions, const SmallArrOfTID_t& prems, SmallArrOfTID_t& elems) const;
137 int_t rang_sommet(const DoubleTab& positions, SmallArrOfTID_t& sommets) const;
138 int_t rang_arete(const DoubleTab& positions, SmallArrOfTID_t& aretes) const;
139 int_t rang_elem(const DoubleTab& positions, SmallArrOfTID_t& elem) const;
140 void rang_elems_sommet(SmallArrOfTID_t&, double x, double y=0, double z=0) const;
141
142 const Domaine_t& domaine() const override { return le_dom.valeur(); }
143 void associer_Domaine(const Domaine_t& d) { le_dom=d; }
144 void construire(int reel=0);
145 int construit() const;
146 void invalide();
147 inline int reel() const { return reel_; }
148
149protected :
151 using Octree_t::pere;
152
155 int valid_, reel_ = -1;
156};
157
158/*! @brief Classe OctreeFloor
159 *
160 * @sa OctreeLoc Octree OctreeRoot
161 */
162template <typename _SIZE_>
163class OctreeFloor_32_64 : public Octree_32_64<_SIZE_>
164{
165public :
166 using int_t = _SIZE_;
168 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
169
170 OctreeFloor_32_64(Octree_t *mon_pere, const ArrOfInt_t& val, const OctreeLoc& loc)
171 {
172 pos.resize_array(Objet_U::dimension);
173 construire(mon_pere, val, loc);
174 }
175
176 void construire(Octree_t* , const ArrOfInt_t&, const OctreeLoc&);
177 int_t rang_elem_loc(const OctreeLoc&, double x, double y=0, double z=0) const override;
178 int_t rang_elem_depuis_loc(const OctreeLoc&, int_t prems, double x, double y=0, double z=0) const override;
179
180 Sortie& printOn(Sortie& is) const override { return Octree_t::printOn(is); }
181 Entree& readOn(Entree& is) override { return Octree_t::readOn(is); }
182 int_t taille() const override;
183
184protected :
186 using Octree_t::pere;
187
189 mutable ArrOfDouble pos; // Tableau de travail - size 3
190};
191
192
193using Octree = Octree_32_64<int>;
194using OctreeRoot = OctreeRoot_32_64<int>;
195
196#endif // Octree_included
197
classe Domaine_32_64 un Domaine est un maillage compose d'un ensemble d'elements geometriques de meme...
Definition Domaine.h:62
double epsilon() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static int dimension
Definition Objet_U.h:99
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
int_t rang_elem_depuis_loc(const OctreeLoc &, int_t prems, double x, double y=0, double z=0) const override
Definition Octree.cpp:1096
Octree_32_64< _SIZE_ > Octree_t
Definition Octree.h:167
ArrOfDouble pos
Definition Octree.h:189
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Definition Octree.h:168
OctreeFloor_32_64(Octree_t *mon_pere, const ArrOfInt_t &val, const OctreeLoc &loc)
Definition Octree.h:170
void construire(Octree_t *, const ArrOfInt_t &, const OctreeLoc &)
Definition Octree.cpp:1132
int_t taille() const override
Renvoie la taille de l'octree.
Definition Octree.cpp:1150
Sortie & printOn(Sortie &is) const override
Definition Octree.h:180
Entree & readOn(Entree &is) override
Definition Octree.h:181
int_t rang_elem_loc(const OctreeLoc &, double x, double y=0, double z=0) const override
Definition Octree.cpp:1062
ArrOfInt_t num_elem
Definition Octree.h:188
Classe OctreeRoot.
Definition Octree.h:102
OctreeRoot_32_64(const OctreeRoot_32_64 &oc)
Definition Octree.h:121
int_t rang_sommet(double x, double y=0, double z=0) const
Definition Octree.cpp:702
int_t rang_arete(const DoubleTab &positions, SmallArrOfTID_t &aretes) const
Definition Octree.cpp:884
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Octree.h:109
int_t rang_elem(double x, double y=0, double z=0) const
Definition Octree.cpp:808
int_t rang_elem_depuis(const DoubleTab &positions, const SmallArrOfTID_t &prems, SmallArrOfTID_t &elems) const
Definition Octree.cpp:963
int_t rang_elem_depuis(int_t prems, double x, double y=0, double z=0) const
Definition Octree.cpp:826
IntTab_T< _SIZE_ > IntTab_t
Definition Octree.h:108
int_t rang_sommet(const DoubleTab &positions, SmallArrOfTID_t &sommets) const
Definition Octree.cpp:844
void construire(int reel=0)
Definition Octree.cpp:627
void rang_elems_sommet(SmallArrOfTID_t &, double x, double y=0, double z=0) const
Definition Octree.cpp:1003
int construit() const
Renvoie vrai si le domaine associe a l'octree est non nulle.
Definition Octree.cpp:1032
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Definition Octree.h:107
int_t rang_arete(double x, double y=0, double z=0) const
Definition Octree.cpp:760
const Domaine_t & domaine() const override
Definition Octree.h:142
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Octree.h:110
Domaine_32_64< _SIZE_ > Domaine_t
Definition Octree.h:111
Octree_32_64< _SIZE_ > Octree_t
Definition Octree.h:112
OctreeRoot_32_64(const Domaine_t &z)
Definition Octree.h:115
OBS_PTR(Domaine_t) le_dom
int_t rang_elem(const DoubleTab &positions, SmallArrOfTID_t &elem) const
Definition Octree.cpp:923
void associer_Domaine(const Domaine_t &d)
Definition Octree.h:143
Classe Octree.
Definition Octree.h:54
Octree_32_64 ** les_octrees
Definition Octree.h:91
void detruire()
Detruit l'octree.
Definition Octree.cpp:588
virtual int_t rang_elem_depuis_loc(const OctreeLoc &, int_t prems, double x, double y=0, double z=0) const
Definition Octree.cpp:231
_SIZE_ int_t
Definition Octree.h:56
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Octree.h:60
virtual int_t taille() const
Renvoie la taille de l'octree.
Definition Octree.cpp:615
void ranger_elem_3D(ArrOfInt &oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t &coords_som, const IntTab_t &les_elems, SmallArrOfTID_t &compteur, Vect_IntTab_t &sous_tab, double xmil, double ymil, double zmil)
Definition Octree.cpp:463
IntTab_T< _SIZE_ > IntTab_t
Definition Octree.h:59
virtual int_t rang_elem_loc(const OctreeLoc &, double x, double y=0, double z=0) const
Definition Octree.cpp:195
TRUST_Vector< IntTab_t > Vect_IntTab_t
Definition Octree.h:61
static int nombre_d_octrees()
Definition Octree.h:76
int niveau() const
Definition Octree.cpp:602
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Definition Octree.h:57
Octree_32_64()
Definition Octree.h:66
void ranger_elem_1D(ArrOfInt &oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t &coords_som, const IntTab_t &les_elems, SmallArrOfTID_t &compteur, Vect_IntTab_t &sous_tab, double xmil)
Definition Octree.cpp:258
Octree_32_64(int n, Octree_32_64 *mon_pere, const ArrOfInt_t &val, const OctreeLoc &loc)
Definition Octree.h:68
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Octree.h:58
void construire(int, const ArrOfInt_t &, const OctreeLoc &, Octree_t *p=0)
Definition Octree.cpp:503
double get_epsilon() const
Definition Octree.h:89
virtual Sortie & printOn(Sortie &is) const
Definition Octree.cpp:27
Octree_32_64 * pere
Definition Octree.h:92
void ranger_elem_2D(ArrOfInt &oks, int_t elem, int_t idx, int nb_som_elem, const DoubleTab_t &coords_som, const IntTab_t &les_elems, SmallArrOfTID_t &compteur, Vect_IntTab_t &sous_tab, double xmil, double ymil)
Definition Octree.cpp:438
virtual Entree & readOn(Entree &is)
Definition Octree.h:79
virtual ~Octree_32_64()
Definition Octree.h:67
virtual const Domaine_t & domaine() const
Definition Octree.h:72
Domaine_32_64< _SIZE_ > Domaine_t
Definition Octree.h:63
Octree_32_64< _SIZE_ > Octree_t
Definition Octree.h:64
Classe de base des flux de sortie.
Definition Sortie.h:52
classe TRUST_Vector
Struct OctreeLoc.
Definition Octree.h:40
double xmax
Definition Octree.h:41
double zmin
Definition Octree.h:41
void construire(const OctreeLoc &loc, int i)
Definition Octree.cpp:61
double ymax
Definition Octree.h:41
double zmax
Definition Octree.h:41
double xmin
Definition Octree.h:41
double ymin
Definition Octree.h:41
int direction(double x, double y, double z) const
Definition Octree.cpp:157