return true;
}
-/*!
- * Permutes values of \a this field according to a given permutation array for cells
- * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
- * The number of cells remains the same; for that the permutation array \a old2NewBg
- * should not contain equal ids.
- * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
- *
- * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
- * to be equal to \a this->getMesh()->getNumberOfCells().
- * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
- * array, so that its maximal cell id to correspond to (be less than) the number
- * of cells in mesh. This new array is then used for the renumbering. If \a
- * check == \c false, \a old2NewBg is used as is, that is less secure as validity
- * of ids in \a old2NewBg is not checked.
- * \throw If the mesh is not set.
- * \throw If the spatial discretization of \a this field is NULL.
- * \throw If \a check == \c true and \a old2NewBg contains equal ids.
- * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
- *
- * \if ENABLE_EXAMPLES
- * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
- * \ref py_mcfielddouble_renumberCells "Here is a Python example".
- * \endif
- */
-void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check)
-{
- renumberCellsWithoutMesh(old2NewBg,check);
- MCAuto<MEDCouplingMesh> m=_mesh->deepCopy();
- m->renumberCells(old2NewBg,check);
- setMesh(m);
- updateTime();
-}
-
-/*!
- * Permutes values of \a this field according to a given permutation array for cells
- * renumbering. The underlying mesh is \b not permuted.
- * The number of cells remains the same; for that the permutation array \a old2NewBg
- * should not contain equal ids.
- * This method performs a part of job of renumberCells(). The reasonable use of this
- * method is only for multi-field instances lying on the same mesh to avoid a
- * systematic duplication and renumbering of _mesh attribute.
- * \warning Use this method with a lot of care!
- * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
- * to be equal to \a this->getMesh()->getNumberOfCells().
- * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
- * array, so that its maximal cell id to correspond to (be less than) the number
- * of cells in mesh. This new array is then used for the renumbering. If \a
- * check == \c false, \a old2NewBg is used as is, that is less secure as validity
- * of ids in \a old2NewBg is not checked.
- * \throw If the mesh is not set.
- * \throw If the spatial discretization of \a this field is NULL.
- * \throw If \a check == \c true and \a old2NewBg contains equal ids.
- * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
- */
-void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
-{
- if(!_mesh)
- throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
- if(_type.isNull())
- throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
- //
- _type->renumberCells(old2NewBg,check);
- std::vector<DataArrayDouble *> arrays;
- timeDiscr()->getArrays(arrays);
- std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
- _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
- //
- updateTime();
-}
-
/*!
* Permutes values of \a this field according to a given permutation array for node
* renumbering. The underlying mesh is deeply copied and its nodes are also permuted.
MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) const;
MEDCOUPLING_EXPORT bool areCompatibleForMerge(const MEDCouplingField *other) const;
MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const;
- MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true);
- MEDCOUPLING_EXPORT void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true);
MEDCOUPLING_EXPORT void renumberNodes(const int *old2NewBg, double eps=1e-15);
MEDCOUPLING_EXPORT void renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps=1e-15);
MEDCOUPLING_EXPORT DataArrayInt *findIdsInRange(double vmin, double vmax) const;
MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const;
MEDCOUPLING_EXPORT std::string simpleRepr() const;
MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true);
+ MEDCOUPLING_EXPORT void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true);
// specific
MEDCOUPLING_EXPORT bool areCompatibleForMul(const MEDCouplingField *other) const;
MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const;
timeDiscrSafe()->getArrays(arrays);
_type->getSerializationIntArray(dataInt);
}
+
+ /*!
+ * Permutes values of \a this field according to a given permutation array for cells
+ * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
+ * The number of cells remains the same; for that the permutation array \a old2NewBg
+ * should not contain equal ids.
+ * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
+ *
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfCells().
+ * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
+ * array, so that its maximal cell id to correspond to (be less than) the number
+ * of cells in mesh. This new array is then used for the renumbering. If \a
+ * check == \c false, \a old2NewBg is used as is, that is less secure as validity
+ * of ids in \a old2NewBg is not checked.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If \a check == \c true and \a old2NewBg contains equal ids.
+ * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
+ * \ref py_mcfielddouble_renumberCells "Here is a Python example".
+ * \endif
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::renumberCells(const int *old2NewBg, bool check)
+ {
+ renumberCellsWithoutMesh(old2NewBg,check);
+ MCAuto<MEDCouplingMesh> m(_mesh->deepCopy());
+ m->renumberCells(old2NewBg,check);
+ setMesh(m);
+ updateTime();
+ }
+
+ /*!
+ * Permutes values of \a this field according to a given permutation array for cells
+ * renumbering. The underlying mesh is \b not permuted.
+ * The number of cells remains the same; for that the permutation array \a old2NewBg
+ * should not contain equal ids.
+ * This method performs a part of job of renumberCells(). The reasonable use of this
+ * method is only for multi-field instances lying on the same mesh to avoid a
+ * systematic duplication and renumbering of _mesh attribute.
+ * \warning Use this method with a lot of care!
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfCells().
+ * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
+ * array, so that its maximal cell id to correspond to (be less than) the number
+ * of cells in mesh. This new array is then used for the renumbering. If \a
+ * check == \c false, \a old2NewBg is used as is, that is less secure as validity
+ * of ids in \a old2NewBg is not checked.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If \a check == \c true and \a old2NewBg contains equal ids.
+ * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
+ {
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
+ if(_type.isNull())
+ throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
+ //
+ _type->renumberCells(old2NewBg,check);
+ std::vector<typename Traits<T>::ArrayType *> arrays;
+ _time_discr->getArrays(arrays);
+ std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
+ _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
+ //
+ updateTime();
+ }
}
#endif
#include "MEDFileSafeCaller.txx"
#include "MEDFileMesh.hxx"
#include "MEDFileField.hxx"
+#include "MEDLoaderTraits.hxx"
#include "CellModel.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldFloat.hxx"
+#include "MEDCouplingFieldInt.hxx"
#include "MEDCouplingGaussLocalization.hxx"
+#include "MEDCouplingTraits.hxx"
#include "MCAuto.hxx"
#include "InterpKernelAutoPtr.hxx"
WriteField(fileName,f,writeFromScratch);
}
-void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
+template<class T>
+void WriteFieldUsingAlreadyWrittenMeshImpl(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
{
if(!f)
throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
f->checkConsistencyLight();
- int status=MEDLoaderBase::getStatusOfFile(fileName);
+ int status(MEDLoaderBase::getStatusOfFile(fileName));
if(status!=MEDLoaderBase::EXIST_RW)
{
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ MCAuto< typename MEDCoupling::MLFieldTraits<T>::F1TSType > f1ts(MEDCoupling::MLFieldTraits<T>::F1TSType::New());
AssignStaticWritePropertiesTo(*f1ts);
MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
if(m)
{
MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
- MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
+ MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
f2->renumberCells(o2n->begin(),false);
f1ts->setFieldNoProfileSBT(f2);
}
f1ts->setFieldNoProfileSBT(f);
f1ts->write(fileName,0);
}
+
+void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
+{
+ const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
+ if(f1)
+ {
+ WriteFieldUsingAlreadyWrittenMeshImpl<double>(fileName,f1);
+ return ;
+ }
+ const MEDCoupling::MEDCouplingFieldInt *f2(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
+ if(f2)
+ {
+ WriteFieldUsingAlreadyWrittenMeshImpl<int>(fileName,f2);
+ return ;
+ }
+ const MEDCoupling::MEDCouplingFieldFloat *f3(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
+ if(f3)
+ {
+ WriteFieldUsingAlreadyWrittenMeshImpl<float>(fileName,f3);
+ return ;
+ }
+ WriteFieldUsingAlreadyWrittenMeshImpl<double>(fileName,NULL);
+}
+
class DataArrayInt;
class MEDCouplingMesh;
class MEDCouplingUMesh;
+ class MEDCouplingField;
class MEDCouplingFieldDouble;
class MEDFileWritable;
MEDLOADER_EXPORT void WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch);
MEDLOADER_EXPORT void WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch);
MEDLOADER_EXPORT void WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch);
- MEDLOADER_EXPORT void WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f);
+ MEDLOADER_EXPORT void WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f);
MEDLOADER_EXPORT void AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj);
}
void WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
void WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
void WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
- void WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
+ void WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f) throw(INTERP_KERNEL::Exception);
}
%rename (MEDFileVersion) MEDFileVersionSwig;