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 "MEDCouplingStructuredMesh.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCoupling1GTUMesh.hxx"
25 #include "MEDCouplingUMesh.hxx"
29 using namespace ParaMEDMEM;
31 MEDCouplingStructuredMesh::MEDCouplingStructuredMesh()
35 MEDCouplingStructuredMesh::MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCopy):MEDCouplingMesh(other)
39 MEDCouplingStructuredMesh::~MEDCouplingStructuredMesh()
43 std::size_t MEDCouplingStructuredMesh::getHeapMemorySizeWithoutChildren() const
45 return MEDCouplingMesh::getHeapMemorySizeWithoutChildren();
48 void MEDCouplingStructuredMesh::copyTinyStringsFrom(const MEDCouplingMesh *other)
50 MEDCouplingMesh::copyTinyStringsFrom(other);
53 bool MEDCouplingStructuredMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const
55 return MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason);
58 INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::getTypeOfCell(int cellId) const
60 return GetGeoTypeGivenMeshDimension(getMeshDimension());
63 INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(int meshDim)
68 return INTERP_KERNEL::NORM_HEXA8;
70 return INTERP_KERNEL::NORM_QUAD4;
72 return INTERP_KERNEL::NORM_SEG2;
74 return INTERP_KERNEL::NORM_POINT1;
76 throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension !");
80 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingStructuredMesh::getAllGeoTypes() const
82 std::set<INTERP_KERNEL::NormalizedCellType> ret2;
83 ret2.insert(getTypeOfCell(0));
87 int MEDCouplingStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
89 int ret=getNumberOfCells();
90 if(type==getTypeOfCell(0))
92 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
93 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getNumberOfCellsWithType : no specified type ! Type available is " << cm.getRepr() << " !";
94 throw INTERP_KERNEL::Exception(oss.str().c_str());
97 DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
99 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
100 if(getTypeOfCell(0)==type)
102 ret->alloc(getNumberOfCells(),1);
110 DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const
112 int nbCells=getNumberOfCells();
113 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
114 ret->alloc(nbCells,1);
115 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
116 ret->fillWithValue((int)cm.getNumberOfNodes());
120 DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const
122 int nbCells=getNumberOfCells();
123 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
124 ret->alloc(nbCells,1);
125 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
126 ret->fillWithValue((int)cm.getNumberOfSons());
131 * This method computes effective number of nodes per cell. That is to say nodes appearing several times in nodal connectivity of a cell,
132 * will be counted only once here whereas it will be counted several times in MEDCouplingMesh::computeNbOfNodesPerCell method.
133 * Here for structured mesh it returns exactly as MEDCouplingStructuredMesh::computeNbOfNodesPerCell does.
135 * \return DataArrayInt * - new object to be deallocated by the caller.
137 DataArrayInt *MEDCouplingStructuredMesh::computeEffectiveNbOfNodesPerCell() const
139 return computeNbOfNodesPerCell();
142 void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
144 int meshDim=getMeshDimension();
145 int tmpCell[3],tmpNode[3];
146 getSplitCellValues(tmpCell);
147 getSplitNodeValues(tmpNode);
149 GetPosFromId(cellId,meshDim,tmpCell,tmp2);
153 conn.push_back(tmp2[0]); conn.push_back(tmp2[0]+1);
156 conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1);
157 conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]);
160 conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]);
161 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]);
162 conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]);
163 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]);
166 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::getNodeIdsOfCell : big problem spacedim must be in 1,2 or 3 !");
171 * This method returns the mesh dimension of \a this. It can be different from space dimension in case of a not null dimension contains only one node.
173 int MEDCouplingStructuredMesh::getMeshDimension() const
175 std::vector<int> ngs(getNodeGridStructure());
177 for(std::vector<int>::const_iterator it=ngs.begin();it!=ngs.end();it++,pos++)
181 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getMeshDimension : At pos #" << pos << " number of nodes is " << *it << " ! Must be > 0 !";
182 throw INTERP_KERNEL::Exception(oss.str().c_str());
191 * This method returns the space dimension by only considering the node grid structure.
192 * For cartesian mesh the returned value is equal to those returned by getSpaceDimension.
193 * But for curvelinear is could be different !
195 int MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct() const
197 std::vector<int> nodeStr(getNodeGridStructure());
199 for(std::vector<int>::const_iterator it=nodeStr.begin();it!=nodeStr.end();it++,pos++)
204 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct : At pos #" << pos << " value of node grid structure is " << *it << " ! must be >=1 !";
205 throw INTERP_KERNEL::Exception(oss.str().c_str());
212 void MEDCouplingStructuredMesh::getSplitCellValues(int *res) const
214 std::vector<int> strct(getCellGridStructure());
215 std::vector<int> ret(MEDCouplingStructuredMesh::GetSplitVectFromStruct(strct));
216 std::copy(ret.begin(),ret.end(),res);
219 void MEDCouplingStructuredMesh::getSplitNodeValues(int *res) const
221 std::vector<int> strct(getNodeGridStructure());
222 std::vector<int> ret(MEDCouplingStructuredMesh::GetSplitVectFromStruct(strct));
223 std::copy(ret.begin(),ret.end(),res);
227 * This method returns the number of cells of unstructured sub level mesh, without building it.
229 int MEDCouplingStructuredMesh::getNumberOfCellsOfSubLevelMesh() const
231 std::vector<int> cgs(getCellGridStructure());
232 return GetNumberOfCellsOfSubLevelMesh(cgs,getMeshDimension());
236 * See MEDCouplingUMesh::getDistributionOfTypes for more information
238 std::vector<int> MEDCouplingStructuredMesh::getDistributionOfTypes() const
240 //only one type of cell
241 std::vector<int> ret(3);
242 ret[0]=getTypeOfCell(0);
243 ret[1]=getNumberOfCells();
244 ret[2]=-1; //ret[3*k+2]==-1 because it has no sense here
249 * This method tries to minimize at most the number of deep copy.
250 * So if \a idsPerType is not empty it can be returned directly (without copy, but with ref count incremented) in return.
252 * See MEDCouplingUMesh::checkTypeConsistencyAndContig for more information
254 DataArrayInt *MEDCouplingStructuredMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
256 int nbOfCells=getNumberOfCells();
258 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : invalid input code should be exactly of size 3 !");
259 if(code[0]!=(int)getTypeOfCell(0))
261 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : Mismatch of geometric type ! Asking for " << code[0] << " whereas the geometric type is \a this is " << getTypeOfCell(0) << " !";
262 throw INTERP_KERNEL::Exception(oss.str().c_str());
266 if(code[1]==nbOfCells)
270 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : mismatch between the number of cells in this (" << nbOfCells << ") and the number of non profile (" << code[1] << ") !";
271 throw INTERP_KERNEL::Exception(oss.str().c_str());
275 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : single geo type mesh ! 0 or -1 is expected at pos #2 of input code !");
276 if(idsPerType.size()!=1)
277 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : input code points to DataArrayInt #0 whereas the size of idsPerType is not equal to 1 !");
278 const DataArrayInt *pfl=idsPerType[0];
280 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : the input code points to a NULL DataArrayInt at rank 0 !");
281 if(pfl->getNumberOfComponents()!=1)
282 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::checkTypeConsistencyAndContig : input profile should have exactly one component !");
283 pfl->checkAllIdsInRange(0,nbOfCells);
285 return const_cast<DataArrayInt *>(pfl);
289 * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in \a profile it returns a list of sub-profiles sorted by geo type.
290 * The result is put in the array \a idsPerType. In the returned parameter \a code, foreach i \a code[3*i+2] refers (if different from -1) to a location into the \a idsPerType.
291 * This method has 1 input \a profile and 3 outputs \a code \a idsInPflPerType and \a idsPerType.
293 * \param [out] code is a vector of size 3*n where n is the number of different geometric type in \a this \b reduced to the profile \a profile. \a code has exactly the same semantic than in MEDCouplingUMesh::checkTypeConsistencyAndContig method.
294 * \param [out] idsInPflPerType is a vector of size of different geometric type in the subpart defined by \a profile of \a this ( equal to \a code.size()/3). For each i,
295 * \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0]
296 * \param [out] idsPerType is a vector of size of different sub profiles needed to be defined to represent the profile \a profile for a given geometric type.
297 * This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile.
299 * \warning for performance reasons no deep copy will be performed, if \a profile can been used as this in output parameters \a idsInPflPerType and \a idsPerType.
301 * \throw if \a profile has not exactly one component. It throws too, if \a profile contains some values not in [0,getNumberOfCells()) or if \a this is not fully defined
304 * - Before \a this has 3 cells \a profile contains [0,1,2]
305 * - After \a code contains [NORM_...,nbCells,-1], \a idsInPflPerType [[0,1,2]] and \a idsPerType is empty <br>
308 * - Before \a this has 3 cells \a profile contains [1,2]
309 * - After \a code contains [NORM_...,nbCells,0], \a idsInPflPerType [[0,1]] and \a idsPerType is [[1,2]] <br>
312 void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const
314 if(!profile || !profile->isAllocated())
315 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL or not allocated !");
316 if(profile->getNumberOfComponents()!=1)
317 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile should have exactly one component !");
318 int nbTuples=profile->getNumberOfTuples();
319 int nbOfCells=getNumberOfCells();
320 code.resize(3); idsInPflPerType.resize(1);
321 code[0]=(int)getTypeOfCell(0); code[1]=nbOfCells;
322 idsInPflPerType.resize(1);
323 if(profile->isIdentity() && nbTuples==nbOfCells)
326 idsInPflPerType[0]=0;
330 code[1]=profile->getNumberOfTuples();
332 profile->checkAllIdsInRange(0,nbOfCells);
333 idsPerType.resize(1);
334 idsPerType[0]=profile->deepCpy();
335 idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
339 * Creates a new unstructured mesh (MEDCoupling1SGTUMesh) from \a this structured one.
340 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
341 * delete this array using decrRef() as it is no more needed.
342 * \throw If \a this->getMeshDimension() is not among [1,2,3].
344 MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const
346 int meshDim(getMeshDimension()),spaceDim(getSpaceDimensionOnNodeStruct());
347 if((meshDim<0 || meshDim>3) || (spaceDim<0 || spaceDim>3))
348 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim and spacedim must be in [1,2,3] !");
349 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
351 getNodeGridStructure(ns);
352 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivity(ns,ns+spaceDim));
353 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim)));
354 ret->setNodalConnectivity(conn); ret->setCoords(coords);
356 { ret->copyTinyInfoFrom(this); }
357 catch(INTERP_KERNEL::Exception&) { }
362 * This method returns the unstructured mesh (having single geometric type) of the sub level mesh of \a this.
363 * This method is equivalent to computing MEDCouplingUMesh::buildDescendingConnectivity on the unstructurized \a this mesh.
365 * The caller is to delete the returned mesh using decrRef() as it is no more needed.
367 MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTSubLevelMesh() const
369 int meshDim(getMeshDimension());
370 if(meshDim<1 || meshDim>3)
371 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTSubLevelMesh : meshdim must be in [2,3] !");
372 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
374 getNodeGridStructure(ns);
375 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim));
376 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1)));
377 ret->setNodalConnectivity(conn); ret->setCoords(coords);
382 * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
383 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
384 * delete this array using decrRef() as it is no more needed.
385 * \throw If \a this->getMeshDimension() is not among [1,2,3].
387 MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const
389 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret0(build1SGTUnstructured());
390 return ret0->buildUnstructured();
394 * Creates a new MEDCouplingUMesh containing a part of cells of \a this mesh.
395 * The cells to include to the
396 * result mesh are specified by an array of cell ids.
397 * \param [in] start - an array of cell ids to include to the result mesh.
398 * \param [in] end - specifies the end of the array \a start, so that
399 * the last value of \a start is \a end[ -1 ].
400 * \return MEDCouplingMesh * - a new instance of MEDCouplingUMesh. The caller is to
401 * delete this mesh using decrRef() as it is no more needed.
403 MEDCouplingMesh *MEDCouplingStructuredMesh::buildPart(const int *start, const int *end) const
405 MEDCouplingUMesh *um=buildUnstructured();
406 MEDCouplingMesh *ret=um->buildPart(start,end);
411 MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
413 std::vector<int> cgs(getCellGridStructure());
414 std::vector< std::pair<int,int> > cellPartFormat,nodePartFormat;
415 if(IsPartStructured(start,end,cgs,cellPartFormat))
417 MEDCouplingAutoRefCountObjectPtr<MEDCouplingStructuredMesh> ret(buildStructuredSubPart(cellPartFormat));
418 nodePartFormat=cellPartFormat;
419 for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
421 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
422 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(DataArrayInt::New()); tmp2->alloc(getNumberOfNodes(),1);
423 tmp2->fillWithValue(-1);
424 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3(DataArrayInt::New()); tmp3->alloc(tmp1->getNumberOfTuples(),1); tmp3->iota(0);
425 tmp2->setPartOfValues3(tmp3,tmp1->begin(),tmp1->end(),0,1,1);
431 MEDCouplingUMesh *um=buildUnstructured();
432 MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
438 DataArrayInt *MEDCouplingStructuredMesh::simplexize(int policy)
440 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::simplexize : not available for Cartesian mesh !");
444 * Returns a new MEDCouplingFieldDouble holding normal vectors to cells of \a this
445 * 2D mesh. The computed vectors have 3 components and are normalized.
446 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on
447 * cells and one time. The caller is to delete this field using decrRef() as
448 * it is no more needed.
449 * \throw If \a this->getMeshDimension() != 2.
451 MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const
453 if(getMeshDimension()!=2)
454 throw INTERP_KERNEL::Exception("Expected a MEDCouplingStructuredMesh with meshDim == 2 !");
455 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
456 DataArrayDouble *array=DataArrayDouble::New();
457 int nbOfCells=getNumberOfCells();
458 array->alloc(nbOfCells,3);
459 double *vals=array->getPointer();
460 for(int i=0;i<nbOfCells;i++)
461 { vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
462 ret->setArray(array);
468 void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
470 std::vector<int> ngs(getNodeGridStructure());
471 int dim(getSpaceDimension());
475 return GetReverseNodalConnectivity1(ngs,revNodal,revNodalIndx);
477 return GetReverseNodalConnectivity2(ngs,revNodal,revNodalIndx);
479 return GetReverseNodalConnectivity3(ngs,revNodal,revNodalIndx);
481 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::getReverseNodalConnectivity : only dimensions 1, 2 and 3 are supported !");
485 void MEDCouplingStructuredMesh::GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
488 revNodalIndx->alloc(nbNodes+1,1);
490 { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
492 { revNodal->alloc(1,1); revNodal->setIJ(0,0,0); revNodalIndx->setIJ(0,0,0); revNodalIndx->setIJ(1,0,1); return ; }
493 revNodal->alloc(2*(nbNodes-1),1);
494 int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
495 *rni++=0; *rni=1; *rn++=0;
496 for(int i=1;i<nbNodes-1;i++,rni++)
502 rn[0]=nbNodes-2; rni[1]=rni[0]+1;
505 void MEDCouplingStructuredMesh::GetReverseNodalConnectivity2(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
507 int nbNodesX(ngs[0]),nbNodesY(ngs[1]);
508 int nbNodes(nbNodesX*nbNodesY);
509 if(nbNodesX==0 || nbNodesY==0)
510 { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
511 if(nbNodesX==1 || nbNodesY==1)
512 { std::vector<int> ngs2(1); ngs2[0]=std::max(nbNodesX,nbNodesY); return GetReverseNodalConnectivity1(ngs2,revNodal,revNodalIndx); }
513 revNodalIndx->alloc(nbNodes+1,1);
514 int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1);
515 revNodal->alloc(4*(nbNodesX-2)*(nbNodesY-2)+2*2*(nbNodesX-2)+2*2*(nbNodesY-2)+4,1);
516 int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
517 *rni++=0; *rni=1; *rn++=0;
518 for(int i=1;i<nbNodesX-1;i++,rni++,rn+=2)
523 rni[1]=rni[0]+1; *rn++=nbCellsX-1;
525 for(int j=1;j<nbNodesY-1;j++)
527 int off(nbCellsX*(j-1)),off2(nbCellsX*j);
528 rni[1]=rni[0]+2; rn[0]=off; rn[1]=off2;
530 for(int i=1;i<nbNodesX-1;i++,rni++,rn+=4)
532 rn[0]=i-1+off; rn[1]=i+off; rn[2]=i-1+off2; rn[3]=i+off2;
535 rni[1]=rni[0]+2; rn[0]=off+nbCellsX-1; rn[1]=off2+nbCellsX-1;
538 int off3(nbCellsX*(nbCellsY-1));
541 for(int i=1;i<nbNodesX-1;i++,rni++,rn+=2)
543 rn[0]=i-1+off3; rn[1]=i+off3;
546 rni[1]=rni[0]+1; rn[0]=nbCellsX*nbCellsY-1;
549 void MEDCouplingStructuredMesh::GetReverseNodalConnectivity3(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
551 int nbNodesX(ngs[0]),nbNodesY(ngs[1]),nbNodesZ(ngs[2]);
552 int nbNodes(nbNodesX*nbNodesY*nbNodesZ);
553 if(nbNodesX==0 || nbNodesY==0 || nbNodesZ==0)
554 { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
555 if(nbNodesX==1 || nbNodesY==1 || nbNodesZ==1)
557 std::vector<int> ngs2(2);
563 { ngs2[pos++]=ngs[i]; }
568 { ngs2[pos++]=ngs[i]; }
571 return GetReverseNodalConnectivity2(ngs2,revNodal,revNodalIndx);
573 revNodalIndx->alloc(nbNodes+1,1);
574 int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1),nbCellsZ(nbNodesZ-1);
575 revNodal->alloc(8*(nbNodesX-2)*(nbNodesY-2)*(nbNodesZ-2)+4*(2*(nbNodesX-2)*(nbNodesY-2)+2*(nbNodesX-2)*(nbNodesZ-2)+2*(nbNodesY-2)*(nbNodesZ-2))+2*4*(nbNodesX-2)+2*4*(nbNodesY-2)+2*4*(nbNodesZ-2)+8,1);
576 int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
578 for(int k=0;k<nbNodesZ;k++)
580 bool factZ(k!=0 && k!=nbNodesZ-1);
581 int offZ0((k-1)*nbCellsX*nbCellsY),offZ1(k*nbCellsX*nbCellsY);
582 for(int j=0;j<nbNodesY;j++)
584 bool factYZ(factZ && (j!=0 && j!=nbNodesY-1));
585 int off00((j-1)*nbCellsX+offZ0),off01(j*nbCellsX+offZ0),off10((j-1)*nbCellsX+offZ1),off11(j*nbCellsX+offZ1);
586 for(int i=0;i<nbNodesX;i++,rni++)
588 int fact(factYZ && (i!=0 && i!=nbNodesX-1));
590 {//most of points fall in this part of code
591 rn[0]=off00+i-1; rn[1]=off00+i; rn[2]=off01+i-1; rn[3]=off01+i;
592 rn[4]=off10+i-1; rn[5]=off10+i; rn[6]=off11+i-1; rn[7]=off11+i;
599 if(k>=1 && j>=1 && i>=1)
601 if(k>=1 && j>=1 && i<nbCellsX)
603 if(k>=1 && j<nbCellsY && i>=1)
605 if(k>=1 && j<nbCellsY && i<nbCellsX)
608 if(k<nbCellsZ && j>=1 && i>=1)
610 if(k<nbCellsZ && j>=1 && i<nbCellsX)
612 if(k<nbCellsZ && j<nbCellsY && i>=1)
614 if(k<nbCellsZ && j<nbCellsY && i<nbCellsX)
616 rni[1]=rni[0]+(int)(std::distance(rnRef,rn));
624 * \return DataArrayInt * - newly allocated instance of nodal connectivity compatible for MEDCoupling1SGTMesh instance
626 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd)
629 int dim(ZipNodeStructure(nodeStBg,nodeStEnd,zippedNodeSt));
634 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
635 conn->alloc(1,1); conn->setIJ(0,0,0);
639 return Build1GTNodalConnectivity1D(zippedNodeSt);
641 return Build1GTNodalConnectivity2D(zippedNodeSt);
643 return Build1GTNodalConnectivity3D(zippedNodeSt);
645 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [0,1,2,3] supported !");
649 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd)
651 std::size_t dim(std::distance(nodeStBg,nodeStEnd));
655 return Build1GTNodalConnectivityOfSubLevelMesh3D(nodeStBg);
657 return Build1GTNodalConnectivityOfSubLevelMesh2D(nodeStBg);
659 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh: only dimension in [2,3] supported !");
664 * This method returns the list of ids sorted ascendingly of entities that are in the corner in ghost zone.
665 * The ids are returned in a newly created DataArrayInt having a single component.
667 * \param [in] st - The structure \b without ghost cells.
668 * \param [in] ghostLev - The size of the ghost zone (>=0)
669 * \return DataArrayInt * - The DataArray containing all the ids the caller is to deallocate.
671 DataArrayInt *MEDCouplingStructuredMesh::ComputeCornersGhost(const std::vector<int>& st, int ghostLev)
674 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : ghost lev must be >= 0 !");
675 std::size_t dim(st.size());
676 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
681 ret->alloc(2*ghostLev,1);
682 int *ptr(ret->getPointer());
683 for(int i=0;i<ghostLev;i++,ptr++)
687 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : element in 1D structure must be >= 0 !");
688 for(int i=0;i<ghostLev;i++,ptr++)
689 *ptr=offset+ghostLev+i;
694 int offsetX(st[0]),offsetY(st[1]);
695 if(offsetX<0 || offsetY<0)
696 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : elements in 2D structure must be >= 0 !");
697 ret->alloc(4*ghostLev,1);
698 int *ptr(ret->getPointer());
699 for(int i=0;i<ghostLev;i++)
701 *ptr++=i*(2*ghostLev+offsetX+1);
702 *ptr++=offsetX+2*ghostLev-1+i*(2*ghostLev+offsetX-1);
704 for(int i=0;i<ghostLev;i++)
706 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+ghostLev-1+i*(2*ghostLev+offsetX-1);
707 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+offsetX+ghostLev+i*(2*ghostLev+offsetX+1);
713 int offsetX(st[0]),offsetY(st[1]),offsetZ(st[2]);
714 if(offsetX<0 || offsetY<0 || offsetZ<0)
715 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : elements in 3D structure must be >= 0 !");
716 ret->alloc(8*ghostLev,1);
717 int *ptr(ret->getPointer());
718 int zeOffsetZ((offsetX+2*ghostLev)*(offsetY+2*ghostLev));
719 for(int i=0;i<ghostLev;i++)
721 *ptr++=i*(2*ghostLev+offsetX+1)+i*zeOffsetZ;
722 *ptr++=offsetX+2*ghostLev-1+i*(2*ghostLev+offsetX-1)+i*zeOffsetZ;
723 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+ghostLev-1+(ghostLev-i-1)*(2*ghostLev+offsetX-1)+i*zeOffsetZ;
724 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+offsetX+ghostLev+(ghostLev-i-1)*(2*ghostLev+offsetX+1)+i*zeOffsetZ;
726 int j(0),zeOffsetZ2(zeOffsetZ*(offsetZ+ghostLev));
727 for(int i=ghostLev-1;i>=0;i--,j++)
729 *ptr++=i*(2*ghostLev+offsetX+1)+j*zeOffsetZ+zeOffsetZ2;
730 *ptr++=offsetX+2*ghostLev-1+i*(2*ghostLev+offsetX-1)+j*zeOffsetZ+zeOffsetZ2;
731 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+ghostLev-1+(ghostLev-i-1)*(2*ghostLev+offsetX-1)+j*zeOffsetZ+zeOffsetZ2;
732 *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+offsetX+ghostLev+(ghostLev-i-1)*(2*ghostLev+offsetX+1)+j*zeOffsetZ+zeOffsetZ2;
737 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : Only dimensions 1, 2 and 3 are supported actually !");
743 * This method retrieves the number of entities (it can be cells or nodes) given a range in compact standard format
744 * used in methods like BuildExplicitIdsFrom,IsPartStructured.
746 * \sa BuildExplicitIdsFrom,IsPartStructured
748 int MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat)
752 for(std::vector< std::pair<int,int> >::const_iterator it=partCompactFormat.begin();it!=partCompactFormat.end();it++,ii++)
754 int a((*it).first),b((*it).second);
755 if(a<0 || b<0 || b-a<0)
757 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt : invalid input at dimension " << ii << " !";
758 throw INTERP_KERNEL::Exception(oss.str().c_str());
765 int MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(const std::vector<int>& st)
768 bool isFetched(false);
769 for(std::size_t i=0;i<st.size();i++)
772 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure : presence of a negative value in structure !");
776 return isFetched?ret:0;
779 void MEDCouplingStructuredMesh::FindTheWidestAxisOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat, int& axisId, int& sizeOfRange)
781 int dim((int)partCompactFormat.size());
783 for(int i=0;i<dim;i++)
785 int curDelta(partCompactFormat[i].second-partCompactFormat[i].first);
788 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::FindTheWidestAxisOfGivenRangeInCompactFrmt : at axis #" << i << " the range is invalid (first value < second value) !";
789 throw INTERP_KERNEL::Exception(oss.str().c_str());
793 axisId=i; sizeOfRange=curDelta;
800 * This method is \b NOT wrapped in python because it has no sense in python (for performance reasons).
801 * This method starts from a structured mesh with structure \a st on which a boolean field \a crit is set.
802 * This method find for such minimalist information of mesh and field which is the part of the mesh, given by the range per axis in output parameter
803 * \a partCompactFormat that contains all the True in \a crit. The returned vector of boolean is the field reduced to that part.
804 * So the number of True is equal in \a st and in returned vector of boolean.
806 * \param [in] st - The structure per axis of the structured mesh considered.
807 * \param [in] crit - The field of boolean (for performance reasons) lying on the mesh defined by \a st.
808 * \param [out] partCompactFormat - The minimal part of \a st containing all the true of \a crit.
809 * \param [out] reducedCrit - The reduction of \a criterion on \a partCompactFormat.
810 * \return - The number of True in \a st (that is equal to those in \a reducedCrit)
812 int MEDCouplingStructuredMesh::FindMinimalPartOf(const std::vector<int>& st, const std::vector<bool>& crit, std::vector<bool>& reducedCrit, std::vector< std::pair<int,int> >& partCompactFormat)
814 if((int)crit.size()!=DeduceNumberOfGivenStructure(st))
815 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf : size of vector of boolean is invalid regarding the declared structure !");
817 switch((int)st.size())
821 ret=FindMinimalPartOf1D(st,crit,partCompactFormat);
826 ret=FindMinimalPartOf2D(st,crit,partCompactFormat);
831 ret=FindMinimalPartOf3D(st,crit,partCompactFormat);
835 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf : only dimension 1, 2 and 3 are supported actually !");
837 ExtractFieldOfBoolFrom(st,crit,partCompactFormat,reducedCrit);
842 * This method is \b NOT wrapped in python.
843 * This method considers \a crit input parameter as a matrix having dimensions specified by \a st. This method returns for each axis
844 * the signature, that is to say the number of elems equal to true in \a crit along this axis.
846 std::vector< std::vector<int> > MEDCouplingStructuredMesh::ComputeSignaturePerAxisOf(const std::vector<int>& st, const std::vector<bool>& crit)
848 int dim((int)st.size());
849 std::vector< std::vector<int> > ret(dim);
856 std::vector<int>& retX(ret[0]);
857 for(int i=0;i<nx;i++)
863 int nx(st[0]),ny(st[1]);
864 ret[0].resize(nx); ret[1].resize(ny);
865 std::vector<int>& retX(ret[0]);
866 for(int i=0;i<nx;i++)
869 for(int j=0;j<ny;j++)
874 std::vector<int>& retY(ret[1]);
875 for(int j=0;j<ny;j++)
878 for(int i=0;i<nx;i++)
887 int nx(st[0]),ny(st[1]),nz(st[2]);
888 ret[0].resize(nx); ret[1].resize(ny); ret[2].resize(nz);
889 std::vector<int>& retX(ret[0]);
890 for(int i=0;i<nx;i++)
893 for(int k=0;k<nz;k++)
896 for(int j=0;j<ny;j++)
902 std::vector<int>& retY(ret[1]);
903 for(int j=0;j<ny;j++)
905 int cnt(0),offy(j*nx);
906 for(int k=0;k<nz;k++)
908 int offz(k*nx*ny+offy);
909 for(int i=0;i<nx;i++)
915 std::vector<int>& retZ(ret[2]);
916 for(int k=0;k<nz;k++)
918 int cnt(0),offz(k*nx*ny);
919 for(int j=0;j<ny;j++)
922 for(int i=0;i<nx;i++)
931 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeSignatureOf : only dimensions 1, 2 and 3 are supported !");
936 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
938 int nbOfCells(*nodeStBg-1);
939 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
940 conn->alloc(2*nbOfCells,1);
941 int *cp=conn->getPointer();
942 for(int i=0;i<nbOfCells;i++)
950 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg)
952 int n1=nodeStBg[0]-1;
953 int n2=nodeStBg[1]-1;
954 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
955 conn->alloc(4*n1*n2,1);
956 int *cp=conn->getPointer();
958 for(int j=0;j<n2;j++)
959 for(int i=0;i<n1;i++,pos++)
961 cp[4*pos+0]=i+1+j*(n1+1);
962 cp[4*pos+1]=i+j*(n1+1);
963 cp[4*pos+2]=i+(j+1)*(n1+1);
964 cp[4*pos+3]=i+1+(j+1)*(n1+1);
969 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg)
971 int n1=nodeStBg[0]-1;
972 int n2=nodeStBg[1]-1;
973 int n3=nodeStBg[2]-1;
974 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
975 conn->alloc(8*n1*n2*n3,1);
976 int *cp=conn->getPointer();
978 for(int k=0;k<n3;k++)
979 for(int j=0;j<n2;j++)
980 for(int i=0;i<n1;i++,pos++)
982 int tmp=(n1+1)*(n2+1);
983 cp[8*pos+0]=i+1+j*(n1+1)+k*tmp;
984 cp[8*pos+1]=i+j*(n1+1)+k*tmp;
985 cp[8*pos+2]=i+(j+1)*(n1+1)+k*tmp;
986 cp[8*pos+3]=i+1+(j+1)*(n1+1)+k*tmp;
987 cp[8*pos+4]=i+1+j*(n1+1)+(k+1)*tmp;
988 cp[8*pos+5]=i+j*(n1+1)+(k+1)*tmp;
989 cp[8*pos+6]=i+(j+1)*(n1+1)+(k+1)*tmp;
990 cp[8*pos+7]=i+1+(j+1)*(n1+1)+(k+1)*tmp;
995 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg)
997 std::vector<int> ngs(3);
998 int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1),n2(nodeStBg[2]-1); ngs[0]=n0; ngs[1]=n1; ngs[2]=n2;
999 int off0(nodeStBg[0]),off1(nodeStBg[0]*nodeStBg[1]);
1000 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
1001 conn->alloc(4*GetNumberOfCellsOfSubLevelMesh(ngs,3));
1002 int *cp(conn->getPointer());
1004 for(int i=0;i<nodeStBg[0];i++)
1005 for(int j=0;j<n1;j++)
1006 for(int k=0;k<n2;k++,cp+=4)
1007 { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+(j+1)*off0+i; cp[3]=k*off1+(j+1)*off0+i; }
1009 for(int j=0;j<nodeStBg[1];j++)
1010 for(int i=0;i<n0;i++)
1011 for(int k=0;k<n2;k++,cp+=4)
1012 { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+j*off0+(i+1); cp[3]=k*off1+j*off0+(i+1); }
1014 for(int k=0;k<nodeStBg[2];k++)
1015 for(int i=0;i<n0;i++)
1016 for(int j=0;j<n1;j++,cp+=4)
1017 { cp[0]=k*off1+j*off0+i; cp[1]=k*off1+j*off0+(i+1); cp[2]=k*off1+(j+1)*off0+(i+1); cp[3]=k*off1+(j+1)*off0+i; }
1022 * \sa MEDCouplingStructuredMesh::FindMinimalPartOf
1024 int MEDCouplingStructuredMesh::FindMinimalPartOf1D(const std::vector<int>& st, const std::vector<bool>& crit, std::vector< std::pair<int,int> >& partCompactFormat)
1027 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf1D : the input size of st must be equal to 1 !");
1028 int nxMin(std::numeric_limits<int>::max()),nxMax(-std::numeric_limits<int>::max());
1029 int nx(st[0]),ret(0);
1030 for(int i=0;i<nx;i++)
1034 nxMin=std::min(nxMin,i); nxMax=std::max(nxMax,i);
1040 partCompactFormat.resize(1);
1041 partCompactFormat[0].first=nxMin; partCompactFormat[0].second=nxMax+1;
1046 * \sa MEDCouplingStructuredMesh::FindMinimalPartOf
1048 int MEDCouplingStructuredMesh::FindMinimalPartOf2D(const std::vector<int>& st, const std::vector<bool>& crit, std::vector< std::pair<int,int> >& partCompactFormat)
1051 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf2D : the input size of st must be equal to 2 !");
1052 int nxMin(std::numeric_limits<int>::max()),nxMax(-std::numeric_limits<int>::max()),nyMin(std::numeric_limits<int>::max()),nyMax(-std::numeric_limits<int>::max());
1053 int it(0),nx(st[0]),ny(st[1]);
1055 for(int i=0;i<ny;i++)
1056 for(int j=0;j<nx;j++,it++)
1060 nxMin=std::min(nxMin,j); nxMax=std::max(nxMax,j);
1061 nyMin=std::min(nyMin,i); nyMax=std::max(nyMax,i);
1067 partCompactFormat.resize(2);
1068 partCompactFormat[0].first=nxMin; partCompactFormat[0].second=nxMax+1;
1069 partCompactFormat[1].first=nyMin; partCompactFormat[1].second=nyMax+1;
1074 * \sa MEDCouplingStructuredMesh::FindMinimalPartOf
1076 int MEDCouplingStructuredMesh::FindMinimalPartOf3D(const std::vector<int>& st, const std::vector<bool>& crit, std::vector< std::pair<int,int> >& partCompactFormat)
1079 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf3D : the input size of st must be equal to 3 !");
1080 int nxMin(std::numeric_limits<int>::max()),nxMax(-std::numeric_limits<int>::max()),nyMin(std::numeric_limits<int>::max()),nyMax(-std::numeric_limits<int>::max()),nzMin(std::numeric_limits<int>::max()),nzMax(-std::numeric_limits<int>::max());
1081 int it(0),nx(st[0]),ny(st[1]),nz(st[2]);
1083 for(int i=0;i<nz;i++)
1084 for(int j=0;j<ny;j++)
1085 for(int k=0;k<nx;k++,it++)
1089 nxMin=std::min(nxMin,k); nxMax=std::max(nxMax,k);
1090 nyMin=std::min(nyMin,j); nyMax=std::max(nyMax,j);
1091 nzMin=std::min(nzMin,i); nzMax=std::max(nzMax,i);
1097 partCompactFormat.resize(3);
1098 partCompactFormat[0].first=nxMin; partCompactFormat[0].second=nxMax+1;
1099 partCompactFormat[1].first=nyMin; partCompactFormat[1].second=nyMax+1;
1100 partCompactFormat[2].first=nzMin; partCompactFormat[2].second=nzMax+1;
1105 * This method computes given the nodal structure defined by [ \a nodeStBg , \a nodeStEnd ) the zipped form.
1106 * std::distance( \a nodeStBg, \a nodeStEnd ) is equal to the space dimension. The returned value is equal to
1107 * the meshDimension (or the zipped spaceDimension).
1109 * \param [out] zipNodeSt - The zipped node strucutre
1112 int MEDCouplingStructuredMesh::ZipNodeStructure(const int *nodeStBg, const int *nodeStEnd, int zipNodeSt[3])
1114 int spaceDim((int)std::distance(nodeStBg,nodeStEnd));
1115 if(spaceDim>3 || spaceDim<1)
1116 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ZipNodeStructure : spaceDim must in [1,2,3] !");
1117 zipNodeSt[0]=0; zipNodeSt[1]=0; zipNodeSt[2]=0;
1119 for(int i=0;i<spaceDim;i++)
1121 int elt(nodeStBg[i]);
1124 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ZipNodeStructure : the input nodal structure at pos#" << i << "(" << nodeStBg[i] << ") is invalid !";
1125 throw INTERP_KERNEL::Exception(oss.str().c_str());
1128 zipNodeSt[zippedI++]=elt;
1133 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg)
1135 std::vector<int> ngs(2);
1136 int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1); ngs[0]=n0; ngs[1]=n1;
1137 int off0(nodeStBg[0]);
1138 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
1139 conn->alloc(2*GetNumberOfCellsOfSubLevelMesh(ngs,2));
1140 int *cp(conn->getPointer());
1142 for(int i=0;i<nodeStBg[0];i++)
1143 for(int j=0;j<n1;j++,cp+=2)
1144 { cp[0]=j*off0+i; cp[1]=(j+1)*off0+i; }
1146 for(int j=0;j<nodeStBg[1];j++)
1147 for(int i=0;i<n0;i++,cp+=2)
1148 { cp[0]=j*off0+i; cp[1]=j*off0+(i+1); }
1153 * Returns a cell id by its (i,j,k) index. The cell is located between the i-th and
1154 * ( i + 1 )-th nodes along X axis etc.
1155 * \param [in] i - a index of node coordinates array along X axis.
1156 * \param [in] j - a index of node coordinates array along Y axis.
1157 * \param [in] k - a index of node coordinates array along Z axis.
1158 * \return int - a cell id in \a this mesh.
1160 int MEDCouplingStructuredMesh::getCellIdFromPos(int i, int j, int k) const
1164 int meshDim(getMeshDimension());
1165 getSplitCellValues(tmp2);
1166 std::transform(tmp,tmp+meshDim,tmp2,tmp,std::multiplies<int>());
1167 return std::accumulate(tmp,tmp+meshDim,0);
1171 * Returns a node id by its (i,j,k) index.
1172 * \param [in] i - a index of node coordinates array along X axis.
1173 * \param [in] j - a index of node coordinates array along Y axis.
1174 * \param [in] k - a index of node coordinates array along Z axis.
1175 * \return int - a node id in \a this mesh.
1177 int MEDCouplingStructuredMesh::getNodeIdFromPos(int i, int j, int k) const
1181 int spaceDim(getSpaceDimension());
1182 getSplitNodeValues(tmp2);
1183 std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies<int>());
1184 return std::accumulate(tmp,tmp+spaceDim,0);
1188 int MEDCouplingStructuredMesh::getNumberOfCells() const
1190 std::vector<int> ngs(getNodeGridStructure());
1192 bool isCatched(false);
1194 for(std::vector<int>::const_iterator it=ngs.begin();it!=ngs.end();it++,ii++)
1199 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getNumberOfCells : at pos #" << ii << " the number of nodes in nodeStructure is " << *it << " ! Must be > 0 !";
1200 throw INTERP_KERNEL::Exception(oss.str().c_str());
1208 return isCatched?ret:0;
1211 int MEDCouplingStructuredMesh::getNumberOfNodes() const
1213 std::vector<int> ngs(getNodeGridStructure());
1215 for(std::vector<int>::const_iterator it=ngs.begin();it!=ngs.end();it++)
1220 void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int *split, int *res)
1223 for(int i=meshDim-1;i>=0;i--)
1225 int pos=work/split[i];
1231 std::vector<int> MEDCouplingStructuredMesh::getCellGridStructure() const
1233 std::vector<int> ret(getNodeGridStructure());
1234 std::transform(ret.begin(),ret.end(),ret.begin(),std::bind2nd(std::plus<int>(),-1));
1239 * Given a struct \a strct it returns a split vector [1,strct[0],strct[0]*strct[1]...]
1240 * This decomposition allows to quickly find i,j,k given a global id.
1242 std::vector<int> MEDCouplingStructuredMesh::GetSplitVectFromStruct(const std::vector<int>& strct)
1244 int spaceDim((int)strct.size());
1245 std::vector<int> res(spaceDim);
1246 for(int l=0;l<spaceDim;l++)
1249 for(int p=0;p<spaceDim-l-1;p++)
1251 res[spaceDim-l-1]=val;
1257 * This method states if given part ids [ \a startIds, \a stopIds) and a structure \a st returns if it can be considered as a structured dataset.
1258 * If true is returned \a partCompactFormat will contain the information to build the corresponding part.
1260 * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt
1262 bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat)
1264 int dim((int)st.size());
1265 partCompactFormat.resize(dim);
1267 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::isPartStructured : input structure must be of dimension in [1,2,3] !");
1268 std::vector<int> tmp2(dim),tmp(dim),tmp3(dim),tmp4(dim); tmp2[0]=1;
1269 for(int i=1;i<dim;i++)
1270 tmp2[i]=tmp2[i-1]*st[i-1];
1271 std::size_t sz(std::distance(startIds,stopIds));
1273 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : empty input !");
1274 GetPosFromId(*startIds,dim,&tmp2[0],&tmp[0]);
1275 partCompactFormat.resize(dim);
1276 for(int i=0;i<dim;i++)
1277 partCompactFormat[i].first=tmp[i];
1278 if(tmp[dim-1]<0 || tmp[dim-1]>=st[dim-1])
1279 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : first id in input is not in valid range !");
1282 for(int i=0;i<dim;i++)
1283 partCompactFormat[i].second=tmp[i]+1;
1286 GetPosFromId(startIds[sz-1],dim,&tmp2[0],&tmp3[0]);
1288 for(int i=0;i<dim;i++)
1290 if(tmp3[i]<0 || tmp3[i]>=st[i])
1291 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : last id in input is not in valid range !");
1292 partCompactFormat[i].second=tmp3[i]+1;
1293 tmp4[i]=partCompactFormat[i].second-partCompactFormat[i].first;
1300 const int *w(startIds);
1305 for(int i=0;i<tmp4[2];i++)
1307 int a=tmp2[2]*(partCompactFormat[2].first+i);
1308 for(int j=0;j<tmp4[1];j++)
1310 int b=tmp2[1]*(partCompactFormat[1].first+j);
1311 for(int k=0;k<tmp4[0];k++,w++)
1313 if(partCompactFormat[0].first+k+b+a!=*w)
1322 for(int j=0;j<tmp4[1];j++)
1324 int b=tmp2[1]*(partCompactFormat[1].first+j);
1325 for(int k=0;k<tmp4[0];k++,w++)
1327 if(partCompactFormat[0].first+k+b!=*w)
1335 for(int k=0;k<tmp4[0];k++,w++)
1337 if(partCompactFormat[0].first+k!=*w)
1343 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : internal error !");
1348 * This method takes in input a compact format [[Xmax,Xmin),[Ymin,Ymax)] and returns the corresponding dimensions for each axis that is to say
1349 * [Xmax-Xmin,Ymax-Ymin].
1351 * \throw if an axis range is so that max<min
1352 * \sa GetCompactFrmtFromDimensions
1354 std::vector<int> MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat)
1356 std::vector<int> ret(partCompactFormat.size());
1357 for(std::size_t i=0;i<partCompactFormat.size();i++)
1359 if(partCompactFormat[i].first>partCompactFormat[i].second)
1361 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt : For axis #" << i << " end is before start !";
1362 throw INTERP_KERNEL::Exception(oss.str().c_str());
1364 ret[i]=partCompactFormat[i].second-partCompactFormat[i].first;
1370 * This method takes in input a vector giving the number of entity per axis and returns for each axis a range starting from [0,0...]
1372 * \throw if there is an axis in \a dims that is < 0.
1373 * \sa GetDimensionsFromCompactFrmt, ChangeReferenceFromGlobalOfCompactFrmt, ChangeReferenceToGlobalOfCompactFrmt
1375 std::vector< std::pair<int,int> > MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(const std::vector<int>& dims)
1377 std::size_t sz(dims.size());
1378 std::vector< std::pair<int,int> > ret(sz);
1379 for(std::size_t i=0;i<sz;i++)
1383 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt : For axis #" << i << " dimension < 0 !";
1384 throw INTERP_KERNEL::Exception(oss.str().c_str());
1387 ret[i].second=dims[i];
1393 * This method returns the intersection zone of two ranges (in compact format) \a r1 and \a r2.
1394 * This method will throw exception if on one axis the intersection is empty.
1396 std::vector< std::pair<int,int> > MEDCouplingStructuredMesh::IntersectRanges(const std::vector< std::pair<int,int> >& r1, const std::vector< std::pair<int,int> >& r2)
1398 std::size_t sz(r1.size());
1400 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IntersectRanges : the two ranges must have the same dimension !");
1401 std::vector< std::pair<int,int> > ret(sz);
1402 for(std::size_t i=0;i<sz;i++)
1404 if(r1[i].first>r1[i].second)
1406 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r1, end is before start !";
1407 throw INTERP_KERNEL::Exception(oss.str().c_str());
1409 if(r2[i].first>r2[i].second)
1411 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r2, end is before start !";
1412 throw INTERP_KERNEL::Exception(oss.str().c_str());
1414 ret[i].first=std::max(r1[i].first,r2[i].first);
1415 ret[i].second=std::min(r1[i].second,r2[i].second);
1416 if(ret[i].first>ret[i].second)
1418 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " the intersection of r1 and r2 is empty !";
1419 throw INTERP_KERNEL::Exception(oss.str().c_str());
1426 * This method is close to BuildExplicitIdsFrom except that instead of returning a DataArrayInt instance containing explicit ids it
1427 * enable elems in the vector of booleans (for performance reasons). As it is method for performance, this method is \b not
1428 * available in python.
1430 * \param [in] st The entity structure.
1431 * \param [in] partCompactFormat The compact subpart to be enabled.
1432 * \param [in,out] vectToSwitchOn Vector which fetched items are enabled.
1434 * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, ExtractFieldOfBoolFrom
1436 void MEDCouplingStructuredMesh::SwitchOnIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat, std::vector<bool>& vectToSwitchOn)
1438 if(st.size()!=partCompactFormat.size())
1439 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::SwitchOnIdsFrom : input arrays must have the same size !");
1440 if((int)vectToSwitchOn.size()!=DeduceNumberOfGivenStructure(st))
1441 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::SwitchOnIdsFrom : invalid size of input vector of boolean regarding the structure !");
1442 std::vector<int> dims(GetDimensionsFromCompactFrmt(partCompactFormat));
1447 for(int i=0;i<dims[2];i++)
1449 int a=(partCompactFormat[2].first+i)*st[0]*st[1];
1450 for(int j=0;j<dims[1];j++)
1452 int b=(partCompactFormat[1].first+j)*st[0];
1453 for(int k=0;k<dims[0];k++)
1454 vectToSwitchOn[partCompactFormat[0].first+k+b+a]=true;
1461 for(int j=0;j<dims[1];j++)
1463 int b=(partCompactFormat[1].first+j)*st[0];
1464 for(int k=0;k<dims[0];k++)
1465 vectToSwitchOn[partCompactFormat[0].first+k+b]=true;
1471 for(int k=0;k<dims[0];k++)
1472 vectToSwitchOn[partCompactFormat[0].first+k]=true;
1476 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::SwitchOnIdsFrom : Dimension supported are 1,2 or 3 !");
1481 * Obviously this method is \b NOT wrapped in python.
1482 * This method is close to SwitchOnIdsFrom except that here, a sub field \a fieldOut is built starting from the input field \a fieldOfBool having the structure \a st.
1483 * The extraction is defined by \a partCompactFormat.
1485 * \param [in] st The entity structure.
1486 * \param [in] fieldOfBool field of booleans having the size equal to \c MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(st).
1487 * \param [in] partCompactFormat The compact subpart to be enabled.
1488 * \param [out] fieldOut the result of the extraction.
1490 * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, SwitchOnIdsFrom, ExtractFieldOfDoubleFrom
1492 void MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom(const std::vector<int>& st, const std::vector<bool>& fieldOfBool, const std::vector< std::pair<int,int> >& partCompactFormat, std::vector<bool>& fieldOut)
1494 if(st.size()!=partCompactFormat.size())
1495 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom : input arrays must have the same size !");
1496 if((int)fieldOfBool.size()!=DeduceNumberOfGivenStructure(st))
1497 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom : invalid size of input field of boolean regarding the structure !");
1498 std::vector<int> dims(GetDimensionsFromCompactFrmt(partCompactFormat));
1499 int nbOfTuplesOfOutField(DeduceNumberOfGivenStructure(dims));
1500 fieldOut.resize(nbOfTuplesOfOutField);
1506 for(int i=0;i<dims[2];i++)
1508 int a=(partCompactFormat[2].first+i)*st[0]*st[1];
1509 for(int j=0;j<dims[1];j++)
1511 int b=(partCompactFormat[1].first+j)*st[0];
1512 for(int k=0;k<dims[0];k++)
1513 fieldOut[it++]=fieldOfBool[partCompactFormat[0].first+k+b+a];
1520 for(int j=0;j<dims[1];j++)
1522 int b=(partCompactFormat[1].first+j)*st[0];
1523 for(int k=0;k<dims[0];k++)
1524 fieldOut[it++]=fieldOfBool[partCompactFormat[0].first+k+b];
1530 for(int k=0;k<dims[0];k++)
1531 fieldOut[it++]=fieldOfBool[partCompactFormat[0].first+k];
1535 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom : Dimension supported are 1,2 or 3 !");
1540 * This method is close to SwitchOnIdsFrom except that here, a sub field \a fieldOut is built starting from the input field \a fieldOfDbl having the structure \a st.
1541 * The extraction is defined by \a partCompactFormat.
1543 * \param [in] st The entity structure.
1544 * \param [in] fieldOfDbl field of doubles having a number of tuples equal to \c MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(st).
1545 * \param [in] partCompactFormat The compact subpart to be enabled.
1546 * \return DataArrayDouble * -the result of the extraction.
1548 * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, SwitchOnIdsFrom, ExtractFieldOfBoolFrom
1550 DataArrayDouble *MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom(const std::vector<int>& st, const DataArrayDouble *fieldOfDbl, const std::vector< std::pair<int,int> >& partCompactFormat)
1552 if(!fieldOfDbl || !fieldOfDbl->isAllocated())
1553 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : input array of double is NULL or not allocated!");
1554 if(st.size()!=partCompactFormat.size())
1555 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : input arrays must have the same size !");
1556 if(fieldOfDbl->getNumberOfTuples()!=DeduceNumberOfGivenStructure(st))
1557 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : invalid size of input array of double regarding the structure !");
1558 std::vector<int> dims(GetDimensionsFromCompactFrmt(partCompactFormat));
1559 int nbOfTuplesOfOutField(DeduceNumberOfGivenStructure(dims)),nbComp(fieldOfDbl->getNumberOfComponents());
1560 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfTuplesOfOutField,nbComp);
1561 ret->copyStringInfoFrom(*fieldOfDbl);
1562 double *ptRet(ret->getPointer());
1563 const double *fieldOfDblPtr(fieldOfDbl->begin());
1568 for(int i=0;i<dims[2];i++)
1570 int a=(partCompactFormat[2].first+i)*st[0]*st[1];
1571 for(int j=0;j<dims[1];j++)
1573 int b=(partCompactFormat[1].first+j)*st[0];
1574 for(int k=0;k<dims[0];k++)
1575 ptRet=std::copy(fieldOfDblPtr+(partCompactFormat[0].first+k+b+a)*nbComp,fieldOfDblPtr+(partCompactFormat[0].first+k+b+a+1)*nbComp,ptRet);
1582 for(int j=0;j<dims[1];j++)
1584 int b=(partCompactFormat[1].first+j)*st[0];
1585 for(int k=0;k<dims[0];k++)
1586 ptRet=std::copy(fieldOfDblPtr+(partCompactFormat[0].first+k+b)*nbComp,fieldOfDblPtr+(partCompactFormat[0].first+k+b+1)*nbComp,ptRet);
1592 for(int k=0;k<dims[0];k++)
1593 ptRet=std::copy(fieldOfDblPtr+(partCompactFormat[0].first+k)*nbComp,fieldOfDblPtr+(partCompactFormat[0].first+k+1)*nbComp,ptRet);
1597 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : Dimension supported are 1,2 or 3 !");
1603 * This method changes the reference of a part of structured mesh \a partOfBigInAbs define in absolute reference to a new reference \a bigInAbs.
1604 * So this method only performs a translation by doing \a partOfBigRelativeToBig = \a partOfBigInAbs - \a bigInAbs
1605 * This method also checks (if \a check=true) that \a partOfBigInAbs is included in \a bigInAbs.
1606 * This method is useful to extract a part from a field lying on a big mesh.
1608 * \sa ChangeReferenceToGlobalOfCompactFrmt, BuildExplicitIdsFrom, SwitchOnIdsFrom, ExtractFieldOfBoolFrom, ExtractFieldOfDoubleFrom
1610 void MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(const std::vector< std::pair<int,int> >& bigInAbs, const std::vector< std::pair<int,int> >& partOfBigInAbs, std::vector< std::pair<int,int> >& partOfBigRelativeToBig, bool check)
1612 std::size_t dim(bigInAbs.size());
1613 if(dim!=partOfBigInAbs.size())
1614 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : The size of parts (dimension) must be the same !");
1615 partOfBigRelativeToBig.resize(dim);
1616 for(std::size_t i=0;i<dim;i++)
1620 if(bigInAbs[i].first>bigInAbs[i].second)
1622 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !";
1623 throw INTERP_KERNEL::Exception(oss.str().c_str());
1625 if(partOfBigInAbs[i].first<bigInAbs[i].first || partOfBigInAbs[i].first>=bigInAbs[i].second)
1627 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (start) !";
1628 throw INTERP_KERNEL::Exception(oss.str().c_str());
1631 partOfBigRelativeToBig[i].first=partOfBigInAbs[i].first-bigInAbs[i].first;
1634 if(partOfBigInAbs[i].second<partOfBigInAbs[i].first || partOfBigInAbs[i].second>bigInAbs[i].second)
1636 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (end) !";
1637 throw INTERP_KERNEL::Exception(oss.str().c_str());
1640 partOfBigRelativeToBig[i].second=partOfBigInAbs[i].second-bigInAbs[i].first;
1645 * This method is performs the opposite reference modification than explained in ChangeReferenceFromGlobalOfCompactFrmt.
1647 * \sa ChangeReferenceFromGlobalOfCompactFrmt
1649 void MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair<int,int> >& bigInAbs, const std::vector< std::pair<int,int> >& partOfBigRelativeToBig, std::vector< std::pair<int,int> >& partOfBigInAbs, bool check)
1651 std::size_t dim(bigInAbs.size());
1652 if(dim!=partOfBigRelativeToBig.size())
1653 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : The size of parts (dimension) must be the same !");
1654 partOfBigInAbs.resize(dim);
1655 for(std::size_t i=0;i<dim;i++)
1659 if(bigInAbs[i].first>bigInAbs[i].second)
1661 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !";
1662 throw INTERP_KERNEL::Exception(oss.str().c_str());
1664 if(partOfBigRelativeToBig[i].first<0 || partOfBigRelativeToBig[i].first>=bigInAbs[i].second-bigInAbs[i].first)
1666 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the start of part is not in the big one !";
1667 throw INTERP_KERNEL::Exception(oss.str().c_str());
1670 partOfBigInAbs[i].first=partOfBigRelativeToBig[i].first+bigInAbs[i].first;
1673 if(partOfBigRelativeToBig[i].second<partOfBigRelativeToBig[i].first || partOfBigRelativeToBig[i].second>bigInAbs[i].second-bigInAbs[i].first)
1675 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the end of part is not in the big one !";
1676 throw INTERP_KERNEL::Exception(oss.str().c_str());
1679 partOfBigInAbs[i].second=partOfBigRelativeToBig[i].second+bigInAbs[i].first;
1684 * This method performs a translation (defined by \a translation) of \a part and returns the result of translated part.
1686 * \sa FindTranslationFrom
1688 std::vector< std::pair<int,int> > MEDCouplingStructuredMesh::TranslateCompactFrmt(const std::vector< std::pair<int,int> >& part, const std::vector<int>& translation)
1690 std::size_t sz(part.size());
1691 if(translation.size()!=sz)
1692 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::TranslateCompactFrmt : the sizes are not equal !");
1693 std::vector< std::pair<int,int> > ret(sz);
1694 for(std::size_t i=0;i<sz;i++)
1696 ret[i].first=part[i].first+translation[i];
1697 ret[i].second=part[i].second+translation[i];
1703 * \sa TranslateCompactFrmt
1705 std::vector<int> MEDCouplingStructuredMesh::FindTranslationFrom(const std::vector< std::pair<int,int> >& startingFrom, const std::vector< std::pair<int,int> >& goingTo)
1707 std::size_t sz(startingFrom.size());
1708 if(goingTo.size()!=sz)
1709 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindTranslationFrom : the sizes are not equal !");
1710 std::vector< int > ret(sz);
1711 for(std::size_t i=0;i<sz;i++)
1713 ret[i]=goingTo[i].first-startingFrom[i].first;
1719 * This method builds the explicit entity array from the structure in \a st and the range in \a partCompactFormat.
1720 * If the range contains invalid values regarding sructure an exception will be thrown.
1722 * \return DataArrayInt * - a new object.
1723 * \sa MEDCouplingStructuredMesh::IsPartStructured, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt, SwitchOnIdsFrom, ExtractFieldOfBoolFrom, ExtractFieldOfDoubleFrom, MultiplyPartOf
1725 DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat)
1727 if(st.size()!=partCompactFormat.size())
1728 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : input arrays must have the same size !");
1730 std::vector<int> dims(st.size());
1731 for(std::size_t i=0;i<st.size();i++)
1733 if(partCompactFormat[i].first<0 || partCompactFormat[i].first>st[i])
1734 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 1 !");
1735 if(partCompactFormat[i].second<0 || partCompactFormat[i].second>st[i])
1736 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 2 !");
1737 if(partCompactFormat[i].second<partCompactFormat[i].first)
1738 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 3 !");
1739 dims[i]=partCompactFormat[i].second-partCompactFormat[i].first;
1742 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
1743 ret->alloc(nbOfItems,1);
1744 int *pt(ret->getPointer());
1749 for(int i=0;i<dims[2];i++)
1751 int a=(partCompactFormat[2].first+i)*st[0]*st[1];
1752 for(int j=0;j<dims[1];j++)
1754 int b=(partCompactFormat[1].first+j)*st[0];
1755 for(int k=0;k<dims[0];k++,pt++)
1756 *pt=partCompactFormat[0].first+k+b+a;
1763 for(int j=0;j<dims[1];j++)
1765 int b=(partCompactFormat[1].first+j)*st[0];
1766 for(int k=0;k<dims[0];k++,pt++)
1767 *pt=partCompactFormat[0].first+k+b;
1773 for(int k=0;k<dims[0];k++,pt++)
1774 *pt=partCompactFormat[0].first+k;
1778 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : Dimension supported are 1,2 or 3 !");
1784 * This method multiplies by \a factor values in tuples located by \a part in \a da.
1786 * \param [in] st - the structure of grid ( \b without considering ghost cells).
1787 * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st.
1788 * \param [in] factor - the factor, the tuples in \a da will be multiply by.
1789 * \param [in,out] da - The DataArray in wich only tuples specified by \a part will be modified.
1791 * \sa BuildExplicitIdsFrom
1793 void MEDCouplingStructuredMesh::MultiplyPartOf(const std::vector<int>& st, const std::vector< std::pair<int,int> >& part, double factor, DataArrayDouble *da)
1795 if(!da || !da->isAllocated())
1796 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : DataArrayDouble instance must be not NULL and allocated !");
1797 if(st.size()!=part.size())
1798 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : input arrays must have the same size !");
1799 std::vector<int> dims(st.size());
1800 for(std::size_t i=0;i<st.size();i++)
1802 if(part[i].first<0 || part[i].first>st[i])
1803 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : invalid input range 1 !");
1804 if(part[i].second<0 || part[i].second>st[i])
1805 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : invalid input range 2 !");
1806 if(part[i].second<part[i].first)
1807 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : invalid input range 3 !");
1808 dims[i]=part[i].second-part[i].first;
1810 int nbOfTuplesExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(st)),nbCompo(da->getNumberOfComponents());
1811 if(da->getNumberOfTuples()!=nbOfTuplesExp)
1813 std::ostringstream oss; oss << "MEDCouplingStructuredMesh::MultiplyPartOf : invalid nb of tuples ! Expected " << nbOfTuplesExp << " having " << da->getNumberOfTuples() << " !";
1814 throw INTERP_KERNEL::Exception(oss.str().c_str());
1816 double *pt(da->getPointer());
1821 for(int i=0;i<dims[2];i++)
1823 int a=(part[2].first+i)*st[0]*st[1];
1824 for(int j=0;j<dims[1];j++)
1826 int b=(part[1].first+j)*st[0];
1827 for(int k=0;k<dims[0];k++)
1829 int offset(part[0].first+k+b+a);
1830 std::transform(pt+nbCompo*offset,pt+nbCompo*(offset+1),pt+nbCompo*offset,std::bind2nd(std::multiplies<double>(),factor));
1838 for(int j=0;j<dims[1];j++)
1840 int b=(part[1].first+j)*st[0];
1841 for(int k=0;k<dims[0];k++)
1843 int offset(part[0].first+k+b);
1844 std::transform(pt+nbCompo*offset,pt+nbCompo*(offset+1),pt+nbCompo*offset,std::bind2nd(std::multiplies<double>(),factor));
1851 for(int k=0;k<dims[0];k++)
1853 int offset(part[0].first+k);
1854 std::transform(pt+nbCompo*offset,pt+nbCompo*(offset+1),pt+nbCompo*offset,std::bind2nd(std::multiplies<double>(),factor));
1859 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : Dimension supported are 1,2 or 3 !");
1864 * This method multiplies by \a factor values in tuples located by \a part in \a da.
1866 * \param [in] st - the structure of grid ( \b without considering ghost cells).
1867 * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st.
1868 * \param [in] ghostSize - \a ghostSize must be >= 0.
1869 * \param [in] factor - the factor, the tuples in \a da will be multiply by.
1870 * \param [in,out] da - The DataArray in wich only tuples specified by \a part will be modified.
1872 * \sa MultiplyPartOf, PutInGhostFormat
1874 void MEDCouplingStructuredMesh::MultiplyPartOfByGhost(const std::vector<int>& st, const std::vector< std::pair<int,int> >& part, int ghostSize, double factor, DataArrayDouble *da)
1876 std::vector<int> stWG;
1877 std::vector< std::pair<int,int> > partWG;
1878 PutInGhostFormat(ghostSize,st,part,stWG,partWG);
1879 MultiplyPartOf(stWG,partWG,factor,da);
1883 * This method multiplies by \a factor values in tuples located by \a part in \a da.
1885 * \param [in] st - the structure of grid ( \b without considering ghost cells).
1886 * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st.
1887 * \param [in] ghostSize - \a ghostSize must be >= 0.
1888 * \param [out] stWithGhost - the structure considering ghost cells.
1889 * \param [out] partWithGhost - the part considering the ghost cells.
1891 * \sa MultiplyPartOf, PutInGhostFormat
1893 void MEDCouplingStructuredMesh::PutInGhostFormat(int ghostSize, const std::vector<int>& st, const std::vector< std::pair<int,int> >& part, std::vector<int>& stWithGhost, std::vector< std::pair<int,int> >&partWithGhost)
1896 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : ghost size must be >= 0 !");
1897 std::size_t dim(part.size());
1899 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : the dimension of input vectors must be the same !");
1900 for(std::size_t i=0;i<dim;i++)
1901 if(part[i].first<0 || part[i].first>part[i].second || part[i].second>st[i])
1902 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : the specified part is invalid ! The begin must be >= 0 and <= end ! The end must be <= to the size at considered dimension !");
1903 stWithGhost.resize(st.size());
1904 std::transform(st.begin(),st.end(),stWithGhost.begin(),std::bind2nd(std::plus<int>(),2*ghostSize));
1906 ApplyGhostOnCompactFrmt(partWithGhost,ghostSize);
1910 * \param [in,out] partBeforeFact - the part of a image mesh in compact format that will be put in ghost reference.
1911 * \param [in] ghostSize - the ghost size of zone for all axis.
1913 void MEDCouplingStructuredMesh::ApplyGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize)
1916 throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ApplyGhostOnCompactFrmt : ghost size must be >= 0 !");
1917 std::size_t sz(partBeforeFact.size());
1918 for(std::size_t i=0;i<sz;i++)
1920 partBeforeFact[i].first+=ghostSize;
1921 partBeforeFact[i].second+=ghostSize;
1925 int MEDCouplingStructuredMesh::GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim)
1928 for(int i=0;i<mdim;i++)
1931 for(int j=0;j<mdim;j++)