--- /dev/null
+// 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 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();
+}
+
+const MEDFileMesh *MEDFileEquivalencePair::getMesh() const
+{
+ return getFather()->getMesh();
+}
+
+MEDFileMesh *MEDFileEquivalencePair::getMesh()
+{
+ return getFather()->getMesh();
+}
+
+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);
+ }
+}
+
+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;
+}
+
+void MEDFileEquivalences::appendEmptyEquivalenceWithName(const std::string& name)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileEquivalencePair> elt(MEDFileEquivalencePair::New(this,name));
+ _equ.push_back(elt);
+
+}
+
+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);
+}
+
+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(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());
+ }
+}
+
+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;
+}
+
+std::size_t MEDFileEquivalenceCellType::getHeapMemorySizeWithoutChildren() const
+{
+ return sizeof(MEDFileEquivalenceCellType);
+}
+
+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;
+}
+
+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)
+{
+ MEDFileEquivalences::CheckDataArray(da);
+ //TODO
+}
+
+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);
+}
--- /dev/null
+// 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);
+ const MEDFileEquivalences *getFather() const { return _father; }
+ MEDFileEquivalences *getFather() { return _father; }
+ const MEDFileMesh *getMesh() const;
+ MEDFileMesh *getMesh();
+ 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 *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); }
+ 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 void appendEmptyEquivalenceWithName(const std::string& name);
+ MEDLOADER_EXPORT void killEquivalenceWithName(const std::string& name);
+ MEDLOADER_EXPORT void killEquivalenceAt(int i);
+ public:
+ static int PresenceOfEquivalences(med_idt fid, const std::string& meshName);
+ static MEDFileEquivalences *Load(med_idt fid, int nbOfEq, MEDFileMesh *owner);
+ static void CheckDataArray(DataArrayInt *data);
+ private:
+ MEDFileEquivalences(MEDFileMesh *owner):_owner(owner) { }
+ 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(); }
+ private:
+ MEDFileEquivalencePair *_father;
+ };
+
+ class MEDFileEquivalenceData : public MEDFileEquivalenceBase
+ {
+ public:
+ MEDFileEquivalenceData(MEDFileEquivalencePair *owner, DataArrayInt *data);
+ void setArray(DataArrayInt *data);
+ const DataArrayInt *getArray() const { return _data; }
+ DataArrayInt *getArray() { return _data; }
+ MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
+ 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; }
+ 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);
+ public:
+ 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);
+ public:
+ MEDFileEquivalenceCell(MEDFileEquivalencePair *owner):MEDFileEquivalenceBase(owner) { }
+ 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;
+ };
+}
+
+#endif
+