1 // Copyright (C) 2007-2013 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.
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 "MEDCouplingCMesh.hxx"
22 #include "MEDCouplingMemArray.hxx"
23 #include "MEDCouplingFieldDouble.hxx"
30 using namespace ParaMEDMEM;
32 MEDCouplingCMesh::MEDCouplingCMesh():_x_array(0),_y_array(0),_z_array(0)
36 MEDCouplingCMesh::MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy)
41 _x_array=other._x_array->deepCpy();
45 _y_array=other._y_array->deepCpy();
49 _z_array=other._z_array->deepCpy();
55 _x_array=other._x_array;
58 _y_array=other._y_array;
61 _z_array=other._z_array;
67 MEDCouplingCMesh::~MEDCouplingCMesh()
77 MEDCouplingCMesh *MEDCouplingCMesh::New()
79 return new MEDCouplingCMesh;
82 MEDCouplingCMesh *MEDCouplingCMesh::New(const char *meshName)
84 MEDCouplingCMesh *ret=new MEDCouplingCMesh;
85 ret->setName(meshName);
89 MEDCouplingMesh *MEDCouplingCMesh::deepCpy() const
94 MEDCouplingCMesh *MEDCouplingCMesh::clone(bool recDeepCpy) const
96 return new MEDCouplingCMesh(*this,recDeepCpy);
99 void MEDCouplingCMesh::updateTime() const
102 updateTimeWith(*_x_array);
104 updateTimeWith(*_y_array);
106 updateTimeWith(*_z_array);
109 std::size_t MEDCouplingCMesh::getHeapMemorySize() const
112 std::set<DataArrayDouble *> s;
113 s.insert(_x_array); s.insert(_y_array); s.insert(_z_array);
115 for(std::set<DataArrayDouble *>::const_iterator it=s.begin();it!=s.end();it++)
117 ret+=(*it)->getHeapMemorySize();
118 return MEDCouplingStructuredMesh::getHeapMemorySize()+ret;
122 * This method copyies all tiny strings from other (name and components name).
123 * @throw if other and this have not same mesh type.
125 void MEDCouplingCMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception)
127 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
129 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::copyTinyStringsFrom : meshes have not same type !");
130 MEDCouplingStructuredMesh::copyTinyStringsFrom(other);
131 if(_x_array && otherC->_x_array)
132 _x_array->copyStringInfoFrom(*otherC->_x_array);
133 if(_y_array && otherC->_y_array)
134 _y_array->copyStringInfoFrom(*otherC->_y_array);
135 if(_z_array && otherC->_z_array)
136 _z_array->copyStringInfoFrom(*otherC->_z_array);
139 bool MEDCouplingCMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
142 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::isEqualIfNotWhy : input other pointer is null !");
143 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
146 reason="mesh given in input is not castable in MEDCouplingCMesh !";
149 if(!MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason))
151 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
152 const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array};
153 std::ostringstream oss; oss.precision(15);
156 if((thisArr[i]!=0 && otherArr[i]==0) || (thisArr[i]==0 && otherArr[i]!=0))
158 oss << "Only one CMesh between the two this and other has its coordinates of rank" << i << " defined !";
163 if(!thisArr[i]->isEqualIfNotWhy(*otherArr[i],prec,reason))
165 oss << "Coordinates DataArrayDouble of rank #" << i << " differ :";
166 reason.insert(0,oss.str());
173 bool MEDCouplingCMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
175 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
178 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
179 const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array};
182 if((thisArr[i]!=0 && otherArr[i]==0) || (thisArr[i]==0 && otherArr[i]!=0))
185 if(!thisArr[i]->isEqualWithoutConsideringStr(*otherArr[i],prec))
191 void MEDCouplingCMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
192 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
194 if(!isEqualWithoutConsideringStr(other,prec))
195 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalWith : Meshes are not the same !");
199 * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCMesh instance too).
200 * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, 'this' and 'other' are the same !
202 void MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
203 DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
205 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
207 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !");
210 void MEDCouplingCMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
212 const char msg0[]="Invalid ";
213 const char msg1[]=" array ! Must contain more than 1 element.";
214 const char msg2[]=" array ! Must be with only one component.";
217 if(_x_array->getNbOfElems()<2)
219 std::ostringstream os; os << msg0 << 'X' << msg1;
220 throw INTERP_KERNEL::Exception(os.str().c_str());
222 if(_x_array->getNumberOfComponents()!=1)
224 std::ostringstream os; os << msg0 << 'X' << msg2;
225 throw INTERP_KERNEL::Exception(os.str().c_str());
230 if(_y_array->getNbOfElems()<2)
232 std::ostringstream os; os << msg0 << 'Y' << msg1;
233 throw INTERP_KERNEL::Exception(os.str().c_str());
235 if(_y_array->getNumberOfComponents()!=1)
237 std::ostringstream os; os << msg0 << 'Y' << msg2;
238 throw INTERP_KERNEL::Exception(os.str().c_str());
244 if(_z_array->getNbOfElems()<2)
246 std::ostringstream os; os << msg0 << 'Z' << msg1;
247 throw INTERP_KERNEL::Exception(os.str().c_str());
249 if(_z_array->getNumberOfComponents()!=1)
251 std::ostringstream os; os << msg0 << 'Z' << msg2;
252 throw INTERP_KERNEL::Exception(os.str().c_str());
257 void MEDCouplingCMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
261 _x_array->checkMonotonic(true, eps);
263 _y_array->checkMonotonic(true, eps);
265 _z_array->checkMonotonic(true, eps);
268 void MEDCouplingCMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
270 checkCoherency1(eps);
273 int MEDCouplingCMesh::getNumberOfCells() const
277 ret*=_x_array->getNbOfElems()-1;
279 ret*=_y_array->getNbOfElems()-1;
281 ret*=_z_array->getNbOfElems()-1;
285 int MEDCouplingCMesh::getNumberOfNodes() const
289 ret*=_x_array->getNbOfElems();
291 ret*=_y_array->getNbOfElems();
293 ret*=_z_array->getNbOfElems();
297 void MEDCouplingCMesh::getSplitCellValues(int *res) const
299 int spaceDim=getSpaceDimension();
300 for(int l=0;l<spaceDim;l++)
303 for(int p=0;p<spaceDim-l-1;p++)
304 val*=getCoordsAt(p)->getNbOfElems()-1;
305 res[spaceDim-l-1]=val;
309 void MEDCouplingCMesh::getSplitNodeValues(int *res) const
311 int spaceDim=getSpaceDimension();
312 for(int l=0;l<spaceDim;l++)
315 for(int p=0;p<spaceDim-l-1;p++)
316 val*=getCoordsAt(p)->getNbOfElems();
317 res[spaceDim-l-1]=val;
321 void MEDCouplingCMesh::getNodeGridStructure(int *res) const
323 int meshDim=getMeshDimension();
324 for(int i=0;i<meshDim;i++)
325 res[i]=getCoordsAt(i)->getNbOfElems();
328 int MEDCouplingCMesh::getSpaceDimension() const
340 int MEDCouplingCMesh::getMeshDimension() const
342 return getSpaceDimension();
345 void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const throw(INTERP_KERNEL::Exception)
348 int spaceDim=getSpaceDimension();
349 getSplitNodeValues(tmp);
350 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
352 GetPosFromId(nodeId,spaceDim,tmp,tmp2);
353 for(int j=0;j<spaceDim;j++)
355 coo.push_back(tabs[j]->getConstPointer()[tmp2[j]]);
358 std::string MEDCouplingCMesh::simpleRepr() const
360 std::ostringstream ret;
361 ret << "Cartesian mesh with name : \"" << getName() << "\"\n";
362 ret << "Description of mesh : \"" << getDescription() << "\"\n";
364 double tt=getTime(tmpp1,tmpp2);
365 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
366 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
367 ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n";
370 ret << "X Array :\n";
371 _x_array->reprZipWithoutNameStream(ret);
375 ret << "Y Array :\n";
376 _y_array->reprZipWithoutNameStream(ret);
380 ret << "Z Array :\n";
381 _z_array->reprZipWithoutNameStream(ret);
386 std::string MEDCouplingCMesh::advancedRepr() const
392 * Returns a DataArrayDouble holding positions of nodes along a given axis.
393 * For more info on Cartesian meshes, see \ref MEDCouplingCMeshPage.
394 * \param [in] i - an index of axis, a value from [0,1,2].
395 * \return const DataArrayDouble * - a pointer to the data array of node coordinates
396 * referred by \a this mesh.
397 * \throw If \a i is not one of [0,1,2].
399 * \ref cpp_mccmesh_getCoordsAt "Here is a C++ example".<br>
400 * \ref py_mccmesh_getCoordsAt "Here is a Python example".
402 const DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception)
413 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
418 * Returns a DataArrayDouble holding positions of nodes along a given axis.
419 * For more info on Cartesian meshes, see \ref MEDCouplingCMeshPage.
420 * \param [in] i - an index of axis, a value from [0,1,2].
421 * \return const DataArrayDouble * - a pointer to the data array of node coordinates
422 * referred by \a this mesh.
423 * \throw If \a i is not one of [0,1,2].
425 * \ref cpp_mccmesh_getCoordsAt "Here is a C++ example".<br>
426 * \ref py_mccmesh_getCoordsAt "Here is a Python example".
428 DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) throw(INTERP_KERNEL::Exception)
439 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
444 * Sets node coordinates along a given axis. For more info on Cartesian meshes, see
445 * \ref MEDCouplingCMeshPage.
446 * \param [in] i - an index of axis, a value in range [0,1,2].
447 * \param [in] arr - DataArrayDouble holding positions of nodes along the i-th
448 * axis. It must be an array of one component.
449 * \throw If \a arr->getNumberOfComponents() != 1.
450 * \throw If \a i is not one of [0,1,2].
452 * \ref medcouplingcppexamplesCmeshStdBuild1 "Here is a C++ example".<br>
453 * \ref medcouplingpyexamplesCmeshStdBuild1 "Here is a Python example".
455 void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception)
458 arr->checkNbOfComps(1,"MEDCouplingCMesh::setCoordsAt");
459 DataArrayDouble **thisArr[3]={&_x_array,&_y_array,&_z_array};
461 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
462 if(arr!=*(thisArr[i]))
465 (*(thisArr[i]))->decrRef();
466 (*(thisArr[i]))=const_cast<DataArrayDouble *>(arr);
468 (*(thisArr[i]))->incrRef();
474 * Sets node coordinates along some of the tree axes. This method updates all the
475 * three node coordinates arrays at once. For more info on Cartesian meshes, see
476 * \ref MEDCouplingCMeshPage.
477 * \param [in] coordsX - DataArrayDouble holding positions of nodes along the X
478 * axis. It must be an array of one component or \c NULL.
479 * \param [in] coordsY - DataArrayDouble holding positions of nodes along the Y
480 * axis. It must be an array of one component or \c NULL.
481 * \param [in] coordsZ - DataArrayDouble holding positions of nodes along the Z
482 * axis. It must be an array of one component or \c NULL.
483 * \throw If \a coords*->getNumberOfComponents() != 1.
485 * \ref medcouplingcppexamplesCmeshStdBuild1 "Here is a C++ example".<br>
486 * \ref medcouplingpyexamplesCmeshStdBuild1 "Here is a Python example".
488 void MEDCouplingCMesh::setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY, const DataArrayDouble *coordsZ)
491 coordsX->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsX");
493 coordsY->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsY");
495 coordsZ->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsZ");
498 _x_array=const_cast<DataArrayDouble *>(coordsX);
503 _y_array=const_cast<DataArrayDouble *>(coordsY);
508 _z_array=const_cast<DataArrayDouble *>(coordsZ);
514 void MEDCouplingCMesh::getBoundingBox(double *bbox) const
516 int dim=getSpaceDimension();
518 for (int idim=0; idim<dim; idim++)
520 const DataArrayDouble *c=getCoordsAt(idim);
523 const double *coords=c->getConstPointer();
524 int nb=c->getNbOfElems();
526 bbox[2*j+1]=coords[nb-1];
533 * Returns a new MEDCouplingFieldDouble containing volumes of cells constituting \a this
535 * For 1D cells, the returned field contains lengths.<br>
536 * For 2D cells, the returned field contains areas.<br>
537 * For 3D cells, the returned field contains volumes.
538 * \param [in] isAbs - a not used parameter.
539 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on cells
540 * and one time . The caller is to delete this field using decrRef() as it is no
543 MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureField(bool isAbs) const
545 std::string name="MeasureOfMesh_";
547 int nbelem=getNumberOfCells();
548 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
549 field->setName(name.c_str());
550 DataArrayDouble* array=DataArrayDouble::New();
551 array->alloc(nbelem,1);
552 double *area_vol=array->getPointer();
553 field->setArray(array) ;
555 field->setMesh(const_cast<MEDCouplingCMesh *>(this));
556 field->synchronizeTimeWithMesh();
558 getSplitCellValues(tmp);
559 int dim=getSpaceDimension();
560 const double **thisArr=new const double *[dim];
561 const DataArrayDouble *thisArr2[3]={_x_array,_y_array,_z_array};
562 for(int i=0;i<dim;i++)
563 thisArr[i]=thisArr2[i]->getConstPointer();
564 for(int icell=0;icell<nbelem;icell++)
567 GetPosFromId(icell,dim,tmp,tmp2);
569 for(int i=0;i<dim;i++)
570 area_vol[icell]*=thisArr[i][tmp2[i]+1]-thisArr[i][tmp2[i]];
577 * not implemented yet !
579 MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureFieldOnNode(bool isAbs) const
581 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getMeasureFieldOnNode : not implemented yet !");
585 int MEDCouplingCMesh::getCellContainingPoint(const double *pos, double eps) const
587 int dim=getSpaceDimension();
590 for(int i=0;i<dim;i++)
592 const double *d=getCoordsAt(i)->getConstPointer();
593 int nbOfNodes=getCoordsAt(i)->getNbOfElems();
595 const double *w=std::find_if(d,d+nbOfNodes,std::bind2nd(std::greater_equal<double>(),ref));
596 int w2=(int)std::distance(d,w);
615 void MEDCouplingCMesh::rotate(const double *center, const double *vector, double angle)
617 throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to StructuredMesh to apply it !");
621 * Translates all nodes of \a this mesh by a given vector. Actually, it adds each
622 * component of the \a vector to all node coordinates of a corresponding axis.
623 * \param [in] vector - the translation vector whose size must be not less than \a
624 * this->getSpaceDimension().
626 void MEDCouplingCMesh::translate(const double *vector)
629 std::transform(_x_array->getConstPointer(),_x_array->getConstPointer()+_x_array->getNbOfElems(),
630 _x_array->getPointer(),std::bind2nd(std::plus<double>(),vector[0]));
632 std::transform(_y_array->getConstPointer(),_y_array->getConstPointer()+_y_array->getNbOfElems(),
633 _y_array->getPointer(),std::bind2nd(std::plus<double>(),vector[1]));
635 std::transform(_z_array->getConstPointer(),_z_array->getConstPointer()+_z_array->getNbOfElems(),
636 _z_array->getPointer(),std::bind2nd(std::plus<double>(),vector[2]));
640 * Applies scaling transformation to all nodes of \a this mesh.
641 * \param [in] point - coordinates of a scaling center. This array is to be of
642 * size \a this->getSpaceDimension() at least.
643 * \param [in] factor - a scale factor.
645 void MEDCouplingCMesh::scale(const double *point, double factor)
649 DataArrayDouble *c=getCoordsAt(i);
652 double *coords=c->getPointer();
653 int lgth=c->getNbOfElems();
654 std::transform(coords,coords+lgth,coords,std::bind2nd(std::minus<double>(),point[i]));
655 std::transform(coords,coords+lgth,coords,std::bind2nd(std::multiplies<double>(),factor));
656 std::transform(coords,coords+lgth,coords,std::bind2nd(std::plus<double>(),point[i]));
663 MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
665 //not implemented yet !
670 * Returns a new DataArrayDouble holding coordinates of all nodes of \a this mesh.
671 * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a
672 * this->getNumberOfNodes() tuples per \a this->getSpaceDimension()
673 * components. The caller is to delete this array using decrRef() as it is
676 DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const
678 DataArrayDouble *ret=DataArrayDouble::New();
679 int spaceDim=getSpaceDimension();
680 int nbNodes=getNumberOfNodes();
681 ret->alloc(nbNodes,spaceDim);
682 double *pt=ret->getPointer();
684 getSplitNodeValues(tmp);
685 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
686 const double *tabsPtr[3];
687 for(int j=0;j<spaceDim;j++)
689 tabsPtr[j]=tabs[j]->getConstPointer();
690 ret->setInfoOnComponent(j,tabs[j]->getInfoOnComponent(0).c_str());
693 for(int i=0;i<nbNodes;i++)
695 GetPosFromId(i,spaceDim,tmp,tmp2);
696 for(int j=0;j<spaceDim;j++)
697 pt[i*spaceDim+j]=tabsPtr[j][tmp2[j]];
703 * Returns a new DataArrayDouble holding barycenters of all cells. The barycenter is
704 * computed by averaging coordinates of cell nodes.
705 * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a
706 * this->getNumberOfCells() tuples per \a this->getSpaceDimension()
707 * components. The caller is to delete this array using decrRef() as it is
710 DataArrayDouble *MEDCouplingCMesh::getBarycenterAndOwner() const
712 DataArrayDouble *ret=DataArrayDouble::New();
713 int spaceDim=getSpaceDimension();
714 int nbCells=getNumberOfCells();
715 ret->alloc(nbCells,spaceDim);
716 double *pt=ret->getPointer();
718 getSplitCellValues(tmp);
719 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
720 std::vector<double> tabsPtr[3];
721 for(int j=0;j<spaceDim;j++)
723 int sz=tabs[j]->getNbOfElems()-1;
724 ret->setInfoOnComponent(j,tabs[j]->getInfoOnComponent(0).c_str());
725 const double *srcPtr=tabs[j]->getConstPointer();
726 tabsPtr[j].insert(tabsPtr[j].end(),srcPtr,srcPtr+sz);
727 std::transform(tabsPtr[j].begin(),tabsPtr[j].end(),srcPtr+1,tabsPtr[j].begin(),std::plus<double>());
728 std::transform(tabsPtr[j].begin(),tabsPtr[j].end(),tabsPtr[j].begin(),std::bind2nd(std::multiplies<double>(),0.5));
731 for(int i=0;i<nbCells;i++)
733 GetPosFromId(i,spaceDim,tmp,tmp2);
734 for(int j=0;j<spaceDim;j++)
735 pt[i*spaceDim+j]=tabsPtr[j][tmp2[j]];
740 DataArrayDouble *MEDCouplingCMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
742 return MEDCouplingCMesh::getBarycenterAndOwner();
745 void MEDCouplingCMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
747 throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for CMesh !");
750 void MEDCouplingCMesh::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
753 double time=getTime(it,order);
756 littleStrings.clear();
757 littleStrings.push_back(getName());
758 littleStrings.push_back(getDescription());
759 littleStrings.push_back(getTimeUnit());
760 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
767 val=thisArr[i]->getNumberOfTuples();
768 st=thisArr[i]->getInfoOnComponent(0);
770 tinyInfo.push_back(val);
771 littleStrings.push_back(st);
773 tinyInfo.push_back(it);
774 tinyInfo.push_back(order);
775 tinyInfoD.push_back(time);
778 void MEDCouplingCMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
788 void MEDCouplingCMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
790 a1=DataArrayInt::New();
792 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
797 sz+=thisArr[i]->getNumberOfTuples();
799 a2=DataArrayDouble::New();
801 double *a2Ptr=a2->getPointer();
804 a2Ptr=std::copy(thisArr[i]->getConstPointer(),thisArr[i]->getConstPointer()+thisArr[i]->getNumberOfTuples(),a2Ptr);
807 void MEDCouplingCMesh::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
808 const std::vector<std::string>& littleStrings)
810 setName(littleStrings[0].c_str());
811 setDescription(littleStrings[1].c_str());
812 setTimeUnit(littleStrings[2].c_str());
813 DataArrayDouble **thisArr[3]={&_x_array,&_y_array,&_z_array};
814 const double *data=a2->getConstPointer();
819 (*(thisArr[i]))=DataArrayDouble::New();
820 (*(thisArr[i]))->alloc(tinyInfo[i],1);
821 (*(thisArr[i]))->setInfoOnComponent(0,littleStrings[i+3].c_str());
822 std::copy(data,data+tinyInfo[i],(*(thisArr[i]))->getPointer());
826 setTime(tinyInfoD[0],tinyInfo[3],tinyInfo[4]);
829 void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
831 std::ostringstream extent;
832 DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
836 { extent << "0 " << thisArr[i]->getNumberOfTuples()-1 << " "; }
838 { extent << "0 0 "; }
840 ofs << " <" << getVTKDataSetType() << " WholeExtent=\"" << extent.str() << "\">\n";
841 ofs << " <Piece Extent=\"" << extent.str() << "\">\n";
842 ofs << " <PointData>\n" << pointData << std::endl;
843 ofs << " </PointData>\n";
844 ofs << " <CellData>\n" << cellData << std::endl;
845 ofs << " </CellData>\n";
846 ofs << " <Coordinates>\n";
850 thisArr[i]->writeVTK(ofs,8,"Array");
853 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=DataArrayDouble::New(); coo->alloc(1,1);
855 coo->writeVTK(ofs,8,"Array");
858 ofs << " </Coordinates>\n";
859 ofs << " </Piece>\n";
860 ofs << " </" << getVTKDataSetType() << ">\n";
863 void MEDCouplingCMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
865 stream << "MEDCouplingCMesh C++ instance at " << this << ". Name : \"" << getName() << "\".";
866 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
867 std::ostringstream stream2[3];
869 int nbOfCells=1,nbOfNodes=1;
872 isDef[i]=thisArr[i]!=0;
876 stream2[i] << tmp << " positions array ";
877 if(!thisArr[i]->isAllocated())
878 stream2[i] << "set but not allocated.";
881 int nbCompo=thisArr[i]->getNumberOfComponents();
884 int nbTuples=thisArr[i]->getNumberOfTuples();
886 { stream2[i] << "set and allocated - WARNING number of elements < 1 !"; nbOfCells=-1; nbOfNodes=-1; }
889 stream2[i] << "(length=" << nbTuples << ")" << ": ";
890 thisArr[i]->reprQuickOverviewData(stream2[i],200);
892 { nbOfNodes*=nbTuples; nbOfCells*=nbTuples-1; }
896 { stream2[i] << "set and allocated - WARNING number of components != 1 !"; nbOfCells=-1; nbOfNodes=-1; }
900 if(!isDef[0] && !isDef[1] && !isDef[2])
901 { stream << " No arrays set !"; return; }
903 { stream << std::endl << "Number of cells : " << nbOfCells << ". Number of nodes : " << nbOfNodes << "."; }
907 stream << std::endl << stream2[i].str();
912 std::string MEDCouplingCMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
914 return std::string("RectilinearGrid");