X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldDiscretization.cxx;h=4790b4cb95d900865a2a569eb0ad42dd3ed9d460;hb=0c9d48870957c4a9f6f82fc8e2c569780a5f886b;hp=2b79696e857281fdee07aef2bddfaf3959ade04e;hpb=97e267c35d896c3c401989a4a165087c3bebd708;p=modules%2Fmed.git diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 2b79696e8..4790b4cb9 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -66,12 +66,13 @@ const TypeOfField MEDCouplingFieldDiscretizationKriging::TYPE=ON_NODES_KR; // doc is here http://www.code-aster.org/V2/doc/default/fr/man_r/r3/r3.01.01.pdf const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG2[2]={1.,1.}; -const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG3[3]={0.5555555555555556,0.5555555555555556,0.8888888888888888}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG3[3]={0.5555555555555556,0.8888888888888888,0.5555555555555556}; 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_QUAD8[8]={1.,1.,1.,1.,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}; @@ -79,7 +80,7 @@ const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA8[8]={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}; const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG2[2]={-1.,1.}; -const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG3[3]={-1.,0.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG3[3]={-1.,1.,0.}; const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG4[4]={-1.,1.,-0.3333333333333333,0.3333333333333333}; const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI3[6]={0.,0.,1.,0.,0.,1.}; const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI6[12]={0.,0.,1.,0.,0.,1.,0.5,0.,0.5,0.5,0.,0.5}; @@ -96,6 +97,20 @@ const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA20[60]={-1.,-1.,-1., const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA27[81]={-1.,-1.,-1.,1.,-1.,-1.,1.,1.,-1.,-1.,1.,-1.,-1.,-1.,1.,1.,-1.,1.,1.,1.,1.,-1.,1.,1.,0.,-1.,-1.,1.,0.,-1.,0.,1.,-1.,-1.,0.,-1.,-1.,-1.,0.,1.,-1.,0.,1.,1.,0.,-1.,1.,0.,0.,-1.,1.,1.,0.,1.,0.,1.,1.,-1.,0.,1.,0.,0.,-1.,0.,-1.,0.,1.,0.,0.,0.,1.,0.,-1.,0.,0.,0.,0.,1.,0.,0.,0.}; const double MEDCouplingFieldDiscretizationGaussNE::REF_PYRA5[15]={1.,0.,0.,0.,1.,0.,-1.,0.,0.,0.,-1.,0.,0.,0.,1.}; const double MEDCouplingFieldDiscretizationGaussNE::REF_PYRA13[39]={1.,0.,0.,0.,1.,0.,-1.,0.,0.,0.,-1.,0.,0.,0.,1.,0.5,0.5,0.,-0.5,0.5,0.,-0.5,-0.5,0.,0.5,-0.5,0.,0.5,0.,0.5,0.,0.5,0.5,-0.5,0.,0.5,0.,-0.5,0.5}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG2[2]={0.577350269189626,-0.577350269189626}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG3[3]={-0.774596669241,0.,0.774596669241}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_SEG4[4]={0.339981043584856,-0.339981043584856,0.861136311594053,-0.861136311594053}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI3[6]={0.16666666666666667,0.16666666666666667,0.6666666666666667,0.16666666666666667,0.16666666666666667,0.6666666666666667}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI6[12]={0.091576213509771,0.091576213509771,0.816847572980458,0.091576213509771,0.091576213509771,0.816847572980458,0.445948490915965,0.10810301816807,0.445948490915965,0.445948490915965,0.10810301816807,0.445948490915965}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_TRI7[14]={0.3333333333333333,0.3333333333333333,0.470142064105115,0.470142064105115,0.05971587178977,0.470142064105115,0.470142064105115,0.05971587178977,0.101286507323456,0.101286507323456,0.797426985353088,0.101286507323456,0.101286507323456,0.797426985353088}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD4[8]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD8[16]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.,-0.774596669241483,0.774596669241483,0.,0.,0.774596669241483,-0.774596669241483,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_QUAD9[18]={-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.,-0.774596669241483,0.774596669241483,0.,0.,0.774596669241483,-0.774596669241483,0.,0.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_TETRA4[12]={0.1381966011250105,0.1381966011250105,0.1381966011250105,0.1381966011250105,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.5854101966249685,0.1381966011250105,0.1381966011250105}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_PENTA6[18]={-0.5773502691896258,0.5,0.5,-0.5773502691896258,0.,0.5,-0.5773502691896258,0.5,0.,0.5773502691896258,0.5,0.5,0.5773502691896258,0.,0.5,0.5773502691896258,0.5,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_HEXA8[24]={-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258,-0.5773502691896258,-0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258,-0.5773502691896258,0.5773502691896258,0.5773502691896258,0.5773502691896258}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_HEXA27[81]={-0.7745966692414834,-0.7745966692414834,-0.7745966692414834,-0.7745966692414834,-0.7745966692414834,0.,-0.7745966692414834,-0.7745966692414834,0.7745966692414834,-0.7745966692414834,0.,-0.7745966692414834,-0.7745966692414834,0.,0.,-0.7745966692414834,0.,0.7745966692414834,-0.7745966692414834,0.7745966692414834,-0.7745966692414834,-0.7745966692414834,0.7745966692414834,0.,-0.7745966692414834,0.7745966692414834,0.7745966692414834,0.,-0.7745966692414834,-0.7745966692414834,0,-0.7745966692414834,0.,0.,-0.7745966692414834,0.7745966692414834,0.,0.,-0.7745966692414834,0.,0.,0.,0.,0.,0.7745966692414834,0.,0.7745966692414834,-0.7745966692414834,0.,0.7745966692414834,0.,0.,0.7745966692414834,0.7745966692414834,0.7745966692414834,-0.7745966692414834,-0.7745966692414834,0.7745966692414834,-0.7745966692414834,0.,0.7745966692414834,-0.7745966692414834,0.7745966692414834,0.7745966692414834,0,-0.7745966692414834,0.7745966692414834,0.,0.,0.7745966692414834,0.,0.7745966692414834,0.7745966692414834,0.7745966692414834,-0.7745966692414834,0.7745966692414834,0.7745966692414834,0.,0.7745966692414834,0.7745966692414834,0.7745966692414834}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_PYRA5[15]={0.5,0.,0.1531754163448146,0.,0.5,0.1531754163448146,-0.5,0.,0.1531754163448146,0.,-0.5,0.1531754163448146,0.,0.,0.6372983346207416}; MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION) { @@ -120,18 +135,17 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::New(TypeOfField } } -TypeOfField MEDCouplingFieldDiscretization::GetTypeOfFieldFromStringRepr(const char *repr) throw(INTERP_KERNEL::Exception) +TypeOfField MEDCouplingFieldDiscretization::GetTypeOfFieldFromStringRepr(const std::string& repr) { - std::string reprCpp(repr); - if(reprCpp==MEDCouplingFieldDiscretizationP0::REPR) + if(repr==MEDCouplingFieldDiscretizationP0::REPR) return MEDCouplingFieldDiscretizationP0::TYPE; - if(reprCpp==MEDCouplingFieldDiscretizationP1::REPR) + if(repr==MEDCouplingFieldDiscretizationP1::REPR) return MEDCouplingFieldDiscretizationP1::TYPE; - if(reprCpp==MEDCouplingFieldDiscretizationGauss::REPR) + if(repr==MEDCouplingFieldDiscretizationGauss::REPR) return MEDCouplingFieldDiscretizationGauss::TYPE; - if(reprCpp==MEDCouplingFieldDiscretizationGaussNE::REPR) + if(repr==MEDCouplingFieldDiscretizationGaussNE::REPR) return MEDCouplingFieldDiscretizationGaussNE::TYPE; - if(reprCpp==MEDCouplingFieldDiscretizationKriging::REPR) + if(repr==MEDCouplingFieldDiscretizationKriging::REPR) return MEDCouplingFieldDiscretizationKriging::TYPE; throw INTERP_KERNEL::Exception("Representation does not match with any field discretization !"); } @@ -164,6 +178,14 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const return clone(); } +/*! + * For all field discretization excepted GaussPts the slice( \a beginCellId, \a endCellIds, \a stepCellId ) has no impact on the cloned instance. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const +{ + return clone(); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -171,17 +193,22 @@ void MEDCouplingFieldDiscretization::updateTime() const { } -std::size_t MEDCouplingFieldDiscretization::getHeapMemorySize() const +std::size_t MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren() const { return 0; } +std::vector MEDCouplingFieldDiscretization::getDirectChildren() const +{ + return std::vector(); +} + /*! * Computes normL1 of DataArrayDouble instance arr. * @param res output parameter expected to be of size arr->getNumberOfComponents(); * @throw when the field discretization fails on getMeasure fields (gauss points for example) */ -void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const { MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,true); int nbOfCompo=arr->getNumberOfComponents(); @@ -205,7 +232,7 @@ void MEDCouplingFieldDiscretization::normL1(const MEDCouplingMesh *mesh, const D * @param res output parameter expected to be of size arr->getNumberOfComponents(); * @throw when the field discretization fails on getMeasure fields (gauss points for example) */ -void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const { MEDCouplingAutoRefCountObjectPtr vol=getMeasureField(mesh,true); int nbOfCompo=arr->getNumberOfComponents(); @@ -230,7 +257,7 @@ void MEDCouplingFieldDiscretization::normL2(const MEDCouplingMesh *mesh, const D * @param res output parameter expected to be of size arr->getNumberOfComponents(); * @throw when the field discretization fails on getMeasure fields (gauss points for example) */ -void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : mesh is NULL !"); @@ -256,6 +283,22 @@ void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const } } +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretization::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretization::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretization::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + MEDCouplingAutoRefCountObjectPtr da=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + return buildSubMeshData(mesh,da->begin(),da->end(),di); +} + void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const { arr=0; @@ -291,12 +334,11 @@ void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +std::set MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const std::string& msg) { + if(!arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !"); int oldNbOfElems=arr->getNumberOfTuples(); int nbOfComp=arr->getNumberOfComponents(); int newNbOfTuples=newNbOfEntity; @@ -389,7 +433,7 @@ void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, cons } } -void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const std::string& msg) { int nbOfComp=arr->getNumberOfComponents(); MEDCouplingAutoRefCountObjectPtr arrCpy=arr->deepCpy(); @@ -434,6 +478,11 @@ const char *MEDCouplingFieldDiscretizationP0::getRepr() const bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -441,18 +490,62 @@ bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDis return ret; } -int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfCells(); } +/*! + * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input. + * The input code coherency is also checked regarding spatial discretization of \a this. + * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned. + * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution). + */ +int MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationP0::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + return ret; +} + int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -460,23 +553,27 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMe return ret; } -void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, +void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); - for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) + for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) { if(*it) (*it)->renumberInPlace(array); } if(check) - delete [] array; + free(const_cast(array)); } DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getBarycenterAndOwner(); } @@ -493,12 +590,19 @@ void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const trueTupleRestriction=tmp2.retn(); } -void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const { + stream << "P0 spatial discretization."; } -void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const { +} + +void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const +{ + if(!mesh || !da) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh or DataArray !"); if(mesh->getNumberOfCells()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -517,6 +621,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !"); @@ -534,8 +640,11 @@ void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { - std::vector elts,eltsIndex; - mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr eltsArr,eltsIndexArr; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr); + const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin()); int spaceDim=mesh->getSpaceDimension(); int nbOfComponents=arr->getNumberOfComponents(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); @@ -591,37 +700,104 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellI * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end). * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh. * Example : The first cell id of returned mesh has the (*di)[0] id in 'mesh' + * + * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange */ MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - MEDCouplingMesh *ret=mesh->buildPart(start,end); - di=DataArrayInt::New(); - di->alloc((int)std::distance(start,end),1); - int *pt=di->getPointer(); - std::copy(start,end,pt); - return ret; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + MEDCouplingAutoRefCountObjectPtr diSafe=DataArrayInt::New(); + diSafe->alloc((int)std::distance(start,end),1); + std::copy(start,end,diSafe->getPointer()); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationP0::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds; + return ret.retn(); } -int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfNodes(); } +/*! + * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input. + * The input code coherency is also checked regarding spatial discretization of \a this. + * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned. + * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution). + */ +int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + return ret; +} + int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfNodes(); } /*! * Nothing to do here. */ -void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector& arrays, +void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { } DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfNodes(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -631,6 +807,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCoupl DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getCoordinatesAndOwner(); } @@ -649,8 +827,10 @@ void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(c trueTupleRestriction=ret2.retn(); } -void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const { + if(!mesh || !da) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh or DataArray !"); if(mesh->getNumberOfNodes()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -667,16 +847,44 @@ void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCoupl */ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - MEDCouplingMesh *ret=mesh->buildPartAndReduceNodes(start,end,di); - DataArrayInt *di2=di->invertArrayO2N2N2O(ret->getNumberOfNodes()); - di->decrRef(); - di=di2; - return ret; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !"); + DataArrayInt *diTmp=0; + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartAndReduceNodes(start,end,diTmp); + MEDCouplingAutoRefCountObjectPtr diTmpSafe(diTmp); + MEDCouplingAutoRefCountObjectPtr di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes()); + di=di2.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationNodes::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationNodes::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !"); + DataArrayInt *diTmp=0; + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp); + if(diTmp) + { + MEDCouplingAutoRefCountObjectPtr diTmpSafe(diTmp); + MEDCouplingAutoRefCountObjectPtr di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes()); + di=di2.retn(); + } + return ret.retn(); } /*! * This method returns a tuple ids selection from cell ids selection [start;end). - * This method is called by MEDCouplingFieldDiscretizationP0::buildSubMeshData to return parameter \b di. + * This method is called by MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData to return parameter \b di. * Here for P1 only nodes fetched by submesh of mesh[startCellIds:endCellIds) is returned ! * * \return a newly allocated array containing ids to select into the DataArrayDouble of the field. @@ -685,7 +893,7 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const M DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const { if(!mesh) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : null mesh !"); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !"); const MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured(); MEDCouplingAutoRefCountObjectPtr umesh2=static_cast(umesh->buildPartOfMySelf(startCellIds,endCellIds,true)); return umesh2->computeFetchedNodeIds(); @@ -746,6 +954,11 @@ const char *MEDCouplingFieldDiscretizationP1::getRepr() const bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -753,7 +966,7 @@ bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDis return ret; } -void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationP1::checkCompatibilityWithNature(NatureOfField nat) const { if(nat!=ConservativeVolumic) throw INTERP_KERNEL::Exception("Invalid nature for P1 field : expected ConservativeVolumic !"); @@ -768,6 +981,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !"); @@ -783,6 +998,8 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co */ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !"); std::vector conn; std::vector coo; mesh->getNodeIdsOfCell(cellId,conn); @@ -808,8 +1025,11 @@ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mes DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { - std::vector elts,eltsIndex; - mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr eltsArr,eltsIndexArr; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr); + const int *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin()); int spaceDim=mesh->getSpaceDimension(); int nbOfComponents=arr->getNumberOfComponents(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); @@ -828,6 +1048,11 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArr return ret.retn(); } +void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const +{ + stream << "P1 spatial discretization."; +} + MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0) { } @@ -853,24 +1078,41 @@ MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(con } } +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, int beginCellIds, int endCellIds, int stepCellIds):_discr_per_cell(0) +{ + DataArrayInt *arr=other._discr_per_cell; + if(arr) + { + _discr_per_cell=arr->selectByTupleId2(beginCellIds,endCellIds,stepCellIds); + } +} + void MEDCouplingFieldDiscretizationPerCell::updateTime() const { if(_discr_per_cell) updateTimeWith(*_discr_per_cell); } -std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySize() const +std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren() const { - std::size_t ret=0; + std::size_t ret(MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren()); + return ret; +} + +std::vector MEDCouplingFieldDiscretizationPerCell::getDirectChildren() const +{ + std::vector ret(MEDCouplingFieldDiscretization::getDirectChildren()); if(_discr_per_cell) - ret+=_discr_per_cell->getHeapMemorySize(); + ret.push_back(_discr_per_cell); return ret; } -void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh or DataArray !"); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); if(nbOfTuples!=mesh->getNumberOfCells()) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !"); @@ -878,10 +1120,15 @@ void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCoupl bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined."; + return false; + } const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast(other); if(!otherC) { - reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other."; + reason="Spatial discretization of this is ON_GAUSS, which is not the case of other."; return false; } if(_discr_per_cell==0) @@ -910,7 +1157,7 @@ bool MEDCouplingFieldDiscretizationPerCell::isEqualWithoutConsideringStr(const M * This method is typically the first step of renumbering. The impact on _discr_per_cell is necessary here. * virtualy by this method. */ -void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, bool check) { int nbCells=_discr_per_cell->getNumberOfTuples(); const int *array=old2NewBg; @@ -922,22 +1169,24 @@ void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, _discr_per_cell=dpc; // if(check) - delete [] const_cast(array); + free(const_cast(array)); } -void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m) +void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !"); if(!_discr_per_cell) { _discr_per_cell=DataArrayInt::New(); - int nbTuples=m->getNumberOfCells(); + int nbTuples=mesh->getNumberOfCells(); _discr_per_cell->alloc(nbTuples,1); int *ptr=_discr_per_cell->getPointer(); std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE); } } -void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : no discretization defined !"); @@ -956,7 +1205,7 @@ void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const throw(INT * * If no descretization is set in 'this' and exception will be thrown. */ -std::vector MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector& locIds) const throw(INTERP_KERNEL::Exception) +std::vector MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector& locIds) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType : no descretization set !"); @@ -968,6 +1217,19 @@ const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() c return _discr_per_cell; } +void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids) +{ + if(adids!=_discr_per_cell) + { + if(_discr_per_cell) + _discr_per_cell->decrRef(); + _discr_per_cell=const_cast(adids); + if(_discr_per_cell) + _discr_per_cell->incrRef(); + declareAsNew(); + } +} + MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() { } @@ -976,6 +1238,10 @@ MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const M { } +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, int beginCellIds, int endCellIds, int stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc) +{ +} + TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const { return TYPE; @@ -983,6 +1249,11 @@ TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast(other); if(!otherC) { @@ -1038,6 +1309,11 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(c return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds); } +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds); +} + std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { std::ostringstream oss; oss << REPR << "." << std::endl; @@ -1061,12 +1337,13 @@ std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const return oss.str(); } -std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySize() const +std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySizeWithoutChildren() const { - std::size_t ret=_loc.capacity()*sizeof(MEDCouplingGaussLocalization); + std::size_t ret(MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren()); + ret+=_loc.capacity()*sizeof(MEDCouplingGaussLocalization); for(std::vector::const_iterator it=_loc.begin();it!=_loc.end();it++) - ret+=(*it).getHeapMemorySize(); - return MEDCouplingFieldDiscretizationPerCell::getHeapMemorySize()+ret; + ret+=(*it).getMemorySize(); + return ret; } const char *MEDCouplingFieldDiscretizationGauss::getRepr() const @@ -1074,25 +1351,87 @@ const char *MEDCouplingFieldDiscretizationGauss::getRepr() const return REPR; } -int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const throw(INTERP_KERNEL::Exception) +/*! + * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input. + * The input code coherency is also checked regarding spatial discretization of \a this. + * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned. + * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution). + */ +int MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const +{ + if(!_discr_per_cell || !_discr_per_cell->isAllocated() || _discr_per_cell->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode"); + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret=0; + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk; + } + if(ret!=_discr_per_cell->getNumberOfTuples()) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::getNumberOfTuplesExpectedRegardingCode : input code points to " << ret << " cells whereas discretization percell array lgth is " << _discr_per_cell->getNumberOfTuples() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return getNumberOfTuples(0);//0 is not an error ! It is to be sure that input mesh is not used +} + +int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const { int ret=0; if (_discr_per_cell == 0) throw INTERP_KERNEL::Exception("Discretization is not initialized!"); const int *dcPtr=_discr_per_cell->getConstPointer(); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + int maxSz=(int)_loc.size(); for(const int *w=dcPtr;w!=dcPtr+nbOfTuples;w++) - ret+=_loc[*w].getNumberOfGaussPt(); + { + if(*w>=0 && *wgetNumberOfCells(); } +/*! + * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField + * and a call to DataArrayDouble::computeOffsets2 on the returned array. + */ DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1115,9 +1454,11 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplin return ret.retn(); } -void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, +void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1137,16 +1478,18 @@ void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplin array2[j]=array3[array[i]]+k; } delete [] array3; - for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) + for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) if(*it) (*it)->renumberInPlace(array2); delete [] array2; if(check) - delete [] const_cast(array); + free(const_cast(array)); } DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !"); checkNoOrphanCells(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(mesh); @@ -1200,7 +1543,7 @@ void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(con /*! * Empty : not a bug */ -void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const { } @@ -1267,15 +1610,16 @@ void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vecto delete [] tmp; } -double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, - int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) +double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const { int offset=getOffsetOfCell(cellId); return da->getIJ(offset+nodeIdInCell,compoId); } -void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const { + if(!mesh || !da) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh or DataArray !"); MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da); for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) (*iter).checkCoherency(); @@ -1375,8 +1719,58 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const Data MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - di=computeTupleIdsToSelectFromCellIds(mesh,start,end); - return mesh->buildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range + return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : NULL input mesh !"); + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : no discretization array set !"); + di=0; beginOut=0; endOut=0; stepOut=stepCellIds; + const char msg[]="MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : cell #"; + int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + const int *w=_discr_per_cell->begin(); + int nbMaxOfLocId=(int)_loc.size(); + for(int i=0;i=0 && *w=endCellIds) + break; + } + else + { std::ostringstream oss; oss << msg << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + } + else + { std::ostringstream oss; oss << msg << i << " is detected as orphan !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + } + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + return ret.retn(); } /*! @@ -1390,20 +1784,10 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCe { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !"); - if(!_discr_per_cell) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null discretization ids !"); + MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer int nbOfCells=mesh->getNumberOfCells(); if(_discr_per_cell->getNumberOfTuples()!=nbOfCells) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : mismatch of nb of tuples of cell ids array and number of cells !"); - MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=DataArrayInt::New(); nbOfNodesPerCell->alloc(nbOfCells,1); - int *retPtr=nbOfNodesPerCell->getPointer(); - const int *pt=_discr_per_cell->getConstPointer(); - int nbMaxOfLocId=(int)_loc.size(); - for(int i=0;i=0 && *ptcomputeOffsets2(); MEDCouplingAutoRefCountObjectPtr sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1); return sel->buildExplicitArrByRanges(nbOfNodesPerCell); @@ -1426,41 +1810,45 @@ void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCoupli throw INTERP_KERNEL::Exception("Number of cells has changed and becomes higher with some cells that have been split ! Unable to conserve the Gauss field !"); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !"); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); - if((int)cm.getDimension()!=m->getMeshDimension()) + if((int)cm.getDimension()!=mesh->getMeshDimension()) { - std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << m->getMeshDimension(); + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension(); oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - buildDiscrPerCellIfNecessary(m); + buildDiscrPerCellIfNecessary(mesh); int id=(int)_loc.size(); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); _loc.push_back(elt); int *ptr=_discr_per_cell->getPointer(); - int nbCells=m->getNumberOfCells(); + int nbCells=mesh->getNumberOfCells(); for(int i=0;igetTypeOfCell(i)==type) + if(mesh->getTypeOfCell(i)==type) ptr[i]=id; zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { - buildDiscrPerCellIfNecessary(m); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !"); + buildDiscrPerCellIfNecessary(mesh); if(std::distance(begin,end)<1) throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !"); - INTERP_KERNEL::NormalizedCellType type=m->getTypeOfCell(*begin); + INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); int id=(int)_loc.size(); int *ptr=_discr_per_cell->getPointer(); for(const int *w=begin+1;w!=end;w++) { - if(m->getTypeOfCell(*w)!=type) + if(mesh->getTypeOfCell(*w)!=type) { std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -1474,7 +1862,7 @@ void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDC zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() { if(_discr_per_cell) { @@ -1484,28 +1872,47 @@ void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP _loc.clear(); } -MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) +{ + if(locId<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !"); + int sz=(int)_loc.size(); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + if(locId>=sz) + _loc.resize(locId+1,gLoc); + _loc[locId]=loc; +} + +void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz) +{ + if(newSz<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !"); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + _loc.resize(newSz,gLoc); +} + +MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) { checkLocalizationId(locId); return _loc[locId]; } -int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const { return (int)_loc.size(); } -int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("No Gauss localization still set !"); - int locId=_discr_per_cell->getConstPointer()[cellId]; + int locId=_discr_per_cell->begin()[cellId]; if(locId<0) throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !"); return locId; } -int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const { std::set ret=getGaussLocalizationIdsOfOneType(type); if(ret.empty()) @@ -1515,7 +1922,7 @@ int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_ return *ret.begin(); } -std::set MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +std::set MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("No Gauss localization still set !"); @@ -1527,7 +1934,7 @@ std::set MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneT return ret; } -void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const { if(locId<0 || locId>=(int)_loc.size()) throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !"); @@ -1538,19 +1945,19 @@ void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int cellIds.push_back(i); } -const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) +const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) const { checkLocalizationId(locId); return _loc[locId]; } -void MEDCouplingFieldDiscretizationGauss::checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::checkLocalizationId(int locId) const { if(locId<0 || locId>=(int)_loc.size()) throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !"); } -int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception) +int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const { int ret=0; const int *start=_discr_per_cell->getConstPointer(); @@ -1565,23 +1972,40 @@ int MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(int cellId) const throw * This method returns a newly created array with number of tuples equals to '_discr_per_cell->getNumberOfTuples' and number of components equal to 1. * The i_th tuple in returned array is the number of gauss point if the corresponding cell. */ -DataArrayInt *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField() const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField() const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : no discretization array set !"); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - const int *w=_discr_per_cell->getConstPointer(); + const int *w=_discr_per_cell->begin(); ret->alloc(nbOfTuples,1); int *valsToFill=ret->getPointer(); + int nbMaxOfLocId=(int)_loc.size(); for(int i=0;i=0 && *wgetConstPointer(); + const int *start=_discr_per_cell->begin(); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); INTERP_KERNEL::AutoPtr tmp=new int[_loc.size()]; std::fill((int *)tmp,(int *)tmp+_loc.size(),-2); @@ -1610,7 +2034,7 @@ void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations() std::vector tmpLoc; for(int i=0;i<(int)_loc.size();i++) if(tmp[i]!=-2) - tmpLoc.push_back(_loc[tmp[i]]); + tmpLoc.push_back(_loc[i]); _loc=tmpLoc; } @@ -1645,6 +2069,11 @@ const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -1652,8 +2081,54 @@ bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFie return ret; } -int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +/*! + * This method returns the number of tuples regarding exclusively the input code \b without \b using \b a \b mesh \b in \b input. + * The input code coherency is also checked regarding spatial discretization of \a this. + * If an incoherency is detected, an exception will be thrown. If the input code is coherent, the number of tuples expected is returned. + * The number of tuples expected is equal to those to have a valid field lying on \a this and having a mesh fitting perfectly the input code (geometric type distribution). + */ +int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode(const std::vector& code, const std::vector& idsPerType) const +{ + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : invalid input code !"); + int nbOfSplit=(int)idsPerType.size(); + int nbOfTypes=(int)code.size()/3; + int ret(0); + for(int i=0;i=nbOfSplit) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input code points to pos " << pos << " in typeid " << i << " ! Should be in [0," << nbOfSplit << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayInt *ids(idsPerType[pos]); + if(!ids || !ids->isAllocated() || ids->getNumberOfComponents()!=1 || ids->getNumberOfTuples()!=nbOfEltInChunk || ids->getMinValueInArray()<0) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuplesExpectedRegardingCode : input pfl chunck at pos " << pos << " should have " << i << " tuples and one component and with ids all >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret+=nbOfEltInChunk*(int)cm.getNumberOfNodes(); + } + return ret; +} + +int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !"); int ret=0; int nbOfCells=mesh->getNumberOfCells(); for(int i=0;igetNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1690,9 +2169,11 @@ DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCoupl return ret; } -void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, +void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1716,16 +2197,18 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCoupl array2[j]=array3[array[i]]+k; } delete [] array3; - for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) + for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) if(*it) (*it)->renumberInPlace(array2); delete [] array2; if(check) - delete [] const_cast(array); + free(const_cast(array)); } DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(umesh); @@ -1746,7 +2229,7 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscVal /*! * Reimplemented from MEDCouplingFieldDiscretization::integral for performance reason. The default implementation is valid too for GAUSS_NE spatial discretization. */ -void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const { if(!mesh || !arr) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !"); @@ -1782,7 +2265,7 @@ void MEDCouplingFieldDiscretizationGaussNE::integral(const MEDCouplingMesh *mesh } } -const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception) +const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) { switch(geoType) { @@ -1807,6 +2290,9 @@ const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometric case INTERP_KERNEL::NORM_QUAD4: lgth=(int)sizeof(FGP_QUAD4)/sizeof(double); return FGP_QUAD4; + case INTERP_KERNEL::NORM_QUAD8: + lgth=(int)sizeof(FGP_QUAD8)/sizeof(double); + return FGP_QUAD8; case INTERP_KERNEL::NORM_QUAD9: lgth=(int)sizeof(FGP_QUAD9)/sizeof(double); return FGP_QUAD9; @@ -1830,7 +2316,7 @@ const double *MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometric } } -const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception) +const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) { switch(geoType) { @@ -1893,6 +2379,85 @@ const double *MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricTy } } +const double *MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) +{ + switch(geoType) + { + case INTERP_KERNEL::NORM_SEG2: + { + lgth=(int)sizeof(LOC_SEG2)/sizeof(double); + return LOC_SEG2; + } + case INTERP_KERNEL::NORM_SEG3: + { + lgth=(int)sizeof(LOC_SEG3)/sizeof(double); + return LOC_SEG3; + } + case INTERP_KERNEL::NORM_SEG4: + { + lgth=(int)sizeof(LOC_SEG4)/sizeof(double); + return LOC_SEG4; + } + case INTERP_KERNEL::NORM_TRI3: + { + lgth=(int)sizeof(LOC_TRI3)/sizeof(double); + return LOC_TRI3; + } + case INTERP_KERNEL::NORM_TRI6: + { + lgth=(int)sizeof(LOC_TRI6)/sizeof(double); + return LOC_TRI6; + } + case INTERP_KERNEL::NORM_TRI7: + { + lgth=(int)sizeof(LOC_TRI7)/sizeof(double); + return LOC_TRI7; + } + case INTERP_KERNEL::NORM_QUAD4: + { + lgth=(int)sizeof(LOC_QUAD4)/sizeof(double); + return LOC_QUAD4; + } + case INTERP_KERNEL::NORM_QUAD8: + { + lgth=(int)sizeof(LOC_QUAD8)/sizeof(double); + return LOC_QUAD8; + } + case INTERP_KERNEL::NORM_QUAD9: + { + lgth=(int)sizeof(LOC_QUAD9)/sizeof(double); + return LOC_QUAD9; + } + case INTERP_KERNEL::NORM_TETRA4: + { + lgth=(int)sizeof(LOC_TETRA4)/sizeof(double); + return LOC_TETRA4; + } + case INTERP_KERNEL::NORM_PENTA6: + { + lgth=(int)sizeof(LOC_PENTA6)/sizeof(double); + return LOC_PENTA6; + } + case INTERP_KERNEL::NORM_HEXA8: + { + lgth=(int)sizeof(LOC_HEXA8)/sizeof(double); + return LOC_HEXA8; + } + case INTERP_KERNEL::NORM_HEXA27: + { + lgth=(int)sizeof(LOC_HEXA27)/sizeof(double); + return LOC_HEXA27; + } + case INTERP_KERNEL::NORM_PYRA5: + { + lgth=(int)sizeof(LOC_PYRA5)/sizeof(double); + return LOC_PYRA5; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType : only SEG[2,3,4], TRI[3,6,7], QUAD[4,8,9], TETRA[4,10], PENTA[6,15], HEXA[8,20,27], PYRA[5,13] supported !"); + } +} + void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *tupleIdsBg, const int *tupleIdsEnd, DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const throw(INTERP_KERNEL::Exception) { @@ -1907,13 +2472,14 @@ void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(c nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction); } -void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const { } -double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, - int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) +double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !"); int offset=0; for(int i=0;igetIJ(offset+nodeIdInCell,compoId); } -void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const { int nbOfTuples=getNumberOfTuples(mesh); if(nbOfTuples!=da->getNumberOfTuples()) @@ -1986,10 +2552,51 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const Da MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - di=computeTupleIdsToSelectFromCellIds(mesh,start,end); - return mesh->buildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range + return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : NULL input mesh !"); + int nbOfCells=mesh->getNumberOfCells(); + di=0; beginOut=0; endOut=0; stepOut=stepCellIds; + const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #"; + for(int i=0;igetTypeOfCell(i); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + if(cm.isDynamic()) + { std::ostringstream oss; oss << msg << i << " presence of dynamic cell (polygons and polyedrons) ! Not implemented !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + int delta=cm.getNumberOfNodes(); + if(i=endCellIds) + break; + } + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + return ret.retn(); } + /*! * This method returns a tuple ids selection from cell ids selection [start;end). * This method is called by MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData to return parameter \b di. @@ -2024,6 +2631,11 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCoup throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingFieldDiscretizationGaussNE::reprQuickOverview(std::ostream& stream) const +{ + stream << "Gauss points on nodes per element spatial discretization."; +} + MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other) { } @@ -2053,7 +2665,7 @@ std::string MEDCouplingFieldDiscretizationKriging::getStringRepr() const return std::string(REPR); } -void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureOfField nat) const { if(nat!=ConservativeVolumic) throw INTERP_KERNEL::Exception("Invalid nature for Kriging field : expected ConservativeVolumic !"); @@ -2061,6 +2673,11 @@ void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureO bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined."; + return false; + } const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -2083,68 +2700,115 @@ void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *ar DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const { - MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); - int nbOfPts=coords->getNumberOfTuples(); - int dimension=coords->getNumberOfComponents(); - // - int delta=0; - MEDCouplingAutoRefCountObjectPtr KnewiK=computeVectorOfCoefficients(mesh,arr,delta); + if(!arr || !arr->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array is null or not allocated !"); + int nbOfRows(getNumberOfMeshPlaces(mesh)); + if(arr->getNumberOfTuples()!=nbOfRows) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array does not have correct number of tuples ! Excepted " << nbOfRows << " having " << arr->getNumberOfTuples() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + int nbCols(-1),nbCompo(arr->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr m(computeEvaluationMatrixOnGivenPts(mesh,loc,nbOfTargetPoints,nbCols)); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + ret->alloc(nbOfTargetPoints,nbCompo); + INTERP_KERNEL::matrixProduct(m->begin(),nbOfTargetPoints,nbCols,arr->begin(),nbOfRows,nbCompo,ret->getPointer()); + return ret.retn(); +} + +void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const +{ + stream << "Kriging spatial discretization."; +} + +/*! + * Returns the matrix of size nbRows = \a nbOfTargetPoints and \a nbCols = \a nbCols. This matrix is useful if + * + * \return the new result matrix to be deallocated by the caller. + */ +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeEvaluationMatrixOnGivenPts(const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints, int& nbCols) const +{ + int isDrift(-1),nbRows(-1); + MEDCouplingAutoRefCountObjectPtr matrixInv(computeInverseMatrix(mesh,isDrift,nbRows)); // + MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); + int nbOfPts(coords->getNumberOfTuples()),dimension(coords->getNumberOfComponents()); MEDCouplingAutoRefCountObjectPtr locArr=DataArrayDouble::New(); locArr->useArray(loc,false,CPP_DEALLOC,nbOfTargetPoints,dimension); + nbCols=nbOfPts; + // MEDCouplingAutoRefCountObjectPtr matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr); - operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfTargetPoints,matrix2->getPointer()); + operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfTargetPoints*nbOfPts,matrix2->getPointer()); + // MEDCouplingAutoRefCountObjectPtr matrix3=DataArrayDouble::New(); - matrix3->alloc((nbOfPts+delta)*nbOfTargetPoints,1); + matrix3->alloc(nbOfTargetPoints*nbRows,1); double *work=matrix3->getPointer(); - const double *workCst=matrix2->getConstPointer(); - const double *workCst2=loc; - for(int i=0;ibegin()),*workCst2(loc); + for(int i=0;igetNumberOfComponents(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - ret->alloc(nbOfTargetPoints,nbOfCompo); - INTERP_KERNEL::matrixProduct(KnewiK->getConstPointer(),1,nbOfPts+delta,matrix3->getConstPointer(),nbOfPts+delta,nbOfTargetPoints*nbOfCompo,ret->getPointer()); - return ret.retn(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + ret->alloc(nbOfTargetPoints,nbRows); + INTERP_KERNEL::matrixProduct(matrix3->begin(),nbOfTargetPoints,nbRows,matrixInv->begin(),nbRows,nbRows,ret->getPointer()); + MEDCouplingAutoRefCountObjectPtr ret2(DataArrayDouble::New()); + ret2->alloc(nbOfTargetPoints*nbOfPts,1); + workCst=ret->begin(); work=ret2->getPointer(); + for(int i=0;igetSpaceDimension() - * \param [in] arr input field DataArrayDouble whose number of tuples must be equal to the number of nodes in \a mesh - * \param [out] isDrift return if drift coefficients are present in the returned vector of coefficients, and if. If different from 0 there is presence of drift coefficients. - * Whatever the value of \a isDrift the number of tuples of returned DataArrayDouble will be equal to \c arr->getNumberOfTuples() + \a isDrift. - * \return a newly allocated array containing coefficients including or not drift coefficient at the end depending the value of \a isDrift parameter. + * \param [out] isDrift return if drift coefficients are present in the returned vector of coefficients. If different from 0 there is presence of drift coefficients. + * \param [out] matSz the size of returned square matrix + * \return the new result matrix to be deallocated by the caller. */ -DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeInverseMatrix(const MEDCouplingMesh *mesh, int& isDrift, int& matSz) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); - //int dimension=coords->getNumberOfComponents(); MEDCouplingAutoRefCountObjectPtr matrix=coords->buildEuclidianDistanceDenseMatrix(); operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer()); // Drift MEDCouplingAutoRefCountObjectPtr matrixWithDrift=performDrift(matrix,coords,isDrift); MEDCouplingAutoRefCountObjectPtr matrixInv=DataArrayDouble::New(); - matrixInv->alloc((nbOfPts+isDrift)*(nbOfPts+isDrift),1); - INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),nbOfPts+isDrift,matrixInv->getPointer()); - // + matSz=nbOfPts+isDrift; + matrixInv->alloc(matSz*matSz,1); + INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),matSz,matrixInv->getPointer()); + return matrixInv.retn(); +} + +/*! + * This method computes coefficients to apply to each representing points of \a mesh, that is to say the nodes of \a mesh given a field array \a arr whose + * number of tuples should be equal to the number of representing points in \a mesh. + * + * \param [in] mesh is the sources of nodes on which kriging will be done regarding the parameters and the value of \c this->getSpaceDimension() + * \param [in] arr input field DataArrayDouble whose number of tuples must be equal to the number of nodes in \a mesh + * \param [out] isDrift return if drift coefficients are present in the returned vector of coefficients. If different from 0 there is presence of drift coefficients. + * Whatever the value of \a isDrift the number of tuples of returned DataArrayDouble will be equal to \c arr->getNumberOfTuples() + \a isDrift. + * \return a newly allocated array containing coefficients including or not drift coefficient at the end depending the value of \a isDrift parameter. + */ +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const +{ + int nbRows(-1); + MEDCouplingAutoRefCountObjectPtr matrixInv(computeInverseMatrix(mesh,isDrift,nbRows)); MEDCouplingAutoRefCountObjectPtr KnewiK=DataArrayDouble::New(); - KnewiK->alloc((nbOfPts+isDrift)*1,1); + KnewiK->alloc(nbRows*1,1); MEDCouplingAutoRefCountObjectPtr arr2=DataArrayDouble::New(); - arr2->alloc((nbOfPts+isDrift)*1,1); + arr2->alloc(nbRows*1,1); 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()); + INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbRows,nbRows,arr2->getConstPointer(),nbRows,1,KnewiK->getPointer()); return KnewiK.retn(); } @@ -2168,8 +2832,23 @@ void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimens } break; } + case 2: + { + for(int i=0;i