Salome HOME
78fd1a0f49658cd085b8f1455f9f1e5b7a902239
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_ConnectZone.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDPARTITIONER_ConnectZone.hxx"
21
22 #include <map>
23
24 using namespace ParaMEDMEM;
25
26 MEDPARTITIONER::ConnectZone::ConnectZone():
27   _name("")
28   ,_description("")
29   ,_local_domain_number(0)
30   ,_distant_domain_number(0)
31   ,_node_corresp(0)
32   ,_face_corresp(0)
33 {
34 }
35
36 MEDPARTITIONER::ConnectZone::~ConnectZone()
37 {
38   delete _node_corresp;
39   delete _face_corresp;
40   for(std::map < std::pair <int, int>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
41     {
42       delete iter->second;
43     }
44 }
45
46 MEDPARTITIONER::ConnectZone::ConnectZone(const ConnectZone & myConnectZone):
47   _name(myConnectZone._name)
48   ,_description(myConnectZone._description)
49   ,_local_domain_number(myConnectZone._local_domain_number)
50   ,_distant_domain_number(myConnectZone._distant_domain_number)
51   ,_node_corresp(myConnectZone._node_corresp)
52   ,_face_corresp(myConnectZone._face_corresp)
53   ,_entity_corresp(myConnectZone._entity_corresp)
54 {
55 }
56
57 std::string MEDPARTITIONER::ConnectZone::getName() const 
58 {
59   return _name;
60 }
61
62 std::string MEDPARTITIONER::ConnectZone::getDescription() const     
63 {
64   return _description;
65 }
66
67 int MEDPARTITIONER::ConnectZone::getDistantDomainNumber() const 
68 {
69   return _distant_domain_number;
70 }
71
72 int MEDPARTITIONER::ConnectZone::getLocalDomainNumber() const 
73 {
74   return _local_domain_number;
75 }
76
77 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const 
78 {
79   return _local_mesh;
80 }
81
82 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const 
83 {
84   return _distant_mesh;
85 }
86
87 bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int distantEntity) const
88 {
89   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
90   for(map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
91     {
92       if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
93         return true;
94     }
95   return false;
96 }
97
98 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
99 {
100   return _node_corresp->getIndex();
101 }
102
103 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
104 {
105   return _node_corresp->getValue();
106 }
107
108 int MEDPARTITIONER::ConnectZone::getNodeNumber() const
109 {
110   return _node_corresp->getNumberOf();
111 }
112
113 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
114 {
115   return _node_corresp;
116 }
117
118 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
119 {
120   return _face_corresp->getIndex();
121 }
122
123 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
124 {
125   return _face_corresp->getValue();
126 }
127
128 int MEDPARTITIONER::ConnectZone::getFaceNumber() const
129 {
130   return _face_corresp->getNumberOf();
131 }
132
133 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
134 {
135   return _face_corresp;
136 }
137
138 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
139                                                               int distantEntity) const
140 {
141   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
142
143   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
144   {
145     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
146       return iter->second->getIndex();
147   }
148   return 0;
149 }
150
151 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity,
152                                                               int distantEntity) const
153 {
154   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
155
156   for (map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
157   {
158     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
159       return iter->second->getValue();
160   }
161   return 0;
162 }
163
164 int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
165                                                         int distantEntity) const
166 {
167   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
168
169   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
170   {
171     if((iter->first).first==localEntity && (iter->first).second==distantEntity)
172       return iter->second->getNumberOf();
173   }
174   return 0;
175 }
176
177 int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
178                                                         int distantEntity) const
179 {
180   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
181
182   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
183   {
184     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
185       return iter->second->getLength();
186   }
187   return 0;
188 }
189
190 const ParaMEDMEM::MEDCouplingSkyLineArray *
191 MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const
192 {
193   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
194
195   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
196   {
197     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
198       return iter->second;
199   }
200   return 0;
201 }
202
203 std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const
204 {
205   std::vector< std::pair< int,int > > types;
206
207   std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator
208     iter = _entity_corresp.begin();
209   for ( ; iter != _entity_corresp.end(); iter++)
210     {
211       types.push_back( iter->first );
212     }
213
214   return types;
215 }
216
217 void MEDPARTITIONER::ConnectZone::setName(const std::string& name) 
218 {
219   _name=name;
220 }
221
222 void MEDPARTITIONER::ConnectZone::setDescription(const std::string& description)
223 {
224   _description=description;
225 }
226
227 void MEDPARTITIONER::ConnectZone::setDistantDomainNumber(int distantDomainNumber)
228 {
229   _distant_domain_number=distantDomainNumber;
230 }
231
232 void MEDPARTITIONER::ConnectZone::setLocalDomainNumber(int localDomainNumber)
233 {
234   _local_domain_number=localDomainNumber;
235 }
236
237 void MEDPARTITIONER::ConnectZone::setLocalMesh(ParaMEDMEM::MEDCouplingUMesh * localMesh)
238 {
239   _local_mesh=localMesh;
240 }
241
242 void MEDPARTITIONER::ConnectZone::setDistantMesh(ParaMEDMEM::MEDCouplingUMesh * distantMesh)
243 {
244   _distant_mesh=distantMesh;
245 }
246
247 /*! transforms an int array containing 
248  * the node-node connections
249  * to a MEDCouplingSkyLineArray
250  */
251 void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nbnode)
252 {
253   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
254   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
255   indexArr->alloc( nbnode+1 );
256   valueArr->alloc( 2*nbnode );
257   int * index = indexArr->getPointer();
258   int * value = valueArr->getPointer();
259   for (int i=0; i<nbnode; i++)
260     {
261       index[i]=2*i;
262       value[2*i  ]=nodeCorresp[2*i];
263       value[2*i+1]=nodeCorresp[2*i+1];
264     }
265   index[nbnode]=2*nbnode;
266   setNodeCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
267 }
268
269 void MEDPARTITIONER::ConnectZone::setNodeCorresp(MEDCouplingSkyLineArray* array)
270 {
271   if ( _node_corresp ) delete _node_corresp;
272   _node_corresp = array;
273 }
274
275 /*! transforms an int array containing 
276  * the face-face connections
277  * to a MEDCouplingSkyLineArray
278  */
279 void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nbface)
280 {
281   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
282   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
283   indexArr->alloc( nbface+1 );
284   valueArr->alloc( 2*nbface );
285   int * index = indexArr->getPointer();
286   int * value = valueArr->getPointer();
287   for (int i=0; i<nbface; i++)
288     {
289       index[i]=2*i;
290       value[2*i]=faceCorresp[2*i];
291       value[2*i+1]=faceCorresp[2*i+1];
292     }
293   index[nbface]=2*nbface;
294   setFaceCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
295 }
296
297 void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
298 {
299   if ( _face_corresp ) delete _face_corresp;
300   _face_corresp = array;
301 }
302
303 /*! transforms an int array containing 
304  * the entity-entity connections
305  * to a MEDCouplingSkyLineArray
306  * 
307  * the resulting MEDCouplingSkyLineArray is put in the map
308  */
309 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
310                                                    const int *entityCorresp, int nbentity)
311
312   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
313   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
314   indexArr->alloc( nbentity+1 );
315   valueArr->alloc( 2*nbentity );
316   int * index = indexArr->getPointer();
317   int * value = valueArr->getPointer();
318   for (int i=0; i<nbentity; i++)
319     {
320       index[i]=2*i;
321       value[2*i  ]=entityCorresp[2*i];
322       value[2*i+1]=entityCorresp[2*i+1];
323     }
324   index[nbentity]=2*nbentity;
325   setEntityCorresp( localEntity, distantEntity, new MEDCouplingSkyLineArray(indexArr,valueArr));
326 }
327
328 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
329                                                    MEDCouplingSkyLineArray *array)
330 {
331   ParaMEDMEM::MEDCouplingSkyLineArray * nullArray = 0;
332   std::map < std::pair <int,int>, ParaMEDMEM::MEDCouplingSkyLineArray * >::iterator it;
333   it = _entity_corresp.insert
334     ( std::make_pair( std::make_pair(localEntity,distantEntity), nullArray )).first;
335   if ( it->second != nullArray ) delete it->second;
336   it->second = array;
337 }