From: geay Date: Fri, 4 Jul 2014 13:42:25 +0000 (+0200) Subject: Feedback from AMR users. X-Git-Tag: V7_5_0a1~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=72643fc81ab0cf4cfc0989ef44fc2a8e598553a5;p=modules%2Fmed.git Feedback from AMR users. --- diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx index 302e8185f..d78f2a58d 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx @@ -146,6 +146,25 @@ const DataArrayDouble *DataArrayDoubleCollection::getFieldWithName(const std::st throw INTERP_KERNEL::Exception(oss.str().c_str()); } +DataArrayDouble *DataArrayDoubleCollection::getFieldWithName(const std::string& name) +{ + std::vector vec; + for(std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr, NatureOfField > >::iterator it=_arrs.begin();it!=_arrs.end();it++) + { + DataArrayDouble *obj((*it).first); + if(obj) + { + if(obj->getName()==name) + return obj; + else + vec.push_back(obj->getName()); + } + } + std::ostringstream oss; oss << "DataArrayDoubleCollection::getFieldWithName non const : fieldName \"" << name << "\" does not exist in this ! Possibilities are :"; + std::copy(vec.begin(),vec.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + DataArrayDouble *DataArrayDoubleCollection::at(int pos) { if(pos<0 || pos>=(int)_arrs.size()) @@ -275,6 +294,12 @@ DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pai for(std::size_t i=0;i& info(fieldNames[i]); + if(info.second<=0) + { + std::ostringstream oss; oss << "DataArrayDoubleCollection constructor : At pos #" << i << " the array with name \"" << info.first << "\" as a number of components equal to " << info.second; + oss << " It has to be >=1 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } _arrs[i].first=DataArrayDouble::New(); _arrs[i].first->alloc(0,info.second); _arrs[i].first->setName(info.first); @@ -858,7 +883,21 @@ const DataArrayDouble *MEDCouplingAMRAttribute::getFieldOn(MEDCouplingCartesianA return ddc.getFieldWithName(fieldName); } } - throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::retrieveFieldOn : the mesh specified is not in the progeny of this !"); + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::getFieldOn : the mesh specified is not in the progeny of this !"); +} + +DataArrayDouble *MEDCouplingAMRAttribute::getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_levs.begin();it!=_levs.end();it++) + { + int tmp(-1); + if((*it)->presenceOf(mesh,tmp)) + { + DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp)); + return ddc.getFieldWithName(fieldName); + } + } + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::getFieldOn non const : the mesh specified is not in the progeny of this !"); } /*! diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx index 3a8b7d32f..861c0b5ec 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx @@ -42,6 +42,7 @@ namespace ParaMEDMEM std::vector getNatures() const; std::vector retrieveFields() const; const DataArrayDouble *getFieldWithName(const std::string& name) const; + DataArrayDouble *getFieldWithName(const std::string& name); DataArrayDouble *at(int pos); const DataArrayDouble *at(int pos) const; int size() const; @@ -139,6 +140,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getNumberOfLevels() const; MEDCOUPLING_EXPORT std::vector retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const; MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; + MEDCOUPLING_EXPORT DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName); MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx index 7f9b405ff..68b90c750 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx @@ -1808,6 +1808,11 @@ MEDCouplingCartesianAMRMesh *MEDCouplingCartesianAMRMesh::New(const std::string& return new MEDCouplingCartesianAMRMesh(meshName,spaceDim,nodeStrctStart,nodeStrctStop,originStart,originStop,dxyzStart,dxyzStop); } +MEDCouplingCartesianAMRMesh *MEDCouplingCartesianAMRMesh::New(MEDCouplingIMesh *mesh) +{ + return new MEDCouplingCartesianAMRMesh(mesh); +} + const MEDCouplingCartesianAMRMeshGen *MEDCouplingCartesianAMRMesh::getFather() const { //I'm god father ! No father ! @@ -1926,6 +1931,10 @@ MEDCouplingCartesianAMRMesh::MEDCouplingCartesianAMRMesh(const std::string& mesh { } +MEDCouplingCartesianAMRMesh::MEDCouplingCartesianAMRMesh(MEDCouplingIMesh *mesh):MEDCouplingCartesianAMRMeshGen(mesh) +{ +} + std::vector MEDCouplingCartesianAMRMesh::getDirectChildren() const { std::vector ret(MEDCouplingCartesianAMRMeshGen::getDirectChildren()); diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx index 285f49226..a8eecc4e1 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx @@ -232,6 +232,7 @@ namespace ParaMEDMEM public: MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop); + MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(MEDCouplingIMesh *mesh); MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getFather() const; MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getGodFather() const; MEDCOUPLING_EXPORT int getAbsoluteLevel() const; @@ -246,6 +247,7 @@ namespace ParaMEDMEM MEDCouplingCartesianAMRMesh(const MEDCouplingCartesianAMRMesh& other); MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop); + MEDCouplingCartesianAMRMesh(MEDCouplingIMesh *mesh); MEDCOUPLING_EXPORT std::vector getDirectChildren() const; ~MEDCouplingCartesianAMRMesh(); }; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index d4d92e319..a81eebcb3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15148,7 +15148,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): ids=b.getIdsInRange(0.4,0.7) f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(im) ; f.setName("toto") ; arr=DataArrayDouble(im.getNumberOfCells()) ; arr[:]=0. ; arr[ids]=1. ; f.setArray(arr) # f.write("test.vti") - amr=MEDCouplingCartesianAMRMesh("mesh",2,[51,51],[0.,0.],[0.04,0.04]) + amr=MEDCouplingCartesianAMRMesh(MEDCouplingIMesh("mesh",2,[51,51],[0.,0.],[0.04,0.04])) arr2=DataArrayByte(im.getNumberOfCells()) ; arr2[:]=0 ; arr2[ids]=1 bso=BoxSplittingOptions() ; bso.setEfficiencyGoal(0.5); bso.setEfficiencyThreshold(0.8) ; bso.setMaximumNbOfCellsInPatch(3000) ; bso.setMinimumPatchLength(6) ; bso.setMaximumPatchLength(11) amr.createPatchesFromCriterion(bso,arr2,[2,2]) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 7e5a3b181..4ff7649a6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -5143,6 +5143,7 @@ namespace ParaMEDMEM class MEDCouplingCartesianAMRMesh : public MEDCouplingCartesianAMRMeshGen { public: + static MEDCouplingCartesianAMRMesh *New(MEDCouplingIMesh *mesh) throw(INTERP_KERNEL::Exception); %extend { static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, PyObject *nodeStrct, PyObject *origin, PyObject *dxyz) throw(INTERP_KERNEL::Exception) @@ -5175,7 +5176,12 @@ namespace ParaMEDMEM MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, PyObject *nodeStrct, PyObject *origin, PyObject *dxyz) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingCartesianAMRMesh_New(meshName,spaceDim,nodeStrct,origin,dxyz); + return ParaMEDMEM_MEDCouplingCartesianAMRMesh_New__SWIG_1(meshName,spaceDim,nodeStrct,origin,dxyz); + } + + MEDCouplingCartesianAMRMesh(MEDCouplingIMesh *mesh) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingCartesianAMRMesh::New(mesh); } } };