Salome HOME
remove src/MEDCalc/doc
[modules/med.git] / src / MEDCoupling / MEDCouplingExtrudedMesh.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingExtrudedMesh.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
26 #include "CellModel.hxx"
27
28 #include "InterpolationUtils.hxx"
29
30 #include <limits>
31 #include <algorithm>
32 #include <functional>
33 #include <iterator>
34 #include <sstream>
35 #include <cmath>
36 #include <list>
37 #include <set>
38
39 using namespace ParaMEDMEM;
40
41 /*!
42  * Build an extruded mesh instance from 3D and 2D unstructured mesh lying on the \b same \b coords.
43  * @param mesh3D 3D unstructured mesh.
44  * @param mesh2D 2D unstructured mesh lying on the same coordinates than mesh3D. \b Warning mesh2D is \b not \b const
45  * because the mesh is aggregated and potentially modified by rotate or translate method.
46  * @param cell2DId Id of cell in mesh2D mesh where the computation of 1D mesh will be done.
47  */
48 MEDCouplingExtrudedMesh *MEDCouplingExtrudedMesh::New(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId)
49 {
50   return new MEDCouplingExtrudedMesh(mesh3D,mesh2D,cell2DId);
51 }
52
53 /*!
54  * This constructor is here only for unserialisation process.
55  * This constructor is normally completely useless for end user.
56  */
57 MEDCouplingExtrudedMesh *MEDCouplingExtrudedMesh::New()
58 {
59   return new MEDCouplingExtrudedMesh;
60 }
61
62 MEDCouplingMeshType MEDCouplingExtrudedMesh::getType() const
63 {
64   return EXTRUDED;
65 }
66
67 std::size_t MEDCouplingExtrudedMesh::getHeapMemorySizeWithoutChildren() const
68 {
69   return MEDCouplingMesh::getHeapMemorySizeWithoutChildren();
70 }
71
72 std::vector<const BigMemoryObject *> MEDCouplingExtrudedMesh::getDirectChildrenWithNull() const
73 {
74   std::vector<const BigMemoryObject *> ret;
75   ret.push_back(_mesh2D);
76   ret.push_back(_mesh1D);
77   ret.push_back(_mesh3D_ids);
78   return ret;
79 }
80
81 /*!
82  * This method copyies all tiny strings from other (name and components name).
83  * @throw if other and this have not same mesh type.
84  */
85 void MEDCouplingExtrudedMesh::copyTinyStringsFrom(const MEDCouplingMesh *other)
86 {
87   const MEDCouplingExtrudedMesh *otherC=dynamic_cast<const MEDCouplingExtrudedMesh *>(other);
88   if(!otherC)
89     throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::copyTinyStringsFrom : meshes have not same type !");
90   MEDCouplingMesh::copyTinyStringsFrom(other);
91   _mesh2D->copyTinyStringsFrom(otherC->_mesh2D);
92   _mesh1D->copyTinyStringsFrom(otherC->_mesh1D);
93 }
94
95 MEDCouplingExtrudedMesh::MEDCouplingExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId)
96 try:_mesh2D(const_cast<MEDCouplingUMesh *>(mesh2D)),_mesh1D(MEDCouplingUMesh::New()),_mesh3D_ids(0),_cell_2D_id(cell2DId)
97 {
98   if(_mesh2D!=0)
99     _mesh2D->incrRef();
100   computeExtrusion(mesh3D);
101   setName(mesh3D->getName());
102 }
103 catch(INTERP_KERNEL::Exception& e)
104 {
105     if(_mesh2D)
106       _mesh2D->decrRef();
107     if(_mesh1D)
108       _mesh1D->decrRef();
109     if(_mesh3D_ids)
110       _mesh3D_ids->decrRef();
111     throw e;
112 }
113
114 MEDCouplingExtrudedMesh::MEDCouplingExtrudedMesh():_mesh2D(0),_mesh1D(0),_mesh3D_ids(0),_cell_2D_id(-1)
115 {
116 }
117
118 MEDCouplingExtrudedMesh::MEDCouplingExtrudedMesh(const MEDCouplingExtrudedMesh& other, bool deepCopy):MEDCouplingMesh(other),_cell_2D_id(other._cell_2D_id)
119 {
120   if(deepCopy)
121     {
122       _mesh2D=other._mesh2D->clone(true);
123       _mesh1D=other._mesh1D->clone(true);
124       _mesh3D_ids=other._mesh3D_ids->deepCpy();
125     }
126   else
127     {
128       _mesh2D=other._mesh2D;
129       if(_mesh2D)
130         _mesh2D->incrRef();
131       _mesh1D=other._mesh1D;
132       if(_mesh1D)
133         _mesh1D->incrRef();
134       _mesh3D_ids=other._mesh3D_ids;
135       if(_mesh3D_ids)
136         _mesh3D_ids->incrRef();
137     }
138 }
139
140 int MEDCouplingExtrudedMesh::getNumberOfCells() const
141 {
142   return _mesh2D->getNumberOfCells()*_mesh1D->getNumberOfCells();
143 }
144
145 int MEDCouplingExtrudedMesh::getNumberOfNodes() const
146 {
147   return _mesh2D->getNumberOfNodes();
148 }
149
150 int MEDCouplingExtrudedMesh::getSpaceDimension() const
151 {
152   return 3;
153 }
154
155 int MEDCouplingExtrudedMesh::getMeshDimension() const
156 {
157   return 3;
158 }
159
160 MEDCouplingMesh *MEDCouplingExtrudedMesh::deepCpy() const
161 {
162   return clone(true);
163 }
164
165 MEDCouplingExtrudedMesh *MEDCouplingExtrudedMesh::clone(bool recDeepCpy) const
166 {
167   return new MEDCouplingExtrudedMesh(*this,recDeepCpy);
168 }
169
170 bool MEDCouplingExtrudedMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const
171 {
172   if(!other)
173     throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::isEqualIfNotWhy : input other pointer is null !");
174   const MEDCouplingExtrudedMesh *otherC=dynamic_cast<const MEDCouplingExtrudedMesh *>(other);
175   std::ostringstream oss;
176   if(!otherC)
177     {
178       reason="mesh given in input is not castable in MEDCouplingExtrudedMesh !";
179       return false;
180     }
181   if(!MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason))
182     return false;
183   if(!_mesh2D->isEqualIfNotWhy(otherC->_mesh2D,prec,reason))
184     {
185       reason.insert(0,"Mesh2D unstructured meshes differ : ");
186       return false;
187     }
188   if(!_mesh1D->isEqualIfNotWhy(otherC->_mesh1D,prec,reason))
189     {
190       reason.insert(0,"Mesh1D unstructured meshes differ : ");
191       return false;
192     }
193   if(!_mesh3D_ids->isEqualIfNotWhy(*otherC->_mesh3D_ids,reason))
194     {
195       reason.insert(0,"Mesh3D ids DataArrayInt instances differ : ");
196       return false;
197     }
198   if(_cell_2D_id!=otherC->_cell_2D_id)
199     {
200       oss << "Cell 2D id of the two extruded mesh differ : this = " << _cell_2D_id << " other = " <<  otherC->_cell_2D_id;
201       reason=oss.str();
202       return false;
203     }
204   return true;
205 }
206
207 bool MEDCouplingExtrudedMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
208 {
209   const MEDCouplingExtrudedMesh *otherC=dynamic_cast<const MEDCouplingExtrudedMesh *>(other);
210   if(!otherC)
211     return false;
212   if(!_mesh2D->isEqualWithoutConsideringStr(otherC->_mesh2D,prec))
213     return false;
214   if(!_mesh1D->isEqualWithoutConsideringStr(otherC->_mesh1D,prec))
215     return false;
216   if(!_mesh3D_ids->isEqualWithoutConsideringStr(*otherC->_mesh3D_ids))
217     return false;
218   if(_cell_2D_id!=otherC->_cell_2D_id)
219     return false;
220   return true;
221 }
222
223 void MEDCouplingExtrudedMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
224                                                    DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const
225 {
226   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::checkDeepEquivalWith : not implemented yet !");
227 }
228
229 void MEDCouplingExtrudedMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
230                                                               DataArrayInt *&cellCor) const
231 {
232   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::checkDeepEquivalOnSameNodesWith : not implemented yet !");
233 }
234
235 INTERP_KERNEL::NormalizedCellType MEDCouplingExtrudedMesh::getTypeOfCell(int cellId) const
236 {
237   const int *ids=_mesh3D_ids->getConstPointer();
238   int nbOf3DCells=_mesh3D_ids->getNumberOfTuples();
239   const int *where=std::find(ids,ids+nbOf3DCells,cellId);
240   if(where==ids+nbOf3DCells)
241     throw INTERP_KERNEL::Exception("Invalid cellId specified >= getNumberOfCells() !");
242   int nbOfCells2D=_mesh2D->getNumberOfCells();
243   int locId=((int)std::distance(ids,where))%nbOfCells2D;
244   INTERP_KERNEL::NormalizedCellType tmp=_mesh2D->getTypeOfCell(locId);
245   return INTERP_KERNEL::CellModel::GetCellModel(tmp).getExtrudedType();
246 }
247
248 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingExtrudedMesh::getAllGeoTypes() const
249 {
250   std::set<INTERP_KERNEL::NormalizedCellType> ret2D(_mesh2D->getAllGeoTypes());
251   std::set<INTERP_KERNEL::NormalizedCellType> ret;
252   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=ret2D.begin();it!=ret2D.end();it++)
253     ret.insert(INTERP_KERNEL::CellModel::GetCellModel(*it).getExtrudedType());
254   return ret;
255 }
256
257 DataArrayInt *MEDCouplingExtrudedMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
258 {
259   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
260   INTERP_KERNEL::NormalizedCellType revExtTyp=cm.getReverseExtrudedType();
261   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
262   if(revExtTyp==INTERP_KERNEL::NORM_ERROR)
263     {
264       ret->alloc(0,1);
265       return ret.retn();
266     }
267   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=_mesh2D->giveCellsWithType(revExtTyp);
268   int nbOfLevs=_mesh1D->getNumberOfCells();
269   int nbOfCells2D=_mesh2D->getNumberOfCells();
270   int nbOfTuples=tmp->getNumberOfTuples();
271   ret->alloc(nbOfLevs*nbOfTuples,1);
272   int *pt=ret->getPointer();
273   for(int i=0;i<nbOfLevs;i++,pt+=nbOfTuples)
274     std::transform(tmp->begin(),tmp->end(),pt,std::bind2nd(std::plus<int>(),i*nbOfCells2D));
275   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=ret->renumberR(_mesh3D_ids->begin());
276   ret2->sort();
277   return ret2.retn();
278 }
279
280 DataArrayInt *MEDCouplingExtrudedMesh::computeNbOfNodesPerCell() const
281 {
282   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2D=_mesh2D->computeNbOfNodesPerCell();
283   int nbOfLevs=_mesh1D->getNumberOfCells();
284   int nbOfCells2D=_mesh2D->getNumberOfCells();
285   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3D=DataArrayInt::New(); ret3D->alloc(nbOfLevs*nbOfCells2D,1);
286   int *pt=ret3D->getPointer();
287   for(int i=0;i<nbOfLevs;i++,pt+=nbOfCells2D)
288     std::copy(ret2D->begin(),ret2D->end(),pt);
289   ret3D->applyLin(2,0,0);
290   return ret3D->renumberR(_mesh3D_ids->begin());
291 }
292
293 DataArrayInt *MEDCouplingExtrudedMesh::computeNbOfFacesPerCell() const
294 {
295   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2D=_mesh2D->computeNbOfNodesPerCell();
296   int nbOfLevs=_mesh1D->getNumberOfCells();
297   int nbOfCells2D=_mesh2D->getNumberOfCells();
298   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3D=DataArrayInt::New(); ret3D->alloc(nbOfLevs*nbOfCells2D,1);
299   int *pt=ret3D->getPointer();
300   for(int i=0;i<nbOfLevs;i++,pt+=nbOfCells2D)
301     std::copy(ret2D->begin(),ret2D->end(),pt);
302   ret3D->applyLin(2,2,0);
303   return ret3D->renumberR(_mesh3D_ids->begin());
304 }
305
306 DataArrayInt *MEDCouplingExtrudedMesh::computeEffectiveNbOfNodesPerCell() const
307 {
308   return computeNbOfNodesPerCell();
309 }
310
311 int MEDCouplingExtrudedMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
312 {
313   int ret=0;
314   int nbOfCells2D=_mesh2D->getNumberOfCells();
315   for(int i=0;i<nbOfCells2D;i++)
316     {
317       INTERP_KERNEL::NormalizedCellType t=_mesh2D->getTypeOfCell(i);
318       if(INTERP_KERNEL::CellModel::GetCellModel(t).getExtrudedType()==type)
319         ret++;
320     }
321   return ret*_mesh1D->getNumberOfCells();
322 }
323
324 void MEDCouplingExtrudedMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
325 {
326   int nbOfCells2D=_mesh2D->getNumberOfCells();
327   int nbOfNodes2D=_mesh2D->getNumberOfNodes();
328   int locId=cellId%nbOfCells2D;
329   int lev=cellId/nbOfCells2D;
330   std::vector<int> tmp,tmp2;
331   _mesh2D->getNodeIdsOfCell(locId,tmp);
332   tmp2=tmp;
333   std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::plus<int>(),nbOfNodes2D*lev));
334   std::transform(tmp2.begin(),tmp2.end(),tmp2.begin(),std::bind2nd(std::plus<int>(),nbOfNodes2D*(lev+1)));
335   conn.insert(conn.end(),tmp.begin(),tmp.end());
336   conn.insert(conn.end(),tmp2.begin(),tmp2.end());
337 }
338
339 void MEDCouplingExtrudedMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
340 {
341   int nbOfNodes2D=_mesh2D->getNumberOfNodes();
342   int locId=nodeId%nbOfNodes2D;
343   int lev=nodeId/nbOfNodes2D;
344   std::vector<double> tmp,tmp2;
345   _mesh2D->getCoordinatesOfNode(locId,tmp);
346   tmp2=tmp;
347   int spaceDim=_mesh1D->getSpaceDimension();
348   const double *z=_mesh1D->getCoords()->getConstPointer();
349   std::transform(tmp.begin(),tmp.end(),z+lev*spaceDim,tmp.begin(),std::plus<double>());
350   std::transform(tmp2.begin(),tmp2.end(),z+(lev+1)*spaceDim,tmp2.begin(),std::plus<double>());
351   coo.insert(coo.end(),tmp.begin(),tmp.end());
352   coo.insert(coo.end(),tmp2.begin(),tmp2.end());
353 }
354
355 std::string MEDCouplingExtrudedMesh::simpleRepr() const
356 {
357   std::ostringstream ret;
358   ret << "3D Extruded mesh from a 2D Surf Mesh with name : \"" << getName() << "\"\n";
359   ret << "Description of mesh : \"" << getDescription() << "\"\n";
360   int tmpp1,tmpp2;
361   double tt=getTime(tmpp1,tmpp2);
362   ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
363   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
364   ret << "Cell id where 1D mesh has been deduced : " << _cell_2D_id << "\n";
365   ret << "Number of cells : " << getNumberOfCells() << "(" << _mesh2D->getNumberOfCells() << "x" << _mesh1D->getNumberOfCells() << ")\n";
366   ret << "1D Mesh info : _____________________\n\n\n";
367   ret << _mesh1D->simpleRepr();
368   ret << "\n\n\n2D Mesh info : _____________________\n\n\n" << _mesh2D->simpleRepr() << "\n\n\n";
369   return ret.str();
370 }
371
372 std::string MEDCouplingExtrudedMesh::advancedRepr() const
373 {
374   std::ostringstream ret;
375   ret << "3D Extruded mesh from a 2D Surf Mesh with name : \"" << getName() << "\"\n";
376   ret << "Description of mesh : \"" << getDescription() << "\"\n";
377   int tmpp1,tmpp2;
378   double tt=getTime(tmpp1,tmpp2);
379   ret << "Time attached to the mesh (unit) : " << tt << " (" << getTimeUnit() << ")\n";
380   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
381   ret << "Cell id where 1D mesh has been deduced : " << _cell_2D_id << "\n";
382   ret << "Number of cells : " << getNumberOfCells() << "(" << _mesh2D->getNumberOfCells() << "x" << _mesh1D->getNumberOfCells() << ")\n";
383   ret << "1D Mesh info : _____________________\n\n\n";
384   ret << _mesh1D->advancedRepr();
385   ret << "\n\n\n2D Mesh info : _____________________\n\n\n" << _mesh2D->advancedRepr() << "\n\n\n";
386   ret << "3D cell ids per level :\n";
387   return ret.str();
388 }
389
390 void MEDCouplingExtrudedMesh::checkCoherency() const
391 {
392 }
393
394 void MEDCouplingExtrudedMesh::checkCoherency1(double eps) const
395 {
396   checkCoherency();
397 }
398
399 void MEDCouplingExtrudedMesh::checkCoherency2(double eps) const
400 {
401   checkCoherency1(eps);
402 }
403
404 void MEDCouplingExtrudedMesh::getBoundingBox(double *bbox) const
405 {
406   double bbox2D[6];
407   _mesh2D->getBoundingBox(bbox2D);
408   const double *nodes1D=_mesh1D->getCoords()->getConstPointer();
409   int nbOfNodes1D=_mesh1D->getNumberOfNodes();
410   double bbox1DMin[3],bbox1DMax[3],tmp[3];
411   std::fill(bbox1DMin,bbox1DMin+3,std::numeric_limits<double>::max());
412   std::fill(bbox1DMax,bbox1DMax+3,-(std::numeric_limits<double>::max()));
413   for(int i=0;i<nbOfNodes1D;i++)
414     {
415       std::transform(nodes1D+3*i,nodes1D+3*(i+1),bbox1DMin,bbox1DMin,static_cast<const double& (*)(const double&, const double&)>(std::min<double>));
416       std::transform(nodes1D+3*i,nodes1D+3*(i+1),bbox1DMax,bbox1DMax,static_cast<const double& (*)(const double&, const double&)>(std::max<double>));
417     }
418   std::transform(bbox1DMax,bbox1DMax+3,bbox1DMin,tmp,std::minus<double>());
419   int id=(int)std::distance(tmp,std::max_element(tmp,tmp+3));
420   bbox[0]=bbox1DMin[0]; bbox[1]=bbox1DMax[0];
421   bbox[2]=bbox1DMin[1]; bbox[3]=bbox1DMax[1];
422   bbox[4]=bbox1DMin[2]; bbox[5]=bbox1DMax[2];
423   bbox[2*id+1]+=tmp[id];
424 }
425
426 void MEDCouplingExtrudedMesh::updateTime() const
427 {
428   if(_mesh2D)
429     {
430       updateTimeWith(*_mesh2D);
431     }
432   if(_mesh1D)
433     {
434       updateTimeWith(*_mesh1D);
435     }
436 }
437
438 void MEDCouplingExtrudedMesh::renumberCells(const int *old2NewBg, bool check)
439 {
440   throw INTERP_KERNEL::Exception("Functionnality of renumbering cells unavailable for ExtrudedMesh");
441 }
442
443 MEDCouplingUMesh *MEDCouplingExtrudedMesh::build3DUnstructuredMesh() const
444 {
445   MEDCouplingUMesh *ret=_mesh2D->buildExtrudedMesh(_mesh1D,0);
446   const int *renum=_mesh3D_ids->getConstPointer();
447   ret->renumberCells(renum,false);
448   ret->setName(getName());
449   return ret;
450 }
451
452 MEDCouplingUMesh *MEDCouplingExtrudedMesh::buildUnstructured() const
453 {
454   return build3DUnstructuredMesh();
455 }
456
457 MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::getMeasureField(bool) const
458 {
459   std::string name="MeasureOfMesh_";
460   name+=getName();
461   MEDCouplingFieldDouble *ret2D=_mesh2D->getMeasureField(true);
462   MEDCouplingFieldDouble *ret1D=_mesh1D->getMeasureField(true);
463   const double *ret2DPtr=ret2D->getArray()->getConstPointer();
464   const double *ret1DPtr=ret1D->getArray()->getConstPointer();
465   int nbOf2DCells=_mesh2D->getNumberOfCells();
466   int nbOf1DCells=_mesh1D->getNumberOfCells();
467   int nbOf3DCells=nbOf2DCells*nbOf1DCells;
468   const int *renum=_mesh3D_ids->getConstPointer();
469   MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
470   ret->setMesh(this);
471   ret->synchronizeTimeWithMesh();
472   DataArrayDouble *da=DataArrayDouble::New();
473   da->alloc(nbOf3DCells,1);
474   double *retPtr=da->getPointer();
475   for(int i=0;i<nbOf1DCells;i++)
476     for(int j=0;j<nbOf2DCells;j++)
477       retPtr[renum[i*nbOf2DCells+j]]=ret2DPtr[j]*ret1DPtr[i];
478   ret->setArray(da);
479   da->decrRef();
480   ret->setName(name);
481   ret2D->decrRef();
482   ret1D->decrRef();
483   return ret;
484 }
485
486 MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::getMeasureFieldOnNode(bool isAbs) const
487 {
488   //not implemented yet
489   return 0;
490 }
491
492 MEDCouplingFieldDouble *MEDCouplingExtrudedMesh::buildOrthogonalField() const
493 {
494   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::buildOrthogonalField : This method has no sense for MEDCouplingExtrudedMesh that is 3D !");
495 }
496
497 int MEDCouplingExtrudedMesh::getCellContainingPoint(const double *pos, double eps) const
498 {
499   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::getCellContainingPoint : not implemented yet !");
500 }
501
502 MEDCouplingExtrudedMesh::~MEDCouplingExtrudedMesh()
503 {
504   if(_mesh2D)
505     _mesh2D->decrRef();
506   if(_mesh1D)
507     _mesh1D->decrRef();
508   if(_mesh3D_ids)
509     _mesh3D_ids->decrRef();
510 }
511
512 void MEDCouplingExtrudedMesh::computeExtrusion(const MEDCouplingUMesh *mesh3D)
513 {
514   const char errMsg1[]="2D mesh is empty unable to compute extrusion !";
515   const char errMsg2[]="Coords between 2D and 3D meshes are not the same ! Try MEDCouplingPointSet::tryToShareSameCoords method";
516   const char errMsg3[]="No chance to find extrusion pattern in mesh3D,mesh2D couple because nbCells3D%nbCells2D!=0 !";
517   if(_mesh2D==0 || mesh3D==0)
518     throw INTERP_KERNEL::Exception(errMsg1);
519   if(_mesh2D->getCoords()!=mesh3D->getCoords())
520     throw INTERP_KERNEL::Exception(errMsg2);
521   if(mesh3D->getNumberOfCells()%_mesh2D->getNumberOfCells()!=0)
522     throw INTERP_KERNEL::Exception(errMsg3);
523   if(!_mesh3D_ids)
524     _mesh3D_ids=DataArrayInt::New();
525   if(!_mesh1D)
526     _mesh1D=MEDCouplingUMesh::New();
527   computeExtrusionAlg(mesh3D);
528 }
529
530 void MEDCouplingExtrudedMesh::build1DExtrusion(int idIn3DDesc, int newId, int nbOf1DLev, MEDCouplingUMesh *subMesh,
531                                                const int *desc3D, const int *descIndx3D,
532                                                const int *revDesc3D, const int *revDescIndx3D,
533                                                bool computeMesh1D)
534 {
535   int nbOf2DCells=_mesh2D->getNumberOfCells();
536   int start=revDescIndx3D[idIn3DDesc];
537   int end=revDescIndx3D[idIn3DDesc+1];
538   if(end-start!=1)
539     {
540       std::ostringstream ost; ost << "Invalid bases 2D mesh specified : 2D cell # " <<  idIn3DDesc;
541       ost << " shared by more than 1 3D cell !!!";
542       throw INTERP_KERNEL::Exception(ost.str().c_str());
543     }
544   int current3DCell=revDesc3D[start];
545   int current2DCell=idIn3DDesc;
546   int *mesh3DIDs=_mesh3D_ids->getPointer();
547   mesh3DIDs[newId]=current3DCell;
548   const int *conn2D=subMesh->getNodalConnectivity()->getConstPointer();
549   const int *conn2DIndx=subMesh->getNodalConnectivityIndex()->getConstPointer();
550   for(int i=1;i<nbOf1DLev;i++)
551     {
552       std::vector<int> conn(conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
553       std::sort(conn.begin(),conn.end());
554       if(computeMesh1D)
555         computeBaryCenterOfFace(conn,i-1);
556       current2DCell=findOppositeFaceOf(current2DCell,current3DCell,conn,
557           desc3D,descIndx3D,conn2D,conn2DIndx);
558       start=revDescIndx3D[current2DCell];
559       end=revDescIndx3D[current2DCell+1];
560       if(end-start!=2)
561         {
562           std::ostringstream ost; ost << "Expecting to have 2 3D cells attached to 2D cell " << current2DCell << "!";
563           ost << " : Impossible or call tryToShareSameCoords method !";
564           throw INTERP_KERNEL::Exception(ost.str().c_str());
565         }
566       if(revDesc3D[start]!=current3DCell)
567         current3DCell=revDesc3D[start];
568       else
569         current3DCell=revDesc3D[start+1];
570       mesh3DIDs[i*nbOf2DCells+newId]=current3DCell;
571     }
572   if(computeMesh1D)
573     {
574       std::vector<int> conn(conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
575       std::sort(conn.begin(),conn.end());
576       computeBaryCenterOfFace(conn,nbOf1DLev-1);
577       current2DCell=findOppositeFaceOf(current2DCell,current3DCell,conn,
578           desc3D,descIndx3D,conn2D,conn2DIndx);
579       conn.clear();
580       conn.insert(conn.end(),conn2D+conn2DIndx[current2DCell]+1,conn2D+conn2DIndx[current2DCell+1]);
581       std::sort(conn.begin(),conn.end());
582       computeBaryCenterOfFace(conn,nbOf1DLev);
583     }
584 }
585
586 int MEDCouplingExtrudedMesh::findOppositeFaceOf(int current2DCell, int current3DCell, const std::vector<int>& connSorted,
587                                                 const int *desc3D, const int *descIndx3D,
588                                                 const int *conn2D, const int *conn2DIndx)
589 {
590   int start=descIndx3D[current3DCell];
591   int end=descIndx3D[current3DCell+1];
592   bool found=false;
593   for(const int *candidate2D=desc3D+start;candidate2D!=desc3D+end && !found;candidate2D++)
594     {
595       if(*candidate2D!=current2DCell)
596         {
597           std::vector<int> conn2(conn2D+conn2DIndx[*candidate2D]+1,conn2D+conn2DIndx[*candidate2D+1]);
598           std::sort(conn2.begin(),conn2.end());
599           std::list<int> intersect;
600           std::set_intersection(connSorted.begin(),connSorted.end(),conn2.begin(),conn2.end(),
601                                 std::insert_iterator< std::list<int> >(intersect,intersect.begin()));
602           if(intersect.empty())
603             return *candidate2D;
604         }
605     }
606   std::ostringstream ost; ost << "Impossible to find an opposite 2D face of face # " <<  current2DCell;
607   ost << " in 3D cell # " << current3DCell << " : Impossible or call tryToShareSameCoords method !";
608   throw INTERP_KERNEL::Exception(ost.str().c_str());
609 }
610
611 void MEDCouplingExtrudedMesh::computeBaryCenterOfFace(const std::vector<int>& nodalConnec, int lev1DId)
612 {
613   double *zoneToUpdate=_mesh1D->getCoords()->getPointer()+lev1DId*3;
614   std::fill(zoneToUpdate,zoneToUpdate+3,0.);
615   const double *coords=_mesh2D->getCoords()->getConstPointer();
616   for(std::vector<int>::const_iterator iter=nodalConnec.begin();iter!=nodalConnec.end();iter++)
617     std::transform(zoneToUpdate,zoneToUpdate+3,coords+3*(*iter),zoneToUpdate,std::plus<double>());
618   std::transform(zoneToUpdate,zoneToUpdate+3,zoneToUpdate,std::bind2nd(std::multiplies<double>(),(double)(1./(int)nodalConnec.size())));
619 }
620
621 int MEDCouplingExtrudedMesh::FindCorrespCellByNodalConn(const std::vector<int>& nodalConnec, const int *revNodalPtr, const int *revNodalIndxPtr)
622 {
623   std::vector<int>::const_iterator iter=nodalConnec.begin();
624   std::set<int> s1(revNodalPtr+revNodalIndxPtr[*iter],revNodalPtr+revNodalIndxPtr[*iter+1]);
625   iter++;
626   for(;iter!=nodalConnec.end();iter++)
627     {
628       std::set<int> s2(revNodalPtr+revNodalIndxPtr[*iter],revNodalPtr+revNodalIndxPtr[*iter+1]);
629       std::set<int> s3;
630       std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::insert_iterator< std::set<int> >(s3,s3.end()));
631       s1=s3;
632     }
633   if(s1.size()==1)
634     return *(s1.begin());
635   std::ostringstream ostr;
636   ostr << "Cell with nodal connec : ";
637   std::copy(nodalConnec.begin(),nodalConnec.end(),std::ostream_iterator<int>(ostr," "));
638   ostr << " is not part of mesh";
639   throw INTERP_KERNEL::Exception(ostr.str().c_str());
640 }
641
642 /*!
643  * This method is callable on 1Dmeshes (meshDim==1 && spaceDim==3) returned by MEDCouplingExtrudedMesh::getMesh1D typically.
644  * These 1Dmeshes (meshDim==1 && spaceDim==3) have a special semantic because these meshes do not specify a static location but a translation along a path.
645  * This method checks that 'm1' and 'm2' are compatible, if not an exception is thrown. In case these meshes ('m1' and 'm2') are compatible 2 corresponding meshes
646  * are created ('m1r' and 'm2r') that can be used for interpolation.
647  * @param m1 input mesh with meshDim==1 and spaceDim==3
648  * @param m2 input mesh with meshDim==1 and spaceDim==3
649  * @param eps tolerance acceptable to determine compatibility
650  * @param m1r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==1
651  * @param m2r output mesh with ref count equal to 1 with meshDim==1 and spaceDim==1
652  * @param v is the output normalized vector of the common direction of 'm1' and 'm2'  
653  * @throw in case that m1 and m2 are not compatible each other.
654  */
655 void MEDCouplingExtrudedMesh::Project1DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps,
656                                               MEDCouplingUMesh *&m1r, MEDCouplingUMesh *&m2r, double *v)
657 {
658   if(m1->getSpaceDimension()!=3 || m1->getSpaceDimension()!=3)
659     throw INTERP_KERNEL::Exception("Input meshes are expected to have a spaceDim==3 for Projec1D !");
660   m1r=m1->clone(true);
661   m2r=m2->clone(true);
662   m1r->changeSpaceDimension(1);
663   m2r->changeSpaceDimension(1);
664   std::vector<int> c;
665   std::vector<double> ref,ref2;
666   m1->getNodeIdsOfCell(0,c);
667   m1->getCoordinatesOfNode(c[0],ref);
668   m1->getCoordinatesOfNode(c[1],ref2);
669   std::transform(ref2.begin(),ref2.end(),ref.begin(),v,std::minus<double>());
670   double n=INTERP_KERNEL::norm<3>(v);
671   std::transform(v,v+3,v,std::bind2nd(std::multiplies<double>(),1/n));
672   m1->project1D(&ref[0],v,eps,m1r->getCoords()->getPointer());
673   m2->project1D(&ref[0],v,eps,m2r->getCoords()->getPointer());
674 }
675
676 void MEDCouplingExtrudedMesh::rotate(const double *center, const double *vector, double angle)
677 {
678   _mesh2D->rotate(center,vector,angle);
679   _mesh1D->rotate(center,vector,angle);
680 }
681
682 void MEDCouplingExtrudedMesh::translate(const double *vector)
683 {
684   _mesh2D->translate(vector);
685   _mesh1D->translate(vector);
686 }
687
688 void MEDCouplingExtrudedMesh::scale(const double *point, double factor)
689 {
690   _mesh2D->scale(point,factor);
691   _mesh1D->scale(point,factor);
692 }
693
694 std::vector<int> MEDCouplingExtrudedMesh::getDistributionOfTypes() const
695 {
696   throw INTERP_KERNEL::Exception("Not implemented yet !");
697 }
698
699 DataArrayInt *MEDCouplingExtrudedMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
700 {
701   throw INTERP_KERNEL::Exception("Not implemented yet !");
702 }
703
704 void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const
705 {
706   throw INTERP_KERNEL::Exception("Not implemented yet !");
707 }
708
709 MEDCouplingMesh *MEDCouplingExtrudedMesh::buildPart(const int *start, const int *end) const
710 {
711   // not implemented yet !
712   return 0;
713 }
714
715 MEDCouplingMesh *MEDCouplingExtrudedMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
716 {
717   // not implemented yet !
718   return 0;
719 }
720
721 DataArrayInt *MEDCouplingExtrudedMesh::simplexize(int policy)
722 {
723   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::simplexize : unavailable for such a type of mesh : Extruded !");
724 }
725
726 MEDCouplingMesh *MEDCouplingExtrudedMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
727 {
728   // not implemented yet !
729   return 0;
730 }
731
732 DataArrayDouble *MEDCouplingExtrudedMesh::getCoordinatesAndOwner() const
733 {
734   DataArrayDouble *arr2D=_mesh2D->getCoords();
735   DataArrayDouble *arr1D=_mesh1D->getCoords();
736   DataArrayDouble *ret=DataArrayDouble::New();
737   ret->alloc(getNumberOfNodes(),3);
738   int nbOf1DLev=_mesh1D->getNumberOfNodes();
739   int nbOf2DNodes=_mesh2D->getNumberOfNodes();
740   const double *ptSrc=arr2D->getConstPointer();
741   double *pt=ret->getPointer();
742   std::copy(ptSrc,ptSrc+3*nbOf2DNodes,pt);
743   for(int i=1;i<nbOf1DLev;i++)
744     {
745       std::copy(ptSrc,ptSrc+3*nbOf2DNodes,pt+3*i*nbOf2DNodes);
746       double vec[3];
747       std::copy(arr1D->getConstPointer()+3*i,arr1D->getConstPointer()+3*(i+1),vec);
748       std::transform(arr1D->getConstPointer()+3*(i-1),arr1D->getConstPointer()+3*i,vec,vec,std::minus<double>());
749       for(int j=0;j<nbOf2DNodes;j++)
750         std::transform(vec,vec+3,pt+3*(i*nbOf2DNodes+j),pt+3*(i*nbOf2DNodes+j),std::plus<double>());
751     }
752   return ret;
753 }
754
755 DataArrayDouble *MEDCouplingExtrudedMesh::getBarycenterAndOwner() const
756 {
757   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::getBarycenterAndOwner : not yet implemented !");
758 }
759
760 DataArrayDouble *MEDCouplingExtrudedMesh::computeIsoBarycenterOfNodesPerCell() const
761 {
762   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::computeIsoBarycenterOfNodesPerCell: not yet implemented !");
763 }
764
765 void MEDCouplingExtrudedMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
766 {
767   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m(buildUnstructured());
768   m->getReverseNodalConnectivity(revNodal,revNodalIndx);
769 }
770
771 void MEDCouplingExtrudedMesh::computeExtrusionAlg(const MEDCouplingUMesh *mesh3D)
772 {
773   _mesh3D_ids->alloc(mesh3D->getNumberOfCells(),1);
774   int nbOf1DLev=mesh3D->getNumberOfCells()/_mesh2D->getNumberOfCells();
775   _mesh1D->setMeshDimension(1);
776   _mesh1D->allocateCells(nbOf1DLev);
777   int tmpConn[2];
778   for(int i=0;i<nbOf1DLev;i++)
779     {
780       tmpConn[0]=i;
781       tmpConn[1]=i+1;
782       _mesh1D->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,tmpConn);
783     }
784   _mesh1D->finishInsertingCells();
785   DataArrayDouble *myCoords=DataArrayDouble::New();
786   myCoords->alloc(nbOf1DLev+1,3);
787   _mesh1D->setCoords(myCoords);
788   myCoords->decrRef();
789   DataArrayInt *desc,*descIndx,*revDesc,*revDescIndx;
790   desc=DataArrayInt::New(); descIndx=DataArrayInt::New(); revDesc=DataArrayInt::New(); revDescIndx=DataArrayInt::New();
791   MEDCouplingUMesh *subMesh=mesh3D->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
792   DataArrayInt *revNodal2D,*revNodalIndx2D;
793   revNodal2D=DataArrayInt::New(); revNodalIndx2D=DataArrayInt::New();
794   subMesh->getReverseNodalConnectivity(revNodal2D,revNodalIndx2D);
795   const int *nodal2D=_mesh2D->getNodalConnectivity()->getConstPointer();
796   const int *nodal2DIndx=_mesh2D->getNodalConnectivityIndex()->getConstPointer();
797   const int *revNodal2DPtr=revNodal2D->getConstPointer();
798   const int *revNodalIndx2DPtr=revNodalIndx2D->getConstPointer();
799   const int *descP=desc->getConstPointer();
800   const int *descIndxP=descIndx->getConstPointer();
801   const int *revDescP=revDesc->getConstPointer();
802   const int *revDescIndxP=revDescIndx->getConstPointer();
803   //
804   int nbOf2DCells=_mesh2D->getNumberOfCells();
805   for(int i=0;i<nbOf2DCells;i++)
806     {
807       int idInSubMesh;
808       std::vector<int> nodalConnec(nodal2D+nodal2DIndx[i]+1,nodal2D+nodal2DIndx[i+1]);
809       try
810       {
811           idInSubMesh=FindCorrespCellByNodalConn(nodalConnec,revNodal2DPtr,revNodalIndx2DPtr);
812       }
813       catch(INTERP_KERNEL::Exception& e)
814       {
815           std::ostringstream ostr; ostr << "mesh2D cell # " << i << " is not part of any cell of 3D mesh !\n";
816           ostr << e.what();
817           throw INTERP_KERNEL::Exception(ostr.str().c_str());
818       }
819       build1DExtrusion(idInSubMesh,i,nbOf1DLev,subMesh,descP,descIndxP,revDescP,revDescIndxP,i==_cell_2D_id);
820     }
821   //
822   revNodal2D->decrRef();
823   revNodalIndx2D->decrRef();
824   subMesh->decrRef();
825   desc->decrRef();
826   descIndx->decrRef();
827   revDesc->decrRef();
828   revDescIndx->decrRef();
829 }
830
831 void MEDCouplingExtrudedMesh::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
832 {
833   std::vector<int> tinyInfo1;
834   std::vector<std::string> ls1;
835   std::vector<double> ls3;
836   _mesh2D->getTinySerializationInformation(ls3,tinyInfo1,ls1);
837   std::vector<int> tinyInfo2;
838   std::vector<std::string> ls2;
839   std::vector<double> ls4;
840   _mesh1D->getTinySerializationInformation(ls4,tinyInfo2,ls2);
841   tinyInfo.clear(); littleStrings.clear();
842   tinyInfo.insert(tinyInfo.end(),tinyInfo1.begin(),tinyInfo1.end());
843   littleStrings.insert(littleStrings.end(),ls1.begin(),ls1.end());
844   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
845   littleStrings.insert(littleStrings.end(),ls2.begin(),ls2.end());
846   tinyInfo.push_back(_cell_2D_id);
847   tinyInfo.push_back((int)tinyInfo1.size());
848   tinyInfo.push_back(_mesh3D_ids->getNbOfElems());
849   littleStrings.push_back(getName());
850   littleStrings.push_back(getDescription());
851 }
852
853 void MEDCouplingExtrudedMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
854 {
855   std::size_t sz=tinyInfo.size();
856   int sz1=tinyInfo[sz-2];
857   std::vector<int> ti1(tinyInfo.begin(),tinyInfo.begin()+sz1);
858   std::vector<int> ti2(tinyInfo.begin()+sz1,tinyInfo.end()-3);
859   MEDCouplingUMesh *um=MEDCouplingUMesh::New();
860   DataArrayInt *a1tmp=DataArrayInt::New();
861   DataArrayDouble *a2tmp=DataArrayDouble::New();
862   int la1=0,la2=0;
863   std::vector<std::string> ls1,ls2;
864   um->resizeForUnserialization(ti1,a1tmp,a2tmp,ls1);
865   la1+=a1tmp->getNbOfElems(); la2+=a2tmp->getNbOfElems();
866   a1tmp->decrRef(); a2tmp->decrRef();
867   a1tmp=DataArrayInt::New(); a2tmp=DataArrayDouble::New();
868   um->resizeForUnserialization(ti2,a1tmp,a2tmp,ls2);
869   la1+=a1tmp->getNbOfElems(); la2+=a2tmp->getNbOfElems();
870   a1tmp->decrRef(); a2tmp->decrRef();
871   um->decrRef();
872   //
873   a1->alloc(la1+tinyInfo[sz-1],1);
874   a2->alloc(la2,1);
875   littleStrings.resize(ls1.size()+ls2.size()+2);
876 }
877
878 void MEDCouplingExtrudedMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
879 {
880   a1=DataArrayInt::New(); a2=DataArrayDouble::New();
881   DataArrayInt *a1_1=0,*a1_2=0;
882   DataArrayDouble *a2_1=0,*a2_2=0;
883   _mesh2D->serialize(a1_1,a2_1);
884   _mesh1D->serialize(a1_2,a2_2);
885   a1->alloc(a1_1->getNbOfElems()+a1_2->getNbOfElems()+_mesh3D_ids->getNbOfElems(),1);
886   int *ptri=a1->getPointer();
887   ptri=std::copy(a1_1->getConstPointer(),a1_1->getConstPointer()+a1_1->getNbOfElems(),ptri);
888   a1_1->decrRef();
889   ptri=std::copy(a1_2->getConstPointer(),a1_2->getConstPointer()+a1_2->getNbOfElems(),ptri);
890   a1_2->decrRef();
891   std::copy(_mesh3D_ids->getConstPointer(),_mesh3D_ids->getConstPointer()+_mesh3D_ids->getNbOfElems(),ptri);
892   a2->alloc(a2_1->getNbOfElems()+a2_2->getNbOfElems(),1);
893   double *ptrd=a2->getPointer();
894   ptrd=std::copy(a2_1->getConstPointer(),a2_1->getConstPointer()+a2_1->getNbOfElems(),ptrd);
895   a2_1->decrRef();
896   std::copy(a2_2->getConstPointer(),a2_2->getConstPointer()+a2_2->getNbOfElems(),ptrd);
897   a2_2->decrRef();
898 }
899
900 void MEDCouplingExtrudedMesh::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
901 {
902   setName(littleStrings[littleStrings.size()-2]);
903   setDescription(littleStrings.back());
904   std::size_t sz=tinyInfo.size();
905   int sz1=tinyInfo[sz-2];
906   _cell_2D_id=tinyInfo[sz-3];
907   std::vector<int> ti1(tinyInfo.begin(),tinyInfo.begin()+sz1);
908   std::vector<int> ti2(tinyInfo.begin()+sz1,tinyInfo.end()-3);
909   DataArrayInt *a1tmp=DataArrayInt::New();
910   DataArrayDouble *a2tmp=DataArrayDouble::New();
911   const int *a1Ptr=a1->getConstPointer();
912   const double *a2Ptr=a2->getConstPointer();
913   _mesh2D=MEDCouplingUMesh::New();
914   std::vector<std::string> ls1,ls2;
915   _mesh2D->resizeForUnserialization(ti1,a1tmp,a2tmp,ls1);
916   std::copy(a2Ptr,a2Ptr+a2tmp->getNbOfElems(),a2tmp->getPointer());
917   std::copy(a1Ptr,a1Ptr+a1tmp->getNbOfElems(),a1tmp->getPointer());
918   a2Ptr+=a2tmp->getNbOfElems();
919   a1Ptr+=a1tmp->getNbOfElems();
920   ls2.insert(ls2.end(),littleStrings.begin(),littleStrings.begin()+ls1.size());
921   std::vector<double> d1(1);
922   _mesh2D->unserialization(d1,ti1,a1tmp,a2tmp,ls2);
923   a1tmp->decrRef(); a2tmp->decrRef();
924   //
925   ls2.clear();
926   ls2.insert(ls2.end(),littleStrings.begin()+ls1.size(),littleStrings.end()-2);
927   _mesh1D=MEDCouplingUMesh::New();
928   a1tmp=DataArrayInt::New(); a2tmp=DataArrayDouble::New();
929   _mesh1D->resizeForUnserialization(ti2,a1tmp,a2tmp,ls1);
930   std::copy(a2Ptr,a2Ptr+a2tmp->getNbOfElems(),a2tmp->getPointer());
931   std::copy(a1Ptr,a1Ptr+a1tmp->getNbOfElems(),a1tmp->getPointer());
932   a1Ptr+=a1tmp->getNbOfElems();
933   _mesh1D->unserialization(d1,ti2,a1tmp,a2tmp,ls2);
934   a1tmp->decrRef(); a2tmp->decrRef();
935   //
936   _mesh3D_ids=DataArrayInt::New();
937   int szIds=(int)std::distance(a1Ptr,a1->getConstPointer()+a1->getNbOfElems());
938   _mesh3D_ids->alloc(szIds,1);
939   std::copy(a1Ptr,a1Ptr+szIds,_mesh3D_ids->getPointer());
940 }
941
942 void MEDCouplingExtrudedMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const
943 {
944   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
945   m->writeVTKLL(ofs,cellData,pointData,byteData);
946 }
947
948 void MEDCouplingExtrudedMesh::reprQuickOverview(std::ostream& stream) const
949 {
950   stream << "MEDCouplingExtrudedMesh C++ instance at " << this << ". Name : \"" << getName() << "\".";
951 }
952
953 std::string MEDCouplingExtrudedMesh::getVTKFileExtension() const
954 {
955   return _mesh2D->getVTKFileExtension();
956 }
957
958 std::string MEDCouplingExtrudedMesh::getVTKDataSetType() const
959 {
960   return _mesh2D->getVTKDataSetType();
961 }