Salome HOME
Updated path
[tools/solverlab.git] / CDMATH / mesh / src / Cell.cxx
1 /*
2  * cell.cxx
3  *
4  *  Created on: 23 janv. 2012
5  *      Authors: CDMAT
6  */
7
8 #include "Cell.hxx"
9 #include "CdmathException.hxx"
10
11 #include <assert.h>
12
13 //----------------------------------------------------------------------
14 Cell::Cell( void )
15 //----------------------------------------------------------------------
16 {
17         _measure = 0.0 ;
18         _numberOfNodes  = 0 ;
19         _numberOfFaces    = 0 ;
20 }
21
22 //----------------------------------------------------------------------
23 Cell::Cell( int numberOfNodes, int numberOfFaces, double measure, const Point p )
24 //----------------------------------------------------------------------
25 {
26         _point        = p ;
27         _numberOfNodes  = numberOfNodes ;
28         _numberOfFaces    = numberOfFaces ;
29         _nodesId = std::vector< int >(_numberOfNodes,0);
30         _facesId = std::vector< int >(_numberOfFaces,0);
31         _normalVectors = Vector(3*_numberOfFaces);
32         _measure = measure ;
33 }
34
35 //----------------------------------------------------------------------
36 Cell::~Cell( void )
37 //----------------------------------------------------------------------
38 {
39 }
40
41 //----------------------------------------------------------------------
42 Cell::Cell( const Cell& cell )
43 //----------------------------------------------------------------------
44 {
45         _point       = cell.getBarryCenter() ;
46         _numberOfNodes = cell.getNumberOfNodes();
47         _numberOfFaces   = cell.getNumberOfFaces() ;
48         _measure = cell.getMeasure() ;
49         _nodesId=cell.getNodesId();
50         _facesId=cell.getFacesId();
51         _normalVectors=cell.getNormalVectors();
52 }
53
54 //----------------------------------------------------------------------
55
56 //----------------------------------------------------------------------
57 std::vector< int >
58 Cell::getNodesId ( void ) const 
59 //----------------------------------------------------------------------
60 {
61         return _nodesId ;
62 }
63
64 //----------------------------------------------------------------------
65 double
66 Cell::getMeasure ( void ) const
67 //----------------------------------------------------------------------
68 {
69         return _measure ;
70 }
71
72 //----------------------------------------------------------------------
73 std::vector< int >
74 Cell::getFacesId ( void ) const 
75 //----------------------------------------------------------------------
76 {
77         return _facesId ;
78 }
79
80 //----------------------------------------------------------------------
81 int
82 Cell::getNumberOfNodes ( void ) const 
83 //----------------------------------------------------------------------
84 {
85         return _numberOfNodes ;
86 }
87
88 //----------------------------------------------------------------------
89 Point
90 Cell::getBarryCenter( void ) const
91 //----------------------------------------------------------------------
92 {
93         return _point ;
94 }
95
96 //----------------------------------------------------------------------
97 double
98 Cell::x( void ) const 
99 //----------------------------------------------------------------------
100 {
101   return _point.x() ;
102 }
103
104 //----------------------------------------------------------------------
105 double
106 Cell::y( void ) const 
107 //----------------------------------------------------------------------
108 {
109         return _point.y() ;
110 }
111
112 //----------------------------------------------------------------------
113 double
114 Cell::z( void ) const 
115 //----------------------------------------------------------------------
116 {
117         return _point.z() ;
118 }
119
120 //----------------------------------------------------------------------
121 int
122 Cell::getNumberOfFaces ( void ) const 
123 //----------------------------------------------------------------------
124 {
125         return _numberOfFaces ;
126 }
127
128 //----------------------------------------------------------------------
129 void
130 Cell::addFaceId (int numFace, int faceId )
131 //----------------------------------------------------------------------
132 {
133         _facesId[numFace] = faceId ;
134 }
135
136 //----------------------------------------------------------------------
137 void
138 Cell::addNormalVector (int numNormalVector, double x, double y, double z)
139 //----------------------------------------------------------------------
140 {
141         _normalVectors(3*numNormalVector) = x ;
142         _normalVectors(3*numNormalVector+1) = y ;
143         _normalVectors(3*numNormalVector+2) = z ;
144 }
145
146 //----------------------------------------------------------------------
147 double
148 Cell::getNormalVector( int numNormalVector, int numComposant ) const
149 //----------------------------------------------------------------------
150 {
151         if (numComposant==0)
152                 return _normalVectors(3*numNormalVector);
153         else if (numComposant==1)
154                 return _normalVectors(3*numNormalVector+1);
155         else if (numComposant==2)
156                 return _normalVectors(3*numNormalVector+2);
157         else
158                 throw CdmathException("Cell::getNormalVector, numComposant should be 0, 1 or 2");
159 }
160
161 //----------------------------------------------------------------------
162 Vector
163 Cell::getNormalVectors (void) const
164 //----------------------------------------------------------------------
165 {
166                 return _normalVectors;
167 }
168
169 //----------------------------------------------------------------------
170 void
171 Cell::addNodeId (int numNode, int nodeId )
172 //----------------------------------------------------------------------
173 {
174         _nodesId[numNode] = nodeId ;
175 }
176
177 //----------------------------------------------------------------------
178 const Cell&
179 Cell::operator= ( const Cell& cell )
180 //----------------------------------------------------------------------
181 {
182         _point       = cell.getBarryCenter() ;
183         _numberOfNodes = cell.getNumberOfNodes() ;
184         _numberOfFaces   = cell.getNumberOfFaces() ;
185         _measure = cell.getMeasure() ;
186
187         _nodesId = cell.getNodesId();
188         _facesId = cell.getFacesId();
189         _normalVectors=cell.getNormalVectors();
190         return *this;
191 }
192
193 //----------------------------------------------------------------------
194 int 
195 Cell::getFaceId(int localId) const
196 //----------------------------------------------------------------------
197 {
198     if(localId<_numberOfFaces)
199         return _facesId[localId];
200     else
201     {
202         std::cout<< "Local id requested : "<< localId<<", total number of faces= "<<_numberOfFaces<<std::endl;
203         throw CdmathException("Cell::getfaceId : incorrect face local id");
204     }
205 }
206
207 //----------------------------------------------------------------------
208 int 
209 Cell::getNodeId(int localId) const
210 //----------------------------------------------------------------------
211 {
212     if(localId<_numberOfNodes)
213         return _nodesId[localId];
214     else
215     {
216         std::cout<< "Local id requested : "<< localId<<", total number of nodes= "<<_numberOfNodes<<std::endl;
217         throw CdmathException("Cell::getNodeId : incorrect node local id");
218     }
219 }
220
221