]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Check the coherency between array size and profile
authorageay <ageay>
Wed, 10 Jul 2013 15:20:58 +0000 (15:20 +0000)
committerageay <ageay>
Wed, 10 Jul 2013 15:20:58 +0000 (15:20 +0000)
src/MEDLoader/MEDFileField.cxx
src/MEDLoader/SauvMedConvertor.cxx
src/MEDLoader/Swig/SauvLoaderTest.py
src/MEDLoader/Test/SauvLoaderTest.cxx

index 745dea27b6f8b2542be73dca2af6f4344f07d0fe..67f4f51ba28bc3ac9ef623789442553f7c9307e2 100644 (file)
@@ -1021,7 +1021,8 @@ void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDC
 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
 {
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
-  //
+  if(!arr || !arr->isAllocated())
+    throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
   _field_pm_pt_pd.resize(1);
   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
@@ -4251,8 +4252,11 @@ void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFie
  */
 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
 {
+  if(!field)
+    throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
+  if(!arrOfVals || !arrOfVals->isAllocated())
+    throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
   TypeOfField type=field->getTypeOfField();
-  int start=copyTinyInfoFrom(field,arrOfVals);
   std::vector<DataArrayInt *> idsInPflPerType;
   std::vector<DataArrayInt *> idsPerType;
   std::vector<int> code,code2;
@@ -4260,20 +4264,34 @@ void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDou
   if(type!=ON_NODES)
     {
       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
+      std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
+      std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
+      std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin()); 
+      int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
+      if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
+        {
+          std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      int start=copyTinyInfoFrom(field,arrOfVals);
       code2=m->getDistributionOfTypes();
       //
-      std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
-      for(std::size_t i=0;i<idsInPflPerType.size();i++)
-        idsInPflPerType2[i]=idsInPflPerType[i];
-      std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
-      for(std::size_t i=0;i<idsPerType.size();i++)
-        idsPerType2[i]=idsPerType[i];
-      //
       int pos=addNewEntryIfNecessary(m);
       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
     }
   else
     {
+      if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
+        throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
+      std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
+      std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
+      int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
+      if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
+        {
+          std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      int start=copyTinyInfoFrom(field,arrOfVals);
       int pos=addNewEntryIfNecessary(m);
       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
     }
index c4b17862c1d5a79a622e0345f6544abec6fe159f..b0ce566b2699e8a4954bc09ac5890a501ca057b9 100644 (file)
@@ -2163,7 +2163,14 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   if ( onAll )
     fld->_curMedField->appendFieldNoProfileSBT( timeStamp );
   else
-    fld->_curMedField->appendFieldProfile( timeStamp, mesh, dimRel, support->_medGroup );
+    {
+      if(fld->getMedType()==ON_GAUSS_NE)
+        {
+          MEDCouplingAutoRefCountObjectPtr< MEDCouplingPointSet > dimMesh2 = dimMesh->buildPartOfMySelf(support->_medGroup->begin(),support->_medGroup->end(),true);
+          timeStamp->setMesh( dimMesh2 );
+        }
+      fld->_curMedField->appendFieldProfile( timeStamp, mesh, dimRel, support->_medGroup );
+    }
   timeStamp->decrRef();
 
   if ( isNewMedField ) // timeStamp must be added before this
index 70fed0dc21a7fa22eeefa51080236142ab6dd2d6..18c4c585553f4e5b72c638ba9abf30f7dc16fe9d 100644 (file)
@@ -72,7 +72,7 @@ class SauvLoaderTest(unittest.TestCase):
         # add a field on 2 faces to pointeMed
         ff1=MEDFileFieldMultiTS.New()
         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME)
-        #f1.setMesh( pointeM1D )
+        #
         f1.setName("Field on 2 faces")
         d=DataArrayDouble.New()
         d.alloc(3+4,2)
@@ -83,6 +83,8 @@ class SauvLoaderTest(unittest.TestCase):
         da=DataArrayInt.New()
         da.setValues([0,2],2,1)
         da.setName("sup2")
+        pointeM1D_2=pointeM1D[da]
+        f1.setMesh( pointeM1D_2 )
         ff1.appendFieldProfile(f1,pointeMedMesh,-1,da)
         pointeMed.getFields().pushField( ff1 )
 
index 113633c734c9066b19a09792eea67f82e9b13703..1f90c7beacd573a42dabe63cdf40059adbfb6a2b 100644 (file)
@@ -192,7 +192,6 @@ void SauvLoaderTest::testMed2Sauv()
   // add a field on 2 faces to pointeMed
   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ff1=MEDFileFieldMultiTS::New();
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
-  f1->setMesh( pointeM1D );
   f1->setName("Field on 2 faces");
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> d=DataArrayDouble::New();
   d->alloc(3+4,2);
@@ -209,6 +208,8 @@ void SauvLoaderTest::testMed2Sauv()
     {
       0,2
     };
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> pointeM1D_part=pointeM1D->buildPartOfMySelf(ids,ids+2,true);
+  f1->setMesh( pointeM1D_part );
   da->alloc(2,1);
   std::copy(ids,ids+da->getNbOfElems(),da->getPointer());
   da->setName("sup2");