TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Trianguler.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 <Trianguler.h>
17#include <Domaine.h>
18
19Implemente_instanciable(Trianguler,"Trianguler",Triangulation_base);
20// XD triangulate interprete trianguler INHERITS_BRACE To achieve a triangular mesh from a mesh comprising rectangles (2
21// XD_CONT triangles per rectangle). Should be used in VEF discretization. Principle: NL2
22// XD_CONT \includeimage{{trianguler.jpeg}}
23// XD attr domain_name ref_domaine domain_name REQ Name of domain.
24
25/*! @brief Simple call to: Interprete::printOn(Sortie&)
26 *
27 * @param os Output stream.
28 * @return The modified output stream.
29 */
31{
32 return Interprete::printOn(os);
33}
34
35
36/*! @brief Simple call to: Interprete::readOn(Entree&)
37 *
38 * @param is Input stream.
39 * @return The modified input stream.
40 */
42{
43 return Interprete::readOn(is);
44}
45
46/*! @brief @brief Triangulates all elements of a domain: transforms the geometric elements of the domain into triangles.
47 *
48 * Currently only Rectangles can be triangulated
49 * (they are split into 2).
50 *
51 * @param domaine The domain whose elements are to be triangulated.
52 */
53void Trianguler::trianguler(Domaine& domaine) const
54{
55 if ((domaine.type_elem()->que_suis_je() == "Rectangle") || (domaine.type_elem()->que_suis_je() == "Quadrangle"))
56 {
57 domaine.typer("Triangle");
58 IntTab& les_elems=domaine.les_elems();
59 const DoubleTab& som =domaine.les_sommets();
60 int oldsz=les_elems.dimension(0);
61 IntTab new_elems(2*oldsz, 3);
62 for(int i=0; i< oldsz; i++)
63 {
64 int i0=les_elems(i,0);
65 int i1=les_elems(i,1);
66 int i2=les_elems(i,2);
67 int i3=les_elems(i,3);
68
69 // NEW: cut along the shorter diagonal if they are not the same length
70 double d1=0,d2=0;
71 for (int dir=0; dir<dimension; dir++)
72 {
73 d1+=(som(i1,dir)-som(i2,dir))*(som(i1,dir)-som(i2,dir));
74 d2+=(som(i3,dir)-som(i0,dir))*(som(i3,dir)-som(i0,dir));
75 }
76 int test;
77 if (est_egal(d1,d2))
78 test=(i%2)==0;
79 else
80 test=(d1<d2);
81 if (test)
82 {
83 new_elems(i,0)=i0;
84 new_elems(i,1)=i1;
85 new_elems(i,2)=i2;
86 new_elems(i+oldsz,0)=i1;
87 new_elems(i+oldsz,1)=i2;
88 new_elems(i+oldsz,2)=i3;
89 }
90 else
91 {
92 new_elems(i,0)=i0;
93 new_elems(i,1)=i1;
94 new_elems(i,2)=i3;
95 new_elems(i+oldsz,0)=i0;
96 new_elems(i+oldsz,1)=i2;
97 new_elems(i+oldsz,2)=i3;
98 }
100 }
101 les_elems.ref(new_elems);
102 }
103 else
104 {
105 Cerr << "We do not yet know how to Trianguler the "
106 << domaine.type_elem()->que_suis_je() <<"s"<<finl;
107 }
108}
109
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void mettre_a_jour_sous_domaine(Domaine_t &domaine, int_t &elem, int_t num_premier_elem, int_t nb_elem) const
static int dimension
Definition Objet_U.h:94
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
Base class for output streams.
Definition Sortie.h:52
virtual void ref(const TRUSTTab &)
Definition TRUSTTab.tpp:308
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
Triangulation_base Base class intended to factor out the triangulation action of interpreters.
Class Trianguler This class is an interpreter used to read and execute.
Definition Trianguler.h:32
void trianguler(Domaine &) const override
Triangulates all elements of a domain: transforms the geometric elements of the domain into triangles...