diff --git a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp index 571796d503a1a73b3eccf631a347884c7522b533..636c64cb986049a7510603ef20ee2b870a4dd562 100644 --- a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp +++ b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp @@ -49,9 +49,9 @@ std::vector<T> readStringToVector(std::string s) std::string readElement(std::string line) { - size_t elemStart = line.find("<")+1; + size_t elemStart = line.find('<')+1; // size_t elemEnd = line.find("/>", elemStart); - size_t nameLen = line.find(" ", elemStart)-elemStart; + size_t nameLen = line.find(' ', elemStart)-elemStart; return line.substr(elemStart, nameLen); } @@ -118,7 +118,7 @@ void VTKFile::readHeader() } -bool VTKFile::markNANs(std::vector<uint> readIndices) +bool VTKFile::markNANs(const std::vector<uint>& readIndices) { std::ifstream buf(fileName.c_str(), std::ios::in | std::ios::binary); @@ -161,7 +161,7 @@ void VTKFile::getData(real *data, uint numberOfNodes, const std::vector<uint> &r { if(!this->loaded) loadFile(); - size_t nPoints = writeIndices.size(); + const size_t nPoints = writeIndices.size(); for(size_t j=0; j<this->quantities.size(); j++) { @@ -177,7 +177,7 @@ void VTKFile::printFileInfo() { printf("file %s with \n nx %i ny %i nz %i \n origin %f %f %f \n spacing %f %f %f \n", fileName.c_str(), nx, ny, nz, minX, minY, minZ, deltaX, deltaY, deltaZ); - for(auto quantity: this->quantities) + for(const auto& quantity: this->quantities) { printf("\t quantity %s offset %i \n", quantity.name.c_str(), quantity.offset); } @@ -199,8 +199,8 @@ void VTKFileCollection::findFiles() std::vector<VTKFile> filesWithThisId; while (!foundLastPart) { - std::string fname = makeFileName((int)files.size(), (int)filesOnThisLevel.size(), (int)filesWithThisId.size()); - std::ifstream f(fname); + const std::string fname = makeFileName((int)files.size(), (int)filesOnThisLevel.size(), (int)filesWithThisId.size()); + const std::ifstream f(fname); if(f.good()) filesWithThisId.emplace_back(fname); else @@ -260,8 +260,8 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords { this->nPoints = (uint)coordsY.size(); this->initializeIndexVectors(); - real max_diff = 1e-4; // maximum distance between point on grid and precursor plane to count as exact match - real eps = 1e-7; // small number to avoid division by zero + const real max_diff = 1e-4; // maximum distance between point on grid and precursor plane to count as exact match + const real eps = 1e-7; // small number to avoid division by zero bool perfect_match = true; this->weights0PP.reserve(this->nPoints); @@ -277,11 +277,11 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords for(uint i=0; i<nPoints; i++) { - real posY = coordsY[i]; - real posZ = coordsZ[i]; + const real posY = coordsY[i]; + const real posZ = coordsZ[i]; bool found0PP = false, found0PM = false, found0MP = false, found0MM = false, foundAll = false; - uint level = this->readLevel; + const uint level = this->readLevel; for(int fileId=0; fileId<(int)this->fileCollection->files[level].size(); fileId++) { @@ -290,7 +290,7 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords // y in simulation is x in precursor/file, z in simulation is y in precursor/file // simulation -> file: N -> E, S -> W, T -> N, B -> S - int idx = file.findNeighborMMM(posY, posZ, 0.f); //!> index of nearest WSB neighbor on precursor file + const int idx = file.findNeighborMMM(posY, posZ, 0.f); //!> index of nearest WSB neighbor on precursor file if(idx!=-1) { @@ -301,7 +301,7 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords this->weights0PM.emplace_back(0.f); this->weights0MP.emplace_back(0.f); this->weights0MM.emplace_back(0.f); - uint writeIdx = this->getWriteIndex(level, fileId, idx); //!> writeIdx: index on host/device array where precursor value will be written to after loading from file + const uint writeIdx = this->getWriteIndex(level, fileId, idx); //!> writeIdx: index on host/device array where precursor value will be written to after loading from file this->planeNeighbor0PP.push_back(writeIdx); //!> neighbor lists mapping where BC kernel should read from on host/device array this->planeNeighbor0PM.push_back(writeIdx); this->planeNeighbor0MP.push_back(writeIdx); @@ -319,8 +319,8 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords if(!found0MM) { found0MM = true; - real dy = file.getX(idx)-posY; - real dz = file.getY(idx)-posZ; + const real dy = file.getX(idx)-posY; + const real dz = file.getY(idx)-posZ; this->weights0MM.emplace_back(1.f/(dy*dy+dz*dz+eps)); this->planeNeighbor0MM.emplace_back(getWriteIndex(level, fileId, idx)); } @@ -329,12 +329,12 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords if(!found0PP) //NT in simulation is EN in precursor { - int index = file.findNeighborPPM(posY, posZ, 0.f); + const int index = file.findNeighborPPM(posY, posZ, 0.f); if(index!=-1) { found0PP = true; - real dy = file.getX(index)-posY; - real dz = file.getY(index)-posZ; + const real dy = file.getX(index)-posY; + const real dz = file.getY(index)-posZ; this->weights0PP.emplace_back(1.f/(dy*dy+dz*dz+eps)); this->planeNeighbor0PP.emplace_back(getWriteIndex(level, fileId, index)); } @@ -342,12 +342,12 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords if(!found0PM) //NB in simulation is ES in precursor { - int index = file.findNeighborPMM(posY, posZ, 0.f); + const int index = file.findNeighborPMM(posY, posZ, 0.f); if(index!=-1) { found0PM = true; - real dy = file.getX(index)-posY; - real dz = file.getY(index)-posZ; + const real dy = file.getX(index)-posY; + const real dz = file.getY(index)-posZ; this->weights0PM.emplace_back(1.f/(dy*dy+dz*dz+eps)); this->planeNeighbor0PP.emplace_back(getWriteIndex(level, fileId, index)); } @@ -355,12 +355,12 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords if(!found0MP) //ST in simulation is WN in precursor { - int index = file.findNeighborMPM(posY, posZ, 0.f); + const int index = file.findNeighborMPM(posY, posZ, 0.f); if(index!=-1) { found0MP = true; - real dy = file.getX(index)-posY; - real dz = file.getY(index)-posZ; + const real dy = file.getX(index)-posY; + const real dz = file.getY(index)-posZ; this->weights0MP.emplace_back(1.f/(dy*dy+dz*dz+eps)); this->planeNeighbor0MP.emplace_back(getWriteIndex(level, fileId, index)); } @@ -392,7 +392,7 @@ void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coords uint VTKReader::getWriteIndex(int level, int id, int linearIndex) { auto it = std::find(this->writeIndices[level][id].begin(), this->writeIndices[level][id].end(), linearIndex); - uint idx = it-this->writeIndices[level][id].begin(); + const uint idx = it-this->writeIndices[level][id].begin(); if(it==this->writeIndices[level][id].end()) { this->writeIndices[level][id].push_back(this->nPointsRead); //!> index on host/device array where value from file will be written to @@ -407,7 +407,7 @@ void VTKReader::getNextData(real* data, uint numberOfNodes, real time) { // for(size_t level=0; level<this->fileCollection->files.size(); level++) // { - uint level = this->readLevel; + const uint level = this->readLevel; for(size_t id=0; id<this->fileCollection->files[level].size(); id++) { size_t numberOfFiles = this->nFile[level][id]; @@ -436,7 +436,7 @@ void VTKReader::getNextData(real* data, uint numberOfNodes, real time) VTKFile* file = &this->fileCollection->files[level][id][numberOfFiles]; - int off = file->getClosestIdxZ(time)*file->getNumberOfPointsInXYPlane(); + const int off = file->getClosestIdxZ(time)*file->getNumberOfPointsInXYPlane(); file->getData(data, numberOfNodes, this->readIndices[level][id], this->writeIndices[level][id], off, this->writingOffset); this->nFile[level][id] = numberOfFiles; } diff --git a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h index 1663a3ff37ba1bb062647847462d4e364baed93b..5172210d1704c7f91d60a306a85a50c951402471 100644 --- a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h +++ b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h @@ -41,7 +41,7 @@ public: }; void getData(real* data, uint numberOfNodes, const std::vector<uint>& readIndices, const std::vector<uint>& writeIndices, uint offsetRead, uint offsetWrite); - bool markNANs(std::vector<uint> readIndices); + bool markNANs(const std::vector<uint>& readIndices); bool inBoundingBox(real posX, real posY, real posZ){return inXBounds(posX) && inYBounds(posY) && inZBounds(posZ); }; bool inXBounds(real posX){ return posX<=maxX && posX>=minX; }; bool inYBounds(real posY){ return posY<=maxY && posY>=minY; }; @@ -183,7 +183,7 @@ public: void getNextData(real* data, uint numberOfNodes, real time) override; void fillArrays(std::vector<real>& coordsY, std::vector<real>& coordsZ) override; private: - uint getWriteIndex(int level, int id, int linearIdx); + uint getWriteIndex(int level, int id, int linearIndex); void initializeIndexVectors(); private: