X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingGaussLocalization.cxx;h=ebf9cc4a0a44a53167824d4b241fbcafe108f184;hb=ffb8188e28b2b60ee207a8644286821bc4e8fcdc;hp=1b5df9b077c53ebc7f57aa6d5fd3ae2f0c70b168;hpb=293a6104470482e450701aa8061d9b244f2057d5;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 1b5df9b07..ebf9cc4a0 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.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 @@ -19,6 +19,9 @@ // Author : Anthony Geay (CEA/DEN) #include "MEDCouplingGaussLocalization.hxx" +#include "InterpKernelGaussCoords.hxx" +#include "MEDCoupling1GTUMesh.hxx" +#include "MEDCouplingUMesh.hxx" #include "CellModel.hxx" #include @@ -27,29 +30,48 @@ #include #include -ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, - const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception) +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) - { - checkCoherency(); - } +{ + checkConsistencyLight(); +} catch(INTERP_KERNEL::Exception& e) - { +{ _type=INTERP_KERNEL::NORM_ERROR; _ref_coord.clear(); _gauss_coord.clear(); _weight.clear(); throw e; - } +} -void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTERP_KERNEL::Exception) +MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) +try:_type(typ) +{ + INTERP_KERNEL::CellModel::GetCellModel(_type); +} +catch(INTERP_KERNEL::Exception& e) +{ + _type=INTERP_KERNEL::NORM_ERROR; + throw e; +} + +void MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ) +{ + INTERP_KERNEL::CellModel::GetCellModel(typ);//throws if not found. This is a check + _type=typ; +} + +void MEDCouplingGaussLocalization::checkConsistencyLight() const { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); int nbNodes=cm.getNumberOfNodes(); 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()); @@ -57,19 +79,19 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTE } if(_gauss_coord.size()!=dim*_weight.size()) { - std::ostringstream oss; oss << "Invalid gsCoo size and weight size : gsCoo.size() must be equal to _weight.size() * " << dim << " (dim) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + std::ostringstream oss; oss << "Invalid gsCoo size and weight size : gsCoo.size() must be equal to _weight.size() * " << dim << " (dim) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } } -int ParaMEDMEM::MEDCouplingGaussLocalization::getDimension() const +int MEDCouplingGaussLocalization::getDimension() const { if(_weight.empty()) return -1; return (int)_gauss_coord.size()/(int)_weight.size(); } -int ParaMEDMEM::MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const +int MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const { int dim=getDimension(); if(dim==0) @@ -77,7 +99,7 @@ int ParaMEDMEM::MEDCouplingGaussLocalization::getNumberOfPtsInRefCell() const return (int)_ref_coord.size()/dim; } -std::string ParaMEDMEM::MEDCouplingGaussLocalization::getStringRepr() const +std::string MEDCouplingGaussLocalization::getStringRepr() const { std::ostringstream oss; oss << "CellType : " << INTERP_KERNEL::CellModel::GetCellModel(_type).getRepr() << std::endl; @@ -87,7 +109,16 @@ std::string ParaMEDMEM::MEDCouplingGaussLocalization::getStringRepr() const return oss.str(); } -bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLocalization& other, double eps) const +std::size_t MEDCouplingGaussLocalization::getMemorySize() const +{ + std::size_t ret=0; + ret+=_ref_coord.capacity()*sizeof(double); + ret+=_gauss_coord.capacity()*sizeof(double); + ret+=_weight.capacity()*sizeof(double); + return ret; +} + +bool MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLocalization& other, double eps) const { if(_type!=other._type) return false; @@ -100,7 +131,7 @@ bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLoc return true; } -double ParaMEDMEM::MEDCouplingGaussLocalization::getRefCoord(int ptIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +double MEDCouplingGaussLocalization::getRefCoord(int ptIdInCell, int comp) const { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); int nbNodes=cm.getNumberOfNodes(); @@ -112,13 +143,13 @@ double ParaMEDMEM::MEDCouplingGaussLocalization::getRefCoord(int ptIdInCell, int return _ref_coord[ptIdInCell*dim+comp]; } -double ParaMEDMEM::MEDCouplingGaussLocalization::getGaussCoord(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +double MEDCouplingGaussLocalization::getGaussCoord(int gaussPtIdInCell, int comp) const { int dim=checkCoherencyOfRequest(gaussPtIdInCell,comp); return _gauss_coord[gaussPtIdInCell*dim+comp]; } -double ParaMEDMEM::MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVal) const throw(INTERP_KERNEL::Exception) +double MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVal) const { checkCoherencyOfRequest(gaussPtIdInCell,0); return _weight[gaussPtIdInCell]; @@ -129,9 +160,9 @@ double ParaMEDMEM::MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, * push at the end of tinyInfo its basic serialization info. The size of pushed data is always the same. * @param tinyInfo inout parameter. */ -void ParaMEDMEM::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()); } @@ -141,7 +172,7 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std: * push at the end of tinyInfo its basic serialization info. The size of pushed data is \b NOT always the same contrary to pushTinySerializationIntInfo. * @param tinyInfo inout parameter. */ -void ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo(std::vector& tinyInfo) const +void MEDCouplingGaussLocalization::pushTinySerializationDblInfo(std::vector& tinyInfo) const { tinyInfo.insert(tinyInfo.end(),_ref_coord.begin(),_ref_coord.end()); tinyInfo.insert(tinyInfo.end(),_gauss_coord.begin(),_gauss_coord.end()); @@ -149,12 +180,12 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo(std: } /*! - * This method operates the exact inverse operation than ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo method. This is one of the last step of unserialization process. + * This method operates the exact inverse operation than MEDCouplingGaussLocalization::pushTinySerializationDblInfo method. This is one of the last step of unserialization process. * This method should be called on an object resized by buildNewInstanceFromTinyInfo static method. * This method takes in argument a pointer 'vals' that point to the begin of double data pushed remotely by pushTinySerializationDblInfo method. * This method returns the pointer 'vals' with an offset of size what it has been read in this method. */ -const double *ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues(const double *vals) +const double *MEDCouplingGaussLocalization::fillWithValues(const double *vals) { const double *work=vals; std::copy(work,work+_ref_coord.size(),_ref_coord.begin()); @@ -166,11 +197,67 @@ const double *ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues(const dou return work; } +/*! + * Given points in \a ptsInRefCoo in the reference coordinates of \a this (in _ref_coord attribute) + * this method computes their coordinates in real world for each cells in \a mesh. + * So the returned array will contain nbCells* \a ptsInRefCoo->getNumberOfTuples() tuples and the number of component + * will be equal to the dimension of \a this. + * + * This method ignores Gauss points in \a this and only those in \a ptsInRefCoo are considered here. + */ +MCAuto MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell(const DataArrayDouble *ptsInRefCoo, const MEDCouplingUMesh *mesh) const +{ + if(!ptsInRefCoo || !mesh) + throw INTERP_KERNEL::Exception("MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell : null pointer !"); + ptsInRefCoo->checkAllocated(); + mesh->checkConsistencyLight(); + // + mcIdType nbCells=mesh->getNumberOfCells(); + const double *coords(mesh->getCoords()->begin()); + const mcIdType *connI(mesh->getNodalConnectivityIndex()->begin()),*conn(mesh->getNodalConnectivity()->begin()); + // + 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!=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(mcIdType i=0;i MEDCouplingGaussLocalization::buildRefCell() const +{ + MCAuto coo(DataArrayDouble::New()); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getType())); + 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(DataArrayIdType::New()); + conn->alloc(cm.getNumberOfNodes(),1); + conn->iota(); + ret->setNodalConnectivity(conn); + return MCAuto(ret->buildUnstructured()); +} + /*! * This method sets the comp_th component of ptIdInCell_th point coordinate of reference element of type this->_type. * @throw if not 0<=ptIdInCell& refCoo) +{ + _ref_coord=refCoo; +} + +void MEDCouplingGaussLocalization::setGaussCoords(const std::vector& gsCoo) +{ + _gauss_coord=gsCoo; +} + +void MEDCouplingGaussLocalization::setWeights(const std::vector& w) +{ + _weight=w; +} + /*! - * The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo. + * The format of 'tinyData' parameter is the same than pushed in method MEDCouplingGaussLocalization::pushTinySerializationIntInfo. */ -ParaMEDMEM::MEDCouplingGaussLocalization ParaMEDMEM::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 ParaMEDMEM::MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3); + return MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3); } -int ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception) +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) @@ -215,7 +317,7 @@ int ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussP return dim; } -bool ParaMEDMEM::MEDCouplingGaussLocalization::AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps) +bool MEDCouplingGaussLocalization::AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps) { std::size_t sz=v1.size(); if(sz!=v2.size())