]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling/MEDCoupling1GTUMesh.cxx
Salome HOME
d80bf9374287fa388401739d1c603e4b3f0b222a
[tools/medcoupling.git] / src / MEDCoupling / MEDCoupling1GTUMesh.cxx
1 // Copyright (C) 2007-2013  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.
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 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCoupling1GTUMesh.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingFieldDouble.hxx"
24
25 #include "SplitterTetra.hxx"
26
27 using namespace ParaMEDMEM;
28
29 MEDCoupling1GTUMesh::MEDCoupling1GTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):_cm(&cm)
30 {
31   setName(name);
32 }
33
34 MEDCoupling1GTUMesh::MEDCoupling1GTUMesh(const MEDCoupling1GTUMesh& other, bool recDeepCpy):MEDCouplingPointSet(other,recDeepCpy),_cm(other._cm)
35 {
36 }
37
38 MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
39 {
40   if(type==INTERP_KERNEL::NORM_ERROR)
41     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
42   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
43   if(!cm.isDynamic())
44     return MEDCoupling1SGTUMesh::New(name,type);
45   else
46     return MEDCoupling1DGTUMesh::New(name,type);
47 }
48
49 MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
50 {
51   if(!m)
52     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh is null !");
53   std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
54   if(gts.size()!=1)
55     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh must have exactly one geometric type !");
56   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*gts.begin());
57   if(!cm.isDynamic())
58     return MEDCoupling1SGTUMesh::New(m);
59   else
60     return MEDCoupling1DGTUMesh::New(m);
61 }
62
63 const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception)
64 {
65   return *_cm;
66 }
67
68 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getCellModelEnum() const throw(INTERP_KERNEL::Exception)
69 {
70   return _cm->getEnum();
71 }
72
73 int MEDCoupling1GTUMesh::getMeshDimension() const
74 {
75   return (int)_cm->getDimension();
76 }
77
78 /*!
79  * This method returns a newly allocated array containing cell ids (ascendingly sorted) whose geometric type are equal to type.
80  * This method does not throw exception if geometric type \a type is not in \a this.
81  * This method throws an INTERP_KERNEL::Exception if meshdimension of \b this is not equal to those of \b type.
82  * The coordinates array is not considered here.
83  *
84  * \param [in] type the geometric type
85  * \return cell ids in this having geometric type \a type.
86  */
87 DataArrayInt *MEDCoupling1GTUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
88 {
89   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
90   if(type==getCellModelEnum())
91     ret->alloc(getNumberOfCells(),1);
92   else
93     ret->alloc(0,1);
94   ret->iota();
95   return ret.retn();
96 }
97
98 /*!
99  * Returns nb of cells having the geometric type \a type. No throw if no cells in \a this has the geometric type \a type.
100  */
101 int MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
102 {
103   return type==getCellModelEnum()?getNumberOfCells():0;
104 }
105
106 /*!
107  * Returns a type of a cell by its id.
108  *  \param [in] cellId - the id of the cell of interest.
109  *  \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type.
110  *  \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ).
111  */
112 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(int cellId) const
113 {
114   if(cellId>=0 && cellId<getNumberOfCells())
115     return getCellModelEnum();
116   std::ostringstream oss; oss << "MEDCoupling1GTUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << getNumberOfCells() << ") !";
117   throw INTERP_KERNEL::Exception(oss.str().c_str());
118 }
119
120 /*!
121  * Returns a set of all cell types available in \a this mesh.
122  * \return std::set<INTERP_KERNEL::NormalizedCellType> - the set of cell types.
123  * \warning this method does not throw any exception even if \a this is not defined.
124  */
125 std::set<INTERP_KERNEL::NormalizedCellType> MEDCoupling1GTUMesh::getAllGeoTypes() const
126 {
127   std::set<INTERP_KERNEL::NormalizedCellType> ret;
128   ret.insert(getCellModelEnum());
129   return ret;
130 }
131
132 /*!
133  * This method expects that \a this is sorted by types. If not an exception will be thrown.
134  * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how
135  * \a this is composed in cell types.
136  * The returned array is of size 3*n where n is the number of different types present in \a this. 
137  * For every k in [0,n] ret[3*k+2]==-1 because it has no sense here. 
138  * This parameter is kept only for compatibility with other methode listed above.
139  */
140 std::vector<int> MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
141 {
142   std::vector<int> ret(3);
143   ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=-1;
144   return ret;
145 }
146
147 /*!
148  * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in \a profile it returns a list of sub-profiles sorted by geo type.
149  * The result is put in the array \a idsPerType. In the returned parameter \a code, foreach i \a code[3*i+2] refers (if different from -1) to a location into the \a idsPerType.
150  * This method has 1 input \a profile and 3 outputs \a code \a idsInPflPerType and \a idsPerType.
151  * 
152  * \param [out] code is a vector of size 3*n where n is the number of different geometric type in \a this \b reduced to the profile \a profile. \a code has exactly the same semantic than in MEDCouplingUMesh::checkTypeConsistencyAndContig method.
153  * \param [out] idsInPflPerType is a vector of size of different geometric type in the subpart defined by \a profile of \a this ( equal to \a code.size()/3). For each i,
154  *              \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0]
155  * \param [out] idsPerType is a vector of size of different sub profiles needed to be defined to represent the profile \a profile for a given geometric type.
156  *              This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile.
157  * 
158  * \warning for performance reasons no deep copy will be performed, if \a profile can been used as this in output parameters \a idsInPflPerType and \a idsPerType.
159  *
160  * \throw if \a profile has not exactly one component. It throws too, if \a profile contains some values not in [0,getNumberOfCells()) or if \a this is not fully defined
161  *
162  *  \b Example1: <br>
163  *          - Before \a this has 3 cells \a profile contains [0,1,2]
164  *          - After \a code contains [NORM_...,nbCells,-1], \a idsInPflPerType [[0,1,2]] and \a idsPerType is empty <br>
165  * 
166  *  \b Example2: <br>
167  *          - Before \a this has 3 cells \a profile contains [1,2]
168  *          - After \a code contains [NORM_...,nbCells,0], \a idsInPflPerType [[0,1]] and \a idsPerType is [[1,2]] <br>
169
170  */
171 void MEDCoupling1GTUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
172 {
173   if(!profile)
174     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile is NULL !");
175   if(profile->getNumberOfComponents()!=1)
176     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile should have exactly one component !");
177   int nbTuples=profile->getNumberOfTuples();
178   int nbOfCells=getNumberOfCells();
179   code.resize(3); idsInPflPerType.resize(1);
180   code[0]=(int)getCellModelEnum(); code[1]=nbTuples;
181   idsInPflPerType.resize(1);
182   if(profile->isIdentity() && nbTuples==nbOfCells)
183     {
184       code[2]=-1;
185       idsInPflPerType[0]=const_cast<DataArrayInt *>(profile); idsInPflPerType[0]->incrRef();
186       idsPerType.clear();
187       return ;
188     }
189   code[2]=0;
190   profile->checkAllIdsInRange(0,nbOfCells);
191   idsPerType.resize(1);
192   idsPerType[0]=const_cast<DataArrayInt *>(profile); idsPerType[0]->incrRef();
193   idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
194 }
195
196 /*!
197  * This method tries to minimize at most the number of deep copy.
198  * So if \a idsPerType is not empty it can be returned directly (without copy, but with ref count incremented) in return.
199  * 
200  * \sa MEDCouplingUMesh::checkTypeConsistencyAndContig
201  */
202 DataArrayInt *MEDCoupling1GTUMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
203 {
204   int nbOfCells=getNumberOfCells();
205   if(code.size()!=3)
206     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : invalid input code should be exactly of size 3 !");
207   if(code[0]!=(int)getCellModelEnum())
208     {
209       std::ostringstream oss; oss << "MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : Mismatch of geometric type ! Asking for " << code[0] << " whereas the geometric type is \a this is " << getCellModelEnum() << " (" << _cm->getRepr() << ") !";
210       throw INTERP_KERNEL::Exception(oss.str().c_str());
211     }
212   if(code[2]==-1)
213     {
214       if(code[1]==nbOfCells)
215         return 0;
216       else
217         {
218           std::ostringstream oss; oss << "MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : mismatch between the number of cells in this (" << nbOfCells << ") and the number of non profile (" << code[1] << ") !";
219           throw INTERP_KERNEL::Exception(oss.str().c_str());
220         }
221     }
222   if(code[2]!=0)
223     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : single geo type mesh ! 0 or -1 is expected at pos #2 of input code !");
224   if(idsPerType.size()!=1)
225     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input code points to DataArrayInt #0 whereas the size of idsPerType is not equal to 1 !");
226   const DataArrayInt *pfl=idsPerType[0];
227   if(!pfl)
228     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : the input code points to a NULL DataArrayInt at rank 0 !");
229   if(pfl->getNumberOfComponents()!=1)
230     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input profile should have exactly one component !");
231   pfl->checkAllIdsInRange(0,nbOfCells);
232   pfl->incrRef();
233   return const_cast<DataArrayInt *>(pfl);
234 }
235
236 void MEDCoupling1GTUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
237 {
238   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
239   m->writeVTKLL(ofs,cellData,pointData);
240 }
241
242 std::string MEDCoupling1GTUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
243 {
244   return std::string("UnstructuredGrid");
245 }
246
247 std::size_t MEDCoupling1GTUMesh::getHeapMemorySize() const
248 {
249   return MEDCouplingPointSet::getHeapMemorySize();
250 }
251
252 bool MEDCoupling1GTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
253 {
254   if(!MEDCouplingPointSet::isEqualIfNotWhy(other,prec,reason))
255     return false;
256   if(!other)
257     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualIfNotWhy : input other pointer is null !");
258   const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
259   if(!otherC)
260     {
261       reason="mesh given in input is not castable in MEDCouplingSGTUMesh !";
262       return false;
263     }
264   if(_cm!=otherC->_cm)
265     {
266       reason="mismatch in geometric type !";
267       return false;
268     }
269   return true;
270 }
271
272 bool MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
273 {
274   if(!MEDCouplingPointSet::isEqualWithoutConsideringStr(other,prec))
275     return false;
276   if(!other)
277     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
278   const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
279   if(!otherC)
280     return false;
281   if(_cm!=otherC->_cm)
282     return false;
283   return true;
284 }
285
286 void MEDCoupling1GTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
287 {
288   MEDCouplingPointSet::checkCoherency();
289 }
290
291 DataArrayDouble *MEDCoupling1GTUMesh::getBarycenterAndOwner() const
292 {
293   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
294   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=m->getBarycenterAndOwner();
295   return ret.retn();
296 }
297
298 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureField(bool isAbs) const
299 {
300   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
301   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureField(isAbs);
302   ret->setMesh(this);
303   return ret.retn();
304 }
305
306 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureFieldOnNode(bool isAbs) const
307 {
308   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
309   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureFieldOnNode(isAbs);
310   ret->setMesh(this);
311   return ret.retn();
312 }
313
314 /*!
315  * to improve perf !
316  */
317 int MEDCoupling1GTUMesh::getCellContainingPoint(const double *pos, double eps) const
318 {
319   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
320   return m->getCellContainingPoint(pos,eps);
321 }
322
323 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::buildOrthogonalField() const
324 {
325   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
326   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->buildOrthogonalField();
327   ret->setMesh(this);
328   return ret.retn();
329 }
330
331 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const double *bbox, double eps) const
332 {
333   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
334   return m->getCellsInBoundingBox(bbox,eps);
335 }
336
337 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps)
338 {
339   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
340   return m->getCellsInBoundingBox(bbox,eps);
341 }
342
343 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
344 {
345   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
346   return m->buildFacePartOfMySelfNode(start,end,fullyIn);
347 }
348
349 DataArrayInt *MEDCoupling1GTUMesh::findBoundaryNodes() const
350 {
351   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
352   return m->findBoundaryNodes();
353 }
354
355 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildBoundaryMesh(bool keepCoords) const
356 {
357   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
358   return m->buildBoundaryMesh(keepCoords);
359 }
360
361 void MEDCoupling1GTUMesh::findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const throw(INTERP_KERNEL::Exception)
362 {
363   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
364   m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr);
365 }
366
367 int MEDCoupling1GTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception)
368 {
369   const DataArrayInt *c1(getNodalConnectivity());
370   if(!c1)
371     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : no connectivity set !");
372   if(c1->getNumberOfComponents()!=1)
373     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !");
374   if(!c1->isAllocated())
375     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !");
376   return c1->getNumberOfTuples();
377 }
378
379 /*!
380  * This method aggregates all the meshes in \a parts to put them in a single unstructured mesh (those returned).
381  * The order of cells is the returned instance is those in the order of instances in \a parts.
382  *
383  * \param [in] parts - all not null parts of single geo type meshes to be aggreagated having the same mesh dimension and same coordinates.
384  * \return MEDCouplingUMesh * - new object to be dealt by the caller.
385  *
386  * \throw If one element is null in \a parts.
387  * \throw If not all the parts do not have the same mesh dimension.
388  * \throw If not all the parts do not share the same coordinates.
389  * \throw If not all the parts have their connectivity set properly.
390  * \throw If \a parts is empty.
391  */
392 MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception)
393 {
394   if(parts.empty())
395     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : input parts vector is empty !");
396   const MEDCoupling1GTUMesh *firstPart(parts[0]);
397   if(!firstPart)
398     throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : the first instance in input parts is null !");
399   const DataArrayDouble *coords(firstPart->getCoords());
400   int meshDim(firstPart->getMeshDimension());
401   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret(MEDCouplingUMesh::New(firstPart->getName().c_str(),meshDim)); ret->setDescription(firstPart->getDescription().c_str());
402   ret->setCoords(coords);
403   int nbOfCells(0),connSize(0);
404   for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
405     {
406       if(!(*it))
407         throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of null pointer in input vector !");
408       if((*it)->getMeshDimension()!=meshDim)
409         throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances in input vector must have same mesh dimension !");
410       if((*it)->getCoords()!=coords)
411         throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances must share the same coordinates pointer !");
412       nbOfCells+=(*it)->getNumberOfCells();
413       connSize+=(*it)->getNodalConnectivityLength();
414     }
415   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
416   connI->alloc(nbOfCells+1,1); conn->alloc(connSize+nbOfCells,1);
417   int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
418   for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
419     {
420       int curNbCells((*it)->getNumberOfCells());
421       int geoType((int)(*it)->getCellModelEnum());
422       const int *cinPtr((*it)->getNodalConnectivity()->begin());
423       const MEDCoupling1SGTUMesh *ps(dynamic_cast<const MEDCoupling1SGTUMesh *>(*it));
424       const MEDCoupling1DGTUMesh *pd(dynamic_cast<const MEDCoupling1DGTUMesh *>(*it));
425       if(ps && !pd)
426         {
427           int nNodesPerCell(ps->getNumberOfNodesPerCell());
428           for(int i=0;i<curNbCells;i++,ci++,cinPtr+=nNodesPerCell)
429             {
430               *c++=geoType;
431               c=std::copy(cinPtr,cinPtr+nNodesPerCell,c);
432               ci[1]=ci[0]+nNodesPerCell+1;
433             }
434         }
435       else if(!ps && pd)
436         {
437           const int *ciinPtr(pd->getNodalConnectivityIndex()->begin());
438           for(int i=0;i<curNbCells;i++,ci++,ciinPtr++)
439             {
440               *c++=geoType;
441               c=std::copy(cinPtr+ciinPtr[0],cinPtr+ciinPtr[1],c);
442               ci[1]=ci[0]+ciinPtr[1]-ciinPtr[0]+1;
443             }
444         }
445       else
446         throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of instance which type is not in [MEDCoupling1SGTUMesh,MEDCoupling1DGTUMesh] !");
447     }
448   ret->setConnectivity(conn,connI,true);
449   return ret.retn();
450 }
451
452 //==
453
454 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
455 {
456   if(recDeepCpy)
457     {
458       const DataArrayInt *c(other._conn);
459       if(c)
460         _conn=c->deepCpy();
461     }
462 }
463
464 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
465 {
466 }
467
468 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
469 {
470   if(type==INTERP_KERNEL::NORM_ERROR)
471     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
472   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
473   if(cm.isDynamic())
474     {
475       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New : the input geometric type " << cm.getRepr() << " is dynamic ! Only static types are allowed here !";
476       throw INTERP_KERNEL::Exception(oss.str().c_str());
477     }
478   return new MEDCoupling1SGTUMesh(name,cm);
479 }
480
481 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
482 {
483   if(!m)
484     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh is null !");
485   std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
486   if(gts.size()!=1)
487     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh must have exactly one geometric type !");
488   int geoType((int)*gts.begin());
489   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(m->getName().c_str(),*gts.begin()));
490   ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str());
491   int nbCells(m->getNumberOfCells());
492   int nbOfNodesPerCell(ret->getNumberOfNodesPerCell());
493   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()); conn->alloc(nbCells*nbOfNodesPerCell,1);
494   int *c(conn->getPointer());
495   const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
496   for(int i=0;i<nbCells;i++,ciin++)
497     {
498       if(cin[ciin[0]]==geoType)
499         {
500           if(ciin[1]-ciin[0]==nbOfNodesPerCell+1)
501             c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
502           else
503             {
504               std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not those expected (" << nbOfNodesPerCell << ") !";
505               throw INTERP_KERNEL::Exception(oss.str().c_str());
506             }
507         }
508       else
509         {
510           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
511           throw INTERP_KERNEL::Exception(oss.str().c_str());
512         }
513     }
514   ret->setNodalConnectivity(conn);
515   return ret.retn();
516 }
517
518 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::clone(bool recDeepCpy) const
519 {
520   return new MEDCoupling1SGTUMesh(*this,recDeepCpy);
521 }
522
523 /*!
524  * This method behaves mostly like MEDCoupling1SGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
525  * The coordinates are shared between \a this and the returned instance.
526  * 
527  * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
528  * \sa MEDCoupling1SGTUMesh::deepCpy
529  */
530 MEDCouplingPointSet *MEDCoupling1SGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
531 {
532   checkCoherency();
533   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(clone(false));
534   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy());
535   ret->setNodalConnectivity(c);
536   return ret.retn();
537 }
538
539 void MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
540 {
541   if(!other)
542     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
543   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
544   if(!otherC)
545     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1SGTUMesh instance !");
546   setNodalConnectivity(otherC->getNodalConnectivity());
547 }
548
549 void MEDCoupling1SGTUMesh::updateTime() const
550 {
551   MEDCoupling1GTUMesh::updateTime();
552   const DataArrayInt *c(_conn);
553   if(c)
554     updateTimeWith(*c);
555 }
556
557 std::size_t MEDCoupling1SGTUMesh::getHeapMemorySize() const
558 {
559   std::size_t ret=0;
560   const DataArrayInt *c(_conn);
561   if(c)
562     ret+=c->getHeapMemorySize();
563   return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
564 }
565
566 MEDCouplingMesh *MEDCoupling1SGTUMesh::deepCpy() const
567 {
568   return clone(true);
569 }
570
571 bool MEDCoupling1SGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
572 {
573   if(!other)
574     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualIfNotWhy : input other pointer is null !");
575   std::ostringstream oss; oss.precision(15);
576   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
577   if(!otherC)
578     {
579       reason="mesh given in input is not castable in MEDCoupling1SGTUMesh !";
580       return false;
581     }
582   if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
583     return false;
584   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
585   if(c1==c2)
586     return true;
587   if(!c1 || !c2)
588     {
589       reason="in connectivity of single static geometric type exactly one among this and other is null !";
590       return false;
591     }
592   if(!c1->isEqualIfNotWhy(*c2,reason))
593     {
594       reason.insert(0,"Nodal connectivity DataArrayInt differ : ");
595       return false;
596     }
597   return true;
598 }
599
600 bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
601 {
602   if(!other)
603     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
604   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
605   if(!otherC)
606     return false;
607   if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
608     return false;
609   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
610   if(c1==c2)
611     return true;
612   if(!c1 || !c2)
613     return false;
614   if(!c1->isEqualWithoutConsideringStr(*c2))
615     return false;
616   return true;
617 }
618
619 void MEDCoupling1SGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception)
620 {
621   const DataArrayInt *c1(_conn);
622   if(c1)
623     {
624       if(c1->getNumberOfComponents()!=1)
625         throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
626       if(c1->getInfoOnComponent(0)!="")
627         throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
628       c1->checkAllocated();
629     }
630   else
631     throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
632 }
633
634 void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
635 {
636   MEDCouplingPointSet::checkCoherency();
637   checkCoherencyOfConnectivity();
638 }
639
640 void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
641 {
642   checkCoherency();
643   const DataArrayInt *c1(_conn);
644   int nbOfTuples=c1->getNumberOfTuples();
645   int nbOfNodesPerCell=(int)_cm->getNumberOfNodes();
646   if(nbOfTuples%nbOfNodesPerCell!=0)
647     {
648       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::checkCoherency1 : the nb of tuples in conn is " << nbOfTuples << " and number of nodes per cell is " << nbOfNodesPerCell << ". But " << nbOfTuples << "%" << nbOfNodesPerCell << " !=0 !";
649       throw INTERP_KERNEL::Exception(oss.str().c_str());
650     }
651   int nbOfNodes=getNumberOfNodes();
652   int nbOfCells=nbOfTuples/nbOfNodesPerCell;
653   const int *w(c1->begin());
654   for(int i=0;i<nbOfCells;i++)
655     for(int j=0;j<nbOfNodesPerCell;j++,w++)
656       {
657         if(*w<0 || *w>=nbOfNodes)
658           {
659             std::ostringstream oss; oss << "At node #" << j << " of  cell #" << i << ", is equal to " << *w << " must be in [0," << nbOfNodes << ") !";
660             throw INTERP_KERNEL::Exception(oss.str().c_str());
661           }
662       }
663 }
664
665 void MEDCoupling1SGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
666 {
667   checkCoherency1(eps);
668 }
669
670 int MEDCoupling1SGTUMesh::getNumberOfCells() const
671 {
672   int nbOfTuples=getNodalConnectivityLength();
673   int nbOfNodesPerCell=getNumberOfNodesPerCell();
674   if(nbOfTuples%nbOfNodesPerCell!=0)
675     {
676       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh:getNumberOfCells: : the nb of tuples in conn is " << nbOfTuples << " and number of nodes per cell is " << nbOfNodesPerCell << ". But " << nbOfTuples << "%" << nbOfNodesPerCell << " !=0 !";
677       throw INTERP_KERNEL::Exception(oss.str().c_str());
678     }
679   return nbOfTuples/nbOfNodesPerCell;
680 }
681
682 int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
683 {
684   checkNonDynamicGeoType();
685   return (int)_cm->getNumberOfNodes();
686 }
687
688 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
689 {
690   checkNonDynamicGeoType();
691   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
692   ret->alloc(getNumberOfCells(),1);
693   ret->fillWithValue((int)_cm->getNumberOfNodes());
694   return ret.retn();
695 }
696
697 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
698 {
699   checkNonDynamicGeoType();
700   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
701   ret->alloc(getNumberOfCells(),1);
702   ret->fillWithValue((int)_cm->getNumberOfSons());
703   return ret.retn();
704 }
705
706 DataArrayInt *MEDCoupling1SGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
707 {
708   checkNonDynamicGeoType();
709   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
710   int nbCells(getNumberOfCells());
711   ret->alloc(nbCells,1);
712   int *retPtr(ret->getPointer());
713   int nbNodesPerCell(getNumberOfNodesPerCell());
714   const int *conn(_conn->begin());
715   for(int i=0;i<nbCells;i++,conn+=nbNodesPerCell,retPtr++)
716     {
717       std::set<int> s(conn,conn+nbNodesPerCell);
718       *retPtr=(int)s.size();
719     }
720   return ret.retn();
721 }
722
723 void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
724 {
725   int sz=getNumberOfNodesPerCell();
726   conn.resize(sz);
727   if(cellId>=0 && cellId<getNumberOfCells())
728     std::copy(_conn->begin()+cellId*sz,_conn->begin()+(cellId+1)*sz,conn.begin());
729   else
730     {
731       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << getNumberOfCells() << ") !";
732       throw INTERP_KERNEL::Exception(oss.str().c_str());
733     }
734 }
735
736 void MEDCoupling1SGTUMesh::checkNonDynamicGeoType() const throw(INTERP_KERNEL::Exception)
737 {
738   if(_cm->isDynamic())
739     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkNonDynamicGeoType : internal error ! the internal geo type is dynamic ! should be static !");
740 }
741
742 std::string MEDCoupling1SGTUMesh::simpleRepr() const
743 {
744   static const char msg0[]="No coordinates specified !";
745   std::ostringstream ret;
746   ret << "Single static geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
747   ret << "Description of mesh : \"" << getDescription() << "\"\n";
748   int tmpp1,tmpp2;
749   double tt=getTime(tmpp1,tmpp2);
750   ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
751   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
752   ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
753   if(_coords!=0)
754     {
755       const int spaceDim=getSpaceDimension();
756       ret << spaceDim << "\nInfo attached on space dimension : ";
757       for(int i=0;i<spaceDim;i++)
758         ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
759       ret << "\n";
760     }
761   else
762     ret << msg0 << "\n";
763   ret << "Number of nodes : ";
764   if(_coords!=0)
765     ret << getNumberOfNodes() << "\n";
766   else
767     ret << msg0 << "\n";
768   ret << "Number of cells : ";
769   if((const DataArrayInt *)_conn)
770     {
771       if(_conn->isAllocated())
772         {
773           if(_conn->getNumberOfComponents()==1)
774             ret << getNumberOfCells() << "\n";
775           else
776             ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
777         }
778       else
779         ret << "Nodal connectivity array specified but not allocated !" << "\n";
780     }
781   else
782     ret << "No connectivity specified !" << "\n";
783   ret << "Cell type : " << _cm->getRepr() << "\n";
784   return ret.str();
785 }
786
787 std::string MEDCoupling1SGTUMesh::advancedRepr() const
788 {
789   std::ostringstream ret;
790   ret << simpleRepr();
791   ret << "\nCoordinates array : \n___________________\n\n";
792   if(_coords)
793     _coords->reprWithoutNameStream(ret);
794   else
795     ret << "No array set !\n";
796   ret << "\n\nConnectivity array : \n____________________\n\n";
797   //
798   if((const DataArrayInt *)_conn)
799     {
800       if(_conn->isAllocated())
801         {
802           if(_conn->getNumberOfComponents()==1)
803             {
804              int nbOfCells=getNumberOfCells();
805              int sz=getNumberOfNodesPerCell();
806              const int *connPtr=_conn->begin();
807              for(int i=0;i<nbOfCells;i++,connPtr+=sz)
808                {
809                  ret << "Cell #" << i << " : ";
810                  std::copy(connPtr,connPtr+sz,std::ostream_iterator<int>(ret," "));
811                  ret << "\n";
812                }
813             }
814           else
815             ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
816         }
817       else
818         ret << "Nodal connectivity array specified but not allocated !" << "\n";
819     }
820   else
821     ret << "No connectivity specified !" << "\n";
822   return ret.str();
823 }
824
825 DataArrayDouble *MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
826 {
827   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
828   int spaceDim=getSpaceDimension();
829   int nbOfCells=getNumberOfCells();//checkCoherency()
830   int nbOfNodes=getNumberOfNodes();
831   ret->alloc(nbOfCells,spaceDim);
832   double *ptToFill=ret->getPointer();
833   const double *coor=_coords->begin();
834   const int *nodal=_conn->begin();
835   int sz=getNumberOfNodesPerCell();
836   double coeff=1./(double)sz;
837   for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim)
838     {
839       std::fill(ptToFill,ptToFill+spaceDim,0.);
840       for(int j=0;j<sz;j++,nodal++)
841         if(*nodal>=0 && *nodal<nbOfNodes)
842           std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
843         else
844           {
845             std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," <<   nbOfNodes << ") !";
846             throw INTERP_KERNEL::Exception(oss.str().c_str());
847           }
848       std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),coeff));
849     }
850   return ret.retn();
851 }
852
853 void MEDCoupling1SGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
854 {
855   int nbCells=getNumberOfCells();
856   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
857   o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
858   if(check)
859     o2n=o2n->checkAndPreparePermutation();
860   //
861   const int *conn=_conn->begin();
862   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(nbCells);
863   const int *n2oPtr=n2o->begin();
864   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
865   newConn->alloc(_conn->getNumberOfTuples(),1);
866   newConn->copyStringInfoFrom(*_conn);
867   int sz=getNumberOfNodesPerCell();
868   //
869   int *newC=newConn->getPointer();
870   for(int i=0;i<nbCells;i++,newC+=sz)
871     {
872       int pos=n2oPtr[i];
873       std::copy(conn+pos*sz,conn+(pos+1)*sz,newC);
874     }
875   _conn=newConn;
876 }
877
878 /*!
879  * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
880  * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
881  * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
882  * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
883  *
884  * \param [in] begin input start of array of node ids.
885  * \param [in] end input end of array of node ids.
886  * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
887  * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
888  */
889 void MEDCoupling1SGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
890 {
891   int nbOfCells=getNumberOfCells();
892   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
893   int tmp=-1;
894   int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
895   std::vector<bool> fastFinder(sz,false);
896   for(const int *work=begin;work!=end;work++)
897     if(*work>=0 && *work<sz)
898       fastFinder[*work]=true;
899   const int *conn=_conn->begin();
900   int nbNodesPerCell=getNumberOfNodesPerCell();
901   for(int i=0;i<nbOfCells;i++,conn+=nbNodesPerCell)
902     {
903       int ref=0,nbOfHit=0;
904       for(int j=0;j<nbNodesPerCell;j++)
905         if(conn[j]>=0)
906           {
907             ref++;
908             if(fastFinder[conn[j]])
909               nbOfHit++;
910           }
911       if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
912         cellIdsKept->pushBackSilent(i);
913     }
914   cellIdsKeptArr=cellIdsKept.retn();
915 }
916
917 MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
918 {
919   if(other->getType()!=SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED)
920     throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single static geo type each other !");
921   const MEDCoupling1SGTUMesh *otherC=static_cast<const MEDCoupling1SGTUMesh *>(other);
922   return Merge1SGTUMeshes(this,otherC);
923 }
924
925 MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
926 {
927   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension());
928   ret->setCoords(getCoords());
929   const int *nodalConn=_conn->begin();
930   int nbCells=getNumberOfCells();
931   int nbNodesPerCell=getNumberOfNodesPerCell();
932   int geoType=(int)getCellModelEnum();
933   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells*(nbNodesPerCell+1),1);
934   int *cPtr=c->getPointer();
935   for(int i=0;i<nbCells;i++,nodalConn+=nbNodesPerCell)
936     {
937       *cPtr++=geoType;
938       cPtr=std::copy(nodalConn,nodalConn+nbNodesPerCell,cPtr);
939     }
940   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::Range(0,(nbCells+1)*(nbNodesPerCell+1),nbNodesPerCell+1);
941   ret->setConnectivity(c,cI,true);
942   return ret.retn();
943 }
944
945 DataArrayInt *MEDCoupling1SGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
946 {
947   switch(policy)
948     {
949     case 0:
950       return simplexizePol0();
951     case 1:
952       return simplexizePol1();
953     case (int) INTERP_KERNEL::PLANAR_FACE_5:
954       return simplexizePlanarFace5();
955     case (int) INTERP_KERNEL::PLANAR_FACE_6:
956       return simplexizePlanarFace6();
957     default:
958       throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::simplexize : unrecognized policy ! Must be :\n  - 0 or 1 (only available for meshdim=2) \n  - PLANAR_FACE_5, PLANAR_FACE_6  (only for meshdim=3)");
959     }
960 }
961
962 /// @cond INTERNAL
963
964 struct MEDCouplingAccVisit
965 {
966   MEDCouplingAccVisit():_new_nb_of_nodes(0) { }
967   int operator()(int val) { if(val!=-1) return _new_nb_of_nodes++; else return -1; }
968   int _new_nb_of_nodes;
969 };
970
971 /// @endcond
972
973 /*!
974  * Finds nodes not used in any cell and returns an array giving a new id to every node
975  * by excluding the unused nodes, for which the array holds -1. The result array is
976  * a mapping in "Old to New" mode. 
977  *  \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
978  *  \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
979  *          this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
980  *          if the node is unused or a new id else. The caller is to delete this
981  *          array using decrRef() as it is no more needed.  
982  *  \throw If the coordinates array is not set.
983  *  \throw If the nodal connectivity of cells is not defined.
984  *  \throw If the nodal connectivity includes an invalid id.
985  */
986 DataArrayInt *MEDCoupling1SGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
987 {
988   nbrOfNodesInUse=-1;
989   int nbOfNodes=getNumberOfNodes();
990   int nbOfCells=getNumberOfCells();
991   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
992   ret->alloc(nbOfNodes,1);
993   int *traducer=ret->getPointer();
994   std::fill(traducer,traducer+nbOfNodes,-1);
995   const int *conn=_conn->begin();
996   int nbNodesPerCell=getNumberOfNodesPerCell();
997   for(int i=0;i<nbOfCells;i++)
998     for(int j=0;j<nbNodesPerCell;j++,conn++)
999       if(*conn>=0 && *conn<nbOfNodes)
1000         traducer[*conn]=1;
1001       else
1002         {
1003           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsInUse : In cell #" << i  << " presence of node id " <<  conn[j] << " not in [0," << nbOfNodes << ") !";
1004           throw INTERP_KERNEL::Exception(oss.str().c_str());
1005         }
1006   nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
1007   std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
1008   return ret.retn();
1009 }
1010
1011 /*!
1012  * Changes ids of nodes within the nodal connectivity arrays according to a permutation
1013  * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
1014  * This method is a generalization of shiftNodeNumbersInConn().
1015  *  \warning This method performs no check of validity of new ids. **Use it with care !**
1016  *  \param [in] newNodeNumbersO2N - a permutation array, of length \a
1017  *         this->getNumberOfNodes(), in "Old to New" mode. 
1018  *         See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
1019  *  \throw If the nodal connectivity of cells is not defined.
1020  */
1021 void MEDCoupling1SGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
1022 {
1023   getNumberOfCells();//only to check that all is well defined.
1024   _conn->transformWithIndArr(newNodeNumbersO2N,newNodeNumbersO2N+getNumberOfNodes());
1025   updateTime();
1026 }
1027
1028 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
1029 {
1030   std::vector<const MEDCoupling1SGTUMesh *> tmp(2);
1031   tmp[0]=const_cast<MEDCoupling1SGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1SGTUMesh *>(mesh2);
1032   return Merge1SGTUMeshes(tmp);
1033 }
1034
1035 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1036 {
1037   std::size_t sz=a.size();
1038   if(sz==0)
1039     return Merge1SGTUMeshesLL(a);
1040   for(std::size_t ii=0;ii<sz;ii++)
1041     if(!a[ii])
1042       {
1043         std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::Merge1SGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
1044         throw INTERP_KERNEL::Exception(oss.str().c_str());
1045       }
1046   const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
1047   for(std::size_t ii=0;ii<sz;ii++)
1048     if(&(a[ii]->getCellModel())!=cm)
1049       throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : all items must have the same geo type !");
1050   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> > bb(sz);
1051   std::vector< const MEDCoupling1SGTUMesh * > aa(sz);
1052   int spaceDim=-3;
1053   for(std::size_t i=0;i<sz && spaceDim==-3;i++)
1054     {
1055       const MEDCoupling1SGTUMesh *cur=a[i];
1056       const DataArrayDouble *coo=cur->getCoords();
1057       if(coo)
1058         spaceDim=coo->getNumberOfComponents();
1059     }
1060   if(spaceDim==-3)
1061     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : no spaceDim specified ! unable to perform merge !");
1062   for(std::size_t i=0;i<sz;i++)
1063     {
1064       bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
1065       aa[i]=bb[i];
1066     }
1067   return Merge1SGTUMeshesLL(aa);
1068 }
1069
1070 /*!
1071  * \throw If presence of a null instance in the input vector \a a.
1072  * \throw If a is empty
1073  */
1074 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1075 {
1076   if(a.empty())
1077     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : input array must be NON EMPTY !");
1078   std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1079   if(!(*it))
1080     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : null instance in the first element of input vector !");
1081   std::vector<const DataArrayInt *> ncs(a.size());
1082   int nbOfCells=(*it)->getNumberOfCells();
1083   const DataArrayDouble *coords=(*it)->getCoords();
1084   const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1085   int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1086   ncs[0]=(*it)->getNodalConnectivity();
1087   it++;
1088   for(int i=1;it!=a.end();i++,it++)
1089     {
1090       if(!(*it))
1091         throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : presence of a null instance in the input vector !");
1092       if(cm!=&((*it)->getCellModel()))
1093         throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1094       (*it)->getNumberOfCells();//to check that all is OK
1095       ncs[i]=(*it)->getNodalConnectivity();
1096       if(coords!=(*it)->getCoords())
1097         throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : not lying on same coords !");
1098     }
1099   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1100   ret->setCoords(coords);
1101   ret->_conn=DataArrayInt::Aggregate(ncs);
1102   return ret.retn();
1103 }
1104
1105 /*!
1106  * Assume that all instances in \a a are non null. If null it leads to a crash. That's why this method is assigned to be low level (LL)
1107  */
1108 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1109 {
1110   if(a.empty())
1111     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : input array must be NON EMPTY !");
1112   std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1113   int nbOfCells=(*it)->getNumberOfCells();
1114   const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1115   int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1116   it++;
1117   for(;it!=a.end();it++)
1118     {
1119       if(cm!=&((*it)->getCellModel()))
1120         throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1121       nbOfCells+=(*it)->getNumberOfCells();
1122     }
1123   std::vector<const MEDCouplingPointSet *> aps(a.size());
1124   std::copy(a.begin(),a.end(),aps.begin());
1125   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
1126   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1127   ret->setCoords(pts);
1128   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New();
1129   c->alloc(nbOfCells*nbNodesPerCell,1);
1130   int *cPtr=c->getPointer();
1131   int offset=0;
1132   for(it=a.begin();it!=a.end();it++)
1133     {
1134       int curConnLgth=(*it)->getNodalConnectivityLength();
1135       const int *curC=(*it)->_conn->begin();
1136       cPtr=std::transform(curC,curC+curConnLgth,cPtr,std::bind2nd(std::plus<int>(),offset));
1137       offset+=(*it)->getNumberOfNodes();
1138     }
1139   //
1140   ret->setNodalConnectivity(c);
1141   return ret.retn();
1142 }
1143
1144 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
1145 {
1146   int ncell=getNumberOfCells();
1147   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
1148   ret->setCoords(_coords);
1149   std::size_t nbOfElemsRet=std::distance(begin,end);
1150   const int *inConn=_conn->getConstPointer();
1151   int sz=getNumberOfNodesPerCell();
1152   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1153   int *connPtr=connRet->getPointer();
1154   for(const int *work=begin;work!=end;work++,connPtr+=sz)
1155     {
1156       if(*work>=0 && *work<ncell)
1157         std::copy(inConn+(work[0])*sz,inConn+(work[0]+1)*sz,connPtr);
1158       else
1159         {
1160           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !";
1161           throw INTERP_KERNEL::Exception(oss.str().c_str());
1162         }
1163     }
1164   ret->_conn=connRet;
1165   ret->copyTinyInfoFrom(this);
1166   return ret.retn();
1167 }
1168
1169 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
1170 {
1171   int ncell=getNumberOfCells();
1172   int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : ");
1173   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
1174   ret->setCoords(_coords);
1175   const int *inConn=_conn->getConstPointer();
1176   int sz=getNumberOfNodesPerCell();
1177   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1178   int *connPtr=connRet->getPointer();
1179   int curId=start;
1180   for(int i=0;i<nbOfElemsRet;i++,connPtr+=sz,curId+=step)
1181     {
1182       if(curId>=0 && curId<ncell)
1183         std::copy(inConn+curId*sz,inConn+(curId+1)*sz,connPtr);
1184       else
1185         {
1186           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : On pos #" << i << " input cell id =" << curId  << " should be in [0," << ncell << ") !";
1187           throw INTERP_KERNEL::Exception(oss.str().c_str());
1188         }
1189     }
1190   ret->_conn=connRet;
1191   ret->copyTinyInfoFrom(this);
1192   return ret.retn();
1193 }
1194
1195 void MEDCoupling1SGTUMesh::computeNodeIdsAlg(std::vector<bool>& nodeIdsInUse) const throw(INTERP_KERNEL::Exception)
1196 {
1197   int sz((int)nodeIdsInUse.size());
1198   int nbCells(getNumberOfCells());
1199   int nbOfNodesPerCell(getNumberOfNodesPerCell());
1200   const int *w(_conn->begin());
1201   for(int i=0;i<nbCells;i++)
1202     for(int j=0;j<nbOfNodesPerCell;j++,w++)
1203       {
1204         if(*w>=0 && *w<sz)
1205           nodeIdsInUse[*w]=true;
1206         else
1207           {
1208             std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeNodeIdsAlg : At cell #" << i << " presence of node id #" << *w << " should be in [0," << sz << ") !";
1209             throw INTERP_KERNEL::Exception(oss.str().c_str());
1210           }
1211       }
1212 }
1213
1214 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
1215 {
1216   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
1217   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1;
1218   const DataArrayInt *nodalConn(_conn);
1219   if(!nodalConn)
1220     {
1221       tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
1222     }
1223   else
1224     tmp1=_conn;
1225   ret->_conn=tmp1;
1226   if(!_coords)
1227     {
1228       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
1229       ret->setCoords(coords);
1230     }
1231   else
1232     ret->setCoords(_coords);
1233   return ret.retn();
1234 }
1235
1236 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol0() throw(INTERP_KERNEL::Exception)
1237 {
1238   int nbOfCells=getNumberOfCells();
1239   if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1240     return DataArrayInt::Range(0,nbOfCells,1);
1241   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1242   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1243   const int *c(_conn->begin());
1244   int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1245   for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1246     {
1247       newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[2];
1248       newConnPtr[3]=c[0]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1249       retPtr[0]=i; retPtr[1]=i;
1250     }
1251   _conn=newConn;
1252   _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1253   updateTime();
1254   return ret.retn();
1255 }
1256
1257 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol1() throw(INTERP_KERNEL::Exception)
1258 {
1259   int nbOfCells=getNumberOfCells();
1260   if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1261     return DataArrayInt::Range(0,nbOfCells,1);
1262   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1263   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1264   const int *c(_conn->begin());
1265   int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1266   for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1267     {
1268       newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[3];
1269       newConnPtr[3]=c[1]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1270       retPtr[0]=i; retPtr[1]=i;
1271     }
1272   _conn=newConn;
1273   _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1274   updateTime();
1275   return ret.retn();
1276 }
1277
1278 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace5() throw(INTERP_KERNEL::Exception)
1279 {
1280   int nbOfCells=getNumberOfCells();
1281   if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1282     return DataArrayInt::Range(0,nbOfCells,1);
1283   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(5*4*nbOfCells,1);
1284   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(5*nbOfCells,1);
1285   const int *c(_conn->begin());
1286   int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1287   for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=20,retPtr+=5)
1288     {
1289       for(int j=0;j<20;j++)
1290         newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_5_WO[j]];
1291       retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i;
1292     }
1293   _conn=newConn;
1294   _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1295   updateTime();
1296   return ret.retn();
1297 }
1298
1299 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace6() throw(INTERP_KERNEL::Exception)
1300 {
1301   int nbOfCells=getNumberOfCells();
1302   if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1303     return DataArrayInt::Range(0,nbOfCells,1);
1304   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(6*4*nbOfCells,1);
1305   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(6*nbOfCells,1);
1306   const int *c(_conn->begin());
1307   int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1308   for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=24,retPtr+=6)
1309     {
1310       for(int j=0;j<24;j++)
1311         newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_6_WO[j]];
1312       retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i; retPtr[5]=i;
1313     }
1314   _conn=newConn;
1315   _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1316   updateTime();
1317   return ret.retn();
1318 }
1319
1320 void MEDCoupling1SGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1321 {
1322   stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
1323   stream << " Mesh dimension : " << getMeshDimension() << ".";
1324   if(!_coords)
1325     { stream << " No coordinates set !"; return ; }
1326   if(!_coords->isAllocated())
1327     { stream << " Coordinates set but not allocated !"; return ; }
1328   stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
1329   stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
1330   if(!(const DataArrayInt *)_conn)
1331     { stream << std::endl << "Nodal connectivity NOT set !"; return ; }
1332   if(_conn->isAllocated())
1333     {
1334       if(_conn->getNumberOfComponents()==1)
1335         stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
1336     }
1337 }
1338
1339 void MEDCoupling1SGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
1340 {
1341   if(!((const DataArrayInt *)_conn) || !((const DataArrayDouble *)_coords))
1342     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFullyDefined : part of this is not fully defined.");
1343 }
1344
1345 /*!
1346  * First step of unserialization process.
1347  */
1348 bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
1349 {
1350   throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !");
1351 }
1352
1353 /*!
1354  * Checks if \a this and \a other meshes are geometrically equivalent with high
1355  * probability, else an exception is thrown. The meshes are considered equivalent if
1356  * (1) meshes contain the same number of nodes and the same number of elements of the
1357  * same types (2) three cells of the two meshes (first, last and middle) are based
1358  * on coincident nodes (with a specified precision).
1359  *  \param [in] other - the mesh to compare with.
1360  *  \param [in] prec - the precision used to compare nodes of the two meshes.
1361  *  \throw If the two meshes do not match.
1362  */
1363 void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1364 {
1365   MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1366   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1367   if(!otherC)
1368     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single static geometric type !");
1369   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1370   if(c1==c2)
1371     return;
1372   if(!c1 || !c2)
1373     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1374   if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1375     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1376   if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1377     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1378   if(c1->getHashCode()!=c2->getHashCode())
1379     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1380 }
1381
1382 MEDCouplingPointSet *MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
1383 {
1384   if(!other)
1385     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
1386   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1387   if(!otherC)
1388     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
1389   std::vector<const MEDCoupling1SGTUMesh *> ms(2);
1390   ms[0]=this;
1391   ms[1]=otherC;
1392   return Merge1SGTUMeshesOnSameCoords(ms);
1393 }
1394
1395 void MEDCoupling1SGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
1396 {
1397   checkFullyDefined();
1398   int nbOfNodes=getNumberOfNodes();
1399   int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
1400   revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
1401   std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
1402   const int *conn=_conn->begin();
1403   int nbOfCells=getNumberOfCells();
1404   int nbOfEltsInRevNodal=0;
1405   int nbOfNodesPerCell=getNumberOfNodesPerCell();
1406   for(int eltId=0;eltId<nbOfCells;eltId++)
1407     {
1408       for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1409         {
1410           if(conn[0]>=0 && conn[0]<nbOfNodes)
1411             {
1412               nbOfEltsInRevNodal++;
1413               revNodalIndxPtr[conn[0]+1]++;
1414             }
1415           else
1416             {
1417               std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
1418               throw INTERP_KERNEL::Exception(oss.str().c_str());
1419             }
1420         }
1421     }
1422   std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
1423   conn=_conn->begin();
1424   int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
1425   revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
1426   std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
1427   for(int eltId=0;eltId<nbOfCells;eltId++)
1428     {
1429       for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1430         {
1431           *std::find_if(revNodalPtr+revNodalIndxPtr[*conn],revNodalPtr+revNodalIndxPtr[*conn+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
1432         }
1433     }
1434 }
1435
1436 /*!
1437  * Use \a nodalConn array as nodal connectivity of \a this. The input \a nodalConn pointer can be null.
1438  */
1439 void MEDCoupling1SGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception)
1440 {
1441   if(nodalConn)
1442     nodalConn->incrRef();
1443   _conn=nodalConn;
1444   declareAsNew();
1445 }
1446
1447 /*!
1448  * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
1449  */
1450 DataArrayInt *MEDCoupling1SGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
1451 {
1452   const DataArrayInt *ret(_conn);
1453   return const_cast<DataArrayInt *>(ret);
1454 }
1455
1456 /*!
1457  * Allocates memory to store an estimation of the given number of cells. Closer is the estimation to the number of cells effectively inserted,
1458  * less will be the needs to realloc. If the number of cells to be inserted is not known simply put 0 to this parameter.
1459  * If a nodal connectivity previouly existed before the call of this method, it will be reset.
1460  *
1461  *  \param [in] nbOfCells - estimation of the number of cell \a this mesh will contain.
1462  */
1463 void MEDCoupling1SGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
1464 {
1465   if(nbOfCells<0)
1466     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::allocateCells : the input number of cells should be >= 0 !");
1467   _conn=DataArrayInt::New();
1468   _conn->reserve(getNumberOfNodesPerCell()*nbOfCells);
1469   declareAsNew();
1470 }
1471
1472 /*!
1473  * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
1474  *
1475  * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
1476  * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
1477  * \throw If the length of the input nodal connectivity array of the cell to add is not equal to number of nodes per cell relative to the unique geometric type
1478  *        attached to \a this.
1479  * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
1480  */
1481 void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
1482 {
1483   int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
1484   int ref=getNumberOfNodesPerCell();
1485   if(sz==ref)
1486     {
1487       DataArrayInt *c(_conn);
1488       if(c)
1489         c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
1490       else
1491         throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1SGTUMesh::allocateCells before !");
1492     }
1493   else
1494     {
1495       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::insertNextCell : input nodal size (" << sz << ") does not match number of nodes per cell of this (";
1496       oss << ref << ") !";
1497       throw INTERP_KERNEL::Exception(oss.str().c_str());
1498     }
1499 }
1500
1501 /*!
1502  * This method builds the dual mesh of \a this and returns it.
1503  * 
1504  * \return MEDCoupling1SGTUMesh * - newly object created to be managed by the caller.
1505  * \throw If \a this is not a mesh containing only simplex cells.
1506  * \throw If \a this is not correctly allocated (coordinates and connectivities have to be correctly set !).
1507  * \throw If at least one node in \a this is orphan (without any simplex cell lying on it !)
1508  */
1509 MEDCoupling1GTUMesh *MEDCoupling1SGTUMesh::computeDualMesh() const throw(INTERP_KERNEL::Exception)
1510 {
1511   const INTERP_KERNEL::CellModel& cm(getCellModel());
1512   if(!cm.isSimplex())
1513     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh : this mesh is not a simplex mesh ! Please invoke simplexize of tetrahedrize on this before calling this method !");
1514   switch(getMeshDimension())
1515     {
1516     case 3:
1517       return computeDualMesh3D();
1518     case 2:
1519       return computeDualMesh2D();
1520     default:
1521       throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh : meshdimension must be in [2,3] !");
1522     }
1523 }
1524
1525 MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTERP_KERNEL::Exception)
1526 {
1527   static const int DUAL_TETRA_0[36]={
1528     4,1,0, 6,0,3, 7,3,1,
1529     4,0,1, 5,2,0, 8,1,2,
1530     6,3,0, 5,0,2, 9,2,3,
1531     7,1,3, 9,3,2, 8,2,1
1532   };
1533   static const int DUAL_TETRA_1[36]={
1534     8,4,10, 11,5,8, 10,7,11,
1535     9,4,8, 8,5,12, 12,6,9,
1536     10,4,9, 9,6,13, 13,7,10,
1537     12,5,11, 13,6,12, 11,7,13
1538   };
1539   static const int FACEID_NOT_SH_NODE[4]={2,3,1,0};
1540   if(getCellModelEnum()!=INTERP_KERNEL::NORM_TETRA4)
1541     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh3D : only TETRA4 supported !");
1542   checkFullyDefined();
1543   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> thisu(buildUnstructured());
1544   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> revNodArr(DataArrayInt::New()),revNodIArr(DataArrayInt::New());
1545   thisu->getReverseNodalConnectivity(revNodArr,revNodIArr);
1546   const int *revNod(revNodArr->begin()),*revNodI(revNodIArr->begin()),*nodal(_conn->begin());
1547   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d1Arr(DataArrayInt::New()),di1Arr(DataArrayInt::New()),rd1Arr(DataArrayInt::New()),rdi1Arr(DataArrayInt::New());
1548   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> edges(thisu->explode3DMeshTo1D(d1Arr,di1Arr,rd1Arr,rdi1Arr));
1549   const int *d1(d1Arr->begin());
1550   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d2Arr(DataArrayInt::New()),di2Arr(DataArrayInt::New()),rd2Arr(DataArrayInt::New()),rdi2Arr(DataArrayInt::New());
1551   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> faces(thisu->buildDescendingConnectivity(d2Arr,di2Arr,rd2Arr,rdi2Arr));  thisu=0;
1552   const int *d2(d2Arr->begin()),*rd2(rd2Arr->begin()),*rdi2(rdi2Arr->begin());
1553   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> edgesBaryArr(edges->getBarycenterAndOwner()),facesBaryArr(faces->getBarycenterAndOwner()),baryArr(getBarycenterAndOwner());
1554   const int nbOfNodes(getNumberOfNodes()),offset0(nbOfNodes+faces->getNumberOfCells()),offset1(offset0+edges->getNumberOfCells());
1555   edges=0; faces=0;
1556   std::vector<const DataArrayDouble *> v(4); v[0]=getCoords(); v[1]=facesBaryArr; v[2]=edgesBaryArr; v[3]=baryArr;
1557   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0; facesBaryArr=0;
1558   std::string name("DualOf_"); name+=getName();
1559   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYHED)); ret->setCoords(zeArr);
1560   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
1561   for(int i=0;i<nbOfNodes;i++,revNodI++)
1562     {
1563       int nbOfCellsSharingNode(revNodI[1]-revNodI[0]);
1564       if(nbOfCellsSharingNode==0)
1565         {
1566           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeDualMesh3D : Node #" << i << " is orphan !"; 
1567           throw INTERP_KERNEL::Exception(oss.str().c_str());
1568         }
1569       for(int j=0;j<nbOfCellsSharingNode;j++)
1570         {
1571           int curCellId(revNod[revNodI[0]+j]);
1572           const int *connOfCurCell(nodal+4*curCellId);
1573           std::size_t nodePosInCurCell(std::distance(connOfCurCell,std::find(connOfCurCell,connOfCurCell+4,i)));
1574           if(j!=0) cArr->pushBackSilent(-1);
1575           int tmp[14];
1576           //
1577           tmp[0]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+0]-4]+offset0; tmp[1]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+1]]+nbOfNodes;
1578           tmp[2]=curCellId+offset1; tmp[3]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+2]]+nbOfNodes;
1579           tmp[4]=-1;
1580           tmp[5]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+3]-4]+offset0; tmp[6]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+4]]+nbOfNodes;
1581           tmp[7]=curCellId+offset1; tmp[8]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+5]]+nbOfNodes;
1582           tmp[9]=-1;
1583           tmp[10]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+6]-4]+offset0; tmp[11]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+7]]+nbOfNodes;
1584           tmp[12]=curCellId+offset1; tmp[13]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+8]]+nbOfNodes;
1585           cArr->insertAtTheEnd(tmp,tmp+14);
1586           int kk(0);
1587           for(int k=0;k<4;k++)
1588             {
1589               if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k)
1590                 {
1591                   const int *faceId(d2+4*curCellId+k);
1592                   if(rdi2[*faceId+1]-rdi2[*faceId]==1)
1593                     {
1594                       int tmp2[5]; tmp2[0]=-1; tmp2[1]=i;
1595                       tmp2[2]=d1[6*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+0]-8]+offset0;
1596                       tmp2[3]=d2[4*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+1]-4]+nbOfNodes;
1597                       tmp2[4]=d1[6*curCellId+DUAL_TETRA_1[9*nodePosInCurCell+3*kk+2]-8]+offset0;
1598                       cArr->insertAtTheEnd(tmp2,tmp2+5);
1599                     }
1600                   kk++;
1601                 }
1602             }
1603         }
1604       ciArr->setIJ(i+1,0,cArr->getNumberOfTuples());
1605     }
1606   ret->setNodalConnectivity(cArr,ciArr);
1607   return ret.retn();
1608 }
1609
1610 MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTERP_KERNEL::Exception)
1611 {
1612   static const int DUAL_TRI_0[6]={0,2, 1,0, 2,1};
1613   static const int DUAL_TRI_1[6]={-3,+5, +3,-4, +4,-5};
1614   static const int FACEID_NOT_SH_NODE[3]={1,2,0};
1615   if(getCellModelEnum()!=INTERP_KERNEL::NORM_TRI3)
1616     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh2D : only TRI3 supported !");
1617   checkFullyDefined();
1618   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> thisu(buildUnstructured());
1619   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> revNodArr(DataArrayInt::New()),revNodIArr(DataArrayInt::New());
1620   thisu->getReverseNodalConnectivity(revNodArr,revNodIArr);
1621   const int *revNod(revNodArr->begin()),*revNodI(revNodIArr->begin()),*nodal(_conn->begin());
1622   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d2Arr(DataArrayInt::New()),di2Arr(DataArrayInt::New()),rd2Arr(DataArrayInt::New()),rdi2Arr(DataArrayInt::New());
1623   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> edges(thisu->buildDescendingConnectivity(d2Arr,di2Arr,rd2Arr,rdi2Arr));  thisu=0;
1624   const int *d2(d2Arr->begin()),*rd2(rd2Arr->begin()),*rdi2(rdi2Arr->begin());
1625   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> edgesBaryArr(edges->getBarycenterAndOwner()),baryArr(getBarycenterAndOwner());
1626   const int nbOfNodes(getNumberOfNodes()),offset0(nbOfNodes+edges->getNumberOfCells());
1627   edges=0;
1628   std::vector<const DataArrayDouble *> v(3); v[0]=getCoords(); v[1]=edgesBaryArr; v[2]=baryArr;
1629   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0;
1630   std::string name("DualOf_"); name+=getName();
1631   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYGON)); ret->setCoords(zeArr);
1632   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
1633   for(int i=0;i<nbOfNodes;i++,revNodI++)
1634     {
1635       int nbOfCellsSharingNode(revNodI[1]-revNodI[0]);
1636       if(nbOfCellsSharingNode==0)
1637         {
1638           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeDualMesh2D : Node #" << i << " is orphan !"; 
1639           throw INTERP_KERNEL::Exception(oss.str().c_str());
1640         }
1641       std::vector< std::vector<int> > polyg;
1642       for(int j=0;j<nbOfCellsSharingNode;j++)
1643         {
1644           int curCellId(revNod[revNodI[0]+j]);
1645           const int *connOfCurCell(nodal+3*curCellId);
1646           std::size_t nodePosInCurCell(std::distance(connOfCurCell,std::find(connOfCurCell,connOfCurCell+4,i)));
1647           std::vector<int> locV(3);
1648           locV[0]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+0]]+nbOfNodes; locV[1]=curCellId+offset0; locV[2]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+1]]+nbOfNodes;
1649           polyg.push_back(locV);
1650           int kk(0);
1651           for(int k=0;k<3;k++)
1652             {
1653               if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k)
1654                 {
1655                   const int *edgeId(d2+3*curCellId+k);
1656                   if(rdi2[*edgeId+1]-rdi2[*edgeId]==1)
1657                     {
1658                       std::vector<int> locV2(2);
1659                       int zeLocEdgeIdRel(DUAL_TRI_1[2*nodePosInCurCell+kk]);
1660                       if(zeLocEdgeIdRel>0)
1661                         {  locV2[0]=d2[3*curCellId+zeLocEdgeIdRel-3]+nbOfNodes;  locV2[1]=i; }
1662                       else
1663                         {  locV2[0]=i; locV2[1]=d2[3*curCellId-zeLocEdgeIdRel-3]+nbOfNodes; }
1664                       polyg.push_back(locV2);
1665                     }
1666                   kk++;
1667                 }
1668             }
1669         }
1670       std::vector<int> zePolyg(MEDCoupling1DGTUMesh::BuildAPolygonFromParts(polyg));
1671       cArr->insertAtTheEnd(zePolyg.begin(),zePolyg.end());
1672       ciArr->setIJ(i+1,0,cArr->getNumberOfTuples());
1673     }
1674   ret->setNodalConnectivity(cArr,ciArr);
1675   return ret.retn();
1676 }
1677
1678 //== 
1679
1680 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
1681 {
1682   if(type==INTERP_KERNEL::NORM_ERROR)
1683     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
1684   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1685   if(!cm.isDynamic())
1686     {
1687       std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New : the input geometric type " << cm.getRepr() << " is static ! Only dynamic types are allowed here !";
1688       throw INTERP_KERNEL::Exception(oss.str().c_str());
1689     }
1690   return new MEDCoupling1DGTUMesh(name,cm);
1691 }
1692
1693 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
1694 {
1695 }
1696
1697 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
1698 {
1699   if(recDeepCpy)
1700     {
1701       const DataArrayInt *c(other._conn);
1702       if(c)
1703         _conn=c->deepCpy();
1704       c=other._conn_indx;
1705       if(c)
1706         _conn_indx=c->deepCpy();
1707     }
1708 }
1709
1710 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::clone(bool recDeepCpy) const
1711 {
1712   return new MEDCoupling1DGTUMesh(*this,recDeepCpy);
1713 }
1714
1715 /*!
1716  * This method behaves mostly like MEDCoupling1DGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
1717  * The coordinates are shared between \a this and the returned instance.
1718  * 
1719  * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
1720  * \sa MEDCoupling1DGTUMesh::deepCpy
1721  */
1722 MEDCouplingPointSet *MEDCoupling1DGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
1723 {
1724   checkCoherency();
1725   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(clone(false));
1726   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy()),ci(_conn_indx->deepCpy());
1727   ret->setNodalConnectivity(c,ci);
1728   return ret.retn();
1729 }
1730
1731 void MEDCoupling1DGTUMesh::updateTime() const
1732 {
1733   MEDCoupling1GTUMesh::updateTime();
1734   const DataArrayInt *c(_conn);
1735   if(c)
1736     updateTimeWith(*c);
1737   c=_conn_indx;
1738   if(c)
1739     updateTimeWith(*c);
1740 }
1741
1742 std::size_t MEDCoupling1DGTUMesh::getHeapMemorySize() const
1743 {
1744   std::size_t ret=0;
1745   const DataArrayInt *c(_conn);
1746   if(c)
1747     ret+=c->getHeapMemorySize();
1748   c=_conn_indx;
1749   if(c)
1750     ret+=c->getHeapMemorySize();
1751   return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
1752 }
1753
1754 MEDCouplingMesh *MEDCoupling1DGTUMesh::deepCpy() const
1755 {
1756   return clone(true);
1757 }
1758
1759 bool MEDCoupling1DGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1760 {
1761   if(!other)
1762     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualIfNotWhy : input other pointer is null !");
1763   std::ostringstream oss; oss.precision(15);
1764   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1765   if(!otherC)
1766     {
1767       reason="mesh given in input is not castable in MEDCoupling1DGTUMesh !";
1768       return false;
1769     }
1770   if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
1771     return false;
1772   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1773   if(c1==c2)
1774     return true;
1775   if(!c1 || !c2)
1776     {
1777       reason="in connectivity of single dynamic geometric type exactly one among this and other is null !";
1778       return false;
1779     }
1780   if(!c1->isEqualIfNotWhy(*c2,reason))
1781     {
1782       reason.insert(0,"Nodal connectivity DataArrayInt differs : ");
1783       return false;
1784     }
1785   c1=_conn_indx; c2=otherC->_conn_indx;
1786   if(c1==c2)
1787     return true;
1788   if(!c1 || !c2)
1789     {
1790       reason="in connectivity index of single dynamic geometric type exactly one among this and other is null !";
1791       return false;
1792     }
1793   if(!c1->isEqualIfNotWhy(*c2,reason))
1794     {
1795       reason.insert(0,"Nodal connectivity index DataArrayInt differs : ");
1796       return false;
1797     }
1798   return true;
1799 }
1800
1801 bool MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
1802 {
1803   if(!other)
1804     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
1805   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1806   if(!otherC)
1807     return false;
1808   if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
1809     return false;
1810   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1811   if(c1==c2)
1812     return true;
1813   if(!c1 || !c2)
1814     return false;
1815   if(!c1->isEqualWithoutConsideringStr(*c2))
1816     return false;
1817   return true;
1818   c1=_conn_indx; c2=otherC->_conn_indx;
1819   if(c1==c2)
1820     return true;
1821   if(!c1 || !c2)
1822     return false;
1823   if(!c1->isEqualWithoutConsideringStr(*c2))
1824     return false;
1825   return true;
1826 }
1827
1828 /*!
1829  * Checks if \a this and \a other meshes are geometrically equivalent with high
1830  * probability, else an exception is thrown. The meshes are considered equivalent if
1831  * (1) meshes contain the same number of nodes and the same number of elements of the
1832  * same types (2) three cells of the two meshes (first, last and middle) are based
1833  * on coincident nodes (with a specified precision).
1834  *  \param [in] other - the mesh to compare with.
1835  *  \param [in] prec - the precision used to compare nodes of the two meshes.
1836  *  \throw If the two meshes do not match.
1837  */
1838 void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1839 {
1840   MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1841   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1842   if(!otherC)
1843     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single dynamic geometric type !");
1844   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1845   if(c1!=c2)
1846     {
1847       if(!c1 || !c2)
1848         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1849       if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1850         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1851       if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1852         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1853       if(c1->getHashCode()!=c2->getHashCode())
1854         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1855     }
1856   c1=_conn_indx; c2=otherC->_conn_indx;
1857   if(c1!=c2)
1858     {
1859       if(!c1 || !c2)
1860         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity index only in one of the 2 meshes !");
1861       if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1862         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, only one is allocated !");
1863       if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1864         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, must have 1 and only 1 component !");
1865       if(c1->getHashCode()!=c2->getHashCode())
1866         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity index differs");
1867     }
1868 }
1869
1870 void MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception)
1871 {
1872   const DataArrayInt *c1(_conn);
1873   if(c1)
1874     {
1875       if(c1->getNumberOfComponents()!=1)
1876         throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
1877       if(c1->getInfoOnComponent(0)!="")
1878         throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
1879       c1->checkAllocated();
1880     }
1881   else
1882     throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
1883   //
1884   int sz2=_conn->getNumberOfTuples();
1885   c1=_conn_indx;
1886   if(c1)
1887     {
1888       if(c1->getNumberOfComponents()!=1)
1889         throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to be with number of components set to one !");
1890       c1->checkAllocated();
1891       if(c1->getNumberOfTuples()<1)
1892         throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have a a size of 1 at least !");
1893       if(c1->getInfoOnComponent(0)!="")
1894         throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have no info on its single component !");
1895       int f=c1->front(),ll=c1->back();
1896       if(f<0 || f>=sz2)
1897         {
1898           std::ostringstream oss; oss << "Nodal connectivity index array first value (" << f << ") is expected to be exactly in [0," << sz2 << ") !";
1899           throw INTERP_KERNEL::Exception(oss.str().c_str());
1900         }
1901       if(ll<0 || ll>sz2)
1902         {
1903           std::ostringstream oss; oss << "Nodal connectivity index array last value (" << ll << ") is expected to be exactly in [0," << sz2 << "] !";
1904           throw INTERP_KERNEL::Exception(oss.str().c_str());
1905         }
1906       if(f>ll)
1907         {
1908           std::ostringstream oss; oss << "Nodal connectivity index array looks very bad (not increasing monotonic) because front (" << f << ") is greater that back (" << ll << ") !";
1909           throw INTERP_KERNEL::Exception(oss.str().c_str());
1910         }
1911     }
1912   else
1913     throw INTERP_KERNEL::Exception("Nodal connectivity index array not defined !");
1914   int szOfC1Exp=_conn_indx->back();
1915   if(sz2<szOfC1Exp)
1916     {
1917       std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !";
1918       throw INTERP_KERNEL::Exception(oss.str().c_str());
1919     }
1920 }
1921
1922 /*!
1923  * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated.
1924  * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one.
1925  * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array.
1926  */
1927 void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
1928 {
1929   MEDCouplingPointSet::checkCoherency();
1930   checkCoherencyOfConnectivity();
1931 }
1932
1933 void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
1934 {
1935   checkCoherency();
1936   const DataArrayInt *c1(_conn),*c2(_conn_indx);
1937   if(!c2->isMonotonic(true))
1938     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkCoherency1 : the nodal connectivity index is expected to be increasing monotinic !");
1939   //
1940   int nbOfTuples=c1->getNumberOfTuples();
1941   int nbOfNodes=getNumberOfNodes();
1942   const int *w(c1->begin());
1943   for(int i=0;i<nbOfTuples;i++,w++)
1944     {
1945       if(*w==-1) continue;
1946       if(*w<0 || *w>=nbOfNodes)
1947         {
1948           std::ostringstream oss; oss << "At pos #" << i << " of nodal connectivity array references to node id #" << *w << " must be in [0," << nbOfNodes << ") !";
1949           throw INTERP_KERNEL::Exception(oss.str().c_str());
1950         }
1951     }
1952 }
1953
1954 void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
1955 {
1956   checkCoherency1(eps);
1957 }
1958
1959 int MEDCoupling1DGTUMesh::getNumberOfCells() const
1960 {
1961   checkCoherencyOfConnectivity();//do not remove
1962   return _conn_indx->getNumberOfTuples()-1;
1963 }
1964
1965 /*!
1966  * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1967  * For each cell in \b this the number of nodes constituting cell is computed.
1968  * For each polyhedron cell, the sum of the number of nodes of each face constituting polyhedron cell is returned.
1969  * So for pohyhedrons some nodes can be counted several times in the returned result.
1970  * 
1971  * \return a newly allocated array
1972  */
1973 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
1974 {
1975   checkCoherency();
1976   _conn_indx->checkMonotonic(true);
1977   if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1978     return _conn_indx->deltaShiftIndex();
1979   // for polyhedrons
1980   int nbOfCells=_conn_indx->getNumberOfTuples()-1;
1981   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1982   ret->alloc(nbOfCells,1);
1983   int *retPtr=ret->getPointer();
1984   const int *ci=_conn_indx->begin(),*c=_conn->begin();
1985   for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
1986     *retPtr=ci[1]-ci[0]-std::count(c+ci[0],c+ci[1],-1);
1987   return ret.retn();
1988 }
1989
1990 /*!
1991  * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1992  * For each cell in \b this the number of faces constituting (entity of dimension this->getMeshDimension()-1) cell is computed.
1993  * 
1994  * \return a newly allocated array
1995  */
1996 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
1997 {
1998   checkCoherency();
1999   _conn_indx->checkMonotonic(true);
2000   if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED && getCellModelEnum()!=INTERP_KERNEL::NORM_QPOLYG)
2001     return _conn_indx->deltaShiftIndex();
2002   if(getCellModelEnum()==INTERP_KERNEL::NORM_QPOLYG)
2003     {
2004       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=_conn_indx->deltaShiftIndex();
2005       ret->applyDivideBy(2);
2006       return ret.retn();
2007     }
2008   // for polyhedrons
2009   int nbOfCells=_conn_indx->getNumberOfTuples()-1;
2010   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2011   ret->alloc(nbOfCells,1);
2012   int *retPtr=ret->getPointer();
2013   const int *ci=_conn_indx->begin(),*c=_conn->begin();
2014   for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
2015     *retPtr=std::count(c+ci[0],c+ci[1],-1)+1;
2016   return ret.retn();
2017 }
2018
2019 /*!
2020  * This method computes effective number of nodes per cell. That is to say nodes appearing several times in nodal connectivity of a cell,
2021  * will be counted only once here whereas it will be counted several times in MEDCoupling1DGTUMesh::computeNbOfNodesPerCell method.
2022  *
2023  * \return DataArrayInt * - new object to be deallocated by the caller.
2024  * \sa MEDCoupling1DGTUMesh::computeNbOfNodesPerCell
2025  */
2026 DataArrayInt *MEDCoupling1DGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
2027 {
2028   checkCoherency();
2029   _conn_indx->checkMonotonic(true);
2030   int nbOfCells(_conn_indx->getNumberOfTuples()-1);
2031   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2032   ret->alloc(nbOfCells,1);
2033   int *retPtr(ret->getPointer());
2034   const int *ci(_conn_indx->begin()),*c(_conn->begin());
2035   if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
2036     {
2037       for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
2038         {
2039           std::set<int> s(c+ci[0],c+ci[1]);
2040           *retPtr=(int)s.size();
2041         }
2042     }
2043   else
2044     {
2045       for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
2046         {
2047           std::set<int> s(c+ci[0],c+ci[1]); s.erase(-1);
2048           *retPtr=(int)s.size();
2049         }
2050     }
2051   return ret.retn();
2052 }
2053
2054 void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
2055 {
2056   int nbOfCells=getNumberOfCells();//performs checks
2057   if(cellId>=0 && cellId<nbOfCells)
2058     {
2059       int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
2060       int nbOfNodes=stp-strt;
2061       if(nbOfNodes<0)
2062         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::getNodeIdsOfCell : the index array is invalid ! Should be increasing monotonic !");
2063       conn.resize(nbOfNodes);
2064       std::copy(_conn->begin()+strt,_conn->begin()+stp,conn.begin());
2065     }
2066   else
2067     {
2068       std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
2069       throw INTERP_KERNEL::Exception(oss.str().c_str());
2070     }
2071 }
2072
2073 std::string MEDCoupling1DGTUMesh::simpleRepr() const
2074 {
2075   static const char msg0[]="No coordinates specified !";
2076   std::ostringstream ret;
2077   ret << "Single dynamic geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
2078   ret << "Description of mesh : \"" << getDescription() << "\"\n";
2079   int tmpp1,tmpp2;
2080   double tt=getTime(tmpp1,tmpp2);
2081   ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
2082   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
2083   ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
2084   if(_coords!=0)
2085     {
2086       const int spaceDim=getSpaceDimension();
2087       ret << spaceDim << "\nInfo attached on space dimension : ";
2088       for(int i=0;i<spaceDim;i++)
2089         ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
2090       ret << "\n";
2091     }
2092   else
2093     ret << msg0 << "\n";
2094   ret << "Number of nodes : ";
2095   if(_coords!=0)
2096     ret << getNumberOfNodes() << "\n";
2097   else
2098     ret << msg0 << "\n";
2099   ret << "Number of cells : ";
2100   bool isOK=true;
2101   try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
2102     {
2103       ret << "Nodal connectivity arrays are not set or badly set !\n";
2104       isOK=false;
2105     }
2106   if(isOK)
2107     ret << getNumberOfCells() << "\n";
2108   ret << "Cell type : " << _cm->getRepr() << "\n";
2109   return ret.str();
2110 }
2111
2112 std::string MEDCoupling1DGTUMesh::advancedRepr() const
2113 {
2114   std::ostringstream ret;
2115   ret << simpleRepr();
2116   ret << "\nCoordinates array : \n___________________\n\n";
2117   if(_coords)
2118     _coords->reprWithoutNameStream(ret);
2119   else
2120     ret << "No array set !\n";
2121   ret << "\n\nNodal Connectivity : \n____________________\n\n";
2122   //
2123   bool isOK=true;
2124   try { checkCoherency1(); } catch(INTERP_KERNEL::Exception& e)
2125     {
2126       ret << "Nodal connectivity arrays are not set or badly set !\n";
2127       isOK=false;
2128     }
2129   if(!isOK)
2130     return ret.str();
2131   int nbOfCells=getNumberOfCells();
2132   const int *ci=_conn_indx->begin(),*c=_conn->begin();
2133   for(int i=0;i<nbOfCells;i++,ci++)
2134     {
2135       ret << "Cell #" << i << " : ";
2136       std::copy(c+ci[0],c+ci[1],std::ostream_iterator<int>(ret," "));
2137       ret << "\n";
2138     }
2139   return ret.str();
2140 }
2141
2142 DataArrayDouble *MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
2143 {
2144   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2145   int spaceDim=getSpaceDimension();
2146   int nbOfCells=getNumberOfCells();//checkCoherency()
2147   int nbOfNodes=getNumberOfNodes();
2148   ret->alloc(nbOfCells,spaceDim);
2149   double *ptToFill=ret->getPointer();
2150   const double *coor=_coords->begin();
2151   const int *nodal=_conn->begin(),*nodali=_conn_indx->begin();
2152   nodal+=nodali[0];
2153   if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
2154     {
2155       for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
2156         {
2157           std::fill(ptToFill,ptToFill+spaceDim,0.);
2158           if(nodali[0]<nodali[1])// >= to avoid division by 0.
2159             {
2160               for(int j=nodali[0];j<nodali[1];j++,nodal++)
2161                 {
2162                   if(*nodal>=0 && *nodal<nbOfNodes)
2163                     std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
2164                   else
2165                     {
2166                       std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," <<   nbOfNodes << ") !";
2167                       throw INTERP_KERNEL::Exception(oss.str().c_str());
2168                     }
2169                   std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./(nodali[1]-nodali[0])));
2170                 }
2171             }
2172           else
2173             {
2174               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : at cell #" << i << " the nodal index array is invalid !";
2175               throw INTERP_KERNEL::Exception(oss.str().c_str());
2176             }
2177         }
2178     }
2179   else
2180     {
2181       for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
2182         {
2183           std::fill(ptToFill,ptToFill+spaceDim,0.);
2184           if(nodali[0]<nodali[1])// >= to avoid division by 0.
2185             {
2186               int nbOfNod=0;
2187               for(int j=nodali[0];j<nodali[1];j++,nodal++)
2188                 {
2189                   if(*nodal==-1) continue;
2190                   if(*nodal>=0 && *nodal<nbOfNodes)
2191                     {
2192                       std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
2193                       nbOfNod++;
2194                     }
2195                   else
2196                     {
2197                       std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," <<   nbOfNodes << ") !";
2198                       throw INTERP_KERNEL::Exception(oss.str().c_str());
2199                     }
2200                 }
2201               if(nbOfNod!=0)
2202                 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./nbOfNod));
2203               else
2204                 {
2205                   std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : no nodes in cell #" << i << " !";
2206                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2207                 }
2208             }
2209           else
2210             {
2211               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron)  : at cell #" << i << " the nodal index array is invalid !";
2212               throw INTERP_KERNEL::Exception(oss.str().c_str());
2213             }
2214         }
2215     }
2216   return ret.retn();
2217 }
2218
2219 void MEDCoupling1DGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
2220 {
2221   int nbCells=getNumberOfCells();
2222   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
2223   o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
2224   if(check)
2225     o2n=o2n->checkAndPreparePermutation();
2226   //
2227   const int *o2nPtr=o2n->getPointer();
2228   const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2229   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
2230   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConnI=DataArrayInt::New();
2231   newConn->alloc(_conn->getNumberOfTuples(),1); newConnI->alloc(nbCells,1);
2232   newConn->copyStringInfoFrom(*_conn); newConnI->copyStringInfoFrom(*_conn_indx);
2233   //
2234   int *newC=newConn->getPointer(),*newCI=newConnI->getPointer();
2235   for(int i=0;i<nbCells;i++)
2236     {
2237       int newPos=o2nPtr[i];
2238       int sz=conni[i+1]-conni[i];
2239       if(sz>=0)
2240         newCI[newPos]=sz;
2241       else
2242         {
2243           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberCells : the index nodal array is invalid for cell #" << i << " !";
2244           throw INTERP_KERNEL::Exception(oss.str().c_str());
2245         }
2246     }
2247   newConnI->computeOffsets2(); newCI=newConnI->getPointer();
2248   //
2249   for(int i=0;i<nbCells;i++,conni++)
2250     {
2251       int sz=conni[1]-conni[0];
2252       int newp=o2nPtr[i];
2253       std::copy(conn+conni[0],conn+conni[1],newC+newCI[newp]);
2254     }
2255   _conn=newConn;
2256   _conn_indx=newConnI;
2257 }
2258
2259 MEDCouplingMesh *MEDCoupling1DGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
2260 {
2261   if(other->getType()!=SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED)
2262     throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single dynamic geo type each other !");
2263   const MEDCoupling1DGTUMesh *otherC=static_cast<const MEDCoupling1DGTUMesh *>(other);
2264   return Merge1DGTUMeshes(this,otherC);
2265 }
2266
2267 MEDCouplingUMesh *MEDCoupling1DGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
2268 {
2269   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension());
2270   ret->setCoords(getCoords());
2271   const int *nodalConn=_conn->begin(),*nodalConnI=_conn_indx->begin();
2272   int nbCells=getNumberOfCells();//checkCoherency
2273   int geoType=(int)getCellModelEnum();
2274   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells+_conn->getNumberOfTuples(),1);
2275   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::New(); cI->alloc(nbCells+1);
2276   int *cPtr=c->getPointer(),*ciPtr=cI->getPointer();
2277   ciPtr[0]=0;
2278   for(int i=0;i<nbCells;i++,ciPtr++)
2279     {
2280       int sz=nodalConnI[i+1]-nodalConnI[i];
2281       if(sz>=0)
2282         {
2283           *cPtr++=geoType;
2284           cPtr=std::copy(nodalConn+nodalConnI[i],nodalConn+nodalConnI[i+1],cPtr);
2285           ciPtr[1]=ciPtr[0]+sz+1;
2286         }
2287       else
2288         {
2289           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::buildUnstructured : Invalid for nodal index for cell #" << i << " !";
2290           throw INTERP_KERNEL::Exception(oss.str().c_str());
2291         }
2292     }
2293   ret->setConnectivity(c,cI,true);
2294   return ret.retn();
2295 }
2296
2297 /*!
2298  * Do nothing for the moment, because there is no policy that allows to split polygons, polyhedrons ... into simplexes
2299  */
2300 DataArrayInt *MEDCoupling1DGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
2301 {
2302   int nbOfCells=getNumberOfCells();
2303   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2304   ret->alloc(nbOfCells,1);
2305   ret->iota(0);
2306   return ret.retn();
2307 }
2308
2309 void MEDCoupling1DGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
2310 {
2311   stream << "MEDCoupling1DGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
2312   stream << " Mesh dimension : " << getMeshDimension() << ".";
2313   if(!_coords)
2314     { stream << " No coordinates set !"; return ; }
2315   if(!_coords->isAllocated())
2316     { stream << " Coordinates set but not allocated !"; return ; }
2317   stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
2318   stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
2319   bool isOK=true;
2320   try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
2321     {
2322       stream << std::endl << "Nodal connectivity NOT set properly !\n";
2323       isOK=false;
2324     }
2325   if(isOK)
2326     stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
2327 }
2328
2329 void MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
2330 {
2331   if(!other)
2332     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
2333   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2334   if(!otherC)
2335     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1DGTUMesh instance !");
2336   setNodalConnectivity(otherC->getNodalConnectivity(),otherC->getNodalConnectivityIndex());
2337 }
2338
2339 MEDCouplingPointSet *MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
2340 {
2341   if(!other)
2342     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
2343   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2344   if(!otherC)
2345     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
2346   std::vector<const MEDCoupling1DGTUMesh *> ms(2);
2347   ms[0]=this;
2348   ms[1]=otherC;
2349   return Merge1DGTUMeshesOnSameCoords(ms);
2350 }
2351
2352 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
2353 {
2354   checkCoherency();
2355   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
2356   ret->setCoords(_coords);
2357   DataArrayInt *c=0,*ci=0;
2358   MEDCouplingUMesh::ExtractFromIndexedArrays(begin,end,_conn,_conn_indx,c,ci);
2359   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2360   ret->setNodalConnectivity(c,ci);
2361   return ret.retn();
2362 }
2363
2364 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
2365 {
2366   checkCoherency();
2367   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
2368   ret->setCoords(_coords);
2369   DataArrayInt *c=0,*ci=0;
2370   MEDCouplingUMesh::ExtractFromIndexedArrays2(start,end,step,_conn,_conn_indx,c,ci);
2371   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2372   ret->setNodalConnectivity(c,ci);
2373   return ret.retn();
2374 }
2375
2376 void MEDCoupling1DGTUMesh::computeNodeIdsAlg(std::vector<bool>& nodeIdsInUse) const throw(INTERP_KERNEL::Exception)
2377 {
2378   int sz((int)nodeIdsInUse.size());
2379   int nbCells(getNumberOfCells());
2380   const int *w(_conn->begin()),*wi(_conn_indx->begin());
2381   for(int i=0;i<nbCells;i++,wi++)
2382     for(const int *pt=w+wi[0];pt!=w+wi[1];pt++)
2383       if(*pt!=-1)
2384         {
2385           if(*pt>=0 && *pt<sz)
2386             nodeIdsInUse[*pt]=true;
2387           else
2388             {
2389               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeNodeIdsAlg : At cell #" << i << " presence of node id #" << *pt << " should be in [0," << sz << ") !";
2390               throw INTERP_KERNEL::Exception(oss.str().c_str());
2391             }
2392         }
2393 }
2394
2395 void MEDCoupling1DGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
2396 {
2397   checkFullyDefined();
2398   int nbOfNodes=getNumberOfNodes();
2399   int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
2400   revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
2401   std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
2402   const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2403   int nbOfCells=getNumberOfCells();
2404   int nbOfEltsInRevNodal=0;
2405   for(int eltId=0;eltId<nbOfCells;eltId++)
2406     {
2407       int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2408       if(nbOfNodesPerCell>=0)
2409         {
2410           for(int j=0;j<nbOfNodesPerCell;j++)
2411             {
2412               int nodeId=conn[conni[eltId]+j];
2413               if(nodeId==-1) continue;            
2414               if(nodeId>=0 && nodeId<nbOfNodes)
2415                 {
2416                   nbOfEltsInRevNodal++;
2417                   revNodalIndxPtr[nodeId+1]++;
2418                 }
2419               else
2420                 {
2421                   std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
2422                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2423                 }
2424             }
2425         }
2426       else
2427         {
2428           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << "nodal connectivity is invalid !";
2429           throw INTERP_KERNEL::Exception(oss.str().c_str());
2430         }
2431     }
2432   std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
2433   conn=_conn->begin();
2434   int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
2435   revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
2436   std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
2437   for(int eltId=0;eltId<nbOfCells;eltId++)
2438     {
2439       int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2440       for(int j=0;j<nbOfNodesPerCell;j++)
2441         {
2442           int nodeId=conn[conni[eltId]+j];
2443           if(nodeId!=-1)
2444             *std::find_if(revNodalPtr+revNodalIndxPtr[nodeId],revNodalPtr+revNodalIndxPtr[nodeId+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
2445         }
2446     }
2447 }
2448
2449 void MEDCoupling1DGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
2450 {
2451   if(!((const DataArrayInt *)_conn) || !((const DataArrayInt *)_conn_indx) || !((const DataArrayDouble *)_coords))
2452     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFullyDefined : part of this is not fully defined.");
2453 }
2454
2455 bool MEDCoupling1DGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
2456 {
2457   throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEmptyMesh : not implemented yet !");
2458 }
2459
2460 /*!
2461  * Finds nodes not used in any cell and returns an array giving a new id to every node
2462  * by excluding the unused nodes, for which the array holds -1. The result array is
2463  * a mapping in "Old to New" mode. 
2464  *  \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
2465  *  \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
2466  *          this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
2467  *          if the node is unused or a new id else. The caller is to delete this
2468  *          array using decrRef() as it is no more needed.  
2469  *  \throw If the coordinates array is not set.
2470  *  \throw If the nodal connectivity of cells is not defined.
2471  *  \throw If the nodal connectivity includes an invalid id.
2472  */
2473 DataArrayInt *MEDCoupling1DGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
2474 {
2475   nbrOfNodesInUse=-1;
2476   int nbOfNodes=getNumberOfNodes();
2477   int nbOfCells=getNumberOfCells();//checkCoherency
2478   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2479   ret->alloc(nbOfNodes,1);
2480   int *traducer=ret->getPointer();
2481   std::fill(traducer,traducer+nbOfNodes,-1);
2482   const int *conn=_conn->begin(),*conni(_conn_indx->begin());
2483   for(int i=0;i<nbOfCells;i++,conni++)
2484     {
2485       int nbNodesPerCell=conni[1]-conni[0];
2486       for(int j=0;j<nbNodesPerCell;j++)
2487         {
2488           int nodeId=conn[conni[0]+j];
2489           if(nodeId==-1) continue;
2490           if(nodeId>=0 && nodeId<nbOfNodes)
2491             traducer[nodeId]=1;
2492           else
2493             {
2494               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsInUse : In cell #" << i  << " presence of node id " <<  nodeId << " not in [0," << nbOfNodes << ") !";
2495               throw INTERP_KERNEL::Exception(oss.str().c_str());
2496             }
2497         }
2498     }
2499   nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
2500   std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
2501   return ret.retn();
2502 }
2503
2504 /*!
2505  * Changes ids of nodes within the nodal connectivity arrays according to a permutation
2506  * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
2507  * This method is a generalization of shiftNodeNumbersInConn().
2508  *  \warning This method performs no check of validity of new ids. **Use it with care !**
2509  *  \param [in] newNodeNumbersO2N - a permutation array, of length \a
2510  *         this->getNumberOfNodes(), in "Old to New" mode. 
2511  *         See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
2512  *  \throw If the nodal connectivity of cells is not defined.
2513  */
2514 void MEDCoupling1DGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
2515 {
2516   getNumberOfCells();//only to check that all is well defined.
2517   //
2518   int nbElemsIn=getNumberOfNodes();
2519   int nbOfTuples=_conn->getNumberOfTuples();
2520   int *pt=_conn->getPointer();
2521   for(int i=0;i<nbOfTuples;i++,pt++)
2522     {
2523       if(*pt==-1) continue;
2524       if(*pt>=0 && *pt<nbElemsIn)
2525         *pt=newNodeNumbersO2N[*pt];
2526       else
2527         {
2528           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
2529           throw INTERP_KERNEL::Exception(oss.str().c_str());
2530         }
2531     }
2532   _conn->declareAsNew();
2533   //
2534   updateTime();
2535 }
2536
2537 /*!
2538  * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
2539  * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
2540  * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
2541  * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
2542  *
2543  * \param [in] begin input start of array of node ids.
2544  * \param [in] end input end of array of node ids.
2545  * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
2546  * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
2547  */
2548 void MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
2549 {
2550   int nbOfCells=getNumberOfCells();
2551   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
2552   int tmp=-1;
2553   int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
2554   std::vector<bool> fastFinder(sz,false);
2555   for(const int *work=begin;work!=end;work++)
2556     if(*work>=0 && *work<sz)
2557       fastFinder[*work]=true;
2558   const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2559   for(int i=0;i<nbOfCells;i++,conni++)
2560     {
2561       int ref=0,nbOfHit=0;
2562       int nbNodesPerCell=conni[1]-conni[0];
2563       if(nbNodesPerCell>=0)
2564         {
2565           for(int j=0;j<nbNodesPerCell;j++)
2566             {
2567               int nodeId=conn[conni[0]+j];
2568               if(nodeId>=0)
2569                 {
2570                   ref++;
2571                   if(fastFinder[nodeId])
2572                     nbOfHit++;
2573                 }
2574             }
2575         }
2576       else
2577         {
2578           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds : invalid index array for cell #" << i << " !";
2579           throw INTERP_KERNEL::Exception(oss.str().c_str());
2580         }
2581       if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
2582         cellIdsKept->pushBackSilent(i);
2583     }
2584   cellIdsKeptArr=cellIdsKept.retn();
2585 }
2586
2587 void MEDCoupling1DGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
2588 {
2589   if(nbOfCells<0)
2590     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::allocateCells : the input number of cells should be >= 0 !");
2591   _conn=DataArrayInt::New();
2592   _conn->reserve(nbOfCells*3);
2593   _conn_indx=DataArrayInt::New();
2594   _conn_indx->reserve(nbOfCells+1); _conn_indx->pushBackSilent(0);
2595   declareAsNew();
2596 }
2597
2598 /*!
2599  * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
2600  *
2601  * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
2602  * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
2603  * \throw If the length of the input nodal connectivity array of the cell to add is not equal to number of nodes per cell relative to the unique geometric type
2604  *        attached to \a this.
2605  * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
2606  */
2607 void MEDCoupling1DGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
2608 {
2609   int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
2610   DataArrayInt *c(_conn),*c2(_conn_indx);
2611   if(c && c2)
2612     {
2613       int pos=c2->back();
2614       if(pos==c->getNumberOfTuples())
2615         {
2616           c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
2617           c2->pushBackSilent(pos+sz);
2618         }
2619       else
2620         {
2621           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::insertNextCell : The nodal index array (end=" << pos << ") mismatches with nodal array (length=" << c->getNumberOfTuples() << ") !";
2622           throw INTERP_KERNEL::Exception(oss.str().c_str());
2623         }
2624     }
2625   else
2626     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1DGTUMesh::allocateCells before !");
2627 }
2628
2629 void MEDCoupling1DGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn, DataArrayInt *nodalConnIndex) throw(INTERP_KERNEL::Exception)
2630 {
2631   if(nodalConn)
2632     nodalConn->incrRef();
2633   _conn=nodalConn;
2634   if(nodalConnIndex)
2635     nodalConnIndex->incrRef();
2636   _conn_indx=nodalConnIndex;
2637   declareAsNew();
2638 }
2639
2640 /*!
2641  * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
2642  */
2643 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
2644 {
2645   const DataArrayInt *ret(_conn);
2646   return const_cast<DataArrayInt *>(ret);
2647 }
2648
2649 /*!
2650  * \return DataArrayInt * - the internal reference to the nodal connectivity index. The caller is not reponsible to deallocate it.
2651  */
2652 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivityIndex() const throw(INTERP_KERNEL::Exception)
2653 {
2654   const DataArrayInt *ret(_conn_indx);
2655   return const_cast<DataArrayInt *>(ret);
2656 }
2657
2658 /*!
2659  * See the definition of the nodal connectivity pack \ref MEDCoupling1DGTUMesh::isPacked "here".
2660  * This method tries to build a new instance geometrically equivalent to \a this, by limiting at most the number of new object (nodal connectivity).
2661  * Geometrically the returned mesh is equal to \a this. So if \a this is already packed, the return value is a shallow copy of \a this.
2662  *
2663  * Whatever the status of pack of \a this, the coordinates array of the returned newly created instance is the same than those in \a this.
2664  * 
2665  * \param [out] isShallowCpyOfNodalConnn - tells if the returned instance share the same pair of nodal connectivity arrays (true) or if nodal
2666  *              connectivity arrays are different (false)
2667  * \return a new object to be managed by the caller.
2668  * 
2669  * \sa MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity, MEDCoupling1DGTUMesh::isPacked
2670  */
2671 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::copyWithNodalConnectivityPacked(bool& isShallowCpyOfNodalConnn) const throw(INTERP_KERNEL::Exception)
2672 {
2673   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
2674   DataArrayInt *nc=0,*nci=0;
2675   isShallowCpyOfNodalConnn=retrievePackedNodalConnectivity(nc,nci);
2676   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ncs(nc),ncis(nci);
2677   ret->_conn=ncs; ret->_conn_indx=ncis;
2678   ret->setCoords(getCoords());
2679   return ret.retn();
2680 }
2681
2682 /*!
2683  * This method allows to compute, if needed, the packed nodal connectivity pair.
2684  * Indeed, it is possible to store in \a this a nodal connectivity array bigger than ranges convered by nodal connectivity index array.
2685  * It is typically the case when nodalConnIndx starts with an id greater than 0, and finishes with id less than number of tuples in \c this->_conn.
2686  * 
2687  * If \a this looks packed (the front of nodal connectivity index equal to 0 and back of connectivity index equal to number of tuple of nodal connectivity array)
2688  * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2689  *
2690  * If nodal connectivity index points to a subpart of nodal connectivity index the packed pair of arrays will be computed (new objects) and returned and false
2691  * will be returned.
2692  * 
2693  * This method return 3 elements.
2694  * \param [out] nodalConn - a pointer that can be equal to \a this->_conn if true is returned (general case). Whatever the value of return parameter
2695  *                          this pointer can be seen as a new object, that is to managed by the caller.
2696  * \param [out] nodalConnIndx - a pointer that can be equal to \a this->_conn_indx if true is returned (general case). Whatever the value of return parameter
2697  *                              this pointer can be seen as a new object, that is to managed by the caller.
2698  * \return bool - an indication of the content of the 2 output parameters. If true, \a this looks packed (general case), if true, \a this is not packed then
2699  * output parameters are newly created objects.
2700  *
2701  * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2702  */
2703 bool MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity(DataArrayInt *&nodalConn, DataArrayInt *&nodalConnIndx) const throw(INTERP_KERNEL::Exception)
2704 {
2705   if(isPacked())//performs the checkCoherency
2706     {
2707       const DataArrayInt *c0(_conn),*c1(_conn_indx);
2708       nodalConn=const_cast<DataArrayInt *>(c0); nodalConnIndx=const_cast<DataArrayInt *>(c1);
2709       nodalConn->incrRef(); nodalConnIndx->incrRef();
2710       return true;
2711     }
2712   int bg=_conn_indx->front(),end=_conn_indx->back();
2713   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nc(_conn->selectByTupleId2(bg,end,1));
2714   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nci(_conn_indx->deepCpy());
2715   nci->applyLin(1,-bg);
2716   nodalConn=nc.retn(); nodalConnIndx=nci.retn();
2717   return false;
2718 }
2719
2720 /*
2721  * If \a this looks packed (the front of nodal connectivity index equal to 0 and back of connectivity index equal to number of tuple of nodal connectivity array)
2722  * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2723  * If nodal connectivity index points to a subpart of nodal connectivity index false will be returned.
2724  * \return bool - true if \a this looks packed, false is not.
2725  *
2726  * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2727  */
2728 bool MEDCoupling1DGTUMesh::isPacked() const throw(INTERP_KERNEL::Exception)
2729 {
2730   checkCoherency();
2731   return _conn_indx->front()==0 && _conn_indx->back()==_conn->getNumberOfTuples();
2732 }
2733
2734 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(const MEDCoupling1DGTUMesh *mesh1, const MEDCoupling1DGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
2735 {
2736   std::vector<const MEDCoupling1DGTUMesh *> tmp(2);
2737   tmp[0]=const_cast<MEDCoupling1DGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1DGTUMesh *>(mesh2);
2738   return Merge1DGTUMeshes(tmp);
2739 }
2740
2741 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2742 {
2743   std::size_t sz=a.size();
2744   if(sz==0)
2745     return Merge1DGTUMeshesLL(a);
2746   for(std::size_t ii=0;ii<sz;ii++)
2747     if(!a[ii])
2748       {
2749         std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::Merge1DGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
2750         throw INTERP_KERNEL::Exception(oss.str().c_str());
2751       }
2752   const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
2753   for(std::size_t ii=0;ii<sz;ii++)
2754     if(&(a[ii]->getCellModel())!=cm)
2755       throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : all items must have the same geo type !");
2756   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > bb(sz);
2757   std::vector< const MEDCoupling1DGTUMesh * > aa(sz);
2758   int spaceDim=-3;
2759   for(std::size_t i=0;i<sz && spaceDim==-3;i++)
2760     {
2761       const MEDCoupling1DGTUMesh *cur=a[i];
2762       const DataArrayDouble *coo=cur->getCoords();
2763       if(coo)
2764         spaceDim=coo->getNumberOfComponents();
2765     }
2766   if(spaceDim==-3)
2767     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : no spaceDim specified ! unable to perform merge !");
2768   for(std::size_t i=0;i<sz;i++)
2769     {
2770       bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
2771       aa[i]=bb[i];
2772     }
2773   return Merge1DGTUMeshesLL(aa);
2774 }
2775
2776 /*!
2777  * \throw If presence of a null instance in the input vector \a a.
2778  * \throw If a is empty
2779  */
2780 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2781 {
2782   if(a.empty())
2783     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : input array must be NON EMPTY !");
2784   std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2785   if(!(*it))
2786     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : null instance in the first element of input vector !");
2787   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2788   std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2789   int nbOfCells=(*it)->getNumberOfCells();
2790   const DataArrayDouble *coords=(*it)->getCoords();
2791   const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2792   bool tmp;
2793   objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2794   ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2795   it++;
2796   for(int i=1;it!=a.end();i++,it++)
2797     {
2798       if(!(*it))
2799         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : presence of null instance !");
2800       if(cm!=&((*it)->getCellModel()))
2801         throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2802       (*it)->getNumberOfCells();//to check that all is OK
2803       objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2804       ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2805       if(coords!=(*it)->getCoords())
2806         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : not lying on same coords !");
2807     }
2808   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2809   ret->setCoords(coords);
2810   ret->_conn=DataArrayInt::Aggregate(ncs);
2811   ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2812   return ret.retn();
2813 }
2814
2815 /*!
2816  * Assume that all instances in \a a are non null. If null it leads to a crash. That's why this method is assigned to be low level (LL)
2817  */
2818 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesLL(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2819 {
2820   if(a.empty())
2821     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : input array must be NON EMPTY !");
2822   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2823   std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2824   std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2825   std::vector<int> nbNodesPerElt(a.size());
2826   int nbOfCells=(*it)->getNumberOfCells();
2827   bool tmp;
2828   objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2829   ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2830   nbNodesPerElt[0]=0;
2831   int prevNbOfNodes=(*it)->getNumberOfNodes();
2832   const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2833   it++;
2834   for(int i=1;it!=a.end();i++,it++)
2835     {
2836       if(cm!=&((*it)->getCellModel()))
2837         throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2838       objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2839       ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2840       nbOfCells+=(*it)->getNumberOfCells();
2841       nbNodesPerElt[i]=nbNodesPerElt[i-1]+prevNbOfNodes;
2842       prevNbOfNodes=(*it)->getNumberOfNodes();
2843     }
2844   std::vector<const MEDCouplingPointSet *> aps(a.size());
2845   std::copy(a.begin(),a.end(),aps.begin());
2846   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
2847   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2848   ret->setCoords(pts);
2849   ret->_conn=AggregateNodalConnAndShiftNodeIds(ncs,nbNodesPerElt);
2850   ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2851   return ret.retn();
2852 }
2853
2854 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
2855 {
2856   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
2857   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1,tmp2;
2858   const DataArrayInt *nodalConn(_conn),*nodalConnI(_conn_indx);
2859   if(!nodalConn)
2860     {
2861       tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
2862     }
2863   else
2864     tmp1=_conn;
2865   ret->_conn=tmp1;
2866   //
2867   if(!nodalConnI)
2868     {
2869       tmp2=DataArrayInt::New(); tmp2->alloc(1,1); tmp2->setIJ(0,0,0);
2870     }
2871   else
2872     tmp2=_conn_indx;
2873   ret->_conn_indx=tmp2;
2874   //
2875   if(!_coords)
2876     {
2877       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
2878       ret->setCoords(coords);
2879     }
2880   else
2881     ret->setCoords(_coords);
2882   return ret.retn();
2883 }
2884
2885 std::vector<int> MEDCoupling1DGTUMesh::BuildAPolygonFromParts(const std::vector< std::vector<int> >& parts) throw(INTERP_KERNEL::Exception)
2886 {
2887   std::vector<int> ret;
2888   if(parts.empty())
2889     return ret;
2890   ret.insert(ret.end(),parts[0].begin(),parts[0].end());
2891   int ref(ret.back());
2892   std::size_t sz(parts.size()),nbh(1);
2893   std::vector<bool> b(sz,true); b[0]=false;
2894   while(nbh<sz)
2895     {
2896       std::size_t i(0);
2897       for(;i<sz;i++) if(b[i] && parts[i].front()==ref) { ret.insert(ret.end(),parts[i].begin()+1,parts[i].end()); nbh++; break; }
2898       if(i<sz)
2899         ref=ret.back();
2900       else
2901         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::BuildAPolygonFromParts : the input vector is not a part of a single polygon !");
2902     }
2903   if(ret.back()==ret.front())
2904     ret.pop_back();
2905   return ret;
2906 }
2907
2908 /*!
2909  * This method performs an aggregation of \a nodalConns (as DataArrayInt::Aggregate does) but in addition of that a shift is applied on the 
2910  * values contained in \a nodalConns using corresponding offset specified in input \a offsetInNodeIdsPerElt.
2911  * But it also manage the values -1, that have a semantic in MEDCoupling1DGTUMesh class (separator for polyhedron).
2912  *
2913  * \param [in] nodalConns - a list of nodal connectivity arrays same size than \a offsetInNodeIdsPerElt.
2914  * \param [in] offsetInNodeIdsPerElt - a list of offsets to apply.
2915  * \return DataArrayInt * - A new object (to be managed by the caller) that is the result of the aggregation.
2916  * \throw If \a nodalConns or \a offsetInNodeIdsPerElt are empty.
2917  * \throw If \a nodalConns and \a offsetInNodeIdsPerElt have not the same size.
2918  * \throw If presence of null pointer in \a nodalConns.
2919  * \throw If presence of not allocated or array with not exactly one component in \a nodalConns.
2920  */
2921 DataArrayInt *MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds(const std::vector<const DataArrayInt *>& nodalConns, const std::vector<int>& offsetInNodeIdsPerElt) throw(INTERP_KERNEL::Exception)
2922 {
2923   std::size_t sz1(nodalConns.size()),sz2(offsetInNodeIdsPerElt.size());
2924   if(sz1!=sz2)
2925     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : input vectors do not have the same size !");
2926   if(sz1==0)
2927     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : empty vectors in input !");
2928   int nbOfTuples=0;
2929   for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++)
2930     {
2931       if(!(*it))
2932         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of null pointer in input vector !");
2933       if(!(*it)->isAllocated())
2934         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of non allocated array in input vector !");
2935       if((*it)->getNumberOfComponents()!=1)
2936         throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of array with not exactly one component !");
2937       nbOfTuples+=(*it)->getNumberOfTuples();
2938     }
2939   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
2940   int *pt=ret->getPointer();
2941   int i=0;
2942   for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++,i++)
2943     {
2944       int curNbt=(*it)->getNumberOfTuples();
2945       const int *inPt=(*it)->begin();
2946       int offset=offsetInNodeIdsPerElt[i];
2947       for(int j=0;j<curNbt;j++,pt++)
2948         {
2949           if(inPt[j]!=-1)
2950             *pt=inPt[j]+offset;
2951           else
2952             *pt=-1;
2953         }
2954     }
2955   return ret.retn();
2956 }
2957
2958 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
2959 {
2960   if(!m)
2961     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh is null !");
2962   std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
2963   if(gts.size()!=1)
2964     throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh must have exactly one geometric type !");
2965   int geoType((int)*gts.begin());
2966   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(m->getName().c_str(),*gts.begin()));
2967   ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str());
2968   int nbCells(m->getNumberOfCells());
2969   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
2970   conn->alloc(m->getMeshLength()-nbCells,1); connI->alloc(nbCells+1,1);
2971   int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
2972   const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
2973   for(int i=0;i<nbCells;i++,ciin++,ci++)
2974     {
2975       if(cin[ciin[0]]==geoType)
2976         {
2977           if(ciin[1]-ciin[0]>=1)
2978             {
2979               c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
2980               ci[1]=ci[0]+ciin[1]-ciin[0]-1;
2981             }
2982           else
2983             {
2984               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not >=0 !";
2985               throw INTERP_KERNEL::Exception(oss.str().c_str());
2986             }
2987         }
2988       else
2989         {
2990           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
2991           throw INTERP_KERNEL::Exception(oss.str().c_str());
2992         }
2993     }
2994   ret->setNodalConnectivity(conn,connI);
2995   return ret.retn();
2996 }