TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Segment.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <Segment.h>
17#include <Domaine.h>
18
19Implemente_instanciable_32_64(Segment_32_64,"Segment",Elem_geom_base_32_64<_T_>);
20// XD segment sonde_base segment NO_BRACE Keyword to define the number of probe segment points. The file is arranged in
21// XD_CONT columns.
22// XD attr nbr entier nbr REQ Number of probe points of the segment, evenly distributed.
23// XD attr point_deb un_point point_deb REQ First outer probe segment point.
24// XD attr point_fin un_point point_fin REQ Second outer probe segment point.
25
26static int faces_sommets_segment[2][1] =
27{ { 0 } ,{ 1 } };
28
29template <typename _SIZE_>
31{
32 return s;
33}
34
35template <typename _SIZE_>
37{
38 return s;
39}
40
41/*! @brief Reorders the vertices of the segment.
42 *
43 */
44template <typename _SIZE_>
46{
47 Domaine_t& domaine=mon_dom.valeur();
48 IntTab_t& elem=domaine.les_elems();
49 const Domaine_t& dom=domaine;
50 SmallArrOfTID_t S(2);
51 int i;
52 const int_t nb_elem=domaine.nb_elem();
53 for (int_t num_poly=0; num_poly<nb_elem; num_poly++)
54 {
55 for(i=0; i<2; i++)
56 S[i] = elem(num_poly,i);
57
58 if(sup_strict(dom.coord(S[0], 0),dom.coord(S[1], 0)))
59 {
60 int_t tmp=S[0];
61 S[0]=S[1];
62 S[1]=tmp;
63 }
64
65 for(i=0; i<2; i++)
66 elem(num_poly, i)=S[i];
67 }
68}
69
70
71/*! @brief Returns the LML name of a segment.
72 *
73 * @return Always equal to "SEGMENT" (or "QUADRANGLE_3D" in 2D).
74 */
75template <typename _SIZE_>
77{
78 static Nom nom="SEGMENT";
79 if (dimension==2)
80 nom="QUADRANGLE_3D";
81 return nom;
82}
83
84
85/*! @brief Returns 1 if element "element" of the domain associated with this geometric element contains the point
86 *
87 * with coordinates specified by parameter "pos". Returns 0 otherwise.
88 *
89 * @param pos Coordinates of the point to locate.
90 * @param element Index of the domain element in which to search for the point.
91 * @return 1 if the point belongs to element "element", 0 otherwise.
92 */
93template <typename _SIZE_>
94int Segment_32_64<_SIZE_>::contient(const ArrOfDouble& pos, int_t element ) const
95{
96 assert(pos.size_array()==dimension);
97
98 const Domaine_t& domaine=mon_dom.valeur();
99 const Domaine_t& dom=domaine;
100 const IntTab_t& elem=domaine.les_elems();
101 // Test whether OM = a.O1 with O and 1 the extreme points of the seg and M the point to be tested
102 double autre_a = 0;
103 for (int d=0; d<dimension; d++)
104 {
105 double O1 = dom.coord(elem(element,1), d) - dom.coord(elem(element,0), d);
106 double OM = pos[d] - dom.coord(elem(element,0), d);
107 if (!est_egal(O1,0))
108 {
109 double a = OM/O1;
110 // M is outside O1?
111 if (a<-Objet_U::precision_geom || a>1+Objet_U::precision_geom) return 0;
112 // a is not the same as for another dimension, <=> not aligned
113 if (autre_a>0 && !est_egal(a, autre_a)) return 0;
114 autre_a = a;
115 }
116 else if (!est_egal(OM,0)) return 0; // M is not along O1
117 }
118 return 1;
119}
120
121
122/*! @brief Returns 1 if the vertices specified by parameter "pos" are the vertices of element "element"
123 *
124 * in the domain associated with this geometric element. Returns 0 otherwise.
125 *
126 * @param pos Vertex indices to compare with those of element "element".
127 * @param element Index of the domain element whose vertices are to be compared.
128 * @return 1 if the specified vertices are those of the given element, 0 otherwise.
129 */
130template <typename _SIZE_>
132{
133 assert(pos.size_array()==1);
134 const Domaine_t& domaine=mon_dom.valeur();
135 if((domaine.sommet_elem(element,0)==pos[0])&&
136 (domaine.sommet_elem(element,1)==pos[1]))
137 return 1;
138 else
139 return 0;
140}
141
142/*! @brief Computes the volumes of the elements of the associated domain.
143 *
144 * @param volumes Vector to fill with the volumes of domain elements.
145 */
146template <typename _SIZE_>
148{
149 const Domaine_t& domaine=mon_dom.valeur();
150 const Domaine_t& dom=domaine;
151 double dx;
152 int_t S1,S2;
153
154 int_t size_tot = domaine.nb_elem_tot();
155 assert(volumes.size_totale()==size_tot);
156 for (int_t num_poly=0; num_poly<size_tot; num_poly++)
157 {
158 S1 = domaine.sommet_elem(num_poly,0);
159 S2 = domaine.sommet_elem(num_poly,1);
160 dx=0;
161 for (int i=0; i<dimension; i++)
162 {
163 double d = dom.coord(S2,i) - dom.coord(S1,i);
164 dx+=d*d;
165 }
166 volumes[num_poly]= sqrt(dx);
167 }
168}
169
170/*! @brief See ElemGeomBase::get_tab_faces_sommets_locaux.
171 */
172template <typename _SIZE_>
174{
175 faces_som_local.resize(2,1);
176 for (int j=0; j<2; j++)
177 faces_som_local(j,0) = faces_sommets_segment[j][0];
178 return 1;
179}
180
181
182template class Segment_32_64<int>;
183#if INT_is_64_ == 2
184template class Segment_32_64<trustIdType>;
185#endif
186
double coord(int_t i, int j) const
Definition Domaine.h:110
Class Elem_geom_base This class is the base class for the definition of elements.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static double precision_geom
Definition Objet_U.h:81
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Class Segment: represents the geometric element segment.
Definition Segment.h:29
static int dimension
Definition Objet_U.h:94
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
See ElemGeomBase::get_tab_faces_sommets_locaux.
Definition Segment.cpp:173
_SIZE_ int_t
Definition Segment.h:35
void calculer_volumes(DoubleVect_t &vols) const override
Computes the volumes of the elements of the associated domain.
Definition Segment.cpp:147
const Nom & nom_lml() const override
Returns the LML name of a segment.
Definition Segment.cpp:76
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Segment.h:37
IntTab_T< _SIZE_ > IntTab_t
Definition Segment.h:36
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Segment.h:38
int contient(const ArrOfDouble &pos, int_t elem) const override
Returns 1 if element "element" of the domain associated with this geometric element contains the poin...
Definition Segment.cpp:94
void reordonner() override
Reorders the vertices of the segment.
Definition Segment.cpp:45
Domaine_32_64< _SIZE_ > Domaine_t
Definition Segment.h:39
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61