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