-// Copyright (C) 2010-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2010-2015 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "vtkCellArray.h"
#include "vtkDoubleArray.h"
#include "vtkObjectFactory.h"
+#ifdef MEDREADER_USE_MPI
+#include "vtkMultiProcessController.h"
+#endif
#include "MEDFileFieldRepresentationTree.hxx"
+#include <map>
#include <string>
#include <vector>
#include <sstream>
{
public:
- vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master)
+ vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master),MyMTime(0)
{
}
int LastLev0;
// The property keeper is usable only in pvsm mode.
PropertyKeeper PK;
+ int MyMTime;
+ std::set<std::string> _wonderful_set;// this set is used by SetFieldsStatus method to detect the fact that SetFieldsStatus has been called for all items ! Great Items are not sorted ! Why ?
+ std::map<std::string,bool> _wonderful_ref;// this map stores the state before a SetFieldsStatus status.
private:
unsigned char FirstCall0;
};
vtkMEDReader::~vtkMEDReader()
{
delete this->Internal;
+ this->Internal = 0;
}
void vtkMEDReader::Reload(int a)
this->SetFileName(fName.c_str());
}
+int vtkMEDReader::GetServerModifTime()
+{
+ if( !this->Internal )
+ return -1;
+ return this->Internal->MyMTime;
+}
+
void vtkMEDReader::GenerateVectors(int val)
{
+ if ( !this->Internal )
+ return;
+
if(this->Internal->FileName.empty())
{//pvsm mode
this->Internal->PK.pushGenerateVectorsValue(val);
void vtkMEDReader::ChangeMode(int newMode)
{
+ if ( !this->Internal )
+ return;
+
if(this->Internal->FileName.empty())
{//pvsm mode
this->Internal->PK.pushChangeModeValue(newMode);
void vtkMEDReader::SetFileName(const char *fname)
{
+ if(!this->Internal)
+ return;
try
{
this->Internal->FileName=fname;
}
if(this->Internal->Tree.getNumberOfLeavesArrays()==0)
{
- this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv);
+ int iPart(-1),nbOfParts(-1);
+#ifdef MEDREADER_USE_MPI
+ vtkMultiProcessController *vmpc(vtkMultiProcessController::GetGlobalController());
+ if(vmpc)
+ {
+ iPart=vmpc->GetLocalProcessId();
+ nbOfParts=vmpc->GetNumberOfProcesses();
+ }
+#endif
+ this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv,iPart,nbOfParts);
if(!this->Internal->PK.arePropertiesOnTreeToSetAfter())
this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client.
this->Internal->TK.setMaxNumberOfTimeSteps(this->Internal->Tree.getMaxNumberOfTimeSteps());
char *vtkMEDReader::GetFileName()
{
+ if (!this->Internal)
+ return 0;
return const_cast<char *>(this->Internal->FileName.c_str());
}
try
{
vtkInformation *outInfo(outputVector->GetInformationObject(0));
- outInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),-1);
outInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkMultiBlockDataSet");
this->UpdateSIL(outInfo);
//
}
catch(INTERP_KERNEL::Exception& e)
{
- std::cerr << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl;
+ std::ostringstream oss;
+ oss << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl;
+ if(this->HasObserver("ErrorEvent") )
+ this->InvokeEvent("ErrorEvent",const_cast<char *>(oss.str().c_str()));
+ else
+ vtkOutputWindowDisplayErrorText(const_cast<char *>(oss.str().c_str()));
+ vtkObject::BreakOnError();
return 0;
}
return 1;
}
catch(INTERP_KERNEL::Exception& e)
{
- std::cerr << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl;
+ std::cerr << "Exception has been thrown in vtkMEDReader::RequestData : " << e.what() << std::endl;
return 0;
}
return 1;
void vtkMEDReader::SetFieldsStatus(const char* name, int status)
{
- //std::cerr << "vtkMEDReader::SetFieldsStatus(" << name << "," << status << ") called !" << std::endl;
+ if( !this->Internal )
+ return;
+
+ //this->Internal->_wonderful_set.insert(name);
if(this->Internal->FileName.empty())
{//pvsm mode
this->Internal->PK.pushFieldStatusEntry(name,status);
return ;
}
+ if(this->Internal->_wonderful_set.empty())
+ this->Internal->_wonderful_ref=this->Internal->Tree.dumpState();// start of SetFieldsStatus serie -> store ref to compare at the end of the SetFieldsStatus serie.
+ this->Internal->_wonderful_set.insert(name);
//not pvsm mode (general case)
try
{
this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status);
- if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1))
- if(!this->Internal->PluginStart0())
- this->Modified();
+ if(this->Internal->_wonderful_set.size()==GetNumberOfFieldsTreeArrays())
+ {
+ if(this->Internal->_wonderful_ref!=this->Internal->Tree.dumpState())
+ {
+ if(!this->Internal->PluginStart0())
+ {
+ this->Modified();
+ }
+ this->Internal->MyMTime++;
+ }
+ this->Internal->_wonderful_set.clear();
+ }
}
catch(INTERP_KERNEL::Exception& e)
{
{
if(!this->Internal)
return 0;
- int ret(this->Internal->Tree.getNumberOfLeavesArrays());
+ return this->Internal->Tree.getNumberOfLeavesArrays();
//std::cerr << "vtkMEDReader::GetNumberOfFieldsTreeArrays called ! " << ret << std::endl;
- return ret;
}
const char *vtkMEDReader::GetFieldsTreeArrayName(int index)
{
+ if(!this->Internal)
+ return 0;
return this->Internal->Tree.getNameOfC(index);
//std::cerr << "vtkMEDReader::GetFieldsTreeArrayName(" << index << ") called ! " << ret << std::endl;
}
int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name)
{
+ if(!this->Internal)
+ return -1;
+
int zeId(this->Internal->Tree.getIdHavingZeName(name));
int ret(this->Internal->Tree.getStatusOf(zeId));
return ret;
void vtkMEDReader::SetTimesFlagsStatus(const char *name, int status)
{
+ if (!this->Internal)
+ return;
+
if(this->Internal->FileName.empty())
{//pvsm mode
this->Internal->PK.pushTimesFlagsStatusEntry(name,status);
int vtkMEDReader::GetTimesFlagsArrayStatus(const char *name)
{
+ if(!this->Internal)
+ return -1;
int pos(0);
std::istringstream iss(name); iss >> pos;
return (int)this->Internal->TK.getTimesFlagArray()[pos].first;
void vtkMEDReader::UpdateSIL(vtkInformation *info)
{
if(!this->Internal)
- return ;
+ return;
vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::New());
std::string meshName(this->BuildSIL(sil));
if(meshName!=this->Internal->DftMeshName)
*/
std::string vtkMEDReader::BuildSIL(vtkMutableDirectedGraph* sil)
{
+ if (!this->Internal)
+ return std::string();
sil->Initialize();
vtkSmartPointer<vtkVariantArray> childEdge(vtkSmartPointer<vtkVariantArray>::New());
childEdge->InsertNextValue(0);
double vtkMEDReader::PublishTimeStepsIfNeeded(vtkInformation *outInfo, bool& isUpdated)
{
+ if(!this->Internal)
+ return 0.0;
+
int lev0(-1);
std::vector<double> tsteps;
if(!this->Internal->IsStdOrMode)
void vtkMEDReader::FillMultiBlockDataSetInstance(vtkMultiBlockDataSet *output, double reqTS)
{
+ if( !this->Internal )
+ return;
std::string meshName;
vtkDataSet *ret(this->Internal->Tree.buildVTKInstance(this->Internal->IsStdOrMode,reqTS,meshName,this->Internal->TK));
if(this->Internal->GenerateVect)