X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingGaussLocalization.cxx;h=785f1fbabad77b7b459828a43c72b27a8981faf5;hb=0ba3453939dda0697b09ed7e728a01d4f33e3ce2;hp=6c69fa0c6b87d0d2d4009b54ceb6fad5aabe263d;hpb=0a68c72a271c88d7d9f558de71acf3940bd1dd4f;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 6c69fa0c6..785f1fbab 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -34,29 +34,18 @@ using namespace MEDCoupling; MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) -try:_type(type),_ref_coord(refCoo),_gauss_coord(gsCoo),_weight(w) +:_type(type),_ref_coord(refCoo),_gauss_coord(gsCoo),_weight(w) { + // Will potentially throw (and then release memory for above objects _ref_coord etc ...) checkConsistencyLight(); } -catch(INTERP_KERNEL::Exception& e) -{ - _type=INTERP_KERNEL::NORM_ERROR; - _ref_coord.clear(); - _gauss_coord.clear(); - _weight.clear(); - throw e; -} MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) -try:_type(typ) +:_type(typ) { + // Will potentially throw INTERP_KERNEL::CellModel::GetCellModel(_type); } -catch(INTERP_KERNEL::Exception& e) -{ - _type=INTERP_KERNEL::NORM_ERROR; - throw e; -} void MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ) { @@ -71,7 +60,7 @@ void MEDCouplingGaussLocalization::checkConsistencyLight() const int dim=cm.getDimension(); if(!cm.isDynamic()) { - if((int)_ref_coord.size()!=nbNodes*dim) + if(ToIdType(_ref_coord.size())!=nbNodes*dim) { std::ostringstream oss; oss << "Invalid size of refCoo : expecting to be : " << nbNodes << " (nbNodePerCell) * " << dim << " (dim) !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -87,15 +76,20 @@ void MEDCouplingGaussLocalization::checkConsistencyLight() const int MEDCouplingGaussLocalization::getDimension() const { if(_weight.empty()) - return -1; + THROW_IK_EXCEPTION("getDimension : weight is empty !"); return (int)_gauss_coord.size()/(int)_weight.size(); } int MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const { - int dim=getDimension(); - if(dim==0) - return -1; + if(_gauss_coord.empty()) + { + if(!_weight.empty()) + THROW_IK_EXCEPTION("getNumberOfPtsInRefCell : gauss_coords are empty whereas weights are not empty !"); + const INTERP_KERNEL::CellModel& cm = INTERP_KERNEL::CellModel::GetCellModel(_type); + return ((int)_ref_coord.size()) / ((int)cm.getDimension()); + } + int dim( getDimension() ); return (int)_ref_coord.size()/dim; } @@ -149,7 +143,7 @@ double MEDCouplingGaussLocalization::getGaussCoord(int gaussPtIdInCell, int comp return _gauss_coord[gaussPtIdInCell*dim+comp]; } -double MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVal) const +double MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell) const { checkCoherencyOfRequest(gaussPtIdInCell,0); return _weight[gaussPtIdInCell]; @@ -160,9 +154,9 @@ double MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVa * push at the end of tinyInfo its basic serialization info. The size of pushed data is always the same. * @param tinyInfo inout parameter. */ -void MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std::vector& tinyInfo) const +void MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std::vector& tinyInfo) const { - tinyInfo.push_back((int)_type); + tinyInfo.push_back(ToIdType(_type)); tinyInfo.push_back(getNumberOfPtsInRefCell()); tinyInfo.push_back(getNumberOfGaussPt()); } @@ -212,23 +206,22 @@ MCAuto MEDCouplingGaussLocalization::localizePtsInRefCooForEach ptsInRefCoo->checkAllocated(); mesh->checkConsistencyLight(); // - int nbCells(mesh->getNumberOfCells()); + mcIdType nbCells=mesh->getNumberOfCells(); const double *coords(mesh->getCoords()->begin()); - const int *connI(mesh->getNodalConnectivityIndex()->begin()),*conn(mesh->getNodalConnectivity()->begin()); + const mcIdType *connI(mesh->getNodalConnectivityIndex()->begin()),*conn(mesh->getNodalConnectivity()->begin()); // - int nbPts(ptsInRefCoo->getNumberOfTuples()); + mcIdType nbPts(ptsInRefCoo->getNumberOfTuples()); INTERP_KERNEL::NormalizedCellType typ(getType()); int dim(INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension()),outDim(mesh->getSpaceDimension()); MCAuto ret(DataArrayDouble::New()); ret->alloc(nbPts*nbCells,outDim); double *retPtr(ret->getPointer()); - if(dim!=ptsInRefCoo->getNumberOfComponents()) + if(dim!=ToIdType(ptsInRefCoo->getNumberOfComponents())) throw INTERP_KERNEL::Exception("MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell : number of components of input coo is not equal to dim of element !"); - const std::vector& wg(getWeights()); INTERP_KERNEL::GaussCoords calculator; calculator.addGaussInfo(typ,dim, ptsInRefCoo->begin(),nbPts,&_ref_coord[0],getNumberOfPtsInRefCell()); // - for(int i=0;i MEDCouplingGaussLocalization::buildRefCell() const { MCAuto coo(DataArrayDouble::New()); const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getType())); - if(getDimension()!=cm.getDimension()) + if(getDimension()!=ToIdType(cm.getDimension())) throw INTERP_KERNEL::Exception("BuildRefCell : dimension mistmatch !"); coo->alloc(cm.getNumberOfNodes(),getDimension()); std::copy(_ref_coord.begin(),_ref_coord.end(),coo->getPointer()); MCAuto ret(MEDCoupling1SGTUMesh::New("",getType())); ret->setCoords(coo); - MCAuto conn(DataArrayInt::New()); + MCAuto conn(DataArrayIdType::New()); conn->alloc(cm.getNumberOfNodes(),1); conn->iota(); ret->setNodalConnectivity(conn); return MCAuto(ret->buildUnstructured()); } +/*! + * This method returns an array containing for each Gauss Points in \a this, function values relative to the points of the + * reference cell. Number of components of returned array is equal to the number of points of the reference cell. + */ +MCAuto MEDCouplingGaussLocalization::getShapeFunctionValues() const +{ + MCAuto ret(DataArrayDouble::New()); + int nbGaussPt(getNumberOfGaussPt()),nbPtsRefCell(getNumberOfPtsInRefCell()),dim(getDimension()); + ret->alloc(nbGaussPt,nbPtsRefCell); + double *retPtr(ret->getPointer()); + for(int iGaussPt = 0 ; iGaussPt < nbGaussPt ; ++iGaussPt) + { + std::vector curGaussPt(_gauss_coord.begin()+iGaussPt*dim,_gauss_coord.begin()+(iGaussPt+1)*dim); + INTERP_KERNEL::GaussInfo gi(_type,curGaussPt,1,_ref_coord,nbPtsRefCell); + gi.initLocalInfo(); + const double *funcVal( gi.getFunctionValues(0) ); + std::copy(funcVal,funcVal+nbPtsRefCell,retPtr); + retPtr += nbPtsRefCell; + } + return ret; +} + +MCAuto MEDCouplingGaussLocalization::getDerivativeOfShapeFunctionValues() const +{ + MCAuto ret(DataArrayDouble::New()); + int nbGaussPt(getNumberOfGaussPt()),nbPtsRefCell(getNumberOfPtsInRefCell()),dim(getDimension()); + ret->alloc(nbGaussPt,nbPtsRefCell*dim); + double *retPtr(ret->getPointer()); + for(int iGaussPt = 0 ; iGaussPt < nbGaussPt ; ++iGaussPt) + { + std::vector curGaussPt(_gauss_coord.begin()+iGaussPt*dim,_gauss_coord.begin()+(iGaussPt+1)*dim); + INTERP_KERNEL::GaussInfo gi(_type,curGaussPt,1,_ref_coord,nbPtsRefCell); + gi.initLocalInfo(); + const double *devOfFuncVal( gi.getDerivativeOfShapeFunctionAt(0) ); + std::copy(devOfFuncVal,devOfFuncVal+nbPtsRefCell*dim,retPtr); + retPtr += nbPtsRefCell*dim; + } + return ret; +} + /*! * This method sets the comp_th component of ptIdInCell_th point coordinate of reference element of type this->_type. * @throw if not 0<=ptIdInCell& w) /*! * The format of 'tinyData' parameter is the same than pushed in method MEDCouplingGaussLocalization::pushTinySerializationIntInfo. */ -MEDCouplingGaussLocalization MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData) +MEDCouplingGaussLocalization MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(mcIdType dim, const std::vector& tinyData) { std::vector v1(dim*tinyData[1]),v2(dim*tinyData[2]),v3(tinyData[2]); return MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3); } -int MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const +int MEDCouplingGaussLocalization::checkCoherencyOfRequest(mcIdType gaussPtIdInCell, int comp) const { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); int dim=cm.getDimension(); - int nbGsPts=getNumberOfGaussPt(); + mcIdType nbGsPts=getNumberOfGaussPt(); if(gaussPtIdInCell<0 || gaussPtIdInCell>=nbGsPts) throw INTERP_KERNEL::Exception("gaussPtIdInCell specified is invalid : must be in [0:nbGsPts) !"); if(comp<0 || comp>=dim) @@ -324,6 +357,20 @@ bool MEDCouplingGaussLocalization::AreAlmostEqual(const std::vector& v1, return false; std::vector tmp(sz); std::transform(v1.begin(),v1.end(),v2.begin(),tmp.begin(),std::minus()); - std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::ptr_fun(fabs)); + std::transform(tmp.begin(),tmp.end(),tmp.begin(),[](double c){return fabs(c);}); return *std::max_element(tmp.begin(),tmp.end()) MEDCouplingGaussLocalization::GetDefaultReferenceCoordinatesOf(INTERP_KERNEL::NormalizedCellType type) +{ + std::vector retCpp(INTERP_KERNEL::GaussInfo::GetDefaultReferenceCoordinatesOf(type)); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + auto nbDim(cm.getDimension()); + std::size_t sz(retCpp.size()); + MCAuto ret(DataArrayDouble::New()); + if( sz%std::size_t(nbDim) != 0 ) + THROW_IK_EXCEPTION("GetDefaultReferenceCoordinatesOf : unexpected size of defaut array : " << sz << " % " << nbDim << " != 0 !"); + ret->alloc(sz/size_t(nbDim),nbDim); + std::copy(retCpp.begin(),retCpp.end(),ret->getPointer()); + return ret; +}