From ae251598a4c09316b03b89502d0112a05f81a9b4 Mon Sep 17 00:00:00 2001 From: wanqing0421 Date: Sun, 16 Feb 2025 12:31:11 +0800 Subject: [PATCH] update rapid filling --- .../binarySystemOfParticles/runThisCase | 0 .../sphereGranFlow/rapidFilling/dataFile | 2 +- .../rapidFilling/settings/particlesDict | 6 +- .../positionFile/positionFile.cpp | 62 ++++++++++++++----- .../positionFile/positionFile.hpp | 13 ++-- 5 files changed, 59 insertions(+), 24 deletions(-) mode change 100644 => 100755 tutorials/sphereGranFlow/binarySystemOfParticles/runThisCase diff --git a/tutorials/sphereGranFlow/binarySystemOfParticles/runThisCase b/tutorials/sphereGranFlow/binarySystemOfParticles/runThisCase old mode 100644 new mode 100755 diff --git a/tutorials/sphereGranFlow/rapidFilling/dataFile b/tutorials/sphereGranFlow/rapidFilling/dataFile index 452a3c0a..4d3ebed1 100644 --- a/tutorials/sphereGranFlow/rapidFilling/dataFile +++ b/tutorials/sphereGranFlow/rapidFilling/dataFile @@ -1,3 +1,3 @@ -2 0.049302 0.00425012 -0.0068537 0.0456989 -0.0209381 -0.00786771 + diff --git a/tutorials/sphereGranFlow/rapidFilling/settings/particlesDict b/tutorials/sphereGranFlow/rapidFilling/settings/particlesDict index fc7e32b5..0566491f 100755 --- a/tutorials/sphereGranFlow/rapidFilling/settings/particlesDict +++ b/tutorials/sphereGranFlow/rapidFilling/settings/particlesDict @@ -38,12 +38,8 @@ positionParticles // positions particles fileInfo { name dataFile; // the name of the file that contains position and particle data, the data format is ASCII. The file is located at the root case folder - - numPoints 10000; - - fields ( (velocity realx3) (shapeName word) ); // (optional, it could be an empty list or omitted) list of other fields/data that should be read from the file - commaSeparated No; // optional (default is No). if Yes, then fields are separated by a comma + commaSeparated No; // optional (default is No). if Yes, then fields are separated by a comma } regionType box; // other options: cylinder and sphere diff --git a/utilities/particlesPhasicFlow/positionFile/positionFile.cpp b/utilities/particlesPhasicFlow/positionFile/positionFile.cpp index 039997f8..ebcbf7dd 100755 --- a/utilities/particlesPhasicFlow/positionFile/positionFile.cpp +++ b/utilities/particlesPhasicFlow/positionFile/positionFile.cpp @@ -21,29 +21,63 @@ Licence: #include "error.hpp" #include "dictionary.hpp" #include "positionFile.hpp" + + +#include "streams.hpp" +// #include "token.hpp" +#include "fileSystem.hpp" #include "iFstream.hpp" +#include "oFstream.hpp" bool pFlow::positionFile::positionPointsFile() { - std::cout << "Reading user defined position file...."; + REPORT(0) << "Reading user defined position file...."; position_.clear(); - // ToDo: read position data from file. - - std::ifstream inFile(fileName_); - - inFile >> numPoints_; + // Read position data from file. + iFstream is(fileName_); realx3 tempPoint; - for(int i = 0; i < numPoints_; i++) - { - inFile >> tempPoint.x_ >> tempPoint.y_ >> tempPoint.z_; + token tok; + + while (!is.eof() || !is.bad()) + { + // read position x + is >> tempPoint.x_; + + if(commaSeparated_) + { + is >> tok; + if(tok.type() != token::COMMA) + { + fatalErrorInFunction << "Error datafile format, the data not comma separated!"; + return false; + } + } + + // read position y + is >> tempPoint.y_; + + if(commaSeparated_) + { + is >> tok; + if(tok.type() != token::COMMA) + { + fatalErrorInFunction << "Error datafile format, the data not comma separated!"; + return false; + } + } + + // read position z + is >> tempPoint.z_; + + // insert position data to vector position_.push_back(tempPoint); } - std::cout << "Done!" << std::endl; + REPORT(0) << "Done!" << END_REPORT; return true; } @@ -63,15 +97,15 @@ pFlow::positionFile::positionFile ( poDict_.getVal("name") ), - numPoints_ + commaSeparated_ ( - poDict_.getVal("numPoints") + poDict_.getValOrSet("commaSeparated", Logical("Yes")) ), position_ ( "position", - max(maxNumberOfParticles(), numPoints_), - numPoints_ , + max(maxNumberOfParticles(), position_.size()), + 0, RESERVE() ) { diff --git a/utilities/particlesPhasicFlow/positionFile/positionFile.hpp b/utilities/particlesPhasicFlow/positionFile/positionFile.hpp index 91b97ee8..e2df0841 100755 --- a/utilities/particlesPhasicFlow/positionFile/positionFile.hpp +++ b/utilities/particlesPhasicFlow/positionFile/positionFile.hpp @@ -35,12 +35,14 @@ private: dictionary poDict_; - word fileName_; + // word fileName_; - uint32 numPoints_; + fileSystem fileName_; realx3Vector position_; + Logical commaSeparated_; + bool positionPointsFile(); public: @@ -76,6 +78,11 @@ public: { return 0; } + + // bool commaSeparated()const + // { + // return commaSeparated_(); + // } // - const access to position const realx3Vector& position()const final @@ -88,8 +95,6 @@ public: { return position_; } - - };