stream << "\n";
}
+std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
+{
+ if(i<(int)_info_on_compo.size())
+ return _info_on_compo[i];
+ else
+ {
+ std::ostringstream oss; oss << "getInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
+void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
+{
+ if(i<(int)_info_on_compo.size())
+ _info_on_compo[i]=info;
+ else
+ {
+ std::ostringstream oss; oss << "setInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
DataArrayDouble *DataArrayDouble::New()
{
return new DataArrayDouble;
MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT std::string getName() const { return _name; }
MEDCOUPLING_EXPORT const std::vector<std::string> &getInfoOnComponent() const { return _info_on_compo; }
- MEDCOUPLING_EXPORT std::string getInfoOnComponent(int i) const { return _info_on_compo[i]; }
- MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) { _info_on_compo[i]=info; }
+ MEDCOUPLING_EXPORT std::string getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfComponents() const { return _info_on_compo.size(); }
MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; }
MEDCOUPLING_EXPORT int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; }
MEDfermer(fid);
return ret;
}
+std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ std::vector<ParaMEDMEM::TypeOfField> ret;
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_int nbFields=MEDnChamp(fid,0);
+ //
+ med_type_champ typcha;
+ //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
+ med_int ngauss=0;
+ med_int numdt=0,numo=0,nbrefmaa;
+ med_float dt=0.0;
+ med_booleen local;
+ //char pflname[MED_TAILLE_NOM+1]="";
+ //char locname[MED_TAILLE_NOM+1]="";
+ char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
+ char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ //
+ for(int i=0;i<nbFields;i++)
+ {
+ med_int ncomp=MEDnChamp(fid,i+1);
+ char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
+ delete [] comp;
+ delete [] unit;
+ if(curFieldName==fieldName)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
+ if(nbPdt>0)
+ {
+ bool found=false;
+ for(int i=0;i<nbPdt && !found;i++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
+ if(curMeshName==meshName)
+ {
+ ret.push_back(ON_NODES);
+ found=true;
+ }
+ }
+ }
+ bool found=false;
+ for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
+ if(nbPdt>0)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
+ if(curMeshName==meshName)
+ {
+ found=true;
+ ret.push_back(ON_CELLS);
+ }
+ }
+ }
+ }
+ }
+ delete [] maa_ass;
+ delete [] dt_unit;
+ delete [] nomcha;
+ MEDfermer(fid);
+ return ret;
+}
+
+std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ std::vector<std::string> ret;
+ med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_int nbFields=MEDnChamp(fid,0);
+ //
+ med_type_champ typcha;
+ //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
+ med_int ngauss=0;
+ med_int numdt=0,numo=0,nbrefmaa;
+ med_float dt=0.0;
+ med_booleen local;
+ //char pflname[MED_TAILLE_NOM+1]="";
+ //char locname[MED_TAILLE_NOM+1]="";
+ char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
+ char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ //
+ for(int i=0;i<nbFields;i++)
+ {
+ med_int ncomp=MEDnChamp(fid,i+1);
+ char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
+ delete [] comp;
+ delete [] unit;
+ //
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
+ bool found=false;
+ if(nbPdt>0)
+ {
+ for(int i=0;i<nbPdt && !found;i++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,i+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
+ if(curMeshName==meshName)
+ {
+ found=true;
+ ret.push_back(curFieldName);
+ }
+ }
+ }
+ //
+ for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
+ if(nbPdt>0)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
+ if(curMeshName==meshName)
+ {
+ found=true;
+ ret.push_back(curFieldName);
+ }
+ }
+ }
+ }
+ delete [] maa_ass;
+ delete [] dt_unit;
+ delete [] nomcha;
+ MEDfermer(fid);
+ return ret;
+}
+
+std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ switch(type)
+ {
+ case ON_CELLS:
+ return GetCellFieldNamesOnMesh(fileName,meshName);
+ case ON_NODES:
+ return GetNodeFieldNamesOnMesh(fileName,meshName);
+ default:
+ throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
+ }
+}
std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
return GetNodeFieldIterations(fileName,meshName,fieldName);
default:
throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
- }
+ }
}
std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
return ret;
}
+/*!
+ * This method reads all the content of a field 'fieldName' at a time specified by (iteration,order) lying on a mesh 'meshName' with a specified type 'TypeOfOutField'
+ * The returned values are strored in 'field' (sorted by type of cell), time corresponding to field, and 'infos' to load properly little strings.
+ * The principle of this method is to put into 'field' only data that fulfills \b perfectly request.
+ */
void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
}
if(meshes.empty())
throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
+ std::string meshName(meshes[0]->getName());
+ if(meshName.empty())
+ throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change name of first element of 2nd parameter !");
DataArrayDouble *coords=meshes.front()->getCoords();
for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
if(coords!=(*iter)->getCoords())
static std::vector<std::string> GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<ParaMEDMEM::TypeOfField> GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector< std::pair<int,int> > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception);
f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7);
self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
pass
+
+ def testMixCellAndNodesFieldRW1(self):
+ fileName="Pyfile21.med";
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f1.setName("FieldMix");
+ f1.setMesh(mesh);
+ array=DataArrayDouble.New();
+ f1.setArray(array);
+ arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.]
+ array.setValues(arr1,6,2);
+ array.setInfoOnComponent(0,"plkj (mm)");
+ array.setInfoOnComponent(1,"pqqqss (mm)");
+ f1.setTime(3.14,2,7);
+ f1.checkCoherency();
+ #
+ f2=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f2.setName("FieldMix");
+ f2.setMesh(mesh);
+ array=DataArrayDouble.New();
+ f2.setArray(array);
+ arr2=[1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
+ 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.]
+ array.setValues(arr2,12,2)
+ array.setInfoOnComponent(0,"plkj (mm)");
+ array.setInfoOnComponent(1,"pqqqss (mm)");
+ f2.setTime(3.17,2,7);
+ f2.checkCoherency();
+ #
+ MEDLoader.WriteField(fileName,f1,True);
+ ts=MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName());
+ self.assertEqual(1,len(ts));
+ self.assertEqual(ON_CELLS,ts[0]);
+ fs=MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName());
+ self.assertEqual(1,len(fs));
+ self.assertTrue(fs[0]=="FieldMix");
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
+ fs=MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName());
+ self.assertEqual(1,len(fs));
+ self.assertTrue(fs[0]=="FieldMix");
+ #
+ ts=MEDLoader.GetTypesOfField(fileName,f1.getName(),f1.getMesh().getName());
+ self.assertEqual(2,len(ts));
+ self.assertEqual(ON_NODES,ts[0]);
+ self.assertEqual(ON_CELLS,ts[1]);
+ #
+ f3=MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
+ self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
+ f3=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
+ self.assertTrue(f3.isEqual(f1,1e-12,1e-12));
+ #
+ pass
pass
unittest.main()
static std::vector<std::string> GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
%extend
std::vector<const ParaMEDMEM::MEDCouplingUMesh *> v2(v.begin(),v.end());
MEDLoader::WriteUMeshes(fileName,v2,writeFromScratch);
}
+ static PyObject *GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< ParaMEDMEM::TypeOfField > v=MEDLoader::GetTypesOfField(fileName,fieldName,meshName);
+ int size=v.size();
+ PyObject *ret=PyList_New(size);
+ for(int i=0;i<size;i++)
+ PyList_SetItem(ret,i,PyInt_FromLong((int)v[i]));
+ return ret;
+ }
}
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
m3d->decrRef();
}
+void MEDLoaderTest::testMixCellAndNodesFieldRW1()
+{
+ const char fileName[]="file21.med";
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setName("FieldMix");
+ f1->setMesh(mesh);
+ DataArrayDouble *array=DataArrayDouble::New();
+ array->alloc(6,2);
+ f1->setArray(array);
+ array->setInfoOnComponent(0,"plkj (mm)");
+ array->setInfoOnComponent(1,"pqqqss (mm)");
+ array->decrRef();
+ double *tmp=array->getPointer();
+ const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
+ std::copy(arr1,arr1+12,tmp);
+ f1->setTime(3.14,2,7);
+ f1->checkCoherency();
+ //
+ MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
+ f2->setName("FieldMix");
+ f2->setMesh(mesh);
+ array=DataArrayDouble::New();
+ array->alloc(12,2);
+ f2->setArray(array);
+ array->setInfoOnComponent(0,"plkj (mm)");
+ array->setInfoOnComponent(1,"pqqqss (mm)");
+ array->decrRef();
+ tmp=array->getPointer();
+ const double arr2[24]={
+ 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
+ 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
+ };
+ std::copy(arr2,arr2+24,tmp);
+ f2->setTime(3.17,2,7);
+ f2->checkCoherency();
+ //
+ MEDLoader::WriteField(fileName,f1,true);
+ std::vector<ParaMEDMEM::TypeOfField> ts=MEDLoader::GetTypesOfField(fileName,f1->getName(),f1->getMesh()->getName());
+ CPPUNIT_ASSERT_EQUAL(1,(int)ts.size());
+ CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[0]);
+ std::vector<std::string> fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
+ CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
+ CPPUNIT_ASSERT(fs[0]=="FieldMix");
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
+ fs=MEDLoader::GetAllFieldNamesOnMesh(fileName,f1->getMesh()->getName());
+ CPPUNIT_ASSERT_EQUAL(1,(int)fs.size());
+ CPPUNIT_ASSERT(fs[0]=="FieldMix");
+ //
+ ts=MEDLoader::GetTypesOfField(fileName,f1->getName(),f1->getMesh()->getName());
+ CPPUNIT_ASSERT_EQUAL(2,(int)ts.size());
+ CPPUNIT_ASSERT_EQUAL(ON_NODES,ts[0]);
+ CPPUNIT_ASSERT_EQUAL(ON_CELLS,ts[1]);
+ //
+ MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
+ CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
+ f3->decrRef();
+ f3=MEDLoader::ReadFieldCell(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
+ CPPUNIT_ASSERT(f3->isEqual(f1,1e-12,1e-12));
+ f3->decrRef();
+ //
+ f1->decrRef();
+ f2->decrRef();
+ mesh->decrRef();
+}
+
MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
{
double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
CPPUNIT_TEST( testFieldShuffleRW1 );
CPPUNIT_TEST( testMultiFieldShuffleRW1 );
CPPUNIT_TEST( testWriteUMeshesRW1 );
+ CPPUNIT_TEST( testMixCellAndNodesFieldRW1 );
CPPUNIT_TEST_SUITE_END();
public:
void testMesh1DRW();
void testFieldShuffleRW1();
void testMultiFieldShuffleRW1();
void testWriteUMeshesRW1();
+ void testMixCellAndNodesFieldRW1();
private:
MEDCouplingUMesh *build1DMesh_1();
MEDCouplingUMesh *build2DCurveMesh_1();