]> SALOME platform Git repositories - tools/solverlab.git/blob - CDMATH/mesh/src/Node.cxx
Salome HOME
Updated GUI documentation
[tools/solverlab.git] / CDMATH / mesh / src / Node.cxx
1 /*
2  * Node.cxx
3  *
4  *  Created on: 23 janv. 2012
5  *      Authors: CDMAT
6  */
7
8 #include "Node.hxx"
9 #include "CdmathException.hxx"
10 #include <algorithm> 
11
12 //----------------------------------------------------------------------
13 Node::Node( void )
14 //----------------------------------------------------------------------
15 {
16         _numberOfCells = 0 ;
17         _numberOfFaces = 0 ;
18         _numberOfEdges = 0 ;
19         _groupNames=std::vector<std::string>(0);
20         _region=-1;
21     _isBorder=false;
22 }
23
24 //----------------------------------------------------------------------
25 Node::~Node( void )
26 //----------------------------------------------------------------------
27 {
28 }
29
30 //----------------------------------------------------------------------
31 Node::Node( const Node& node )
32 //----------------------------------------------------------------------
33 {
34         _point = node.getPoint() ;
35         _cellsId = node.getCellsId() ;
36         _facesId = node.getFacesId() ;
37         _numberOfCells = node.getNumberOfCells() ;
38         _numberOfFaces = node.getNumberOfFaces() ;
39         _numberOfEdges = node.getNumberOfEdges() ;
40         _groupNames=node.getGroupNames();
41         _region=node.getRegion();
42     _isBorder=node.isBorder();
43 }
44
45 //----------------------------------------------------------------------
46 Node::Node( const int numberOfCells, const int numberOfFaces, const int numberOfEdges, const Point p)
47 //----------------------------------------------------------------------
48 {
49
50         _point = p ;
51         _numberOfCells = numberOfCells ;
52         _numberOfFaces = numberOfFaces ;
53         _numberOfEdges = numberOfEdges ;
54         _cellsId = std::vector< int >(_numberOfCells,0);
55         _facesId = std::vector< int >(_numberOfFaces,0);
56         _neighbourNodesId = std::vector< int >(_numberOfEdges,0);
57         _groupNames=std::vector<std::string>(0);
58         _region=-1;
59     _isBorder=false;
60 }
61
62 //----------------------------------------------------------------------
63 std::vector< int >
64 Node::getCellsId( void ) const 
65 //----------------------------------------------------------------------
66 {
67         return _cellsId ;
68 }
69
70 //----------------------------------------------------------------------
71 std::vector< int >
72 Node::getFacesId( void ) const 
73 //----------------------------------------------------------------------
74 {
75         return _facesId ;
76 }
77
78 //----------------------------------------------------------------------
79 std::vector< int >
80 Node::getNeighbourNodesId( void ) const 
81 //----------------------------------------------------------------------
82 {
83         return _neighbourNodesId ;
84 }
85
86 //----------------------------------------------------------------------
87 int
88 Node::getNumberOfCells( void ) const 
89 //----------------------------------------------------------------------
90 {
91         return _numberOfCells ;
92 }
93
94 //----------------------------------------------------------------------
95 int
96 Node::getNumberOfFaces( void ) const 
97 //----------------------------------------------------------------------
98 {
99         return _numberOfFaces ;
100 }
101
102 //----------------------------------------------------------------------
103 int
104 Node::getNumberOfEdges( void ) const 
105 //----------------------------------------------------------------------
106 {
107         return _numberOfEdges ;
108 }
109
110 //----------------------------------------------------------------------
111 Point
112 Node::getPoint( void ) const
113 //----------------------------------------------------------------------
114 {
115         return _point ;
116 }
117
118 //----------------------------------------------------------------------
119 double
120 Node::x( void ) const 
121 //----------------------------------------------------------------------
122 {
123         return _point.x() ;
124 }
125
126 //----------------------------------------------------------------------
127 double
128 Node::y( void ) const 
129 //----------------------------------------------------------------------
130 {
131         return _point.y() ;
132 }
133
134 //----------------------------------------------------------------------
135 double
136 Node::z( void ) const 
137 //----------------------------------------------------------------------
138 {
139         return _point.z() ;
140 }
141
142 std::vector<std::string>
143 Node::getGroupNames(void) const
144 {
145         return _groupNames;
146 }
147
148 std::string
149 Node::getGroupName(int igroup) const
150 {
151     if (igroup<_groupNames.size())
152         return _groupNames[igroup];
153     else
154     {
155         std::cout<<"Error Node::getGroupName(int igroup), group number "<<igroup+1<<" requested"<<std::endl;
156         std::cout<<"Node belongs to "<< _groupNames.size() <<" groups"<<std::endl;
157         throw CdmathException("Node has no group with number igroup");
158     }
159 }
160
161 void
162 Node::setGroupName(const std::string groupName)
163 {
164         if(std::find(_groupNames.begin(), _groupNames.end(), groupName) == _groupNames.end())//No group named groupName
165         {
166                 _groupNames.insert(_groupNames.begin(),groupName);
167                 _region=0;
168         }
169         else
170                 std::cout<<"Warning Node::setGroupName, group name "<< groupName <<" is already present. No duplication"<<std::endl;
171 }
172
173 bool
174 Node::isBorder(void) const
175 {
176         if (_region==0 | _isBorder)
177                 return true;
178         else
179                 return false;
180 }
181
182 int
183 Node::getRegion(void) const
184 {
185         return _region;
186 }
187
188 //----------------------------------------------------------------------
189 void
190 Node::addFaceId (const int numFace, const int faceId, bool isBorder  )
191 //----------------------------------------------------------------------
192 {
193         _facesId[numFace] = faceId ;
194     if(isBorder)
195     {
196         if(std::find(_groupNames.begin(), _groupNames.end(), "Boundary") == _groupNames.end())//No group named Boundary
197             _groupNames.insert(_groupNames.begin(),"Boundary");
198         _isBorder=true;
199     }
200 }
201
202 //----------------------------------------------------------------------
203 void
204 Node::addCellId (const int numCell, const int cellId )
205 //----------------------------------------------------------------------
206 {
207         _cellsId[numCell] = cellId ;
208 }
209
210 //----------------------------------------------------------------------
211 void
212 Node::addNeighbourNodeId (const int numNode, const int nodeId ) 
213 //----------------------------------------------------------------------
214 {
215         _neighbourNodesId[numNode] = nodeId ;
216 }
217
218 //----------------------------------------------------------------------
219 double
220 Node::distance( const Node& n ) const
221 //----------------------------------------------------------------------
222 {
223         double distance=_point.distance(n.getPoint());
224         return distance ;
225 }
226
227 //----------------------------------------------------------------------
228 int
229 //----------------------------------------------------------------------
230 Node::getFaceId(int localId) const
231 //----------------------------------------------------------------------
232 {
233     if(localId<_numberOfFaces)
234         return _facesId[localId];
235     else
236     {
237         std::cout<< "Local id requested : "<< localId<<", total number of faces= "<<_numberOfFaces<<std::endl;
238         throw CdmathException("Node::getFaceId : incorrect face local id");
239     }
240 }
241
242 //----------------------------------------------------------------------
243 int
244 //----------------------------------------------------------------------
245 Node::getNeighbourNodeId(int localId) const
246 //----------------------------------------------------------------------
247 {
248     if(localId<_numberOfEdges)
249         return _neighbourNodesId[localId];
250     else
251     {
252         std::cout<< "Local id requested : "<< localId<<", total number of edges= "<<_numberOfEdges<<std::endl;
253         throw CdmathException("Node::getNeighbourNodeId : incorrect node local id");
254     }
255 }
256
257 const Node& 
258 Node::operator= ( const Node& node )
259 //----------------------------------------------------------------------
260 {
261    _point = node.getPoint()  ;
262    _cellsId = node.getCellsId() ;
263    _facesId = node.getFacesId() ;
264    _neighbourNodesId = node.getNeighbourNodesId() ;
265    _numberOfCells = node.getNumberOfCells() ;
266    _numberOfFaces = node.getNumberOfFaces() ;
267    _numberOfEdges = node.getNumberOfEdges() ;
268    _groupNames = node.getGroupNames();  
269    _isBorder=node.isBorder();
270         return *this;
271 }