1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDFileMeshSupport.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileMeshLL.hxx"
24 #include "MEDFileSafeCaller.txx"
26 #include "InterpKernelAutoPtr.hxx"
28 using namespace MEDCoupling;
30 MEDFileMeshSupports *MEDFileMeshSupports::New(const std::string& fileName)
32 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
36 MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid)
38 return new MEDFileMeshSupports(fid);
41 MEDFileMeshSupports *MEDFileMeshSupports::New()
43 return new MEDFileMeshSupports;
46 MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid)
48 med_int nbSM(MEDnSupportMesh(fid));
49 _supports.resize(nbSM);
50 for(int i=0;i<nbSM;i++)
52 INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
53 INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
55 med_int nAxis(MEDsupportMeshnAxis(fid,i+1));
56 INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
57 med_int spaceDim(0),meshDim(0);
58 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,msn,&spaceDim,&meshDim,description,&axType,axisName,axisUnit));
59 std::string name(MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE));
60 _supports[i]=MEDFileUMesh::New(fid,name);
64 MEDFileMeshSupports::MEDFileMeshSupports()
68 MEDFileMeshSupports::~MEDFileMeshSupports()
72 std::vector<const BigMemoryObject *> MEDFileMeshSupports::getDirectChildrenWithNull() const
74 std::size_t sz(_supports.size());
75 std::vector<const BigMemoryObject *> ret(sz);
76 for(std::size_t i=0;i<sz;i++)
81 std::size_t MEDFileMeshSupports::getHeapMemorySizeWithoutChildren() const
83 return _supports.capacity()*sizeof(MCAuto<MEDFileUMesh>);
86 void MEDFileMeshSupports::writeLL(med_idt fid) const
88 for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
93 std::vector<std::string> MEDFileMeshSupports::getSupMeshNames() const
95 std::vector<std::string> ret;
96 for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
98 ret.push_back((*it)->getName());
102 const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& name) const
104 std::vector<std::string> mns;
105 for(std::vector< MCAuto<MEDFileUMesh> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
107 if((*it).isNotNull())
109 std::string na((*it)->getName());
116 std::ostringstream oss;
117 oss << "MEDFileMeshSupports::getSupMeshWithName : no such name \"" << name << "\". Possibilities are :";
118 std::copy(mns.begin(),mns.end(),std::ostream_iterator<std::string>(oss,","));
120 throw INTERP_KERNEL::Exception(oss.str());
123 mcIdType MEDFileMeshSupports::getNumberOfNodesInConnOf(TypeOfField entity, const std::string& name) const
125 const MEDFileUMesh *sup(getSupMeshWithName(name));
129 return sup->getNumberOfNodes();
132 std::vector<INTERP_KERNEL::NormalizedCellType> gt(sup->getAllGeoTypes());
134 throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : on cells only one geometric type allowed !");
135 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(gt[0]));
136 return sup->getNumberOfCellsAtLevel(0)*cm.getNumberOfNodes();
139 throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : not recognized entity type !");