diff --git a/src/Interaction/contactSearch/contactSearch/contactSearch.hpp b/src/Interaction/contactSearch/contactSearch/contactSearch.hpp index 7725f7e6..d6428064 100644 --- a/src/Interaction/contactSearch/contactSearch/contactSearch.hpp +++ b/src/Interaction/contactSearch/contactSearch/contactSearch.hpp @@ -19,116 +19,229 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __contactSearch_hpp__ -#define __contactSearch_hpp__ +#ifndef __ContactSearch_hpp__ +#define __ContactSearch_hpp__ -#include "interactionBase.hpp" -#include "unsortedPairs.hpp" +#include "contactSearch.hpp" #include "box.hpp" -#include "dictionary.hpp" namespace pFlow { - -class contactSearch +template< + template class BaseMethod, + template class WallMapping +> +class ContactSearch : - public interactionBase + public contactSearch { public: - using IdType = typename interactionBase::IdType; + + using IdType = typename contactSearch::IdType; - using IndexType = typename interactionBase::IndexType; + using IndexType = typename contactSearch::IndexType; - using ExecutionSpace = typename interactionBase::ExecutionSpace; + using ExecutionSpace = typename contactSearch::ExecutionSpace; - using PairContainerType = unsortedPairs; + using PairContainerType = typename contactSearch::PairContainerType; + + using ParticleContactSearchType = + BaseMethod< + ExecutionSpace>; + + using WallMappingType = + WallMapping< + ExecutionSpace>; protected: - - const box& domain_; - - dictionary dict_; - - Timer sphereSphereTimer_; - - Timer sphereWallTimer_; - - auto& dict() - { - return dict_; - } + + uniquePtr particleContactSearch_ = nullptr; + + uniquePtr wallMapping_ = nullptr; + public: - TypeInfo("contactSearch"); + TypeInfoTemplate2("ContactSearch", ParticleContactSearchType, WallMappingType); - contactSearch( - const dictionary& dict, + ContactSearch( + const dictionary& csDict, const box& domain, const particles& prtcl, const geometry& geom, - Timers& timers); + Timers& timers) + : + contactSearch(csDict, domain, prtcl, geom, timers) + + { - virtual ~contactSearch()=default; + auto method = dict().getVal("method"); + auto wmMethod = dict().getVal("wallMapping"); + + auto nbDict = dict().subDict(method+"Info"); + + real minD, maxD; + this->Particles().boundingSphereMinMax(minD, maxD); + + const auto& position = this->Particles().pointPosition().deviceVectorAll(); + const auto& diam = this->Particles().boundingSphere().deviceVectorAll(); + + particleContactSearch_ = + makeUnique + ( + nbDict, + this->domain(), + minD, + maxD, + position, + diam + ); + REPORT(2)<<"Contact search algorithm for particle-particle is "<< + greenText(particleContactSearch_().typeName())<Geometry().numPoints(); + int32 wnTri = this->Geometry().size(); + + const auto& wPoints = this->Geometry().points().deviceVectorAll(); + const auto& wVertices = this->Geometry().vertices().deviceVectorAll(); + + wallMapping_ = + makeUnique( + wmDict, + particleContactSearch_().numLevels(), + particleContactSearch_().getCellsLevels(), + wnPoints, + wnTri, + wPoints, + wVertices + ); + REPORT(2)<<"Wall mapping algorithm for particle-wall is "<< + greenText(wallMapping_().typeName())<< endREPORT; + + } + + + add_vCtor( contactSearch, - dictionary, - ( - const dictionary& dict, - const box& domain, - const particles& prtcl, - const geometry& geom, - Timers& timers - ), - (dict, domain, prtcl, geom, timers) - ); - - const auto& domain()const - { - return domain_; - } - - const auto& dict()const - { - return dict_; - } - - - virtual + ContactSearch, + dictionary); + bool broadSearch( PairContainerType& ppPairs, PairContainerType& pwPairs, - bool force = false) = 0; + bool force = false) override + { - virtual - bool ppEnterBroadSearch()const = 0; + + if(particleContactSearch_) + { + auto activeRange = this->Particles().activeRange(); - virtual - bool pwEnterBroadSearch()const = 0; + sphereSphereTimer_.start(); - virtual - bool ppPerformedBroadSearch()const = 0; + if(this->Particles().allActive()) + { + particleContactSearch_().broadSearch(ppPairs, activeRange, force); + } + else + { + particleContactSearch_().broadSearch(ppPairs, activeRange, this->Particles().activePointsMaskD(), force); + } - virtual - bool pwPerformedBroadSearch()const = 0; + sphereSphereTimer_.end(); + + } + else + return false; + + if(wallMapping_) + { + sphereWallTimer_.start(); + wallMapping_().broadSearch(pwPairs, particleContactSearch_(), force); + sphereWallTimer_.end(); + } + else + return false; + + + + return true; + } + + + bool ppEnterBroadSearch()const override + { + if(particleContactSearch_) + { + return particleContactSearch_().enterBoadSearch(); + } + return false; + } + + bool pwEnterBroadSearch()const override + { + if(wallMapping_) + { + return wallMapping_().enterBoadSearch(); + } + return false; + } - static - uniquePtr create( - const dictionary& dict, - const box& domain, - const particles& prtcl, - const geometry& geom, - Timers& timers); + bool ppPerformedBroadSearch()const override + { + if(particleContactSearch_) + { + return particleContactSearch_().performedSearch(); + } + return false; + } + + bool pwPerformedBroadSearch()const override + { + if(wallMapping_) + { + return wallMapping_().performedSearch(); + } + return false; + } + + /*bool update(const eventMessage& msg) + { + if(msg.isSizeChanged() ) + { + auto newSize = this->prtcl().size(); + if(!particleContactSearch_().objectSizeChanged(newSize)) + { + fatalErrorInFunction<< + "erro in changing the size for particleContactSearch_ \n"; + return false; + } + } + + if(msg.isCapacityChanged() ) + { + auto newSize = this->prtcl().capacity(); + if(!particleContactSearch_().objectSizeChanged(newSize)) + { + fatalErrorInFunction<< + "erro in changing the capacity for particleContactSearch_ \n"; + return false; + } + } + + return true; + }*/ + + }; - } diff --git a/src/Particles/Insertion/insertion/insertion.cpp b/src/Particles/Insertion/insertion/insertion.cpp index 5737d521..a8a406e3 100644 --- a/src/Particles/Insertion/insertion/insertion.cpp +++ b/src/Particles/Insertion/insertion/insertion.cpp @@ -18,57 +18,187 @@ Licence: -----------------------------------------------------------------------------*/ - -#include "particles.hpp" -#include "dictionary.hpp" -#include "insertion.hpp" -#include "streams.hpp" - -bool pFlow::insertion::readInsertionDict +template +bool pFlow::Insertion::readInsertionDict ( const dictionary& dict ) { - - active_ = dict.getVal("active"); - - if(active_) - REPORT(1)<< "Particle insertion mechanism is "<< - yellowText("active")<<" in the simulation."<isActive() ) + { + return true; + } + + wordList regionDicNames = dict.dictionaryKeywords(); + + for(auto& name:regionDicNames) + { + REPORT(2)<<"reading insertion region "<< greenText(name)< +bool pFlow::Insertion::writeInsertionDict ( dictionary& dict )const { - if(!dict.add("active", active_) ) - { - fatalErrorInFunction<< - " error in writing active to dictionary "<isActive() ) return true; + + ForAll(i,regions_) { - fatalErrorInFunction<< - " error in writing checkForCollision to dictionary "< +pFlow::Insertion::Insertion ( - particles& prtcl + particles& prtcl, + const ShapeType& shapes ) : - particles_(prtcl) -{} \ No newline at end of file + insertion(prtcl), + shapes_(shapes) +{ + + +} + + +template +bool pFlow::Insertion::insertParticles +( + real currentTime, + real dt +) +{ + if(!isActive()) return true; + + + ForAll(i,regions_) + { + bool insertionOccured = false; + auto& rgn = regions_[i]; + if( rgn.insertionTime(currentTime, dt) ) + { + + realx3Vector pos; + wordVector shapes; + if( rgn.insertParticles(currentTime, dt, shapes, pos, insertionOccured) ) + { + + if(insertionOccured) + { + REPORT(0)<<"\nParticle insertion from "<< greenText(rgn.name())< +bool pFlow::Insertion::read +( + iIstream& is +) +{ + + // create an empty dictionary + dictionary dict(is.name(), true); + + if(!dict.read(is)) + { + ioErrorInFile( is.name(), is.lineNumber() )<< + " error in reading "<< insertionFile__ << "dictionary from file."< +bool pFlow::Insertion::write +( + iOstream& os +)const +{ + + dictionary dict(insertionFile__,true); + + if(! writeInsertionDict(dict) ) + { + fatalErrorInFunction<< + " error in writing to " << dict.globalName()< +class Insertion +: + public insertion { protected: - // - insertion active - Logical active_ = "No"; - // - check for collision / desabled for now - Logical checkForCollision_ = "No"; + const ShapeType& shapes_; + + // - insertion regions + ListPtr> regions_; - // - particles - particles& particles_; - bool readInsertionDict(const dictionary& dict); bool writeInsertionDict(dictionary& dict)const; public: - // type info - TypeInfo("insertion"); + TypeInfoTemplateNV("Insertion",ShapeType); - insertion(particles& prtcl); - - virtual ~insertion() = default; - - bool isActive()const { - return active_(); - } + Insertion(particles& prtcl, const ShapeType& shapes); - virtual bool read(iIstream& is) = 0; + bool insertParticles(real currentTime, real dt); - virtual bool write(iOstream& os)const = 0; + virtual bool read(iIstream& is) override; + virtual bool write(iOstream& os)const override; }; + } +#include "Insertion.cpp" + #endif diff --git a/src/Particles/Insertion/insertionRegion/insertionRegion.cpp b/src/Particles/Insertion/insertionRegion/insertionRegion.cpp index bce4ac48..57404bf7 100644 --- a/src/Particles/Insertion/insertionRegion/insertionRegion.cpp +++ b/src/Particles/Insertion/insertionRegion/insertionRegion.cpp @@ -18,122 +18,98 @@ Licence: -----------------------------------------------------------------------------*/ - -#include "insertionRegion.hpp" -#include "dictionary.hpp" - -bool pFlow::insertionRegion::readInsertionRegion +template +bool pFlow::InsertionRegion::checkForContact ( - const dictionary& dict + const realx3Vector& pos, + const realVector& diams, + const realx3& p, + const real& d ) { - name_ = dict.name(); - type_ = dict.getVal("type"); - - pRegion_ = peakableRegion::create(type_, dict.subDict(type_+"Info")); - - mixture_ = makeUnique(dict.subDict("mixture")); - - addToNumInserted(mixture_().totalInserted()); - - if( !dict.containsDictionay("setFields")) + ForAll(i, pos) { - output<<"\n insertion region "<< name_ << " does not contain setFields dictionary." - " An empty dictoiinary is created for it. \n"; - setFields_ = makeUnique( dictionary("setFields") ); - } - else - { - setFields_ = makeUnique( dict.subDict("setFields") ); + if( length(pos[i]-p) < 0.5*(diams[i]+d) ) return true; } - for(auto& sfEntry:setFields_()) + return false; +} + +template +pFlow::InsertionRegion::InsertionRegion +( + const dictionary& dict, + const ShapeType& shapes +) +: + insertionRegion(dict), + shapes_(shapes) +{ + +} + + +template +bool pFlow::InsertionRegion::insertParticles +( + real currentTime, + real dt, + wordVector& names, + realx3Vector& pos, + bool& insertionOccured +) +{ + insertionOccured = false; + + if(!insertionTime( currentTime, dt)) return true; + + size_t newNum = numberToBeInserted(currentTime); + + if(newNum == 0) return true; + + names.reserve(max(newNum,names.capacity())); + pos.reserve(max(newNum,pos.capacity())); + names.clear(); + pos.clear(); + + realVector diams(newNum, RESERVE()); + + mixture_->getNextShapeNameN(newNum, names); + + if(!shapes_.shapeToDiameter(names,diams)) { - if(!sfEntry.checkForTypeAndValueAll()) + fatalErrorInFunction<< + " error occured in insertion region "<< name() << + " while converting shapes to diameter. \n"; + return false; + } + + size_t n = 0; + + for(label iter=0; iter< 10*newNum ; ++iter) + { + if( !(n < newNum) ) { - fatalErrorInFunction<< - " error in setFields dictionary "<< dict.globalName()<clone(): nullptr), - mixture_( src.mixture_? src.mixture_->clone(): nullptr), - setFields_( src.setFields_? src.setFields_->clone(): nullptr) -{} - -pFlow::insertionRegion& pFlow::insertionRegion::operator= -( - const insertionRegion& src -) -{ - - if(&src == this)return *this; - timeFlowControl::operator=(src); - - name_ = src.name_; - type_ = src.type_; - pRegion_ = (src.pRegion_? src.pRegion_->clone(): nullptr); - mixture_ = (src.mixture_? src.mixture_->clone(): nullptr); - setFields_ = (src.setFields_? src.setFields_->clone(): nullptr); - - return *this; -} - + fatalErrorInFunction<< + " Cannot insert "<< newNum << " new particles from region "<< name()<<". \n" + " pFlow could position only "<< n<< " particles in this region. \n"; + addToNumInserted(n); + insertionOccured = false; + return false; +} \ No newline at end of file diff --git a/src/Particles/Insertion/insertionRegion/insertionRegion.hpp b/src/Particles/Insertion/insertionRegion/insertionRegion.hpp index 04a1bf7e..d7bdbf0a 100644 --- a/src/Particles/Insertion/insertionRegion/insertionRegion.hpp +++ b/src/Particles/Insertion/insertionRegion/insertionRegion.hpp @@ -18,97 +18,78 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __insertionRegion_hpp__ -#define __insertionRegion_hpp__ +#ifndef __InsertionRegion_hpp__ +#define __InsertionRegion_hpp__ -#include "timeFlowControl.hpp" -#include "shapeMixture.hpp" -#include "peakableRegions.hpp" -#include "setFieldList.hpp" + +#include "insertionRegion.hpp" +#include "dictionary.hpp" namespace pFlow { -class dictionary; - -class insertionRegion +template +class InsertionRegion : - public timeFlowControl + public insertionRegion { protected: + // - type of particle shapes + const ShapeType& shapes_; - // - name of the region - word name_; - - // - type of insertion region - word type_; - - // peakable region of points - uniquePtr pRegion_ = nullptr; - - // mixture of shapes - uniquePtr mixture_ = nullptr; - - // setFields for insertion region - uniquePtr setFields_ = nullptr; - - - bool readInsertionRegion(const dictionary& dict); - - bool writeInsertionRegion(dictionary& dict) const; - + static bool checkForContact( + const realx3Vector& pos, + const realVector& diams, + const realx3& p, + const real& d); public: - TypeInfoNV("insertionRegion"); + // - type info + TypeInfoTemplateNV("insertionRegion", ShapeType); - //// - Constructors + InsertionRegion(const dictionary& dict, const ShapeType& shapes); - insertionRegion(const dictionary& dict); + InsertionRegion(const InsertionRegion& ) = default; - insertionRegion(const insertionRegion& src); + InsertionRegion(InsertionRegion&&) = default; - insertionRegion(insertionRegion&&) = default; + InsertionRegion& operator=(const InsertionRegion& ) = default; - insertionRegion& operator=(const insertionRegion&); - - insertionRegion& operator=(insertionRegion&&) = default; + InsertionRegion& operator=(InsertionRegion&&) = default; - ~insertionRegion() = default; + auto clone()const + { + return makeUnique>(*this); + } + + auto clonePtr()const + { + return new InsertionRegion(*this); + } - //// - Methods - const auto& setFields()const - { - return setFields_(); - } + bool insertParticles + ( + real currentTime, + real dt, + wordVector& names, + realx3Vector& pos, + bool& insertionOccured + ); - const auto& name()const - { - return name_; - } - - - //// - IO operation - - bool read(const dictionary& dict) - { - if(!timeFlowControl::read(dict))return false; - - return readInsertionRegion(dict); - } - - bool write(dictionary& dict)const - { - if(!timeFlowControl::write(dict)) return false; - - return writeInsertionRegion(dict); - } + //bool read(const dictionary& dict); + //bool write(dictionary& dict)const; }; -} //pFlow -#endif //__insertionRegion_hpp__ + +} // pFlow + + +#include "InsertionRegion.cpp" + +#endif diff --git a/src/phasicFlow/random/randomReal/randomReal.cpp b/src/phasicFlow/random/randomReal/randomReal.cpp index 2f3392e0..ba8abdc1 100644 --- a/src/phasicFlow/random/randomReal/randomReal.cpp +++ b/src/phasicFlow/random/randomReal/randomReal.cpp @@ -18,34 +18,36 @@ Licence: -----------------------------------------------------------------------------*/ - -#include "randomReal.hpp" +#include "RandomReal.hpp" -pFlow::uniquePtr pFlow::randomReal::create +template +pFlow::RandomReal::RandomReal ( word distribution ) +: + randomReal(distribution), + distribution_() { - word dist = angleBracketsNames("randomReal", distribution); - if( wordvCtorSelector_.search(dist) ) - { - return wordvCtorSelector_[dist] (distribution); - } - else - { - printKeys - ( - fatalError << "Ctor Selector "<< dist << " dose not exist. \n" - <<"Avaiable ones are: \n\n" - , - wordvCtorSelector_ - ); - fatalExit(); - } - - return nullptr; } +template +pFlow::real pFlow::RandomReal::randomNumber +( + real a, real b +) +{ + return distribution_.randomNumber(a,b); +} +template +pFlow::realx3 pFlow::RandomReal::randomNumber +( + realx3 a, + realx3 b +) +{ + return distribution_.randomNumber(a,b); +} \ No newline at end of file diff --git a/src/phasicFlow/random/randomReal/randomReal.hpp b/src/phasicFlow/random/randomReal/randomReal.hpp index 45ca0522..3800afdc 100644 --- a/src/phasicFlow/random/randomReal/randomReal.hpp +++ b/src/phasicFlow/random/randomReal/randomReal.hpp @@ -18,50 +18,56 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __randomReal_hpp__ -#define __randomReal_hpp__ +#ifndef __RandomReal_hpp__ +#define __RandomReal_hpp__ + +//#include + +#include "randomReal.hpp" +#include "uniformRandomReal.hpp" -#include "types.hpp" -#include "virtualConstructor.hpp" namespace pFlow { - -class randomReal +template +class RandomReal +: + public randomReal { - protected: + DistributionType distribution_; + public: - TypeInfo("randomReal"); + // type info + TypeInfoTemplate("randomReal", DistributionType); - randomReal(word UNUSED(distribution)){} - create_vCtor + RandomReal(word distribution); + + add_vCtor ( randomReal, - word, - (word distribution), - (distribution) + RandomReal, + word ); - virtual ~randomReal()= default; + virtual ~RandomReal()= default; - virtual real randomNumber(real a, real b) = 0; + virtual real randomNumber(real a, real b)override; - virtual realx3 randomNumber(realx3 a, realx3 b) = 0; + virtual realx3 randomNumber(realx3 a, realx3 b)override; + - - - - static - uniquePtr create(word distribution); }; - } +#include "RandomReal.cpp" + + + #endif diff --git a/src/phasicFlow/streams/iStream/iOstream.cpp b/src/phasicFlow/streams/iStream/iOstream.cpp index 622ff494..33a1cc47 100644 --- a/src/phasicFlow/streams/iStream/iOstream.cpp +++ b/src/phasicFlow/streams/iStream/iOstream.cpp @@ -18,163 +18,43 @@ Licence: -----------------------------------------------------------------------------*/ - +#include "IOstream.hpp" #include "iOstream.hpp" -#include "token.hpp" +#include "error.hpp" -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void pFlow::iOstream::decrIndent() +unsigned int pFlow::IOstream::precision_ = 6; + +pFlow::word pFlow::IOstream::staticName_("IOstream"); + + +const pFlow::word& pFlow::IOstream::name() const { - if (!indentLevel_) - { - std::cerr - << "iOstream::decrIndent() : attempt to decrement 0 indent level\n"; - } - else - { - --indentLevel_; - } + return staticName_; } -pFlow::iOstream& pFlow::iOstream::writeWordKeyword(const word& kw) +pFlow::word& pFlow::IOstream::name() { - - indent(); - writeQuoted(kw, false); - - if (indentSize_ <= 1) + return staticName_; +} + +bool pFlow::IOstream::check(const char* operation) const +{ + return fatalCheck(operation); +} + + +bool pFlow::IOstream::fatalCheck(const char* operation) const +{ + const bool ok = !bad(); + + if (!ok) { - write(char(token::SPACE)); - return *this; + fatalErrorInFunction + << "error in IOstream " << name() << " for operation " << operation; + fatalExit; } - int32 nSpaces = entryIndentation_ - int32(kw.size()); - - // Could also increment by indentSize_ ... - if (nSpaces < 1) - { - nSpaces = 1; - } - - while (nSpaces--) - { - write(char(token::SPACE)); - } - - return *this; -} - - -pFlow::iOstream& pFlow::iOstream::beginBlock(const word& kw) -{ - indent(); write(kw); newLine(); - beginBlock(); - - return *this; -} - - -pFlow::iOstream& pFlow::iOstream::beginBlock() -{ - indent(); write(char(token::BEGIN_BLOCK)); newLine(); - incrIndent(); - - return *this; -} - - -pFlow::iOstream& pFlow::iOstream::endBlock() -{ - decrIndent(); - indent(); write(char(token::END_BLOCK)); newLine(); - - return *this; -} - - -pFlow::iOstream& pFlow::iOstream::endEntry() -{ - write(char(token::END_STATEMENT)); newLine(); - - return *this; -} - -//- Write a newLine to stream -pFlow::iOstream& pFlow::iOstream::newLine() -{ - write(char(token::NL)); - return *this; -} - -pFlow::iOstream& pFlow::iOstream::space -( - int32 n -) -{ - for(int32 i=0; i -#include "IOstream.hpp" +#include "bTypesFunctions.hpp" -const inline char* defaultColor = "\033[0m"; -const inline char* blackColor = "\033[30m"; -const inline char* redColor = "\033[31m"; -const inline char* greenColor = "\033[32m"; -const inline char* yellowColor = "\033[33m"; -const inline char* blueColor = "\033[34m"; -const inline char* magentaColor = "\033[35m"; -const inline char* cyanColor = "\033[36m"; -const inline char* whiteColor = "\033[37m"; +using std::ios_base; +using std::istream; +using std::ostream; -const inline char* boldChar = "\033[1m"; +using std::cin; +using std::cout; +using std::cerr; namespace pFlow { -// Forward Declarations -class token; - - - -class iOstream -: - public IOstream +class IOstream { + +public: + + + enum streamAccess : char + { + CLOSED = 0, //!< stream is not open + OPENED //!< stream is open + }; + + + //- Default precision + static unsigned int precision_; + protected: - // Protected Data + //- Name for any generic stream - normally treat as readonly + static word staticName_; - //- Indentation of the entry from the start of the keyword - static constexpr const unsigned short entryIndentation_ = 16; + streamAccess openClosed_; - //- Number of spaces per indent level - unsigned short indentSize_ = 4; + ios_base::iostate ioState_; - //- Current indent level - unsigned short indentLevel_ = 0; + + //- The file line + int32 lineNumber_; + + + // Protected Member Functions + + //- Set stream opened + void setOpened() + { + openClosed_ = OPENED; + } + + //- Set stream closed + void setClosed() + { + openClosed_ = CLOSED; + } + + //- Set stream state + void setState(ios_base::iostate state) + { + ioState_ = state; + } + + //- Set stream to be good + void setGood() + { + ioState_ = ios_base::iostate(0); + } public: - - // Constructor - explicit iOstream() - {} + // Constructors + explicit IOstream(): + openClosed_(CLOSED), + ioState_(ios_base::iostate(0)), + lineNumber_(0) + { + setBad(); + } - //- Copy construct - iOstream(const iOstream&) = default; + IOstream(const IOstream&) = default; //- Destructor - virtual ~iOstream() = default; + virtual ~IOstream() = default; + + + //// Member Functions + //- Return the name of the stream + virtual const word& name() const; - // Write Functions + //- Return non-const access to the name of the stream + virtual word& name(); - //- Write token to stream or otherwise handle it. - // \return false if the token type was not handled by this method - virtual bool write(const token& tok) = 0; + //- Check IOstream status for given operation. + // Print IOstream state or generate a FatalIOError + // when an error has occurred. + // The base implementation is a fatalCheck + virtual bool check(const char* operation) const; - //- Write character - virtual iOstream& write(const char c) = 0; + //- Check IOstream status for given operation. + // Generate a FatalIOError when an error has occurred. + bool fatalCheck(const char* operation) const; - //- Write character string - virtual iOstream& write(const char* str) = 0; + //- Return true if stream has been opened + bool opened() const + { + return openClosed_ == OPENED; + } - //- Write word - virtual iOstream& write(const word& str) = 0; + //- Return true if stream is closed + bool closed() const + { + return openClosed_ == CLOSED; + } + //- Return true if next operation might succeed + bool good() const + { + return ioState_ == 0; + } - //- Write std::string surrounded by quotes. - // Optional write without quotes. - virtual iOstream& writeQuoted + //- Return true if end of input seen + bool eof() const + { + return ioState_ & ios_base::eofbit; + } + + //- Return true if next operation will fail + bool fail() const + { + return ioState_ & (ios_base::badbit | ios_base::failbit); + } + + //- Return true if stream is corrupted + bool bad() const + { + return ioState_ & ios_base::badbit; + } + + //- Return true if the stream has not failed + explicit operator bool() const + { + return !fail(); + } + + //- Return true if the stream has failed + bool operator!() const + { + return fail(); + } + + + //- Const access to the current stream line number + int32 lineNumber() const + { + return lineNumber_; + } + + //- Non-const access to the current stream line number + int32& lineNumber() + { + return lineNumber_; + } + + //- Set the stream line number + // \return the previous value + int32 lineNumber(const int32 num) + { + const int32 old(lineNumber_); + lineNumber_ = num; + return old; + } + + //- Return flags of stream + virtual ios_base::fmtflags flags() const = 0; + + //- Return the default precision + static unsigned int defaultPrecision() + { + return precision_; + } + + //- Reset the default precision + // \return the previous value + static unsigned int defaultPrecision(unsigned int prec) + { + unsigned int old(precision_); + precision_ = prec; + return old; + } + + //- Set stream to have reached eof + void setEof() + { + ioState_ |= ios_base::eofbit; + } + + //- Set stream to have failed + void setFail() + { + ioState_ |= ios_base::failbit; + } + + //- Set stream to be bad + void setBad() + { + ioState_ |= ios_base::badbit; + } + + //- Set flags of stream + virtual ios_base::fmtflags flags(const ios_base::fmtflags f) = 0; + + //- Set flags of stream + ios_base::fmtflags setf(const ios_base::fmtflags f) + { + return flags(flags() | f); + } + + //- Set flags of given field of stream + ios_base::fmtflags setf ( - const word& str, - const bool quoted=true - ) = 0; - - - //- Write int64 - virtual iOstream& write(const int64 val) = 0; - - //- Write int32 - virtual iOstream& write(const int32 val) = 0; - - //- Write label - virtual iOstream& write(const label val) = 0; - - //- Write uint32 - virtual iOstream& write(const uint32 val) = 0; - - //- Write uint16 - virtual iOstream& write(const uint16 val) = 0; - - //- Write float - virtual iOstream& write(const float val) = 0; - - //- Write double - virtual iOstream& write(const double val) = 0; - - - - //- Add indentation characters - virtual void indent() = 0; - - //- Return indent level - unsigned short indentSize() const + const ios_base::fmtflags f, + const ios_base::fmtflags mask + ) { - return indentSize_; + return flags((flags() & ~mask) | (f & mask)); } - //- Access to indent size - unsigned short& indentSize() + //- Unset flags of stream + void unsetf(const ios_base::fmtflags f) { - return indentSize_; + flags(flags() & ~f); } - //- Return indent level - unsigned short indentLevel() const - { - return indentLevel_; - } - //- Access to indent level - unsigned short& indentLevel() - { - return indentLevel_; - } - - //- Increment the indent level - void incrIndent() - { - ++indentLevel_; - } - - //- Decrement the indent level - void decrIndent(); - - - - - //- Write begin block group with a name - // Increments indentation, adds newline. - virtual iOstream& beginBlock(const word& kw); - - //- Write begin block group without a name - // Increments indentation, adds newline. - virtual iOstream& beginBlock(); - - //- Write end block group - // Decrements indentation, adds newline. - virtual iOstream& endBlock(); - - //- Write begin list "(" - virtual iOstream& beginList(); - - //- Write begin list with keyword "kw (" - virtual iOstream& beginList(const word& kw); - - //- Write end list ")" - virtual iOstream& endList(); - - //- Write begin list "[" - virtual iOstream& beginSquare(); - - //- Write begin list with keyword "kw [" - virtual iOstream& beginSquare(const word& kw); - - //- Write end list "]" - virtual iOstream& endSquare(); - - //- Write end entry (';') followed by newline. - virtual iOstream& endEntry(); - - //- Write a newLine to stream - virtual iOstream& newLine(); - - //- Write space to stream - virtual iOstream& space(int32 n=1); - - - //- Write the keyword followed by an appropriate indentation - virtual iOstream& writeWordKeyword(const word& kw); - - //- Write a keyword/value entry. - template - iOstream& writeWordEntry(const word& key, const T& value) - { - writeWordKeyword(key) << value; - return endEntry(); - } - - //// Stream state functions - - //- Flush stream - virtual void flush() = 0; - - //- Add newline and flush stream - virtual void endl() = 0; - - //- Get padding character - virtual char fill() const = 0; - - //- Set padding character for formatted field up to field width - virtual char fill(const char fillch) = 0; - - //- Get width of output field - virtual int width() const = 0; - - //- Set width of output field (and return old width) - virtual int width(const int w) = 0; - - //- Get precision of output field - virtual int precision() const = 0; - - //- Set precision of output field (and return old precision) - virtual int precision(const int p) = 0; +}; // end of IOstream - // Member Operators +//- An IOstream manipulator +typedef IOstream& (*IOstreamManip)(IOstream&); - //- Return a non-const reference to const iOstream - // Needed for write functions where the stream argument is temporary: - // e.g. thing thisThing(OFstream("thingFileName")()); - iOstream& operator()() const - { - return const_cast(*this); - } -}; - - - -//- An iOstream manipulator -typedef iOstream& (*iOstreamManip)(iOstream&); - - -//- operator<< handling for manipulators without arguments -inline iOstream& operator<<(iOstream& os, iOstreamManip f) +inline IOstream& dec(IOstream& io) { - return f(os); + io.setf(ios_base::dec, ios_base::dec|ios_base::hex|ios_base::oct); + return io; } -//- operator<< handling for manipulators without arguments -inline iOstream& operator<<(iOstream& os, IOstreamManip f) +inline IOstream& hex(IOstream& io) { - f(os); - return os; + io.setf(ios_base::hex, ios_base::dec|ios_base::hex|ios_base::oct); + return io; +} + +inline IOstream& oct(IOstream& io) +{ + io.setf(ios_base::oct, ios_base::dec|ios_base::hex|ios_base::oct); + return io; +} + +inline IOstream& fixed(IOstream& io) +{ + io.setf(ios_base::fixed, ios_base::floatfield); + return io; +} + +inline IOstream& scientific(IOstream& io) +{ + io.setf(ios_base::scientific, ios_base::floatfield); + return io; } -//- Indent stream -inline iOstream& indent(iOstream& os) -{ - os.indent(); - return os; -} -//- Increment the indent level -inline iOstream& incrIndent(iOstream& os) -{ - os.incrIndent(); - return os; -} +} // pFlow -//- Decrement the indent level -inline iOstream& decrIndent(iOstream& os) -{ - os.decrIndent(); - return os; -} - - -//- Flush stream -inline iOstream& flush(iOstream& os) -{ - os.flush(); - return os; -} - - -//- Add newline and flush stream -inline iOstream& endl(iOstream& os) -{ - os.endl(); - return os; -} - - -//- Write begin block group without a name -// Increments indentation, adds newline. -inline iOstream& beginBlock(iOstream& os) -{ - os.beginBlock(); - return os; -} - - -//- Write end block group -// Decrements indentation, adds newline. -inline iOstream& endBlock(iOstream& os) -{ - os.endBlock(); - return os; -} - - -//- Write end entry (';') followed by newline. -inline iOstream& endEntry(iOstream& os) -{ - os.endEntry(); - return os; -} - - -// overloading for basic types -inline iOstream& operator<<( iOstream& os, const char c) -{ - return os.write(c); -} - -inline iOstream& operator<<( iOstream& os, const char * buf) -{ - return os.write(buf); -} - -inline iOstream& operator<<( iOstream& os, const word& w) -{ - return os.write(w); -} - - -inline iOstream& operator<<( iOstream& os, const int64& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const int32& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const int16& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const int8& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const label& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const uint32& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const uint16& val) -{ - return os.write(val); -} - -inline iOstream& operator<<( iOstream& os, const float& val) -{ - return os.write(val); -} - - -inline iOstream& operator<<( iOstream& os, const double& val) -{ - return os.write(val); -} -// Useful aliases for tab and newline characters -constexpr char tab = '\t'; -constexpr char nl = '\n'; - - - - -} // pFlow - - -#endif - -// ************************************************************************* // +#endif // __IOstream__hpp__ diff --git a/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.cpp b/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.cpp index fb36b661..f178026b 100644 --- a/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.cpp +++ b/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.cpp @@ -19,42 +19,45 @@ Licence: -----------------------------------------------------------------------------*/ -#include "peakableRegion.hpp" -#include "dictionary.hpp" - -pFlow::peakableRegion::peakableRegion +template +pFlow::PeakableRegion::PeakableRegion ( - const word& type, const dictionary& dict + const word& type, + const dictionary& dict ) +: + peakableRegion(type, dict), + region_(dict) { - CONSUME_PARAM(type); - CONSUME_PARAM(dict); + +} + +template +bool pFlow::PeakableRegion::isInside +( + const realx3& point +)const +{ + return region_.isInside(point); } -pFlow::uniquePtr pFlow::peakableRegion::create -( - const word& type, - const dictionary& dict -) +template +pFlow::realx3 pFlow::PeakableRegion::peek()const { - word regionType = angleBracketsNames("peakableRegion", type); + return region_.peek(); +} + +template +bool pFlow::PeakableRegion::read(const dictionary& dict) +{ + return region_.read(dict); +} + +template +bool pFlow::PeakableRegion::write(dictionary& dict)const +{ + return region_.write(dict); +} - if( wordvCtorSelector_.search(regionType) ) - { - return wordvCtorSelector_[regionType] (type, dict); - } - else - { - printKeys - ( - fatalError << "Ctor Selector "<< regionType << " dose not exist. \n" - <<"Avaiable ones are: \n\n" - , - wordvCtorSelector_ - ); - fatalExit; - } - return nullptr; -} \ No newline at end of file diff --git a/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.hpp b/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.hpp index 7f573572..eefecc19 100644 --- a/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.hpp +++ b/src/phasicFlow/structuredData/peakableRegion/peakableRegion/peakableRegion.hpp @@ -19,64 +19,72 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __peakableRegion_hpp__ -#define __peakableRegion_hpp__ +#ifndef __PeakableRegion_hpp__ +#define __PeakableRegion_hpp__ -#include "types.hpp" -#include "virtualConstructor.hpp" +#include "peakableRegion.hpp" +#include "dictionary.hpp" namespace pFlow { -class dictionary; -class peakableRegion + +template +class PeakableRegion +: + public peakableRegion { protected: - + RegionType region_; + public: // type info - TypeInfo("peakableRegion"); + TypeInfoTemplate("peakableRegion", RegionType); - peakableRegion(const word& type, const dictionary& dict); + //// - Constructors + PeakableRegion(const word& type, const dictionary& dict); - create_vCtor( + add_vCtor( peakableRegion, - word, - (const word& type, const dictionary& dict), - (type, dict) + PeakableRegion, + word ); - virtual uniquePtr clone()const = 0; + virtual uniquePtr clone()const override + { + return makeUnique>(*this); + } - virtual peakableRegion* clonePtr()const = 0; + virtual peakableRegion* clonePtr()const override + { + return new PeakableRegion(*this); + } - virtual ~peakableRegion() = default; + + virtual ~PeakableRegion() = default; //// - Methods - virtual bool isInside(const realx3& point)const = 0; + virtual bool isInside(const realx3& point)const override; - virtual realx3 peek()const = 0; + virtual realx3 peek()const override; //// - IO operatoins - virtual bool read(const dictionary& dict) = 0; + virtual bool read(const dictionary& dict) override; - virtual bool write(dictionary& dict)const = 0; - - // - static create - static uniquePtr - create(const word& type, const dictionary& dict); + virtual bool write(dictionary& dict)const override; }; } // pFlow +#include "PeakableRegion.cpp" #endif diff --git a/utilities/postprocessPhasicFlow/includeMask.hpp b/utilities/postprocessPhasicFlow/includeMask.hpp index 795a6d84..8e042ce5 100644 --- a/utilities/postprocessPhasicFlow/includeMask.hpp +++ b/utilities/postprocessPhasicFlow/includeMask.hpp @@ -18,87 +18,230 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __includeMask_hpp__ -#define __includeMask_hpp__ +#ifndef __IncludeMask_hpp__ +#define __IncludeMask_hpp__ -#include "virtualConstructor.hpp" -#include "readFromTimeFolder.hpp" -#include "dictionary.hpp" +#include "includeMask.hpp" namespace pFlow { -class includeMask +template +struct greaterThanOp +{ + TypeInfoNV("greaterThan"); + + inline + bool operator()(const T &compVal, const T &val) const { + return val > compVal; } +}; + +template +struct greaterThanEqOp +{ + TypeInfoNV("greaterThanEq"); + + inline + bool operator()(const T &compVal, const T &val) const { + return val >= compVal; } +}; + +template +struct lessThanOp +{ + TypeInfoNV("lessThan"); + + inline + bool operator()(const T &compVal, const T &val) const { + return val < compVal; } +}; + +template +struct lessThanEqOp +{ + TypeInfoNV("lessThanEq"); + + inline + bool operator()(const T &compVal, const T &val) const { + return val <= compVal; } +}; + +template +struct equalOp +{ + TypeInfoNV("equal"); + + inline + bool operator()(const T &compVal, const T &val) const { + return equal(val , compVal); } +}; + + +template +struct betweenOp +{ + TypeInfoNV("between"); + + inline + bool operator()(const T &compVal1, const T &compVal2 ,const T &val) const { + return val>compVal1 && val +struct betweenEqOp +{ + TypeInfoNV("betweenEq"); + + inline + bool operator()(const T &compVal1, const T &compVal2 ,const T &val) const { + return val>=compVal1 && val<=compVal2; } +}; + +template +struct allOp +{ + TypeInfoNV("all"); + + inline + bool operator()() const {return true; } +}; + + + +template class Operator> +class compareOne +{ +public: + + using opertorType = Operator; + +protected: + T compValue_{}; + opertorType operator_{}; +public: + + TypeInfoNV(Operator::TYPENAME()); + + compareOne(const dictionary& dict) + : + compValue_(dict.getVal("value")) + {} + + bool operator()(const T& value)const + { + return operator_(compValue_, value); + } +}; + +template class Operator> +class compareTwo +{ +public: + using opertorType = Operator; +protected: + T compValue1_; + T compValue2_; + opertorType operator_{}; +public: + + TypeInfoNV(opertorType::TYPENAME()); + + compareTwo(const dictionary& dict) + : + compValue1_(dict.getVal("value1")), + compValue2_(dict.getVal("value2")) + {} + + bool operator()(const T& value)const + { + return operator_(compValue1_, compValue2_, value); + } +}; + +template +class compareZero { protected: - word fieldName_; + Operator operator_{}; +public: - word fieldType_; + TypeInfoNV(Operator::TYPENAME()); + compareZero(const dictionary& dict); - word operatorType_; + bool operator()(const T& value) const + { + return operator_(); + } +}; - readFromTimeFolder& timeFolder_; - - static - bool getFieldType(const dictionary& dict, readFromTimeFolder& timeFolder, word& fName, word& fType); +template +class IncludeMask +: + public includeMask +{ +protected: + + Operator operator_; + + pointField_H field_; public: - TypeInfo("includeMask"); + TypeInfoTemplate2("IncludeMask", T, Operator); - includeMask(const dictionary& dict, const word& opType, readFromTimeFolder& timeFolder); - - virtual ~includeMask() = default; - - create_vCtor( - includeMask, - dictionary, - ( - const dictionary& dict, - const word& opType, - readFromTimeFolder& timeFolder - ), - (dict, opType, timeFolder) - ); - - word fieldName()const - { - return fieldName_; - } - - word fieldType()const - { - return fieldType_; - } - - word operatorType()const - { - return operatorType_; - } - - auto& timeFolder() - { - return timeFolder_; - } - - virtual bool isIncluded(int32 n) const = 0; - - bool operator()(int32 n) const - { - return isIncluded(n); - } - - static - uniquePtr create( + IncludeMask( const dictionary& dict, - const word& opType, - readFromTimeFolder& timeFolder); - + const word& opType, + readFromTimeFolder& timeFolder) + : + includeMask(dict, opType, timeFolder), + operator_(dict), + field_(timeFolder.readPointField_H(this->fieldName())) + {} + + add_vCtor( + includeMask, + IncludeMask, + dictionary); + + bool isIncluded(int32 n)const override + { + return operator_(field_[n]); + } + }; +template +class IncludeMask> +: + public includeMask +{ +public: + TypeInfoTemplate2("IncludeMask", T, allOp); + + IncludeMask( + const dictionary& dict, + const word& opType, + readFromTimeFolder& timeFolder) + : + includeMask(dict, opType, timeFolder) + {} + + add_vCtor( + includeMask, + IncludeMask, + dictionary); + + bool isIncluded(int32 n)const override + { + return true; + } +}; + } // pFlow diff --git a/utilities/postprocessPhasicFlow/processField.hpp b/utilities/postprocessPhasicFlow/processField.hpp index 9b4f67f6..5ee87687 100644 --- a/utilities/postprocessPhasicFlow/processField.hpp +++ b/utilities/postprocessPhasicFlow/processField.hpp @@ -18,152 +18,147 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __processField_hpp__ -#define __processField_hpp__ +#ifndef __ProcessField_hpp__ +#define __ProcessField_hpp__ -#include "virtualConstructor.hpp" -#include "dictionary.hpp" -#include "readFromTimeFolder.hpp" -#include "includeMask.hpp" -#include "pointRectCell.hpp" +#include "processField.hpp" +#include "rectMeshFields.hpp" +#include "twoPartEntry.hpp" +#include "fieldOperations.hpp" +#include "rectMeshFieldToVTK.hpp" namespace pFlow { -class repository; - -class processField +template +class ProcessField +: + public processField { + protected: - dictionary dict_; + pointField_H& field_; - pointRectCell& pointToCell_; - - mutable readFromTimeFolder timeFolder_; - word processedFieldName_; - - word fieldName_; - - word fieldType_; - - word operation_; - - word includeMaskType_; - - int32 threshold_ = 1; - - uniquePtr includeMask_ = nullptr; - - bool static getFieldType( - const dictionary& dict, - readFromTimeFolder& timeFolder, - word& fieldName, - word& fieldType); + rectMeshField_H& processedField_; public: - TypeInfo("processField"); - - processField(const dictionary& dict, pointRectCell& pToCell, repository& rep); + TypeInfoTemplate("ProcessField", T); - create_vCtor( - processField, - dictionary, - (const dictionary& dict, - pointRectCell& pToCell, - repository& rep), - (dict, pToCell, rep) ); - - - const auto& mesh()const - { - return pointToCell_.mesh(); - } - - const auto& pointToCell()const - { - return pointToCell_; - } - - auto& dict() - { - return dict_; - } - - const auto& dict()const - { - return dict_; - } - - auto& timeFolderRepository() - { - return timeFolder_.db(); - } - - auto& processedRepository() - { - return pointToCell_.processedRepository(); - } - - const word& fieldType()const - { - return fieldType_; - } - - const word& fieldName()const - { - return fieldName_; - } - - bool isUniform()const - { - return fieldName_ == "uniformField"; - } - - const word& operation()const - { - return operation_; - } - - auto& timeFolder() - { - return timeFolder_; - } - - const word& includeMaskType()const - { - return includeMaskType_; - } - - auto threshold()const - { - return threshold_; - } - - const word& processedFieldName()const - { - return processedFieldName_; - } - - // requires a class to read pointField from timefolder - virtual bool process() = 0; - - virtual bool writeToVTK(iOstream& is) const = 0; - - static - uniquePtr create( + ProcessField( const dictionary& dict, pointRectCell& pToCell, - repository& rep); + repository& rep) + : + processField(dict, pToCell, rep), + field_( + this->isUniform()? + timeFolder().createUniformPointField_H(this->fieldName(), getUniformValue() ): + timeFolder().readPointField_H(this->fieldName()) + ), + processedField_ + ( + processedRepository().emplaceObject> + ( + objectFile + ( + processedFieldName(), + "", + objectFile::READ_NEVER, + objectFile::WRITE_ALWAYS + ), + mesh(), + processedFieldName(), + T{} + ) + ) + { + + } + + add_vCtor( + processField, + ProcessField, + dictionary); + + + T getUniformValue()const + { + const dataEntry& entry = dict().dataEntryRef("field"); + twoPartEntry tpEntry(entry); + return tpEntry.secondPartVal(); + } + + virtual bool process() override + { + + const includeMask& incMask = includeMask_(); + + auto numerator = sumMaksOp( field_ , this->pointToCell(), incMask); + + rectMeshField_H denomerator( this->mesh(), real{} ); + + if(operation() == "sum") + { + denomerator = rectMeshField_H(this->mesh(), static_cast(1.0)); + + }else if(operation() == "average") + { + + pointField_H oneFld(field_.pStruct(), static_cast(1.0), static_cast(1.0)); + + denomerator = sumOp(oneFld, this->pointToCell()); + + }else if(operation() == "averageMask") + { + pointField_H oneFld(field_.pStruct(), static_cast(1.0), static_cast(1.0)); + + denomerator = sumMaksOp(oneFld, this->pointToCell(), incMask); + }else + { + fatalErrorInFunction<<"operation is not known: "<< operation()<mesh().nx(); i++ ) + { + for(int32 j=0; jmesh().ny(); j++ ) + { + for(int32 k=0; kmesh().nz(); k++ ) + { + if( pointToCell().nPointInCell(i,j,k)>= threshold() ) + { + processedField_(i,j,k) = numerator(i,j,k)/denomerator(i,j,k); + } + else + { + processedField_(i,j,k) = T{}; + } + } + } + } + + + return true; + } + + + bool writeToVTK(iOstream& os)const override + { + return convertRectMeshField(os, processedField_); + } + }; -} +} // pFlow -#endif //__processField_hpp__ \ No newline at end of file + +#endif //__ProcessField_hpp__