From: ageay Date: Mon, 5 Jul 2010 17:25:11 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_main_FINAL~100 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=575eb861ddd761cea838a63975466231637a6d69;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index cd5c40ec9..06f35c86d 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -390,8 +390,22 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName return ret; } -std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char *fileName, const char *fieldName) +std::vector< std::pair > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) { + switch(type) + { + case ON_CELLS: + return GetCellFieldIterations(fileName,meshName,fieldName); + case ON_NODES: + 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) +{ + std::string meshNameCpp(meshName); std::vector< std::pair > ret; med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); med_int nbFields=MEDnChamp(fid,0); @@ -423,8 +437,12 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * for(int k=0;k > MEDLoader::GetCellFieldIterations(const char * return ret; } -std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *fieldName) +std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) { + std::string meshNameCpp(meshName); std::vector< std::pair > ret; med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); med_int nbFields=MEDnChamp(fid,0); @@ -463,7 +482,11 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * for(int k=0;k @@ -80,12 +81,14 @@ public: static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName); static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName); static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName); - static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *fieldName); - static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *fieldName); + static std::vector< std::pair > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName); + static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName); + static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch); diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 1784852e8..bd663c7fd 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -161,6 +161,97 @@ void MEDLoaderTest::testFieldRW2() f1->decrRef(); } +/*! + * Multi field in a same file, but this field has several + */ +void MEDLoaderTest::testFieldRW3() +{ + static const double VAL1=12345.67890314; + static const double VAL2=-1111111111111.; + const char name1[]="AField"; + const char name3[]="AMesh1"; + const char name2[]="AMesh2"; + MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1(); + ((MEDCouplingMesh *)f1->getMesh())->setName(name3); + f1->setName(name1); + f1->setTime(10.,8,9); + double *tmp=f1->getArray()->getPointer(); + tmp[0]=VAL1; + MEDLoader::WriteField("file11.med",f1,true); + f1->setTime(10.14,18,19); + tmp[0]=VAL2; + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + ((MEDCouplingMesh *)f1->getMesh())->setName(name2); + f1->setTime(10.55,28,29); + tmp[0]=3*VAL1; + MEDLoader::WriteField("file11.med",f1,false); + f1->setTime(10.66,38,39); + tmp[0]=3*VAL2; + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + f1->setTime(10.77,48,49); + tmp[0]=4*VAL2; + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + //ON NODES + f1->decrRef(); + f1=buildVecFieldOnNodes_1(); + f1->setName(name1); + ((MEDCouplingMesh *)f1->getMesh())->setName(name2); + f1->setTime(110.,8,9); + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + f1->setTime(110.,108,109); + tmp=f1->getArray()->getPointer(); + tmp[3]=VAL1; + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + f1->setTime(210.,208,209); + tmp[3]=VAL2; + MEDLoader::WriteFieldUsingAlreadyWrittenMesh("file11.med",f1); + // + std::vector< std::pair > it1=MEDLoader::GetCellFieldIterations("file11.med",name3,name1); + CPPUNIT_ASSERT_EQUAL(2,(int)it1.size()); + CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second); + CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second); + std::vector< std::pair > it2=MEDLoader::GetCellFieldIterations("file11.med",name2,name1); + CPPUNIT_ASSERT_EQUAL(3,(int)it2.size()); + CPPUNIT_ASSERT_EQUAL(28,it2[0].first); CPPUNIT_ASSERT_EQUAL(29,it2[0].second); + CPPUNIT_ASSERT_EQUAL(38,it2[1].first); CPPUNIT_ASSERT_EQUAL(39,it2[1].second); + CPPUNIT_ASSERT_EQUAL(48,it2[2].first); CPPUNIT_ASSERT_EQUAL(49,it2[2].second); + std::vector< std::pair > it3=MEDLoader::GetNodeFieldIterations("file11.med",name2,name1); + CPPUNIT_ASSERT_EQUAL(3,(int)it3.size()); + CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second); + CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second); + CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second); + std::vector< std::pair > it4=MEDLoader::GetNodeFieldIterations("file11.med",name3,name1); + CPPUNIT_ASSERT(it4.empty()); + // + f1->decrRef(); + // + f1=MEDLoader::ReadFieldDoubleCell("file11.med",name3,0,name1,8,9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[0],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleCell("file11.med",name3,0,name1,18,19); + CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleCell("file11.med",name2,0,name1,28,29); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleCell("file11.med",name2,0,name1,38,39); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleCell("file11.med",name2,0,name1,48,49); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13); + f1->decrRef(); + // + f1=MEDLoader::ReadFieldDoubleNode("file11.med",name2,0,name1,8,9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleNode("file11.med",name2,0,name1,108,109); + CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13); + f1->decrRef(); + f1=MEDLoader::ReadFieldDoubleNode("file11.med",name2,0,name1,208,209); + CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13); + f1->decrRef(); +} + void MEDLoaderTest::testMultiMeshRW1() { MEDCouplingUMesh *mesh1=build3DMesh_1(); @@ -377,7 +468,7 @@ MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1() array->decrRef(); double *tmp=array->getPointer(); const double arr1[36]={ - 0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25., + 70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95., 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025., }; std::copy(arr1,arr1+36,tmp); diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index 22350e413..b1b2184df 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -37,6 +37,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testMesh3DRW ); CPPUNIT_TEST( testFieldRW1 ); CPPUNIT_TEST( testFieldRW2 ); + CPPUNIT_TEST( testFieldRW3 ); CPPUNIT_TEST( testMultiMeshRW1 ); CPPUNIT_TEST_SUITE_END(); public: @@ -47,6 +48,7 @@ namespace ParaMEDMEM void testMesh3DRW(); void testFieldRW1(); void testFieldRW2(); + void testFieldRW3(); void testMultiMeshRW1(); private: MEDCouplingUMesh *build1DMesh_1();