]> SALOME platform Git repositories - tools/solverlab.git/blob - CDMATH/mesh/src/Face.cxx
Salome HOME
Updated GUI documentation
[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 <algorithm> 
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         if(std::find(_groupNames.begin(), _groupNames.end(), groupName) == _groupNames.end())//No group named groupName
125         {
126                 _groupNames.insert(_groupNames.begin(),groupName);
127                 _region=0;
128         }
129         else
130                 cout<<"Warning Face::setGroupName, group name "<< groupName <<" is already present. No duplication"<<endl;
131 }
132
133 bool
134 Face::isBorder(void)
135 {
136         if (_region==0 || _numberOfCells==1)
137                 return true;
138         else
139                 return false;
140 }
141 //----------------------------------------------------------------------
142 Point
143 Face::getBarryCenter( void ) const
144 //----------------------------------------------------------------------
145 {
146         return _point ;
147 }
148
149 //----------------------------------------------------------------------
150 double
151 Face::x( void ) const
152 //----------------------------------------------------------------------
153 {
154   return _point.x() ;
155 }
156
157 //----------------------------------------------------------------------
158 double
159 Face::y( void ) const
160 //----------------------------------------------------------------------
161 {
162         return _point.y() ;
163 }
164
165 //----------------------------------------------------------------------
166 double
167 Face::z( void ) const
168 //----------------------------------------------------------------------
169 {
170         return _point.z() ;
171 }
172
173 //----------------------------------------------------------------------
174 std::vector< int >
175 Face::getCellsId( void ) const
176 //----------------------------------------------------------------------
177 {
178         return _cellsId ;
179 }
180
181 //----------------------------------------------------------------------
182 std::vector< int >
183 Face::getNodesId( void ) const
184 //----------------------------------------------------------------------
185 {
186         return _nodesId ;
187 }
188
189 //----------------------------------------------------------------------
190 double
191 Face::getMeasure( void ) const
192 //----------------------------------------------------------------------
193 {
194         return _measure ;
195 }
196
197 //----------------------------------------------------------------------
198 int
199 Face::getNumberOfCells( void ) const
200 //----------------------------------------------------------------------
201 {
202         return _numberOfCells ;
203 }
204
205 //----------------------------------------------------------------------
206 int
207 Face::getNumberOfNodes( void ) const
208 //----------------------------------------------------------------------
209 {
210         return _numberOfNodes ;
211 }
212
213 //----------------------------------------------------------------------
214 void
215 Face::addCellId(const int numCell, const int cellId )
216 //----------------------------------------------------------------------
217 {
218         _cellsId[numCell] = cellId ;
219 }
220 //----------------------------------------------------------------------
221 void
222 Face::addNodeId(const int numNode, const int nodeId )
223 //----------------------------------------------------------------------
224 {
225         _nodesId[numNode] = nodeId ;
226 }
227
228 //----------------------------------------------------------------------
229 const Face&
230 Face::operator= ( const Face& face )
231 //----------------------------------------------------------------------
232 {
233         _measure = face.getMeasure() ;
234         _point = face.getBarryCenter() ;
235         _numberOfCells = face.getNumberOfCells() ;
236         _numberOfNodes = face.getNumberOfNodes() ;
237         _nodesId=face.getNodesId();
238         _cellsId=face.getCellsId();
239         _groupNames=face.getGroupNames();
240         _region=face.getRegion();
241         _xN=face.getXN();
242         _yN=face.getYN();
243         _zN=face.getZN();
244         return *this;
245 }
246 //------------------------------------------------------------------------
247 int
248 Face::getNodeId(int localId) const
249 //------------------------------------------------------------------------
250 {
251     if(localId<_numberOfNodes)
252         return _nodesId[localId];
253     else
254     {
255         std::cout<< "Local id requested : "<< localId<<" total number of nodes= "<<_numberOfNodes<<std::endl;
256         throw CdmathException("Face::getNodeId : incorrect node local id");
257     }
258 }
259 //------------------------------------------------------------------------
260 int
261 Face::getCellId(int localId) const
262 //------------------------------------------------------------------------
263 {
264     if(localId<_numberOfCells)
265         return _cellsId[localId];
266     else
267     {
268         std::cout<< "Local id requested : "<< localId<<" total number of cells= "<<_numberOfCells<<std::endl;
269         throw CdmathException("Face::getCellId : incorrect cell local id");
270     }
271 }