//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// Author : Anthony Geay (CEA/DEN)
#include "MEDCouplingFieldDiscretization.hxx"
#include "MEDCouplingCMesh.hxx"
#include <list>
#include <limits>
#include <sstream>
+#include <numeric>
#include <algorithm>
#include <functional>
const TypeOfField MEDCouplingFieldDiscretizationKriging::TYPE=ON_NODES_KR;
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG2[2]={1.,1.};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG3[3]={0.5555555555555556,0.5555555555555556,0.8888888888888888};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG4[4]={0.347854845137454,0.347854845137454,0.652145154862546,0.652145154862546};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI3[3]={0.16666666666666666,0.16666666666666666,0.16666666666666666};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI6[6]={0.0549758718227661,0.0549758718227661,0.0549758718227661,0.11169079483905,0.11169079483905,0.11169079483905};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_TRI7[7]={0.062969590272413,0.062969590272413,0.062969590272413,0.066197076394253,0.066197076394253,0.066197076394253,0.1125};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD4[4]={1.,1.,1.,1.};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_QUAD9[9]={0.30864197530864196,0.30864197530864196,0.30864197530864196,0.30864197530864196,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.49382716049382713,0.7901234567901234};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_TETRA4[4]={0.041666666666666664,0.041666666666666664,0.041666666666666664,0.041666666666666664};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA6[6]={0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA8[8]={1.,1.,1.,1.,1.,1.,1.,1.};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA27[27]={0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.1714677640603567,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.27434842249657065,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.43895747599451296,0.7023319615912208};
+const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA5[5]={0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333};
+
MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION)
{
}
return isEqual(other,eps);
}
+/*!
+ * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance.
+ */
+MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const int *startCellIds, const int *endCellIds) const
+{
+ return clone();
+}
+
/*!
* Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally.
*/
{
}
+std::size_t MEDCouplingFieldDiscretization::getHeapMemorySize() const
+{
+ return 0;
+}
+
/*!
* Computes normL1 of DataArrayDouble instance arr.
* @param res output parameter expected to be of size arr->getNumberOfComponents();
*/
void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception)
{
- MEDCouplingFieldDouble *vol=getMeasureField(mesh,true);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
int nbOfCompo=arr->getNumberOfComponents();
int nbOfElems=getNumberOfTuples(mesh);
std::fill(res,res+nbOfCompo,0.);
deno+=v;
}
std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
- vol->decrRef();
}
/*!
*/
void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception)
{
- MEDCouplingFieldDouble *vol=getMeasureField(mesh,true);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,true);
int nbOfCompo=arr->getNumberOfComponents();
int nbOfElems=getNumberOfTuples(mesh);
std::fill(res,res+nbOfCompo,0.);
}
std::transform(res,res+nbOfCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
std::transform(res,res+nbOfCompo,res,std::ptr_fun<double,double>(std::sqrt));
- vol->decrRef();
}
/*!
*/
void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception)
{
- MEDCouplingFieldDouble *vol=getMeasureField(mesh,isWAbs);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,isWAbs);
int nbOfCompo=arr->getNumberOfComponents();
int nbOfElems=getNumberOfTuples(mesh);
std::fill(res,res+nbOfCompo,0.);
std::transform(tmp,tmp+nbOfCompo,res,res,std::plus<double>());
}
delete [] tmp;
- vol->decrRef();
}
void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const
throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
}
+std::set<int> MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+ throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
+}
+
void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
{
throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
}
-void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, DataArrayDouble *arr, const char *msg)
+void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const char *msg)
{
int oldNbOfElems=arr->getNumberOfTuples();
int nbOfComp=arr->getNumberOfComponents();
- int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1;
- DataArrayDouble *arrCpy=arr->deepCpy();
+ int newNbOfTuples=newNbOfEntity;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrCpy=arr->deepCpy();
const double *ptSrc=arrCpy->getConstPointer();
arr->reAlloc(newNbOfTuples);
double *ptToFill=arr->getPointer();
//if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
if(*std::max_element((double *)tmp,((double *)tmp)+nbOfComp)>eps)
{
- arrCpy->decrRef();
std::ostringstream oss;
oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
<< " have been merged and " << msg << " field on them are different !";
}
}
}
- arrCpy->decrRef();
}
-void MEDCouplingFieldDiscretization::renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg)
+void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg)
{
int nbOfComp=arr->getNumberOfComponents();
- DataArrayDouble *arrCpy=arr->deepCpy();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrCpy=arr->deepCpy();
const double *ptSrc=arrCpy->getConstPointer();
arr->reAlloc(new2OldSz);
double *ptToFill=arr->getPointer();
int oldNb=new2OldPtr[i];
std::copy(ptSrc+oldNb*nbOfComp,ptSrc+(oldNb+1)*nbOfComp,ptToFill+i*nbOfComp);
}
- arrCpy->decrRef();
}
MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization()
MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getMeasureField : mesh instance specified is NULL !");
return mesh->getMeasureField(isAbs);
}
oss << ") detected outside mesh : unable to apply P0::getValueOnMulti ! ";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- ret->incrRef();
- return ret;
+ return ret.retn();
}
/*!
* Nothing to do. It's not a bug.
*/
-void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const
+void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
{
}
-void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
{
- renumberEntitiesFromO2NArr(epsOnVals,old2New,arr,"Cell");
+ RenumberEntitiesFromO2NArr(epsOnVals,old2New,newSz,arr,"Cell");
}
void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const
{
- renumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell");
+ RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell");
}
/*!
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
ret->alloc((int)std::distance(startCellIds,endCellIds),1);
std::copy(startCellIds,endCellIds,ret->getPointer());
- ret->incrRef(); return ret;
+ return ret.retn();
}
/*!
return umesh2->computeFetchedNodeIds();
}
-void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, DataArrayDouble *arr) const
+void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, int newNbOfNodes, DataArrayDouble *arr) const
{
- renumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,arr,"Node");
+ RenumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,newNbOfNodes,arr,"Node");
}
/*!
* Nothing to do it's not a bug.
*/
-void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
{
}
MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getMeasureField : mesh instance specified is NULL !");
return mesh->getMeasureFieldOnNode(isAbs);
}
oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! ";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- ret->incrRef();
- return ret;
+ return ret.retn();
}
MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0)
_discr_per_cell->decrRef();
}
-MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other):_discr_per_cell(0)
+MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds):_discr_per_cell(0)
{
DataArrayInt *arr=other._discr_per_cell;
if(arr)
- _discr_per_cell=arr->deepCpy();
+ {
+ if(startCellIds==0 && endCellIds==0)
+ _discr_per_cell=arr->deepCpy();
+ else
+ _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds);
+ }
}
void MEDCouplingFieldDiscretizationPerCell::updateTime() const
updateTimeWith(*_discr_per_cell);
}
+std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySize() const
+{
+ std::size_t ret=0;
+ if(_discr_per_cell)
+ ret+=_discr_per_cell->getHeapMemorySize();
+ return ret;
+}
+
void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception)
{
if(!_discr_per_cell)
{
}
-MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other):MEDCouplingFieldDiscretizationPerCell(other),_loc(other._loc)
+MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds, const int *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc)
{
}
return new MEDCouplingFieldDiscretizationGauss(*this);
}
+MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const int *startCellIds, const int *endCellIds) const
+{
+ return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds);
+}
+
std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const
{
std::ostringstream oss; oss << REPR << "." << std::endl;
return oss.str();
}
+std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySize() const
+{
+ std::size_t ret=_loc.capacity()*sizeof(MEDCouplingGaussLocalization);
+ for(std::vector<MEDCouplingGaussLocalization>::const_iterator it=_loc.begin();it!=_loc.end();it++)
+ ret+=(*it).getHeapMemorySize();
+ return MEDCouplingFieldDiscretizationPerCell::getHeapMemorySize()+ret;
+}
+
const char *MEDCouplingFieldDiscretizationGauss::getRepr() const
{
return REPR;
DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const
{
int nbOfTuples=mesh->getNumberOfCells();
- DataArrayInt *ret=DataArrayInt::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
ret->alloc(nbOfTuples+1,1);
int *retPtr=ret->getPointer();
const int *start=_discr_per_cell->getConstPointer();
+ if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !");
+ int maxPossible=(int)_loc.size();
retPtr[0]=0;
for(int i=0;i<nbOfTuples;i++,start++)
- retPtr[i+1]=retPtr[i]+_loc[*start].getNumberOfGaussPt();
- return ret;
+ {
+ if(*start>=0 && *start<maxPossible)
+ retPtr[i+1]=retPtr[i]+_loc[*start].getNumberOfGaussPt();
+ else
+ {
+ std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getOffsetArr : At position #" << i << " the locid = " << *start << " whereas it should be in [0," << maxPossible << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return ret.retn();
}
void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector<DataArrayDouble *>& arrays,
DataArrayDouble *ret=DataArrayDouble::New();
int spaceDim=mesh->getSpaceDimension();
ret->alloc(nbOfTuples,spaceDim);
- std::vector< std::vector<int> > locIds;
+ std::vector< int > locIds;
std::vector<DataArrayInt *> parts=splitIntoSingleGaussDicrPerCellType(locIds);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > parts2(parts.size());
std::copy(parts.begin(),parts.end(),parts2.begin());
for(std::size_t i=0;i<parts2.size();i++)
{
INTERP_KERNEL::GaussCoords calculator;
- for(std::vector<int>::const_iterator it=locIds[i].begin();it!=locIds[i].end();it++)
- {
- const MEDCouplingGaussLocalization& cli=_loc[*it];//curLocInfo
- INTERP_KERNEL::NormalizedCellType typ=cli.getType();
- const std::vector<double>& wg=cli.getWeights();
- calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(),
+ //
+ const MEDCouplingGaussLocalization& cli=_loc[locIds[i]];//curLocInfo
+ INTERP_KERNEL::NormalizedCellType typ=cli.getType();
+ const std::vector<double>& wg=cli.getWeights();
+ calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(),
&cli.getGaussCoords()[0],(int)wg.size(),&cli.getRefCoords()[0],
INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes());
- }
+ //
int nbt=parts2[i]->getNumberOfTuples();
for(const int *w=parts2[i]->getConstPointer();w!=parts2[i]->getConstPointer()+nbt;w++)
- {
- const MEDCouplingGaussLocalization& cli=_loc[*w];
- calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w]));
- }
+ calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w]));
}
ret->copyStringInfoFrom(*umesh->getCoords());
return ret;
MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : mesh instance specified is NULL !");
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
int *retPtr=nbOfNodesPerCell->getPointer();
const int *pt=_discr_per_cell->getConstPointer();
int nbMaxOfLocId=(int)_loc.size();
- for(int i=0;i<nbOfCells;i++,retPtr++)
+ for(int i=0;i<nbOfCells;i++,retPtr++,pt++)
{
if(*pt>=0 && *pt<nbMaxOfLocId)
*retPtr=_loc[*pt].getNumberOfGaussPt();
/*!
* No implementation needed !
*/
-void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const
+void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
{
}
-void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
{
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
}
int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+ std::set<int> ret=getGaussLocalizationIdsOfOneType(type);
+ if(ret.empty())
+ throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
+ if(ret.size()>1)
+ throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
+ return *ret.begin();
+}
+
+std::set<int> MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
{
if(!_discr_per_cell)
throw INTERP_KERNEL::Exception("No Gauss localization still set !");
for(std::vector<MEDCouplingGaussLocalization>::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++)
if((*iter).getType()==type)
ret.insert(id);
- if(ret.empty())
- throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !");
- if(ret.size()>1)
- throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !");
- return *ret.begin();
+ return ret;
}
void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
valsToFill[i]=_loc[*w].getNumberOfGaussPt();
else
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : orphan cell detected !");
- ret->incrRef();
- return ret;
+ return ret.retn();
}
/*!
{
const int *start=_discr_per_cell->getConstPointer();
int nbOfTuples=_discr_per_cell->getNumberOfTuples();
- int *tmp=new int[_loc.size()];
- std::fill(tmp,tmp+_loc.size(),-2);
+ INTERP_KERNEL::AutoPtr<int> tmp=new int[_loc.size()];
+ std::fill((int *)tmp,(int *)tmp+_loc.size(),-2);
for(const int *w=start;w!=start+nbOfTuples;w++)
if(*w>=0)
tmp[*w]=1;
if(tmp[i]!=-2)
tmp[i]=fid++;
if(fid==(int)_loc.size())
- {//no zip needed
- delete [] tmp;
- return;
- }
+ return;
// zip needed
int *start2=_discr_per_cell->getPointer();
for(int *w2=start2;w2!=start2+nbOfTuples;w2++)
- *w2=tmp[*w2];
+ if(*w2>=0)
+ *w2=tmp[*w2];
std::vector<MEDCouplingGaussLocalization> tmpLoc;
for(int i=0;i<(int)_loc.size();i++)
if(tmp[i]!=-2)
tmpLoc.push_back(_loc[tmp[i]]);
- delete [] tmp;
_loc=tmpLoc;
}
*
* If no descretization is set in 'this' and exception will be thrown.
*/
-std::vector<DataArrayInt *> MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType(std::vector< std::vector<int> >& locIds) const throw(INTERP_KERNEL::Exception)
+std::vector<DataArrayInt *> MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType(std::vector<int>& locIds) const throw(INTERP_KERNEL::Exception)
{
if(!_discr_per_cell)
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType : no descretization set !");
- locIds.clear();
- std::vector<DataArrayInt *> ret;
- const int *discrPerCell=_discr_per_cell->getConstPointer();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=_discr_per_cell->getIdsNotEqual(-1);
- int nbOfTuplesSet=ret2->getNumberOfTuples();
- std::list<int> idsRemaining(ret2->getConstPointer(),ret2->getConstPointer()+nbOfTuplesSet);
- std::list<int>::iterator it=idsRemaining.begin();
- while(it!=idsRemaining.end())
- {
- std::vector<int> ids;
- std::set<int> curLocIds;
- std::set<INTERP_KERNEL::NormalizedCellType> curCellTypes;
- while(it!=idsRemaining.end())
- {
- int curDiscrId=discrPerCell[*it];
- INTERP_KERNEL::NormalizedCellType typ=_loc[curDiscrId].getType();
- if(curCellTypes.find(typ)!=curCellTypes.end())
- {
- if(curLocIds.find(curDiscrId)!=curLocIds.end())
- {
- curLocIds.insert(curDiscrId);
- curCellTypes.insert(typ);
- ids.push_back(*it);
- it=idsRemaining.erase(it);
- }
- else
- it++;
- }
- else
- {
- curLocIds.insert(curDiscrId);
- curCellTypes.insert(typ);
- ids.push_back(*it);
- it=idsRemaining.erase(it);
- }
- }
- it=idsRemaining.begin();
- ret.resize(ret.size()+1);
- DataArrayInt *part=DataArrayInt::New();
- part->alloc((int)ids.size(),1);
- std::copy(ids.begin(),ids.end(),part->getPointer());
- ret.back()=part;
- locIds.resize(locIds.size()+1);
- locIds.back().insert(locIds.back().end(),curLocIds.begin(),curLocIds.end());
- }
- return ret;
+ return _discr_per_cell->partitionByDifferentValues(locIds);
}
MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE()
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
+void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception)
+{
+ if(!mesh || !arr)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !");
+ int nbOfCompo=arr->getNumberOfComponents();
+ std::fill(res,res+nbOfCompo,0.);
+ //
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=getMeasureField(mesh,isWAbs);
+ std::set<INTERP_KERNEL::NormalizedCellType> types=mesh->getAllGeoTypes();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
+ nbOfNodesPerCell->computeOffsets2();
+ const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin();
+ for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=types.begin();it!=types.end();it++)
+ {
+ std::size_t wArrSz=-1;
+ const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz);
+ INTERP_KERNEL::AutoPtr<double> wArr2=new double[wArrSz];
+ double sum=std::accumulate(wArr,wArr+wArrSz,0.);
+ std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies<double>(),1./sum));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=mesh->giveCellsWithType(*it);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell);
+ const int *ptIds2=ids2->begin(),*ptIds=ids->begin();
+ int nbOfCellsWithCurGeoType=ids->getNumberOfTuples();
+ for(int i=0;i<nbOfCellsWithCurGeoType;i++,ptIds++,ptIds2+=wArrSz)
+ {
+ for(int k=0;k<nbOfCompo;k++)
+ {
+ double tmp=0.;
+ for(std::size_t j=0;j<wArrSz;j++)
+ tmp+=arrPtr[nbOfCompo*ptIds2[j]+k]*wArr2[j];
+ res[k]+=tmp*volPtr[*ptIds];
+ }
+ }
+ }
+}
+
+const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception)
+{
+ switch(geoType)
+ {
+ case INTERP_KERNEL::NORM_SEG2:
+ lgth=(int)sizeof(FGP_SEG2)/sizeof(double);
+ return FGP_SEG2;
+ case INTERP_KERNEL::NORM_SEG3:
+ lgth=(int)sizeof(FGP_SEG3)/sizeof(double);
+ return FGP_SEG3;
+ case INTERP_KERNEL::NORM_SEG4:
+ lgth=(int)sizeof(FGP_SEG4)/sizeof(double);
+ return FGP_SEG4;
+ case INTERP_KERNEL::NORM_TRI3:
+ lgth=(int)sizeof(FGP_TRI3)/sizeof(double);
+ return FGP_TRI3;
+ case INTERP_KERNEL::NORM_TRI6:
+ lgth=(int)sizeof(FGP_TRI6)/sizeof(double);
+ return FGP_TRI6;
+ case INTERP_KERNEL::NORM_TRI7:
+ lgth=(int)sizeof(FGP_TRI7)/sizeof(double);
+ return FGP_TRI7;
+ case INTERP_KERNEL::NORM_QUAD4:
+ lgth=(int)sizeof(FGP_QUAD4)/sizeof(double);
+ return FGP_QUAD4;
+ case INTERP_KERNEL::NORM_QUAD9:
+ lgth=(int)sizeof(FGP_QUAD9)/sizeof(double);
+ return FGP_QUAD9;
+ case INTERP_KERNEL::NORM_TETRA4:
+ lgth=(int)sizeof(FGP_TETRA4)/sizeof(double);
+ return FGP_TETRA4;
+ case INTERP_KERNEL::NORM_PENTA6:
+ lgth=(int)sizeof(FGP_PENTA6)/sizeof(double);
+ return FGP_PENTA6;
+ case INTERP_KERNEL::NORM_HEXA8:
+ lgth=(int)sizeof(FGP_HEXA8)/sizeof(double);
+ return FGP_HEXA8;
+ case INTERP_KERNEL::NORM_HEXA27:
+ lgth=(int)sizeof(FGP_HEXA27)/sizeof(double);
+ return FGP_HEXA27;
+ case INTERP_KERNEL::NORM_PYRA5:
+ lgth=(int)sizeof(FGP_PYRA5)/sizeof(double);
+ return FGP_PYRA5;
+ default:
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType : only SEG[2,3,4], TRI[3,6,7], QUAD[4,9], TETRA4, PENTA6, HEXA[8,27], PYRA5 supported !");
+ }
+}
+
void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd,
DataArrayInt *&cellRest)
{
MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getMeasureField : mesh instance specified is NULL !");
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
{
if(!mesh)
throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds : null mesh !");
- const MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh=mesh->buildUnstructured();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=umesh->computeNbOfNodesPerCell();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
nbOfNodesPerCell->computeOffsets2();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1);
return sel->buildExplicitArrByRanges(nbOfNodesPerCell);
/*!
* No implementation needed !
*/
-void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const
+void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const
{
}
-void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const
{
throw INTERP_KERNEL::Exception("Not implemented yet !");
}
MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationKriging::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const
{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getMeasureField : mesh instance specified is NULL !");
throw INTERP_KERNEL::Exception("getMeasureField on FieldDiscretizationKriging : not implemented yet !");
}
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
ret->alloc(nbOfTargetPoints,nbOfCompo);
INTERP_KERNEL::matrixProduct(KnewiK->getConstPointer(),1,nbOfPts+delta,matrix3->getConstPointer(),nbOfPts+delta,nbOfTargetPoints*nbOfCompo,ret->getPointer());
- ret->incrRef();
- return ret;
+ return ret.retn();
}
/*!
{
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=getLocalizationOfDiscValues(mesh);
int nbOfPts=coords->getNumberOfTuples();
- int dimension=coords->getNumberOfComponents();
+ //int dimension=coords->getNumberOfComponents();
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> matrix=coords->buildEuclidianDistanceDenseMatrix();
operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer());
// Drift
double *work=std::copy(arr->begin(),arr->end(),arr2->getPointer());
std::fill(work,work+isDrift,0.);
INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbOfPts+isDrift,nbOfPts+isDrift,arr2->getConstPointer(),nbOfPts+isDrift,1,KnewiK->getPointer());
- KnewiK->incrRef();
- return KnewiK;
+ return KnewiK.retn();
}
/*!
destWork+=spaceDimension;
}
//
- ret->incrRef();
- return ret;
+ return ret.retn();
}