]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 5 Jul 2010 17:25:11 +0000 (17:25 +0000)
committerageay <ageay>
Mon, 5 Jul 2010 17:25:11 +0000 (17:25 +0000)
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/MEDLoader.hxx
src/MEDLoader/Test/MEDLoaderTest.cxx
src/MEDLoader/Test/MEDLoaderTest.hxx

index cd5c40ec9766ef55df8f02eeaec263b61e3b0f5c..06f35c86d351ce3a4d443fdbe64e501d5594527d 100644 (file)
@@ -390,8 +390,22 @@ std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName
   return ret;
 }
 
-std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *fieldName)
+std::vector< std::pair<int,int> > 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<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
+{
+  std::string meshNameCpp(meshName);
   std::vector< std::pair<int,int> > ret;
   med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
   med_int nbFields=MEDnChamp(fid,0);
@@ -423,8 +437,12 @@ std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *
               for(int k=0;k<nbPdt;k++)
                 {
                   MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
-                  found=true;
-                  ret.push_back(std::make_pair(numdt,numo));
+                  std::string maa_ass_cpp(maa_ass);
+                  if(meshNameCpp==maa_ass_cpp)
+                    {
+                      found=true;
+                      ret.push_back(std::make_pair(numdt,numo));
+                    }
                 }
             }
         }
@@ -433,8 +451,9 @@ std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *
   return ret;
 }
 
-std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *fieldName)
+std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
 {
+  std::string meshNameCpp(meshName);
   std::vector< std::pair<int,int> > ret;
   med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
   med_int nbFields=MEDnChamp(fid,0);
@@ -463,7 +482,11 @@ std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *
           for(int k=0;k<nbPdt;k++)
             {
               MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
-              ret.push_back(std::make_pair(numdt,numo));
+               std::string maa_ass_cpp(maa_ass);
+               if(meshNameCpp==maa_ass_cpp)
+                 {
+                   ret.push_back(std::make_pair(numdt,numo));
+                 }
             }
         }
     }
@@ -1140,6 +1163,19 @@ ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileNam
   return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim);
 }
 
+ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
+{
+  switch(type)
+    {
+    case ON_CELLS:
+      return ReadFieldDoubleCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+    case ON_NODES:
+      return ReadFieldDoubleNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+    default:
+      throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
+    } 
+}
+
 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
 {
   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS);
index ffd68857c0c6dfbcef8b1da87fd7cc057233a1ae..1c40b79f9fb7d1d33883c18cbfc9e06e6d3aec33 100644 (file)
@@ -21,6 +21,7 @@
 #define __MEDLOADER_HXX__
 
 #include "InterpKernelException.hxx"
+#include "MEDCouplingRefCountObject.hxx"
 #include "NormalizedUnstructuredMesh.hxx"
 
 #include <list>
@@ -80,12 +81,14 @@ public:
   static std::vector<std::string> GetMeshFamilyNames(const char *fileName, const char *meshName);
   static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName);
   static std::vector<std::string> GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName);
-  static std::vector< std::pair<int,int> > GetCellFieldIterations(const char *fileName, const char *fieldName);
-  static std::vector< std::pair<int,int> > GetNodeFieldIterations(const char *fileName, const char *fieldName);
+  static std::vector< std::pair<int,int> > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName);
+  static std::vector< std::pair<int,int> > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName);
+  static std::vector< std::pair<int,int> > 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<std::string>& fams);
   static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& 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);
index 1784852e8037b9a3abffb63b48916274d15b1064..bd663c7fd758e134fbf661da8cafc5e4663aaf41 100644 (file)
@@ -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<int,int> > 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<int,int> > 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<int,int> > 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<int,int> > 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);
index 22350e413fb353c80ffd9d5a02bec5a16d29ede4..b1b2184df1b19df038c3696d63dd0afe3f2188bb 100644 (file)
@@ -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();