TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Octree_Double.tpp
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_Double_TPP_included
17#define Octree_Double_TPP_included
18
19/*! @brief Builds an octree from volumetric elements described by sets of vertices.
20 *
21 * Stores in the octree the bounding parallelepipeds of each
22 * element (containing all vertices of the element) plus a margin of epsilon.
23 * If include_virtual=1, stores elements.dimension_tot(0) elements, otherwise
24 * stores elements.dimension(0).
25 *
26 * Templated because the float version is needed for lata tools.
27 *
28 */
29template<typename _SIZE_>
30template<class _TAB_TYPE_>
31void Octree_Double_32_64<_SIZE_>::build_elements(const _TAB_TYPE_& coords, const IntTab_t& elements,
32 const double epsilon, const bool include_virtual)
33{
34 octree_int_.reset();
35 compute_origin_factors(coords, epsilon, include_virtual);
36
37 const int_t nb_elems = include_virtual ? elements.dimension_tot(0) : elements.dimension(0);
38 const int nb_som_elem = elements.dimension_int(1);
39 const int dim = coords.dimension_int(1);
40 IntTab_t elements_boxes;
41 elements_boxes.resize(nb_elems, dim * 2, RESIZE_OPTIONS::NOCOPY_NOINIT);
42 for (int_t i = 0; i < nb_elems; i++)
43 {
44 for (int j = 0; j < dim; j++)
45 {
46 double xmin = 1.e37;
47 double xmax = -1.e37;
48 for (int k = 0; k < nb_som_elem; k++)
49 {
50 const int_t som = elements(i, k);
51 if (som < 0) continue; // for polyhedrons, som might be -1 (padding)
52 const double x = coords(som, j);
53 xmin = (x<xmin) ? x : xmin;
54 xmax = (x>xmax) ? x : xmax;
55 }
56 int pos1 = 0, pos2 = 0;
57 if (!integer_position(xmin, j, pos1) || !integer_position(xmax, j, pos2))
58 {
59 Cerr << "Fatal error in octree : integer position outside octree" << finl;
61 }
62 elements_boxes(i, j) = pos1;
63 elements_boxes(i, j+dim) = pos2;
64 }
65 }
66 octree_int_.build(dim, elements_boxes);
67}
68
69/*! @brief Helper method for build_nodes and build_elements: computes the conversion factors from real to integer coordinates for Octree_Int.
70 *
71 * epsilon is added to the min and max coordinates for the octree bounding box.
72 *
73 * Templated because the float version is needed for lata tools.
74 */
75template<typename _SIZE_>
76template<class _TAB_TYPE_>
78 const double epsilon,
79 const int include_virtual)
80{
81 // Search for the min and max coordinates of the domain
82 const int_t nb_som = include_virtual ? coords.dimension_tot(0) : coords.dimension(0);
83 if (nb_som == 0) return; // empty octree
84
85 dim_ = coords.dimension_int(1);
86 origin_.resize_array(3);
87 factor_.resize_array(3);
88 ArrOfDouble_t xmin(dim_);
89 xmin = 1.e37;
90 ArrOfDouble_t xmax(dim_);
91 xmax = -1.e-37;
92 assert(dim_ >= 1 && dim_ <= 3);
93 for (int_t i = 0; i < nb_som; i++)
94 for (int j = 0; j < dim_; j++)
95 {
96 const double x = coords(i, j);
97 if (x < xmin[j])
98 xmin[j] = x;
99 if (x > xmax[j])
100 xmax[j] = x;
101 }
102
103 const double coord_max = (double) Octree_Int_32_64<_SIZE_>::coord_max_;
104 for (int j = 0; j < dim_; j++)
105 {
106 xmin[j] -= epsilon;
107 xmax[j] += epsilon;
108 origin_[j] = xmin[j];
109 if (xmax[j] - xmin[j] > 0.)
110 factor_[j] = coord_max / (xmax[j] - xmin[j]);
111 else
112 factor_[j] = 0.;
113 }
114}
115
116#endif
bool integer_position(double x, int direction, int &ix) const
Converts a real coordinate to an integer coordinate for the octree_int.
void compute_origin_factors(const _TAB_TYPE_ &coords, const double epsilon, const int include_virtual)
Helper method for build_nodes and build_elements: computes the conversion factors from real to intege...
Octree_Int_32_64< _SIZE_ > octree_int_
ArrOfDouble_T< _SIZE_ > ArrOfDouble_t
IntTab_T< _SIZE_ > IntTab_t
void build_elements(const _TAB_TYPE_ &coords, const IntTab_t &elements, const double epsilon, const bool include_virtual)
Builds an octree from volumetric elements described by sets of vertices.
static const int coord_max_
Definition Octree_Int.h:48
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
int dimension_int(int d) const
Definition TRUSTTab.tpp:152
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