-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <numeric>
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
MEDCouplingStructuredMesh::MEDCouplingStructuredMesh()
{
DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
if(getTypeOfCell(0)==type)
{
ret->alloc(getNumberOfCells(),1);
DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const
{
int nbCells=getNumberOfCells();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
ret->alloc(nbCells,1);
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
ret->fillWithValue((int)cm.getNumberOfNodes());
DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const
{
int nbCells=getNumberOfCells();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+ MCAuto<DataArrayInt> ret=DataArrayInt::New();
ret->alloc(nbCells,1);
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
ret->fillWithValue((int)cm.getNumberOfSons());
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL or not allocated !");
if(profile->getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile should have exactly one component !");
- int nbTuples=profile->getNumberOfTuples();
+ int nbTuples(profile->getNumberOfTuples());
int nbOfCells=getNumberOfCells();
code.resize(3); idsInPflPerType.resize(1);
code[0]=(int)getTypeOfCell(0); code[1]=nbOfCells;
idsInPflPerType.resize(1);
- if(profile->isIdentity() && nbTuples==nbOfCells)
+ if(profile->isIota(nbOfCells))
{
code[2]=-1;
- idsInPflPerType[0]=0;
+ idsInPflPerType[0]=profile->deepCopy();
idsPerType.clear();
return ;
}
code[2]=0;
profile->checkAllIdsInRange(0,nbOfCells);
idsPerType.resize(1);
- idsPerType[0]=profile->deepCpy();
+ idsPerType[0]=profile->deepCopy();
idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
}
/*!
* Creates a new unstructured mesh (MEDCoupling1SGTUMesh) from \a this structured one.
+ *
+ * In the returned mesh, the nodes are ordered with the first axis varying first: (X0,Y0), (X1,Y0), ... (X0,Y1), (X1,Y1), ...
+ * and the cells are ordered with the same logic, i.e. in (i,j) notation: (0,0), (1,0), (2,0), ... (0,1), (1,1), ...
+ *
* \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
* delete this array using decrRef() as it is no more needed.
* \throw If \a this->getMeshDimension() is not among [1,2,3].
int meshDim(getMeshDimension()),spaceDim(getSpaceDimensionOnNodeStruct());
if((meshDim<0 || meshDim>3) || (spaceDim<0 || spaceDim>3))
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim and spacedim must be in [1,2,3] !");
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
+ MCAuto<DataArrayDouble> coords(getCoordinatesAndOwner());
int ns[3];
getNodeGridStructure(ns);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivity(ns,ns+spaceDim));
- MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim)));
+ MCAuto<DataArrayInt> conn(Build1GTNodalConnectivity(ns,ns+spaceDim));
+ MCAuto<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim)));
ret->setNodalConnectivity(conn); ret->setCoords(coords);
try
{ ret->copyTinyInfoFrom(this); }
int meshDim(getMeshDimension());
if(meshDim<1 || meshDim>3)
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTSubLevelMesh : meshdim must be in [2,3] !");
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
+ MCAuto<DataArrayDouble> coords(getCoordinatesAndOwner());
int ns[3];
getNodeGridStructure(ns);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim));
- MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1)));
+ MCAuto<DataArrayInt> conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim));
+ MCAuto<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1)));
ret->setNodalConnectivity(conn); ret->setCoords(coords);
return ret.retn();
}
/*!
* Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
+ *
+ * In the returned mesh, the nodes are ordered with the first axis varying first: (X0,Y0), (X1,Y0), ... (X0,Y1), (X1,Y1), ...
+ * and the cells are ordered with the same logic, i.e. in (i,j) notation: (0,0), (1,0), (2,0), ... (0,1), (1,1), ...
+ *
* \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
* delete this array using decrRef() as it is no more needed.
* \throw If \a this->getMeshDimension() is not among [1,2,3].
*/
MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret0(build1SGTUnstructured());
+ MCAuto<MEDCoupling1SGTUMesh> ret0(build1SGTUnstructured());
return ret0->buildUnstructured();
}
*/
MEDCouplingMesh *MEDCouplingStructuredMesh::buildPart(const int *start, const int *end) const
{
- MEDCouplingUMesh *um=buildUnstructured();
- MEDCouplingMesh *ret=um->buildPart(start,end);
- um->decrRef();
- return ret;
+ MCAuto<MEDCouplingUMesh> um(buildUnstructured());
+ return um->buildPart(start,end);
}
MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
std::vector< std::pair<int,int> > cellPartFormat,nodePartFormat;
if(IsPartStructured(start,end,cgs,cellPartFormat))
{
- MEDCouplingAutoRefCountObjectPtr<MEDCouplingStructuredMesh> ret(buildStructuredSubPart(cellPartFormat));
+ MCAuto<MEDCouplingStructuredMesh> ret(buildStructuredSubPart(cellPartFormat));
nodePartFormat=cellPartFormat;
for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
(*it).second++;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(DataArrayInt::New()); tmp2->alloc(getNumberOfNodes(),1);
+ MCAuto<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
+ MCAuto<DataArrayInt> tmp2(DataArrayInt::New()); tmp2->alloc(getNumberOfNodes(),1);
tmp2->fillWithValue(-1);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3(DataArrayInt::New()); tmp3->alloc(tmp1->getNumberOfTuples(),1); tmp3->iota(0);
+ MCAuto<DataArrayInt> tmp3(DataArrayInt::New()); tmp3->alloc(tmp1->getNumberOfTuples(),1); tmp3->iota(0);
tmp2->setPartOfValues3(tmp3,tmp1->begin(),tmp1->end(),0,1,1);
arr=tmp2.retn();
return ret.retn();
}
else
{
- MEDCouplingUMesh *um=buildUnstructured();
- MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
- um->decrRef();
- return ret;
+ MCAuto<MEDCouplingUMesh> um(buildUnstructured());
+ return um->buildPartAndReduceNodes(start,end,arr);
}
}
{
if(getMeshDimension()!=2)
throw INTERP_KERNEL::Exception("Expected a MEDCouplingStructuredMesh with meshDim == 2 !");
- MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
- DataArrayDouble *array=DataArrayDouble::New();
- int nbOfCells=getNumberOfCells();
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME));
+ MCAuto<DataArrayDouble> array(DataArrayDouble::New());
+ int nbOfCells(getNumberOfCells());
array->alloc(nbOfCells,3);
- double *vals=array->getPointer();
+ double *vals(array->getPointer());
for(int i=0;i<nbOfCells;i++)
{ vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
ret->setArray(array);
- array->decrRef();
ret->setMesh(this);
- return ret;
+ return ret.retn();
}
void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
{
case 0:
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(1,1); conn->setIJ(0,0,0);
return conn.retn();
}
if(ghostLev<0)
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : ghost lev must be >= 0 !");
std::size_t dim(st.size());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New());
switch(dim)
{
case 1:
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
{
- int nbOfCells(*nodeStBg-1);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ std::size_t nbOfCells(*nodeStBg-1);
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(2*nbOfCells,1);
int *cp=conn->getPointer();
- for(int i=0;i<nbOfCells;i++)
+ for(std::size_t i=0;i<nbOfCells;i++)
{
cp[2*i+0]=i;
cp[2*i+1]=i+1;
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg)
{
- int n1=nodeStBg[0]-1;
- int n2=nodeStBg[1]-1;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ std::size_t n1(nodeStBg[0]-1),n2(nodeStBg[1]-1);
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(4*n1*n2,1);
- int *cp=conn->getPointer();
- int pos=0;
+ int *cp(conn->getPointer());
+ std::size_t pos(0);
for(int j=0;j<n2;j++)
for(int i=0;i<n1;i++,pos++)
{
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg)
{
- int n1=nodeStBg[0]-1;
- int n2=nodeStBg[1]-1;
- int n3=nodeStBg[2]-1;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ std::size_t n1(nodeStBg[0]-1),n2(nodeStBg[1]-1),n3(nodeStBg[2]-1);
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(8*n1*n2*n3,1);
- int *cp=conn->getPointer();
- int pos=0;
+ int *cp(conn->getPointer());
+ std::size_t pos(0);
for(int k=0;k<n3;k++)
for(int j=0;j<n2;j++)
for(int i=0;i<n1;i++,pos++)
std::vector<int> ngs(3);
int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1),n2(nodeStBg[2]-1); ngs[0]=n0; ngs[1]=n1; ngs[2]=n2;
int off0(nodeStBg[0]),off1(nodeStBg[0]*nodeStBg[1]);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(4*GetNumberOfCellsOfSubLevelMesh(ngs,3));
int *cp(conn->getPointer());
//X
std::vector<int> ngs(2);
int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1); ngs[0]=n0; ngs[1]=n1;
int off0(nodeStBg[0]);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ MCAuto<DataArrayInt> conn(DataArrayInt::New());
conn->alloc(2*GetNumberOfCellsOfSubLevelMesh(ngs,2));
int *cp(conn->getPointer());
//X
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : invalid size of input array of double regarding the structure !");
std::vector<int> dims(GetDimensionsFromCompactFrmt(partCompactFormat));
int nbOfTuplesOfOutField(DeduceNumberOfGivenStructure(dims)),nbComp(fieldOfDbl->getNumberOfComponents());
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfTuplesOfOutField,nbComp);
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfTuplesOfOutField,nbComp);
ret->copyStringInfoFrom(*fieldOfDbl);
double *ptRet(ret->getPointer());
const double *fieldOfDblPtr(fieldOfDbl->begin());
dims[i]=partCompactFormat[i].second-partCompactFormat[i].first;
nbOfItems*=dims[i];
}
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New());
ret->alloc(nbOfItems,1);
int *pt(ret->getPointer());
switch(st.size())