From 2733a58ed66cba0f45322d62e01c67b2f44041fe Mon Sep 17 00:00:00 2001 From: andy <andy> Date: Tue, 18 Dec 2012 09:28:28 +0000 Subject: [PATCH] ENH: basicSourtce - simplified setting of continuous operation --- src/fieldSources/basicSource/basicSource.C | 29 ++++++++++++++------- src/fieldSources/basicSource/basicSource.H | 4 +-- src/fieldSources/basicSource/basicSourceI.H | 14 +++++++--- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/fieldSources/basicSource/basicSource.C b/src/fieldSources/basicSource/basicSource.C index 64be60fa84e..7732f89f9a9 100644 --- a/src/fieldSources/basicSource/basicSource.C +++ b/src/fieldSources/basicSource/basicSource.C @@ -108,7 +108,6 @@ void Foam::basicSource::setSelection(const dictionary& dict) void Foam::basicSource::setCellSet() { - Info<< incrIndent << indent << "Source: " << name_ << endl; switch (selectionMode_) { case smPoints: @@ -237,7 +236,7 @@ void Foam::basicSource::setCellSet() Info<< indent << "- selected " << returnReduce(cells_.size(), sumOp<label>()) - << " cell(s) with volume " << V_ << nl << decrIndent << endl; + << " cell(s) with volume " << V_ << nl << endl; } } @@ -257,8 +256,8 @@ Foam::basicSource::basicSource dict_(dict), coeffs_(dict.subDict(modelType + "Coeffs")), active_(readBool(dict_.lookup("active"))), - timeStart_(readScalar(dict_.lookup("timeStart"))), - duration_(readScalar(dict_.lookup("duration"))), + timeStart_(-1.0), + duration_(0.0), selectionMode_ ( selectionModeTypeNames_.read(dict_.lookup("selectionMode")) @@ -273,9 +272,24 @@ Foam::basicSource::basicSource fieldNames_(), applied_() { + Info<< incrIndent << indent << "Source: " << name_ << endl; + + if (dict_.readIfPresent("timeStart", timeStart_)) + { + dict_.lookup("duration") >> duration_; + Info<< indent << "- applying source at time " << timeStart_ + << " for duration " << duration_ << endl; + } + else + { + Info<< indent<< "-applying source for all time" << endl; + } + setSelection(dict_); setCellSet(); + + Info<< decrIndent; } @@ -325,12 +339,7 @@ Foam::basicSource::~basicSource() bool Foam::basicSource::isActive() { - if - ( - active_ - && (mesh_.time().value() >= timeStart_) - && (mesh_.time().value() <= timeEnd()) - ) + if (active_ && inTimeLimits(mesh_.time().value())) { // Update the cell set if the mesh is changing if (mesh_.changing()) diff --git a/src/fieldSources/basicSource/basicSource.H b/src/fieldSources/basicSource/basicSource.H index 3e4740cead0..8c5543c48ab 100644 --- a/src/fieldSources/basicSource/basicSource.H +++ b/src/fieldSources/basicSource/basicSource.H @@ -277,8 +277,8 @@ public: //- Return const access to the duration inline scalar duration() const; - //- Return const access to the time end - inline scalar timeEnd() const; + //- Return true if within time limits + inline bool inTimeLimits(const scalar time) const; //- Return const access to the cell selection mode inline const selectionModeType& selectionMode() const; diff --git a/src/fieldSources/basicSource/basicSourceI.H b/src/fieldSources/basicSource/basicSourceI.H index 6ffc096defc..e77d808e3de 100644 --- a/src/fieldSources/basicSource/basicSourceI.H +++ b/src/fieldSources/basicSource/basicSourceI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -63,9 +63,17 @@ inline Foam::scalar Foam::basicSource::duration() const } -inline Foam::scalar Foam::basicSource::timeEnd() const +inline bool Foam::basicSource::inTimeLimits(const scalar time) const { - return timeStart_ + duration_; + return + ( + (timeStart_ < 0) + || + ( + (mesh_.time().value() >= timeStart_) + && (mesh_.time().value() <= (timeStart_ + duration_)) + ) + ); } -- GitLab