1 // Copyright (C) 2007-2017 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"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileMeshLL.hxx"
25 #include "MEDFileSafeCaller.txx"
27 #include "InterpKernelAutoPtr.hxx"
29 using namespace MEDCoupling;
31 MEDFileMeshSupport *MEDFileMeshSupport::New()
33 return new MEDFileMeshSupport;
36 MEDFileMeshSupport *MEDFileMeshSupport::New(const std::string& fileName, int smid)
38 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
42 MEDFileMeshSupport *MEDFileMeshSupport::New(med_idt fid, int smid)
44 return new MEDFileMeshSupport(fid,smid);
47 std::vector<const BigMemoryObject *> MEDFileMeshSupport::getDirectChildrenWithNull() const
49 return std::vector<const BigMemoryObject *>();
52 std::size_t MEDFileMeshSupport::getHeapMemorySizeWithoutChildren() const
57 int MEDFileMeshSupport::getSpaceDim() const
62 void MEDFileMeshSupport::setSpaceDim(int dim)
67 int MEDFileMeshSupport::getMeshDim() const
72 void MEDFileMeshSupport::setMeshDim(int dim)
77 void MEDFileMeshSupport::writeLL(med_idt fid) const
81 MEDFileMeshSupport::MEDFileMeshSupport(med_idt fid, int smid)
83 INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
84 INTERP_KERNEL::AutoPtr<char> description(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
86 int nAxis(MEDsupportMeshnAxis(fid,smid+1));
87 INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
88 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid+1,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit));
89 _name=MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE);
90 _description=MEDLoaderBase::buildStringFromFortran(description,MED_COMMENT_SIZE);
91 _axis_type=MEDFileMeshL2::TraduceAxisType(axType);
92 int nCoords(0),nmodels(0);
94 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
95 nCoords=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_COORDINATE,MED_NODAL,&chgt,&trsf);
96 nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
98 _coords=DataArrayDouble::New(); _coords->alloc(nCoords,nAxis);
99 for(int i=0;i<nAxis;i++)
101 std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
102 MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
103 _coords->setInfoOnComponent(i,info);
105 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer()));
107 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
108 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)
110 _fam_coords=DataArrayInt::New();
111 _fam_coords->alloc(nCoords,1);
112 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
116 if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&chgt,&trsf)>0)
118 _num_coords=DataArrayInt::New();
119 _num_coords->alloc(nCoords,1);
120 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
124 if(MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&chgt,&trsf)>0)
126 _name_coords=DataArrayAsciiChar::New();
127 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
128 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
129 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
134 //med_bool withnodename;
135 //MEDmeshNodeRd(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,_coords->getPointer(),);
136 std::cerr << nCoords << " ** " << nmodels << std::endl;
139 MEDFileMeshSupport::~MEDFileMeshSupport()
143 MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1),_axis_type(AX_CART)
147 MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid)
149 return new MEDFileMeshSupports(fid);
152 MEDFileMeshSupports *MEDFileMeshSupports::New()
154 return new MEDFileMeshSupports;
157 MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid)
159 int nbSM(MEDnSupportMesh(fid));
160 _supports.resize(nbSM);
161 for(int i=0;i<nbSM;i++)
162 _supports[i]=MEDFileMeshSupport::New(fid,i);
165 MEDFileMeshSupports::MEDFileMeshSupports()
169 MEDFileMeshSupports::~MEDFileMeshSupports()
173 std::vector<const BigMemoryObject *> MEDFileMeshSupports::getDirectChildrenWithNull() const
175 std::size_t sz(_supports.size());
176 std::vector<const BigMemoryObject *> ret(sz);
177 for(std::size_t i=0;i<sz;i++)
182 std::size_t MEDFileMeshSupports::getHeapMemorySizeWithoutChildren() const
184 return _supports.capacity()*sizeof(MCAuto<MEDFileMeshSupport>);
187 void MEDFileMeshSupports::writeLL(med_idt fid) const
189 for(std::vector< MCAuto<MEDFileMeshSupport> >::const_iterator it=_supports.begin();it!=_supports.end();it++)
190 if((*it).isNotNull())