From b47fe4cd443d45e5b18f549807db4e6e937b8582 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 30 Nov 2015 17:44:50 +0100 Subject: [PATCH] step1 --- src/MEDLoader/MEDFileEquivalence.cxx | 367 +++++++++++++++++++++++++++ src/MEDLoader/MEDFileEquivalence.hxx | 161 ++++++++++++ src/MEDLoader/MEDFileMesh.hxx | 1 + 3 files changed, 529 insertions(+) create mode 100644 src/MEDLoader/MEDFileEquivalence.cxx create mode 100644 src/MEDLoader/MEDFileEquivalence.hxx diff --git a/src/MEDLoader/MEDFileEquivalence.cxx b/src/MEDLoader/MEDFileEquivalence.cxx new file mode 100644 index 000000000..55a917b84 --- /dev/null +++ b/src/MEDLoader/MEDFileEquivalence.cxx @@ -0,0 +1,367 @@ +// 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 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 MEDFileEquivalencePair::getDirectChildrenWithNull() const +{ + std::vector 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 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 node(new MEDFileEquivalenceNode(this,da)); + _node=node; + } + _cell=MEDFileEquivalenceCell::Load(fid,this); +} + +std::vector MEDFileEquivalences::getDirectChildrenWithNull() const +{ + std::size_t sz(_equ.size()); + std::vector ret(sz); + for(std::size_t i=0;igetIteration(); it=_owner->getOrder(); +} + +std::string MEDFileEquivalences::getMeshName() const +{ + return _owner->getName(); +} + +void MEDFileEquivalences::pushEquivalence(MEDFileEquivalencePair *elt) +{ + MEDCouplingAutoRefCountObjectPtr 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 >::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 eqs(getEquivalenceNames()); + std::copy(eqs.begin(),eqs.end(),std::ostream_iterator(oss,", ")); + oss << "] !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileEquivalences::size() const +{ + return _equ.size(); +} + +std::vector MEDFileEquivalences::getEquivalenceNames() const +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::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 elt(MEDFileEquivalencePair::New(this,name)); + _equ.push_back(elt); + +} + +void MEDFileEquivalences::killEquivalenceWithName(const std::string& name) +{ + std::vector< MEDCouplingAutoRefCountObjectPtr >::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 >::iterator it(_equ.begin()); + for(int j=0;j 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 equ(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + INTERP_KERNEL::AutoPtr 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 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 MEDFileEquivalenceData::getDirectChildrenWithNull() const +{ + std::vector ret(1); + ret[0]=_data; + return ret; +} + +std::size_t MEDFileEquivalenceCellType::getHeapMemorySizeWithoutChildren() const +{ + return sizeof(MEDFileEquivalenceCellType); +} + +std::vector MEDFileEquivalenceCell::getDirectChildrenWithNull() const +{ + std::size_t sz(_types.size()); + std::vector ret(sz); + for(std::size_t i=0;i 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 >::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;i0) + { + MEDCouplingAutoRefCountObjectPtr 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 ct(new MEDFileEquivalenceCellType(getFather(),typmai2[i],da)); + _types.push_back(ct); + } + } +} + +std::size_t MEDFileEquivalenceNode::getHeapMemorySizeWithoutChildren() const +{ + return sizeof(MEDFileEquivalenceNode); +} diff --git a/src/MEDLoader/MEDFileEquivalence.hxx b/src/MEDLoader/MEDFileEquivalence.hxx new file mode 100644 index 000000000..9e8694247 --- /dev/null +++ b/src/MEDLoader/MEDFileEquivalence.hxx @@ -0,0 +1,161 @@ +// 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 + +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 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 _cell; + MEDCouplingAutoRefCountObjectPtr _node; + }; + + class MEDFileEquivalences : public RefCountObject + { + public: + MEDLOADER_EXPORT std::vector 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 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 > _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 getDirectChildrenWithNull() const; + protected: + MEDCouplingAutoRefCountObjectPtr _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 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 > _types; + }; + + class MEDFileEquivalenceNode : public MEDFileEquivalenceData + { + public: + MEDFileEquivalenceNode(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceData(owner,data) { } + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + }; +} + +#endif + diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index b87be4b64..4cb74554f 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -199,6 +199,7 @@ namespace ParaMEDMEM void loadEquivalences(med_idt fid); MEDFileEquivalences *getEquivalences() { return _equiv; } const MEDFileEquivalences *getEquivalences() const { return _equiv; } + void initializeEquivalences() { _equiv=MEDFileEquivalences::New(this); } protected: int _order; int _iteration; -- 2.39.2