/*!
* Sets information on all components. This method can change number of components
* at certain conditions; if the conditions are not respected, an exception is thrown.
- * The number of components can be changed provided that \a this is not allocated.
+ * The number of components can be changed in \a this only if \a this is not allocated.
+ * The condition of number of components must not be changed.
*
* To know more on format of the component information see
* \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
}
+/*!
+ * This method desallocated \a this without modification of informations relative to the components.
+ * After call of this method, DataArrayDouble::isAllocated will return false.
+ * If \a this is already not allocated, \a this is let unchanged.
+ */
+void DataArrayDouble::desallocate() throw(INTERP_KERNEL::Exception)
+{
+ _mem.destroy();
+}
+
std::size_t DataArrayDouble::getHeapMemorySize() const
{
std::size_t sz=_mem.getNbOfElemAllocated();
* than the current number the array is truncated, otherwise the array is extended.
* \param [in] nbOfTuples - new number of tuples.
* \throw If \a this is not allocated.
+ * \throw If \a nbOfTuples is negative.
*/
void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
+ if(nbOfTuples<0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::reAlloc : input new number of tuples should be >=0 !");
checkAllocated();
_mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
declareAsNew();
throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
}
+/*!
+ * This method desallocated \a this without modification of informations relative to the components.
+ * After call of this method, DataArrayInt::isAllocated will return false.
+ * If \a this is already not allocated, \a this is let unchanged.
+ */
+void DataArrayInt::desallocate() throw(INTERP_KERNEL::Exception)
+{
+ _mem.destroy();
+}
+
std::size_t DataArrayInt::getHeapMemorySize() const
{
std::size_t sz=_mem.getNbOfElemAllocated();
* than the current number the array is truncated, otherwise the array is extended.
* \param [in] nbOfTuples - new number of tuples.
* \throw If \a this is not allocated.
+ * \throw If \a nbOfTuples is negative.
*/
void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
+ if(nbOfTuples<0)
+ throw INTERP_KERNEL::Exception("DataArrayInt::reAlloc : input new number of tuples should be >=0 !");
checkAllocated();
_mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
declareAsNew();
static void CPPDeallocator(void *pt, void *param);
static void CDeallocator(void *pt, void *param);
private:
- static void destroyPointer(T *pt, Deallocator dealloc, void *param);
+ static void DestroyPointer(T *pt, Deallocator dealloc, void *param);
static Deallocator BuildFromType(DeallocType type) throw(INTERP_KERNEL::Exception);
private:
std::size_t _nb_of_elem;
MEDCOUPLING_EXPORT int getNumberOfComponents() const { return (int)_info_on_compo.size(); }
MEDCOUPLING_EXPORT virtual bool isAllocated() const throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual void checkAllocated() const throw(INTERP_KERNEL::Exception) = 0;
+ MEDCOUPLING_EXPORT virtual void desallocate() throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception) = 0;
+ MEDCOUPLING_EXPORT virtual void reAlloc(int newNbOfTuple) throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual void renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual void renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT virtual void setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception) = 0;
MEDCOUPLING_EXPORT static DataArrayDouble *New();
MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void desallocate() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
MEDCOUPLING_EXPORT std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); }
MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const;
MEDCOUPLING_EXPORT static DataArrayInt *New();
MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void desallocate() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
MEDCOUPLING_EXPORT std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); }
MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const;
MEDCOUPLING_EXPORT virtual DataArrayChar *deepCpy() const = 0;
MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void desallocate() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
MEDCOUPLING_EXPORT std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); }
MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const;
template<class T>
void MemArray<T>::useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfElem)
{
+ destroy();
_nb_of_elem=nbOfElem;
_nb_of_elem_alloc=nbOfElem;
- destroy();
if(ownership)
_pointer.setInternal(const_cast<T *>(array));
else
template<class T>
void MemArray<T>::useExternalArrayWithRWAccess(const T *array, std::size_t nbOfElem)
{
+ destroy();
_nb_of_elem=nbOfElem;
_nb_of_elem_alloc=nbOfElem;
- destroy();
_pointer.setInternal(const_cast<T *>(array));
_ownership=false;
_dealloc=CPPDeallocator;
T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
if(_ownership)
- destroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
+ DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
_pointer.setInternal(pointer);
_nb_of_elem=std::min<std::size_t>(_nb_of_elem,newNbOfElements);
_nb_of_elem_alloc=newNbOfElements;
T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
if(_ownership)
- destroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
+ DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
_pointer.setInternal(pointer);
_nb_of_elem=newNbOfElements;
_nb_of_elem_alloc=newNbOfElements;
}
template<class T>
- void MemArray<T>::destroyPointer(T *pt, typename MemArray<T>::Deallocator dealloc, void *param)
+ void MemArray<T>::DestroyPointer(T *pt, typename MemArray<T>::Deallocator dealloc, void *param)
{
if(dealloc)
dealloc(pt,param);
void MemArray<T>::destroy()
{
if(_ownership)
- destroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
+ DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
_pointer.null();
_ownership=false;
_dealloc=NULL;
_param_for_deallocator=NULL;
+ _nb_of_elem=0;
+ _nb_of_elem_alloc=0;
}
template<class T>
throw INTERP_KERNEL::Exception("DataArrayChar::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
}
+/*!
+ * This method desallocated \a this without modification of informations relative to the components.
+ * After call of this method, DataArrayChar::isAllocated will return false.
+ * If \a this is already not allocated, \a this is let unchanged.
+ */
+void DataArrayChar::desallocate() throw(INTERP_KERNEL::Exception)
+{
+ _mem.destroy();
+}
+
std::size_t DataArrayChar::getHeapMemorySize() const
{
std::size_t sz=_mem.getNbOfElemAllocated();
* than the current number the array is truncated, otherwise the array is extended.
* \param [in] nbOfTuples - new number of tuples.
* \throw If \a this is not allocated.
+ * \throw If \a nbOfTuples is negative.
*/
void DataArrayChar::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
+ if(nbOfTuples<0)
+ throw INTERP_KERNEL::Exception("DataArrayChar::reAlloc : input new number of tuples should be >=0 !");
checkAllocated();
_mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
declareAsNew();
CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI3),2);
CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI3)),std::string("NORM_TRI3"));
CPPUNIT_ASSERT_THROW(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_POLYGON),INTERP_KERNEL::Exception);
- CPPUNIT_ASSERT(not MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
+ CPPUNIT_ASSERT(!MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_POLYGON));
CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_POLYGON),2);
CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_POLYGON)),std::string("NORM_POLYGON"));
self.assertTrue(c.isEqual(DataArrayInt([5,2,1,10])))
pass
+ def testSwig2DADesallocate1(self):
+ d=DataArrayDouble([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(d.isAllocated())
+ d.checkAllocated()
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ ref=d.getHeapMemorySize()
+ d.desallocate()
+ self.assertEqual(ref-d.getHeapMemorySize(),6*8)
+ self.assertTrue(not d.isAllocated())
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ self.assertRaises(InterpKernelException,d.checkAllocated)
+ #
+ d=DataArrayInt([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(d.isAllocated())
+ d.checkAllocated()
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ ref=d.getHeapMemorySize()
+ d.desallocate()
+ self.assertEqual(ref-d.getHeapMemorySize(),6*4)
+ self.assertTrue(not d.isAllocated())
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ self.assertRaises(InterpKernelException,d.checkAllocated)
+ pass
+
def setUp(self):
pass
pass
void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception);
int getNumberOfComponents() const;
virtual void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception);
+ virtual void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception);
virtual bool isAllocated() const throw(INTERP_KERNEL::Exception);
virtual void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ virtual void desallocate() throw(INTERP_KERNEL::Exception);
virtual int getNumberOfTuples() const throw(INTERP_KERNEL::Exception);
virtual std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception);
virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception);
std::string reprZip() const throw(INTERP_KERNEL::Exception);
bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception);
- void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception);
DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception);
DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception);
- void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception);
DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception);
DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception);
DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception);
void fillWithValue(char val) throw(INTERP_KERNEL::Exception);
std::string repr() const throw(INTERP_KERNEL::Exception);
std::string reprZip() const throw(INTERP_KERNEL::Exception);
- void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception);
DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception);
DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception);
DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception);
INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
med_geometry_type mgeoti;
med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
- DataArray *arr=getOrCreateAndGetArray();
if(_start>_end)
throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
+ if(_start==_end)
+ return ;
+ DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
if(_start<0 || _start>=arr->getNumberOfTuples())
{
std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
+ med_int tmp1,nbi;
+ INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
+ int nbOfCompo=arr->getNumberOfComponents();
+ if(_end-_start!=nbValsInFile*nbi)
+ {
+ std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi << " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
if(arrD)
{
- double *startFeeding=arrD->getPointer()+_start*arrD->getNumberOfComponents();
+ double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
return ;
DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
if(arrI)
{
- int *startFeeding=arrI->getPointer()+_start*arrI->getNumberOfComponents();
+ int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
return ;
_field_per_mesh[0]->writeLL(fid,nasc);
}
-void MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception)
+/*!
+ * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated.
+ * If false is returned the memory allocation is not required.
+ */
+bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception)
{
if(_nb_of_tuples_to_be_allocated>=0)
{
getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
_nb_of_tuples_to_be_allocated=-2;
- return ;
+ return true;
}
if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
- return ;
+ return false;
if(_nb_of_tuples_to_be_allocated==-1)
throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
if(_nb_of_tuples_to_be_allocated<-3)
(*it)->loadBigArraysRecursively(fid,nasc);
}
+void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
+{
+ if(allocIfNecessaryTheArrayToReceiveDataFromFile())
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
+ (*it)->loadBigArraysRecursively(fid,nasc);
+}
+
void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
{
loadOnlyStructureOfDataRecursively(fid,nasc);
loadBigArraysRecursively(fid,nasc);
}
+void MEDFileAnyTypeField1TSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
+{
+ DataArray *thisArr(getUndergroundDataArray());
+ if(thisArr && thisArr->isAllocated())
+ {
+ _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
+ thisArr->desallocate();
+ }
+}
+
std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
{
std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
{
if(!arr)
- _arr=0;
+ {
+ _nb_of_tuples_to_be_allocated=-1;
+ _arr=0;
+ return ;
+ }
DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
if(!arrC)
throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
+ else
+ _nb_of_tuples_to_be_allocated=-3;
arrC->incrRef();
_arr=arrC;
}
void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
{
if(!arr)
- _arr=0;
+ {
+ _nb_of_tuples_to_be_allocated=-1;
+ _arr=0;
+ return ;
+ }
DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
if(!arrC)
throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
+ else
+ _nb_of_tuples_to_be_allocated=-3;
arrC->incrRef();
_arr=arrC;
}
oss << "(" << (*iter).first << "," << (*iter).second << "), ";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
+ if(loadAll)
+ ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
+ else
+ ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
return ret.retn();
}
writeLL(fid);
}
+/*!
+ * This method alloc the arrays and load potentially huge arrays contained in this field.
+ * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
+ * This method can be also called to refresh or reinit values from a file.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
+ */
+void MEDFileAnyTypeField1TS::loadArrays() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
+}
+
+/*!
+ * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
+ * But once data loaded once, this method does nothing.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::releaseArrays
+ */
+void MEDFileAnyTypeField1TS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
+}
+
+/*!
+ * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
+ * This method does not release arrays set outside the context of a MED file.
+ *
+ * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary
+ */
+void MEDFileAnyTypeField1TS::releaseArrays() throw(INTERP_KERNEL::Exception)
+{
+ contentNotNullBase()->releaseArrays();
+}
+
void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
{
int nbComp=getNumberOfComponents();
_time_steps[i]->writeLL(fid,opts,*this);
}
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursively(fid,nasc);
+ }
+}
+
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
+ }
+}
+
+void MEDFileAnyTypeFieldMultiTSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
+ {
+ MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
+ if(elt)
+ elt->releaseArrays();
+ }
+}
+
int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
{
return _time_steps.size();
* \throw If reading the file fails.
* \throw If there is no field named \a fieldName in the file.
*/
-MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
{
MEDFileUtilities::CheckFileForRead(fileName);
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
- MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
ret->loadGlobals(fid);
return ret.retn();
writeLL(fid);
}
+/*!
+ * This method alloc the arrays and load potentially huge arrays contained in this field.
+ * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
+ * This method can be also called to refresh or reinit values from a file.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ */
+void MEDFileAnyTypeFieldMultiTS::loadArrays() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
+}
+
+/*!
+ * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
+ * But once data loaded once, this method does nothing.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::releaseArrays
+ */
+void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
+}
+
+/*!
+ * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
+ * This method does not release arrays set outside the context of a MED file.
+ *
+ * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
+ */
+void MEDFileAnyTypeFieldMultiTS::releaseArrays() throw(INTERP_KERNEL::Exception)
+{
+ contentNotNullBase()->releaseArrays();
+}
+
std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
{
std::ostringstream oss;
}
/*!
- * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
+ * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
* The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
* ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
*/
writeLL(fid);
}
+/*!
+ * This method alloc the arrays and load potentially huge arrays contained in this field.
+ * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
+ * This method can be also called to refresh or reinit values from a file.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ */
+void MEDFileFields::loadArrays() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
+ {
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursively(fid,*elt);
+ }
+}
+
+/*!
+ * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
+ * But once data loaded once, this method does nothing.
+ *
+ * \throw If the fileName is not set or points to a non readable MED file.
+ * \sa MEDFileFields::loadArrays, MEDFileFields::releaseArrays
+ */
+void MEDFileFields::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
+ {
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
+ if(elt)
+ elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
+ }
+}
+
+/*!
+ * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
+ * This method does not release arrays set outside the context of a MED file.
+ *
+ * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary
+ */
+void MEDFileFields::releaseArrays() throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
+ {
+ MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
+ if(elt)
+ elt->releaseArrays();
+ }
+}
+
std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
{
std::vector<std::string> ret;
bool renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
public:
void allocNotFromFile(int newNbOfTuples) throw(INTERP_KERNEL::Exception);
- void allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception);
+ bool allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception);
void loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
+ void loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
void loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
void writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception);
protected:
int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception);
int getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception);
public:
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > splitComponents() const throw(INTERP_KERNEL::Exception);
MEDFileAnyTypeField1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
int copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception);
bool renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception);
void loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll) throw(INTERP_KERNEL::Exception);
void writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception);
+ void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
+ void loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
public:
const MEDFileAnyTypeField1TSWithoutSDA *getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception);
MEDFileAnyTypeField1TSWithoutSDA *getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception);
static MEDFileAnyTypeFieldMultiTSWithoutSDA *BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception);
public:
static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
- static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, const char *fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
std::size_t getHeapMemorySize() const;
MEDFileFields *shallowCpy() const throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
int getNumberOfFields() const;
std::vector< std::pair<int,int> > getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception);
std::vector<std::string> getFieldsNames() const throw(INTERP_KERNEL::Exception);
static MEDFileAnyTypeField1TS *New(const char *fileName, const char *fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
static MEDFileAnyTypeField1TS *New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
int getDimension() const throw(INTERP_KERNEL::Exception);
int getIteration() const throw(INTERP_KERNEL::Exception);
int getOrder() const throw(INTERP_KERNEL::Exception);
{
public:
static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
- static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ static MEDFileAnyTypeFieldMultiTS *New(const char *fileName, const char *fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
MEDFileAnyTypeFieldMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception);
virtual MEDFileAnyTypeFieldMultiTS *shallowCpy() const throw(INTERP_KERNEL::Exception);
std::string getName() const throw(INTERP_KERNEL::Exception);
int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
//
virtual MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception);
MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
static MEDFileFields *New(const char *fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
MEDFileFields *deepCpy() const throw(INTERP_KERNEL::Exception);
MEDFileFields *shallowCpy() const throw(INTERP_KERNEL::Exception);
+ void loadArrays() throw(INTERP_KERNEL::Exception);
+ void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
+ void releaseArrays() throw(INTERP_KERNEL::Exception);
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
int getNumberOfFields() const;
std::vector<std::string> getFieldsNames() const throw(INTERP_KERNEL::Exception);
ff0=MEDFileField1TS()
f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
f0.checkCoherency()
- #ff0.setFieldNoProfileSBT(f0)
pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
ff0.setFieldProfile(f0,mm,0,pfl)
fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]