1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPARTITIONER_ConnectZone.hxx"
22 #include "MEDCouplingSkyLineArray.hxx"
26 using namespace MEDCoupling;
28 MEDPARTITIONER::ConnectZone::ConnectZone():
31 ,_local_domain_number(0)
32 ,_distant_domain_number(0)
38 MEDPARTITIONER::ConnectZone::~ConnectZone()
42 for(std::map < std::pair <int, int>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
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)
59 std::string MEDPARTITIONER::ConnectZone::getName() const
64 std::string MEDPARTITIONER::ConnectZone::getDescription() const
69 int MEDPARTITIONER::ConnectZone::getDistantDomainNumber() const
71 return _distant_domain_number;
74 int MEDPARTITIONER::ConnectZone::getLocalDomainNumber() const
76 return _local_domain_number;
79 MEDCoupling::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const
84 MEDCoupling::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const
89 bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int distantEntity) const
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++)
94 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
100 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
102 return _node_corresp->getIndex();
105 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
107 return _node_corresp->getValue();
110 int MEDPARTITIONER::ConnectZone::getNodeNumber() const
112 return _node_corresp->getNumberOf();
115 const MEDCoupling::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
117 return _node_corresp;
120 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
122 return _face_corresp->getIndex();
125 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
127 return _face_corresp->getValue();
130 int MEDPARTITIONER::ConnectZone::getFaceNumber() const
132 return _face_corresp->getNumberOf();
135 const MEDCoupling::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
137 return _face_corresp;
140 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
141 int distantEntity) const
143 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
145 for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
147 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
148 return iter->second->getIndex();
153 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity,
154 int distantEntity) const
156 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
158 for (map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
160 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
161 return iter->second->getValue();
166 int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
167 int distantEntity) const
169 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
171 for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
173 if((iter->first).first==localEntity && (iter->first).second==distantEntity)
174 return iter->second->getNumberOf();
179 int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
180 int distantEntity) const
182 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
184 for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
186 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
187 return iter->second->getLength();
192 const MEDCoupling::MEDCouplingSkyLineArray *
193 MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const
195 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
197 for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
199 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
205 std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const
207 std::vector< std::pair< int,int > > types;
209 std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator
210 iter = _entity_corresp.begin();
211 for ( ; iter != _entity_corresp.end(); iter++)
213 types.push_back( iter->first );
219 void MEDPARTITIONER::ConnectZone::setName(const std::string& name)
224 void MEDPARTITIONER::ConnectZone::setDescription(const std::string& description)
226 _description=description;
229 void MEDPARTITIONER::ConnectZone::setDistantDomainNumber(int distantDomainNumber)
231 _distant_domain_number=distantDomainNumber;
234 void MEDPARTITIONER::ConnectZone::setLocalDomainNumber(int localDomainNumber)
236 _local_domain_number=localDomainNumber;
239 void MEDPARTITIONER::ConnectZone::setLocalMesh(MEDCoupling::MEDCouplingUMesh * localMesh)
241 _local_mesh=localMesh;
244 void MEDPARTITIONER::ConnectZone::setDistantMesh(MEDCoupling::MEDCouplingUMesh * distantMesh)
246 _distant_mesh=distantMesh;
249 /*! transforms an int array containing
250 * the node-node connections
251 * to a MEDCouplingSkyLineArray
253 void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nbnode)
255 MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
256 MCAuto<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++)
264 value[2*i ]=nodeCorresp[2*i];
265 value[2*i+1]=nodeCorresp[2*i+1];
267 index[nbnode]=2*nbnode;
268 setNodeCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
271 void MEDPARTITIONER::ConnectZone::setNodeCorresp(MEDCouplingSkyLineArray* array)
273 if ( _node_corresp ) delete _node_corresp;
274 _node_corresp = array;
277 /*! transforms an int array containing
278 * the face-face connections
279 * to a MEDCouplingSkyLineArray
281 void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nbface)
283 MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
284 MCAuto<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++)
292 value[2*i]=faceCorresp[2*i];
293 value[2*i+1]=faceCorresp[2*i+1];
295 index[nbface]=2*nbface;
296 setFaceCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
299 void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
301 if ( _face_corresp ) delete _face_corresp;
302 _face_corresp = array;
305 /*! transforms an int array containing
306 * the entity-entity connections
307 * to a MEDCouplingSkyLineArray
309 * the resulting MEDCouplingSkyLineArray is put in the map
311 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
312 const int *entityCorresp, int nbentity)
314 MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
315 MCAuto<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++)
323 value[2*i ]=entityCorresp[2*i];
324 value[2*i+1]=entityCorresp[2*i+1];
326 index[nbentity]=2*nbentity;
327 setEntityCorresp( localEntity, distantEntity, new MEDCouplingSkyLineArray(indexArr,valueArr));
330 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
331 MEDCouplingSkyLineArray *array)
333 MEDCoupling::MEDCouplingSkyLineArray * nullArray = 0;
334 std::map < std::pair <int,int>, MEDCoupling::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;