1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingCurveLinearMesh.hxx"
22 #include "MEDCouplingPointSet.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
26 #include "VolSurfUser.txx"
27 #include "PointLocatorAlgos.txx"
34 using namespace ParaMEDMEM;
36 MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh():_coords(0),_structure(0)
40 MEDCouplingCurveLinearMesh::MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_structure(other._structure)
44 if((const DataArrayDouble *)other._coords)
45 _coords=other._coords->deepCpy();
48 _coords=other._coords;
51 MEDCouplingCurveLinearMesh::~MEDCouplingCurveLinearMesh()
55 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::New()
57 return new MEDCouplingCurveLinearMesh;
60 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::New(const std::string& meshName)
62 MEDCouplingCurveLinearMesh *ret=new MEDCouplingCurveLinearMesh;
63 ret->setName(meshName);
67 MEDCouplingMesh *MEDCouplingCurveLinearMesh::deepCpy() const
72 MEDCouplingCurveLinearMesh *MEDCouplingCurveLinearMesh::clone(bool recDeepCpy) const
74 return new MEDCouplingCurveLinearMesh(*this,recDeepCpy);
77 void MEDCouplingCurveLinearMesh::updateTime() const
79 if((const DataArrayDouble *)_coords)
80 updateTimeWith(*_coords);
83 std::size_t MEDCouplingCurveLinearMesh::getHeapMemorySizeWithoutChildren() const
85 std::size_t ret(MEDCouplingStructuredMesh::getHeapMemorySizeWithoutChildren());
86 ret+=_structure.capacity()*sizeof(int);
90 std::vector<const BigMemoryObject *> MEDCouplingCurveLinearMesh::getDirectChildren() const
92 std::vector<const BigMemoryObject *> ret;
93 if((const DataArrayDouble *)_coords)
94 ret.push_back((const DataArrayDouble *)_coords);
99 * This method copyies all tiny strings from other (name and components name).
100 * @throw if other and this have not same mesh type.
102 void MEDCouplingCurveLinearMesh::copyTinyStringsFrom(const MEDCouplingMesh *other)
104 const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
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);
112 bool MEDCouplingCurveLinearMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const
115 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::isEqualIfNotWhy : input other pointer is null !");
116 const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
119 reason="mesh given in input is not castable in MEDCouplingCurveLinearMesh !";
122 if(!MEDCouplingStructuredMesh::isEqualIfNotWhy(other,prec,reason))
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))
127 oss << "Only one CurveLinearMesh between the two this and other has its coordinates defined !";
131 if((const DataArrayDouble *)_coords)
133 if(!_coords->isEqualIfNotWhy(*(otherC->_coords),prec,reason))
135 oss << "Coordinates DataArrayDouble of differ :";
136 reason.insert(0,oss.str());
139 if(_structure!=otherC->_structure)
140 { reason="CurveLinearMesh structures differ !"; return false; }
145 bool MEDCouplingCurveLinearMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
147 const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
150 if(((const DataArrayDouble *)_coords && ((const DataArrayDouble *)otherC->_coords)==0) || (((const DataArrayDouble *)_coords)==0 && (const DataArrayDouble *)otherC->_coords))
152 if((const DataArrayDouble *)_coords)
154 if(!_coords->isEqualWithoutConsideringStr(*(otherC->_coords),prec))
156 if(_structure!=otherC->_structure)
162 void MEDCouplingCurveLinearMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
163 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const
165 if(!isEqualWithoutConsideringStr(other,prec))
166 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalWith : Meshes are not the same !");
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, \a this and \a other are the same !
173 void MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
174 DataArrayInt *&cellCor) const
176 if(!isEqualWithoutConsideringStr(other,prec))
177 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !");
180 void MEDCouplingCurveLinearMesh::checkCoherency() const
182 std::size_t sz=_structure.size(),i=0,nbOfNodes=1;
184 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : structure should have a lgth of size 1 at least !");
185 for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++,i++)
188 { 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()); }
191 if(!((const DataArrayDouble *)_coords))
192 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array is not set !");
193 if(!_coords->isAllocated())
194 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array is not allocated !");
195 if(_coords->getNumberOfComponents()<1)
196 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkCoherency : the array should have >= 1 components !");
197 if(_coords->getNumberOfTuples()!=(int)nbOfNodes)
199 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() << " !";
200 throw INTERP_KERNEL::Exception(oss.str().c_str());
204 void MEDCouplingCurveLinearMesh::checkCoherency1(double eps) const
209 void MEDCouplingCurveLinearMesh::checkCoherency2(double eps) const
211 checkCoherency1(eps);
214 int MEDCouplingCurveLinearMesh::getNumberOfCells() const
217 return MEDCouplingStructuredMesh::getNumberOfCells();
220 int MEDCouplingCurveLinearMesh::getNumberOfNodes() const
223 return MEDCouplingStructuredMesh::getNumberOfNodes();
226 void MEDCouplingCurveLinearMesh::getNodeGridStructure(int *res) const
228 std::copy(_structure.begin(),_structure.end(),res);
232 * MEDCouplingCurveLinearMesh has the property to define 2 space dimensions. One coming from its coordinates. The other coming from the node structure.
233 * Normally they should be equal ! This method returns the space dimension from coordinates. If the other one is requested call getSpaceDimensionOnNodeStruct.
235 * \sa MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct
237 int MEDCouplingCurveLinearMesh::getSpaceDimension() const
239 if(!((const DataArrayDouble *)_coords))
240 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getSpaceDimension : no array set ! impossible to deduce a space dimension !");
241 return _coords->getNumberOfComponents();
244 void MEDCouplingCurveLinearMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
246 if(!((const DataArrayDouble *)_coords))
247 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCoordinatesOfNode : Coordinates not set !");
248 int nbOfCompo=_coords->getNumberOfComponents();
249 if(nodeId>=0 && nodeId<_coords->getNumberOfTuples())
250 coo.insert(coo.end(),_coords->begin()+nodeId*nbOfCompo,_coords->begin()+(nodeId+1)*nbOfCompo);
252 { std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::getCoordinatesOfNode : nodeId has to be in [0," << _coords->getNumberOfTuples() << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
255 std::string MEDCouplingCurveLinearMesh::simpleRepr() const
257 std::ostringstream ret;
258 ret << "Curve linear mesh with name : \"" << getName() << "\"\n";
259 ret << "Description of mesh : \"" << getDescription() << "\"\n";
261 double tt=getTime(tmpp1,tmpp2);
262 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
263 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
264 ret << "The nodal stucture of curve linear mesh is : [";
265 std::copy(_structure.begin(),_structure.end(),std::ostream_iterator<int>(ret,",")); ret << "]\n";
266 ret << "The coords array is this : ";
267 if((const DataArrayDouble *)_coords)
268 _coords->reprZipWithoutNameStream(ret);
270 ret << "no array specified !";
274 std::string MEDCouplingCurveLinearMesh::advancedRepr() const
279 DataArrayDouble *MEDCouplingCurveLinearMesh::getCoords()
284 const DataArrayDouble *MEDCouplingCurveLinearMesh::getCoords() const
289 void MEDCouplingCurveLinearMesh::setCoords(const DataArrayDouble *coords)
291 if(coords!=(const DataArrayDouble *)_coords)
293 _coords=const_cast<DataArrayDouble *>(coords);
300 void MEDCouplingCurveLinearMesh::setNodeGridStructure(const int *gridStructBg, const int *gridStructEnd)
302 std::size_t sz=std::distance(gridStructBg,gridStructEnd);
305 _structure.resize(0);
306 _structure.insert(_structure.end(),gridStructBg,gridStructEnd);
310 std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::setNodeGridStructure : size of input nodal grid structure (" << sz << ") should be in 1, 2 or 3 !";
311 throw INTERP_KERNEL::Exception(oss.str().c_str());
315 std::vector<int> MEDCouplingCurveLinearMesh::getNodeGridStructure() const
320 MEDCouplingStructuredMesh *MEDCouplingCurveLinearMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const
323 int dim(getSpaceDimension());
324 std::vector<int> dims(getMeshDimension());
325 if(dim!=(int)cellPart.size())
327 std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
328 throw INTERP_KERNEL::Exception(oss.str().c_str());
330 std::vector< std::pair<int,int> > nodePartFormat(cellPart);
331 for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
333 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
334 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> ret(dynamic_cast<MEDCouplingCurveLinearMesh *>(deepCpy()));
335 const DataArrayDouble *coo(ret->getCoords());
338 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo2(coo->selectByTupleIdSafe(tmp1->begin(),tmp1->end()));
339 ret->setCoords(coo2);
341 for(int i=0;i<dim;i++)
343 dims[i]=cellPart[i].second-cellPart[i].first+1;
345 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::buildStructuredSubPart : invalid input cellPart !");
347 ret->setNodeGridStructure(&dims[0],&dims[0]+dims.size());
351 void MEDCouplingCurveLinearMesh::getBoundingBox(double *bbox) const
353 if(!((const DataArrayDouble *)_coords))
354 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBoundingBox : Coordinates not set !");
355 _coords->getMinMaxPerComponent(bbox);
358 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureField(bool isAbs) const
361 int meshDim=getMeshDimension();
362 std::string name="MeasureOfMesh_"; name+=getName();
363 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
364 field->setName(name); field->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(this)); field->synchronizeTimeWithMesh();
368 { getMeasureFieldMeshDim3(isAbs,field); return field.retn(); }
370 { getMeasureFieldMeshDim2(isAbs,field); return field.retn(); }
372 { getMeasureFieldMeshDim1(isAbs,field); return field.retn(); }
374 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureField : mesh dimension must be in [1,2,3] !");
379 * \param [in,out] f field feeded with good values.
380 * \sa MEDCouplingCurveLinearMesh::getMeasureField
382 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim1(bool isAbs, MEDCouplingFieldDouble *field) const
384 int nbnodes=getNumberOfNodes();
385 int spaceDim=getSpaceDimension();
386 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
388 { arr->alloc(0,1); return; }
391 arr->alloc(nbnodes-1,1);
392 std::transform(_coords->begin()+1,_coords->end(),_coords->begin(),arr->getPointer(),std::minus<double>());
398 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp=DataArrayDouble::New(); tmp->alloc(nbnodes-1,spaceDim);
399 std::transform(_coords->begin()+spaceDim,_coords->end(),_coords->begin(),tmp->getPointer(),std::minus<double>());
400 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=tmp->magnitude(); field->setArray(tmp2);
405 * \param [in,out] f field feeded with good values.
406 * \sa MEDCouplingCurveLinearMesh::getMeasureField
408 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim2(bool isAbs, MEDCouplingFieldDouble *field) const
410 int nbcells=getNumberOfCells();
411 int spaceDim=getSpaceDimension();
412 if(spaceDim!=2 && spaceDim!=3)
413 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim2 : with meshDim 2 only space dimension 2 and 3 are possible !");
414 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
415 arr->alloc(nbcells,1);
416 double *pt=arr->getPointer();
417 const double *coords=_coords->begin();
418 int nX=_structure[0]-1;
420 for(int i=0;i<nbcells;i++,pt++)
422 int cy=i/nX,cx=i-cy*nX;
423 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;
424 *pt=INTERP_KERNEL::computeVolSurfOfCell2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_QUAD4,conn,4,coords,spaceDim);
431 * \param [in,out] f field feeded with good values.
432 * \sa MEDCouplingCurveLinearMesh::getMeasureField
434 void MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim3(bool isAbs, MEDCouplingFieldDouble *field) const
436 int nbcells=getNumberOfCells();
437 int spaceDim=getSpaceDimension();
439 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldMeshDim3 : with meshDim 3 only space dimension 3 is possible !");
440 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::New(); field->setArray(arr);
441 arr->alloc(nbcells,1);
442 double *pt=arr->getPointer();
443 const double *coords=_coords->begin();
444 int nX=_structure[0]-1,nY=(_structure[0]-1)*(_structure[1]-1);
445 int nY1=_structure[0]*_structure[1];
447 for(int i=0;i<nbcells;i++,pt++)
451 int cx=(i-cz*nY)-nX*cy;
452 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;
453 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;
454 *pt=INTERP_KERNEL::computeVolSurfOfCell2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_HEXA8,conn,8,coords,3);
461 * not implemented yet !
463 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureFieldOnNode(bool isAbs) const
465 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureFieldOnNode : not implemented yet !");
468 MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::buildOrthogonalField() const
470 if(getMeshDimension()!=2)
471 throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
472 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
473 DataArrayDouble *array=DataArrayDouble::New();
474 int nbOfCells=getNumberOfCells();
475 array->alloc(nbOfCells,3);
476 double *vals=array->getPointer();
477 for(int i=0;i<nbOfCells;i++)
478 { vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
479 ret->setArray(array);
489 template<const int SPACEDIMM>
493 static const int MY_SPACEDIM=SPACEDIMM;
494 static const int MY_MESHDIM=8;
495 typedef int MyConnType;
496 static const INTERP_KERNEL::NumberingPolicy My_numPol=INTERP_KERNEL::ALL_C_MODE;
498 // useless, but for windows compilation ...
499 const double* getCoordinatesPtr() const { return 0; }
500 const int* getConnectivityPtr() const { return 0; }
501 const int* getConnectivityIndexPtr() const { return 0; }
502 INTERP_KERNEL::NormalizedCellType getTypeOfElement(int) const { return (INTERP_KERNEL::NormalizedCellType)0; }
509 int MEDCouplingCurveLinearMesh::getCellContainingPoint(const double *pos, double eps) const
512 int spaceDim=getSpaceDimension();
513 const double *coords=_coords->getConstPointer();
515 _coords->distanceToTuple(pos,pos+spaceDim,nodeId);
517 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : internal problem 1 !");
519 int nbOfNodes=getNumberOfNodes();
521 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : No cells in this !");
522 switch(getMeshDimension())
529 conn[0]=nodeId-1; conn[1]=nodeId;
530 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<1> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_SEG2,coords,conn,2,eps))
533 if(nodeId<nbOfNodes-1)
535 conn[0]=nodeId; conn[1]=nodeId+1;
536 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<1> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_SEG2,coords,conn,2,eps))
543 int ny=nodeId/_structure[0],nx=nodeId-ny*_structure[0];
546 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);
547 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
548 return nx-1+(ny-1)*_structure[0];
550 if(nx<_structure[0]-1 && ny>0)
552 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);
553 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
554 return nx+(ny-1)*_structure[0];
556 if(nx>0 && ny<_structure[1]-1)
558 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;
559 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
560 return nx-1+ny*_structure[0];
562 if(nx<_structure[0]-1 && ny<_structure[1]-1)
564 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;
565 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<2> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_QUAD4,coords,conn,4,eps))
566 return nx+ny*_structure[0];
573 int nY=_structure[0]*_structure[1];
574 int nz=nodeId/_structure[1]; int ny=(nodeId-nz*nY)/_structure[0]; int nx=(nodeId-nz*nY)-_structure[0]*ny;
575 if(nx>0 && ny>0 && nz>0)
577 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);
578 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;
579 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
580 return nx-1+(ny-1)*_structure[0]+(nz-1)*nY;
582 if(nx<_structure[0]-1 && ny>0 && nz>0)
584 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);
585 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;
586 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
587 return nx+(ny-1)*_structure[0]+(nz-1)*nY;
589 if(nx>0 && ny<_structure[1]-1 && nz>0)
591 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);
592 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;
593 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
594 return nx-1+ny*_structure[0]+(nz-1)*nY;
596 if(nx<_structure[0]-1 && ny<_structure[1]-1 && nz>0)
598 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);
599 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;
600 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
601 return nx+ny*_structure[0]+(nz-1)*nY;
603 if(nx>0 && ny>0 && nz<_structure[2]-1)
605 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);
606 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;
607 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
608 return nx-1+(ny-1)*_structure[0]+nz*nY;
610 if(nx<_structure[0]-1 && ny>0 && nz<_structure[2]-1)
612 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);
613 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;
614 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
615 return nx+(ny-1)*_structure[0]+nz*nY;
617 if(nx>0 && ny<_structure[1]-1 && nz<_structure[2]-1)
619 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);
620 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;
621 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
622 return nx-1+ny*_structure[0]+nz*nY;
624 if(nx<_structure[0]-1 && ny<_structure[1]-1 && nz<_structure[2]-1)
626 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);
627 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;
628 if(INTERP_KERNEL::PointLocatorAlgos<DummyClsMCL<3> >::isElementContainsPoint(pos,INTERP_KERNEL::NORM_HEXA8,coords,conn,8,eps))
629 return nx+ny*_structure[0]+nz*nY;
634 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : mesh dimension managed are 1, 2 or 3 !");
638 void MEDCouplingCurveLinearMesh::rotate(const double *center, const double *vector, double angle)
640 if(!((DataArrayDouble *)_coords))
641 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::rotate : no coordinates set !");
642 int spaceDim=getSpaceDimension();
643 int nbNodes=_coords->getNumberOfTuples();
644 double *coords=_coords->getPointer();
646 MEDCouplingPointSet::Rotate3DAlg(center,vector,angle,nbNodes,coords);
648 MEDCouplingPointSet::Rotate2DAlg(center,angle,nbNodes,coords);
650 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::rotate : invalid space dim for rotation must be 2 or 3");
651 _coords->declareAsNew();
655 void MEDCouplingCurveLinearMesh::translate(const double *vector)
658 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::translate : NULL input point !");
659 if(!((DataArrayDouble *)_coords))
660 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::translate : no coordinates set !");
661 double *coords=_coords->getPointer();
662 int nbNodes=getNumberOfNodes();
663 int dim=getSpaceDimension();
664 for(int i=0; i<nbNodes; i++)
665 for(int idim=0; idim<dim;idim++)
666 coords[i*dim+idim]+=vector[idim];
667 _coords->declareAsNew();
671 void MEDCouplingCurveLinearMesh::scale(const double *point, double factor)
674 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::scale : NULL input point !");
675 if(!((DataArrayDouble *)_coords))
676 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::scale : no coordinates set !");
677 double *coords=_coords->getPointer();
678 int nbNodes=_coords->getNumberOfTuples();
679 int dim=_coords->getNumberOfComponents();
680 for(int i=0;i<nbNodes;i++)
682 std::transform(coords+i*dim,coords+(i+1)*dim,point,coords+i*dim,std::minus<double>());
683 std::transform(coords+i*dim,coords+(i+1)*dim,coords+i*dim,std::bind2nd(std::multiplies<double>(),factor));
684 std::transform(coords+i*dim,coords+(i+1)*dim,point,coords+i*dim,std::plus<double>());
686 _coords->declareAsNew();
690 MEDCouplingMesh *MEDCouplingCurveLinearMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
692 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::mergeMyselfWith : not available for CurveLinear Mesh !");
695 DataArrayDouble *MEDCouplingCurveLinearMesh::getCoordinatesAndOwner() const
697 DataArrayDouble *ret=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords);
703 DataArrayDouble *MEDCouplingCurveLinearMesh::getBarycenterAndOwner() const
706 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
707 int spaceDim=getSpaceDimension();
708 int meshDim=getMeshDimension();
709 int nbOfCells=getNumberOfCells();
710 ret->alloc(nbOfCells,spaceDim);
711 ret->copyStringInfoFrom(*getCoords());
715 { getBarycenterAndOwnerMeshDim3(ret); return ret.retn(); }
717 { getBarycenterAndOwnerMeshDim2(ret); return ret.retn(); }
719 { getBarycenterAndOwnerMeshDim1(ret); return ret.retn(); }
721 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwner : mesh dimension must be in [1,2,3] !");
725 DataArrayDouble *MEDCouplingCurveLinearMesh::computeIsoBarycenterOfNodesPerCell() const
727 return MEDCouplingCurveLinearMesh::getBarycenterAndOwner();
731 * \param [in,out] bary Barycenter array feeded with good values.
732 * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
734 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim3(DataArrayDouble *bary) const
736 int nbOfCells=getNumberOfCells();
737 double *ptToFill=bary->getPointer();
738 const double *coor=_coords->getConstPointer();
739 if(getSpaceDimension()!=3)
740 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim3 : with meshDim 3 only space dimension 3 is possible !");
741 int nX=_structure[0]-1,nY=(_structure[0]-1)*(_structure[1]-1);
742 int nY1=_structure[0]*_structure[1];
744 for(int i=0;i<nbOfCells;i++)
748 int cx=(i-cz*nY)-nX*cy;
749 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;
750 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;
751 INTERP_KERNEL::computeBarycenter2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_HEXA8,conn,8,coor,3,ptToFill);
757 * \param [in,out] bary Barycenter array feeded with good values.
758 * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
760 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim2(DataArrayDouble *bary) const
762 int nbcells=getNumberOfCells();
763 int spaceDim=getSpaceDimension();
764 double *ptToFill=bary->getPointer();
765 const double *coor=_coords->getConstPointer();
766 if(spaceDim!=2 && spaceDim!=3)
767 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim2 : with meshDim 2 only space dimension 2 and 3 are possible !");
768 int nX=_structure[0]-1;
770 for(int i=0;i<nbcells;i++)
772 int cy=i/nX,cx=i-cy*nX;
773 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;
774 INTERP_KERNEL::computeBarycenter2<int,INTERP_KERNEL::ALL_C_MODE>(INTERP_KERNEL::NORM_QUAD4,conn,4,coor,spaceDim,ptToFill);
780 * \param [in,out] bary Barycenter array feeded with good values.
781 * \sa MEDCouplingCurveLinearMesh::getBarycenterAndOwner
783 void MEDCouplingCurveLinearMesh::getBarycenterAndOwnerMeshDim1(DataArrayDouble *bary) const
785 int spaceDim=getSpaceDimension();
786 std::transform(_coords->begin()+spaceDim,_coords->end(),_coords->begin(),bary->getPointer(),std::plus<double>());
787 std::transform(bary->begin(),bary->end(),bary->getPointer(),std::bind2nd(std::multiplies<double>(),0.5));
790 void MEDCouplingCurveLinearMesh::renumberCells(const int *old2NewBg, bool check)
792 throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for CurveLinear Mesh !");
795 void MEDCouplingCurveLinearMesh::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
798 double time=getTime(it,order);
801 littleStrings.clear();
802 littleStrings.push_back(getName());
803 littleStrings.push_back(getDescription());
804 littleStrings.push_back(getTimeUnit());
806 std::vector<std::string> littleStrings2;
807 if((const DataArrayDouble *)_coords)
808 _coords->getTinySerializationStrInformation(littleStrings2);
809 littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end());
811 tinyInfo.push_back(it);
812 tinyInfo.push_back(order);
813 tinyInfo.push_back((int)_structure.size());
814 for(std::vector<int>::const_iterator itt=_structure.begin();itt!=_structure.end();itt++)
815 tinyInfo.push_back(*itt);
816 std::vector<int> tinyInfo2;
817 if((const DataArrayDouble *)_coords)
818 _coords->getTinySerializationIntInformation(tinyInfo2);
819 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
821 tinyInfoD.push_back(time);
824 void MEDCouplingCurveLinearMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
826 a1->alloc(tinyInfo[2],1);
827 std::vector<int> tinyInfo2(tinyInfo.begin()+3+tinyInfo[2],tinyInfo.end());
828 a2->resizeForUnserialization(tinyInfo2);
831 void MEDCouplingCurveLinearMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
833 a1=DataArrayInt::New();
834 a1->alloc((int)_structure.size(),1);
835 int *ptr=a1->getPointer();
836 for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++,ptr++)
839 if((const DataArrayDouble *)_coords)
840 if(_coords->isAllocated())
841 sz=_coords->getNbOfElems();
842 a2=DataArrayDouble::New();
844 if(sz!=0 && (const DataArrayDouble *)_coords)
845 std::copy(_coords->begin(),_coords->end(),a2->getPointer());
848 void MEDCouplingCurveLinearMesh::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
849 const std::vector<std::string>& littleStrings)
851 setName(littleStrings[0]);
852 setDescription(littleStrings[1]);
853 setTimeUnit(littleStrings[2]);
854 setTime(tinyInfoD[0],tinyInfo[0],tinyInfo[1]);
856 _structure.resize(sz);
857 for(int i=0;i<sz;i++)
858 _structure[i]=tinyInfo[3+i];
859 if((int)tinyInfo.size()>sz+3)
861 _coords=DataArrayDouble::New();
862 std::vector<int> tinyInfo2(tinyInfo.begin()+3+sz,tinyInfo.end());
863 _coords->resizeForUnserialization(tinyInfo2);
864 std::copy(a2->begin(),a2->end(),_coords->getPointer());
865 std::vector<std::string> littleStrings2(littleStrings.begin()+3,littleStrings.end());
866 _coords->finishUnserialization(tinyInfo2,littleStrings2);
870 void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const
872 std::ostringstream extent;
873 int meshDim=(int)_structure.size();
874 if(meshDim<=0 || meshDim>3)
875 throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::writeVTKLL : meshDim invalid ! must be in [1,2,3] !");
877 { int val=i<meshDim?_structure[i]-1:0; extent << "0 " << val << " "; }
878 ofs << " <" << getVTKDataSetType() << " WholeExtent=\"" << extent.str() << "\">\n";
879 ofs << " <Piece Extent=\"" << extent.str() << "\">\n";
880 ofs << " <PointData>\n" << pointData << std::endl;
881 ofs << " </PointData>\n";
882 ofs << " <CellData>\n" << cellData << std::endl;
883 ofs << " </CellData>\n";
884 ofs << " <Points>\n";
885 if(getSpaceDimension()==3)
886 _coords->writeVTK(ofs,8,"Points",byteData);
889 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->changeNbOfComponents(3,0.);
890 coo->writeVTK(ofs,8,"Points",byteData);
892 ofs << " </Points>\n";
893 ofs << " </Piece>\n";
894 ofs << " </" << getVTKDataSetType() << ">\n";
897 void MEDCouplingCurveLinearMesh::reprQuickOverview(std::ostream& stream) const
899 stream << "MEDCouplingCurveLinearMesh C++ instance at " << this << ". Name : \"" << getName() << "\".";
900 stream << " Nodal structure : [";
901 for(std::size_t i=0;i<_structure.size();i++)
904 stream << " " << tmp << "=" << _structure[i];
905 if(i!=_structure.size()-1)
909 const DataArrayDouble *coo(_coords);
911 { stream << std::endl << "No coordinates set !"; return ; }
912 if(!coo->isAllocated())
913 { stream << std::endl << "Coordinates set but not allocated !"; return ; }
914 int nbOfCompo=coo->getNumberOfComponents();
915 if(nbOfCompo!=(int)_structure.size())
916 { stream << std::endl << "Coordinates set and allocated but mismatch number of components !"; return ; }
917 stream << std::endl << "Coordinates ( number of tuples = " << coo->getNumberOfTuples() << " ) : ";
918 coo->reprQuickOverviewData(stream,200);
921 std::string MEDCouplingCurveLinearMesh::getVTKFileExtension() const
923 return std::string("vts");
926 std::string MEDCouplingCurveLinearMesh::getVTKDataSetType() const
928 return std::string("StructuredGrid");