1 // Copyright (C) 2007-2015 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"
24 using namespace ParaMEDMEM;
26 MEDPARTITIONER::ConnectZone::ConnectZone():
29 ,_local_domain_number(0)
30 ,_distant_domain_number(0)
36 MEDPARTITIONER::ConnectZone::~ConnectZone()
40 for(std::map < std::pair <int, int>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
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)
57 std::string MEDPARTITIONER::ConnectZone::getName() const
62 std::string MEDPARTITIONER::ConnectZone::getDescription() const
67 int MEDPARTITIONER::ConnectZone::getDistantDomainNumber() const
69 return _distant_domain_number;
72 int MEDPARTITIONER::ConnectZone::getLocalDomainNumber() const
74 return _local_domain_number;
77 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const
82 ParaMEDMEM::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const
87 bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int distantEntity) const
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++)
92 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
98 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
100 return _node_corresp->getIndex();
103 const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
105 return _node_corresp->getValue();
108 int MEDPARTITIONER::ConnectZone::getNodeNumber() const
110 return _node_corresp->getNumberOf();
113 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
115 return _node_corresp;
118 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
120 return _face_corresp->getIndex();
123 const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
125 return _face_corresp->getValue();
128 int MEDPARTITIONER::ConnectZone::getFaceNumber() const
130 return _face_corresp->getNumberOf();
133 const ParaMEDMEM::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
135 return _face_corresp;
138 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
139 int distantEntity) const
141 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
143 for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
145 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
146 return iter->second->getIndex();
151 const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity,
152 int distantEntity) const
154 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
156 for (map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
158 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
159 return iter->second->getValue();
164 int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
165 int distantEntity) const
167 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
169 for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
171 if((iter->first).first==localEntity && (iter->first).second==distantEntity)
172 return iter->second->getNumberOf();
177 int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
178 int distantEntity) const
180 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
182 for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
184 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
185 return iter->second->getLength();
190 const ParaMEDMEM::MEDCouplingSkyLineArray *
191 MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const
193 typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
195 for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
197 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
203 std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const
205 std::vector< std::pair< int,int > > types;
207 std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator
208 iter = _entity_corresp.begin();
209 for ( ; iter != _entity_corresp.end(); iter++)
211 types.push_back( iter->first );
217 void MEDPARTITIONER::ConnectZone::setName(const std::string& name)
222 void MEDPARTITIONER::ConnectZone::setDescription(const std::string& description)
224 _description=description;
227 void MEDPARTITIONER::ConnectZone::setDistantDomainNumber(int distantDomainNumber)
229 _distant_domain_number=distantDomainNumber;
232 void MEDPARTITIONER::ConnectZone::setLocalDomainNumber(int localDomainNumber)
234 _local_domain_number=localDomainNumber;
237 void MEDPARTITIONER::ConnectZone::setLocalMesh(ParaMEDMEM::MEDCouplingUMesh * localMesh)
239 _local_mesh=localMesh;
242 void MEDPARTITIONER::ConnectZone::setDistantMesh(ParaMEDMEM::MEDCouplingUMesh * distantMesh)
244 _distant_mesh=distantMesh;
247 /*! transforms an int array containing
248 * the node-node connections
249 * to a MEDCouplingSkyLineArray
251 void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nbnode)
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++)
262 value[2*i ]=nodeCorresp[2*i];
263 value[2*i+1]=nodeCorresp[2*i+1];
265 index[nbnode]=2*nbnode;
266 setNodeCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
269 void MEDPARTITIONER::ConnectZone::setNodeCorresp(MEDCouplingSkyLineArray* array)
271 if ( _node_corresp ) delete _node_corresp;
272 _node_corresp = array;
275 /*! transforms an int array containing
276 * the face-face connections
277 * to a MEDCouplingSkyLineArray
279 void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nbface)
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++)
290 value[2*i]=faceCorresp[2*i];
291 value[2*i+1]=faceCorresp[2*i+1];
293 index[nbface]=2*nbface;
294 setFaceCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
297 void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
299 if ( _face_corresp ) delete _face_corresp;
300 _face_corresp = array;
303 /*! transforms an int array containing
304 * the entity-entity connections
305 * to a MEDCouplingSkyLineArray
307 * the resulting MEDCouplingSkyLineArray is put in the map
309 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
310 const int *entityCorresp, int nbentity)
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++)
321 value[2*i ]=entityCorresp[2*i];
322 value[2*i+1]=entityCorresp[2*i+1];
324 index[nbentity]=2*nbentity;
325 setEntityCorresp( localEntity, distantEntity, new MEDCouplingSkyLineArray(indexArr,valueArr));
328 void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
329 MEDCouplingSkyLineArray *array)
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;