#include "vtkIdTypeArray.h"
#include "vtkDoubleArray.h"
#include "vtkIntArray.h"
+#include "vtkFloatArray.h"
#include "vtkCellArray.h"
#include "vtkPointData.h"
#include "vtkFieldData.h"
const char MEDFileFieldRepresentationTree::COMPO_STR_TO_LOCATE_MESH_DA[]="-@?|*_";
-vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew, ExportedTinyInfo *internalInfo) const
+template<class T>
+vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd, vtkDataSet *ds, bool& isNew, ExportedTinyInfo *internalInfo) const
{
vtkIdTypeArray *try0(isExisting(locsReallyUsed,vtkd));
if(try0)
else
{
isNew=true;
- return createNew(globs,locsReallyUsed,vtkd,ds,internalInfo);
+ return createNew<T>(globs,locsReallyUsed,vtkd,ds,internalInfo);
}
}
-vtkIdTypeArray *ELGACmp::isExisting(const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd) const
+vtkIdTypeArray *ELGACmp::isExisting(const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd) const
{
std::vector< std::vector<std::string> >::iterator it(std::find(_loc_names.begin(),_loc_names.end(),locsReallyUsed));
if(it==_loc_names.end())
return ret;
}
-vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const
+template<class T>
+vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const
{
- const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
+ const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<T>::VTK_DATA_ARRAY_DELETE;
std::vector< std::vector<std::string> > locNames(_loc_names);
std::vector<vtkIdTypeArray *> elgas(_elgas);
std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > defs;
typedef MEDCoupling::DataArrayInt MCType;
};
+template<>
+class MEDFileVTKTraits<float>
+{
+public:
+ typedef vtkFloatArray VtkType;
+ typedef MEDCoupling::DataArrayFloat MCType;
+};
+
template<>
class MEDFileVTKTraits<double>
{
mcTab->accessToMemArray().setSpecificDeallocator(0);
}
+template<class T>
+void AssignToFieldData(DataArray *vPtr, const MEDTimeReq *tr, vtkFieldData *att, const std::string& crudeName, bool noCpyNumNodes,
+ const std::vector<TypeOfField>& discs, const ELGACmp& elgaCmp, const MEDCoupling::MEDFileFieldGlobsReal *globs,
+ MEDFileAnyTypeField1TS *f1ts, vtkDataSet *ds, ExportedTinyInfo *internalInfo)
+{
+ const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<T>::VTK_DATA_ARRAY_DELETE;
+ typename MEDFileVTKTraits<T>::MCType *vi(static_cast<typename MEDFileVTKTraits<T>::MCType *>(vPtr));
+ typename MEDFileVTKTraits<T>::VtkType *vtkd(MEDFileVTKTraits<T>::VtkType::New());
+ vtkd->SetNumberOfComponents(vi->getNumberOfComponents());
+ for(int i=0;i<vi->getNumberOfComponents();i++)
+ vtkd->SetComponentName(i,vi->getVarOnComponent(i).c_str());
+ AssignDataPointerToVTK<T>(vtkd,vi,noCpyNumNodes);
+ std::string name(tr->buildName(crudeName));
+ vtkd->SetName(name.c_str());
+ att->AddArray(vtkd);
+ vtkd->Delete();
+ if(discs[0]==ON_GAUSS_PT)
+ {
+ bool tmp;
+ elgaCmp.findOrCreate<T>(globs,f1ts->getLocsReallyUsed(),vtkd,ds,tmp,internalInfo);
+ }
+ if(discs[0]==ON_GAUSS_NE)
+ {
+ vtkIdTypeArray *elno(vtkIdTypeArray::New());
+ elno->SetNumberOfComponents(1);
+ vtkIdType ncell(ds->GetNumberOfCells());
+ int *pt(new int[ncell]),offset(0);
+ std::set<int> cellTypes;
+ for(vtkIdType cellId=0;cellId<ncell;cellId++)
+ {
+ vtkCell *cell(ds->GetCell(cellId));
+ int delta(cell->GetNumberOfPoints());
+ cellTypes.insert(cell->GetCellType());
+ pt[cellId]=offset;
+ offset+=delta;
+ }
+ elno->GetInformation()->Set(MEDUtilities::ELNO(),1);
+ elno->SetVoidArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE);
+ std::string nameElno("ELNO"); nameElno+="@"; nameElno+=name;
+ elno->SetName(nameElno.c_str());
+ ds->GetCellData()->AddArray(elno);
+ vtkd->GetInformation()->Set(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME(),elno->GetName());
+ elno->GetInformation()->Set(vtkAbstractArray::GUI_HIDE(),1);
+ //
+ vtkInformationQuadratureSchemeDefinitionVectorKey *key(vtkQuadratureSchemeDefinition::DICTIONARY());
+ for(std::set<int>::const_iterator it=cellTypes.begin();it!=cellTypes.end();it++)
+ {
+ const unsigned char *pos(std::find(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH,*it));
+ if(pos==MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH)
+ continue;
+ INTERP_KERNEL::NormalizedCellType ct((INTERP_KERNEL::NormalizedCellType)std::distance(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,pos));
+ const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(ct));
+ int nbGaussPt(cm.getNumberOfNodes()),dim(cm.getDimension());
+ vtkQuadratureSchemeDefinition *def(vtkQuadratureSchemeDefinition::New());
+ double *shape(new double[nbGaussPt*nbGaussPt]);
+ std::size_t dummy;
+ const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));//GetLocsFromGeometricType
+ const double *refCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));
+ const double *weights(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(ct,dummy));
+ std::vector<double> gsCoords2(gsCoords,gsCoords+nbGaussPt*dim),refCoords2(refCoords,refCoords+nbGaussPt*dim);
+ INTERP_KERNEL::GaussInfo calculator(ct,gsCoords2,nbGaussPt,refCoords2,nbGaussPt);
+ calculator.initLocalInfo();
+ for(int i=0;i<nbGaussPt;i++)
+ {
+ const double *pt0(calculator.getFunctionValues(i));
+ std::copy(pt0,pt0+nbGaussPt,shape+nbGaussPt*i);
+ }
+ def->Initialize(*it,nbGaussPt,nbGaussPt,shape,const_cast<double *>(weights));
+ delete [] shape;
+ key->Set(elno->GetInformation(),def,*it);
+ key->Set(vtkd->GetInformation(),def,*it);
+ def->Delete();
+ }
+ //
+ elno->Delete();
+ }
+}
+
//=
MEDFileFieldRepresentationLeavesArrays::MEDFileFieldRepresentationLeavesArrays():_id(-1)
MEDFileAnyTypeField1TS *f1tsPtr(f1ts);
MEDFileField1TS *f1tsPtrDbl(dynamic_cast<MEDFileField1TS *>(f1tsPtr));
MEDFileIntField1TS *f1tsPtrInt(dynamic_cast<MEDFileIntField1TS *>(f1tsPtr));
+ MEDFileFloatField1TS *f1tsPtrFloat(dynamic_cast<MEDFileFloatField1TS *>(f1tsPtr));
DataArray *crudeArr(0),*postProcessedArr(0);
if(f1tsPtrDbl)
crudeArr=f1tsPtrDbl->getUndergroundDataArray();
else if(f1tsPtrInt)
crudeArr=f1tsPtrInt->getUndergroundDataArray();
+ else if(f1tsPtrFloat)
+ crudeArr=f1tsPtrFloat->getUndergroundDataArray();
else
- throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeavesArrays::appendFields : only FLOAT64 and INT32 fields are dealt for the moment !");
+ throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeavesArrays::appendFields : only FLOAT64, FLOAT32 and INT32 fields are dealt for the moment !");
MEDFileField1TSStructItem fsst(MEDFileField1TSStructItem::BuildItemFrom(f1ts,mst));
f1ts->loadArraysIfNecessary();
MCAuto<DataArray> v(mml->buildDataArray(fsst,globs,crudeArr));
}
if(f1tsPtrDbl)
{
- DataArray *vPtr(v); DataArrayDouble *vd(static_cast<DataArrayDouble *>(vPtr));
- vtkDoubleArray *vtkd(vtkDoubleArray::New());
- vtkd->SetNumberOfComponents(vd->getNumberOfComponents());
- for(int i=0;i<vd->getNumberOfComponents();i++)
- vtkd->SetComponentName(i,vd->getInfoOnComponent(i).c_str());
- AssignDataPointerToVTK<double>(vtkd,vd,postProcessedArr==crudeArr);
- std::string name(tr->buildName(f1ts->getName()));
- vtkd->SetName(name.c_str());
- att->AddArray(vtkd);
- vtkd->Delete();
- if(discs[0]==ON_GAUSS_PT)
- {
- bool tmp;
- _elga_cmp.findOrCreate(globs,f1ts->getLocsReallyUsed(),vtkd,ds,tmp,internalInfo);
- }
- if(discs[0]==ON_GAUSS_NE)
- {
- vtkIdTypeArray *elno(vtkIdTypeArray::New());
- elno->SetNumberOfComponents(1);
- vtkIdType ncell(ds->GetNumberOfCells());
- int *pt(new int[ncell]),offset(0);
- std::set<int> cellTypes;
- for(vtkIdType cellId=0;cellId<ncell;cellId++)
- {
- vtkCell *cell(ds->GetCell(cellId));
- int delta(cell->GetNumberOfPoints());
- cellTypes.insert(cell->GetCellType());
- pt[cellId]=offset;
- offset+=delta;
- }
- elno->GetInformation()->Set(MEDUtilities::ELNO(),1);
- elno->SetVoidArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE);
- std::string nameElno("ELNO"); nameElno+="@"; nameElno+=name;
- elno->SetName(nameElno.c_str());
- ds->GetCellData()->AddArray(elno);
- vtkd->GetInformation()->Set(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME(),elno->GetName());
- elno->GetInformation()->Set(vtkAbstractArray::GUI_HIDE(),1);
- //
- vtkInformationQuadratureSchemeDefinitionVectorKey *key(vtkQuadratureSchemeDefinition::DICTIONARY());
- for(std::set<int>::const_iterator it=cellTypes.begin();it!=cellTypes.end();it++)
- {
- const unsigned char *pos(std::find(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH,*it));
- if(pos==MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH)
- continue;
- INTERP_KERNEL::NormalizedCellType ct((INTERP_KERNEL::NormalizedCellType)std::distance(MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,pos));
- const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(ct));
- int nbGaussPt(cm.getNumberOfNodes()),dim(cm.getDimension());
- vtkQuadratureSchemeDefinition *def(vtkQuadratureSchemeDefinition::New());
- double *shape(new double[nbGaussPt*nbGaussPt]);
- std::size_t dummy;
- const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));//GetLocsFromGeometricType
- const double *refCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));
- const double *weights(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(ct,dummy));
- std::vector<double> gsCoords2(gsCoords,gsCoords+nbGaussPt*dim),refCoords2(refCoords,refCoords+nbGaussPt*dim);
- INTERP_KERNEL::GaussInfo calculator(ct,gsCoords2,nbGaussPt,refCoords2,nbGaussPt);
- calculator.initLocalInfo();
- for(int i=0;i<nbGaussPt;i++)
- {
- const double *pt0(calculator.getFunctionValues(i));
- std::copy(pt0,pt0+nbGaussPt,shape+nbGaussPt*i);
- }
- def->Initialize(*it,nbGaussPt,nbGaussPt,shape,const_cast<double *>(weights));
- delete [] shape;
- key->Set(elno->GetInformation(),def,*it);
- key->Set(vtkd->GetInformation(),def,*it);
- def->Delete();
- }
- //
- elno->Delete();
- }
+ AssignToFieldData<double>(v,tr,att,f1ts->getName(),postProcessedArr==crudeArr,discs,_elga_cmp,globs,f1ts,ds,internalInfo);
}
else if(f1tsPtrInt)
{
- DataArray *vPtr(v); DataArrayInt *vi(static_cast<DataArrayInt *>(vPtr));
- vtkIntArray *vtkd(vtkIntArray::New());
- vtkd->SetNumberOfComponents(vi->getNumberOfComponents());
- for(int i=0;i<vi->getNumberOfComponents();i++)
- vtkd->SetComponentName(i,vi->getVarOnComponent(i).c_str());
- AssignDataPointerToVTK<int>(vtkd,vi,postProcessedArr==crudeArr);
- std::string name(tr->buildName(f1ts->getName()));
- vtkd->SetName(name.c_str());
- att->AddArray(vtkd);
- vtkd->Delete();
+ AssignToFieldData<int>(v,tr,att,f1ts->getName(),postProcessedArr==crudeArr,discs,_elga_cmp,globs,f1ts,ds,internalInfo);
+ }
+ else if(f1tsPtrFloat)
+ {
+ AssignToFieldData<float>(v,tr,att,f1ts->getName(),postProcessedArr==crudeArr,discs,_elga_cmp,globs,f1ts,ds,internalInfo);
}
else
throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeavesArrays::appendFields : only FLOAT64 and INT32 fields are dealt for the moment ! Internal Error !");
#include "MEDFileData.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingRefCountObject.hxx"
+#include "MEDLoaderTraits.hxx"
#include <map>
#include <deque>
using MEDCoupling::MEDFileAnyTypeFieldMultiTS;
using MEDCoupling::DataArray;
using MEDCoupling::DataArrayInt;
+using MEDCoupling::DataArrayFloat;
using MEDCoupling::DataArrayDouble;
using MEDCoupling::MEDCouplingMesh;
using MEDCoupling::MEDCouplingUMesh;
using MEDCoupling::MEDCouplingCMesh;
using MEDCoupling::MEDCouplingFieldDouble;
+using MEDCoupling::MEDCouplingFieldFloat;
using MEDCoupling::MEDCouplingFieldInt;
using MEDCoupling::MCAuto;
+using MEDCoupling::Traits;
+using MEDCoupling::MLFieldTraits;
vtkStandardNewMacro(vtkMEDWriter);
std::string _reason;
};
+template<class T>
+class MEDFileVTKTraits
+{
+public:
+ typedef void VtkType;
+ typedef void MCType;
+};
+
+template<>
+class MEDFileVTKTraits<int>
+{
+public:
+ typedef vtkIntArray VtkType;
+ typedef MEDCoupling::DataArrayInt MCType;
+};
+
+template<>
+class MEDFileVTKTraits<float>
+{
+public:
+ typedef vtkFloatArray VtkType;
+ typedef MEDCoupling::DataArrayFloat MCType;
+};
+
+template<>
+class MEDFileVTKTraits<double>
+{
+public:
+ typedef vtkDoubleArray VtkType;
+ typedef MEDCoupling::DataArrayDouble MCType;
+};
+
///////////////////
std::map<int,int> ComputeMapOfType()
throw MZCException(oss.str());
}
-DataArrayDouble *ConvertVTKArrayToMCArrayDouble(vtkDataArray *data)
+template<class T>
+typename Traits<T>::ArrayType *ConvertVTKArrayToMCArrayDouble(vtkDataArray *data)
{
if(!data)
throw MZCException("ConvertVTKArrayToMCArrayDouble : internal error !");
int nbTuples(data->GetNumberOfTuples()),nbComp(data->GetNumberOfComponents());
std::size_t nbElts(nbTuples*nbComp);
- MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
+ MCAuto< typename Traits<T>::ArrayType > ret(Traits<T>::ArrayType::New());
ret->alloc(nbTuples,nbComp);
for(int i=0;i<nbComp;i++)
{
const char *comp(data->GetComponentName(i));
if(comp)
ret->setInfoOnComponent(i,comp);
+ else
+ {
+ if(nbComp>1 && nbComp<=3)
+ {
+ char tmp[2];
+ tmp[0]='X'+i; tmp[1]='\0';
+ ret->setInfoOnComponent(i,tmp);
+ }
+ }
}
- double *ptOut(ret->getPointer());
- vtkFloatArray *d0(vtkFloatArray::SafeDownCast(data));
+ T *ptOut(ret->getPointer());
+ typename MEDFileVTKTraits<T>::VtkType *d0(MEDFileVTKTraits<T>::VtkType::SafeDownCast(data));
if(d0)
{
- const float *pt(d0->GetPointer(0));
+ const T *pt(d0->GetPointer(0));
for(std::size_t i=0;i<nbElts;i++)
- ptOut[i]=pt[i];
- return ret.retn();
- }
- vtkDoubleArray *d1(vtkDoubleArray::SafeDownCast(data));
- if(d1)
- {
- const double *pt(d1->GetPointer(0));
- std::copy(pt,pt+nbElts,ptOut);
+ ptOut[i]=(T)pt[i];
return ret.retn();
}
std::ostringstream oss;
- oss << "ConvertVTKArrayToMCArrayDouble : unrecognized array \"" << typeid(*data).name() << "\" type !";
+ oss << "ConvertVTKArrayToMCArrayDouble : unrecognized array \"" << data->GetClassName() << "\" type !";
throw MZCException(oss.str());
}
+DataArrayDouble *ConvertVTKArrayToMCArrayDoubleForced(vtkDataArray *data)
+{
+ if(!data)
+ throw MZCException("ConvertVTKArrayToMCArrayDoubleForced : internal error 0 !");
+ vtkFloatArray *d0(vtkFloatArray::SafeDownCast(data));
+ if(d0)
+ {
+ MCAuto<DataArrayFloat> ret(ConvertVTKArrayToMCArrayDouble<float>(data));
+ MCAuto<DataArrayDouble> ret2(ret->convertToDblArr());
+ return ret2.retn();
+ }
+ vtkDoubleArray *d1(vtkDoubleArray::SafeDownCast(data));
+ if(d1)
+ return ConvertVTKArrayToMCArrayDouble<double>(data);
+ throw MZCException("ConvertVTKArrayToMCArrayDoubleForced : unrecognized type of data for double !");
+}
+
DataArray *ConvertVTKArrayToMCArray(vtkDataArray *data)
{
if(!data)
throw MZCException("ConvertVTKArrayToMCArray : internal error !");
vtkFloatArray *d0(vtkFloatArray::SafeDownCast(data));
+ if(d0)
+ return ConvertVTKArrayToMCArrayDouble<float>(data);
vtkDoubleArray *d1(vtkDoubleArray::SafeDownCast(data));
- if(d0 || d1)
- return ConvertVTKArrayToMCArrayDouble(data);
+ if(d1)
+ return ConvertVTKArrayToMCArrayDouble<double>(data);
vtkIntArray *d2(vtkIntArray::SafeDownCast(data));
vtkLongArray *d3(vtkLongArray::SafeDownCast(data));
vtkUnsignedCharArray *d4(vtkUnsignedCharArray::SafeDownCast(data));
_m=MEDCouplingUMesh::MergeUMeshesOnSameCoords(vs2);
}
-void AppendMCFieldFrom(MEDCoupling::TypeOfField tf, MEDCouplingMesh *mesh, MEDFileData *mfd, MCAuto<DataArray> da, const DataArrayInt *n2oPtr)
+template<class T>
+void AppendToFields(MEDCoupling::TypeOfField tf, MEDCouplingMesh *mesh, const DataArrayInt *n2oPtr, typename MEDFileVTKTraits<T>::MCType *dadPtr, MEDFileFields *fs, double timeStep, int tsId)
+{
+ std::string fieldName(dadPtr->getName());
+ MCAuto< typename Traits<T>::FieldType > f(Traits<T>::FieldType::New(tf));
+ f->setTime(timeStep,tsId,0);
+ f->setName(fieldName);
+ if(!n2oPtr)
+ f->setArray(dadPtr);
+ else
+ {
+ MCAuto< typename Traits<T>::ArrayType > dad2(dadPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
+ f->setArray(dad2);
+ }
+ f->setMesh(mesh);
+ MCAuto< typename MLFieldTraits<T>::FMTSType > fmts(MLFieldTraits<T>::FMTSType::New());
+ MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
+ f1ts->setFieldNoProfileSBT(f);
+ fmts->pushBackTimeStep(f1ts);
+ fs->pushField(fmts);
+}
+
+void AppendMCFieldFrom(MEDCoupling::TypeOfField tf, MEDCouplingMesh *mesh, MEDFileData *mfd, MCAuto<DataArray> da, const DataArrayInt *n2oPtr, double timeStep, int tsId)
{
static const char FAMFIELD_FOR_CELLS[]="FamilyIdCell";
static const char FAMFIELD_FOR_NODES[]="FamilyIdNode";
if(!fs || !ms)
throw MZCException("AppendMCFieldFrom : internal error 2 !");
MCAuto<DataArrayDouble> dad(MEDCoupling::DynamicCast<DataArray,DataArrayDouble>(da));
- DataArrayDouble *dadPtr(dad);
- std::string fieldName;
- if(dadPtr)
+ if(dad.isNotNull())
{
- fieldName=dadPtr->getName();
- MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(tf));
- f->setName(fieldName);
- if(!n2oPtr)
- f->setArray(dadPtr);
- else
- {
- MCAuto<DataArrayDouble> dad2(dadPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
- f->setArray(dad2);
- }
- f->setMesh(mesh);
- MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
- MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
- f1ts->setFieldNoProfileSBT(f);
- fmts->pushBackTimeStep(f1ts);
- fs->pushField(fmts);
+ AppendToFields<double>(tf,mesh,n2oPtr,dad,fs,timeStep,tsId);
+ return ;
+ }
+ MCAuto<DataArrayFloat> daf(MEDCoupling::DynamicCast<DataArray,DataArrayFloat>(da));
+ if(daf.isNotNull())
+ {
+ AppendToFields<float>(tf,mesh,n2oPtr,daf,fs,timeStep,tsId);
return ;
}
MCAuto<DataArrayInt> dai(MEDCoupling::DynamicCast<DataArray,DataArrayInt>(da));
- DataArrayInt *daiPtr(dai);
- if(daiPtr)
+ if(dai.isNotNull())
{
- fieldName=daiPtr->getName();
+ std::string fieldName(dai->getName());
if((fieldName!=FAMFIELD_FOR_CELLS || tf!=MEDCoupling::ON_CELLS) && (fieldName!=FAMFIELD_FOR_NODES || tf!=MEDCoupling::ON_NODES))
{
- MCAuto<MEDCouplingFieldInt> f(MEDCouplingFieldInt::New(tf));
- f->setName(fieldName);
- f->setMesh(mesh);
- MCAuto<MEDFileIntFieldMultiTS> fmts(MEDFileIntFieldMultiTS::New());
- MCAuto<MEDFileIntField1TS> f1ts(MEDFileIntField1TS::New());
- if(!n2oPtr)
- {
- f->setArray(dai);
- f1ts->setFieldNoProfileSBT(f);
- }
- else
- {
- MCAuto<DataArrayInt> dai2(daiPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
- f->setArray(dai2);
- f1ts->setFieldNoProfileSBT(f);
- }
- fmts->pushBackTimeStep(f1ts);
- fs->pushField(fmts);
+ AppendToFields<int>(tf,mesh,n2oPtr,dai,fs,timeStep,tsId);
return ;
}
else if(fieldName==FAMFIELD_FOR_CELLS && tf==MEDCoupling::ON_CELLS)
if(!mm)
throw MZCException("AppendMCFieldFrom : internal error 3 !");
if(!n2oPtr)
- mm->setFamilyFieldArr(mesh->getMeshDimension()-mm->getMeshDimension(),daiPtr);
+ mm->setFamilyFieldArr(mesh->getMeshDimension()-mm->getMeshDimension(),dai);
else
{
- MCAuto<DataArrayInt> dai2(daiPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
+ MCAuto<DataArrayInt> dai2(dai->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
mm->setFamilyFieldArr(mesh->getMeshDimension()-mm->getMeshDimension(),dai2);
}
}
if(!mm)
throw MZCException("AppendMCFieldFrom : internal error 4 !");
if(!n2oPtr)
- mm->setFamilyFieldArr(1,daiPtr);
+ mm->setFamilyFieldArr(1,dai);
else
{
- MCAuto<DataArrayInt> dai2(daiPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
+ MCAuto<DataArrayInt> dai2(dai->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
mm->setFamilyFieldArr(1,dai2);
}
}
}
}
-void PutAtLevelDealOrder(MEDFileData *mfd, int meshDimRel, const MicroField& mf)
+void PutAtLevelDealOrder(MEDFileData *mfd, int meshDimRel, const MicroField& mf, double timeStep, int tsId)
{
if(!mfd)
throw MZCException("PutAtLevelDealOrder : internal error !");
for(std::vector<MCAuto<DataArray> >::const_iterator it=cells.begin();it!=cells.end();it++)
{
MCAuto<DataArray> da(*it);
- AppendMCFieldFrom(MEDCoupling::ON_CELLS,mesh,mfd,da,n2oPtr);
+ AppendMCFieldFrom(MEDCoupling::ON_CELLS,mesh,mfd,da,n2oPtr,timeStep,tsId);
}
}
-void AssignSingleGTMeshes(MEDFileData *mfd, const std::vector< MicroField >& ms)
+void AssignSingleGTMeshes(MEDFileData *mfd, const std::vector< MicroField >& ms, double timeStep, int tsId)
{
if(!mfd)
throw MZCException("AssignSingleGTMeshes : internal error !");
const std::vector< MicroField >& vs((*it).second);
if(vs.size()==1)
{
- PutAtLevelDealOrder(mfd,(*it).first-meshDim,vs[0]);
+ PutAtLevelDealOrder(mfd,(*it).first-meshDim,vs[0],timeStep,tsId);
}
else
{
MicroField merge(vs);
- PutAtLevelDealOrder(mfd,(*it).first-meshDim,merge);
+ PutAtLevelDealOrder(mfd,(*it).first-meshDim,merge,timeStep,tsId);
}
}
}
vtkDataArray *data(pts->GetData());
if(!data)
throw MZCException("BuildCoordsFrom : internal error 3 !");
- MCAuto<DataArrayDouble> coords(ConvertVTKArrayToMCArrayDouble(data));
- return coords.retn();
+ return ConvertVTKArrayToMCArrayDoubleForced(data);
}
-void AddNodeFields(MEDFileData *mfd, vtkDataSetAttributes *dsa)
+void AddNodeFields(MEDFileData *mfd, vtkDataSetAttributes *dsa, double timeStep, int tsId)
{
if(!mfd || !dsa)
throw MZCException("AddNodeFields : internal error !");
continue;
MCAuto<DataArray> da(ConvertVTKArrayToMCArray(arr));
da->setName(name);
- AppendMCFieldFrom(MEDCoupling::ON_NODES,mesh,mfd,da,0);
+ AppendMCFieldFrom(MEDCoupling::ON_NODES,mesh,mfd,da,NULL,timeStep,tsId);
}
}
return ret;
}
-void ConvertFromRectilinearGrid(MEDFileData *ret, vtkRectilinearGrid *ds, const std::vector<int>& context)
+void ConvertFromRectilinearGrid(MEDFileData *ret, vtkRectilinearGrid *ds, const std::vector<int>& context, double timeStep, int tsId)
{
if(!ds || !ret)
throw MZCException("ConvertFromRectilinearGrid : internal error !");
vtkDataArray *cx(ds->GetXCoordinates()),*cy(ds->GetYCoordinates()),*cz(ds->GetZCoordinates());
if(cx)
{
- MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDouble(cx));
+ MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDoubleForced(cx));
cmeshmc->setCoordsAt(0,arr);
}
if(cy)
{
- MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDouble(cy));
+ MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDoubleForced(cy));
cmeshmc->setCoordsAt(1,arr);
}
if(cz)
{
- MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDouble(cz));
+ MCAuto<DataArrayDouble> arr(ConvertVTKArrayToMCArrayDoubleForced(cz));
cmeshmc->setCoordsAt(2,arr);
}
std::string meshName(GetMeshNameWithContext(context));
for(std::vector<MCAuto<DataArray> >::const_iterator it=cellFs.begin();it!=cellFs.end();it++)
{
MCAuto<DataArray> da(*it);
- AppendMCFieldFrom(MEDCoupling::ON_CELLS,cmeshmc,ret,da,0);
+ AppendMCFieldFrom(MEDCoupling::ON_CELLS,cmeshmc,ret,da,NULL,timeStep,tsId);
}
std::vector<MCAuto<DataArray> > nodeFs(AddPartFields(0,ds->GetPointData()));
for(std::vector<MCAuto<DataArray> >::const_iterator it=nodeFs.begin();it!=nodeFs.end();it++)
{
MCAuto<DataArray> da(*it);
- AppendMCFieldFrom(MEDCoupling::ON_NODES,cmeshmc,ret,da,0);
+ AppendMCFieldFrom(MEDCoupling::ON_NODES,cmeshmc,ret,da,NULL,timeStep,tsId);
}
}
-void ConvertFromPolyData(MEDFileData *ret, vtkPolyData *ds, const std::vector<int>& context)
+void ConvertFromPolyData(MEDFileData *ret, vtkPolyData *ds, const std::vector<int>& context, double timeStep, int tsId)
{
if(!ds || !ret)
throw MZCException("ConvertFromPolyData : internal error !");
ms.push_back(MicroField(subMesh,cellFs));
}
}
- AssignSingleGTMeshes(ret,ms);
- AddNodeFields(ret,ds->GetPointData());
+ AssignSingleGTMeshes(ret,ms,timeStep,tsId);
+ AddNodeFields(ret,ds->GetPointData(),timeStep,tsId);
}
-void ConvertFromUnstructuredGrid(MEDFileData *ret, vtkUnstructuredGrid *ds, const std::vector<int>& context)
+void ConvertFromUnstructuredGrid(MEDFileData *ret, vtkUnstructuredGrid *ds, const std::vector<int>& context, double timeStep, int tsId)
{
if(!ds || !ret)
throw MZCException("ConvertFromUnstructuredGrid : internal error !");
std::vector<MCAuto<DataArray> > cellFs(AddPartFields(cellIdsCurLev,ds->GetCellData()));
ms.push_back(MicroField(m0,cellFs));
}
- AssignSingleGTMeshes(ret,ms);
- AddNodeFields(ret,ds->GetPointData());
+ AssignSingleGTMeshes(ret,ms,timeStep,tsId);
+ AddNodeFields(ret,ds->GetPointData(),timeStep,tsId);
}
///////////////////
-vtkMEDWriter::vtkMEDWriter():WriteAllTimeSteps(0),FileName(0),IsTouched(false)
+vtkMEDWriter::vtkMEDWriter():WriteAllTimeSteps(0),NumberOfTimeSteps(0),CurrentTimeIndex(0),FileName(0)
{
}
int vtkMEDWriter::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
//std::cerr << "########################################## vtkMEDWriter::RequestInformation ########################################## " << (const char *) this->FileName << std::endl;
+ vtkInformation *inInfo(inputVector[0]->GetInformationObject(0));
+ if(inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
+ this->NumberOfTimeSteps=inInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
+ else
+ this->NumberOfTimeSteps=0;
+ return 1;
+}
+
+int vtkMEDWriter::RequestUpdateExtent(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* vtkNotUsed(outputVector))
+{
+ double *inTimes(inputVector[0]->GetInformationObject(0)->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS()));
+ if(inTimes && this->WriteAllTimeSteps)
+ {
+ double timeReq(inTimes[this->CurrentTimeIndex]);
+ inputVector[0]->GetInformationObject(0)->Set(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(),timeReq);
+ }
return 1;
}
-void WriteMEDFileFromVTKDataSet(MEDFileData *mfd, vtkDataSet *ds, const std::vector<int>& context)
+void WriteMEDFileFromVTKDataSet(MEDFileData *mfd, vtkDataSet *ds, const std::vector<int>& context, double timeStep, int tsId)
{
if(!ds || !mfd)
throw MZCException("Internal error in WriteMEDFileFromVTKDataSet.");
vtkRectilinearGrid *ds4(vtkRectilinearGrid::SafeDownCast(ds));
if(ds2)
{
- ConvertFromPolyData(mfd,ds2,context);
+ ConvertFromPolyData(mfd,ds2,context,timeStep,tsId);
}
else if(ds3)
{
- ConvertFromUnstructuredGrid(mfd,ds3,context);
+ ConvertFromUnstructuredGrid(mfd,ds3,context,timeStep,tsId);
}
else if(ds4)
{
- ConvertFromRectilinearGrid(mfd,ds4,context);
+ ConvertFromRectilinearGrid(mfd,ds4,context,timeStep,tsId);
}
else
throw MZCException("Unrecognized vtkDataSet ! Sorry ! Try to convert it to UnstructuredGrid to be able to write it !");
}
-void WriteMEDFileFromVTKMultiBlock(MEDFileData *mfd, vtkMultiBlockDataSet *ds, const std::vector<int>& context)
+void WriteMEDFileFromVTKMultiBlock(MEDFileData *mfd, vtkMultiBlockDataSet *ds, const std::vector<int>& context, double timeStep, int tsId)
{
if(!ds || !mfd)
throw MZCException("Internal error in WriteMEDFileFromVTKMultiBlock.");
vtkDataSet *uniqueEltc(vtkDataSet::SafeDownCast(uniqueElt));
if(uniqueEltc)
{
- WriteMEDFileFromVTKDataSet(mfd,uniqueEltc,context);
+ WriteMEDFileFromVTKDataSet(mfd,uniqueEltc,context,timeStep,tsId);
return ;
}
}
vtkDataSet *elt1(vtkDataSet::SafeDownCast(elt));
if(elt1)
{
- WriteMEDFileFromVTKDataSet(mfd,elt1,context);
+ WriteMEDFileFromVTKDataSet(mfd,elt1,context,timeStep,tsId);
continue;
}
vtkMultiBlockDataSet *elt2(vtkMultiBlockDataSet::SafeDownCast(elt));
if(elt2)
{
- WriteMEDFileFromVTKMultiBlock(mfd,elt2,context);
+ WriteMEDFileFromVTKMultiBlock(mfd,elt2,context,timeStep,tsId);
continue;
}
std::ostringstream oss; oss << "In context ";
}
}
-void WriteMEDFileFromVTKGDS(MEDFileData *mfd, vtkDataObject *input)
+void WriteMEDFileFromVTKGDS(MEDFileData *mfd, vtkDataObject *input, double timeStep, int tsId)
{
if(!input || !mfd)
throw MZCException("WriteMEDFileFromVTKGDS : internal error !");
vtkDataSet *input1(vtkDataSet::SafeDownCast(input));
if(input1)
{
- WriteMEDFileFromVTKDataSet(mfd,input1,context);
+ WriteMEDFileFromVTKDataSet(mfd,input1,context,timeStep,tsId);
return ;
}
vtkMultiBlockDataSet *input2(vtkMultiBlockDataSet::SafeDownCast(input));
if(input2)
{
- WriteMEDFileFromVTKMultiBlock(mfd,input2,context);
+ WriteMEDFileFromVTKMultiBlock(mfd,input2,context,timeStep,tsId);
return ;
}
throw MZCException("WriteMEDFileFromVTKGDS : not recognized data type !");
//std::cerr << "########################################## vtkMEDWriter::RequestData ########################################## " << (const char *) this->FileName << std::endl;
try
{
+ bool writeAll((this->WriteAllTimeSteps!=0 && this->NumberOfTimeSteps>0));
+ if(writeAll)
+ {
+ if(this->CurrentTimeIndex==0)
+ request->Set(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING(),1);
+ }
+ else
+ {
+ request->Remove(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING());
+ this->CurrentTimeIndex=0;
+ }
+ //////////////
vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0));
std::string meshName;
std::vector<Grp> groups; std::vector<Fam> fams;
vtkDataObject *input(vtkDataObject::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
if(!input)
throw MZCException("Not recognized data object in input of the MEDWriter ! Maybe not implemented yet !");
+ double timeStep;
+ {
+ vtkInformation *inInfo(inputVector[0]->GetInformationObject(0));
+ vtkDataObject* input(vtkDataObject::GetData(inInfo));
+ timeStep=input->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP());
+ }
+ ////////////
MCAuto<MEDFileData> mfd(MEDFileData::New());
- WriteMEDFileFromVTKGDS(mfd,input);
+ WriteMEDFileFromVTKGDS(mfd,input,timeStep,this->CurrentTimeIndex);
PutFamGrpInfoIfAny(mfd,meshName,groups,fams);
- mfd->write(this->FileName,this->IsTouched?0:2); this->IsTouched=true;
+ if(this->WriteAllTimeSteps==0 || (this->WriteAllTimeSteps!=0 && this->CurrentTimeIndex==0))
+ mfd->write(this->FileName,2);
+ else
+ {
+ mfd->getFields()->write(this->FileName,0);
+ }
outInfo->Set(vtkDataObject::DATA_OBJECT(),input);
+ ///////////
+ if(writeAll)
+ {
+ this->CurrentTimeIndex++;
+ if(this->CurrentTimeIndex>=this->NumberOfTimeSteps)
+ {
+ request->Remove(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING());
+ this->CurrentTimeIndex=0;
+ }
+ }
}
catch(MZCException& e)
{