From: ageay Date: Wed, 10 Jul 2013 15:20:58 +0000 (+0000) Subject: Check the coherency between array size and profile X-Git-Tag: B4KillOfAutomake~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=05797234e86a4c183157cdf7e44250c5286fbb53;p=modules%2Fmed.git Check the coherency between array size and profile --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 745dea27b..67f4f51ba 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -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 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 idsInPflPerType; std::vector idsPerType; std::vector code,code2; @@ -4260,20 +4264,34 @@ void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDou if(type!=ON_NODES) { m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType); + std::vector< MEDCouplingAutoRefCountObjectPtr > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin()); + std::vector< MEDCouplingAutoRefCountObjectPtr > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); + std::vector 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 > idsInPflPerType2(idsInPflPerType.size()); - for(std::size_t i=0;i > idsPerType2(idsPerType.size()); - for(std::size_t i=0;iassignFieldProfile(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 v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0; + std::vector 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); } diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index c4b17862c..b0ce566b2 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -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 diff --git a/src/MEDLoader/Swig/SauvLoaderTest.py b/src/MEDLoader/Swig/SauvLoaderTest.py index 70fed0dc2..18c4c5855 100644 --- a/src/MEDLoader/Swig/SauvLoaderTest.py +++ b/src/MEDLoader/Swig/SauvLoaderTest.py @@ -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 ) diff --git a/src/MEDLoader/Test/SauvLoaderTest.cxx b/src/MEDLoader/Test/SauvLoaderTest.cxx index 113633c73..1f90c7bea 100644 --- a/src/MEDLoader/Test/SauvLoaderTest.cxx +++ b/src/MEDLoader/Test/SauvLoaderTest.cxx @@ -192,7 +192,6 @@ void SauvLoaderTest::testMed2Sauv() // add a field on 2 faces to pointeMed MEDCouplingAutoRefCountObjectPtr ff1=MEDFileFieldMultiTS::New(); MEDCouplingAutoRefCountObjectPtr f1=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME); - f1->setMesh( pointeM1D ); f1->setName("Field on 2 faces"); MEDCouplingAutoRefCountObjectPtr d=DataArrayDouble::New(); d->alloc(3+4,2); @@ -209,6 +208,8 @@ void SauvLoaderTest::testMed2Sauv() { 0,2 }; + MEDCouplingAutoRefCountObjectPtr 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");