Salome HOME
mv MEDFileEquivalence to medtool subdirectory
authorCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 2 Dec 2015 13:13:24 +0000 (14:13 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 2 Dec 2015 13:13:24 +0000 (14:13 +0100)
src/MEDLoader/MEDFileEquivalence.cxx [new file with mode: 0644]
src/MEDLoader/MEDFileEquivalence.hxx [new file with mode: 0644]

diff --git a/src/MEDLoader/MEDFileEquivalence.cxx b/src/MEDLoader/MEDFileEquivalence.cxx
new file mode 100644 (file)
index 0000000..5f9ff6d
--- /dev/null
@@ -0,0 +1,769 @@
+// Copyright (C) 2007-2015  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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "MEDFileEquivalence.hxx"
+#include "MEDFileSafeCaller.txx"
+#include "MEDCouplingMemArray.hxx"
+#include "MEDLoaderBase.hxx"
+#include "MEDFileMesh.hxx"
+#include "InterpKernelAutoPtr.hxx"
+
+extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
+extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
+extern med_geometry_type typmai3[34];
+extern med_geometry_type typmainoeud[1];
+
+using namespace ParaMEDMEM;
+
+MEDFileEquivalencePair *MEDFileEquivalencePair::Load(MEDFileEquivalences *father, med_idt fid, const std::string& name, const std::string &desc)
+{
+  if(!father)
+    throw INTERP_KERNEL::Exception("MEDFileEquivalencePair::Load : father is NULL ! Should not !");
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> ret(new MEDFileEquivalencePair(father,name,desc));
+  ret->load(fid);
+  return ret.retn();
+}
+
+void MEDFileEquivalencePair::write(med_idt fid) const
+{
+  std::string meshName(getFather()->getMeshName());
+  INTERP_KERNEL::AutoPtr<char> meshName2(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> name(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> desc(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
+  MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,meshName2,getFather()->getMesh()->getTooLongStrPolicy());
+  MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,name,getFather()->getMesh()->getTooLongStrPolicy());
+  MEDLoaderBase::safeStrCpy(_description.c_str(),MED_COMMENT_SIZE,desc,getFather()->getMesh()->getTooLongStrPolicy());
+  MEDFILESAFECALLERWR0(MEDequivalenceCr,(fid,meshName2,name,desc));
+  const MEDFileEquivalenceCell *cell(_cell);
+  if(cell)
+    cell->write(fid);
+  const MEDFileEquivalenceNode *node(_node);
+  if(node)
+    node->write(fid);
+}
+
+const MEDFileMesh *MEDFileEquivalencePair::getMesh() const
+{
+  return getFather()->getMesh();
+}
+
+MEDFileMesh *MEDFileEquivalencePair::getMesh()
+{
+  return getFather()->getMesh();
+}
+
+MEDFileEquivalencePair *MEDFileEquivalencePair::deepCpy(MEDFileEquivalences *father) const
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> ret(new MEDFileEquivalencePair(father,_name,_description));
+  const MEDFileEquivalenceCell *cell(_cell);
+  if(cell)
+    ret->_cell=cell->deepCpy(const_cast<MEDFileEquivalencePair *>(this));
+  const MEDFileEquivalenceNode *node(_node);
+  if(node)
+    ret->_node=node->deepCpy(const_cast<MEDFileEquivalencePair *>(this));
+  return ret.retn();
+}
+
+bool MEDFileEquivalencePair::isEqual(const MEDFileEquivalencePair *other, std::string& what) const
+{
+  if(_name!=other->_name)
+    {
+      std::ostringstream oss; oss << "Names differs : " << _name << " != " << other->_name << " !";
+      what=oss.str();
+      return false;
+    }
+  if(_description!=other->_description)
+    {
+       std::ostringstream oss; oss << "Description differs : " << _description << " != " << other->_description << " !";
+       what=oss.str();
+       return false;
+    }
+  const MEDFileEquivalenceCell *c1(_cell),*c2(other->_cell);
+  if((c1 && !c2) || (!c1 && c2))
+    {
+      std::ostringstream oss; oss << "Cell def of Equiv " << _name << " are defined for this and not for other (or reversely) !";
+      what=oss.str();
+      return false;
+    }
+  if(c1 && c2)
+    if(!c1->isEqual(c2,what))
+      return false;
+  const MEDFileEquivalenceNode *n1(_node),*n2(other->_node);
+  if((n1 && !n2) || (!n1 && n2))
+    {
+      std::ostringstream oss; oss << "Node def of Equiv " << _name << " are defined for this and not for other (or reversely) !";
+      what=oss.str();
+      return false;
+    }
+  if(n1 && n2)
+    if(!n1->isEqual(n2,what))
+      return false;
+  return true;
+}
+
+void MEDFileEquivalencePair::getRepr(std::ostream& oss) const
+{
+  const MEDFileEquivalenceNode *node(_node);
+  const MEDFileEquivalenceCell *cell(_cell);
+  oss << std::endl << "  name of equivalence : " << _name << std::endl;
+  oss << "  description of equivalence : " << _description << std::endl;
+  oss << "  Node : ";
+  if(!node)
+    oss << "None" << std::endl;
+  else
+    node->getRepr(oss);
+  oss << "  Cell : ";
+  if(!cell)
+    oss << "None" << std::endl;
+  else
+    cell->getRepr(oss);
+}
+
+MEDFileEquivalencePair *MEDFileEquivalencePair::New(MEDFileEquivalences *father, const std::string& name)
+{
+  return new MEDFileEquivalencePair(father,name,std::string());
+}
+
+std::vector<const BigMemoryObject *> MEDFileEquivalencePair::getDirectChildrenWithNull() const
+{
+  std::vector<const BigMemoryObject *> ret(2);
+  ret[0]=_cell; ret[1]=_node;
+  return ret;
+}
+
+void MEDFileEquivalencePair::setArray(int meshDimRelToMaxExt, DataArrayInt *da)
+{
+  if(meshDimRelToMaxExt>1)
+    throw INTERP_KERNEL::Exception("MEDFileEquivalencePair::setArray : meshDimRelToMaxExt must be in [1,0,-1,-2,-3] at most !");
+  if(meshDimRelToMaxExt==1)
+    {
+      MEDFileEquivalenceNode *node(_node);
+      if(!node)
+        {
+          _node=new MEDFileEquivalenceNode(this,0);
+          node=_node;
+        }
+      node->setArray(da);
+    }
+  else
+    {
+      MEDFileEquivalenceCell *cell(_cell);
+      if(!cell)
+        {
+          _cell=new MEDFileEquivalenceCell(this);
+          cell=_cell;
+        }
+      cell->setArray(meshDimRelToMaxExt,da);
+    }
+}
+
+/*!
+ * The returned pointer is a borrowed pointer.
+ */
+MEDFileEquivalenceCell *MEDFileEquivalencePair::initCell()
+{
+  _cell=new MEDFileEquivalenceCell(this);
+  return _cell;
+}
+
+/*!
+ * The returned pointer is a borrowed pointer.
+ */
+MEDFileEquivalenceNode *MEDFileEquivalencePair::initNode()
+{
+  _node=new MEDFileEquivalenceNode(this,0);
+  return _node;
+}
+
+std::size_t MEDFileEquivalencePair::getHeapMemorySizeWithoutChildren() const
+{
+  return 0;
+}
+
+void MEDFileEquivalencePair::load(med_idt fid)
+{
+  std::string meshName(_father->getMeshName());
+  int dt,it;
+  _father->getDtIt(dt,it);
+  med_int ncor;
+  MEDFILESAFECALLERRD0(MEDequivalenceCorrespondenceSize,(fid,meshName.c_str(),_name.c_str(),dt,it,MED_NODE,MED_NONE,&ncor));
+  if(ncor>0)
+    {
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da(DataArrayInt::New());
+      da->alloc(ncor*2);
+      MEDFILESAFECALLERRD0(MEDequivalenceCorrespondenceRd,(fid,meshName.c_str(),_name.c_str(),dt,it,MED_NODE,MED_NONE,da->getPointer()));
+      da->applyLin(1,-1);
+      da->rearrange(2);
+      MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceNode> node(new MEDFileEquivalenceNode(this,da));
+      _node=node;
+    }
+  _cell=MEDFileEquivalenceCell::Load(fid,this);
+}
+
+std::vector<const BigMemoryObject *> MEDFileEquivalences::getDirectChildrenWithNull() const
+{
+  std::size_t sz(_equ.size());
+  std::vector<const BigMemoryObject *> ret(sz);
+  for(std::size_t i=0;i<sz;i++)
+    ret[i]=_equ[i];
+  return ret;
+}
+
+std::size_t MEDFileEquivalences::getHeapMemorySizeWithoutChildren() const
+{
+  return sizeof(MEDFileEquivalences)+_equ.capacity()*sizeof(MEDFileEquivalencePair);
+}
+
+void MEDFileEquivalences::getDtIt(int &dt, int &it) const
+{
+  dt=_owner->getIteration(); it=_owner->getOrder();
+}
+
+std::string MEDFileEquivalences::getMeshName() const
+{
+  return _owner->getName();
+}
+
+void MEDFileEquivalences::pushEquivalence(MEDFileEquivalencePair *elt)
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> elta(elt);
+  if(elt)
+    elt->incrRef();
+  _equ.push_back(elta);
+}
+
+MEDFileEquivalencePair *MEDFileEquivalences::getEquivalence(int i)
+{
+  int sz(size());
+  if(i<0 || i>=sz)
+    {
+      std::ostringstream oss; oss << "MEDFileEquivalences::getEquivalence : invalid id ! Must be in [0," << sz << ") !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  return _equ[i];
+}
+
+MEDFileEquivalencePair *MEDFileEquivalences::getEquivalenceWithName(const std::string& name)
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::iterator it=_equ.begin();it!=_equ.end();it++)
+    {
+      MEDFileEquivalencePair *elt(*it);
+      if(elt)
+        {
+          if(elt->getName()==name)
+            return elt;
+        }
+    }
+  std::ostringstream oss; oss << "MEDFileEquivalences::getEquivalenceWithName : no equivalence with name \"" << name << "\" ! Must be in [ ";
+  std::vector<std::string> eqs(getEquivalenceNames());
+  std::copy(eqs.begin(),eqs.end(),std::ostream_iterator<std::string>(oss,", "));
+  oss << "] !";
+  throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
+int MEDFileEquivalences::size() const
+{
+  return _equ.size();
+}
+
+std::vector<std::string> MEDFileEquivalences::getEquivalenceNames() const
+{
+  std::vector<std::string> ret;
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::const_iterator it=_equ.begin();it!=_equ.end();it++)
+    {
+      const MEDFileEquivalencePair *elt(*it);
+      if(elt)
+        {
+          ret.push_back(elt->getName());
+        }
+    }
+  return ret;
+}
+
+MEDFileEquivalencePair *MEDFileEquivalences::appendEmptyEquivalenceWithName(const std::string& name)
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> elt(MEDFileEquivalencePair::New(this,name));
+  _equ.push_back(elt);
+  return elt;
+}
+
+MEDFileEquivalences *MEDFileEquivalences::deepCpy(MEDFileMesh *owner) const
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalences> ret(new MEDFileEquivalences(owner));
+  ret->deepCpyFrom(*this);
+  return ret.retn();
+}
+
+bool MEDFileEquivalences::isEqual(const MEDFileEquivalences *other, std::string& what) const
+{
+  std::size_t sz(_equ.size());
+  if(sz!=other->_equ.size())
+    {
+      what="Equivalences differs : not same number !";
+      return false;
+    }
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const MEDFileEquivalencePair *thisp(_equ[i]),*otherp(other->_equ[i]);
+      if(!thisp && !otherp)
+        continue;
+      if(thisp && otherp)
+        {
+          if(!thisp->isEqual(otherp,what))
+            {
+              std::ostringstream oss; oss << "At Eq #" << i << " there is a difference !";
+              what=oss.str()+what;
+              return false;
+            }
+        }
+      else
+        {
+          std::ostringstream oss; oss << "At Eq #" << i << " defined in this not is other (or reversely) !";
+          what=oss.str()+what;
+          return false;
+        }
+    }
+}
+
+void MEDFileEquivalences::getRepr(std::ostream& oss) const
+{
+  std::size_t ii(0);
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::const_iterator it=_equ.begin();it!=_equ.end();it++,ii++)
+    {
+      const MEDFileEquivalencePair *elt(*it);
+      oss << "Equivalence #" << ii << " : " ;
+      if(elt)
+        elt->getRepr(oss);
+      else
+        oss << "None" << std::endl;
+    }
+}
+
+void MEDFileEquivalences::killEquivalenceWithName(const std::string& name)
+{
+  std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::iterator it(_equ.begin());
+  for(;it!=_equ.end();it++)
+    {
+      const MEDFileEquivalencePair *elt(*it);
+      if(elt && elt->getName()==name)
+        break;
+    }
+  if(it==_equ.end())
+    {
+      std::ostringstream oss; oss << "MEDFileEquivalences::killEquivalenceWithName : Equivalence with name \"" << name << "\" not found !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  _equ.erase(it);
+}
+
+void MEDFileEquivalences::killEquivalenceAt(int i)
+{
+  int sz(size());
+  if(i<0 || i>=sz)
+    {
+      std::ostringstream oss; oss << "MEDFileEquivalences::killEquivalenceAt : Id must be in [0," << sz << ") !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::iterator it(_equ.begin());
+  for(int j=0;j<i;it++,j++);
+  _equ.erase(it);
+}
+
+void MEDFileEquivalences::clear()
+{
+  _equ.clear();
+}
+
+void MEDFileEquivalences::write(med_idt fid) const
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::const_iterator it=_equ.begin();it!=_equ.end();it++)
+    {
+      const MEDFileEquivalencePair *elt(*it);
+      if(elt)
+        elt->write(fid);
+    }
+}
+
+int MEDFileEquivalences::PresenceOfEquivalences(med_idt fid, const std::string& meshName)
+{
+  med_int nequ(MEDnEquivalence(fid,meshName.c_str()));
+  return nequ;
+}
+
+MEDFileEquivalences *MEDFileEquivalences::Load(med_idt fid, int nbOfEq, MEDFileMesh *owner)
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalences> ret(new MEDFileEquivalences(owner));
+  if(!owner)
+    throw INTERP_KERNEL::Exception("MEDFileEquivalences::Load : owner is NULL !");
+  std::string meshName(owner->getName());
+  for(int i=0;i<nbOfEq;i++)
+    {
+      INTERP_KERNEL::AutoPtr<char> equ(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+      INTERP_KERNEL::AutoPtr<char> desc(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
+      int nstep,nocstpncor;
+      MEDFILESAFECALLERRD0(MEDequivalenceInfo,(fid,meshName.c_str(),i+1,equ,desc,&nstep,&nocstpncor));
+      std::string eqName(MEDLoaderBase::buildStringFromFortran(equ,MED_NAME_SIZE)),eqDescName(MEDLoaderBase::buildStringFromFortran(desc,MED_COMMENT_SIZE));
+      MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> eqv(MEDFileEquivalencePair::Load(ret,fid,eqName,eqDescName));
+      ret->pushEquivalence(eqv);
+    }
+  return ret.retn();
+}
+
+void MEDFileEquivalences::CheckDataArray(const DataArrayInt *data)
+{
+  if(!data)
+    return;
+  data->checkAllocated();
+  if(data->getNumberOfComponents()!=2)
+    {
+      std::ostringstream oss; oss << "MEDFileEquivalences::CheckDataArray : Input DataArray must have 2 components !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+void MEDFileEquivalences::deepCpyFrom(const MEDFileEquivalences& other)
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> >::const_iterator it=other._equ.begin();it!=other._equ.end();it++)
+    {
+      const MEDFileEquivalencePair *elt(*it);
+      MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> eltCpy;
+      if(elt)
+        {
+          eltCpy=elt->deepCpy(this);
+        }
+      _equ.push_back(eltCpy);
+    }
+}
+
+MEDFileEquivalenceBase::MEDFileEquivalenceBase(MEDFileEquivalencePair *father):_father(father)
+{
+}
+
+MEDFileEquivalenceData::MEDFileEquivalenceData(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceBase(owner),_data(data)
+{
+  if(data)
+    data->incrRef();
+}
+
+void MEDFileEquivalenceData::setArray(DataArrayInt *data)
+{
+  MEDFileEquivalences::CheckDataArray(data);
+  _data=data;
+  if(data)
+    data->incrRef();
+}
+
+std::vector<const BigMemoryObject *> MEDFileEquivalenceData::getDirectChildrenWithNull() const
+{
+  std::vector<const BigMemoryObject *> ret(1);
+  ret[0]=_data;
+  return ret;
+}
+
+bool MEDFileEquivalenceData::isEqual(const MEDFileEquivalenceData *other, std::string& what) const
+{
+  const DataArrayInt *d1(_data),*d2(other->_data);
+  if((!d1 && d2) || (d1 && !d2))
+    {
+      what="Data array is defined in this not in other (or reversely) !";
+      return false;
+    }
+  if(d1 && d2)
+    {
+      if(!d1->isEqualIfNotWhy(*d2,what))
+        return false;
+    }
+  return true;
+}
+
+void MEDFileEquivalenceData::writeLL(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const
+{
+  
+  const DataArrayInt *da(getArray());
+  if(!da)
+    return ;
+  MEDFileEquivalences::CheckDataArray(da);
+  const MEDFileMesh *mesh(getFather()->getMesh());
+  int dt,it;
+  mesh->getTime(dt,it);
+  std::string meshName(mesh->getName());
+  std::string equName(getFather()->getName());
+  INTERP_KERNEL::AutoPtr<char> meshName2(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> name(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,meshName2,getFather()->getMesh()->getTooLongStrPolicy());
+  MEDLoaderBase::safeStrCpy(equName.c_str(),MED_NAME_SIZE,name,getFather()->getMesh()->getTooLongStrPolicy());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2(da->deepCpy()); da2->rearrange(1); da2->applyLin(1,1); da2->rearrange(2);
+  MEDFILESAFECALLERWR0(MEDequivalenceCorrespondenceWr,(fid,meshName2,name,dt,it,medtype,medgt,da2->getNumberOfTuples(),da2->begin()));
+}
+
+std::size_t MEDFileEquivalenceCellType::getHeapMemorySizeWithoutChildren() const
+{
+  return sizeof(MEDFileEquivalenceCellType);
+}
+
+MEDFileEquivalenceCellType *MEDFileEquivalenceCellType::deepCpy(MEDFileEquivalencePair *owner) const
+{
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
+  if(getArray())
+    da=getArray()->deepCpy();
+  return new MEDFileEquivalenceCellType(owner,_type,da);
+}
+
+bool MEDFileEquivalenceCellType::isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const
+{
+  if(_type!=other->_type)
+    {
+      what="Geo types differs !";
+      return false;
+    }
+  return MEDFileEquivalenceData::isEqual(other,what);
+}
+
+void MEDFileEquivalenceCellType::getRepr(std::ostream& oss) const
+{
+  const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_type));
+  const DataArrayInt *da(getArray());
+  oss << cm.getRepr() << ":";
+  if(da)
+    oss << da->getNumberOfTuples() << " tuples";
+  else
+    oss << "no dataarray";
+  oss << ",";
+}
+
+void MEDFileEquivalenceCellType::write(med_idt fid) const
+{
+  writeLL(fid,MED_CELL,typmai3[_type]);
+}
+
+std::vector<const BigMemoryObject *> MEDFileEquivalenceCell::getDirectChildrenWithNull() const
+{
+  std::size_t sz(_types.size());
+  std::vector<const BigMemoryObject *> ret(sz);
+  for(std::size_t i=0;i<sz;i++)
+    ret[i]=_types[i];
+  return ret;
+}
+
+std::size_t MEDFileEquivalenceCell::getHeapMemorySizeWithoutChildren() const
+{
+  return sizeof(MEDFileEquivalenceCell)+_types.capacity()*sizeof(MEDFileEquivalenceCellType);
+}
+
+MEDFileEquivalenceCell *MEDFileEquivalenceCell::Load(med_idt fid, MEDFileEquivalencePair *owner)
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCell> ret(new MEDFileEquivalenceCell(owner));
+  ret->load(fid);
+  if(ret->size()>0)
+    return ret.retn();
+  else
+    return 0;
+}
+
+void MEDFileEquivalenceCell::write(med_idt fid) const
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::const_iterator it=_types.begin();it!=_types.end();it++)
+    {
+      const MEDFileEquivalenceCellType *ct(*it);
+      if(ct)
+        ct->write(fid);
+    }
+}
+
+MEDFileEquivalenceCell *MEDFileEquivalenceCell::deepCpy(MEDFileEquivalencePair *owner) const
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCell> ret(new MEDFileEquivalenceCell(owner));
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::const_iterator it=_types.begin();it!=_types.end();it++)
+    {
+      const MEDFileEquivalenceCellType *elt(*it);
+      MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> eltCpy;
+      if(elt)
+        eltCpy=elt->deepCpy(owner);
+      ret->_types.push_back(eltCpy);
+    }
+  return ret.retn();
+}
+
+bool MEDFileEquivalenceCell::isEqual(const MEDFileEquivalenceCell *other, std::string& what) const
+{
+  std::size_t sz(_types.size());
+  if(sz!=other->_types.size())
+    {
+      std::ostringstream oss; oss << "Nb of geo types differs : " << sz << " != " << other->_types.size();
+      what=oss.str();
+      return false;
+    }
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const MEDFileEquivalenceCellType *ct1(_types[i]),*ct2(other->_types[i]);
+      if((ct1 && !ct2) || (!ct1 && ct2))
+        {
+          std::ostringstream oss; oss << "At gt #" << i << " this is defined not other (or reversely !)";
+          what=oss.str();
+          return false;
+        }
+      if(ct1 && ct2)
+        {
+          if(!ct1->isEqual(ct2,what))
+            {
+              std::ostringstream oss; oss << "At gt #" << i << " of Eq " << getFather()->getName() << " it differs !";
+              what=oss.str()+what;
+              return false;
+            }
+        }
+    }
+  return true;
+}
+
+void MEDFileEquivalenceCell::getRepr(std::ostream& oss) const
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::const_iterator it=_types.begin();it!=_types.end();it++)
+    {
+      const MEDFileEquivalenceCellType *elt(*it);
+      if(elt)
+        elt->getRepr(oss);
+    }
+}
+
+DataArrayInt *MEDFileEquivalenceCell::getArray(INTERP_KERNEL::NormalizedCellType type)
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::iterator it=_types.begin();it!=_types.end();it++)
+    {
+      MEDFileEquivalenceCellType *elt(*it);
+      if(elt && elt->getType()==type)
+        return elt->getArray();
+    }
+  std::ostringstream oss; oss << "MEDFileEquivalenceCell::getArray : In Equivalence \"" << getFather()->getName() << "\" the geotype " << type << " is not available !";
+  throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
+void MEDFileEquivalenceCell::setArray(int meshDimRelToMax, DataArrayInt *da)
+{
+  if(!da)
+    return ;
+  MEDFileEquivalences::CheckDataArray(da);
+  MEDFileMesh *mm(getMesh());
+  int totalNbOfCells(mm->getNumberOfCellsAtLevel(meshDimRelToMax));
+  //
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(da->deepCpy()); tmp->rearrange(1);
+  int maxv,minv;
+  tmp->getMinMaxValues(minv,maxv);
+  if((minv<0 || minv>=totalNbOfCells) || (maxv<0 || maxv>=totalNbOfCells))
+    {
+      std::ostringstream oss; oss << "MEDFileEquivalenceCell::setArray : Input 2 component DataArray has incorrect values ! all values must be in [0," << totalNbOfCells << ") !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  //
+  std::vector<INTERP_KERNEL::NormalizedCellType> gts(mm->getGeoTypesAtLevel(meshDimRelToMax));
+  int startId(0),endId;
+  std::vector<int> compS(1,0);
+  for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it=gts.begin();it!=gts.end();it++)
+    {
+      endId=startId+mm->getNumberOfCellsWithType(*it);
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da0(da->keepSelectedComponents(compS));
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids(da0->getIdsInRange(startId,endId));
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da1(da->selectByTupleIdSafe(ids->begin(),ids->end()));
+      da1->applyLin(1,-startId);
+      setArrayForType(*it,da1);
+      startId=endId;
+    }
+}
+
+void MEDFileEquivalenceCell::setArrayForType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da)
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::iterator it=_types.begin();it!=_types.end();it++)
+    {
+      MEDFileEquivalenceCellType *elt(*it);
+      if(elt && elt->getType()==type)
+        {
+          elt->setArray(da);
+          return ;
+        }
+    }
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> newElt(new MEDFileEquivalenceCellType(getFather(),type,da));
+  _types.push_back(newElt);
+}
+
+std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileEquivalenceCell::getTypes() const
+{
+  std::vector<INTERP_KERNEL::NormalizedCellType> ret;
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> >::const_iterator it=_types.begin();it!=_types.end();it++)
+    {
+      const MEDFileEquivalenceCellType *elt(*it);
+      if(elt)
+        ret.push_back(elt->getType());
+    }
+  return ret;
+}
+
+void MEDFileEquivalenceCell::load(med_idt fid)
+{
+  std::string meshName(getFather()->getFather()->getMeshName()),name(getName());
+  int dt,it;
+  getFather()->getFather()->getDtIt(dt,it);
+  for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
+    {
+      med_int ncor;
+      MEDFILESAFECALLERRD0(MEDequivalenceCorrespondenceSize,(fid,meshName.c_str(),name.c_str(),dt,it,MED_CELL,typmai[i],&ncor));
+      if(ncor>0)
+        {
+          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da(DataArrayInt::New());
+          da->alloc(ncor*2);
+          MEDFILESAFECALLERRD0(MEDequivalenceCorrespondenceRd,(fid,meshName.c_str(),name.c_str(),dt,it,MED_CELL,typmai[i],da->getPointer()));
+          da->applyLin(1,-1);
+          da->rearrange(2);
+          MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> ct(new MEDFileEquivalenceCellType(getFather(),typmai2[i],da));
+          _types.push_back(ct);
+        }
+    }
+}
+
+std::size_t MEDFileEquivalenceNode::getHeapMemorySizeWithoutChildren() const
+{
+  return sizeof(MEDFileEquivalenceNode);
+}
+
+void MEDFileEquivalenceNode::write(med_idt fid) const
+{
+  writeLL(fid,MED_NODE,MED_NONE);
+}
+
+MEDFileEquivalenceNode *MEDFileEquivalenceNode::deepCpy(MEDFileEquivalencePair *owner) const
+{
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
+  if(getArray())
+    da=getArray()->deepCpy();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceNode> ret(new MEDFileEquivalenceNode(owner,da));
+  return ret.retn();
+}
+
+bool MEDFileEquivalenceNode::isEqual(const MEDFileEquivalenceNode *other, std::string& what) const
+{
+  return MEDFileEquivalenceData::isEqual(other,what);
+}
+
+void MEDFileEquivalenceNode::getRepr(std::ostream& oss) const
+{
+  const DataArrayInt *da(getArray());
+  if(!da)
+    oss << " No dataarray defined !" << std::endl;
+  else
+    oss << da->getNumberOfTuples() << " tuples in node equivalence." << std::endl;
+}
diff --git a/src/MEDLoader/MEDFileEquivalence.hxx b/src/MEDLoader/MEDFileEquivalence.hxx
new file mode 100644 (file)
index 0000000..bcf1490
--- /dev/null
@@ -0,0 +1,202 @@
+// Copyright (C) 2007-2015  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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDFILEEQUIVALENCE_HXX__
+#define __MEDFILEEQUIVALENCE_HXX__
+
+#include "MEDLoaderDefines.hxx"
+#include "MEDCouplingRefCountObject.hxx"
+#include "MEDCouplingMemArray.hxx"
+#include "MEDFileUtilities.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+
+#include <vector>
+
+namespace ParaMEDMEM
+{
+  class MEDFileEquivalenceCell;
+  class MEDFileEquivalenceNode;
+  class MEDFileEquivalences;
+  class MEDFileMesh;
+
+  class MEDFileEquivalencePair : public RefCountObject
+  {
+  public:
+    static MEDFileEquivalencePair *Load(MEDFileEquivalences *father, med_idt fid, const std::string& name, const std::string &desc);
+    void write(med_idt fid) const;
+    const MEDFileEquivalences *getFather() const { return _father; }
+    MEDFileEquivalences *getFather() { return _father; }
+    const MEDFileMesh *getMesh() const;
+    MEDFileMesh *getMesh();
+    MEDFileEquivalencePair *deepCpy(MEDFileEquivalences *father) const;
+    bool isEqual(const MEDFileEquivalencePair *other, std::string& what) const;
+    void getRepr(std::ostream& oss) const;
+    static MEDFileEquivalencePair *New(MEDFileEquivalences *father, const std::string& name);
+    MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+    MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+  public:
+    MEDLOADER_EXPORT std::string getName() const { return _name; }
+    MEDLOADER_EXPORT void setName(const std::string& name) { _name=name; }
+    MEDLOADER_EXPORT std::string getDescription() const { return _description; }
+    MEDLOADER_EXPORT void setDescription(const std::string& descr) { _description=descr; }
+    MEDLOADER_EXPORT MEDFileEquivalenceCell *initCell();
+    MEDLOADER_EXPORT MEDFileEquivalenceNode *initNode();
+    MEDLOADER_EXPORT MEDFileEquivalenceCell *getCell() { return _cell; }
+    MEDLOADER_EXPORT MEDFileEquivalenceNode *getNode() { return _node; }
+    MEDLOADER_EXPORT void setArray(int meshDimRelToMaxExt, DataArrayInt *da);
+  private:
+    MEDFileEquivalencePair(MEDFileEquivalences *father, const std::string& name, const std::string& desc):_father(father),_name(name),_description(desc) { }
+    void load(med_idt fid);
+  private:
+    MEDFileEquivalences *_father;
+    std::string _name;
+    std::string _description;
+    MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCell> _cell;
+    MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceNode> _node;
+  };
+
+  class MEDFileEquivalences : public RefCountObject
+  {
+  public:
+    MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+    MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+    MEDLOADER_EXPORT const MEDFileMesh *getMesh() const { return _owner; }
+    MEDLOADER_EXPORT MEDFileMesh *getMesh() { return _owner; }
+    void getDtIt(int &dt, int &it) const;
+    std::string getMeshName() const;
+    void pushEquivalence(MEDFileEquivalencePair *elt);
+    static MEDFileEquivalences *New(MEDFileMesh *owner) { return new MEDFileEquivalences(owner); }
+    MEDFileEquivalences *deepCpy(MEDFileMesh *owner) const;
+    bool isEqual(const MEDFileEquivalences *other, std::string& what) const;
+    void getRepr(std::ostream& oss) const;
+  public:
+    MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalence(int i);
+    MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalenceWithName(const std::string& name);
+    MEDLOADER_EXPORT int size() const;
+    MEDLOADER_EXPORT std::vector<std::string> getEquivalenceNames() const;
+    MEDLOADER_EXPORT MEDFileEquivalencePair *appendEmptyEquivalenceWithName(const std::string& name);
+    MEDLOADER_EXPORT void killEquivalenceWithName(const std::string& name);
+    MEDLOADER_EXPORT void killEquivalenceAt(int i);
+    MEDLOADER_EXPORT void clear();
+  public:
+    void write(med_idt fid) const;
+    static int PresenceOfEquivalences(med_idt fid, const std::string& meshName);
+    static MEDFileEquivalences *Load(med_idt fid, int nbOfEq, MEDFileMesh *owner);
+    static void CheckDataArray(const DataArrayInt *data);
+  private:
+    MEDFileEquivalences(MEDFileMesh *owner):_owner(owner) { }
+    void deepCpyFrom(const MEDFileEquivalences& other);
+  private:
+    MEDFileMesh *_owner;
+    std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> > _equ;
+  };
+
+  class MEDFileEquivalenceBase : public RefCountObject
+  {
+  protected:
+    MEDFileEquivalenceBase(MEDFileEquivalencePair *father);
+    const MEDFileEquivalencePair *getFather() const { return _father; }
+    MEDFileEquivalencePair *getFather() { return _father; }
+    const MEDFileMesh *getMesh() const { return getFather()->getMesh(); }
+    MEDFileMesh *getMesh() { return getFather()->getMesh(); }
+  protected:
+    ~MEDFileEquivalenceBase() { }
+  private:
+    MEDFileEquivalencePair *_father;
+  };
+
+  class MEDFileEquivalenceData : public MEDFileEquivalenceBase
+  {
+  public:
+    MEDFileEquivalenceData(MEDFileEquivalencePair *owner, DataArrayInt *data);
+    MEDLOADER_EXPORT void setArray(DataArrayInt *data);
+    MEDLOADER_EXPORT const DataArrayInt *getArray() const { return _data; }
+    MEDLOADER_EXPORT DataArrayInt *getArray() { return _data; }
+    MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+    bool isEqual(const MEDFileEquivalenceData *other, std::string& what) const;
+  protected:
+    void writeLL(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const;
+  protected:
+    ~MEDFileEquivalenceData() { }
+  protected:
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _data;
+  };
+
+  class MEDFileEquivalenceCellType : public MEDFileEquivalenceData
+  {
+  public:
+    MEDFileEquivalenceCellType(MEDFileEquivalencePair *owner, INTERP_KERNEL::NormalizedCellType type, DataArrayInt *data):MEDFileEquivalenceData(owner,data),_type(type) { }
+    MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+    INTERP_KERNEL::NormalizedCellType getType() const { return _type; }
+    MEDFileEquivalenceCellType *deepCpy(MEDFileEquivalencePair *owner) const;
+    bool isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const;
+    void getRepr(std::ostream& oss) const;
+  public:
+    void write(med_idt fid) const;
+  private:
+    ~MEDFileEquivalenceCellType() { }
+  private:
+    INTERP_KERNEL::NormalizedCellType _type;
+  };
+
+  class MEDFileEquivalenceCell : public MEDFileEquivalenceBase
+  {
+  public:
+    MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+    MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+    static MEDFileEquivalenceCell *Load(med_idt fid, MEDFileEquivalencePair *owner);
+    void write(med_idt fid) const;
+    MEDFileEquivalenceCell *deepCpy(MEDFileEquivalencePair *owner) const;
+    bool isEqual(const MEDFileEquivalenceCell *other, std::string& what) const;
+    void getRepr(std::ostream& oss) const;
+  public:
+    MEDLOADER_EXPORT void clear() { _types.clear(); }
+    MEDLOADER_EXPORT std::size_t size() const { return _types.size(); }
+    MEDLOADER_EXPORT DataArrayInt *getArray(INTERP_KERNEL::NormalizedCellType type);
+    MEDLOADER_EXPORT void setArray(int meshDimRelToMax, DataArrayInt *da);
+    MEDLOADER_EXPORT void setArrayForType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da);
+    MEDLOADER_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getTypes() const;
+  public:
+    MEDFileEquivalenceCell(MEDFileEquivalencePair *owner):MEDFileEquivalenceBase(owner) { }
+  private:
+    ~MEDFileEquivalenceCell() { }
+  private:
+    void load(med_idt fid);
+    std::string getName() const { return getFather()->getName(); }
+  private:
+    std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalenceCellType> > _types;
+  };
+
+  class MEDFileEquivalenceNode : public MEDFileEquivalenceData
+  {
+  public:
+    MEDFileEquivalenceNode(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceData(owner,data) { }
+    MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
+    void write(med_idt fid) const;
+    MEDFileEquivalenceNode *deepCpy(MEDFileEquivalencePair *owner) const;
+    bool isEqual(const MEDFileEquivalenceNode *other, std::string& what) const;
+    void getRepr(std::ostream& oss) const;
+  private:
+    ~MEDFileEquivalenceNode() { }
+  };
+}
+
+#endif
+