Salome HOME
initial project version
[tools/solverlab.git] / CDMATH / mesh / src / Face.cxx
1 /*
2  * face.cxx
3  *
4  *  Created on: 23 janv. 2012
5  *      Authors: CDMAT
6  */
7
8 #include "Face.hxx"
9 #include "CdmathException.hxx"
10
11 #include <cmath>
12
13 using namespace std;
14
15 //----------------------------------------------------------------------
16 Face::Face( void )
17 //----------------------------------------------------------------------
18 {
19         _measure = 0.0 ;
20         _region=-1;
21         _groupNames=std::vector<std::string>(0);
22         _numberOfCells = 0 ;
23         _numberOfNodes = 0 ;
24         _xN=0.;
25         _yN=0.;
26         _zN=0.;
27 }
28
29 //----------------------------------------------------------------------
30 Face::Face( const Face& face )
31 //----------------------------------------------------------------------
32 {
33         _measure = face.getMeasure() ;
34         _region=face.getRegion();
35         _groupNames=face.getGroupNames();
36         _point = face.getBarryCenter();
37         _numberOfCells = face.getNumberOfCells() ;
38         _numberOfNodes = face.getNumberOfNodes() ;
39         _nodesId=face.getNodesId();
40         _cellsId=face.getCellsId();
41         _xN=face.getXN();
42         _yN=face.getYN();
43         _zN=face.getZN();
44 }
45
46 //----------------------------------------------------------------------
47 Face::Face( const int numberOfNodes, const int numberOfCells, const double measure, const Point p, double xN, double yN, double zN )
48 //----------------------------------------------------------------------
49 {
50         _point        = p ;
51         _numberOfNodes = numberOfNodes ;
52         _numberOfCells   = numberOfCells ;
53         _nodesId = std::vector< int >(_numberOfNodes,0);
54         _cellsId = std::vector< int >(_numberOfCells,0);
55         _measure = measure ;
56         _region=-1;
57         _xN=xN;
58         _yN=yN;
59         _zN=zN;
60
61     if(numberOfCells==1)
62         _groupNames=std::vector<std::string>(1,"Boundary");
63     else if(numberOfCells>=2)//On a graph geometry (spaceDim>meshDim), a face is a node and can have more than 2 cell neighbour
64         _groupNames=std::vector<std::string>(0);
65     else
66     {
67         cout<<"Error, trying to create a face with "<< numberOfCells <<" cell neighbours"<<endl;
68         throw CdmathException("A face must have at least one cell neighbour (MEDCoupling philosophy)");    
69     }
70 }
71
72 //----------------------------------------------------------------------
73 Face::~Face( void )
74 //----------------------------------------------------------------------
75 {
76 }
77
78 int
79 Face::getRegion(void) const
80 {
81         return _region;
82 }
83
84 double
85 Face::getXN(void) const
86 {
87         return _xN;
88 }
89
90 double
91 Face::getYN(void) const
92 {
93         return _yN;
94 }
95
96 double
97 Face::getZN(void) const
98 {
99         return _zN;
100 }
101
102 std::vector<std::string>
103 Face::getGroupNames(void) const
104 {
105         return _groupNames;
106 }
107
108 string
109 Face::getGroupName(int igroup) const
110 {
111     if(igroup<_groupNames.size())
112         return _groupNames[igroup];
113     else
114     {
115         std::cout<<"Error Face::getGroupName(int igroup), group number "<<igroup+1<<" requested"<<std::endl;
116         std::cout<<"Face belongs to "<< _groupNames.size() <<" groups"<<std::endl;
117         throw CdmathException("Face has no group with number igroup");
118     }
119 }
120
121 void
122 Face::setGroupName(const string groupName)
123 {
124         _groupNames.insert(_groupNames.begin(),groupName);
125         _region=0;
126 }
127
128 bool
129 Face::isBorder(void)
130 {
131         if (_region==0 || _numberOfCells==1)
132                 return true;
133         else
134                 return false;
135 }
136 //----------------------------------------------------------------------
137 Point
138 Face::getBarryCenter( void ) const
139 //----------------------------------------------------------------------
140 {
141         return _point ;
142 }
143
144 //----------------------------------------------------------------------
145 double
146 Face::x( void ) const
147 //----------------------------------------------------------------------
148 {
149   return _point.x() ;
150 }
151
152 //----------------------------------------------------------------------
153 double
154 Face::y( void ) const
155 //----------------------------------------------------------------------
156 {
157         return _point.y() ;
158 }
159
160 //----------------------------------------------------------------------
161 double
162 Face::z( void ) const
163 //----------------------------------------------------------------------
164 {
165         return _point.z() ;
166 }
167
168 //----------------------------------------------------------------------
169 std::vector< int >
170 Face::getCellsId( void ) const
171 //----------------------------------------------------------------------
172 {
173         return _cellsId ;
174 }
175
176 //----------------------------------------------------------------------
177 std::vector< int >
178 Face::getNodesId( void ) const
179 //----------------------------------------------------------------------
180 {
181         return _nodesId ;
182 }
183
184 //----------------------------------------------------------------------
185 double
186 Face::getMeasure( void ) const
187 //----------------------------------------------------------------------
188 {
189         return _measure ;
190 }
191
192 //----------------------------------------------------------------------
193 int
194 Face::getNumberOfCells( void ) const
195 //----------------------------------------------------------------------
196 {
197         return _numberOfCells ;
198 }
199
200 //----------------------------------------------------------------------
201 int
202 Face::getNumberOfNodes( void ) const
203 //----------------------------------------------------------------------
204 {
205         return _numberOfNodes ;
206 }
207
208 //----------------------------------------------------------------------
209 void
210 Face::addCellId(const int numCell, const int cellId )
211 //----------------------------------------------------------------------
212 {
213         _cellsId[numCell] = cellId ;
214 }
215 //----------------------------------------------------------------------
216 void
217 Face::addNodeId(const int numNode, const int nodeId )
218 //----------------------------------------------------------------------
219 {
220         _nodesId[numNode] = nodeId ;
221 }
222
223 //----------------------------------------------------------------------
224 const Face&
225 Face::operator= ( const Face& face )
226 //----------------------------------------------------------------------
227 {
228         _measure = face.getMeasure() ;
229         _point = face.getBarryCenter() ;
230         _numberOfCells = face.getNumberOfCells() ;
231         _numberOfNodes = face.getNumberOfNodes() ;
232         _nodesId=face.getNodesId();
233         _cellsId=face.getCellsId();
234         _groupNames=face.getGroupNames();
235         _region=face.getRegion();
236         _xN=face.getXN();
237         _yN=face.getYN();
238         _zN=face.getZN();
239         return *this;
240 }
241 //------------------------------------------------------------------------
242 int
243 Face::getNodeId(int localId) const
244 //------------------------------------------------------------------------
245 {
246     if(localId<_numberOfNodes)
247         return _nodesId[localId];
248     else
249     {
250         std::cout<< "Local id requested : "<< localId<<" total number of nodes= "<<_numberOfNodes<<std::endl;
251         throw CdmathException("Face::getNodeId : incorrect node local id");
252     }
253 }
254 //------------------------------------------------------------------------
255 int
256 Face::getCellId(int localId) const
257 //------------------------------------------------------------------------
258 {
259     if(localId<_numberOfCells)
260         return _cellsId[localId];
261     else
262     {
263         std::cout<< "Local id requested : "<< localId<<" total number of cells= "<<_numberOfCells<<std::endl;
264         throw CdmathException("Face::getCellId : incorrect cell local id");
265     }
266 }