]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Before refactoring for convergence between meshes and structureMeshes
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 18 Jan 2017 10:42:40 +0000 (11:42 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 18 Jan 2017 10:42:40 +0000 (11:42 +0100)
src/MEDLoader/MEDFileData.cxx
src/MEDLoader/MEDFileData.hxx
src/MEDLoader/MEDFileMeshSupport.cxx
src/MEDLoader/MEDFileMeshSupport.hxx

index 6add25ef62b5fc3888ee4bf7ef6ec94730b03c47..f5a33b39146cce0c7b0b896f2900fc91408326d3 100644 (file)
@@ -69,6 +69,7 @@ std::vector<const BigMemoryObject *> MEDFileData::getDirectChildrenWithNull() co
   ret.push_back((const MEDFileFields *)_fields);
   ret.push_back((const MEDFileMeshes *)_meshes);
   ret.push_back((const MEDFileParameters *)_params);
+  ret.push_back((const MEDFileMeshSupports *)_mesh_supports);
   return ret;
 
 }
@@ -308,6 +309,7 @@ try
   _fields=MEDFileFields::New(fid);
   _meshes=MEDFileMeshes::New(fid);
   _params=MEDFileParameters::New(fid);
+  _mesh_supports=MEDFileMeshSupports::New(fid);
 }
 catch(INTERP_KERNEL::Exception& e)
 {
@@ -317,15 +319,14 @@ catch(INTERP_KERNEL::Exception& e)
 void MEDFileData::writeLL(med_idt fid) const
 {
   writeHeader(fid);
-  const MEDFileMeshes *ms(_meshes);
-  if(ms)
-    ms->writeLL(fid);
-  const MEDFileFields *fs(_fields);
-  if(fs)
-    fs->writeLL(fid);
-  const MEDFileParameters *ps(_params);
-  if(ps)
-    ps->writeLL(fid);
+  if(_meshes.isNotNull())
+    _meshes->writeLL(fid);
+  if(_fields.isNotNull())
+    _fields->writeLL(fid);
+  if(_params.isNotNull())
+    _params->writeLL(fid);
+  if(_mesh_supports.isNotNull())
+    _mesh_supports->writeLL(fid);
 }
 
 std::string MEDFileData::getHeader() const
@@ -342,8 +343,9 @@ void MEDFileData::setHeader(const std::string& header)
 void MEDFileData::readHeader(med_idt fid)
 {
   INTERP_KERNEL::AutoPtr<char> header(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
-  MEDFILESAFECALLERRD0(MEDfileCommentRd,(fid,header));
-  _header=MEDLoaderBase::buildStringFromFortran(header,MED_COMMENT_SIZE);
+  int ret(MEDfileCommentRd(fid,header));
+  if(ret==0)
+    _header=MEDLoaderBase::buildStringFromFortran(header,MED_COMMENT_SIZE);
 }
 
 void MEDFileData::writeHeader(med_idt fid) const
index 2baac71f6b7c64244104eb6d96e3f0e4d58af07d..e2dbfb79915a9aa4357b9bbaf9c4ae93d2cd4751 100644 (file)
@@ -67,11 +67,12 @@ namespace MEDCoupling
     MEDFileData(med_idt fid);
     void readHeader(med_idt fid);
     void writeHeader(med_idt fid) const;
+    void readMeshSupports(med_idt fid);
   private:
     MCAuto<MEDFileFields> _fields;
     MCAuto<MEDFileMeshes> _meshes;
     MCAuto<MEDFileParameters> _params;
-    std::vector< MCAuto<MEDFileMeshSupport> > _mesh_supports;
+    MCAuto<MEDFileMeshSupports> _mesh_supports;
     std::string _header;
   };
 }
index b7ff2ab561524754a565cfc3959aac5c16e88a92..d92a46de7a852469f2e5175c9f0e26b8304871c7 100644 (file)
@@ -21,6 +21,7 @@
 #include "MEDFileMeshSupport.hxx"
 
 #include "MEDLoaderBase.hxx"
+#include "MEDFileMeshLL.hxx"
 #include "MEDFileSafeCaller.txx"
 
 #include "InterpKernelAutoPtr.hxx"
@@ -80,13 +81,112 @@ void MEDFileMeshSupport::writeLL(med_idt fid) const
 MEDFileMeshSupport::MEDFileMeshSupport(med_idt fid, int smid)
 {
   INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
-  INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
   med_axis_type axType;
-  int nAxis(MEDsupportMeshnAxis(fid,smid));
+  int nAxis(MEDsupportMeshnAxis(fid,smid+1));
   INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
-  MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit));
+  MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid+1,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit));
+  _name=MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE);
+  _description=MEDLoaderBase::buildStringFromFortran(description,MED_COMMENT_SIZE);
+  _axis_type=MEDFileMeshL2::TraduceAxisType(axType);
+  int nCoords(0),nmodels(0);
+  {
+    med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+    nCoords=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_COORDINATE,MED_NODAL,&chgt,&trsf);
+    nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
+  }
+  _coords=DataArrayDouble::New(); _coords->alloc(nCoords,nAxis);
+  for(int i=0;i<nAxis;i++)
+    {
+      std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
+                                                          MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
+      _coords->setInfoOnComponent(i,info);
+    }
+  MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer()));
+  {
+    med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf)>0)
+      {
+        _fam_coords=DataArrayInt::New();
+        _fam_coords->alloc(nCoords,1);
+        MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
+      }
+    else
+      _fam_coords=0;
+    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&chgt,&trsf)>0)
+      {
+        _num_coords=DataArrayInt::New();
+        _num_coords->alloc(nCoords,1);
+        MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
+      }
+    else
+    _num_coords=0;
+    if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&chgt,&trsf)>0)
+      {
+        _name_coords=DataArrayAsciiChar::New();
+        _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
+        MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
+        _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
+      }
+    else
+      _name_coords=0;
+  }
+    //med_bool withnodename;
+  //MEDmeshNodeRd(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer(),);
+  std::cerr << nCoords << " ** " << nmodels << std::endl;
 }
 
-MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1)
+MEDFileMeshSupport::~MEDFileMeshSupport()
 {
 }
+
+MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1),_axis_type(AX_CART)
+{
+}
+
+MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid)
+{
+  return new MEDFileMeshSupports(fid);
+}
+
+MEDFileMeshSupports *MEDFileMeshSupports::New()
+{
+  return new MEDFileMeshSupports;
+}
+
+MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid)
+{
+  int nbSM(MEDnSupportMesh(fid));
+  _supports.resize(nbSM);
+  for(int i=0;i<nbSM;i++)
+    _supports[i]=MEDFileMeshSupport::New(fid,i);
+}
+
+MEDFileMeshSupports::MEDFileMeshSupports()
+{
+}
+
+MEDFileMeshSupports::~MEDFileMeshSupports()
+{
+}
+
+std::vector<const BigMemoryObject *> MEDFileMeshSupports::getDirectChildrenWithNull() const
+{
+  std::size_t sz(_supports.size());
+  std::vector<const BigMemoryObject *> ret(sz);
+  for(std::size_t i=0;i<sz;i++)
+    ret[i]=_supports[i];
+  return ret;
+}
+
+std::size_t MEDFileMeshSupports::getHeapMemorySizeWithoutChildren() const
+{
+  return _supports.capacity()*sizeof(MCAuto<MEDFileMeshSupport>);
+}
+
+void MEDFileMeshSupports::writeLL(med_idt fid) const
+{
+  for(std::vector< MCAuto<MEDFileMeshSupport> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
+    if((*it).isNotNull())
+      (*it)->writeLL(fid);
+}
index f8d136776405b4f4ba2a33e646edfa393cb7efb7..e26c0a0d04ba8d9a1389b3d2d2923ef460f097f0 100644 (file)
@@ -41,14 +41,41 @@ namespace MEDCoupling
     MEDLOADER_EXPORT void setSpaceDim(int dim);
     MEDLOADER_EXPORT int getMeshDim() const;
     MEDLOADER_EXPORT void setMeshDim(int dim);
-  private:
+    MEDLOADER_EXPORT void setAxisType(MEDCouplingAxisType at) { _axis_type=at; }
+    MEDLOADER_EXPORT MEDCouplingAxisType getAxisType() const { return _axis_type; }
+  public:
     void writeLL(med_idt fid) const;
+  private:
     MEDFileMeshSupport(med_idt fid, int smid);
     MEDFileMeshSupport();
+    ~MEDFileMeshSupport();
   private:
     int _space_dim;
     int _mesh_dim;
+    std::string _name;
     std::string _description;
+    MEDCouplingAxisType _axis_type;
+    MCAuto<DataArrayDouble> _coords;
+    MCAuto<DataArrayInt> _fam_coords;
+    MCAuto<DataArrayInt> _num_coords;
+    MCAuto<DataArrayAsciiChar> _name_coords;
+  };
+
+  class MEDFileMeshSupports : public RefCountObject, public MEDFileWritableStandAlone
+  {
+  public:
+    MEDLOADER_EXPORT static MEDFileMeshSupports *New(med_idt fid);
+    MEDLOADER_EXPORT static MEDFileMeshSupports *New();
+  public:
+    std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+    std::size_t getHeapMemorySizeWithoutChildren() const;
+    void writeLL(med_idt fid) const;
+  private:
+    MEDFileMeshSupports(med_idt fid);
+    MEDFileMeshSupports();
+    ~MEDFileMeshSupports();
+  private:
+    std::vector< MCAuto<MEDFileMeshSupport> > _supports;
   };
 }