From: ageay Date: Wed, 3 Apr 2013 15:30:09 +0000 (+0000) Subject: Little possiblities for advanced users on Gauss spatial discretization X-Git-Tag: V6_main_FINAL~215 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6370e8195f630e67f83b9e831203d4e1a6c147c1;p=tools%2Fmedcoupling.git Little possiblities for advanced users on Gauss spatial discretization --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 8478acdf5..12c7138fd 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -195,6 +195,7 @@ void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh) if(_mesh) _mesh->decrRef(); _mesh=mesh; + declareAsNew(); if(_mesh) { _mesh->incrRef(); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 0703fbcab..297a8de77 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -978,6 +978,19 @@ const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() c return _discr_per_cell; } +void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception) +{ + 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() { } @@ -1494,6 +1507,25 @@ void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP _loc.clear(); } +void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception) +{ + if(locId<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !"); + int sz=(int)_loc.size(); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + if(locId>=sz) + _loc.resize(locId+1,gLoc); + _loc[locId]=loc; +} + +void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception) +{ + if(newSz<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !"); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + _loc.resize(newSz,gLoc); +} + MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) { checkLocalizationId(locId); @@ -2242,4 +2274,3 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataA // return ret.retn(); } - diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 9defb6756..5363e458c 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -191,6 +191,7 @@ namespace ParaMEDMEM { public: const DataArrayInt *getArrayOfDiscIds() const; + void setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception); void checkNoOrphanCells() const throw(INTERP_KERNEL::Exception); std::vector splitIntoSingleGaussDicrPerCellType(std::vector< int >& locIds) const throw(INTERP_KERNEL::Exception); protected: @@ -252,6 +253,8 @@ namespace ParaMEDMEM void 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 clearGaussLocalizations() throw(INTERP_KERNEL::Exception); + void setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception); + void resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception); MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index d2d915cf4..3c00355ab 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -213,17 +213,30 @@ std::string MEDCouplingFieldDouble::simpleRepr() const std::ostringstream ret; ret << "FieldDouble with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; - ret << "FieldDouble nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; + if(_type) + { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no spatial discretization !\n"; } + if(_time_discr) + { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no time discretization !\n"; } + ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; if(getArray()) { - int nbOfCompo=getArray()->getNumberOfComponents(); - ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; - ret << "FieldDouble default array has following info on components : "; - for(int i=0;igetInfoOnComponent(i) << "\" "; - ret << "\n"; + if(getArray()->isAllocated()) + { + int nbOfCompo=getArray()->getNumberOfComponents(); + ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + ret << "FieldDouble default array has following info on components : "; + for(int i=0;igetInfoOnComponent(i) << "\" "; + ret << "\n"; + } + else + { + ret << "Array set but not allocated !\n"; + } } if(_mesh) ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index 815803f81..1433d9994 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -61,8 +61,11 @@ std::string MEDCouplingFieldTemplate::simpleRepr() const std::ostringstream ret; ret << "FieldTemplate with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; + if(_type) + { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldTemplate has no spatial discretization !\n"; } + ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; if(_mesh) ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); else diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 085ea3c2f..5906ffc8b 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -42,6 +42,23 @@ catch(INTERP_KERNEL::Exception& e) throw e; } +ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception) +try:_type(typ) +{ + INTERP_KERNEL::CellModel::GetCellModel(_type); +} +catch(INTERP_KERNEL::Exception& e) + { + _type=INTERP_KERNEL::NORM_ERROR; + throw e; + } + +void ParaMEDMEM::MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception) +{ + INTERP_KERNEL::CellModel::GetCellModel(typ);//throws if not found. This is a check + _type=typ; +} + void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTERP_KERNEL::Exception) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); @@ -203,6 +220,21 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::setWeight(int gaussPtIdInCell, do _weight[gaussPtIdInCell]=newVal; } +void ParaMEDMEM::MEDCouplingGaussLocalization::setRefCoords(const std::vector& refCoo) throw(INTERP_KERNEL::Exception) +{ + _ref_coord=refCoo; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setGaussCoords(const std::vector& gsCoo) throw(INTERP_KERNEL::Exception) +{ + _gauss_coord=gsCoo; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setWeights(const std::vector& w) throw(INTERP_KERNEL::Exception) +{ + _weight=w; +} + /*! * The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo. */ diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx index cdfae2ba1..d8559ebd9 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx @@ -36,7 +36,9 @@ namespace ParaMEDMEM public: MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); + MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getType() const { return _type; } + void setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception); int getNumberOfGaussPt() const { return (int)_weight.size(); } int getDimension() const; int getNumberOfPtsInRefCell() const; @@ -57,6 +59,9 @@ namespace ParaMEDMEM void setRefCoord(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception); + void setRefCoords(const std::vector& refCoo) throw(INTERP_KERNEL::Exception); + void setGaussCoords(const std::vector& gsCoo) throw(INTERP_KERNEL::Exception); + void setWeights(const std::vector& w) throw(INTERP_KERNEL::Exception); // static MEDCouplingGaussLocalization BuildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData); static bool AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); diff --git a/src/MEDCoupling/MEDCouplingNatureOfField.cxx b/src/MEDCoupling/MEDCouplingNatureOfField.cxx index bf8984875..da684878f 100644 --- a/src/MEDCoupling/MEDCouplingNatureOfField.cxx +++ b/src/MEDCoupling/MEDCouplingNatureOfField.cxx @@ -41,5 +41,14 @@ namespace ParaMEDMEM std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos); return REPR_OF_NATUREOFFIELD[pos2]; } + + std::string MEDCouplingNatureOfField::GetReprNoThrow(NatureOfField nat) + { + const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat); + if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES) + return std::string("Unrecognized nature of field !"); + std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos); + return std::string(REPR_OF_NATUREOFFIELD[pos2]); + } } diff --git a/src/MEDCoupling/MEDCouplingNatureOfField.hxx b/src/MEDCoupling/MEDCouplingNatureOfField.hxx index 2ee69f390..0061b4952 100644 --- a/src/MEDCoupling/MEDCouplingNatureOfField.hxx +++ b/src/MEDCoupling/MEDCouplingNatureOfField.hxx @@ -39,6 +39,7 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static const char *GetRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static std::string GetReprNoThrow(NatureOfField nat); private: static const int NB_OF_POSSIBILITIES=5; static const char *REPR_OF_NATUREOFFIELD[NB_OF_POSSIBILITIES]; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 585018792..7c1ec56fe 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -11903,6 +11903,37 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0]))) self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6]))) pass + + def testSwigAdvGauss(self): + f=MEDCouplingFieldTemplate(ON_GAUSS_PT) + f.setDiscretization(None) + f.__repr__() ; f.__str__() + # + f=MEDCouplingFieldTemplate(ON_GAUSS_PT) + d=f.getDiscretization() + i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1) + d.setArrayOfDiscIds(i) + f.__repr__() ; f.__str__() + i2=d.getArrayOfDiscIds() + self.assertEqual(i.__repr__(),i2.__repr__()) + # + f=MEDCouplingFieldDouble(ON_GAUSS_PT) + f.setDiscretization(None) + f.__repr__() ; f.__str__() + # + f=MEDCouplingFieldDouble(ON_GAUSS_PT) + d=f.getDiscretization() + i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1) + d.setArrayOfDiscIds(i) + f.__repr__() ; f.__str__() + # + gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.]) + gl.setWeights([3.]) + gl.__repr__() ; gl.__str__() + gl=MEDCouplingGaussLocalization(NORM_ERROR) + gl.setWeights([3.]) + gl.__repr__() ; gl.__str__() + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 767ceffce..9b600a3f6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -521,6 +521,21 @@ namespace ParaMEDMEM } } + %extend MEDCouplingGaussLocalization + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->getStringRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; oss << "MEDCouplingGaussLocalization C++ instance at " << self << "." << std::endl; + oss << self->getStringRepr(); + return oss.str(); + } + } + class MEDCouplingMesh : public RefCountObject, public TimeLabel { public: