TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Reorienter_triangles.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 <Reorienter_triangles.h>
17#include <Scatter.h>
18
19Implemente_instanciable_32_64(Reorienter_triangles_32_64,"Reorienter_triangles",Interprete_geometrique_base_32_64<_T_>);
20// XD reorienter_triangles interprete reorienter_triangles INHERITS_BRACE not_set
21// XD attr domain_name ref_domaine domain_name REQ Name of domain.
22
23template <typename _SIZE_>
25{
26 return Interprete::printOn(os);
27}
28
29template <typename _SIZE_>
31{
32 return Interprete::readOn(is);
33}
34
35template <typename _SIZE_>
37{
38 Cerr << "Reorientation of triangles for either direct..." << finl;
39 if (Objet_U::dimension != 2)
40 {
41 Cerr << "we can not reorientate (Reorienter) triangles in dimension " << Objet_U::dimension <<finl;
43 }
44 this->associer_domaine(is);
45 Domaine_t& dom=this->domaine();
47 this->reorienter(dom);
49 Cerr << "Reorientation of triangles... OK" << finl;
50 return is;
51}
52
53template <typename _SIZE_>
54Sens_Orient Reorienter_triangles_32_64<_SIZE_>::test_orientation_triangle(IntTab_t& les_elems, int_t ielem, const DoubleTab_t& coord_sommets) const
55{
56 static const int SOM_Z = 0;
57 static const int SOM_A = 1;
58 static const int SOM_B = 2;
59
60 const int_t som_Z = les_elems(ielem,SOM_Z);
61 const int_t som_A = les_elems(ielem,SOM_A);
62 const int_t som_B = les_elems(ielem,SOM_B);
63
64 double ZA0 = coord_sommets(som_A,0) - coord_sommets(som_Z,0);
65 double ZB0 = coord_sommets(som_B,0) - coord_sommets(som_Z,0);
66 double ZA1 = coord_sommets(som_A,1) - coord_sommets(som_Z,1);
67 double ZB1 = coord_sommets(som_B,1) - coord_sommets(som_Z,1);
68
69 //compute cross product ZAxZB
70 double pdtvect = ZA0*ZB1 - ZA1*ZB0;
71
72 if (pdtvect<0.)
73 {
74 //the cross product is negative: this is a badly oriented triangle
75#ifdef _AFFDEBUG
76 {
77 Process::Journal<<" element "<<num_element<<" indirect"<<finl;
78 }
79#endif
80 return Sens_Orient::INDIRECT;
81 }
82#ifdef _AFFDEBUG
83 {
84 Process::Journal<<" element "<<num_element<<" direct"<<finl;
85 }
86#endif
87
88 return Sens_Orient::DIRECT;
89}
90
91template <typename _SIZE_>
93{
94 static const int SOM_A = 1;
95 static const int SOM_B = 2;
96
97 //to reorient the triangle, swap vertices 1 and 2
98 int_t tmp;
99 tmp = les_elems(num_element,SOM_A);
100 les_elems(num_element,SOM_A) = les_elems(num_element,SOM_B);
101 les_elems(num_element,SOM_B) = tmp;
102 return Sens_Orient::DIRECT;
103}
104
105/*!
106 * @brief This method reorients triangles to the direct (positive) orientation.
107 * @param dom the domain whose triangles are to be reoriented
108 */
109template <typename _SIZE_>
111{
112 const DoubleTab_t& coord_sommets = dom.coord_sommets();
113
114 if (dom.type_elem()->que_suis_je() == "Triangle" )
115 {
116 //domain of triangles
117 IntTab_t& les_elems = dom.les_elems();
118 int_t nb_elems = les_elems.dimension(0);
119
120 //sweep over triangles
121 for (int_t ielem=0 ; ielem<nb_elems ; ielem++)
122 {
123 if (test_orientation_triangle(les_elems, ielem, coord_sommets)==Sens_Orient::INDIRECT)
124 {
125 //triangle oriented in indirect sense -> needs reorienting
126 reorienter_triangle(les_elems, ielem);
127
128#ifdef _AFFDEBUG
129 {
130 Process::Journal<<" #element reoriente "<<ielem<<finl;
131 static const int SOM_Z = 0;
132 static const int SOM_A = 1;
133 static const int SOM_B = 2;
134 const int som_Z = les_elems(ielem,SOM_Z);
135 const int som_A = les_elems(ielem,SOM_A);
136 const int som_B = les_elems(ielem,SOM_B);
137 Process::Journal<<" somZ= "<<som_Z<<" coords= "<<coord_sommets(som_Z, 0)<<" "<<coord_sommets(som_Z, 1)<<finl;
138 Process::Journal<<" somA= "<<som_A<<" coords= "<<coord_sommets(som_A, 0)<<" "<<coord_sommets(som_A, 1)<<finl;
139 Process::Journal<<" somB= "<<som_B<<" coords= "<<coord_sommets(som_B, 0)<<" "<<coord_sommets(som_B, 1)<<finl;
140 }
141#endif
142 }
143 }
144 }
145}
146
147
149#if INT_is_64_ == 2
151#endif
152
153
IntTab_t & les_elems()
Definition Domaine.h:129
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Class Interprete_geometrique_base.
friend class Entree
Definition Objet_U.h:71
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
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 Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
Definition Process.cpp:592
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
class Reorienter_triangle Sweeps through the mesh triangles to ensure they are positively oriented.
void reorienter(Domaine_t &) const
This method reorients triangles to the direct (positive) orientation.
Sens_Orient reorienter_triangle(IntTab_t &les_elems, int_t ielem) const
Sens_Orient test_orientation_triangle(IntTab_t &les_elems, int_t ielem, const DoubleTab_t &coord_sommets) const
Domaine_32_64< _SIZE_ > Domaine_t
DoubleTab_T< _SIZE_ > DoubleTab_t
Entree & interpreter_(Entree &) override
static void init_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
Create parallel descriptors for the vertex and element arrays of the domain (necessary because Scatte...
Definition Scatter.cpp:2739
static void uninit_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
Method used by interpreters that modify the domain (sequential), destroys the descriptors of vertices...
Definition Scatter.cpp:2754
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133