%feature("unref") MEDCouplingField "$this->decrRef();"
%feature("unref") MEDCouplingFieldDouble "$this->decrRef();"
%feature("unref") MEDCouplingMultiFields "$this->decrRef();"
+%feature("unref") MEDCouplingFieldTemplate "$this->decrRef();"
+%feature("unref") MEDCouplingMultiFields "$this->decrRef();"
%rename(assign) *::operator=;
%ignore ParaMEDMEM::RefCountObject::decrRef;
--- /dev/null
+// Copyright (C) 2007-2011 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.
+//
+// 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
+//
+
+#include "MEDFileData.hxx"
+
+using namespace ParaMEDMEM;
+
+MEDFileData *MEDFileData::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileData(fileName);
+}
+
+MEDFileData *MEDFileData::New()
+{
+ return new MEDFileData;
+}
+
+MEDFileFields *MEDFileData::getFields() const
+{
+ return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
+}
+
+MEDFileMeshes *MEDFileData::getMeshes() const
+{
+ return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
+}
+
+void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception)
+{
+ if(!fields)
+ throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !");
+ fields->incrRef();
+ _fields=fields;
+}
+
+void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception)
+{
+ if(!meshes)
+ throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !");
+ meshes->incrRef();
+ _meshes=meshes;
+}
+
+int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
+{
+ const MEDFileFields *f=_fields;
+ if(!f)
+ throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
+ return f->getNumberOfFields();
+}
+
+int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
+{
+ const MEDFileMeshes *m=_meshes;
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
+ return m->getNumberOfMeshes();
+}
+
+MEDFileData::MEDFileData()
+{
+}
+
+MEDFileData::MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception)
+try
+ {
+ _fields=MEDFileFields::New(fileName);
+ _meshes=MEDFileMeshes::New(fileName);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ const MEDFileMeshes *ms=_meshes;
+ if(ms)
+ ms->write(fileName,mode);
+ const MEDFileFields *fs=_fields;
+ if(fs)
+ fs->write(fileName,mode);
+}
--- /dev/null
+// Copyright (C) 2007-2011 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.
+//
+// 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
+//
+
+#ifndef __MEDFILEDATA_HXX__
+#define __MEDFILEDATA_HXX__
+
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MEDFileField.hxx"
+#include "MEDFileMesh.hxx"
+
+namespace ParaMEDMEM
+{
+ /*!
+ * User class.
+ */
+ class MEDFileData : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileData *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileData *New();
+ MEDFileFields *getFields() const;
+ MEDFileMeshes *getMeshes() const;
+ void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception);
+ void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception);
+ int getNumberOfFields() const throw(INTERP_KERNEL::Exception);
+ int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
+ //
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileData();
+ MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDCouplingAutoRefCountObjectPtr<MEDFileFields> _fields;
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> _meshes;
+ };
+}
+
+#endif
void MEDFileFieldPerMeshPerType::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
{
for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
- (*it)->writeLL(fid);
+ {
+ (*it)->copyOptionsFrom(*this);
+ (*it)->writeLL(fid);
+ }
}
med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
{
int nbOfTypes=_field_pm_pt.size();
for(int i=0;i<nbOfTypes;i++)
- _field_pm_pt[i]->writeLL(fid);
+ {
+ _field_pm_pt[i]->copyOptionsFrom(*this);
+ _field_pm_pt[i]->writeLL(fid);
+ }
}
void MEDFileFieldPerMesh::getDimension(int& dim) const
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : empty field !");
if(_field_per_mesh.size()>1)
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
+ _field_per_mesh[0]->copyOptionsFrom(*this);
_field_per_mesh[0]->writeLL(fid);
}
+/*!
+ * SBT means Sort By Type.
+ * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check.
+ *
+ */
+void MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception)
+{
+ const MEDCouplingMesh *mesh=field->getMesh();
+ //
+ TypeOfField type=field->getTypeOfField();
+ if(type!=ON_NODES)
+ {
+ std::vector<int> code=MEDFileField1TSWithoutDAS::CheckSBTMesh(mesh);
+ copyTinyInfoFrom(field);
+ //
+ int pos=addNewEntryIfNecessary(mesh);
+ _field_per_mesh[pos]->assignFieldNoProfile(code,field,glob);
+ }
+ else
+ {
+ copyTinyInfoFrom(field);
+ int pos=addNewEntryIfNecessary(mesh);
+ _field_per_mesh[pos]->assignNodeFieldNoProfile(field,glob);
+ }
+}
+
MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception)
{
MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
{
_file_name="";
- const MEDCouplingMesh *mesh=field->getMesh();
- //
- TypeOfField type=field->getTypeOfField();
- if(type!=ON_NODES)
- {
- std::vector<int> code=MEDFileField1TSWithoutDAS::CheckSBTMesh(mesh);
- copyTinyInfoFrom(field);
- //
- int pos=addNewEntryIfNecessary(mesh);
- _field_per_mesh[pos]->assignFieldNoProfile(code,field,*this);
- }
- else
- {
- copyTinyInfoFrom(field);
- int pos=addNewEntryIfNecessary(mesh);
- _field_per_mesh[pos]->assignNodeFieldNoProfile(field,*this);
- }
+ MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(field,*this);
}
MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep);
}
+MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS()
+{
+}
+
MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName)
{
}
MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
-try:_name(fieldName)
+try:_name(fieldName),_infos(infos)
{
finishLoading(fid,nbOfStep);
}
}
}
+void MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
+{
+ _name=field->getName();
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom : unsupported fields with no name in MED file !");
+ const DataArrayDouble *arr=field->getArray();
+ if(!arr)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom : no array set !");
+ _infos=arr->getInfoOnComponent();
+}
+
+void MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception)
+{
+ static const char MSG[]="MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo : invalid ";
+ if(_name!=field->getName())
+ {
+ std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
+ oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ const DataArrayDouble *arr=field->getArray();
+ if(!arr)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo : no array set !");
+ if(_infos!=arr->getInfoOnComponent())
+ {
+ std::ostringstream oss; oss << MSG << "components ! should be \"";
+ std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
+ oss << " But compo in input fields are : ";
+ std::vector<std::string> tmp=arr->getInfoOnComponent();
+ std::copy(tmp.begin(),tmp.end(),std::ostream_iterator<std::string>(oss,", "));
+ oss << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
void MEDFileFieldMultiTSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
{
if(_time_steps.empty())
return ret;
}
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
+{
+ return new MEDFileFieldMultiTS;
+}
+
MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
return new MEDFileFieldMultiTS(fileName,fieldName);
return myF1TS.getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
}
+void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
+{
+ if(_time_steps.empty())
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> obj=new MEDFileField1TSWithoutDAS;
+ obj->setFieldNoProfileSBT(field,*this);
+ copyTinyInfoFrom(field);
+ _time_steps.push_back(obj);
+ }
+ else
+ {
+ checkCoherencyOfTinyInfo(field);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> obj=new MEDFileField1TSWithoutDAS;
+ obj->setFieldNoProfileSBT(field,*this);
+ _time_steps.push_back(obj);
+ }
+}
+
+MEDFileFieldMultiTS::MEDFileFieldMultiTS()
+{
+}
+
MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobs(fileName)
{
return getLocsReallyUsed2();
}
+MEDFileFields *MEDFileFields::New()
+{
+ return new MEDFileFields;
+}
+
MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
{
return new MEDFileFields(fileName);
return _fields.size();
}
+MEDFileFields::MEDFileFields()
+{
+}
+
MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
try:MEDFieldFieldGlobs(fileName)
{
MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
std::vector<std::string> infos(ncomp);
for(int j=0;j<ncomp;j++)
- infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
- _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i,infos,nbOfStep);
+ infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
+ _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i+1,infos,nbOfStep);
}
int nProfil=MEDnProfile(fid);
_pfls.resize(nProfil);
throw e;
}
+void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ int i=0;
+ med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutDAS> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
+ {
+ const MEDFileFieldMultiTSWithoutDAS *elt=*it;
+ if(!elt)
+ {
+ std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ elt->copyOptionsFrom(*this);
+ elt->writeLL(fid);
+ }
+}
+
std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
{
std::vector<std::string> ret;
return ret;
}
+void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
+{
+ _fields.resize(newSize);
+}
+
+void MEDFileFields::pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
+{
+ if(!field)
+ throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
+ field->incrRef();
+ _fields.push_back(field);
+}
+
+void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
+{
+ if(!field)
+ throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
+ if(i>=_fields.size())
+ _fields.resize(i+1);
+ field->incrRef();
+ _fields[i]=field;
+}
+
+void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
+{
+ if(i<0 || i>=_fields.size())
+ {
+ std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ _fields.erase(_fields.begin()+i);
+}
std::vector<std::string> getLocsReallyUsed2() const;
static void CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
static std::vector<int> CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception);
+ //
+ void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception);
public:
MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobs *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
int addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception);
int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception);
MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos);
+ public:
MEDFileField1TSWithoutDAS();
protected:
std::string _name;
static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception);
int getNumberOfTS() const;
std::vector< std::pair<int,int> > getIterations() const;
+ void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
public:
std::vector<std::string> getPflsReallyUsed2() const;
std::vector<std::string> getLocsReallyUsed2() const;
const std::vector<std::string>& getInfo() const throw(INTERP_KERNEL::Exception);
std::string getMeshName() const throw(INTERP_KERNEL::Exception);
std::string getDtUnit() const throw(INTERP_KERNEL::Exception);
+ MEDFileFieldMultiTSWithoutDAS();
MEDFileFieldMultiTSWithoutDAS(const char *fieldName);
MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception);
void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception);
- void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
+ void copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception);
+ void checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception);
protected:
std::string _name;
std::vector<std::string> _infos;
class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs
{
public:
+ static MEDFileFieldMultiTS *New();
static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ //
+ void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception);
private:
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
private:
+ MEDFileFieldMultiTS();
MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
};
class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs, public MEDFileWritable
{
public:
+ static MEDFileFields *New();
static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
int getNumberOfFields() const;
+ //
+ void resize(int newSize) throw(INTERP_KERNEL::Exception);
+ void pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception);
+ void setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception);
+ void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception);
private:
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
private:
+ MEDFileFields();
MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception);
private:
std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutDAS> > _fields;
throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
}
}
+
+
+MEDFileMeshMultiTS *MEDFileMeshMultiTS::New()
+{
+ return new MEDFileMeshMultiTS;
+}
+
+MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileMeshMultiTS(fileName);
+}
+
+MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileMeshMultiTS(fileName,mName);
+}
+
+const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception)
+{
+ if(_mesh_one_ts.empty())
+ throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !");
+ return _mesh_one_ts[0]->getName();
+}
+
+MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception)
+{
+ if(_mesh_one_ts.empty())
+ throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !");
+ return const_cast<MEDFileMesh *>(static_cast<const MEDFileMesh *>(_mesh_one_ts[0]));
+}
+
+void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception)
+{
+ if(!mesh1TimeStep)
+ throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !");
+ _mesh_one_ts.resize(1);
+ mesh1TimeStep->incrRef();
+ //MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> toto=mesh1TimeStep;
+ _mesh_one_ts[0]=mesh1TimeStep;
+}
+
+void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
+ {
+ (*it)->copyOptionsFrom(*this);
+ (*it)->write(fileName,mode);
+ }
+}
+
+void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+{//for the moment to be improved
+ _mesh_one_ts.resize(1);
+ _mesh_one_ts[0]=MEDFileMesh::New(fileName,mName,-1,-1);
+}
+
+MEDFileMeshMultiTS::MEDFileMeshMultiTS()
+{
+}
+
+MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
+try
+ {
+ std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
+ if(ms.empty())
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int dt,it;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
+ loadFromFile(fileName,ms.front().c_str());
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+try
+ {
+ loadFromFile(fileName,mName);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+MEDFileMeshes *MEDFileMeshes::New()
+{
+ return new MEDFileMeshes;
+}
+
+MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ return new MEDFileMeshes(fileName);
+}
+
+void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ checkCoherency();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
+ {
+ (*it)->copyOptionsFrom(*this);
+ (*it)->write(fileName,mode);
+ }
+}
+
+int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
+{
+ return _meshes.size();
+}
+
+MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
+{
+ if(i<0 || i>=(int)_meshes.size())
+ {
+ std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return _meshes[i]->getOneTimeStep();
+}
+
+void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception)
+{
+ _meshes.resize(newSize);
+}
+
+void MEDFileMeshes::pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
+{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !");
+ MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
+ elt->setOneTimeStep(mesh);
+ _meshes.push_back(elt);
+}
+
+void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
+{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !");
+ if(i>=_meshes.size())
+ _meshes.resize(i+1);
+ MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
+ elt->setOneTimeStep(mesh);
+ _meshes[i]=elt;
+}
+
+void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception)
+{
+ if(i<0 || i>=_meshes.size())
+ {
+ std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ _meshes.erase(_meshes.begin()+i);
+}
+
+void MEDFileMeshes::loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
+ int i=0;
+ _meshes.resize(ms.size());
+ for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
+ _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it).c_str());
+}
+
+MEDFileMeshes::MEDFileMeshes()
+{
+}
+
+MEDFileMeshes::MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception)
+try
+ {
+ loadFromFile(fileName);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ }
+
+void MEDFileMeshes::checkCoherency() const throw(INTERP_KERNEL::Exception)
+{
+ static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank ";
+ int i=0;
+ std::set<std::string> s;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
+ {
+ const MEDFileMeshMultiTS *elt=(*it);
+ if(!elt)
+ {
+ std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ std::size_t sz=s.size();
+ s.insert(std::string((*it)->getName()));
+ if(s.size()==sz)
+ {
+ std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+}
mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
};
-
class MEDFileCMesh : public MEDFileMesh
{
friend class MEDFileMesh;
mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_nodes;
mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_cells;
};
+
+ class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileMeshMultiTS *New();
+ static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ const char *getName() const throw(INTERP_KERNEL::Exception);
+ MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception);
+ private:
+ void loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ MEDFileMeshMultiTS();
+ MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception);
+ MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ private:
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> > _mesh_one_ts;
+ };
+
+ class MEDFileMeshes : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileMeshes *New();
+ static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
+ MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception);
+ //
+ void resize(int newSize) throw(INTERP_KERNEL::Exception);
+ void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
+ void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
+ void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception);
+ private:
+ void checkCoherency() const throw(INTERP_KERNEL::Exception);
+ void loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception);
+ MEDFileMeshes();
+ MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception);
+ private:
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> > _meshes;
+ };
}
#endif
#include "MEDLoader.hxx"
#include "MEDFileMesh.hxx"
#include "MEDFileField.hxx"
+#include "MEDFileData.hxx"
#include "MEDLoaderTypemaps.i"
using namespace ParaMEDMEM;
%newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh;
%newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh;
%newobject ParaMEDMEM::MEDFileCMesh::New;
+%newobject ParaMEDMEM::MEDFileMeshMultiTS::New;
+%newobject ParaMEDMEM::MEDFileMeshMultiTS::getOneTimeStep;
+%newobject ParaMEDMEM::MEDFileMeshes::New;
+%newobject ParaMEDMEM::MEDFileMeshes::getMeshAtPos;
%newobject ParaMEDMEM::MEDFileFields::New;
%newobject ParaMEDMEM::MEDFileFieldMultiTS::New;
%newobject ParaMEDMEM::MEDFileField1TS::getFieldOnMeshAtLevel;
%newobject ParaMEDMEM::MEDFileField1TS::getFieldAtLevelOld;
+%newobject ParaMEDMEM::MEDFileData::New;
+
+%feature("unref") MEDFileMesh "$this->decrRef();"
+%feature("unref") MEDFileUMesh "$this->decrRef();"
+%feature("unref") MEDFileCMesh "$this->decrRef();"
+%feature("unref") MEDFileMeshMultiTS "$this->decrRef();"
+%feature("unref") MEDFileMeshes "$this->decrRef();"
+%feature("unref") MEDFileField1TS "$this->decrRef();"
+%feature("unref") MEDFileFieldMultiTS "$this->decrRef();"
+%feature("unref") MEDFileFields "$this->decrRef();"
+
class MEDLoader
{
public:
}
};
+ class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileMeshMultiTS *New();
+ static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ const char *getName() const throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileMesh *ret=self->getOneTimeStep();
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ }
+ };
+
+ class MEDFileMeshes : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileMeshes *New();
+ static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
+ //
+ void resize(int newSize) throw(INTERP_KERNEL::Exception);
+ void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
+ void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
+ void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
+ {
+ MEDFileMesh *ret=self->getMeshAtPos(i);
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ }
+ };
+
class MEDFieldFieldGlobs
{
public:
class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs, public MEDFileWritable
{
public:
+ static MEDFileFieldMultiTS *New();
static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
+ //
+ void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception);
};
class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs, public MEDFileWritable
{
public:
+ static MEDFileFields *New();
static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
int getNumberOfFields() const;
- std::vector<std::string> getPfls() const;
- std::vector<std::string> getLocs() const;
+ //
+ void resize(int newSize) throw(INTERP_KERNEL::Exception);
+ void pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception);
+ void setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception);
+ void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception);
+ };
+
+ class MEDFileData : public RefCountObject, public MEDFileWritable
+ {
+ public:
+ static MEDFileData *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileData *New();
+ MEDFileFields *getFields() const;
+ MEDFileMeshes *getMeshes() const;
+ void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception);
+ void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception);
+ int getNumberOfFields() const throw(INTERP_KERNEL::Exception);
+ int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
+ //
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
};
}
self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
#
pass
+ def testMEDFileData1(self):
+ fname="Pyfile29.med"
+ d=MEDFileData.New()
+ #
+ m1=MEDLoaderDataForTest.build1DMesh_1()
+ mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
+ mmm1=MEDFileMeshMultiTS.New() ;
+ mmm1.setOneTimeStep(mm1)
+ m2=MEDLoaderDataForTest.build2DCurveMesh_1()
+ mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
+ mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
+ ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
+ d.setMeshes(ms)
+ #
+ ff1=MEDFileFieldMultiTS.New()
+ ff21=MEDFileFieldMultiTS.New()
+ ff22=MEDFileFieldMultiTS.New()
+ f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
+ f1.getArray().setInfoOnComponent(0,"power [kW]")
+ ff1.appendFieldNoProfileSBT(f1)
+ f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
+ f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
+ ff21.appendFieldNoProfileSBT(f21)
+ f22=f21.deepCpy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
+ f22.applyFunc(2,"3*x*IVec+2*x*JVec")
+ f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
+ ff22.appendFieldNoProfileSBT(f22)
+ fs=MEDFileFields.New()
+ fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
+ d.setFields(fs)
+ #
+ d.write(fname,0)
+ #
+ d2=MEDFileData.New(fname)
+ self.assertEqual(2,d2.getNumberOfMeshes())
+ self.assertEqual(3,d2.getNumberOfFields())
+ m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
+ self.assertTrue(m1.isEqual(m1bis,1e-12))
+ pass
pass
unittest.main()