Salome HOME
402d6624998a78aedf174ca9e6706998d41e9482
[modules/med.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 "MEDCouplingSkyLineArray.hxx"
23
24 #include <map>
25
26 using namespace ParaMEDMEM;
27
28 MEDPARTITIONER::ConnectZone::ConnectZone():
29   _name("")
30   ,_description("")
31   ,_local_domain_number(0)
32   ,_distant_domain_number(0)
33   ,_node_corresp(0)
34   ,_face_corresp(0)
35 {
36 }
37
38 MEDPARTITIONER::ConnectZone::~ConnectZone()
39 {
40   delete _node_corresp;
41   delete _face_corresp;
42   for(std::map < std::pair <int, int>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
43     {
44       delete iter->second;
45     }
46 }
47
48 MEDPARTITIONER::ConnectZone::ConnectZone(const ConnectZone & myConnectZone):
49   _name(myConnectZone._name)
50   ,_description(myConnectZone._description)
51   ,_local_domain_number(myConnectZone._local_domain_number)
52   ,_distant_domain_number(myConnectZone._distant_domain_number)
53   ,_node_corresp(myConnectZone._node_corresp)
54   ,_face_corresp(myConnectZone._face_corresp)
55   ,_entity_corresp(myConnectZone._entity_corresp)
56 {
57 }
58
59 std::string MEDPARTITIONER::ConnectZone::getName() const 
60 {
61   return _name;
62 }
63
64 std::string MEDPARTITIONER::ConnectZone::getDescription() const     
65 {
66   return _description;
67 }
68
69 int MEDPARTITIONER::ConnectZone::getDistantDomainNumber() const 
70 {
71   return _distant_domain_number;
72 }
73
74 int MEDPARTITIONER::ConnectZone::getLocalDomainNumber() const 
75 {
76   return _local_domain_number;
77 }
78
79 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const 
80 {
81   return _local_mesh;
82 }
83
84 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const 
85 {
86   return _distant_mesh;
87 }
88
89 bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int distantEntity) const
90 {
91   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
92   for(map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
93     {
94       if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
95         return true;
96     }
97   return false;
98 }
99
100 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
101 {
102   return _node_corresp->getIndex();
103 }
104
105 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
106 {
107   return _node_corresp->getValue();
108 }
109
110 int MEDPARTITIONER::ConnectZone::getNodeNumber() const
111 {
112   return _node_corresp->getNumberOf();
113 }
114
115 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
116 {
117   return _node_corresp;
118 }
119
120 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
121 {
122   return _face_corresp->getIndex();
123 }
124
125 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
126 {
127   return _face_corresp->getValue();
128 }
129
130 int MEDPARTITIONER::ConnectZone::getFaceNumber() const
131 {
132   return _face_corresp->getNumberOf();
133 }
134
135 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
136 {
137   return _face_corresp;
138 }
139
140 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
141                                                               int distantEntity) const
142 {
143   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
144
145   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
146   {
147     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
148       return iter->second->getIndex();
149   }
150   return 0;
151 }
152
153 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity,
154                                                               int distantEntity) const
155 {
156   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
157
158   for (map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
159   {
160     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
161       return iter->second->getValue();
162   }
163   return 0;
164 }
165
166 int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
167                                                         int distantEntity) const
168 {
169   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
170
171   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
172   {
173     if((iter->first).first==localEntity && (iter->first).second==distantEntity)
174       return iter->second->getNumberOf();
175   }
176   return 0;
177 }
178
179 int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
180                                                         int distantEntity) const
181 {
182   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
183
184   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
185   {
186     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
187       return iter->second->getLength();
188   }
189   return 0;
190 }
191
192 const ParaMEDMEM::MEDCouplingSkyLineArray *
193 MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const
194 {
195   typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
196
197   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
198   {
199     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
200       return iter->second;
201   }
202   return 0;
203 }
204
205 std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const
206 {
207   std::vector< std::pair< int,int > > types;
208
209   std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator
210     iter = _entity_corresp.begin();
211   for ( ; iter != _entity_corresp.end(); iter++)
212     {
213       types.push_back( iter->first );
214     }
215
216   return types;
217 }
218
219 void MEDPARTITIONER::ConnectZone::setName(const std::string& name) 
220 {
221   _name=name;
222 }
223
224 void MEDPARTITIONER::ConnectZone::setDescription(const std::string& description)
225 {
226   _description=description;
227 }
228
229 void MEDPARTITIONER::ConnectZone::setDistantDomainNumber(int distantDomainNumber)
230 {
231   _distant_domain_number=distantDomainNumber;
232 }
233
234 void MEDPARTITIONER::ConnectZone::setLocalDomainNumber(int localDomainNumber)
235 {
236   _local_domain_number=localDomainNumber;
237 }
238
239 void MEDPARTITIONER::ConnectZone::setLocalMesh(ParaMEDMEM::MEDCouplingUMesh * localMesh)
240 {
241   _local_mesh=localMesh;
242 }
243
244 void MEDPARTITIONER::ConnectZone::setDistantMesh(ParaMEDMEM::MEDCouplingUMesh * distantMesh)
245 {
246   _distant_mesh=distantMesh;
247 }
248
249 /*! transforms an int array containing 
250  * the node-node connections
251  * to a MEDCouplingSkyLineArray
252  */
253 void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nbnode)
254 {
255   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
256   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
257   indexArr->alloc( nbnode+1 );
258   valueArr->alloc( 2*nbnode );
259   int * index = indexArr->getPointer();
260   int * value = valueArr->getPointer();
261   for (int i=0; i<nbnode; i++)
262     {
263       index[i]=2*i;
264       value[2*i  ]=nodeCorresp[2*i];
265       value[2*i+1]=nodeCorresp[2*i+1];
266     }
267   index[nbnode]=2*nbnode;
268   setNodeCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
269 }
270
271 void MEDPARTITIONER::ConnectZone::setNodeCorresp(MEDCouplingSkyLineArray* array)
272 {
273   if ( _node_corresp ) delete _node_corresp;
274   _node_corresp = array;
275 }
276
277 /*! transforms an int array containing 
278  * the face-face connections
279  * to a MEDCouplingSkyLineArray
280  */
281 void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nbface)
282 {
283   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
284   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
285   indexArr->alloc( nbface+1 );
286   valueArr->alloc( 2*nbface );
287   int * index = indexArr->getPointer();
288   int * value = valueArr->getPointer();
289   for (int i=0; i<nbface; i++)
290     {
291       index[i]=2*i;
292       value[2*i]=faceCorresp[2*i];
293       value[2*i+1]=faceCorresp[2*i+1];
294     }
295   index[nbface]=2*nbface;
296   setFaceCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
297 }
298
299 void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
300 {
301   if ( _face_corresp ) delete _face_corresp;
302   _face_corresp = array;
303 }
304
305 /*! transforms an int array containing 
306  * the entity-entity connections
307  * to a MEDCouplingSkyLineArray
308  * 
309  * the resulting MEDCouplingSkyLineArray is put in the map
310  */
311 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
312                                                    const int *entityCorresp, int nbentity)
313
314   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> indexArr( DataArrayInt::New() );
315   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> valueArr( DataArrayInt::New() );
316   indexArr->alloc( nbentity+1 );
317   valueArr->alloc( 2*nbentity );
318   int * index = indexArr->getPointer();
319   int * value = valueArr->getPointer();
320   for (int i=0; i<nbentity; i++)
321     {
322       index[i]=2*i;
323       value[2*i  ]=entityCorresp[2*i];
324       value[2*i+1]=entityCorresp[2*i+1];
325     }
326   index[nbentity]=2*nbentity;
327   setEntityCorresp( localEntity, distantEntity, new MEDCouplingSkyLineArray(indexArr,valueArr));
328 }
329
330 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
331                                                    MEDCouplingSkyLineArray *array)
332 {
333   ParaMEDMEM::MEDCouplingSkyLineArray * nullArray = 0;
334   std::map < std::pair <int,int>, ParaMEDMEM::MEDCouplingSkyLineArray * >::iterator it;
335   it = _entity_corresp.insert
336     ( std::make_pair( std::make_pair(localEntity,distantEntity), nullArray )).first;
337   if ( it->second != nullArray ) delete it->second;
338   it->second = array;
339 }