56 return std::make_shared<VTKFileCollection>(path, prefix);
59 throw std::runtime_error(
"createFileCollection: Unknown file type");
65 switch(fileCollection->getFileType())
68 return std::make_shared<VTKReader>(std::static_pointer_cast<VTKFileCollection>(fileCollection), readLevel, cycleFiles);
71 throw std::runtime_error(
"createReaderForCollection: No reader availabel for this file t");
79 std::stringstream
input(
s);
107 const size_t elemStart = line.find(
'<')+1;
120void VTKFile::readHeader()
123 std::ifstream file(this->fileName);
144 Quantity
quant = Quantity();
147 this->quantities.push_back(
quant );
153 while(file.get()!=
'_'){}
165 this->deltaX = spacing[0];
166 this->deltaY = spacing[1];
167 this->deltaZ = spacing[2];
173 this->minX = origin[0]+this->deltaX*
pieceExtent[0]; this->maxX = (this->nx-1)*this->deltaX+this->minX;
174 this->minY = origin[1]+this->deltaY*
pieceExtent[2]; this->maxY = (this->ny-1)*this->deltaY+this->minY;
175 this->minZ = origin[2]+this->deltaZ*
pieceExtent[4]; this->maxZ = (this->nz-1)*this->deltaZ+this->minZ;
182 std::ifstream
buf(fileName.c_str(), std::ios::in | std::ios::binary);
184 std::vector<double>
tmp;
185 tmp.reserve(readIndices.size());
186 buf.seekg(this->quantities[0].offset);
187 buf.read((
char*)
tmp.data(),
sizeof(
double)*readIndices.size());
188 const auto firstNAN = std::find_if(
tmp.begin(),
tmp.end(), [](
auto it){ return std::isnan(it); });
195 std::ifstream
buf(this->fileName.c_str(), std::ios::in | std::ios::binary);
196 for(
auto&
quantity: this->quantities)
210 for(
auto&
quantity : this->quantities)
215 this->loaded =
false;
223 const size_t nPoints = writeIndices.size();
225 for(
size_t j=0;
j<this->quantities.size();
j++)
228 for(
size_t i=0;
i<nPoints;
i++)
235void VTKFile::printFileInfo()
237 VF_LOG_INFO(
"file {} with \n nx {} ny {} nz {]} \n origin {} {} {}\n spacing {} {} {} ",
238 fileName, nx, ny, nz, minX, minY, minZ, deltaX, deltaY, deltaZ);
247void VTKFileCollection::findFiles()
262 const std::ifstream f(fname);
285 throw std::runtime_error(
"VTKFileCollection found no files!");
305void VTKReader::initializeIndexVectors()
307 this->readIndices.resize(this->fileCollection->files.size());
308 this->writeIndices.resize(this->fileCollection->files.size());
309 this->nFile.resize(this->fileCollection->files.size());
310 for(
size_t lev=0;
lev<this->fileCollection->files.size();
lev++)
312 this->readIndices[
lev].resize(this->fileCollection->files[
lev].size());
313 this->writeIndices[
lev].resize(this->fileCollection->files[
lev].size());
314 this->nFile[
lev].resize(this->fileCollection->files[
lev].size());
321 this->initializeIndexVectors();
343 const uint level = this->readLevel;
347 VTKFile &file = this->fileCollection->files[level][
fileId][0];
436 throw std::runtime_error(
"VTKReader::fillArrays(): Did not find neighbors in the FileCollection for all points");
444 for(
size_t level=0; level<this->fileCollection->files.size(); level++){
445 for(
size_t id=0;
id<this->fileCollection->files[level].size();
id++){
446 if(this->fileCollection->files[level][
id][0].markNANs(
this->readIndices[level][
id]))
447 throw std::runtime_error(
"Found a NAN in the precursor where a velocity is needed");
453 const auto it = std::find(this->writeIndices[level][
id].begin(), this->writeIndices[level][
id].end(),
linearIndex);
454 const uint idx =
it-this->writeIndices[level][id].begin();
455 if(
it==this->writeIndices[level][
id].end())
457 this->writeIndices[level][id].push_back(this->
nPointsRead);
458 this->readIndices[level][id].push_back(
linearIndex);
467 const uint level = this->readLevel;
468 for(
size_t id=0;
id<this->fileCollection->files[level].size();
id++)
472 if(!this->fileCollection->files[level][
id][
numberOfFiles].inZBounds(time-startTime))
477 if(
numberOfFiles == this->fileCollection->files[level][
id].size())
485 throw std::runtime_error(
"Not enough Precursor Files to read");
489 this->fileCollection->files[level][id][
numberOfFiles-1].unloadFile();
490 if(
numberOfFiles+1<this->fileCollection->files[level][
id].size())
496 read = std::async(std::launch::async, [](
VTKFile* file){ file->
loadFile(); }, &this->fileCollection->files[level][id][
numberOfFiles+1]);
504 file->
getData(data, numberOfNodes, this->readIndices[level][
id], this->writeIndices[level][
id],
off, this->
writingOffset);
#define VF_LOG_CRITICAL(...)
std::vector< std::vector< std::vector< VTKFile > > > files
int findNeighborPMM(real posX, real posY, real posZ) const
real getX(int linearIdx) const
int getClosestIdxZ(real posZ) const
bool inBoundingBox(real posX, real posY, real posZ) const
int getNumberOfPoints() const
int findNeighborMPM(real posX, real posY, real posZ) const
bool markNANs(const std::vector< uint > &readIndices) const
void getData(real *data, uint numberOfNodes, const std::vector< uint > &readIndices, const std::vector< uint > &writeIndices, uint offsetRead, uint offsetWrite)
real getY(int linearIdx) const
int getNumberOfPointsInXYPlane() const
int findNeighborPPM(real posX, real posY, real posZ) const
int findNeighborMMM(real posX, real posY, real posZ) const
void fillArrays(std::vector< real > &coordsY, std::vector< real > &coordsZ) override
void getNextData(real *data, uint numberOfNodes, real time) override
std::shared_ptr< T > SPtr
std::string readAttribute(const std::string &line, const std::string &attributeName)
std::string getTag(std::ifstream &input)
SPtr< TransientBCInputFileReader > createReaderForCollection(SPtr< FileCollection > fileCollection, uint readLevel, bool cycleFiles)
std::vector< T > readStringToVector(std::string s)
std::string readElement(const std::string &line)
SPtr< FileCollection > createFileCollection(const std::string &path, const std::string &prefix, TransientBCFileType type)