From: ageay Date: Wed, 13 Oct 2010 07:35:08 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_5~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c10c7aa0705bfcc59d2071c8a579e3bc62fccbd8;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index e481cd340..7ced3782b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -62,6 +62,28 @@ void DataArray::reprWithoutNameStream(std::ostream& stream) const 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; diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 18396d86f..33b8896b6 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -88,8 +88,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT std::string getName() const { return _name; } MEDCOUPLING_EXPORT const std::vector &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; } diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 1b4b88e92..0062be8b6 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -407,6 +407,155 @@ std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, con MEDfermer(fid); return ret; } +std::vector MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception) +{ + CheckFileForRead(fileName); + std::vector 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;i0) + { + bool found=false; + for(int i=0;i0) + { + 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 MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) +{ + CheckFileForRead(fileName); + std::vector 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;i0) + { + for(int i=0;i0) + { + 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 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 MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { @@ -515,7 +664,7 @@ std::vector< std::pair > MEDLoader::GetFieldIterations(ParaMEDMEM::Type 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 > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) @@ -617,6 +766,11 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * 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& field, @@ -2334,6 +2488,9 @@ void MEDLoader::WriteUMeshes(const char *fileName, const std::vectorgetName()); + 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_iterator iter=meshes.begin();iter!=meshes.end();iter++) if(coords!=(*iter)->getCoords()) diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index f302c023c..48d95e6c5 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -89,6 +89,9 @@ class MEDLOADER_EXPORT MEDLoader static std::vector GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector< std::pair > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index 1b1103bed..ad9472fd1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -387,6 +387,58 @@ class MEDLoaderTest(unittest.TestCase): 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() diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/libMEDLoader_Swig.i index 37648ec84..f9144f47f 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.i @@ -52,6 +52,8 @@ public: static std::vector GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); %extend @@ -122,6 +124,15 @@ public: std::vector 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& fams) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index b5da3bfd5..a62bc1be3 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -588,6 +588,72 @@ void MEDLoaderTest::testWriteUMeshesRW1() 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 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 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 }; diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index 2b508205a..0863ad1df 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -48,6 +48,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldShuffleRW1 ); CPPUNIT_TEST( testMultiFieldShuffleRW1 ); CPPUNIT_TEST( testWriteUMeshesRW1 ); + CPPUNIT_TEST( testMixCellAndNodesFieldRW1 ); CPPUNIT_TEST_SUITE_END(); public: void testMesh1DRW(); @@ -68,6 +69,7 @@ namespace ParaMEDMEM void testFieldShuffleRW1(); void testMultiFieldShuffleRW1(); void testWriteUMeshesRW1(); + void testMixCellAndNodesFieldRW1(); private: MEDCouplingUMesh *build1DMesh_1(); MEDCouplingUMesh *build2DCurveMesh_1();