From 801fb7bd5f22aca0454d04b4c1677d8ba1e56046 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 27 Mar 2018 11:00:12 +0100 Subject: [PATCH] ENH: streamLine/wallBoundedStreamLine - minor refactoring to enable new derived functionality --- .../field/streamLine/streamLineBase.C | 253 ++++++++++-------- .../field/streamLine/streamLineBase.H | 23 +- .../wallBoundedStreamLine.C | 14 + .../wallBoundedStreamLine.H | 26 +- .../wallBoundedStreamLineParticle.H | 9 +- 5 files changed, 204 insertions(+), 121 deletions(-) diff --git a/src/functionObjects/field/streamLine/streamLineBase.C b/src/functionObjects/field/streamLine/streamLineBase.C index 0b74470c08..2359322ed3 100644 --- a/src/functionObjects/field/streamLine/streamLineBase.C +++ b/src/functionObjects/field/streamLine/streamLineBase.C @@ -141,11 +141,11 @@ void Foam::functionObjects::streamLineBase::initInterpolations { if (foundObject(fieldName)) { - nScalar++; + ++nScalar; } else if (foundObject(fieldName)) { - nVector++; + ++nVector; } else { @@ -509,114 +509,8 @@ void Foam::functionObjects::streamLineBase::trimToBox(const treeBoundBox& bb) } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::functionObjects::streamLineBase::streamLineBase -( - const word& name, - const Time& runTime, - const dictionary& dict -) -: - fvMeshFunctionObject(name, runTime, dict), - dict_(dict) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::functionObjects::streamLineBase::~streamLineBase() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::functionObjects::streamLineBase::read(const dictionary& dict) +bool Foam::functionObjects::streamLineBase::writeToFile() { - if (&dict_ != &dict) - { - // Update local copy of dictionary: - dict_ = dict; - } - - fvMeshFunctionObject::read(dict); - - Info<< type() << " " << name() << ":" << nl; - - dict.lookup("fields") >> fields_; - UName_ = dict.lookupOrDefault("U", "U"); - - Info<< " Employing velocity field " << UName_ << endl; - - if (!fields_.found(UName_)) - { - FatalIOErrorInFunction(dict) - << "Velocity field for tracking " << UName_ - << " should be present in the list of fields " << fields_ - << exit(FatalIOError); - } - - - dict.lookup("trackForward") >> trackForward_; - dict.lookup("lifeTime") >> lifeTime_; - if (lifeTime_ < 1) - { - FatalErrorInFunction - << "Illegal value " << lifeTime_ << " for lifeTime" - << exit(FatalError); - } - - - trackLength_ = VGREAT; - if (dict.readIfPresent("trackLength", trackLength_)) - { - Info<< type() << " : fixed track length specified : " - << trackLength_ << nl << endl; - } - - - bounds_ = boundBox::invertedBox; - if (dict.readIfPresent("bounds", bounds_) && !bounds_.empty()) - { - Info<< " clipping all segments to " << bounds_ << nl << endl; - } - - - interpolationScheme_ = dict.lookupOrDefault - ( - "interpolationScheme", - interpolationCellPoint::typeName - ); - - //Info<< " using interpolation " << interpolationScheme_ << endl; - - cloudName_ = dict.lookupOrDefault("cloud", type()); - - sampledSetPtr_.clear(); - sampledSetAxis_.clear(); - - scalarFormatterPtr_ = writer::New(dict.lookup("setFormat")); - vectorFormatterPtr_ = writer::New(dict.lookup("setFormat")); - - return true; -} - - -bool Foam::functionObjects::streamLineBase::execute() -{ - return true; -} - - -bool Foam::functionObjects::streamLineBase::write() -{ - Log << type() << " " << name() << " write:" << nl; - - - // Do all injection and tracking - track(); - - if (Pstream::parRun()) { // Append slave tracks to master ones @@ -897,6 +791,147 @@ bool Foam::functionObjects::streamLineBase::write() } +void Foam::functionObjects::streamLineBase::resetFieldNames +( + const word& newUName, + const wordList& newFieldNames +) +{ + UName_ = newUName; + fields_ = newFieldNames; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::streamLineBase::streamLineBase +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + dict_(dict), + fields_() +{} + + +Foam::functionObjects::streamLineBase::streamLineBase +( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames +) +: + fvMeshFunctionObject(name, runTime, dict), + dict_(dict), + fields_(fieldNames) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::streamLineBase::~streamLineBase() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::streamLineBase::read(const dictionary& dict) +{ + if (&dict_ != &dict) + { + // Update local copy of dictionary: + dict_ = dict; + } + + fvMeshFunctionObject::read(dict); + + Info<< type() << " " << name() << ":" << nl; + + UName_ = dict.lookupOrDefault("U", "U"); + + if (fields_.empty()) + { + dict.lookup("fields") >> fields_; + + if (!fields_.found(UName_)) + { + FatalIOErrorInFunction(dict) + << "Velocity field for tracking " << UName_ + << " should be present in the list of fields " << fields_ + << exit(FatalIOError); + } + } + + Info<< " Employing velocity field " << UName_ << endl; + + dict.lookup("trackForward") >> trackForward_; + dict.lookup("lifeTime") >> lifeTime_; + if (lifeTime_ < 1) + { + FatalErrorInFunction + << "Illegal value " << lifeTime_ << " for lifeTime" + << exit(FatalError); + } + + + trackLength_ = VGREAT; + if (dict.readIfPresent("trackLength", trackLength_)) + { + Info<< type() << " : fixed track length specified : " + << trackLength_ << nl << endl; + } + + + bounds_ = boundBox::invertedBox; + if (dict.readIfPresent("bounds", bounds_) && !bounds_.empty()) + { + Info<< " clipping all segments to " << bounds_ << nl << endl; + } + + + interpolationScheme_ = dict.lookupOrDefault + ( + "interpolationScheme", + interpolationCellPoint::typeName + ); + + //Info<< " using interpolation " << interpolationScheme_ << endl; + + cloudName_ = dict.lookupOrDefault("cloud", type()); + + sampledSetPtr_.clear(); + sampledSetAxis_.clear(); + + scalarFormatterPtr_ = writer::New(dict.lookup("setFormat")); + vectorFormatterPtr_ = writer::New(dict.lookup("setFormat")); + + return true; +} + + +bool Foam::functionObjects::streamLineBase::execute() +{ + return true; +} + + +bool Foam::functionObjects::streamLineBase::write() +{ + Log << type() << " " << name() << " write:" << nl; + + // Do all injection and tracking + track(); + + writeToFile(); + + return true; +} + + void Foam::functionObjects::streamLineBase::updateMesh(const mapPolyMesh& mpm) { if (&mpm.mesh() == &mesh_) diff --git a/src/functionObjects/field/streamLine/streamLineBase.H b/src/functionObjects/field/streamLine/streamLineBase.H index 881ef4d140..292a7eb907 100644 --- a/src/functionObjects/field/streamLine/streamLineBase.H +++ b/src/functionObjects/field/streamLine/streamLineBase.H @@ -63,7 +63,7 @@ class streamLineBase : public fvMeshFunctionObject { - // Private data +protected: //- Seed set engine mutable autoPtr sampledSetPtr_; @@ -71,8 +71,6 @@ class streamLineBase //- Axis of the sampled points to output mutable word sampledSetAxis_; -protected: - //- Input dictionary dictionary dict_; @@ -184,6 +182,16 @@ protected: //- Do the actual tracking to fill the track data virtual void track() = 0; + //- Write tracks to file + virtual bool writeToFile(); + + //- Reset the field names + virtual void resetFieldNames + ( + const word& newUName, + const wordList& newFieldNames + ); + public: @@ -202,6 +210,15 @@ public: const dictionary& dict ); + //- Construct from Time and dictionary and list of fields to sample + streamLineBase + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames + ); + //- Destructor virtual ~streamLineBase(); diff --git a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C index 894f41d6d5..35adfda92d 100644 --- a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C +++ b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C @@ -236,6 +236,20 @@ Foam::functionObjects::wallBoundedStreamLine::wallBoundedStreamLine } +Foam::functionObjects::wallBoundedStreamLine::wallBoundedStreamLine +( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames +) +: + streamLineBase(name, runTime, dict, fieldNames) +{ + read(dict_); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::functionObjects::wallBoundedStreamLine::~wallBoundedStreamLine() diff --git a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H index 69d619cafb..155ddceb29 100644 --- a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H +++ b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H @@ -125,6 +125,17 @@ class wallBoundedStreamLine { // Private Member Functions + //- Disallow default bitwise copy construct + wallBoundedStreamLine(const wallBoundedStreamLine&) = delete; + + //- Disallow default bitwise assignment + void operator=(const wallBoundedStreamLine&) = delete; + + +protected: + + // Protected Member Functions + //- Find wall tet on cell tetIndices findNearestTet ( @@ -133,12 +144,6 @@ class wallBoundedStreamLine const label celli ) const; - //- Disallow default bitwise copy construct - wallBoundedStreamLine(const wallBoundedStreamLine&) = delete; - - //- Disallow default bitwise assignment - void operator=(const wallBoundedStreamLine&) = delete; - public: @@ -156,6 +161,15 @@ public: const dictionary& dict ); + //- Construct from Time and dictionary and list of fields to sample + wallBoundedStreamLine + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const wordList& fieldNames + ); + //- Destructor virtual ~wallBoundedStreamLine(); diff --git a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H index 406468e1cb..b8189d6b24 100644 --- a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H +++ b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H @@ -121,12 +121,15 @@ public: allScalars_(allScalars), allVectors_(allVectors) {} + + virtual ~trackingData() + {} }; -private: +protected: - // Private data + // Protected data //- Lifetime of particle. Particle dies when reaches 0. label lifeTime_; @@ -141,7 +144,7 @@ private: List> sampledVectors_; - // Private Member Functions + // Protected Member Functions vector interpolateFields (