X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldDiscretization.cxx;h=25fa1696a244822d4b242fb204cb5820f71e37fe;hb=04f1c450d57b28c7c473bdc59dc87eeef7393ca5;hp=2739ca421baee04a9a10e8fda3d0d6a09ed36dd7;hpb=293a6104470482e450701aa8061d9b244f2057d5;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx old mode 100644 new mode 100755 index 2739ca421..25fa1696a --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,13 +16,13 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include "MEDCouplingFieldDiscretization.hxx" #include "MEDCouplingCMesh.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" -#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MCAuto.hxx" #include "CellModel.hxx" #include "InterpolationUtils.hxx" @@ -34,10 +34,11 @@ #include #include #include +#include #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; const double MEDCouplingFieldDiscretization::DFLT_PRECISION=1.e-12; @@ -49,7 +50,7 @@ const char MEDCouplingFieldDiscretizationP1::REPR[]="P1"; const TypeOfField MEDCouplingFieldDiscretizationP1::TYPE=ON_NODES; -const int MEDCouplingFieldDiscretizationPerCell::DFT_INVALID_LOCID_VALUE=-1; +const mcIdType MEDCouplingFieldDiscretizationPerCell::DFT_INVALID_LOCID_VALUE=-1; const char MEDCouplingFieldDiscretizationGauss::REPR[]="GAUSS"; @@ -63,6 +64,66 @@ const char MEDCouplingFieldDiscretizationKriging::REPR[]="KRIGING"; 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_POINT1[1]={0.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_SEG2[2]={1.,1.}; +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_TETRA10[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA6[6]={0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA15[15]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PENTA18[18]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA8[8]={1.,1.,1.,1.,1.,1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA20[20]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_HEXA27[27]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA5[5]={0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333,0.13333333333333333}; +const double MEDCouplingFieldDiscretizationGaussNE::FGP_PYRA13[13]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::REF_SEG2[2]={-1.,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}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_TRI7[14]={0.,0.,1.,0.,0.,1.,0.5,0.,0.5,0.5,0.,0.5,0.3333333333333333,0.3333333333333333}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD4[8]={-1.,-1.,1.,-1.,1.,1.,-1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD8[16]={-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_QUAD9[18]={-1.,-1.,1.,-1.,1.,1.,-1.,1.,0.,-1.,1.,0.,0.,1.,-1.,0.,0.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_TETRA4[12]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_TETRA10[30]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.5,0.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_PENTA6[18]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_PENTA15[45]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_PENTA18[54]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA8[24]={-1.,-1.,-1.,1.,-1.,-1.,1.,1.,-1.,-1.,1.,-1.,-1.,-1.,1.,1.,-1.,1.,1.,1.,1.,-1.,1.,1.}; +const double MEDCouplingFieldDiscretizationGaussNE::REF_HEXA20[60]={-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.}; +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.,-1.,0.,-1.,0.,1.,-1.,1.,0.,-1.,0.,-1.,-1.,-1.,0.,1.,0.,1.,1.,1.,0.,1.,0.,-1.,1.,-1.,-1.,0.,-1.,1.,0.,1.,1.,0.,1.,-1.,0.,0.,0.,-1.,-1.,0.,0.,0.,1.,0.,1.,0.,0.,0.,-1.,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_TETRA10[30]={0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.,0.5,0.5,0.,0.5,0.,0.5,0.5,0.,0.};//to check +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_PENTA15[45]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::LOC_PENTA18[54]={-1.,1.,0.,-1.,0.,1.,-1.,0.,0.,1.,1.,0.,1.,0.,1.,1.,0.,0.,-1.,0.5,0.5,-1.,0.,0.5,-1.,0.5,0.,0.,1.,0.,0.,0.,1.,0.,0.,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.5,0.};//to check +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_HEXA20[60]={-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.};//to check +const double MEDCouplingFieldDiscretizationGaussNE::LOC_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.,-1.,0.,-1.,0.,1.,-1.,1.,0.,-1.,0.,-1.,-1.,-1.,0.,1.,0.,1.,1.,1.,0.,1.,0.,-1.,1.,-1.,-1.,0.,-1.,1.,0.,1.,1.,0.,1.,-1.,0.,0.,0.,-1.,-1.,0.,0.,0.,1.,0.,1.,0.,0.,0.,-1.,0.,0.,0.,1.,0.,0.,0.}; +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}; +const double MEDCouplingFieldDiscretizationGaussNE::LOC_PYRA13[39]={1.,0.,0.,0.,-1.,0.,-1.,0.,0.,0.,1.,0.,0.,0.,0.999999999999,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};//to check 0.99999... to avoid nan ! on node #4 of PYRA13 + MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT_PRECISION) { } @@ -70,7 +131,7 @@ MEDCouplingFieldDiscretization::MEDCouplingFieldDiscretization():_precision(DFLT MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::New(TypeOfField type) { switch(type) - { + { case MEDCouplingFieldDiscretizationP0::TYPE: return new MEDCouplingFieldDiscretizationP0; case MEDCouplingFieldDiscretizationP1::TYPE: @@ -82,26 +143,40 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::New(TypeOfField case MEDCouplingFieldDiscretizationKriging::TYPE: return new MEDCouplingFieldDiscretizationKriging; default: - throw INTERP_KERNEL::Exception("Choosen discretization is not implemented yet."); - } + throw INTERP_KERNEL::Exception("Chosen discretization is not implemented yet."); + } } -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 !"); } +std::string MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(TypeOfField type) +{ + if(type==MEDCouplingFieldDiscretizationP0::TYPE) + return MEDCouplingFieldDiscretizationP0::REPR; + if(type==MEDCouplingFieldDiscretizationP1::TYPE) + return MEDCouplingFieldDiscretizationP1::REPR; + if(type==MEDCouplingFieldDiscretizationGauss::TYPE) + return MEDCouplingFieldDiscretizationGauss::REPR; + if(type==MEDCouplingFieldDiscretizationGaussNE::TYPE) + return MEDCouplingFieldDiscretizationGaussNE::REPR; + if(type==MEDCouplingFieldDiscretizationKriging::TYPE) + return MEDCouplingFieldDiscretizationKriging::REPR; + throw INTERP_KERNEL::Exception("GetTypeOfFieldRepr : Representation does not match with any field discretization !"); +} + bool MEDCouplingFieldDiscretization::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const { std::string reason; @@ -113,6 +188,31 @@ bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCoupl return isEqual(other,eps); } +/*! + * This method is an alias of MEDCouplingFieldDiscretization::clone. It is only here for coherency with all the remaining of MEDCoupling. + * \sa MEDCouplingFieldDiscretization::clone. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::deepCopy() const +{ + return clone(); +} + +/*! + * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const mcIdType *startCellIds, const mcIdType *endCellIds) 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(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const +{ + return clone(); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -120,29 +220,38 @@ void MEDCouplingFieldDiscretization::updateTime() const { } +std::size_t MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren() const +{ + return 0; +} + +std::vector MEDCouplingFieldDiscretization::getDirectChildrenWithNull() 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 { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,true); - int nbOfCompo=arr->getNumberOfComponents(); - int nbOfElems=getNumberOfTuples(mesh); + MCAuto vol=getMeasureField(mesh,true); + std::size_t nbOfCompo=arr->getNumberOfComponents(); + mcIdType nbOfElems=getNumberOfTuples(mesh); std::fill(res,res+nbOfCompo,0.); const double *arrPtr=arr->getConstPointer(); const double *volPtr=vol->getArray()->getConstPointer(); double deno=0.; - for(int i=0;i(),1./deno)); - vol->decrRef(); } /*! @@ -150,25 +259,24 @@ 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 { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,true); - int nbOfCompo=arr->getNumberOfComponents(); - int nbOfElems=getNumberOfTuples(mesh); + MCAuto vol=getMeasureField(mesh,true); + std::size_t nbOfCompo=arr->getNumberOfComponents(); + mcIdType nbOfElems=getNumberOfTuples(mesh); std::fill(res,res+nbOfCompo,0.); const double *arrPtr=arr->getConstPointer(); const double *volPtr=vol->getArray()->getConstPointer(); double deno=0.; - for(int i=0;i(),1./deno)); std::transform(res,res+nbOfCompo,res,std::ptr_fun(std::sqrt)); - vol->decrRef(); } /*! @@ -176,25 +284,48 @@ 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 { - MEDCouplingFieldDouble *vol=getMeasureField(mesh,isWAbs); - int nbOfCompo=arr->getNumberOfComponents(); - int nbOfElems=getNumberOfTuples(mesh); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : mesh is NULL !"); + if(!arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::integral : input array is NULL !"); + MCAuto vol=getMeasureField(mesh,isWAbs); + std::size_t nbOfCompo(arr->getNumberOfComponents()); + mcIdType nbOfElems(getNumberOfTuples(mesh)); + if(nbOfElems!=arr->getNumberOfTuples()) + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretization::integral : field is not correct ! number of tuples in array is " << arr->getNumberOfTuples(); + oss << " whereas number of tuples expected is " << nbOfElems << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } std::fill(res,res+nbOfCompo,0.); - const double *arrPtr=arr->getConstPointer(); - const double *volPtr=vol->getArray()->getConstPointer(); - double *tmp=new double[nbOfCompo]; - for (int i=0;ibegin()),*volPtr(vol->getArray()->begin()); + INTERP_KERNEL::AutoPtr tmp=new double[nbOfCompo]; + for(mcIdType i=0;i(),volPtr[i])); - std::transform(tmp,tmp+nbOfCompo,res,res,std::plus()); + std::transform(arrPtr+i*nbOfCompo,arrPtr+(i+1)*nbOfCompo,(double *)tmp,std::bind2nd(std::multiplies(),volPtr[i])); + std::transform((double *)tmp,(double *)tmp+nbOfCompo,res,res,std::plus()); } - delete [] tmp; - vol->decrRef(); } -void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) 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, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const +{ + MCAuto da=DataArrayIdType::Range(beginCellIds,endCellIds,stepCellIds); + return buildSubMeshData(mesh,da->begin(),da->end(),di); +} + +void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayIdType *& arr) const { arr=0; } @@ -202,7 +333,7 @@ void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& ar /*! * Empty : Not a bug */ -void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const +void MEDCouplingFieldDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const { } @@ -213,11 +344,18 @@ void MEDCouplingFieldDiscretization::getTinySerializationDbleInformation(std::ve { } -void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr) +void MEDCouplingFieldDiscretization::resizeForUnserialization(const std::vector& tinyInfo, DataArrayIdType *& arr) { arr=0; } +/*! + * Empty : Not a bug + */ +void MEDCouplingFieldDiscretization::checkForUnserialization(const std::vector& tinyInfo, const DataArrayIdType *arr) +{ +} + /*! * Empty : Not a bug */ @@ -227,83 +365,89 @@ void MEDCouplingFieldDiscretization::finishUnserialization(const std::vector& refCoo, - const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) + const std::vector& gsCoo, const std::vector& wg) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + +void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const mcIdType *begin, const mcIdType *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -void MEDCouplingFieldDiscretization::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, - const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretization::clearGaussLocalizations() { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -void MEDCouplingFieldDiscretization::clearGaussLocalizations() throw(INTERP_KERNEL::Exception) +MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(mcIdType locId) { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(mcIdType locId) const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -const MEDCouplingGaussLocalization& MEDCouplingFieldDiscretization::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) +mcIdType MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -int MEDCouplingFieldDiscretization::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +mcIdType MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(mcIdType cellId) const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +mcIdType MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(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(mcIdType 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, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const mcIdType *old2NewPtr, mcIdType newNbOfEntity, DataArrayDouble *arr, const std::string& msg) { - int oldNbOfElems=arr->getNumberOfTuples(); - int nbOfComp=arr->getNumberOfComponents(); - int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1; - DataArrayDouble *arrCpy=arr->deepCpy(); + if(!arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !"); + mcIdType oldNbOfElems=arr->getNumberOfTuples(); + std::size_t nbOfComp=arr->getNumberOfComponents(); + mcIdType newNbOfTuples=newNbOfEntity; + MCAuto arrCpy=arr->deepCopy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(newNbOfTuples); double *ptToFill=arr->getPointer(); std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits::max()); INTERP_KERNEL::AutoPtr tmp=new double[nbOfComp]; - for(int i=0;i=0)//if newNb<0 the node is considered as out. { if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to(),std::numeric_limits::max())) - ==ptToFill+(newNb+1)*nbOfComp) + ==ptToFill+(newNb+1)*nbOfComp) std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp); else { @@ -312,7 +456,6 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(double eps, cons //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 !"; @@ -321,22 +464,34 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(double eps, cons } } } - arrCpy->decrRef(); } -void MEDCouplingFieldDiscretization::renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const mcIdType *new2OldPtr, mcIdType new2OldSz, DataArrayDouble *arr, const std::string& msg) { - int nbOfComp=arr->getNumberOfComponents(); - DataArrayDouble *arrCpy=arr->deepCpy(); + std::size_t nbOfComp=arr->getNumberOfComponents(); + MCAuto arrCpy=arr->deepCopy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(new2OldSz); double *ptToFill=arr->getPointer(); - for(int i=0;idecrRef(); +} + +template +MCAuto MEDCouplingFieldDiscretization::EasyAggregate(std::vector& fds) +{ + if(fds.empty()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : input array is empty"); + for(const MEDCouplingFieldDiscretization * it : fds) + { + const FIELD_DISC *itc(dynamic_cast(it)); + if(!itc) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::aggregate : same field discretization expected for all input discretizations !"); + } + return fds[0]->clone(); } MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization() @@ -348,6 +503,11 @@ TypeOfField MEDCouplingFieldDiscretizationP0::getEnum() const return TYPE; } +/*! + * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this. + * + * \sa MEDCouplingFieldDiscretization::deepCopy. + */ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP0::clone() const { return new MEDCouplingFieldDiscretizationP0; @@ -365,6 +525,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) @@ -372,59 +537,119 @@ bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDis return ret; } -int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const +mcIdType MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfCells(); } -int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const +/*! + * 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). + */ +mcIdType 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 !"); + mcIdType nbOfSplit=ToIdType(idsPerType.size()); + mcIdType nbOfTypes=ToIdType(code.size()/3); + mcIdType ret=0; + for(mcIdType 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 DataArrayIdType *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; +} + +mcIdType 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 +DataArrayIdType *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const { - int nbOfTuples=mesh->getNumberOfCells(); - DataArrayInt *ret=DataArrayInt::New(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !"); + std::size_t nbOfTuples=mesh->getNumberOfCells(); + DataArrayIdType *ret=DataArrayIdType::New(); ret->alloc(nbOfTuples+1,1); ret->iota(0); return ret; } -void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, - const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, + const mcIdType *old2NewBg, bool check) { - const int *array=old2NewBg; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !"); + const mcIdType *array=old2NewBg; if(check) - array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); - for(std::vector::const_iterator it=arrays.begin();it!=arrays.end();it++) + array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); + 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 { - return mesh->getBarycenterAndOwner(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !"); + return mesh->computeCellCenterOfMass(); +} + +void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd, + DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds : NULL input mesh !"); + MCAuto tmp=DataArrayIdType::New(); + tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1); + std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer()); + MCAuto tmp2(tmp->deepCopy()); + cellRestriction=tmp.retn(); + trueTupleRestriction=tmp2.retn(); } -void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, - DataArrayInt *&cellRest) +void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const { - cellRest=DataArrayInt::New(); - cellRest->alloc((int)std::distance(partBg,partEnd),1); - std::copy(partBg,partEnd,cellRest->getPointer()); + stream << "P0 spatial discretization."; } -void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const { } -void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +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; @@ -436,36 +661,43 @@ void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMe 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); } void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { - int id=mesh->getCellContainingPoint(loc,_precision); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !"); + mcIdType id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !"); arr->getTuple(id,res); } -void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const { const MEDCouplingCMesh *meshC=dynamic_cast(mesh); if(!meshC) throw INTERP_KERNEL::Exception("P0::getValueOnPos is only accessible for structured meshes !"); - int id=meshC->getCellIdFromPos(i,j,k); + mcIdType id=meshC->getCellIdFromPos(i,j,k); arr->getTuple(id,res); } -DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const { - std::vector elts,eltsIndex; - mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !"); + MCAuto eltsArr,eltsIndexArr; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr); + const mcIdType *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin()); int spaceDim=mesh->getSpaceDimension(); - int nbOfComponents=arr->getNumberOfComponents(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + std::size_t nbOfComponents=arr->getNumberOfComponents(); + MCAuto ret=DataArrayDouble::New(); ret->alloc(nbOfPoints,nbOfComponents); double *ptToFill=ret->getPointer(); - for(int i=0;i=1) arr->getTuple(elts[eltsIndex[i]],ptToFill); else @@ -475,25 +707,24 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArr 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 mcIdType *, mcIdType 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 mcIdType *old2New, mcIdType 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 +void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const { - renumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell"); + RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell"); } /*! @@ -504,51 +735,123 @@ void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingM * \return a newly allocated array containing ids to select into the DataArrayDouble of the field. * */ -DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const +DataArrayIdType *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const { - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - ret->alloc((int)std::distance(startCellIds,endCellIds),1); + MCAuto ret=DataArrayIdType::New(); + ret->alloc(std::distance(startCellIds,endCellIds),1); std::copy(startCellIds,endCellIds,ret->getPointer()); - ret->incrRef(); return ret; + return ret.retn(); } /*! * 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 *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&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 !"); + MCAuto ret=mesh->buildPart(start,end); + MCAuto diSafe=DataArrayIdType::New(); + diSafe->alloc(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, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !"); + MCAuto ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds; + return ret.retn(); +} + +MCAuto MEDCouplingFieldDiscretizationP0::aggregate(std::vector& fds) const +{ + return EasyAggregate(fds); } -int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const +mcIdType MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfNodes(); } -int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const +/*! + * 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). + */ +mcIdType 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 !"); + mcIdType nbOfSplit=ToIdType(idsPerType.size()); + mcIdType nbOfTypes=ToIdType(code.size()/3); + mcIdType ret=0; + for(mcIdType 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 DataArrayIdType *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; +} + +mcIdType 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, - const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCouplingMesh *, const std::vector& arrays, + const mcIdType *old2NewBg, bool check) { } -DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const +DataArrayIdType *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const { - int nbOfTuples=mesh->getNumberOfNodes(); - DataArrayInt *ret=DataArrayInt::New(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !"); + mcIdType nbOfTuples=mesh->getNumberOfNodes(); + DataArrayIdType *ret=DataArrayIdType::New(); ret->alloc(nbOfTuples+1,1); ret->iota(0); return ret; @@ -556,17 +859,30 @@ 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(); } -void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, - DataArrayInt *&cellRest) +void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd, + DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const { - cellRest=mesh->getCellIdsFullyIncludedInNodeIds(partBg,partEnd); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : NULL input mesh !"); + MCAuto ret1=mesh->getCellIdsFullyIncludedInNodeIds(tupleIdsBg,tupleIdsEnd); + const MEDCouplingUMesh *meshc=dynamic_cast(mesh); + if(!meshc) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds : trying to subpart field on nodes by node ids ! Your mesh has to be unstructured !"); + MCAuto meshPart=static_cast(meshc->buildPartOfMySelf(ret1->begin(),ret1->end(),true)); + MCAuto ret2=meshPart->computeFetchedNodeIds(); + cellRestriction=ret1.retn(); + 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; @@ -578,60 +894,88 @@ void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCoupl /*! * 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 nodes ids) in mesh 'mesh' of entity in returned submesh. + * @param di is an array returned that specifies entity ids (here nodes ids) in mesh 'mesh' of entity in returned submesh. * Example : The first node id of returned mesh has the (*di)[0] id in 'mesh' */ -MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const +MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&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 !"); + DataArrayIdType *diTmp=0; + MCAuto ret=mesh->buildPartAndReduceNodes(start,end,diTmp); + MCAuto diTmpSafe(diTmp); + MCAuto 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, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !"); + DataArrayIdType *diTmp=0; + MCAuto ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp); + if(diTmp) + { + MCAuto diTmpSafe(diTmp); + MCAuto 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. * */ -DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const +DataArrayIdType *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const { if(!mesh) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : null mesh !"); - const MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured(); - MEDCouplingAutoRefCountObjectPtr umesh2=static_cast(umesh->buildPartOfMySelf(startCellIds,endCellIds,true)); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !"); + const MCAuto umesh=mesh->buildUnstructured(); + MCAuto umesh2=static_cast(umesh->buildPartOfMySelf(startCellIds,endCellIds,true)); return umesh2->computeFetchedNodeIds(); } -void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const mcIdType *old2NewPtr, mcIdType 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 mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const { } /*! * Nothing to do it's not a bug. */ -void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const { } -void MEDCouplingFieldDiscretizationOnNodes::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +void MEDCouplingFieldDiscretizationOnNodes::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const { const MEDCouplingCMesh *meshC=dynamic_cast(mesh); if(!meshC) throw INTERP_KERNEL::Exception("OnNodes::getValueOnPos(i,j,k) is only accessible for structured meshes !"); - int id=meshC->getNodeIdFromPos(i,j,k); + mcIdType id=meshC->getNodeIdFromPos(i,j,k); arr->getTuple(id,res); } @@ -640,6 +984,11 @@ TypeOfField MEDCouplingFieldDiscretizationP1::getEnum() const return TYPE; } +/*! + * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this. + * + * \sa MEDCouplingFieldDiscretization::deepCopy. + */ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationP1::clone() const { return new MEDCouplingFieldDiscretizationP1; @@ -657,6 +1006,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) @@ -664,20 +1018,24 @@ 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 !"); + if(nat!=IntensiveMaximum) + throw INTERP_KERNEL::Exception("Invalid nature for P1 field : expected IntensiveMaximum !"); } 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); } void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { - int id=mesh->getCellContainingPoint(loc,_precision); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !"); + mcIdType id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !"); INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(id); @@ -690,12 +1048,14 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co * This method localizes a point defined by 'loc' in a cell with id 'cellId' into mesh 'mesh'. * The result is put into res expected to be of size at least arr->getNumberOfComponents() */ -void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const +void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, mcIdType cellId, const DataArrayDouble *arr, const double *loc, double *res) const { - std::vector conn; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !"); + std::vector conn; std::vector coo; mesh->getNodeIdsOfCell(cellId,conn); - for(std::vector::const_iterator iter=conn.begin();iter!=conn.end();iter++) + for(std::vector::const_iterator iter=conn.begin();iter!=conn.end();iter++) mesh->getCoordinatesOfNode(*iter,coo); int spaceDim=mesh->getSpaceDimension(); std::size_t nbOfNodes=conn.size(); @@ -703,8 +1063,9 @@ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mes for(std::size_t i=0;i tmp=new double[nbOfNodes]; - INTERP_KERNEL::barycentric_coords(vec,loc,tmp); - int sz=arr->getNumberOfComponents(); + INTERP_KERNEL::NormalizedCellType ct(mesh->getTypeOfCell(cellId)); + INTERP_KERNEL::barycentric_coords(ct,vec,loc,tmp); + std::size_t sz=arr->getNumberOfComponents(); INTERP_KERNEL::AutoPtr tmp2=new double[sz]; std::fill(res,res+sz,0.); for(std::size_t i=0;i elts,eltsIndex; - mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !"); + MCAuto eltsArr,eltsIndexArr; + mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,eltsArr,eltsIndexArr); + const mcIdType *elts(eltsArr->begin()),*eltsIndex(eltsIndexArr->begin()); int spaceDim=mesh->getSpaceDimension(); - int nbOfComponents=arr->getNumberOfComponents(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + std::size_t nbOfComponents=arr->getNumberOfComponents(); + MCAuto ret=DataArrayDouble::New(); ret->alloc(nbOfPoints,nbOfComponents); double *ptToFill=ret->getPointer(); - for(int i=0;i=1) getValueInCell(mesh,elts[eltsIndex[i]],arr,loc+i*spaceDim,ptToFill+i*nbOfComponents); else @@ -734,8 +1098,17 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArr oss << ") detected outside mesh : unable to apply P1::getValueOnMulti ! "; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - ret->incrRef(); - return ret; + return ret.retn(); +} + +void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const +{ + stream << "P1 spatial discretization."; +} + +MCAuto MEDCouplingFieldDiscretizationP1::aggregate(std::vector& fds) const +{ + return EasyAggregate(fds); } MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0) @@ -748,11 +1121,34 @@ MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell() _discr_per_cell->decrRef(); } -MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other):_discr_per_cell(0) +/*! + * This constructor deep copies MEDCoupling::DataArrayIdType instance from other (if any). + */ +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const mcIdType *startCellIds, const mcIdType *endCellIds):_discr_per_cell(0) +{ + DataArrayIdType *arr=other._discr_per_cell; + if(arr) + { + if(startCellIds==0 && endCellIds==0) + _discr_per_cell=arr->deepCopy(); + else + _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds); + } +} + +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds):_discr_per_cell(0) { - DataArrayInt *arr=other._discr_per_cell; + DataArrayIdType *arr=other._discr_per_cell; if(arr) - _discr_per_cell=arr->deepCpy(); + { + _discr_per_cell=arr->selectByTupleIdSafeSlice(beginCellIds,endCellIds,stepCellIds); + } +} + +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(DataArrayIdType *dpc):_discr_per_cell(dpc) +{ + if(_discr_per_cell) + _discr_per_cell->incrRef(); } void MEDCouplingFieldDiscretizationPerCell::updateTime() const @@ -761,21 +1157,41 @@ void MEDCouplingFieldDiscretizationPerCell::updateTime() const updateTimeWith(*_discr_per_cell); } -void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) +std::size_t MEDCouplingFieldDiscretizationPerCell::getHeapMemorySizeWithoutChildren() const +{ + std::size_t ret(MEDCouplingFieldDiscretization::getHeapMemorySizeWithoutChildren()); + return ret; +} + +std::vector MEDCouplingFieldDiscretizationPerCell::getDirectChildrenWithNull() const +{ + std::vector ret(MEDCouplingFieldDiscretization::getDirectChildrenWithNull()); + ret.push_back(_discr_per_cell); + return ret; +} + +void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArray *da) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !"); - int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh or DataArray !"); + mcIdType 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 !"); } 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) @@ -784,7 +1200,7 @@ bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFie return false; bool ret=_discr_per_cell->isEqualIfNotWhy(*otherC->_discr_per_cell,reason); if(!ret) - reason.insert(0,"Field discretization per cell DataArrayInt given the discid per cell :"); + reason.insert(0,"Field discretization per cell DataArrayIdType given the discid per cell :"); return ret; } @@ -802,54 +1218,90 @@ 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. + * virtually by this method. */ -void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationPerCell::renumberCells(const mcIdType *old2NewBg, bool check) { - int nbCells=_discr_per_cell->getNumberOfTuples(); - const int *array=old2NewBg; + mcIdType nbCells=_discr_per_cell->getNumberOfTuples(); + const mcIdType *array=old2NewBg; if(check) - array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+nbCells); + array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+nbCells); // - DataArrayInt *dpc=_discr_per_cell->renumber(array); + DataArrayIdType *dpc=_discr_per_cell->renumber(array); _discr_per_cell->decrRef(); _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(); + _discr_per_cell=DataArrayIdType::New(); + mcIdType nbTuples=mesh->getNumberOfCells(); _discr_per_cell->alloc(nbTuples,1); - int *ptr=_discr_per_cell->getPointer(); + mcIdType *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 !"); - MEDCouplingAutoRefCountObjectPtr test=_discr_per_cell->getIdsEqual(DFT_INVALID_LOCID_VALUE); + MCAuto test( _discr_per_cell->findIdsEqual(DFT_INVALID_LOCID_VALUE)); if(test->getNumberOfTuples()!=0) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : presence of orphan cells !"); } -const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const +/*! + * This method is useful when 'this' describes a field discretization with several gauss discretization on a \b same cell type. + * For example same NORM_TRI3 cells having 6 gauss points and others with 12 gauss points. + * This method returns 2 arrays with same size : the return value and 'locIds' output parameter. + * For a given i into [0,locIds.size) ret[i] represents the set of cell ids of i_th set an locIds[i] represents the set of discretisation of the set. + * The return vector contains a set of newly created instance to deal with. + * The returned vector represents a \b partition of cells ids with a gauss discretization set. + * + * If no descretization is set in 'this' and exception will be thrown. + */ +std::vector MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType(std::vector& locIds) const +{ + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::splitIntoSingleGaussDicrPerCellType : no descretization set !"); + return _discr_per_cell->partitionByDifferentValues(locIds); +} + +const DataArrayIdType *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const { return _discr_per_cell; } +void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayIdType *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() { } -MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other):MEDCouplingFieldDiscretizationPerCell(other),_loc(other._loc) +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const mcIdType *startCellIds, const mcIdType *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc) +{ +} + +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc) { } @@ -860,6 +1312,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) { @@ -900,11 +1357,26 @@ bool MEDCouplingFieldDiscretizationGauss::isEqualWithoutConsideringStr(const MED return true; } +/*! + * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this. + * + * \sa MEDCouplingFieldDiscretization::deepCopy. + */ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() const { return new MEDCouplingFieldDiscretizationGauss(*this); } +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const mcIdType *startCellIds, const mcIdType *endCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds); +} + +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds); +} + std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { std::ostringstream oss; oss << REPR << "." << std::endl; @@ -913,7 +1385,7 @@ std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const if(_discr_per_cell->isAllocated()) { oss << "Discretization per cell : "; - std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator(oss,", ")); + std::copy(_discr_per_cell->begin(),_discr_per_cell->end(),std::ostream_iterator(oss,", ")); oss << std::endl; } } @@ -928,131 +1400,222 @@ std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const return oss.str(); } +std::size_t MEDCouplingFieldDiscretizationGauss::getHeapMemorySizeWithoutChildren() const +{ + 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).getMemorySize(); + return ret; +} + const char *MEDCouplingFieldDiscretizationGauss::getRepr() const { return REPR; } -int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const +/*! + * 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). + */ +mcIdType 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 !"); + mcIdType nbOfSplit=ToIdType(idsPerType.size()); + mcIdType nbOfTypes=ToIdType(code.size()/3); + mcIdType ret(0); + for(mcIdType 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 DataArrayIdType *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 +} + +mcIdType MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh *) const { - int ret=0; - const int *dcPtr=_discr_per_cell->getConstPointer(); - int nbOfTuples=_discr_per_cell->getNumberOfTuples(); - for(const int *w=dcPtr;w!=dcPtr+nbOfTuples;w++) - ret+=_loc[*w].getNumberOfGaussPt(); + mcIdType ret=0; + if (_discr_per_cell == 0) + throw INTERP_KERNEL::Exception("Discretization is not initialized!"); + const mcIdType *dcPtr=_discr_per_cell->getConstPointer(); + mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples(); + mcIdType maxSz=ToIdType(_loc.size()); + for(const mcIdType *w=dcPtr;w!=dcPtr+nbOfTuples;w++) + { + if(*w>=0 && *wgetNumberOfCells(); } -DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const +/*! + * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField + * and a call to DataArrayDouble::computeOffsetsFull on the returned array. + */ +DataArrayIdType *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const { - int nbOfTuples=mesh->getNumberOfCells(); - DataArrayInt *ret=DataArrayInt::New(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !"); + mcIdType nbOfTuples=mesh->getNumberOfCells(); + MCAuto ret=DataArrayIdType::New(); ret->alloc(nbOfTuples+1,1); - int *retPtr=ret->getPointer(); - const int *start=_discr_per_cell->getConstPointer(); + mcIdType *retPtr(ret->getPointer()); + const mcIdType *start(_discr_per_cell->begin()); + if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !"); + mcIdType maxPossible=ToIdType(_loc.size()); retPtr[0]=0; - for(int i=0;i=0 && *start& arrays, - const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, + const mcIdType *old2NewBg, bool check) { - const int *array=old2NewBg; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !"); + const mcIdType *array=old2NewBg; if(check) - array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); - int nbOfCells=_discr_per_cell->getNumberOfTuples(); - int nbOfTuples=getNumberOfTuples(0); - const int *dcPtr=_discr_per_cell->getConstPointer(); - int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace. - int *array3=new int[nbOfCells];//store for each cell in present dcp array (already renumbered) the offset needed by each cell in new numbering. + array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); + mcIdType nbOfCells=_discr_per_cell->getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(0); + const mcIdType *dcPtr=_discr_per_cell->getConstPointer(); + mcIdType *array2=new mcIdType[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace. + mcIdType *array3=new mcIdType[nbOfCells];//store for each cell in present dcp array (already renumbered) the offset needed by each cell in new numbering. array3[0]=0; - for(int i=1;i::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); - DataArrayDouble *ret=DataArrayDouble::New(); + MCAuto umesh=mesh->buildUnstructured();//in general do nothing + mcIdType nbOfTuples=getNumberOfTuples(mesh); + MCAuto ret=DataArrayDouble::New(); int spaceDim=mesh->getSpaceDimension(); ret->alloc(nbOfTuples,spaceDim); - std::vector< std::vector > locIds; - std::vector parts=splitIntoSingleGaussDicrPerCellType(locIds); - std::vector< MEDCouplingAutoRefCountObjectPtr > parts2(parts.size()); + std::vector< mcIdType > locIds; + std::vector parts=splitIntoSingleGaussDicrPerCellType(locIds); + std::vector< MCAuto > parts2(parts.size()); std::copy(parts.begin(),parts.end(),parts2.begin()); - MEDCouplingAutoRefCountObjectPtr offsets=buildNbOfGaussPointPerCellField(); + MCAuto offsets=buildNbOfGaussPointPerCellField(); offsets->computeOffsets(); - const int *ptrOffsets=offsets->getConstPointer(); + const mcIdType *ptrOffsets=offsets->getConstPointer(); const double *coords=umesh->getCoords()->getConstPointer(); - const int *connI=umesh->getNodalConnectivityIndex()->getConstPointer(); - const int *conn=umesh->getNodalConnectivity()->getConstPointer(); + const mcIdType *connI=umesh->getNodalConnectivityIndex()->getConstPointer(); + const mcIdType *conn=umesh->getNodalConnectivity()->getConstPointer(); double *valsToFill=ret->getPointer(); for(std::size_t i=0;i::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& 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])); - } + // + const MEDCouplingGaussLocalization& cli(_loc[locIds[i]]);//curLocInfo + INTERP_KERNEL::NormalizedCellType typ(cli.getType()); + const std::vector& wg(cli.getWeights()); + calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(), + &cli.getGaussCoords()[0],ToIdType(wg.size()),&cli.getRefCoords()[0], + INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes()); + // + for(const mcIdType *w=parts2[i]->begin();w!=parts2[i]->end();w++) + calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w])); } ret->copyStringInfoFrom(*umesh->getCoords()); - return ret; + return ret.retn(); } -void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, - DataArrayInt *&cellRest) +void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const mcIdType *tupleIdsBg, const mcIdType *tupleIdsEnd, + DataArrayIdType *&cellRestriction, DataArrayIdType *&trueTupleRestriction) const { - throw INTERP_KERNEL::Exception("Not implemented yet !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !"); + MCAuto tmp=DataArrayIdType::New(); tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1); + std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer()); + tmp->sort(true); + tmp=tmp->buildUnique(); + MCAuto nbOfNodesPerCell=buildNbOfGaussPointPerCellField(); + nbOfNodesPerCell->computeOffsetsFull(); + nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction); } /*! * Empty : not a bug */ -void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::checkCompatibilityWithNature(NatureOfField nat) const { } -void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector& tinyInfo) const +void MEDCouplingFieldDiscretizationGauss::getTinySerializationIntInformation(std::vector& tinyInfo) const { - int val=-1; + mcIdType val=-1; if(_discr_per_cell) val=_discr_per_cell->getNumberOfTuples(); tinyInfo.push_back(val); - tinyInfo.push_back((int)_loc.size()); + tinyInfo.push_back(ToIdType(_loc.size())); if(_loc.empty()) tinyInfo.push_back(-1); else @@ -1067,36 +1630,42 @@ void MEDCouplingFieldDiscretizationGauss::getTinySerializationDbleInformation(st (*iter).pushTinySerializationDblInfo(tinyInfo); } -void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayInt *& arr) const +void MEDCouplingFieldDiscretizationGauss::getSerializationIntArray(DataArrayIdType *& arr) const { arr=0; if(_discr_per_cell) arr=_discr_per_cell; } -void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *& arr) +void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::vector& tinyInfo, DataArrayIdType *& arr) { - int val=tinyInfo[0]; + mcIdType val=tinyInfo[0]; if(val>=0) { - _discr_per_cell=DataArrayInt::New(); + _discr_per_cell=DataArrayIdType::New(); _discr_per_cell->alloc(val,1); } else _discr_per_cell=0; arr=_discr_per_cell; - int nbOfLoc=tinyInfo[1]; - _loc.clear(); - int dim=tinyInfo[2]; - int delta=-1; - if(nbOfLoc>0) - delta=((int)tinyInfo.size()-3)/nbOfLoc; - for(int i=0;i& tinyInfo, const DataArrayIdType *arr) +{ + static const char MSG[]="MEDCouplingFieldDiscretizationGauss::checkForUnserialization : expect to have one not null DataArrayIdType !"; + mcIdType val=tinyInfo[0]; + if(val>=0) { - std::vector tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta); - MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp); - _loc.push_back(elt); + if(!arr) + throw INTERP_KERNEL::Exception(MSG); + arr->checkNbOfTuplesAndComp(val,1,MSG); + _discr_per_cell=const_cast(arr); + _discr_per_cell->incrRef(); } + else + _discr_per_cell=0; + commonUnserialization(tinyInfo); } void MEDCouplingFieldDiscretizationGauss::finishUnserialization(const std::vector& tinyInfo) @@ -1109,26 +1678,27 @@ 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, mcIdType cellId, mcIdType nodeIdInCell, int compoId) const { - int offset=getOffsetOfCell(cellId); + mcIdType 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(); - int nbOfDesc=(int)_loc.size(); - int nbOfCells=mesh->getNumberOfCells(); - const int *dc=_discr_per_cell->getConstPointer(); - for(int i=0;igetNumberOfCells(); + const mcIdType *dc=_discr_per_cell->getConstPointer(); + for(mcIdType i=0;i=nbOfDesc) { - std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happend !"; + std::ostringstream oss; oss << "Cell # " << i << " of mesh \"" << mesh->getName() << "\" has an undefined gauss location ! Should never happened !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } if(dc[i]<0) @@ -1142,17 +1712,62 @@ void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplin throw INTERP_KERNEL::Exception(oss.str().c_str()); } } - int nbOfTuples=getNumberOfTuples(mesh); + mcIdType nbOfTuples(getNumberOfTuples(mesh)); if(nbOfTuples!=da->getNumberOfTuples()) { - std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !"; + std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " having " << da->getNumberOfTuples() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGauss::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const { - throw INTERP_KERNEL::Exception("Not implemented yet !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : mesh instance specified is NULL !"); + MCAuto vol=mesh->getMeasureField(isAbs); + const double *volPtr=vol->getArray()->begin(); + MCAuto ret=MEDCouplingFieldDouble::New(ON_GAUSS_PT); + ret->setMesh(mesh); + ret->setDiscretization(const_cast(this)); + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array not defined ! spatial localization is incorrect !"); + _discr_per_cell->checkAllocated(); + if(_discr_per_cell->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but with nb of components different from 1 !"); + if(_discr_per_cell->getNumberOfTuples()!=vol->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getMeasureField : no discr per cell array defined but mismatch between nb of cells of mesh and size of spatial disr array !"); + MCAuto offset=getOffsetArr(mesh); + MCAuto arr=DataArrayDouble::New(); arr->alloc(getNumberOfTuples(mesh),1); + ret->setArray(arr); + double *arrPtr=arr->getPointer(); + const mcIdType *offsetPtr=offset->getConstPointer(); + mcIdType maxGaussLoc=ToIdType(_loc.size()); + std::vector locIds; + std::vector ids=splitIntoSingleGaussDicrPerCellType(locIds); + std::vector< MCAuto > ids2(ids.size()); std::copy(ids.begin(),ids.end(),ids2.begin()); + for(std::size_t i=0;i=0 && locId weights=new double[nbOfGaussPt]; + double sum=std::accumulate(loc.getWeights().begin(),loc.getWeights().end(),0.); + std::transform(loc.getWeights().begin(),loc.getWeights().end(),(double *)weights,std::bind2nd(std::multiplies(),1./sum)); + for(const mcIdType *cellId=curIds->begin();cellId!=curIds->end();cellId++) + for(mcIdType j=0;jgetIJ(0,0) << " ! Must be in [0," << maxGaussLoc << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + ret->synchronizeTimeWithSupport(); + return ret.retn(); } void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const @@ -1160,20 +1775,70 @@ void MEDCouplingFieldDiscretizationGauss::getValueOn(const DataArrayDouble *arr, throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +void MEDCouplingFieldDiscretizationGauss::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const { - throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); + throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !"); } -DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const { throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented yet for gauss points !"); } -MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const +MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const { - di=computeTupleIdsToSelectFromCellIds(mesh,start,end); - return mesh->buildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !"); + MCAuto diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MCAuto 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, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&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 #"; + mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples(); + const mcIdType *w=_discr_per_cell->begin(); + mcIdType nbMaxOfLocId=ToIdType(_loc.size()); + for(mcIdType 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()); } + } + MCAuto ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + return ret.retn(); } /*! @@ -1183,95 +1848,133 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MED * \return a newly allocated array containing ids to select into the DataArrayDouble of the field. * */ -DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const +DataArrayIdType *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !"); - if(!_discr_per_cell) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null discretization ids !"); - int nbOfCells=mesh->getNumberOfCells(); + MCAuto nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer + mcIdType 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); + nbOfNodesPerCell->computeOffsetsFull(); + MCAuto sel=DataArrayIdType::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,ToIdType(std::distance(startCellIds,endCellIds)),1); return sel->buildExplicitArrByRanges(nbOfNodesPerCell); } /*! * No implementation needed ! */ -void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const +void MEDCouplingFieldDiscretizationGauss::renumberValuesOnNodes(double , const mcIdType *, mcIdType 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 mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const { throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const { 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, - const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +MCAuto MEDCouplingFieldDiscretizationGauss::aggregate(std::vector& fds) const { + if(fds.empty()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : input array is empty"); + std::vector loc;//store the localizations for the output GaussDiscretization object + std::vector< MCAuto > discPerCells(fds.size()); + std::size_t i(0); + for(auto it=fds.begin();it!=fds.end();++it,++i) + { + const MEDCouplingFieldDiscretizationGauss *itc(dynamic_cast(*it)); + if(!itc) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : same field discretization expected for all input discretizations !"); + // + std::vector loc2(itc->_loc); + std::vector newLocId(loc2.size()); + for(std::size_t j=0;j_discr_per_cell); + if(!dpc) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::aggregate : Presence of nullptr array of disc per cell !"); + MCAuto dpc2(dpc->deepCopy()); + dpc2->transformWithIndArr(newLocId.data(),newLocId.data()+newLocId.size()); + discPerCells[i]=dpc2; + } + MCAuto dpc3(DataArrayIdType::Aggregate(ToConstVect(discPerCells))); + MCAuto ret(new MEDCouplingFieldDiscretizationGauss(dpc3,loc)); + return DynamicCast(ret); +} + +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) +{ + 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(ToIdType(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); - int id=(int)_loc.size(); + buildDiscrPerCellIfNecessary(mesh); + mcIdType id=ToIdType(_loc.size()); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); _loc.push_back(elt); - int *ptr=_discr_per_cell->getPointer(); - int nbCells=m->getNumberOfCells(); - for(int i=0;igetTypeOfCell(i)==type) + mcIdType *ptr=_discr_per_cell->getPointer(); + mcIdType nbCells=mesh->getNumberOfCells(); + for(mcIdType i=0;igetTypeOfCell(i)==type) ptr[i]=id; zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, - const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const mcIdType *begin, const mcIdType *end, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) { - 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++) + mcIdType id=ToIdType(_loc.size()); + mcIdType *ptr=_discr_per_cell->getPointer(); + for(const mcIdType *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()); } } // - for(const int *w2=begin;w2!=end;w2++) + for(const mcIdType *w2=begin;w2!=end;w2++) ptr[*w2]=id; // _loc.push_back(elt); zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() { if(_discr_per_cell) { @@ -1281,36 +1984,49 @@ void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP _loc.clear(); } -MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(mcIdType locId, const MEDCouplingGaussLocalization& loc) +{ + if(locId<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !"); + mcIdType sz=ToIdType(_loc.size()); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + if(locId>=sz) + _loc.resize(locId+1,gLoc); + _loc[locId]=loc; +} + +void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(mcIdType 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(mcIdType locId) { checkLocalizationId(locId); return _loc[locId]; } -int MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception) +mcIdType MEDCouplingFieldDiscretizationGauss::getNbOfGaussLocalization() const { - return (int)_loc.size(); + return ToIdType(_loc.size()); } -int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception) +mcIdType MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(mcIdType cellId) const { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("No Gauss localization still set !"); - int locId=_discr_per_cell->getConstPointer()[cellId]; + mcIdType 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) +mcIdType MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const { - if(!_discr_per_cell) - throw INTERP_KERNEL::Exception("No Gauss localization still set !"); - std::set ret; - int id=0; - for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++) - if((*iter).getType()==type) - ret.insert(id); + std::set ret=getGaussLocalizationIdsOfOneType(type); if(ret.empty()) throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !"); if(ret.size()>1) @@ -1318,34 +2034,46 @@ int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_ return *ret.begin(); } -void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) +std::set MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const { - if(locId<0 || locId>=(int)_loc.size()) + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("No Gauss localization still set !"); + std::set ret; + mcIdType id=0; + for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++) + if((*iter).getType()==type) + ret.insert(id); + return ret; +} + +void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(mcIdType locId, std::vector& cellIds) const +{ + if(locId<0 || locId>=ToIdType(_loc.size())) throw INTERP_KERNEL::Exception("Invalid locId given : must be in range [0:getNbOfGaussLocalization()) !"); - int nbOfTuples=_discr_per_cell->getNumberOfTuples(); - const int *ptr=_discr_per_cell->getConstPointer(); - for(int i=0;igetNumberOfTuples(); + const mcIdType *ptr=_discr_per_cell->getConstPointer(); + for(mcIdType i=0;i=(int)_loc.size()) + if(locId<0 || locId>=ToIdType(_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) +mcIdType MEDCouplingFieldDiscretizationGauss::getOffsetOfCell(mcIdType cellId) const { - int ret=0; - const int *start=_discr_per_cell->getConstPointer(); - for(const int *w=start;w!=start+cellId;w++) + mcIdType ret=0; + const mcIdType *start=_discr_per_cell->getConstPointer(); + for(const mcIdType *w=start;w!=start+cellId;w++) ret+=_loc[*w].getNumberOfGaussPt(); return ret; } @@ -1356,119 +2084,86 @@ 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) +DataArrayIdType *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(); + mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples(); + MCAuto ret=DataArrayIdType::New(); + const mcIdType *w=_discr_per_cell->begin(); ret->alloc(nbOfTuples,1); - int *valsToFill=ret->getPointer(); - for(int i=0;igetPointer(); + mcIdType nbMaxOfLocId=ToIdType(_loc.size()); + for(mcIdType i=0;i=0 && *wincrRef(); - return ret; + { + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : cell #" << i << " is detected as orphan !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return ret.retn(); +} + +void MEDCouplingFieldDiscretizationGauss::reprQuickOverview(std::ostream& stream) const +{ + stream << "Gauss points spatial discretization."; } /*! * This method makes the assumption that _discr_per_cell is set. * This method reduces as much as possible number size of _loc. - * This method is usefull when several set on same cells has been done and that some Gauss Localization are no more used. + * This method is useful when several set on same cells has been done and that some Gauss Localization are no more used. */ void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations() { - 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); - for(const int *w=start;w!=start+nbOfTuples;w++) + const mcIdType *start=_discr_per_cell->begin(); + mcIdType nbOfTuples=_discr_per_cell->getNumberOfTuples(); + INTERP_KERNEL::AutoPtr tmp=new mcIdType[_loc.size()]; + std::fill((mcIdType *)tmp,(mcIdType *)tmp+_loc.size(),-2); + for(const mcIdType *w=start;w!=start+nbOfTuples;w++) if(*w>=0) tmp[*w]=1; - int fid=0; - for(int i=0;i<(int)_loc.size();i++) + mcIdType fid=0; + for(mcIdType i=0;igetPointer(); - for(int *w2=start2;w2!=start2+nbOfTuples;w2++) - *w2=tmp[*w2]; + mcIdType *start2=_discr_per_cell->getPointer(); + for(mcIdType *w2=start2;w2!=start2+nbOfTuples;w2++) + if(*w2>=0) + *w2=tmp[*w2]; std::vector tmpLoc; - for(int i=0;i<(int)_loc.size();i++) + for(mcIdType i=0;i MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType(std::vector< std::vector >& locIds) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGauss::commonUnserialization(const std::vector& tinyInfo) { - if(!_discr_per_cell) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType : no descretization set !"); - locIds.clear(); - std::vector ret; - const int *discrPerCell=_discr_per_cell->getConstPointer(); - MEDCouplingAutoRefCountObjectPtr ret2=_discr_per_cell->getIdsNotEqual(-1); - int nbOfTuplesSet=ret2->getNumberOfTuples(); - std::list idsRemaining(ret2->getConstPointer(),ret2->getConstPointer()+nbOfTuplesSet); - std::list::iterator it=idsRemaining.begin(); - while(it!=idsRemaining.end()) + mcIdType nbOfLoc=tinyInfo[1]; + _loc.clear(); + mcIdType dim=tinyInfo[2]; + mcIdType delta=-1; + if(nbOfLoc>0) + delta=(ToIdType(tinyInfo.size())-3)/nbOfLoc; + for(mcIdType i=0;i ids; - std::set curLocIds; - std::set 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()); + std::vector tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta); + MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp); + _loc.push_back(elt); } - return ret; } MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE() @@ -1480,6 +2175,11 @@ TypeOfField MEDCouplingFieldDiscretizationGaussNE::getEnum() const return TYPE; } +/*! + * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this. + * + * \sa MEDCouplingFieldDiscretization::deepCopy. + */ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGaussNE::clone() const { return new MEDCouplingFieldDiscretizationGaussNE(*this); @@ -1497,6 +2197,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) @@ -1504,11 +2209,57 @@ bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFie return ret; } -int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const +/*! + * 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). + */ +mcIdType 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 !"); + mcIdType nbOfSplit=ToIdType(idsPerType.size()); + mcIdType nbOfTypes=ToIdType(code.size()/3); + mcIdType ret(0); + for(mcIdType 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 DataArrayIdType *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*ToIdType(cm.getNumberOfNodes()); + } + return ret; +} + +mcIdType MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const { - int ret=0; - int nbOfCells=mesh->getNumberOfCells(); - for(int i=0;igetNumberOfCells(); + for(mcIdType i=0;igetTypeOfCell(i); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); @@ -1519,19 +2270,23 @@ int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMe return ret; } -int MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const +mcIdType MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } -DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const +DataArrayIdType *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const { - int nbOfTuples=mesh->getNumberOfCells(); - DataArrayInt *ret=DataArrayInt::New(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !"); + mcIdType nbOfTuples=mesh->getNumberOfCells(); + DataArrayIdType *ret=DataArrayIdType::New(); ret->alloc(nbOfTuples+1,1); - int *retPtr=ret->getPointer(); + mcIdType *retPtr=ret->getPointer(); retPtr[0]=0; - for(int i=0;igetTypeOfCell(i); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); @@ -1542,60 +2297,373 @@ DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCoupl return ret; } -void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, - const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, + const mcIdType *old2NewBg, bool check) { - const int *array=old2NewBg; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !"); + const mcIdType *array=old2NewBg; if(check) - array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); - int nbOfCells=mesh->getNumberOfCells(); - int nbOfTuples=getNumberOfTuples(mesh); - int *array2=new int[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace. - int *array3=new int[nbOfCells];//store for each cell in after renumbering the offset needed by each cell in new numbering. + array=DataArrayIdType::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); + mcIdType nbOfCells=mesh->getNumberOfCells(); + mcIdType nbOfTuples=getNumberOfTuples(mesh); + mcIdType *array2=new mcIdType[nbOfTuples];//stores the final conversion array old2New to give to arrays in renumberInPlace. + mcIdType *array3=new mcIdType[nbOfCells];//store for each cell in after renumbering the offset needed by each cell in new numbering. array3[0]=0; - for(int i=1;igetTypeOfCell((int)std::distance(array,std::find(array,array+nbOfCells,i-1))); + INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(ToIdType(std::distance(array,std::find(array,array+nbOfCells,i-1)))); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); array3[i]=array3[i-1]+cm.getNumberOfNodes(); } - int j=0; - for(int i=0;igetTypeOfCell(i); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); - for(int k=0;k<(int)cm.getNumberOfNodes();k++,j++) + for(mcIdType k=0;k::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 { - throw INTERP_KERNEL::Exception("Not implemented yet !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !"); + MCAuto ret=DataArrayDouble::New(); + MCAuto umesh=mesh->buildUnstructured();//in general do nothing + mcIdType nbOfTuples=getNumberOfTuples(umesh); + int spaceDim=mesh->getSpaceDimension(); + ret->alloc(nbOfTuples,spaceDim); + const double *coords=umesh->getCoords()->begin(); + const mcIdType *connI=umesh->getNodalConnectivityIndex()->getConstPointer(); + const mcIdType *conn=umesh->getNodalConnectivity()->getConstPointer(); + mcIdType nbCells=umesh->getNumberOfCells(); + double *retPtr=ret->getPointer(); + for(mcIdType i=0;i=0) + retPtr=std::copy(coords+(*w)*spaceDim,coords+((*w)+1)*spaceDim,retPtr); + return ret.retn(); } -void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, const int *partBg, const int *partEnd, - DataArrayInt *&cellRest) +/*! + * 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("Not implemented yet !"); + if(!mesh || !arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::integral : input mesh or array is null !"); + std::size_t nbOfCompo=arr->getNumberOfComponents(); + std::fill(res,res+nbOfCompo,0.); + // + MCAuto vol=mesh->getMeasureField(isWAbs); + std::set types=mesh->getAllGeoTypes(); + MCAuto nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); + nbOfNodesPerCell->computeOffsetsFull(); + const double *arrPtr=arr->begin(),*volPtr=vol->getArray()->begin(); + for(std::set::const_iterator it=types.begin();it!=types.end();it++) + { + std::size_t wArrSz=-1; + const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz); + INTERP_KERNEL::AutoPtr wArr2=new double[wArrSz]; + double sum=std::accumulate(wArr,wArr+wArrSz,0.); + std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies(),1./sum)); + MCAuto ids=mesh->giveCellsWithType(*it); + MCAuto ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell); + const mcIdType *ptIds2=ids2->begin(),*ptIds=ids->begin(); + mcIdType nbOfCellsWithCurGeoType=ids->getNumberOfTuples(); + for(mcIdType i=0;i tmp=DataArrayIdType::New(); tmp->alloc(std::distance(tupleIdsBg,tupleIdsEnd),1); + std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer()); + tmp->sort(true); + tmp=tmp->buildUnique(); + MCAuto nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); + nbOfNodesPerCell->computeOffsetsFull(); + nbOfNodesPerCell->findIdsRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction); +} + +void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const +{ +} + +double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, mcIdType cellId, mcIdType nodeIdInCell, int compoId) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !"); + mcIdType offset=0; + for(mcIdType i=0;igetTypeOfCell(i); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); @@ -1604,9 +2672,9 @@ double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh return da->getIJ(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); + mcIdType nbOfTuples(getNumberOfTuples(mesh)); if(nbOfTuples!=da->getNumberOfTuples()) { std::ostringstream oss; oss << "Invalid number of tuples in the array : expecting " << nbOfTuples << " !"; @@ -1616,7 +2684,37 @@ void MEDCouplingFieldDiscretizationGaussNE::checkCoherencyBetween(const MEDCoupl MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationGaussNE::getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const { - throw INTERP_KERNEL::Exception("Not implemented yet !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getMeasureField : mesh instance specified is NULL !"); + MCAuto vol=mesh->getMeasureField(isAbs); + const double *volPtr=vol->getArray()->begin(); + MCAuto ret=MEDCouplingFieldDouble::New(ON_GAUSS_NE); + ret->setMesh(mesh); + // + std::set types=mesh->getAllGeoTypes(); + MCAuto nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); + mcIdType nbTuples=nbOfNodesPerCell->accumulate((std::size_t)0); + nbOfNodesPerCell->computeOffsetsFull(); + MCAuto arr=DataArrayDouble::New(); arr->alloc(nbTuples,1); + ret->setArray(arr); + double *arrPtr=arr->getPointer(); + for(std::set::const_iterator it=types.begin();it!=types.end();it++) + { + std::size_t wArrSz=-1; + const double *wArr=GetWeightArrayFromGeometricType(*it,wArrSz); + INTERP_KERNEL::AutoPtr wArr2=new double[wArrSz]; + double sum=std::accumulate(wArr,wArr+wArrSz,0.); + std::transform(wArr,wArr+wArrSz,(double *)wArr2,std::bind2nd(std::multiplies(),1./sum)); + MCAuto ids=mesh->giveCellsWithType(*it); + MCAuto ids2=ids->buildExplicitArrByRanges(nbOfNodesPerCell); + const mcIdType *ptIds2=ids2->begin(),*ptIds=ids->begin(); + mcIdType nbOfCellsWithCurGeoType=ids->getNumberOfTuples(); + for(mcIdType i=0;isynchronizeTimeWithSupport(); + return ret.retn(); } void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const @@ -1624,22 +2722,63 @@ void MEDCouplingFieldDiscretizationGaussNE::getValueOn(const DataArrayDouble *ar throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const +void MEDCouplingFieldDiscretizationGaussNE::getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, mcIdType i, mcIdType j, mcIdType k, double *res) const { - throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applyable for Gauss points !"); + throw INTERP_KERNEL::Exception("getValueOnPos(i,j,k) : Not applicable for Gauss points !"); } -DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const +DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfPoints) const { throw INTERP_KERNEL::Exception("getValueOnMulti : Not implemented for Gauss NE !"); } -MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const +MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const MEDCouplingMesh *mesh, const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const { - di=computeTupleIdsToSelectFromCellIds(mesh,start,end); - return mesh->buildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !"); + MCAuto diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MCAuto 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, mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&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 !"); + mcIdType nbOfCells=mesh->getNumberOfCells(); + di=0; beginOut=0; endOut=0; stepOut=stepCellIds; + const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #"; + for(mcIdType 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()); } + mcIdType delta=cm.getNumberOfNodes(); + if(i=endCellIds) + break; + } + MCAuto 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. @@ -1647,34 +2786,43 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData(const M * \return a newly allocated array containing ids to select into the DataArrayDouble of the field. * */ -DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const +DataArrayIdType *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const mcIdType *startCellIds, const mcIdType *endCellIds) const { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFromCellIds : null mesh !"); - const MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured(); - MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=umesh->computeNbOfNodesPerCell(); - nbOfNodesPerCell->computeOffsets2(); - MEDCouplingAutoRefCountObjectPtr sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1); + MCAuto nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); + nbOfNodesPerCell->computeOffsetsFull(); + MCAuto sel=DataArrayIdType::New(); sel->useArray(startCellIds,false,DeallocType::CPP_DEALLOC,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 mcIdType *, mcIdType 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 mcIdType *old2New, mcIdType newSz, DataArrayDouble *arr) const { throw INTERP_KERNEL::Exception("Not implemented yet !"); } -void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const +MCAuto MEDCouplingFieldDiscretizationGaussNE::aggregate(std::vector& fds) const +{ + return EasyAggregate(fds); +} + +void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const mcIdType *new2old, mcIdType newSz, DataArrayDouble *arr) const { 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) { } @@ -1689,6 +2837,11 @@ const char *MEDCouplingFieldDiscretizationKriging::getRepr() const return REPR; } +/*! + * This method is simply called by MEDCouplingFieldDiscretization::deepCopy. It performs the deep copy of \a this. + * + * \sa MEDCouplingFieldDiscretization::deepCopy. + */ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationKriging::clone() const { return new MEDCouplingFieldDiscretizationKriging; @@ -1699,14 +2852,19 @@ 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 !"); + if(nat!=IntensiveMaximum) + throw INTERP_KERNEL::Exception("Invalid nature for Kriging field : expected IntensiveMaximum !"); } 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) @@ -1716,48 +2874,124 @@ bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFie 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 !"); } void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { - MEDCouplingAutoRefCountObjectPtr res2=MEDCouplingFieldDiscretizationKriging::getValueOnMulti(arr,mesh,loc,1); + MCAuto res2=MEDCouplingFieldDiscretizationKriging::getValueOnMulti(arr,mesh,loc,1); std::copy(res2->begin(),res2->end(),res); } -DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, mcIdType nbOfTargetPoints) const +{ + if(!arr || !arr->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : input array is null or not allocated !"); + mcIdType 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()); + } + mcIdType nbCols(-1); + std::size_t nbCompo=arr->getNumberOfComponents(); + MCAuto m(computeEvaluationMatrixOnGivenPts(mesh,loc,nbOfTargetPoints,nbCols)); + MCAuto ret(DataArrayDouble::New()); + ret->alloc(nbOfTargetPoints,nbCompo); + INTERP_KERNEL::matrixProduct(m->begin(),nbOfTargetPoints,nbCols,arr->begin(),nbOfRows,ToIdType(nbCompo),ret->getPointer()); + return ret.retn(); +} + +void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const +{ + stream << "Kriging spatial discretization."; +} + +MCAuto MEDCouplingFieldDiscretizationKriging::aggregate(std::vector& fds) const +{ + return EasyAggregate(fds); +} + +/*! + * 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, mcIdType nbOfTargetPoints, mcIdType& nbCols) const { - MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); - int nbOfPts=coords->getNumberOfTuples(); - int dimension=coords->getNumberOfComponents(); + mcIdType isDrift(-1),nbRows(-1); + MCAuto matrixInv(computeInverseMatrix(mesh,isDrift,nbRows)); // - int delta=0; - MEDCouplingAutoRefCountObjectPtr KnewiK=computeVectorOfCoefficients(mesh,arr,delta); + MCAuto coords=getLocalizationOfDiscValues(mesh); + mcIdType nbOfPts(coords->getNumberOfTuples()); + std::size_t dimension(coords->getNumberOfComponents()); + MCAuto locArr=DataArrayDouble::New(); + locArr->useArray(loc,false,DeallocType::CPP_DEALLOC,nbOfTargetPoints,dimension); + nbCols=nbOfPts; // - MEDCouplingAutoRefCountObjectPtr locArr=DataArrayDouble::New(); - locArr->useArray(loc,false,CPP_DEALLOC,nbOfTargetPoints,dimension); - MEDCouplingAutoRefCountObjectPtr matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr); - operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfTargetPoints,matrix2->getPointer()); - MEDCouplingAutoRefCountObjectPtr matrix3=DataArrayDouble::New(); - matrix3->alloc((nbOfPts+delta)*nbOfTargetPoints,1); + MCAuto matrix2=coords->buildEuclidianDistanceDenseMatrixWith(locArr); + operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfTargetPoints*nbOfPts,matrix2->getPointer()); + // + MCAuto matrix3=DataArrayDouble::New(); + 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(mcIdType 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()); - ret->incrRef(); - return ret; + MCAuto ret(DataArrayDouble::New()); + ret->alloc(nbOfTargetPoints,nbRows); + INTERP_KERNEL::matrixProduct(matrix3->begin(),nbOfTargetPoints,nbRows,matrixInv->begin(),nbRows,nbRows,ret->getPointer()); + MCAuto ret2(DataArrayDouble::New()); + ret2->alloc(nbOfTargetPoints*nbOfPts,1); + workCst=ret->begin(); work=ret2->getPointer(); + for(mcIdType i=0;i matrixWithDrift(computeMatrix(mesh,isDrift,matSz)); + MCAuto matrixInv(DataArrayDouble::New()); + matrixInv->alloc(matSz*matSz,1); + INTERP_KERNEL::inverseMatrix(matrixWithDrift->getConstPointer(),matSz,matrixInv->getPointer()); + return matrixInv.retn(); +} + +/*! + * This method computes the kriging matrix. + * \return the new result matrix to be deallocated by the caller. + * \sa computeInverseMatrix + */ +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeMatrix(const MEDCouplingMesh *mesh, mcIdType& isDrift, mcIdType& matSz) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeMatrix : NULL input mesh !"); + MCAuto coords(getLocalizationOfDiscValues(mesh)); + mcIdType nbOfPts(coords->getNumberOfTuples()); + MCAuto matrix(coords->buildEuclidianDistanceDenseMatrix()); + operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer()); + // Drift + MCAuto matrixWithDrift(performDrift(matrix,coords,isDrift)); + matSz=nbOfPts+isDrift; + return matrixWithDrift.retn(); } /*! @@ -1766,32 +3000,19 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const Da * * \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, and if. If different from 0 there is presence of drift coefficients. + * \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 -{ - 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()); - // - MEDCouplingAutoRefCountObjectPtr KnewiK=DataArrayDouble::New(); - KnewiK->alloc((nbOfPts+isDrift)*1,1); - MEDCouplingAutoRefCountObjectPtr arr2=DataArrayDouble::New(); - arr2->alloc((nbOfPts+isDrift)*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()); - KnewiK->incrRef(); - return KnewiK; +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, mcIdType& isDrift) const +{ + mcIdType nbRows(-1); + MCAuto matrixInv(computeInverseMatrix(mesh,isDrift,nbRows)); + MCAuto KnewiK(DataArrayDouble::New()); + KnewiK->alloc(nbRows*1,1); + MCAuto arr2(PerformDriftOfVec(arr,isDrift)); + INTERP_KERNEL::matrixProduct(matrixInv->getConstPointer(),nbRows,nbRows,arr2->getConstPointer(),arr2->getNumberOfTuples(),1,KnewiK->getPointer()); + return KnewiK.retn(); } /*! @@ -1801,24 +3022,98 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficie * \param [in] nbOfElems is the result of the product of nb of rows and the nb of columns of matrix \a matrixPtr * \param [in,out] matrixPtr is the dense matrix whose on each values the operation will be applied */ -void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimension, int nbOfElems, double *matrixPtr) const +void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimension, mcIdType nbOfElems, double *matrixPtr) const { switch(spaceDimension) - { + { case 1: { - for(int i=0;iisAllocated() || matr->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input dense matrix ! Must be allocated not NULL and with exactly one component !"); + if(!arr || !arr->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : invalid input array of coordiantes ! Must be allocated and not NULL !"); + std::size_t spaceDimension(arr->getNumberOfComponents()); + mcIdType nbOfPts(arr->getNumberOfTuples()),nbOfEltInMatrx(matr->getNumberOfTuples()); + delta=ToIdType(spaceDimension)+1; + mcIdType nbOfCols(nbOfEltInMatrx/nbOfPts); + if(nbOfEltInMatrx%nbOfPts!=0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftRect : size of input dense matrix and input arrays mismatch ! NbOfElems in matrix % nb of tuples in array must be equal to 0 !"); + MCAuto ret(DataArrayDouble::New()); ret->alloc(nbOfPts*(nbOfCols+delta)); + double *retPtr(ret->getPointer()); + const double *mPtr(matr->begin()),*aPtr(arr->begin()); + for(mcIdType i=0;iisAllocated() || arr->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : input array must be not NULL allocated and with one component !"); + if(isDrift<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::PerformDriftOfVec : isDrift parameter must be >=0 !"); + MCAuto arr2(DataArrayDouble::New()); + arr2->alloc((arr->getNumberOfTuples()+isDrift)*1,1); + double *work(std::copy(arr->begin(),arr->end(),arr2->getPointer())); + std::fill(work,work+isDrift,0.); + return arr2.retn(); +} + /*! * Starting from a square matrix \a matr, this method returns a newly allocated dense square matrix whose \a matr is included in returned matrix * in the top left corner, and in the remaining returned matrix the parameters to take into account about the kriging drift. @@ -1828,20 +3123,21 @@ void MEDCouplingFieldDiscretizationKriging::operateOnDenseMatrix(int spaceDimens * \param [in] matr input matrix whose drift part will be added * \param [out] delta the difference between the size of the output matrix and the input matrix \a matr. * \return a newly allocated matrix bigger than input matrix \a matr. + * \sa MEDCouplingFieldDiscretizationKriging::PerformDriftRect */ -DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataArrayDouble *matr, const DataArrayDouble *arr, int& delta) const +DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataArrayDouble *matr, const DataArrayDouble *arr, mcIdType& delta) const { - int spaceDimension=arr->getNumberOfComponents(); - delta=spaceDimension+1; - int szOfMatrix=arr->getNumberOfTuples(); + std::size_t spaceDimension(arr->getNumberOfComponents()); + delta=ToIdType(spaceDimension)+1; + mcIdType szOfMatrix(arr->getNumberOfTuples()); if(szOfMatrix*szOfMatrix!=matr->getNumberOfTuples()) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::performDrift : invalid size"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + MCAuto ret=DataArrayDouble::New(); ret->alloc((szOfMatrix+delta)*(szOfMatrix+delta),1); const double *srcWork=matr->getConstPointer(); const double *srcWork2=arr->getConstPointer(); double *destWork=ret->getPointer(); - for(int i=0;i arrNoI=arr->toNoInterlace(); + MCAuto arrNoI=arr->toNoInterlace(); srcWork2=arrNoI->getConstPointer(); - for(int i=0;iincrRef(); - return ret; + return ret.retn(); } -