Salome HOME
Feedback from AMR users.
authorgeay <anthony.geay@cea.fr>
Fri, 4 Jul 2014 13:42:25 +0000 (15:42 +0200)
committergeay <anthony.geay@cea.fr>
Fri, 4 Jul 2014 13:42:25 +0000 (15:42 +0200)
src/MEDCoupling/MEDCouplingAMRAttribute.cxx
src/MEDCoupling/MEDCouplingAMRAttribute.hxx
src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx
src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 302e8185f493898f2c09e1beae61ee95cc29fcd2..d78f2a58d2dabf60374e72256e420ac661986b07 100644 (file)
@@ -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<std::string> vec;
+  for(std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, 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<std::string>(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<sz;i++)
     {
       const std::pair<std::string,int>& 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<MEDCouplingGridCollection> >::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 !");
 }
 
 /*!
index 3a8b7d32fd9273e9df54af38d0689edac873032a..861c0b5ec7779efbed7c1d69d417490a2f7297ec 100644 (file)
@@ -42,6 +42,7 @@ namespace ParaMEDMEM
     std::vector<NatureOfField> getNatures() const;
     std::vector<DataArrayDouble *> 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<DataArrayDouble *> 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;
index 7f9b405ff187f83d351f8470227574fe8b0f65b1..68b90c7503c1215bb24fe057b68e0a7a4d8b67ca 100644 (file)
@@ -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<const BigMemoryObject *> MEDCouplingCartesianAMRMesh::getDirectChildren() const
 {
   std::vector<const BigMemoryObject *> ret(MEDCouplingCartesianAMRMeshGen::getDirectChildren());
index 285f49226be73ca7741ec0d037e4062300d8f714..a8eecc4e13483d59b6e865d9928cb4a6d0578386 100644 (file)
@@ -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<const BigMemoryObject *> getDirectChildren() const;
     ~MEDCouplingCartesianAMRMesh();
   };
index d4d92e319f5a38ee853161ec2a2de0811ce5d0b9..a81eebcb303e2ae3d10fa487c12f6a0b93d1a351 100644 (file)
@@ -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])
index 7e5a3b181f198534a3f78f2512d790b69fb8df68..4ff7649a6bc9fb3a2ee09302c4187f7edae1de67 100644 (file)
@@ -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);
       }
     }
   };