Salome HOME
Debug on Colinearize2D.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingCurveLinearMesh.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingCurveLinearMesh.hxx"
22 #include "MEDCouplingPointSet.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25
26 #include "VolSurfUser.txx"
27 #include "PointLocatorAlgos.txx"
28
29 #include <functional>
30 #include <algorithm>
31 #include <sstream>
32 #include <numeric>
33
34 using namespace ParaMEDMEM;
35
36 MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh():_coords(0),_structure(0)
37 {
38 }
39
40 MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_structure(other._structure)
41 {
42   if(deepCopy)
43     {
44       if((const DataArrayDouble *)other._coords)
45         _coords=other._coords->deepCpy();
46     }
47   else
48     _coords=other._coords;
49 }
50
51 MEDCouplingCurveLinearMesh::~MEDCouplingCurveLinearMesh()
52 {
53 }
54
55 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::New()
56 {
57   return new MEDCouplingCurveLinearMesh;
58 }
59
60 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::New(const std::string& meshName)
61 {
62   MEDCouplingCurveLinearMesh *ret=new MEDCouplingCurveLinearMesh;
63   ret->setName(meshName);
64   return ret;
65 }
66
67 MEDCouplingMesh *MEDCouplingCurveLinearMesh::deepCpy() const
68 {
69   return clone(true);
70 }
71
72 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::clone(bool recDeepCpy) const
73 {
74   return new MEDCouplingCurveLinearMesh(*this,recDeepCpy);
75 }
76
77 void MEDCouplingCurveLinearMesh::updateTime() const
78 {
79   if((const DataArrayDouble *)_coords)
80     updateTimeWith(*_coords);
81 }
82
83 std::size_t MEDCouplingCurveLinearMesh::getHeapMemorySizeWithoutChildren() const
84 {
85   std::size_t ret(MEDCouplingStructuredMesh::getHeapMemorySizeWithoutChildren());
86   ret+=_structure.capacity()*sizeof(int);
87   return ret;
88 }
89
90 std::vector<const BigMemoryObject *> MEDCouplingCurveLinearMesh::getDirectChildren() const
91 {
92   std::vector<const BigMemoryObject *> ret;
93   if((const DataArrayDouble *)_coords)
94     ret.push_back((const DataArrayDouble *)_coords);
95   return ret;
96 }
97
98 /*!
99  * This method copyies all tiny strings from other (name and components name).
100  * @throw if other and this have not same mesh type.
101  */
102 void MEDCouplingCurveLinearMesh::copyTinyStringsFrom(const MEDCouplingMesh *other)
103
104   const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
105   if(!otherC)
106     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::copyTinyStringsFrom : meshes have not same type !");
107   MEDCouplingStructuredMesh::copyTinyStringsFrom(other);
108   if((DataArrayDouble *)_coords && (const DataArrayDouble *)otherC->_coords)
109     _coords->copyStringInfoFrom(*otherC->_coords);
110 }
111
112 bool MEDCouplingCurveLinearMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const
113 {
114   if(!other)
115     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::isEqualIfNotWhy : input other pointer is null !");
116   const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
117   if(!otherC)
118     {
119       reason="mesh given in input is not castable in MEDCouplingCurveLinearMesh !";
120       return false;
121     }
122   if(!MEDCouplingStructuredMesh::isEqualIfNotWhy(other,prec,reason))
123     return false;
124   std::ostringstream oss; oss.precision(15);
125   if(((const DataArrayDouble *)_coords && ((const DataArrayDouble *)otherC->_coords)==0) || (((const DataArrayDouble *)_coords)==0 && (const DataArrayDouble *)otherC->_coords))
126     {
127       oss << "Only one CurveLinearMesh between the two this and other has its coordinates defined !";
128       reason=oss.str();
129       return false;
130     }
131   if((const DataArrayDouble *)_coords)
132     {
133       if(!_coords->isEqualIfNotWhy(*(otherC->_coords),prec,reason))
134         {
135           oss << "Coordinates DataArrayDouble of differ :";
136           reason.insert(0,oss.str());
137           return false;
138         }
139       if(_structure!=otherC->_structure)
140         { reason="CurveLinearMesh structures differ !"; return false; }
141     }
142   return true;
143 }
144
145 bool MEDCouplingCurveLinearMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
146 {
147   const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
148   if(!otherC)
149     return false;
150   if(((const DataArrayDouble *)_coords && ((const DataArrayDouble *)otherC->_coords)==0) || (((const DataArrayDouble *)_coords)==0 && (const DataArrayDouble *)otherC->_coords))
151     return false;
152   if((const DataArrayDouble *)_coords)
153     {
154       if(!_coords->isEqualWithoutConsideringStr(*(otherC->_coords),prec))
155         return false;
156       if(_structure!=otherC->_structure)
157         return false;
158     }
159   return true;
160 }
161
162 void MEDCouplingCurveLinearMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
163                                                       DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const
164 {
165   if(!isEqualWithoutConsideringStr(other,prec))
166     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalWith : Meshes are not the same !");
167 }
168
169 /*!
170  * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCurveLinearMesh instance too).
171  * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCurveLinearMesh, 'this' and 'other' are the same !
172  */
173 void MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
174                                                                  DataArrayInt *&cellCor) const
175 {
176   const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
177   if(!otherC)
178     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !");
179 }
180
181 void MEDCouplingCurveLinearMesh::checkCoherency() const
182 {
183   std::size_t sz=_structure.size(),i=0,nbOfNodes=1;
184   if(sz<1)
185     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : structure should have a lgth of size 1 at least !");
186   for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++,i++)
187     {
188       if((*it)<1)
189         { std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::checkCoherency : At pos #" << i << " of structure value is " << *it << "should be >= 1 !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
190       nbOfNodes*=*it;
191     }
192   if(!((const DataArrayDouble *)_coords))
193     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array is not set !");
194   if(!_coords->isAllocated())
195     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array is not allocated !");
196   if(_coords->getNumberOfComponents()<1)
197     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array should have >= 1 components !");
198   if(_coords->getNumberOfTuples()!=(int)nbOfNodes)
199     {
200       std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::checkCoherency : structure said that number of nodes should be equal to " << nbOfNodes << " but number of tuples in array is equal to " << _coords->getNumberOfTuples() << " !";
201       throw INTERP_KERNEL::Exception(oss.str().c_str());
202     }
203 }
204
205 void MEDCouplingCurveLinearMesh::checkCoherency1(double eps) const
206 {
207   checkCoherency();
208 }
209
210 void MEDCouplingCurveLinearMesh::checkCoherency2(double eps) const
211 {
212   checkCoherency1(eps);
213 }
214
215 int MEDCouplingCurveLinearMesh::getNumberOfCells() const
216 {
217   checkCoherency();
218   return MEDCouplingStructuredMesh::getNumberOfCells();
219 }
220
221 int MEDCouplingCurveLinearMesh::getNumberOfNodes() const
222 {
223   checkCoherency();
224   return MEDCouplingStructuredMesh::getNumberOfNodes();
225 }
226
227 void MEDCouplingCurveLinearMesh::getSplitCellValues(int *res) const
228 {
229   int meshDim=getMeshDimension();
230   for(int l=0;l<meshDim;l++)
231     {
232       int val=1;
233       for(int p=0;p<meshDim-l-1;p++)
234         val*=_structure[p]-1;
235       res[meshDim-l-1]=val;
236     }
237 }
238
239 void MEDCouplingCurveLinearMesh::getSplitNodeValues(int *res) const
240 {
241   int meshDim=getMeshDimension();
242   for(int l=0;l<meshDim;l++)
243     {
244       int val=1;
245       for(int p=0;p<meshDim-l-1;p++)
246         val*=_structure[p];
247       res[meshDim-l-1]=val;
248     }
249 }
250
251 void MEDCouplingCurveLinearMesh::getNodeGridStructure(int *res) const
252 {
253   std::copy(_structure.begin(),_structure.end(),res);
254 }
255
256 /*!
257  * MEDCouplingCurveLinearMesh has the property to define 2 space dimensions. One coming from its coordinates. The other coming from the node structure.
258  * Normally they should be equal ! This method returns the space dimension from coordinates. If the other one is requested call getSpaceDimensionOnNodeStruct.
259  *
260  * \sa MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct
261  */
262 int MEDCouplingCurveLinearMesh::getSpaceDimension() const
263 {
264   if(!((const DataArrayDouble *)_coords))
265     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getSpaceDimension : no array set ! impossible to deduce a space dimension !");
266   return _coords->getNumberOfComponents();
267 }
268
269 void MEDCouplingCurveLinearMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
270 {
271   if(!((const DataArrayDouble *)_coords))
272     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCoordinatesOfNode : Coordinates not set !");
273   int nbOfCompo=_coords->getNumberOfComponents();
274   if(nodeId>=0 && nodeId<_coords->getNumberOfTuples())
275     coo.insert(coo.end(),_coords->begin()+nodeId*nbOfCompo,_coords->begin()+(nodeId+1)*nbOfCompo);
276   else
277     { std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::getCoordinatesOfNode : nodeId has to be in [0," << _coords->getNumberOfTuples() << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
278 }
279
280 std::string MEDCouplingCurveLinearMesh::simpleRepr() const
281 {
282   std::ostringstream ret;
283   ret << "Curve linear mesh with name : \"" << getName() << "\"\n";
284   ret << "Description of mesh : \"" << getDescription() << "\"\n";
285   int tmpp1,tmpp2;
286   double tt=getTime(tmpp1,tmpp2);
287   ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
288   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
289   ret << "The nodal stucture of curve linear mesh is : [";
290   std::copy(_structure.begin(),_structure.end(),std::ostream_iterator<int>(ret,",")); ret << "]\n";
291   ret << "The coords array is this : ";
292   if((const DataArrayDouble *)_coords)
293     _coords->reprZipWithoutNameStream(ret);
294   else
295     ret << "no array specified !";
296   return ret.str();
297 }
298
299 std::string MEDCouplingCurveLinearMesh::advancedRepr() const
300 {
301   return simpleRepr();
302 }
303
304 DataArrayDouble *MEDCouplingCurveLinearMesh::getCoords()
305 {
306   return _coords;
307 }
308
309 const DataArrayDouble *MEDCouplingCurveLinearMesh::getCoords() const
310 {
311   return _coords;
312 }
313
314 void MEDCouplingCurveLinearMesh::setCoords(const DataArrayDouble *coords)
315 {
316   if(coords!=(const DataArrayDouble *)_coords)
317     {
318       _coords=const_cast<DataArrayDouble *>(coords);
319       if(coords)
320         coords->incrRef();
321       declareAsNew();
322     }
323 }
324
325 void MEDCouplingCurveLinearMesh::setNodeGridStructure(const int *gridStructBg, const int *gridStructEnd)
326 {
327   std::size_t sz=std::distance(gridStructBg,gridStructEnd);
328   if(sz>=1 && sz<=3)
329     {
330       _structure.resize(0);
331       _structure.insert(_structure.end(),gridStructBg,gridStructEnd);
332     }
333   else
334     {
335       std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::setNodeGridStructure : size of input nodal grid structure (" << sz << ") should be in 1, 2 or 3 !";
336       throw INTERP_KERNEL::Exception(oss.str().c_str());
337     }
338 }
339
340 std::vector<int> MEDCouplingCurveLinearMesh::getNodeGridStructure() const
341 {
342   return _structure;
343 }
344
345 MEDCouplingStructuredMesh *MEDCouplingCurveLinearMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const
346 {
347   checkCoherency();
348   int dim(getMeshDimension());
349   std::vector<int> dims(getMeshDimension());
350   if(dim!=(int)cellPart.size())
351     {
352       std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
353       throw INTERP_KERNEL::Exception(oss.str().c_str());
354     }
355   std::vector< std::pair<int,int> > nodePartFormat(cellPart);
356   for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
357     (*it).second++;
358   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
359   MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> ret(dynamic_cast<MEDCouplingCurveLinearMesh *>(deepCpy()));
360   const DataArrayDouble *coo(ret->getCoords());
361   if(coo)
362     {
363       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo2(coo->selectByTupleIdSafe(tmp1->begin(),tmp1->end()));
364       ret->setCoords(coo2);
365     }
366   for(int i=0;i<dim;i++)
367     {
368       dims[i]=cellPart[i].second-cellPart[i].first+1;
369       if(dims[i]<1)
370         throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::buildStructuredSubPart : invalid input cellPart !");
371     }
372   ret->setNodeGridStructure(&dims[0],&dims[0]+dims.size());
373   return ret.retn();
374 }
375
376 void MEDCouplingCurveLinearMesh::getBoundingBox(double *bbox) const
377 {
378   if(!((const DataArrayDouble *)_coords))
379     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBoundingBox : Coordinates not set !");
380   _coords->getMinMaxPerComponent(bbox);
381 }
382
383 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureField(bool isAbs) const
384 {
385   checkCoherency();
386   int meshDim=getMeshDimension();
387   std::string name="MeasureOfMesh_"; name+=getName();
388   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
389   field->setName(name); field->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(this)); field->synchronizeTimeWithMesh();
390   switch(meshDim)
391   {
392     case 3:
393       { getMeasureFieldMeshDim3(isAbs,field); return field.retn(); }
394     case 2:
395       { getMeasureFieldMeshDim2(isAbs,field); return field.retn(); }
396     case 1:
397       { getMeasureFieldMeshDim1(isAbs,field); return field.retn(); }
398     default:
399       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureField : mesh dimension must be in [1,2,3] !");
400   }
401 }
402
403 /*!
404  * \param [in,out] f field feeded with good values.
405  * \sa MEDCouplingCurveLinearMesh::getMeasureField
406  */
407 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim1(bool isAbs, MEDCouplingFieldDouble *field) const
408 {
409   int nbnodes=getNumberOfNodes();
410   int spaceDim=getSpaceDimension();
411   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
412   if(nbnodes==0)
413     { arr->alloc(0,1); return; }
414   if(spaceDim==1)
415     {
416       arr->alloc(nbnodes-1,1);
417       std::transform(_coords->begin()+1,_coords->end(),_coords->begin(),arr->getPointer(),std::minus<double>());
418       if(isAbs)
419         arr->abs();
420     }
421   else
422     {
423       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp=DataArrayDouble::New(); tmp->alloc(nbnodes-1,spaceDim);
424       std::transform(_coords->begin()+spaceDim,_coords->end(),_coords->begin(),tmp->getPointer(),std::minus<double>());
425       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=tmp->magnitude(); field->setArray(tmp2);
426     }
427 }
428
429 /*!
430  * \param [in,out] f field feeded with good values.
431  * \sa MEDCouplingCurveLinearMesh::getMeasureField
432  */
433 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim2(bool isAbs, MEDCouplingFieldDouble *field) const
434 {
435   int nbcells=getNumberOfCells();
436   int spaceDim=getSpaceDimension();
437   if(spaceDim!=2 && spaceDim!=3)
438     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim2 : with meshDim 2 only space dimension 2 and 3 are possible !");
439   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
440   arr->alloc(nbcells,1);
441   double *pt=arr->getPointer();
442   const double *coords=_coords->begin();
443   int nX=_structure[0]-1;
444   int conn[4];
445   for(int i=0;i<nbcells;i++,pt++)
446     {
447       int cy=i/nX,cx=i-cy*nX;
448       conn[0]=cy*(nX+1)+cx; conn[1]=(cy+1)*(nX+1)+cx; conn[2]=(cy+1)*(nX+1)+1+cx; conn[3]=cy*(nX+1)+cx+1;
449       *pt=INTERP_KERNEL::computeVolSurfOfCell2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_QUAD4,conn,4,coords,spaceDim);
450     }
451   if(isAbs)
452     arr->abs();
453 }
454
455 /*!
456  * \param [in,out] f field feeded with good values.
457  * \sa MEDCouplingCurveLinearMesh::getMeasureField
458  */
459 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim3(bool isAbs, MEDCouplingFieldDouble *field) const
460 {
461   int nbcells=getNumberOfCells();
462   int spaceDim=getSpaceDimension();
463   if(spaceDim!=3)
464     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim3 : with meshDim 3 only space dimension 3 is possible !");
465   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
466   arr->alloc(nbcells,1);
467   double *pt=arr->getPointer();
468   const double *coords=_coords->begin();
469   int nX=_structure[0]-1,nY=(_structure[0]-1)*(_structure[1]-1);
470   int nY1=_structure[0]*_structure[1];
471   int conn[8];
472   for(int i=0;i<nbcells;i++,pt++)
473     {
474       int cz=i/nY;
475       int cy=(i-cz*nY)/nX;
476       int cx=(i-cz*nY)-nX*cy;
477       conn[0]=cz*nY1+cy*(nX+1)+cx; conn[1]=cz*nY1+(cy+1)*(nX+1)+cx; conn[2]=cz*nY1+(cy+1)*(nX+1)+1+cx; conn[3]=cz*nY1+cy*(nX+1)+cx+1;
478       conn[4]=(cz+1)*nY1+cy*(nX+1)+cx; conn[5]=(cz+1)*nY1+(cy+1)*(nX+1)+cx; conn[6]=(cz+1)*nY1+(cy+1)*(nX+1)+1+cx; conn[7]=(cz+1)*nY1+cy*(nX+1)+cx+1;
479       *pt=INTERP_KERNEL::computeVolSurfOfCell2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_HEXA8,conn,8,coords,3);
480     }
481   if(isAbs)
482     arr->abs();
483 }
484
485 /*!
486  * not implemented yet !
487  */
488 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureFieldOnNode(bool isAbs) const
489 {
490   throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldOnNode : not implemented yet !");
491 }
492
493 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::buildOrthogonalField() const
494 {
495   if(getMeshDimension()!=2)
496     throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
497   MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
498   DataArrayDouble *array=DataArrayDouble::New();
499   int nbOfCells=getNumberOfCells();
500   array->alloc(nbOfCells,3);
501   double *vals=array->getPointer();
502   for(int i=0;i<nbOfCells;i++)
503     { vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
504   ret->setArray(array);
505   array->decrRef();
506   ret->setMesh(this);
507   return ret;
508 }
509
510 /// @cond INTERNAL
511
512 namespace ParaMEDMEM
513 {
514   template<const int SPACEDIMM>
515   class DummyClsMCL
516   {
517   public:
518     static const int MY_SPACEDIM=SPACEDIMM;
519     static const int MY_MESHDIM=8;
520     typedef int MyConnType;
521     static const INTERP_KERNEL::NumberingPolicy My_numPol=INTERP_KERNEL::ALL_C_MODE;
522     // begin
523     // useless, but for windows compilation ...
524     const double* getCoordinatesPtr() const { return 0; }
525     const int* getConnectivityPtr() const { return 0; }
526     const int* getConnectivityIndexPtr() const { return 0; }
527     INTERP_KERNEL::NormalizedCellType getTypeOfElement(int) const { return (INTERP_KERNEL::NormalizedCellType)0; }
528     // end
529   };
530 }
531
532 /// @endcond
533
534 int MEDCouplingCurveLinearMesh::getCellContainingPoint(const double *pos, double eps) const
535 {
536   checkCoherency();
537   int spaceDim=getSpaceDimension();
538   const double *coords=_coords->getConstPointer();
539   int nodeId=-1;
540   _coords->distanceToTuple(pos,pos+spaceDim,nodeId);
541   if(nodeId<0)
542     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : internal problem 1 !");
543   int conn[8];
544   int nbOfNodes=getNumberOfNodes();
545   if(nbOfNodes==1)
546     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : No cells in this !");
547   switch(getMeshDimension())
548   {
549     case 1:
550       if(spaceDim==1)
551         {
552           if(nodeId>0)
553             {
554               conn[0]=nodeId-1; conn[1]=nodeId;
555               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<1> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_SEG2,coords,conn,2,eps))
556                 return nodeId-1;
557             }
558           if(nodeId<nbOfNodes-1)
559             {
560               conn[0]=nodeId; conn[1]=nodeId+1;
561               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<1> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_SEG2,coords,conn,2,eps))
562                 return nodeId;
563             }
564         }
565     case 2:
566       if(spaceDim==2)
567         {
568           int ny=nodeId/_structure[0],nx=nodeId-ny*_structure[0];
569           if(nx>0 && ny>0)
570             {
571               conn[0]=nx-1+_structure[0]*(ny-1); conn[1]=nx-1+_structure[0]*ny; conn[2]=nx+_structure[0]*ny; conn[3]=nx+_structure[0]*(ny-1);
572               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
573                 return nx-1+(ny-1)*_structure[0];
574             }
575           if(nx<_structure[0]-1 && ny>0)
576             {
577               conn[0]=nx+_structure[0]*(ny-1); conn[1]=nx+_structure[0]*ny; conn[2]=nx+1+_structure[0]*ny; conn[3]=nx+1+_structure[0]*(ny-1);
578               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
579                 return nx+(ny-1)*_structure[0];
580             }
581           if(nx>0 && ny<_structure[1]-1)
582             {
583               conn[0]=nx-1+_structure[0]*ny; conn[1]=nx-1+_structure[0]*(ny+1); conn[2]=nx+_structure[0]*(ny+1); conn[3]=nx+_structure[0]*ny;
584               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
585                 return nx-1+ny*_structure[0];
586             }
587           if(nx<_structure[0]-1 && ny<_structure[1]-1)
588             {
589               conn[0]=nx+_structure[0]*ny; conn[1]=nx+_structure[0]*(ny+1); conn[2]=nx+1+_structure[0]*(ny+1); conn[3]=nx+1+_structure[0]*ny;
590               if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
591                 return nx+ny*_structure[0];
592             }
593         }
594     case 3:
595       {
596         if(spaceDim==3)
597           {
598             int nY=_structure[0]*_structure[1];
599             int nz=nodeId/_structure[1]; int ny=(nodeId-nz*nY)/_structure[0]; int nx=(nodeId-nz*nY)-_structure[0]*ny;
600             if(nx>0 && ny>0 && nz>0)
601               {
602                 conn[0]=nx-1+_structure[0]*(ny-1)+nY*(nz-1); conn[1]=nx-1+_structure[2]*ny+nY*(nz-1); conn[2]=nx+_structure[2]*ny+nY*(nz-1); conn[3]=nx+_structure[0]*(ny-1)+nY*(nz-1);
603                 conn[4]=nx-1+_structure[0]*(ny-1)+nY*nz; conn[5]=nx-1+_structure[0]*ny+nY*nz; conn[6]=nx+_structure[0]*ny+nY*nz; conn[7]=nx+_structure[0]*(ny-1)+nY*nz;
604                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
605                   return nx-1+(ny-1)*_structure[0]+(nz-1)*nY;
606               }
607             if(nx<_structure[0]-1 && ny>0 && nz>0)
608               {
609                 conn[0]=nx+_structure[0]*(ny-1)+nY*(nz-1); conn[1]=nx+_structure[0]*ny+nY*(nz-1); conn[2]=nx+1+_structure[0]*ny+nY*(nz-1); conn[3]=nx+1+_structure[0]*(ny-1)+nY*(nz-1);
610                 conn[4]=nx+_structure[0]*(ny-1)+nY*nz; conn[5]=nx+_structure[0]*ny+nY*nz; conn[6]=nx+1+_structure[0]*ny+nY*nz; conn[7]=nx+1+_structure[0]*(ny-1)+nY*nz;
611                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
612                   return nx+(ny-1)*_structure[0]+(nz-1)*nY;
613               }
614             if(nx>0 && ny<_structure[1]-1 && nz>0)
615               {
616                 conn[0]=nx-1+_structure[0]*ny+nY*(nz-1); conn[1]=nx-1+_structure[0]*(ny+1)+nY*(nz-1); conn[2]=nx+_structure[0]*(ny+1)+nY*(nz-1); conn[3]=nx+_structure[0]*ny+nY*(nz-1);
617                 conn[4]=nx-1+_structure[0]*ny+nY*nz; conn[5]=nx-1+_structure[0]*(ny+1)+nY*nz; conn[6]=nx+_structure[0]*(ny+1)+nY*nz; conn[7]=nx+_structure[0]*ny+nY*nz;
618                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
619                   return nx-1+ny*_structure[0]+(nz-1)*nY;
620               }
621             if(nx<_structure[0]-1 && ny<_structure[1]-1 && nz>0)
622               {
623                 conn[0]=nx+_structure[0]*ny+nY*(nz-1); conn[1]=nx+_structure[0]*(ny+1)+nY*(nz-1); conn[2]=nx+1+_structure[0]*(ny+1)+nY*(nz-1); conn[3]=nx+1+_structure[0]*ny+nY*(nz-1);
624                 conn[4]=nx+_structure[0]*ny+nY*nz; conn[5]=nx+_structure[0]*(ny+1)+nY*nz; conn[6]=nx+1+_structure[0]*(ny+1)+nY*nz; conn[7]=nx+1+_structure[0]*ny+nY*nz;
625                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
626                   return nx+ny*_structure[0]+(nz-1)*nY;
627               }
628             if(nx>0 && ny>0 && nz<_structure[2]-1)
629               {
630                 conn[0]=nx-1+_structure[0]*(ny-1)+nY*(nz-1); conn[1]=nx-1+_structure[2]*ny+nY*(nz-1); conn[2]=nx+_structure[2]*ny+nY*(nz-1); conn[3]=nx+_structure[0]*(ny-1)+nY*(nz-1);
631                 conn[4]=nx-1+_structure[0]*(ny-1)+nY*nz; conn[5]=nx-1+_structure[0]*ny+nY*nz; conn[6]=nx+_structure[0]*ny+nY*nz; conn[7]=nx+_structure[0]*(ny-1)+nY*nz;
632                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
633                   return nx-1+(ny-1)*_structure[0]+nz*nY;
634               }
635             if(nx<_structure[0]-1 && ny>0 && nz<_structure[2]-1)
636               {
637                 conn[0]=nx+_structure[0]*(ny-1)+nY*(nz-1); conn[1]=nx+_structure[0]*ny+nY*(nz-1); conn[2]=nx+1+_structure[0]*ny+nY*(nz-1); conn[3]=nx+1+_structure[0]*(ny-1)+nY*(nz-1);
638                 conn[4]=nx+_structure[0]*(ny-1)+nY*nz; conn[5]=nx+_structure[0]*ny+nY*nz; conn[6]=nx+1+_structure[0]*ny+nY*nz; conn[7]=nx+1+_structure[0]*(ny-1)+nY*nz;
639                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
640                   return nx+(ny-1)*_structure[0]+nz*nY;
641               }
642             if(nx>0 && ny<_structure[1]-1 && nz<_structure[2]-1)
643               {
644                 conn[0]=nx-1+_structure[0]*ny+nY*(nz-1); conn[1]=nx-1+_structure[0]*(ny+1)+nY*(nz-1); conn[2]=nx+_structure[0]*(ny+1)+nY*(nz-1); conn[3]=nx+_structure[0]*ny+nY*(nz-1);
645                 conn[4]=nx-1+_structure[0]*ny+nY*nz; conn[5]=nx-1+_structure[0]*(ny+1)+nY*nz; conn[6]=nx+_structure[0]*(ny+1)+nY*nz; conn[7]=nx+_structure[0]*ny+nY*nz;
646                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
647                   return nx-1+ny*_structure[0]+nz*nY;
648               }
649             if(nx<_structure[0]-1 && ny<_structure[1]-1 && nz<_structure[2]-1)
650               {
651                 conn[0]=nx+_structure[0]*ny+nY*(nz-1); conn[1]=nx+_structure[0]*(ny+1)+nY*(nz-1); conn[2]=nx+1+_structure[0]*(ny+1)+nY*(nz-1); conn[3]=nx+1+_structure[0]*ny+nY*(nz-1);
652                 conn[4]=nx+_structure[0]*ny+nY*nz; conn[5]=nx+_structure[0]*(ny+1)+nY*nz; conn[6]=nx+1+_structure[0]*(ny+1)+nY*nz; conn[7]=nx+1+_structure[0]*ny+nY*nz;
653                 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
654                   return nx+ny*_structure[0]+nz*nY;
655               }
656           }
657       }
658     default:
659       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : mesh dimension managed are 1, 2 or 3 !");
660   }
661 }
662
663 void MEDCouplingCurveLinearMesh::rotate(const double *center, const double *vector, double angle)
664 {
665   if(!((DataArrayDouble *)_coords))
666     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::rotate : no coordinates set !");
667   int spaceDim=getSpaceDimension();
668   int nbNodes=_coords->getNumberOfTuples();
669   double *coords=_coords->getPointer();
670   if(spaceDim==3)
671     MEDCouplingPointSet::Rotate3DAlg(center,vector,angle,nbNodes,coords);
672   else if(spaceDim==2)
673     MEDCouplingPointSet::Rotate2DAlg(center,angle,nbNodes,coords);
674   else
675     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::rotate : invalid space dim for rotation must be 2 or 3");
676   _coords->declareAsNew();
677   updateTime();
678 }
679
680 void MEDCouplingCurveLinearMesh::translate(const double *vector)
681 {
682   if(!vector)
683     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::translate : NULL input point !");
684   if(!((DataArrayDouble *)_coords))
685     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::translate : no coordinates set !");
686   double *coords=_coords->getPointer();
687   int nbNodes=getNumberOfNodes();
688   int dim=getSpaceDimension();
689   for(int i=0; i<nbNodes; i++)
690     for(int idim=0; idim<dim;idim++)
691       coords[i*dim+idim]+=vector[idim];
692   _coords->declareAsNew();
693   updateTime();
694 }
695
696 void MEDCouplingCurveLinearMesh::scale(const double *point, double factor)
697 {
698   if(!point)
699     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::scale : NULL input point !");
700   if(!((DataArrayDouble *)_coords))
701     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::scale : no coordinates set !");
702   double *coords=_coords->getPointer();
703   int nbNodes=_coords->getNumberOfTuples();
704   int dim=_coords->getNumberOfComponents();
705   for(int i=0;i<nbNodes;i++)
706     {
707       std::transform(coords+i*dim,coords+(i+1)*dim,point,coords+i*dim,std::minus<double>());
708       std::transform(coords+i*dim,coords+(i+1)*dim,coords+i*dim,std::bind2nd(std::multiplies<double>(),factor));
709       std::transform(coords+i*dim,coords+(i+1)*dim,point,coords+i*dim,std::plus<double>());
710     }
711   _coords->declareAsNew();
712   updateTime();
713 }
714
715 MEDCouplingMesh *MEDCouplingCurveLinearMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
716 {
717   throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::mergeMyselfWith : not available for CurveLinear Mesh !");
718 }
719
720 DataArrayDouble *MEDCouplingCurveLinearMesh::getCoordinatesAndOwner() const
721 {
722   DataArrayDouble *ret=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords);
723   if(ret)
724     ret->incrRef();
725   return ret;
726 }
727
728 DataArrayDouble *MEDCouplingCurveLinearMesh::getBarycenterAndOwner() const
729 {
730   checkCoherency();
731   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
732   int spaceDim=getSpaceDimension();
733   int meshDim=getMeshDimension();
734   int nbOfCells=getNumberOfCells();
735   ret->alloc(nbOfCells,spaceDim);
736   ret->copyStringInfoFrom(*getCoords());
737   switch(meshDim)
738   {
739     case 3:
740       { getBarycenterAndOwnerMeshDim3(ret); return ret.retn(); }
741     case 2:
742       { getBarycenterAndOwnerMeshDim2(ret); return ret.retn(); }
743     case 1:
744       { getBarycenterAndOwnerMeshDim1(ret); return ret.retn(); }
745     default:
746       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwner : mesh dimension must be in [1,2,3] !");
747   }
748 }
749
750 DataArrayDouble *MEDCouplingCurveLinearMesh::computeIsoBarycenterOfNodesPerCell() const
751 {
752   return MEDCouplingCurveLinearMesh::getBarycenterAndOwner();
753 }
754
755 /*!
756  * \param [in,out] bary Barycenter array feeded with good values.
757  * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
758  */
759 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim3(DataArrayDouble *bary) const
760 {
761   int nbOfCells=getNumberOfCells();
762   double *ptToFill=bary->getPointer();
763   const double *coor=_coords->getConstPointer();
764   if(getSpaceDimension()!=3)
765     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim3 : with meshDim 3 only space dimension 3 is possible !");
766   int nX=_structure[0]-1,nY=(_structure[0]-1)*(_structure[1]-1);
767   int nY1=_structure[0]*_structure[1];
768   int conn[8];
769   for(int i=0;i<nbOfCells;i++)
770     {
771       int cz=i/nY;
772       int cy=(i-cz*nY)/nX;
773       int cx=(i-cz*nY)-nX*cy;
774       conn[0]=cz*nY1+cy*(nX+1)+cx+1; conn[1]=cz*nY1+cy*(nX+1)+cx; conn[2]=cz*nY1+(cy+1)*(nX+1)+cx; conn[3]=cz*nY1+(cy+1)*(nX+1)+1+cx;
775       conn[4]=(cz+1)*nY1+cy*(nX+1)+cx+1; conn[5]=(cz+1)*nY1+cy*(nX+1)+cx; conn[6]=(cz+1)*nY1+(cy+1)*(nX+1)+cx; conn[7]=(cz+1)*nY1+(cy+1)*(nX+1)+1+cx;
776       INTERP_KERNEL::computeBarycenter2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_HEXA8,conn,8,coor,3,ptToFill);
777       ptToFill+=3;
778     }
779 }
780
781 /*!
782  * \param [in,out] bary Barycenter array feeded with good values.
783  * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
784  */
785 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim2(DataArrayDouble *bary) const
786 {
787   int nbcells=getNumberOfCells();
788   int spaceDim=getSpaceDimension();
789   double *ptToFill=bary->getPointer();
790   const double *coor=_coords->getConstPointer();
791   if(spaceDim!=2 && spaceDim!=3)
792     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim2 : with meshDim 2 only space dimension 2 and 3 are possible !");
793   int nX=_structure[0]-1;
794   int conn[4];
795   for(int i=0;i<nbcells;i++)
796     {
797       int cy=i/nX,cx=i-cy*nX;
798       conn[0]=cy*(nX+1)+cx; conn[1]=(cy+1)*(nX+1)+cx; conn[2]=(cy+1)*(nX+1)+1+cx; conn[3]=cy*(nX+1)+cx+1;
799       INTERP_KERNEL::computeBarycenter2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_QUAD4,conn,4,coor,spaceDim,ptToFill);
800       ptToFill+=spaceDim;
801     }
802 }
803
804 /*!
805  * \param [in,out] bary Barycenter array feeded with good values.
806  * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
807  */
808 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim1(DataArrayDouble *bary) const
809 {
810   int spaceDim=getSpaceDimension();
811   std::transform(_coords->begin()+spaceDim,_coords->end(),_coords->begin(),bary->getPointer(),std::plus<double>());
812   std::transform(bary->begin(),bary->end(),bary->getPointer(),std::bind2nd(std::multiplies<double>(),0.5));
813 }
814
815 void MEDCouplingCurveLinearMesh::renumberCells(const int *old2NewBg, bool check)
816 {
817   throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for CurveLinear Mesh !");
818 }
819
820 void MEDCouplingCurveLinearMesh::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
821 {
822   int it,order;
823   double time=getTime(it,order);
824   tinyInfo.clear();
825   tinyInfoD.clear();
826   littleStrings.clear();
827   littleStrings.push_back(getName());
828   littleStrings.push_back(getDescription());
829   littleStrings.push_back(getTimeUnit());
830   //
831   std::vector<std::string> littleStrings2;
832   if((const DataArrayDouble *)_coords)
833     _coords->getTinySerializationStrInformation(littleStrings2);
834   littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end());
835   //
836   tinyInfo.push_back(it);
837   tinyInfo.push_back(order);
838   tinyInfo.push_back((int)_structure.size());
839   for(std::vector<int>::const_iterator itt=_structure.begin();itt!=_structure.end();itt++)
840     tinyInfo.push_back(*itt);
841   std::vector<int> tinyInfo2;
842   if((const DataArrayDouble *)_coords)
843     _coords->getTinySerializationIntInformation(tinyInfo2);
844   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
845   //
846   tinyInfoD.push_back(time);
847 }
848
849 void MEDCouplingCurveLinearMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
850 {
851   a1->alloc(tinyInfo[2],1);
852   std::vector<int> tinyInfo2(tinyInfo.begin()+3+tinyInfo[2],tinyInfo.end());
853   a2->resizeForUnserialization(tinyInfo2);
854 }
855
856 void MEDCouplingCurveLinearMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
857 {
858   a1=DataArrayInt::New();
859   a1->alloc((int)_structure.size(),1);
860   int *ptr=a1->getPointer();
861   for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++,ptr++)
862     *ptr=(*it);
863   int sz=0;
864   if((const DataArrayDouble *)_coords)
865     if(_coords->isAllocated())
866       sz=_coords->getNbOfElems();
867   a2=DataArrayDouble::New();
868   a2->alloc(sz,1);
869   if(sz!=0 && (const DataArrayDouble *)_coords)
870     std::copy(_coords->begin(),_coords->end(),a2->getPointer());
871 }
872
873 void MEDCouplingCurveLinearMesh::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
874                                                  const std::vector<std::string>& littleStrings)
875 {
876   setName(littleStrings[0]);
877   setDescription(littleStrings[1]);
878   setTimeUnit(littleStrings[2]);
879   setTime(tinyInfoD[0],tinyInfo[0],tinyInfo[1]);
880   int sz=tinyInfo[2];
881   _structure.resize(sz);
882   for(int i=0;i<sz;i++)
883     _structure[i]=tinyInfo[3+i];
884   if((int)tinyInfo.size()>sz+3)
885     {
886       _coords=DataArrayDouble::New();
887       std::vector<int> tinyInfo2(tinyInfo.begin()+3+sz,tinyInfo.end());
888       _coords->resizeForUnserialization(tinyInfo2);
889       std::copy(a2->begin(),a2->end(),_coords->getPointer());
890       std::vector<std::string> littleStrings2(littleStrings.begin()+3,littleStrings.end());
891       _coords->finishUnserialization(tinyInfo2,littleStrings2);
892     }
893 }
894
895 void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const
896 {
897   std::ostringstream extent;
898   int meshDim=(int)_structure.size();
899   if(meshDim<=0 || meshDim>3)
900     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::writeVTKLL : meshDim invalid ! must be in [1,2,3] !");
901   for(int i=0;i<3;i++)
902     { int val=i<meshDim?_structure[i]-1:0; extent << "0 " <<  val << " "; }
903   ofs << "  <" << getVTKDataSetType() << " WholeExtent=\"" << extent.str() << "\">\n";
904   ofs << "    <Piece Extent=\"" << extent.str() << "\">\n";
905   ofs << "      <PointData>\n" << pointData << std::endl;
906   ofs << "      </PointData>\n";
907   ofs << "      <CellData>\n" << cellData << std::endl;
908   ofs << "      </CellData>\n";
909   ofs << "      <Points>\n";
910   if(getSpaceDimension()==3)
911     _coords->writeVTK(ofs,8,"Points",byteData);
912   else
913     {
914       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->changeNbOfComponents(3,0.);
915       coo->writeVTK(ofs,8,"Points",byteData);
916     }
917   ofs << "      </Points>\n";
918   ofs << "    </Piece>\n";
919   ofs << "  </" << getVTKDataSetType() << ">\n";
920 }
921
922 void MEDCouplingCurveLinearMesh::reprQuickOverview(std::ostream& stream) const
923 {
924   stream << "MEDCouplingCurveLinearMesh C++ instance at " << this << ". Name : \"" << getName() << "\".";
925   stream << " Nodal structure : [";
926   for(std::size_t i=0;i<_structure.size();i++)
927     {
928       char tmp='X'+i;
929       stream << " " << tmp << "=" << _structure[i];
930       if(i!=_structure.size()-1)
931         stream << ", ";
932     }
933   stream << " ].";
934   const DataArrayDouble *coo(_coords);
935   if(!coo)
936     { stream << std::endl << "No coordinates set !"; return ; }
937   if(!coo->isAllocated())
938     { stream << std::endl << "Coordinates set but not allocated !"; return ; }
939   int nbOfCompo=coo->getNumberOfComponents();
940   if(nbOfCompo!=(int)_structure.size())
941     { stream << std::endl << "Coordinates set and allocated but mismatch number of components !"; return ; }
942   stream << std::endl << "Coordinates ( number of tuples = " << coo->getNumberOfTuples() << " ) : ";
943   coo->reprQuickOverviewData(stream,200);
944 }
945
946 std::string MEDCouplingCurveLinearMesh::getVTKDataSetType() const
947 {
948   return std::string("StructuredGrid");
949 }