return arrOutC;
}
+/*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ */
+MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+ if(!mm)
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
+ MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
+ std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
+ for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
+ {
+ if((*it0)!=ON_NODES)
+ {
+ std::vector<int> levs;
+ getNonEmptyLevels(mm->getName(),levs);
+ for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
+ {
+ std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
+ if(it2!=extractDef.end())
+ {
+ MCAuto<DataArrayInt> t((*it2).second);
+ MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
+ MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
+ ret->setFieldNoProfileSBT(fOut);
+ }
+ }
+ }
+ else
+ {
+ std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
+ if(it2==extractDef.end())
+ throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
+ MCAuto<DataArrayInt> t((*it2).second);
+ MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
+ MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
+ DataArrayDouble *arr(f->getArray());
+ MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
+ fOut->setArray(newArr);
+ ret->setFieldNoProfileSBT(fOut);
+ }
+ }
+ return ret.retn();
+}
+
MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
{
* delete this field using decrRef() as it is no more needed.
* \throw If \a pos is not a valid time step id.
*/
-MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
+MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
{
const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
if(!item)
return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
}
+/*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ */
+MEDFileFieldMultiTS *MEDFileFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+ if(!mm)
+ throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
+ MCAuto<MEDFileFieldMultiTS> fmtsOut(MEDFileFieldMultiTS::New());
+ int nbTS(getNumberOfTS());
+ for(int i=0;i<nbTS;i++)
+ {
+ MCAuto<MEDFileField1TS> f1ts(getTimeStepAtPos(i));
+ MCAuto<MEDFileField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
+ fmtsOut->pushBackTimeStep(f1tsOut);
+ }
+ return fmtsOut.retn();
+}
+
//= MEDFileAnyTypeFieldMultiTSIterator
MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
}
+MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+ throw INTERP_KERNEL::Exception("*MEDFileIntFieldMultiTS::extractPart : not implemented yet for int !");
+}
+
//= MEDFileFields
MEDFileFields *MEDFileFields::New()
return ret;
}
+/*!
+ * Return an extraction of \a this using \a extractDef map to specify the extraction.
+ * The keys of \a extractDef is level relative to max ext of \a mm mesh.
+ *
+ * \return A new object that the caller is responsible to deallocate.
+ */
+MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
+{
+ if(!mm)
+ throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
+ MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
+ int nbFields(getNumberOfFields());
+ for(int i=0;i<nbFields;i++)
+ {
+ MEDFileAnyTypeFieldMultiTS *fmts(getFieldAtPos(i));
+ if(!fmts)
+ {
+ std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
+ fsOut->pushField(fmtsOut);
+ }
+ return fsOut.retn();
+}
+
MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
{
if(i<0 || i>=(int)_fields.size())
public:
MEDLOADER_EXPORT static void SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr);
MEDLOADER_EXPORT static DataArrayDouble *ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr);
+ public:
+ MEDLOADER_EXPORT MEDFileField1TS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
private:
med_field_type getMEDFileFieldType() const { return MED_FLOAT64; }
const MEDFileField1TSWithoutSDA *contentNotNull() const;
MEDLOADER_EXPORT std::vector< std::vector<TypeOfField> > getTypesOfFieldAvailable() const;
MEDLOADER_EXPORT std::vector< std::vector< std::pair<int,int> > > getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
MEDLOADER_EXPORT MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> getContent();
+ public:
+ MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const = 0;
public:
MEDLOADER_EXPORT std::vector<std::string> getPflsReallyUsed() const;
MEDLOADER_EXPORT std::vector<std::string> getLocsReallyUsed() const;
MEDLOADER_EXPORT void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const;
MEDLOADER_EXPORT MEDFileIntFieldMultiTS *convertToInt(bool isDeepCpyGlobs=true) const;
//
- MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const;
+ MEDLOADER_EXPORT MEDFileField1TS *getTimeStepAtPos(int pos) const;
MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const;
MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const;
//
MEDLOADER_EXPORT std::vector< std::vector<DataArrayDouble *> > getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const;
MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArray(int iteration, int order) const;
MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const;
+ public:
+ MEDLOADER_EXPORT MEDFileFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
private:
const MEDFileFieldMultiTSWithoutSDA *contentNotNull() const;
MEDFileFieldMultiTSWithoutSDA *contentNotNull();
MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile);
//
MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray(int iteration, int order) const;
+ public:
+ MEDLOADER_EXPORT MEDFileIntFieldMultiTS *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
private:
const MEDFileIntFieldMultiTSWithoutSDA *contentNotNull() const;
MEDFileIntFieldMultiTSWithoutSDA *contentNotNull();
MEDLOADER_EXPORT void destroyFieldsAtPos2(int bg, int end, int step);
MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab);
MEDLOADER_EXPORT bool renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N);
+ public:
+ MEDLOADER_EXPORT MEDFileFields *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
public:
MEDLOADER_EXPORT std::vector<std::string> getPflsReallyUsed() const;
MEDLOADER_EXPORT std::vector<std::string> getLocsReallyUsed() const;
%newobject MEDCoupling::MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps;
%newobject MEDCoupling::MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps;
%newobject MEDCoupling::MEDFileFields::__iter__;
+%newobject MEDCoupling::MEDFileFields::extractPart;
%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::New;
%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::deepCopy;
%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::getTimeStep;
%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime;
%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::__iter__;
+%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::extractPart;
%newobject MEDCoupling::MEDFileFieldMultiTS::New;
%newobject MEDCoupling::MEDFileFieldMultiTS::LoadSpecificEntities;
%newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtLevel;
%newobject MEDCoupling::MEDFileField1TS::getFieldAtLevelOld;
%newobject MEDCoupling::MEDFileField1TS::getUndergroundDataArray;
%newobject MEDCoupling::MEDFileField1TS::convertToInt;
+%newobject MEDCoupling::MEDFileField1TS::extractPart;
+
%newobject MEDCoupling::MEDFileIntField1TS::New;
%newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray;
%newobject MEDCoupling::MEDFileIntField1TS::convertToDouble;
PyTuple_SetItem(ret,1,elt);
return ret;
}
+
+ MEDFileField1TS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const
+ {
+ std::map<int, MCAuto<DataArrayInt> > extractDefCpp;
+ convertToMapIntDataArrayInt(extractDef,extractDefCpp);
+ return self->extractPart(extractDefCpp,mm);
+ }
}
};
}
}
+ MEDFileAnyTypeFieldMultiTS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const
+ {
+ std::map<int, MCAuto<DataArrayInt> > extractDefCpp;
+ convertToMapIntDataArrayInt(extractDef,extractDefCpp);
+ return self->extractPart(extractDefCpp,mm);
+ }
+
static PyObject *MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(PyObject *li) throw(INTERP_KERNEL::Exception)
{
std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTS;
self->destroyFieldsAtPos(&idsToRemove[0],&idsToRemove[0]+idsToRemove.size());
}
}
+
+ MEDFileFields *extractPart(PyObject *extractDef, MEDFileMesh *mm) const throw(INTERP_KERNEL::Exception)
+ {
+ std::map<int, MCAuto<DataArrayInt> > extractDefCpp;
+ convertToMapIntDataArrayInt(extractDef,extractDefCpp);
+ return self->extractPart(extractDefCpp,mm);
+ }
}
};
else
throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");
}
+
+void convertToMapIntDataArrayInt(PyObject *pyMap, std::map<int, MCAuto<DataArrayInt> >& cppMap)
+{
+ if(!PyDict_Check(pyMap))
+ throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : input is not a python map !");
+ PyObject *key, *value;
+ Py_ssize_t pos(0);
+ cppMap.clear();
+ while (PyDict_Next(pyMap,&pos,&key,&value))
+ {
+ if(!PyInt_Check(key))
+ throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : keys in map must be PyInt !");
+ long k(PyInt_AS_LONG(key));
+ void *argp(0);
+ int status(SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0));
+ if(!SWIG_IsOK(status))
+ {
+ std::ostringstream oss; oss << "convertToMapIntDataArrayInt : values in map must be DataArrayInt !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ DataArrayInt *arg(reinterpret_cast<DataArrayInt*>(argp));
+ MCAuto<DataArrayInt> arg2(arg);
+ if(arg)
+ arg->incrRef();
+ cppMap[k]=arg2;
+ }
+}
+