1 // Copyright (C) 2007-2012 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
20 #include "MEDCouplingCMesh.hxx"
21 #include "MEDCouplingUMesh.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):MEDCouplingMesh(other)
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);
110 * This method copyies all tiny strings from other (name and components name).
111 * @throw if other and this have not same mesh type.
113 void MEDCouplingCMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception)
115 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
117 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::copyTinyStringsFrom : meshes have not same type !");
118 MEDCouplingMesh::copyTinyStringsFrom(other);
119 if(_x_array && otherC->_x_array)
120 _x_array->copyStringInfoFrom(*otherC->_x_array);
121 if(_y_array && otherC->_y_array)
122 _y_array->copyStringInfoFrom(*otherC->_y_array);
123 if(_z_array && otherC->_z_array)
124 _z_array->copyStringInfoFrom(*otherC->_z_array);
127 bool MEDCouplingCMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
130 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::isEqualIfNotWhy : input other pointer is null !");
131 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
134 reason="mesh given in input is not castable in MEDCouplingCMesh !";
137 if(!MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason))
139 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
140 const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array};
141 std::ostringstream oss; oss.precision(15);
144 if((thisArr[i]!=0 && otherArr[i]==0) || (thisArr[i]==0 && otherArr[i]!=0))
146 oss << "Only one CMesh between the two this and other has its coordinates of rank" << i << " defined !";
151 if(!thisArr[i]->isEqualIfNotWhy(*otherArr[i],prec,reason))
153 oss << "Coordinates DataArrayDouble of rank #" << i << " differ :";
154 reason.insert(0,oss.str());
161 bool MEDCouplingCMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
163 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
166 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
167 const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array};
170 if((thisArr[i]!=0 && otherArr[i]==0) || (thisArr[i]==0 && otherArr[i]!=0))
173 if(!thisArr[i]->isEqualWithoutConsideringStr(*otherArr[i],prec))
179 void MEDCouplingCMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
180 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
182 if(!isEqualWithoutConsideringStr(other,prec))
183 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalWith : Meshes are not the same !");
187 * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCMesh instance too).
188 * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, 'this' and 'other' are the same !
190 void MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
191 DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
193 const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
195 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !");
198 void MEDCouplingCMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
200 const char msg0[]="Invalid ";
201 const char msg1[]=" array ! Must contain more than 1 element.";
202 const char msg2[]=" array ! Must be with only one component.";
205 if(_x_array->getNbOfElems()<2)
207 std::ostringstream os; os << msg0 << 'X' << msg1;
208 throw INTERP_KERNEL::Exception(os.str().c_str());
210 if(_x_array->getNumberOfComponents()!=1)
212 std::ostringstream os; os << msg0 << 'X' << msg2;
213 throw INTERP_KERNEL::Exception(os.str().c_str());
218 if(_y_array->getNbOfElems()<2)
220 std::ostringstream os; os << msg0 << 'Y' << msg1;
221 throw INTERP_KERNEL::Exception(os.str().c_str());
223 if(_y_array->getNumberOfComponents()!=1)
225 std::ostringstream os; os << msg0 << 'Y' << msg2;
226 throw INTERP_KERNEL::Exception(os.str().c_str());
232 if(_z_array->getNbOfElems()<2)
234 std::ostringstream os; os << msg0 << 'Z' << msg1;
235 throw INTERP_KERNEL::Exception(os.str().c_str());
237 if(_z_array->getNumberOfComponents()!=1)
239 std::ostringstream os; os << msg0 << 'Z' << msg2;
240 throw INTERP_KERNEL::Exception(os.str().c_str());
245 void MEDCouplingCMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
249 _x_array->checkMonotonic(true, eps);
251 _y_array->checkMonotonic(true, eps);
253 _z_array->checkMonotonic(true, eps);
256 void MEDCouplingCMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
258 checkCoherency1(eps);
261 int MEDCouplingCMesh::getNumberOfCells() const
265 ret*=_x_array->getNbOfElems()-1;
267 ret*=_y_array->getNbOfElems()-1;
269 ret*=_z_array->getNbOfElems()-1;
273 int MEDCouplingCMesh::getNumberOfNodes() const
277 ret*=_x_array->getNbOfElems();
279 ret*=_y_array->getNbOfElems();
281 ret*=_z_array->getNbOfElems();
285 void MEDCouplingCMesh::getSplitCellValues(int *res) const
287 int spaceDim=getSpaceDimension();
288 for(int l=0;l<spaceDim;l++)
291 for(int p=0;p<spaceDim-l-1;p++)
292 val*=getCoordsAt(p)->getNbOfElems()-1;
293 res[spaceDim-l-1]=val;
297 void MEDCouplingCMesh::getSplitNodeValues(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();
305 res[spaceDim-l-1]=val;
309 int MEDCouplingCMesh::getCellIdFromPos(int i, int j, int k) const
313 int spaceDim=getSpaceDimension();
314 getSplitCellValues(tmp2);
315 std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies<int>());
316 return std::accumulate(tmp,tmp+spaceDim,0);
319 int MEDCouplingCMesh::getNodeIdFromPos(int i, int j, int k) const
323 int spaceDim=getSpaceDimension();
324 getSplitNodeValues(tmp2);
325 std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies<int>());
326 return std::accumulate(tmp,tmp+spaceDim,0);
329 void MEDCouplingCMesh::GetPosFromId(int nodeId, int spaceDim, const int *split, int *res)
332 for(int i=spaceDim-1;i>=0;i--)
334 int pos=work/split[i];
340 int MEDCouplingCMesh::getSpaceDimension() const
352 int MEDCouplingCMesh::getMeshDimension() const
354 return getSpaceDimension();
357 INTERP_KERNEL::NormalizedCellType MEDCouplingCMesh::getTypeOfCell(int cellId) const
359 switch(getMeshDimension())
362 return INTERP_KERNEL::NORM_HEXA8;
364 return INTERP_KERNEL::NORM_QUAD4;
366 return INTERP_KERNEL::NORM_SEG2;
368 throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingCMesh::getTypeOfCell !");
372 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingCMesh::getAllGeoTypes() const
374 INTERP_KERNEL::NormalizedCellType ret;
375 switch(getMeshDimension())
378 ret=INTERP_KERNEL::NORM_HEXA8;
381 ret=INTERP_KERNEL::NORM_QUAD4;
384 ret=INTERP_KERNEL::NORM_SEG2;
387 throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingCMesh::getAllGeoTypes !");
389 std::set<INTERP_KERNEL::NormalizedCellType> ret2;
394 int MEDCouplingCMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
396 int ret=getNumberOfCells();
397 int dim=getMeshDimension();
400 case INTERP_KERNEL::NORM_HEXA8:
403 case INTERP_KERNEL::NORM_QUAD4:
406 case INTERP_KERNEL::NORM_SEG2:
410 throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingCMesh::getTypeOfCell !");
415 void MEDCouplingCMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
417 int spaceDim=getSpaceDimension();
418 int tmpCell[3],tmpNode[3];
419 getSplitCellValues(tmpCell);
420 getSplitNodeValues(tmpNode);
422 GetPosFromId(cellId,spaceDim,tmpCell,tmp2);
426 conn.push_back(tmp2[0]); conn.push_back(tmp2[0]+1);
429 conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1);
430 conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]+1); conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]);
433 conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]);
434 conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]);
435 conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]);
436 conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]);
439 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getNodeIdsOfCell : big problem spacedim must be in 1,2 or 3 !");
443 void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const throw(INTERP_KERNEL::Exception)
446 int spaceDim=getSpaceDimension();
447 getSplitNodeValues(tmp);
448 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
450 GetPosFromId(nodeId,spaceDim,tmp,tmp2);
451 for(int j=0;j<spaceDim;j++)
453 coo.push_back(tabs[j]->getConstPointer()[tmp2[j]]);
456 std::string MEDCouplingCMesh::simpleRepr() const
458 std::ostringstream ret;
459 ret << "Cartesian mesh with name : \"" << getName() << "\"\n";
460 ret << "Description of mesh : \"" << getDescription() << "\"\n";
462 double tt=getTime(tmpp1,tmpp2);
463 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
464 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
465 ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n";
468 ret << "X Array :\n";
469 _x_array->reprZipWithoutNameStream(ret);
473 ret << "Y Array :\n";
474 _y_array->reprZipWithoutNameStream(ret);
478 ret << "Z Array :\n";
479 _z_array->reprZipWithoutNameStream(ret);
484 std::string MEDCouplingCMesh::advancedRepr() const
489 const DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception)
500 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
504 DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) throw(INTERP_KERNEL::Exception)
515 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
519 void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception)
521 DataArrayDouble **thisArr[3]={&_x_array,&_y_array,&_z_array};
523 throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2.");
524 if(arr!=*(thisArr[i]))
527 (*(thisArr[i]))->decrRef();
528 (*(thisArr[i]))=const_cast<DataArrayDouble *>(arr);
530 (*(thisArr[i]))->incrRef();
535 void MEDCouplingCMesh::setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY, const DataArrayDouble *coordsZ)
539 _x_array=const_cast<DataArrayDouble *>(coordsX);
544 _y_array=const_cast<DataArrayDouble *>(coordsY);
549 _z_array=const_cast<DataArrayDouble *>(coordsZ);
556 * See MEDCouplingUMesh::getDistributionOfTypes for more information
558 std::vector<int> MEDCouplingCMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
560 //only one type of cell
561 std::vector<int> ret(3);
562 ret[0]=getTypeOfCell(0);
563 ret[1]=getNumberOfCells();
564 ret[2]=0; //ret[3*k+2]==0 because it has no sense here
569 * See MEDCouplingUMesh::checkTypeConsistencyAndContig for more information
571 DataArrayInt *MEDCouplingCMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
574 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkTypeConsistencyAndContig : code is empty, should not !");
575 std::size_t sz=code.size();
577 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkTypeConsistencyAndContig : code should be of size 3 exactly !");
579 int nbCells=getNumberOfCellsWithType((INTERP_KERNEL::NormalizedCellType)code[0]);
585 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkTypeConsistencyAndContig : number of cells mismatch !");
590 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkTypeConsistencyAndContig : code[2]<-1 mismatch !");
591 if(code[2]>=(int)idsPerType.size())
592 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkTypeConsistencyAndContig : code[2]>size idsPerType !");
593 return idsPerType[code[2]]->deepCpy();
598 * See MEDCouplingUMesh::splitProfilePerType for more information
600 void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
602 int nbCells=getNumberOfCells();
604 code[0]=(int)getTypeOfCell(0);
607 idsInPflPerType.push_back(profile->deepCpy());
608 idsPerType.push_back(profile->deepCpy());
611 MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
613 int spaceDim=getSpaceDimension();
614 MEDCouplingUMesh *ret=MEDCouplingUMesh::New(getName(),spaceDim);
615 DataArrayDouble *coords=getCoordinatesAndOwner();
616 ret->setCoords(coords);
621 fill1DUnstructuredMesh(ret);
624 fill2DUnstructuredMesh(ret);
627 fill3DUnstructuredMesh(ret);
630 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::buildUnstructured : big problem spacedim must be in 1,2 or 3 !");
635 MEDCouplingMesh *MEDCouplingCMesh::buildPart(const int *start, const int *end) const
637 MEDCouplingUMesh *um=buildUnstructured();
638 MEDCouplingMesh *ret=um->buildPart(start,end);
643 MEDCouplingMesh *MEDCouplingCMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
645 MEDCouplingUMesh *um=buildUnstructured();
646 MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
651 DataArrayInt *MEDCouplingCMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
653 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::simplexize : not available for Cartesian mesh !");
656 void MEDCouplingCMesh::getBoundingBox(double *bbox) const
658 int dim=getSpaceDimension();
660 for (int idim=0; idim<dim; idim++)
662 const DataArrayDouble *c=getCoordsAt(idim);
665 const double *coords=c->getConstPointer();
666 int nb=c->getNbOfElems();
668 bbox[2*j+1]=coords[nb-1];
674 MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureField(bool isAbs) const
676 std::string name="MeasureOfMesh_";
678 int nbelem=getNumberOfCells();
679 MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS);
680 field->setName(name.c_str());
681 DataArrayDouble* array=DataArrayDouble::New();
682 array->alloc(nbelem,1);
683 double *area_vol=array->getPointer();
684 field->setArray(array) ;
686 field->setMesh(const_cast<MEDCouplingCMesh *>(this));
688 getSplitCellValues(tmp);
689 int dim=getSpaceDimension();
690 const double **thisArr=new const double *[dim];
691 const DataArrayDouble *thisArr2[3]={_x_array,_y_array,_z_array};
692 for(int i=0;i<dim;i++)
693 thisArr[i]=thisArr2[i]->getConstPointer();
694 for(int icell=0;icell<nbelem;icell++)
697 GetPosFromId(icell,dim,tmp,tmp2);
699 for(int i=0;i<dim;i++)
700 area_vol[icell]*=thisArr[i][tmp2[i]+1]-thisArr[i][tmp2[i]];
707 * not implemented yet !
709 MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureFieldOnNode(bool isAbs) const
711 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getMeasureFieldOnNode : not implemented yet !");
715 MEDCouplingFieldDouble *MEDCouplingCMesh::buildOrthogonalField() const
717 if(getMeshDimension()!=2)
718 throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
719 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
720 DataArrayDouble *array=DataArrayDouble::New();
721 int nbOfCells=getNumberOfCells();
722 array->alloc(nbOfCells,3);
723 double *vals=array->getPointer();
724 for(int i=0;i<nbOfCells;i++)
725 { vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
726 ret->setArray(array);
732 int MEDCouplingCMesh::getCellContainingPoint(const double *pos, double eps) const
734 int dim=getSpaceDimension();
737 for(int i=0;i<dim;i++)
739 const double *d=getCoordsAt(i)->getConstPointer();
740 int nbOfNodes=getCoordsAt(i)->getNbOfElems();
742 const double *w=std::find_if(d,d+nbOfNodes,std::bind2nd(std::greater_equal<double>(),ref));
743 int w2=(int)std::distance(d,w);
762 void MEDCouplingCMesh::rotate(const double *center, const double *vector, double angle)
764 throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to StructuredMesh to apply it !");
767 void MEDCouplingCMesh::translate(const double *vector)
770 std::transform(_x_array->getConstPointer(),_x_array->getConstPointer()+_x_array->getNbOfElems(),
771 _x_array->getPointer(),std::bind2nd(std::plus<double>(),vector[0]));
773 std::transform(_y_array->getConstPointer(),_y_array->getConstPointer()+_y_array->getNbOfElems(),
774 _y_array->getPointer(),std::bind2nd(std::plus<double>(),vector[1]));
776 std::transform(_z_array->getConstPointer(),_z_array->getConstPointer()+_z_array->getNbOfElems(),
777 _z_array->getPointer(),std::bind2nd(std::plus<double>(),vector[2]));
780 void MEDCouplingCMesh::scale(const double *point, double factor)
784 DataArrayDouble *c=getCoordsAt(i);
787 double *coords=c->getPointer();
788 int lgth=c->getNbOfElems();
789 std::transform(coords,coords+lgth,coords,std::bind2nd(std::minus<double>(),point[i]));
790 std::transform(coords,coords+lgth,coords,std::bind2nd(std::multiplies<double>(),factor));
791 std::transform(coords,coords+lgth,coords,std::bind2nd(std::plus<double>(),point[i]));
798 MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
800 //not implemented yet !
804 DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const
806 DataArrayDouble *ret=DataArrayDouble::New();
807 int spaceDim=getSpaceDimension();
808 int nbNodes=getNumberOfNodes();
809 ret->alloc(nbNodes,spaceDim);
810 double *pt=ret->getPointer();
812 getSplitNodeValues(tmp);
813 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
814 const double *tabsPtr[3];
815 for(int j=0;j<spaceDim;j++)
817 tabsPtr[j]=tabs[j]->getConstPointer();
818 ret->setInfoOnComponent(j,tabs[j]->getInfoOnComponent(0).c_str());
821 for(int i=0;i<nbNodes;i++)
823 GetPosFromId(i,spaceDim,tmp,tmp2);
824 for(int j=0;j<spaceDim;j++)
825 pt[i*spaceDim+j]=tabsPtr[j][tmp2[j]];
830 DataArrayDouble *MEDCouplingCMesh::getBarycenterAndOwner() const
832 DataArrayDouble *ret=DataArrayDouble::New();
833 int spaceDim=getSpaceDimension();
834 int nbCells=getNumberOfCells();
835 ret->alloc(nbCells,spaceDim);
836 double *pt=ret->getPointer();
838 getSplitCellValues(tmp);
839 const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
840 std::vector<double> tabsPtr[3];
841 for(int j=0;j<spaceDim;j++)
843 int sz=tabs[j]->getNbOfElems()-1;
844 ret->setInfoOnComponent(j,tabs[j]->getInfoOnComponent(0).c_str());
845 const double *srcPtr=tabs[j]->getConstPointer();
846 tabsPtr[j].insert(tabsPtr[j].end(),srcPtr,srcPtr+sz);
847 std::transform(tabsPtr[j].begin(),tabsPtr[j].end(),srcPtr+1,tabsPtr[j].begin(),std::plus<double>());
848 std::transform(tabsPtr[j].begin(),tabsPtr[j].end(),tabsPtr[j].begin(),std::bind2nd(std::multiplies<double>(),0.5));
851 for(int i=0;i<nbCells;i++)
853 GetPosFromId(i,spaceDim,tmp,tmp2);
854 for(int j=0;j<spaceDim;j++)
855 pt[i*spaceDim+j]=tabsPtr[j][tmp2[j]];
860 void MEDCouplingCMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
862 throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for CMesh !");
865 void MEDCouplingCMesh::fill1DUnstructuredMesh(MEDCouplingUMesh *m) const
867 const DataArrayDouble *c=getCoordsAt(0);
868 int nbOfCells=c->getNbOfElems()-1;
869 DataArrayInt *connI=DataArrayInt::New();
870 connI->alloc(nbOfCells+1,1);
871 int *ci=connI->getPointer();
872 DataArrayInt *conn=DataArrayInt::New();
873 conn->alloc(3*nbOfCells,1);
875 int *cp=conn->getPointer();
876 for(int i=0;i<nbOfCells;i++)
878 cp[3*i]=(int)INTERP_KERNEL::NORM_SEG2;
883 m->setConnectivity(conn,connI,true);
888 void MEDCouplingCMesh::fill2DUnstructuredMesh(MEDCouplingUMesh *m) const
890 const DataArrayDouble *c1=getCoordsAt(0);
891 const DataArrayDouble *c2=getCoordsAt(1);
892 int n1=c1->getNbOfElems()-1;
893 int n2=c2->getNbOfElems()-1;
894 DataArrayInt *connI=DataArrayInt::New();
895 connI->alloc(n1*n2+1,1);
896 int *ci=connI->getPointer();
897 DataArrayInt *conn=DataArrayInt::New();
898 conn->alloc(5*n1*n2,1);
900 int *cp=conn->getPointer();
902 for(int j=0;j<n2;j++)
903 for(int i=0;i<n1;i++,pos++)
905 cp[5*pos]=(int)INTERP_KERNEL::NORM_QUAD4;
906 cp[5*pos+1]=i+1+j*(n1+1);
907 cp[5*pos+2]=i+j*(n1+1);
908 cp[5*pos+3]=i+(j+1)*(n1+1);
909 cp[5*pos+4]=i+1+(j+1)*(n1+1);
912 m->setConnectivity(conn,connI,true);
917 void MEDCouplingCMesh::fill3DUnstructuredMesh(MEDCouplingUMesh *m) const
919 const DataArrayDouble *c1=getCoordsAt(0);
920 const DataArrayDouble *c2=getCoordsAt(1);
921 const DataArrayDouble *c3=getCoordsAt(2);
922 int n1=c1->getNbOfElems()-1;
923 int n2=c2->getNbOfElems()-1;
924 int n3=c3->getNbOfElems()-1;
925 DataArrayInt *connI=DataArrayInt::New();
926 connI->alloc(n1*n2*n3+1,1);
927 int *ci=connI->getPointer();
928 DataArrayInt *conn=DataArrayInt::New();
929 conn->alloc(9*n1*n2*n3,1);
931 int *cp=conn->getPointer();
933 for(int k=0;k<n3;k++)
934 for(int j=0;j<n2;j++)
935 for(int i=0;i<n1;i++,pos++)
937 cp[9*pos]=(int)INTERP_KERNEL::NORM_HEXA8;
938 int tmp=(n1+1)*(n2+1);
939 cp[9*pos+1]=i+1+j*(n1+1)+k*tmp;
940 cp[9*pos+2]=i+j*(n1+1)+k*tmp;
941 cp[9*pos+3]=i+(j+1)*(n1+1)+k*tmp;
942 cp[9*pos+4]=i+1+(j+1)*(n1+1)+k*tmp;
943 cp[9*pos+5]=i+1+j*(n1+1)+(k+1)*tmp;
944 cp[9*pos+6]=i+j*(n1+1)+(k+1)*tmp;
945 cp[9*pos+7]=i+(j+1)*(n1+1)+(k+1)*tmp;
946 cp[9*pos+8]=i+1+(j+1)*(n1+1)+(k+1)*tmp;
949 m->setConnectivity(conn,connI,true);
954 void MEDCouplingCMesh::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
957 double time=getTime(it,order);
960 littleStrings.clear();
961 littleStrings.push_back(getName());
962 littleStrings.push_back(getDescription());
963 littleStrings.push_back(getTimeUnit());
964 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
971 val=thisArr[i]->getNumberOfTuples();
972 st=thisArr[i]->getInfoOnComponent(0);
974 tinyInfo.push_back(val);
975 littleStrings.push_back(st);
977 tinyInfo.push_back(it);
978 tinyInfo.push_back(order);
979 tinyInfoD.push_back(time);
982 void MEDCouplingCMesh::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
992 void MEDCouplingCMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
994 a1=DataArrayInt::New();
996 const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
1001 sz+=thisArr[i]->getNumberOfTuples();
1003 a2=DataArrayDouble::New();
1005 double *a2Ptr=a2->getPointer();
1006 for(int i=0;i<3;i++)
1008 a2Ptr=std::copy(thisArr[i]->getConstPointer(),thisArr[i]->getConstPointer()+thisArr[i]->getNumberOfTuples(),a2Ptr);
1011 void MEDCouplingCMesh::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
1012 const std::vector<std::string>& littleStrings)
1014 setName(littleStrings[0].c_str());
1015 setDescription(littleStrings[1].c_str());
1016 setTimeUnit(littleStrings[2].c_str());
1017 DataArrayDouble **thisArr[3]={&_x_array,&_y_array,&_z_array};
1018 const double *data=a2->getConstPointer();
1019 for(int i=0;i<3;i++)
1023 (*(thisArr[i]))=DataArrayDouble::New();
1024 (*(thisArr[i]))->alloc(tinyInfo[i],1);
1025 (*(thisArr[i]))->setInfoOnComponent(0,littleStrings[i+3].c_str());
1026 std::copy(data,data+tinyInfo[i],(*(thisArr[i]))->getPointer());
1030 setTime(tinyInfoD[0],tinyInfo[3],tinyInfo[4]);
1033 void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
1035 throw INTERP_KERNEL::Exception("MEDCouplingCMesh::writeVTKLL : not implemented yet !");
1038 std::string MEDCouplingCMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
1040 return std::string("RectilinearGrid");