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