Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDMEM / MEDMEM_ConnectZone.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // few STL include files
24 //
25 #include <map>
26
27 // few Med Memory include files
28 #include "MEDMEM_define.hxx"
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_SkyLineArray.hxx"
31 #include "MEDMEM_ConnectZone.hxx"
32
33 using namespace MEDMEM;
34
35   CONNECTZONE::CONNECTZONE():
36   _name("")
37   ,_description("")
38   ,_localDomainNumber(0)
39   ,_distantDomainNumber(0)
40   ,_nodeCorresp(0)
41   ,_faceCorresp(0)
42   {
43         _entityCorresp.clear();
44   }
45   
46   CONNECTZONE::~CONNECTZONE(){
47   if (_nodeCorresp !=0) delete _nodeCorresp;
48   if (_faceCorresp !=0) delete _faceCorresp;
49   for (map < pair <MED_EN::medEntityMesh, MED_EN::medEntityMesh>,MEDMEM::MEDSKYLINEARRAY * >::iterator 
50    iter = _entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
51    {
52                 delete iter->second;
53    }
54   }
55   
56   CONNECTZONE::CONNECTZONE(const CONNECTZONE & myConnectZone):
57   _name(myConnectZone._name)
58   ,_description(myConnectZone._description)
59   ,_localDomainNumber(myConnectZone._localDomainNumber)
60   ,_distantDomainNumber(myConnectZone._distantDomainNumber)
61   ,_nodeCorresp(myConnectZone._nodeCorresp)
62   ,_faceCorresp(myConnectZone._faceCorresp)
63   ,_entityCorresp(myConnectZone._entityCorresp)
64   {
65   }
66   string CONNECTZONE::getName() const 
67   {
68         return _name;
69   }
70   string CONNECTZONE::getDescription() const 
71   {
72         return _description;
73   }
74   int CONNECTZONE::getDistantDomainNumber() const 
75   {
76         return _distantDomainNumber;
77   }
78   int CONNECTZONE::getLocalDomainNumber() const 
79   {
80         return _localDomainNumber;
81   }
82   
83   MEDMEM::MESH * CONNECTZONE::getLocalMesh() const 
84   {
85         return _localMesh;
86   }
87   
88   MEDMEM::MESH * CONNECTZONE::getDistantMesh() const 
89   {
90         return _distantMesh;
91   }
92
93   bool CONNECTZONE::isEntityCorrespPresent(MED_EN::medEntityMesh localEntity,
94                               MED_EN::medEntityMesh distantEntity) const
95 {
96         typedef map<pair<MED_EN::medEntityMesh,MED_EN::medEntityMesh>, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter;
97         
98         for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
99         {
100                 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
101                         return true;
102         }
103         return false;
104 }                
105               
106   const int * CONNECTZONE::getNodeCorrespIndex() const
107   {
108         return _nodeCorresp->getIndex();
109   }
110   
111   const int * CONNECTZONE::getNodeCorrespValue() const
112   {
113         return _nodeCorresp->getValue();
114   }
115   int CONNECTZONE::getNodeNumber() const
116   {
117         return _nodeCorresp->getNumberOf();
118   }
119   const int * CONNECTZONE::getFaceCorrespIndex() const
120   {
121         return _faceCorresp->getIndex();
122   }
123   
124   const int * CONNECTZONE::getFaceCorrespValue() const
125   {
126         return _faceCorresp->getValue();
127   }
128   int CONNECTZONE::getFaceNumber() const
129   {
130         return _faceCorresp->getNumberOf();
131   }
132 const int * CONNECTZONE::getEntityCorrespIndex(MED_EN::medEntityMesh localEntity,
133                                     MED_EN::medEntityMesh distantEntity) const
134 {
135         typedef map<pair<MED_EN::medEntityMesh,MED_EN::medEntityMesh>, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter;
136         
137         for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
138         {
139                 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
140                         return iter->second->getIndex();
141         }
142         return 0;                       
143 }
144
145 const int * CONNECTZONE::getEntityCorrespValue(MED_EN::medEntityMesh localEntity,
146                                     MED_EN::medEntityMesh distantEntity) const
147 {
148         typedef map<pair<MED_EN::medEntityMesh,MED_EN::medEntityMesh>, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter;
149         
150         for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
151         {
152                 if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
153                         return iter->second->getValue();
154         }
155         return 0;                       
156 }
157
158 int CONNECTZONE::getEntityCorrespNumber(MED_EN::medEntityMesh localEntity,
159                   MED_EN::medEntityMesh distantEntity) const
160 {
161   typedef map<pair<MED_EN::medEntityMesh,MED_EN::medEntityMesh>, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter;
162   
163   for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
164   {
165     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
166       return iter->second->getNumberOf();
167   }
168   return 0;           
169 }
170
171
172 int CONNECTZONE::getEntityCorrespLength(MED_EN::medEntityMesh localEntity,
173                   MED_EN::medEntityMesh distantEntity) const
174 {
175   typedef map<pair<MED_EN::medEntityMesh,MED_EN::medEntityMesh>, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter;
176   
177   for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++)
178   {
179     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
180       return iter->second->getLength();
181   }
182   return 0;           
183 }
184
185   void CONNECTZONE::setName(string name) 
186   {
187         _name=name;
188   }
189   void CONNECTZONE::setDescription(string description)
190   {
191         _description=description;
192   }
193   void CONNECTZONE::setDistantDomainNumber(int distantDomainNumber)
194   {
195         _distantDomainNumber=distantDomainNumber;
196   }
197   void CONNECTZONE::setLocalDomainNumber(int localDomainNumber)
198   {
199         _localDomainNumber=localDomainNumber;
200   }
201   void CONNECTZONE::setLocalMesh(MEDMEM::MESH * localMesh)
202   {
203         _localMesh=localMesh;
204   }
205   
206   void CONNECTZONE::setDistantMesh(MEDMEM::MESH * distantMesh)
207   {
208         _distantMesh=distantMesh;
209   }
210
211 /*! transforms an int array containing 
212  * the node-node connections
213  * to a MEDSKYLINEARRAY
214  */
215   void CONNECTZONE::setNodeCorresp(int * nodeCorresp, int nbnode)
216   {
217         int* index= new int[nbnode];
218         for (int i=0; i<nbnode; i++)
219         {
220                 index[i]=2*i;
221         }
222         _nodeCorresp = new MEDMEM::MEDSKYLINEARRAY(nbnode, 2*nbnode, index, nodeCorresp);
223   }
224   
225   void CONNECTZONE::setNodeCorresp(MEDMEM::MEDSKYLINEARRAY* array)
226   {
227         _nodeCorresp = array;
228   }
229   /*! transforms an int array containing 
230  * the face-face connections
231  * to a MEDSKYLINEARRAY
232  */
233   void CONNECTZONE::setFaceCorresp(int * faceCorresp, int nbface)
234   {
235         int* index= new int[nbface];
236         for (int i=0; i<nbface; i++)
237         {
238                 index[i]=2*i;
239         }
240         _faceCorresp = new MEDMEM::MEDSKYLINEARRAY(nbface, 2*nbface, index, faceCorresp);
241   }
242   
243   void CONNECTZONE::setFaceCorresp(MEDMEM::MEDSKYLINEARRAY* array)
244   {
245         _faceCorresp = array;
246   }
247   
248   /*! transforms an int array containing 
249  * the entity-entity connections
250  * to a MEDSKYLINEARRAY
251  * 
252  * the resulting MEDSKYLINEARRAY is put in the map
253  */
254   void CONNECTZONE::setEntityCorresp(MED_EN::medEntityMesh localEntity,
255                         MED_EN::medEntityMesh distantEntity,
256                         int * entityCorresp, int nbentity)
257   {
258         int* index= new int[nbentity];
259         for (int i=0; i<nbentity; i++)
260         {
261                 index[i]=2*i;
262         }
263         _entityCorresp[make_pair(localEntity,distantEntity)]=
264          new MEDMEM::MEDSKYLINEARRAY(nbentity, 2*nbentity, index, entityCorresp);
265   }
266   
267   
268     void CONNECTZONE::setEntityCorresp(MED_EN::medEntityMesh localEntity,
269                         MED_EN::medEntityMesh distantEntity,
270                         MEDMEM::MEDSKYLINEARRAY* array)
271   {
272         _entityCorresp[make_pair(localEntity,distantEntity)]=array;
273   }
274   
275
276
277
278
279
280