From 175e8bf27eb6a2491eaa146eb9b3b9fd5e8cb707 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 1 Nov 2011 15:23:51 +0000 Subject: [PATCH 1/8] ENH: Aligned finite volume sources - now all derived from basicSource --- src/finiteVolume/Make/files | 15 +- .../actuationDiskSource/actuationDiskSource.C | 41 +- .../actuationDiskSource/actuationDiskSource.H | 17 +- .../basicSource/basicSource/basicSource.C | 98 ++++- .../basicSource/basicSource/basicSource.H | 87 +++- .../basicSource/basicSource/basicSourceI.H | 6 +- .../basicSource/basicSource/basicSourceList.C | 64 +-- .../basicSource/basicSource/basicSourceList.H | 20 +- .../basicSourceListTemplates.C} | 45 +- .../explicitSetValue/explicitSetValue.C | 32 +- .../explicitSetValue/explicitSetValue.H | 31 +- .../explicitSetValue/explicitSetValueIO.C | 12 +- .../explicitSetValueTemplates.C | 6 +- .../explicitSource/ExplicitSource.C | 184 ++++++++ .../{explicitSource.H => ExplicitSource.H} | 154 +++---- .../ExplicitSourceI.H} | 31 +- .../{explicitSourceI.H => ExplicitSourceIO.C} | 27 +- .../explicitSource/explicitSource.C | 109 +---- .../explicitSource/explicitSourceTemplates.C | 104 ----- .../explicitSource/makeBasicSource.H} | 45 +- .../pressureGradientExplicitSource.C | 232 +++++------ .../pressureGradientExplicitSource.H | 73 ++-- .../pressureGradientExplicitSourceIO.C} | 34 +- .../radialActuationDiskSource.C | 36 +- .../radialActuationDiskSource.H | 7 +- .../radialActuationDiskSourceTemplates.C | 13 +- .../rotorDiskSource/rotorDiskSource.C | 47 ++- .../rotorDiskSource/rotorDiskSource.H | 15 +- .../TimeActivatedExplicitSource.C | 389 ----------------- .../TimeActivatedExplicitSource.H | 392 ------------------ .../TimeActivatedExplicitSourceI.H | 228 ---------- .../TimeActivatedExplicitSourceIO.C | 101 ----- .../TimeActivatedExplicitSourceList.C | 222 ---------- .../TimeActivatedExplicitSourceList.H | 171 -------- 34 files changed, 850 insertions(+), 2238 deletions(-) rename src/finiteVolume/cfdTools/general/fieldSources/basicSource/{explicitSource/explicitSourceIO.C => basicSource/basicSourceListTemplates.C} (68%) create mode 100644 src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.C rename src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/{explicitSource.H => ExplicitSource.H} (57%) rename src/finiteVolume/cfdTools/general/fieldSources/basicSource/{explicitSetValue/explicitSetValueI.H => explicitSource/ExplicitSourceI.H} (70%) rename src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/{explicitSourceI.H => ExplicitSourceIO.C} (76%) delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceTemplates.C rename src/finiteVolume/cfdTools/general/fieldSources/{timeActivatedExplicitSource/timeActivatedExplicitSource.H => basicSource/explicitSource/makeBasicSource.H} (53%) rename src/finiteVolume/cfdTools/general/fieldSources/{ => basicSource}/pressureGradientExplicitSource/pressureGradientExplicitSource.C (56%) rename src/finiteVolume/cfdTools/general/fieldSources/{ => basicSource}/pressureGradientExplicitSource/pressureGradientExplicitSource.H (68%) rename src/finiteVolume/cfdTools/general/fieldSources/{timeActivatedExplicitSource/timeActivatedExplicitSource.C => basicSource/pressureGradientExplicitSource/pressureGradientExplicitSourceIO.C} (69%) delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.C delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.H delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceI.H delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceIO.C delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceList.C delete mode 100644 src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceList.H diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index d30f23b9bd..6ee60166c8 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -378,19 +378,20 @@ $(SRF)/SRFModel/rpm/rpm.C $(SRF)/derivedFvPatchFields/SRFVelocityFvPatchVectorField/SRFVelocityFvPatchVectorField.C $(SRF)/derivedFvPatchFields/SRFFreestreamVelocityFvPatchVectorField/SRFFreestreamVelocityFvPatchVectorField.C -fieldSources = $(general)/fieldSources -$(fieldSources)/pressureGradientExplicitSource/pressureGradientExplicitSource.C -$(fieldSources)/timeActivatedExplicitSource/timeActivatedExplicitSource.C - basicSource = $(general)/fieldSources/basicSource $(basicSource)/basicSource/basicSource.C $(basicSource)/basicSource/basicSourceIO.C $(basicSource)/basicSource/basicSourceList.C $(basicSource)/basicSource/IObasicSourceList.C -$(basicSource)/actuationDiskSource/actuationDiskSource.C -$(basicSource)/radialActuationDiskSource/radialActuationDiskSource.C + +$(basicSource)/pressureGradientExplicitSource/pressureGradientExplicitSource.C +$(basicSource)/pressureGradientExplicitSource/pressureGradientExplicitSourceIO.C + $(basicSource)/explicitSource/explicitSource.C + $(basicSource)/explicitSetValue/explicitSetValue.C +$(basicSource)/explicitSetValue/explicitSetValueIO.C + $(basicSource)/rotorDiskSource/rotorDiskSource.C $(basicSource)/rotorDiskSource/bladeModel/bladeModel.C $(basicSource)/rotorDiskSource/profileModel/profileModel.C @@ -398,5 +399,7 @@ $(basicSource)/rotorDiskSource/profileModel/profileModelList.C $(basicSource)/rotorDiskSource/profileModel/lookup/lookupProfile.C $(basicSource)/rotorDiskSource/profileModel/series/seriesProfile.C +$(basicSource)/actuationDiskSource/actuationDiskSource.C +$(basicSource)/radialActuationDiskSource/radialActuationDiskSource.C LIB = $(FOAM_LIBBIN)/libfiniteVolume diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.C index e7e996d1db..27b91a854a 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.C @@ -35,7 +35,12 @@ License namespace Foam { defineTypeNameAndDebug(actuationDiskSource, 0); - addToRunTimeSelectionTable(basicSource, actuationDiskSource, dictionary); + addToRunTimeSelectionTable + ( + basicSource, + actuationDiskSource, + dictionary + ); } @@ -75,7 +80,6 @@ Foam::actuationDiskSource::actuationDiskSource ) : basicSource(name, modelType, dict, mesh), - coeffs_(dict.subDict(modelType + "Coeffs")), diskDir_(coeffs_.lookup("diskDir")), Cp_(readScalar(coeffs_.lookup("Cp"))), Ct_(readScalar(coeffs_.lookup("Ct"))), @@ -90,17 +94,35 @@ Foam::actuationDiskSource::actuationDiskSource // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::actuationDiskSource::addSu(fvMatrix& UEqn) +Foam::label Foam::actuationDiskSource::applyToField +( + const word& fieldName +) const +{ + if (fieldName == fieldName_) + { + return 0; + } + + return -1; +} + + +void Foam::actuationDiskSource::addSup +( + fvMatrix& eqn, + const label +) { bool compressible = false; - if (UEqn.dimensions() == dimensionSet(1, 1, -2, 0, 0)) + if (eqn.dimensions() == dimForce) { compressible = true; } - const scalarField& cellsV = this->mesh().V(); - vectorField& Usource = UEqn.source(); - const vectorField& U = UEqn.psi(); + const scalarField& cellsV = mesh_.V(); + vectorField& Usource = eqn.source(); + const vectorField& U = eqn.psi(); if (V() > VSMALL) { @@ -111,7 +133,7 @@ void Foam::actuationDiskSource::addSu(fvMatrix& UEqn) Usource, cells_, cellsV, - this->mesh().lookupObject("rho"), + mesh_.lookupObject("rho"), U ); } @@ -133,7 +155,7 @@ void Foam::actuationDiskSource::addSu(fvMatrix& UEqn) void Foam::actuationDiskSource::writeData(Ostream& os) const { os << indent << name_ << endl; - dict_.write(os); + coeffs_.write(os); } @@ -141,7 +163,6 @@ bool Foam::actuationDiskSource::read(const dictionary& dict) { if (basicSource::read(dict)) { - coeffs_ = dict.subDict(typeName + "Coeffs"); coeffs_.readIfPresent("diskDir", diskDir_); coeffs_.readIfPresent("Cp", Cp_); coeffs_.readIfPresent("Ct", Ct_); diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.H index cbe98ea4c8..1be5babe3f 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/actuationDiskSource/actuationDiskSource.H @@ -74,8 +74,8 @@ protected: // Protected data - //- Coefficients dictionary - dictionary coeffs_; + //- Name of field to apply source upon + word fieldName_; //- Disk area normal vector diskDir_; @@ -140,6 +140,12 @@ public: // Member Functions + // Check + + //- Return index of field name if found in fieldNames list + virtual label applyToField(const word& fieldName) const; + + // Access //- Return Cp @@ -169,11 +175,8 @@ public: // Public Functions - //-Source term to fvMatrix - virtual void addSu(fvMatrix& UEqn); - - //-Source term to fvMatrix - virtual void addSu(fvMatrix& UEqn){} + //- Source term to fvMatrix + virtual void addSup(fvMatrix& eqn, const label fieldI); // I-O diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.C index cd7394a173..4f975249fe 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.C @@ -118,7 +118,7 @@ void Foam::basicSource::setCellSet() { WarningIn ( - "TimeActivatedExplicitSource::setCellIds()" + "basicSource::setCellIds()" ) << "Unable to find owner cell for point " << points_[i] << endl; @@ -148,7 +148,7 @@ void Foam::basicSource::setCellSet() label zoneID = mesh_.cellZones().findZoneID(cellSetName_); if (zoneID == -1) { - FatalErrorIn("basicSource::setCellIds()") + FatalErrorIn("basicSource::setCellIds()") << "Cannot find cellZone " << cellSetName_ << endl << "Valid cellZones are " << mesh_.cellZones().names() << exit(FatalError); @@ -166,7 +166,7 @@ void Foam::basicSource::setCellSet() } default: { - FatalErrorIn("basicSource::setCellIds()") + FatalErrorIn("basicSource::setCellIds()") << "Unknown selectionMode " << selectionModeTypeNames_[selectionMode_] << ". Valid selectionMode types are" << selectionModeTypeNames_ @@ -194,24 +194,24 @@ Foam::basicSource::basicSource ( const word& name, const word& modelType, - const dictionary& dict, + const dictionary& coeffs, const fvMesh& mesh ) : name_(name), mesh_(mesh), - dict_(dict), - active_(readBool(dict_.lookup("active"))), - timeStart_(readScalar(dict_.lookup("timeStart"))), - duration_(readScalar(dict_.lookup("duration"))), + coeffs_(coeffs), + active_(readBool(coeffs_.lookup("active"))), + timeStart_(readScalar(coeffs_.lookup("timeStart"))), + duration_(readScalar(coeffs_.lookup("duration"))), selectionMode_ ( - selectionModeTypeNames_.read(dict_.lookup("selectionMode")) + selectionModeTypeNames_.read(coeffs_.lookup("selectionMode")) ), cellSetName_("none"), V_(0.0) { - setSelection(dict_); + setSelection(coeffs_); setCellSet(); } @@ -222,11 +222,11 @@ Foam::basicSource::basicSource Foam::autoPtr Foam::basicSource::New ( const word& name, - const dictionary& dict, + const dictionary& coeffs, const fvMesh& mesh ) { - word modelType(dict.lookup("type")); + word modelType(coeffs.lookup("type")); Info<< "Selecting model type " << modelType << endl; @@ -237,16 +237,16 @@ Foam::autoPtr Foam::basicSource::New { FatalErrorIn ( - "basicSource::New(const volVectorField&, " - "const surfaceScalarField&, transportModel&)" + "basicSource::New" + "(const name&, const dictionary&, const fvMesh&)" ) << "Unknown Model type " << modelType << nl << nl - << "Valid model types are :" << nl + << "Valid model types are:" << nl << dictionaryConstructorTablePtr_->sortedToc() << exit(FatalError); } - return autoPtr(cstrIter()(name, modelType, dict, mesh)); + return autoPtr(cstrIter()(name, modelType, coeffs, mesh)); } @@ -275,21 +275,75 @@ bool Foam::basicSource::isActive() } -void Foam::basicSource::addSu(Foam::fvMatrix& Eqn) +void Foam::basicSource::addSup(fvMatrix& eqn, const label fieldI) { - notImplemented("Foam::basicSource addSu(Foam::fvMatrix& Eqn)"); + // do nothing } -void Foam::basicSource::addSu(Foam::fvMatrix& Eqn) +void Foam::basicSource::addSup(fvMatrix& eqn, const label fieldI) { - notImplemented("Foam::basicSource addSu(Foam::fvMatrix& Eqn)"); + // do nothing } -void Foam::basicSource::setValue(Foam::fvMatrix& Eqn) +void Foam::basicSource::addSup +( + fvMatrix& eqn, + const label fieldI +) { - notImplemented("Foam::basicSource setValue(Foam::fvMatrix& Eqn)"); + // do nothing +} + + +void Foam::basicSource::addSup(fvMatrix& eqn, const label fieldI) +{ + // do nothing +} + + +void Foam::basicSource::addSup(fvMatrix& eqn, const label fieldI) +{ + // do nothing +} + + +void Foam::basicSource::setValue(fvMatrix& eqn, const label fieldI) +{ + // do nothing +} + + +void Foam::basicSource::setValue(fvMatrix& eqn, const label fieldI) +{ + // do nothing +} + + +void Foam::basicSource::setValue +( + fvMatrix& eqn, + const label fieldI +) +{ + // do nothing +} + + +void Foam::basicSource::setValue +( + fvMatrix& eqn, + const label fieldI +) +{ + // do nothing +} + + +void Foam::basicSource::setValue(fvMatrix& eqn, const label fieldI) +{ + // do nothing } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.H index 9862282479..52148c3ceb 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSource.H @@ -129,11 +129,14 @@ protected: const fvMesh& mesh_; //- Dictionary containing the data of the source - const dictionary& dict_; + dictionary coeffs_; //- Source active flag bool active_; + //- Flag to indicate whether or not the source has been applied +// bool applied_; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //- Time start scalar timeStart_; @@ -271,7 +274,7 @@ public: inline const fvMesh& mesh() const; //- Return dictionary - inline const dictionary& dictCoeffs() const; + inline const dictionary& coeffs() const; //- Return const access to the source active flag inline bool active() const; @@ -316,18 +319,86 @@ public: //- Is the source active? bool isActive(); + //- Return index of field name if found in fieldNames list + virtual label applyToField(const word& fieldName) const = 0; + // Evaluation - //- Add source term to vector fvMatrix - virtual void addSu(fvMatrix& Eqn); + // Add explicit and implicit contributions - //- Add source term to scalar fvMatrix - virtual void addSu(fvMatrix& Eqn); + //- Scalar + virtual void addSup + ( + fvMatrix& eqn, + const label fieldI + ); - //- Set constant value on field - virtual void setValue(fvMatrix& Eq); + //- Vector + virtual void addSup + ( + fvMatrix& eqn, + const label fieldI + ); + //- Spherical tensor + virtual void addSup + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Symmetric tensor + virtual void addSup + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Tensor + virtual void addSup + ( + fvMatrix& eqn, + const label fieldI + ); + + + // Set values directly + + //- Scalar + virtual void setValue + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Vector + virtual void setValue + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Spherical tensor + virtual void setValue + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Symmetric tensor + virtual void setValue + ( + fvMatrix& eqn, + const label fieldI + ); + + //- Tensor + virtual void setValue + ( + fvMatrix& eqn, + const label fieldI + ); // I-O diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceI.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceI.H index e7a126d5c9..127db8a60f 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceI.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceI.H @@ -38,11 +38,13 @@ inline const Foam::fvMesh& Foam::basicSource::mesh() const return mesh_; } -inline const Foam::dictionary& Foam::basicSource::dictCoeffs() const + +inline const Foam::dictionary& Foam::basicSource::coeffs() const { - return dict_; + return coeffs_; } + inline bool Foam::basicSource::active() const { return active_; diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.C index 79af025143..4fb8a8a0d8 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.C @@ -24,6 +24,14 @@ License \*---------------------------------------------------------------------------*/ #include "basicSourceList.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(basicSourceList, 0); +} // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -50,59 +58,23 @@ Foam::basicSourceList::basicSourceList label i = 0; forAllConstIter(dictionary, dict, iter) { - const word& name = iter().keyword(); - const dictionary& sourceDict = iter().dict(); + if (iter().isDict()) + { + const word& name = iter().keyword(); + const dictionary& sourceDict = iter().dict(); - this->set - ( - i++, - basicSource::New(name, sourceDict, mesh) - ); + this->set + ( + i++, + basicSource::New(name, sourceDict, mesh) + ); + } } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::basicSourceList::addSu(fvMatrix& Eqn) -{ - forAll(*this, i) - { - if (this->operator[](i).isActive()) - { - this->operator[](i).addSu(Eqn); - } - } -} - - -void Foam::basicSourceList::addSu(fvMatrix& Eqn) -{ - - forAll(*this, i) - { - if (this->operator[](i).isActive()) - { - this->operator[](i).addSu(Eqn); - } - } -} - - -void Foam::basicSourceList::setValue(fvMatrix& Eqn) -{ - - forAll(*this, i) - { - if (this->operator[](i).isActive()) - { - this->operator[](i).setValue(Eqn); - } - } -} - - bool Foam::basicSourceList::read(const dictionary& dict) { bool allOk = true; diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.H index 30e6501de1..956c5fe4c8 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceList.H @@ -71,6 +71,10 @@ private: public: + //- Runtime type information + TypeName("basicSourceList"); + + // Constructors //- Construct from components with list of field names @@ -86,14 +90,8 @@ public: // Evaluation - //- Add source terms to scalar fvMatrix - void addSu(fvMatrix& Eq); - - //- Add source terms to vector fvMatrix - void addSu(fvMatrix& Eq); - - //- Set constant value on field - void setValue(fvMatrix& Eq); + template + void apply(fvMatrix& eqn); // I-O @@ -119,6 +117,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "basicSourceListTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceIO.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceListTemplates.C similarity index 68% rename from src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceIO.C rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceListTemplates.C index f97ad32906..51ac28bd97 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceIO.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/basicSource/basicSourceListTemplates.C @@ -23,38 +23,31 @@ License \*---------------------------------------------------------------------------*/ -#include "explicitSource.H" - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::explicitSource::writeData(Ostream& os) const +template +void Foam::basicSourceList::apply(fvMatrix& eqn) { - os << indent << name_ << endl; - dict_.write(os); -} + const word& fieldName = eqn.psi().name(); - -bool Foam::explicitSource::read(const dictionary& dict) -{ - if (basicSource::read(dict)) + forAll(*this, i) { - coeffs_ = dict.subDict(typeName + "Coeffs"); - setFieldData(coeffs_.subDict("fieldData")); - return true; + basicSource& source = this->operator[](i); + + label fieldI = source.applyToField(fieldName); + + if (source.isActive() && (fieldI != -1)) + { + if (debug) + { + Info<< "Applying source " << source.name() << " to field " + << fieldName << endl; + } + + source.addSup(eqn, fieldI); + source.setValue(eqn, fieldI); + } } - else - { - return false; - } -} - - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const explicitSource& source) -{ - source.writeData(os); - return os; } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.C index 898f2c41c3..cb778fcae8 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.C @@ -61,7 +61,7 @@ void Foam::explicitSetValue::setFieldData(const dictionary& dict) fieldName, this->mesh().time().timeName(), this->mesh(), - IOobject::NO_READ, + IOobject::MUST_READ, IOobject::NO_WRITE, false ); @@ -93,22 +93,40 @@ Foam::explicitSetValue::explicitSetValue const fvMesh& mesh ) : - basicSource(name, modelType, dict, mesh), - coeffs_(dict.subDict(modelType + "Coeffs")) + basicSource(name, modelType, dict, mesh) { setFieldData(coeffs_.subDict("fieldData")); } -void Foam::explicitSetValue::setValue(fvMatrix& Eqn) +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::label Foam::explicitSetValue::applyToField +( + const word& fieldName +) const { - setFieldValue(Eqn, scalarFields_[Eqn.psi().name()]); + notImplemented("Foam::explicitSetValue::applyToField(const word&)"); } -void Foam::explicitSetValue::setValue(fvMatrix& Eqn) +void Foam::explicitSetValue::setValue +( + fvMatrix& eqn, + const label +) { - setFieldValue(Eqn, vectorFields_[Eqn.psi().name()]); + setFieldValue(eqn, scalarFields_[eqn.psi().name()]); +} + + +void Foam::explicitSetValue::setValue +( + fvMatrix& eqn, + const label +) +{ + setFieldValue(eqn, vectorFields_[eqn.psi().name()]); } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.H index df3d404f1a..6effb616a3 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValue.H @@ -87,12 +87,6 @@ class explicitSetValue protected: - // Protected data - - //- Coefficients dictionary - dictionary coeffs_; - - // Protected functions //- Set the local field data @@ -126,20 +120,19 @@ public: // Member Functions + // Check - // Edit - - //- Return points - inline const List& points() const; + //- Return index of field name if found in fieldNames list + virtual label applyToField(const word& fieldName) const; // Evaluation //- Set value on vector field - virtual void setValue(fvMatrix& UEqn); + virtual void setValue(fvMatrix& eqn, const label fieldI); //- Set value on scalar field - virtual void setValue(fvMatrix& UEqn); + virtual void setValue(fvMatrix& eqn, const label fieldI); // I-O @@ -147,15 +140,8 @@ public: //- Write the source properties virtual void writeData(Ostream&) const; - //- Read fieldData in sub-dictionary + //- Read source dictionary virtual bool read(const dictionary& dict); - - //- Ostream operator - friend Ostream& operator<< - ( - Ostream& os, - const explicitSetValue& source - ); }; @@ -165,11 +151,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "explicitSetValueIO.C" -#include "explicitSetValueI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #ifdef NoRepository # include "explicitSetValueTemplates.C" #endif diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueIO.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueIO.C index 24e9205606..45d56fc783 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueIO.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueIO.C @@ -30,7 +30,7 @@ License void Foam::explicitSetValue::writeData(Ostream& os) const { os << indent << name_ << endl; - dict_.write(os); + coeffs_.write(os); } @@ -38,7 +38,6 @@ bool Foam::explicitSetValue::read(const dictionary& dict) { if (basicSource::read(dict)) { - coeffs_ = dict.subDict(typeName + "Coeffs"); setFieldData(coeffs_.subDict("fieldData")); return true; } @@ -49,13 +48,4 @@ bool Foam::explicitSetValue::read(const dictionary& dict) } -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const explicitSetValue& source) -{ - source.writeData(os); - return os; -} - - // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueTemplates.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueTemplates.C index f67c318343..9a5a7bbbb2 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueTemplates.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueTemplates.C @@ -52,14 +52,14 @@ void Foam::explicitSetValue::setFieldValue ) ); - List values(this->cells().size()); + List values(cells_.size()); - forAll (values, i) + forAll(values, i) { values[i] = data; } - Eqn.setValues(this->cells(), values); + Eqn.setValues(cells_, values); } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.C new file mode 100644 index 0000000000..41d0d4f4f1 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.C @@ -0,0 +1,184 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "ExplicitSource.H" +#include "fvMesh.H" +#include "volFields.H" +#include "dimensionedType.H" + +// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // + + +template +const Foam::wordList Foam::ExplicitSource:: +volumeModeTypeNames_ +( + IStringStream("(absolute specific)")() +); + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +typename Foam::ExplicitSource::volumeModeType +Foam::ExplicitSource::wordToVolumeModeType +( + const word& vmtName +) const +{ + forAll(volumeModeTypeNames_, i) + { + if (vmtName == volumeModeTypeNames_[i]) + { + return volumeModeType(i); + } + } + + FatalErrorIn + ( + "ExplicitSource::volumeModeType" + "ExplicitSource::wordToVolumeModeType(const word&)" + ) << "Unknown volumeMode type " << vmtName + << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_ + << exit(FatalError); + + return volumeModeType(0); +} + + +template +Foam::word Foam::ExplicitSource::volumeModeTypeToWord +( + const volumeModeType& vmtType +) const +{ + if (vmtType > volumeModeTypeNames_.size()) + { + return "UNKNOWN"; + } + else + { + return volumeModeTypeNames_[vmtType]; + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::ExplicitSource::ExplicitSource +( + const word& name, + const word& modelType, + const dictionary& coeffs, + const fvMesh& mesh +) +: + basicSource(name, modelType, coeffs, mesh), + volumeMode_(wordToVolumeModeType(coeffs_.lookup("volumeMode"))), + VDash_(1.0), + fieldData_() +{ + const dictionary& fieldDict(coeffs_.subDict("fieldData")); + fieldData_.setSize(fieldDict.toc().size()); + label i = 0; + forAllConstIter(dictionary, fieldDict, iter) + { + fieldData_[i].first() = iter().keyword(); + fieldDict.lookup(iter().keyword()) >> fieldData_[i].second(); + i++; + } + + // Set volume normalisation + if (volumeMode_ == vmAbsolute) + { + VDash_ = V_; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::label Foam::ExplicitSource::applyToField +( + const word& fieldName +) const +{ + forAll(fieldData_, i) + { + if (fieldData_[i].first() == fieldName) + { + return i; + } + } + + return -1; +} + + +template +void Foam::ExplicitSource::addSup +( + fvMatrix& eqn, + const label fieldI +) +{ + if (debug) + { + Info<< "ExplicitSource<"<< pTraits::typeName + << ">::addSup for source " << name_ << endl; + } + + DimensionedField Su + ( + IOobject + ( + name_ + fieldData_[fieldI].first() + "Sup", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensioned + ( + "zero", + eqn.dimensions()/dimVolume, + pTraits::zero + ), + false + ); + + forAll(cells_, i) + { + Su[cells_[i]] = fieldData_[fieldI].second()/VDash_; + } + + eqn -= Su; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.H similarity index 57% rename from src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.H rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.H index 05c3782254..2b24fb159c 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSource.H @@ -22,37 +22,45 @@ License along with OpenFOAM. If not, see . Class - Foam::explicitSource + Foam::ExplicitSource Description - Explicit source. + Time activated explicit source. Sources described by: - explicitSourceCoeffs { - points // list of points when selectionMode = points + active true; // on/off switch + timeStart 0.2; // start time + duration 2.0; // duration + selectionMode points; // cellSet/cellZone/all + volumeMode absolute; // specific + + fieldData // field data - usage for multiple fields ( - (-0.088 0.007 -0.02) - (-0.028 0.007 -0.02) + (H2O 0.005) ); - volumeMode specific; //absolute - fieldData // field data - usage for multiple fields - { - k 30.7; - epsilon 1.5; - } + + fieldData 0.005; // field data - usage for single field + + points // list of points when selectionMode = points + ( + (2.75 0.5 0) + ); + + cellSet c0; // cellSet name when selectionMode=cellSet + cellZone c0; // cellZone name when selectionMode=cellZone } SourceFiles - explicitSource.C + ExplicitSource.C \*---------------------------------------------------------------------------*/ -#ifndef explicitSource_H -#define explicitSource_H +#ifndef ExplicitSource_H +#define ExplicitSource_H -#include "cellSet.H" +#include "Tuple2.H" #include "volFieldsFwd.H" #include "DimensionedField.H" #include "basicSource.H" @@ -62,35 +70,31 @@ SourceFiles namespace Foam { +// Forward declaration of classes + +class fvMesh; + +template +class ExplicitSource; + +// Forward declaration of friend functions + +template +Ostream& operator<< +( + Ostream&, + const ExplicitSource& +); + /*---------------------------------------------------------------------------*\ - Class explicitSource Declaration + Class ExplicitSource Declaration \*---------------------------------------------------------------------------*/ -class explicitSource +template +class ExplicitSource : public basicSource { - // Private data - - //- List of field types - HashTable scalarFields_; - HashTable vectorFields_; - - //- Add source to matrix - template - void addSource(fvMatrix&, const Type&) const; - - //- Add field names and values to field table for types. - template - void addField - ( - HashTable& fields, - const wordList& fieldTypes, - const wordList& fieldNames, - const dictionary& dict - ); - - public: // Public data @@ -103,36 +107,44 @@ public: }; //- Word list of volume mode type names - static const NamedEnum volumeModeTypeNames_; + static const wordList volumeModeTypeNames_; protected: // Protected data - //- Coefficients dictionary - dictionary coeffs_; + typedef Tuple2 fieldNameValuePair; //- Volume mode volumeModeType volumeMode_; + //- Volume normalisation + scalar VDash_; + + //- Source value per field + List fieldData_; + // Protected functions - //- Set the local field data - void setFieldData(const dictionary& dict); + //- Helper function to convert from a word to a volumeModeType + volumeModeType wordToVolumeModeType(const word& vtName) const; + + //- Helper function to convert from a volumeModeType to a word + word volumeModeTypeToWord(const volumeModeType& vtType) const; public: //- Runtime type information - TypeName("explicitSource"); + TypeName("ExplicitSource"); // Constructors //- Construct from components - explicitSource + ExplicitSource ( const word& name, const word& modelType, @@ -140,42 +152,37 @@ public: const fvMesh& mesh ); - //- Return clone - autoPtr clone() const - { - notImplemented - ( - "autoPtr clone() const" - ); - return autoPtr(NULL); - } - - // Member Functions + // Check + + //- Return index of field name if found in fieldNames list + virtual label applyToField(const word& fieldName) const; + + // Access //- Return const access to the volume mode inline const volumeModeType& volumeMode() const; + //- Return const access to the source field value + inline const Type& fieldData() const; + // Edit //- Return access to the volume mode inline volumeModeType& volumeMode(); - //- Return points - inline const List& points() const; + //- Return access to the source field value + inline Type& fieldData(); // Evaluation - //-Source term to fvMatrix - virtual void addSu(fvMatrix& UEqn); - - //-Source term to fvMatrix - virtual void addSu(fvMatrix& UEqn); + //- Add explicit contribution to equation + virtual void addSup(fvMatrix& eqn, const label fieldI); // I-O @@ -183,15 +190,8 @@ public: //- Write the source properties virtual void writeData(Ostream&) const; - //- Read fieldData in sub-dictionary + //- Read source dictionary virtual bool read(const dictionary& dict); - - //- Ostream operator - friend Ostream& operator<< - ( - Ostream& os, - const explicitSource& source - ); }; @@ -201,14 +201,14 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "explicitSourceIO.C" -#include "explicitSourceI.H" +#ifdef NoRepository +# include "ExplicitSource.C" +# include "ExplicitSourceIO.C" +#endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "explicitSourceTemplates.C" -#endif +#include "ExplicitSourceI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueI.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceI.H similarity index 70% rename from src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueI.H rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceI.H index 35aa075140..0cb38f2a53 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSetValue/explicitSetValueI.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceI.H @@ -23,14 +23,37 @@ License \*---------------------------------------------------------------------------*/ -#include "explicitSetValue.H" +#include "ExplicitSource.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline const Foam::List& -Foam::explicitSetValue::points() const +template +inline const typename Foam::ExplicitSource::volumeModeType& +Foam::ExplicitSource::volumeMode() const { - return points_; + return volumeMode_; +} + + +template +inline const Type& Foam::ExplicitSource::fieldData() const +{ + return fieldData_; +} + + +template +inline typename Foam::ExplicitSource::volumeModeType& +Foam::ExplicitSource::volumeMode() +{ + return volumeMode_; +} + + +template +inline Type& Foam::ExplicitSource::fieldData() +{ + return fieldData_; } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceI.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceIO.C similarity index 76% rename from src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceI.H rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceIO.C index 8bc5a62628..1b651bbd49 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceI.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/ExplicitSourceIO.C @@ -23,28 +23,29 @@ License \*---------------------------------------------------------------------------*/ -#include "explicitSource.H" +#include "ExplicitSource.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline const Foam::explicitSource::volumeModeType& -Foam::explicitSource::volumeMode() const +template +void Foam::ExplicitSource::writeData(Ostream& os) const { - return volumeMode_; + notImplemented + ( + "void Foam::ExplicitSource::read(Ostream&) const" + ); } -inline Foam::explicitSource::volumeModeType& -Foam::explicitSource::volumeMode() +template +bool Foam::ExplicitSource::read(const dictionary& dict) { - return volumeMode_; -} + notImplemented + ( + "bool Foam::ExplicitSource::read(const dictionary&)" + ); - -inline const Foam::List& -Foam::explicitSource::points() const -{ - return points_; + return false; } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.C index af5555f3fb..338a422059 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSource.C @@ -23,111 +23,18 @@ License \*---------------------------------------------------------------------------*/ -#include "explicitSource.H" -#include "fvMesh.H" -#include "volFields.H" -#include "addToRunTimeSelectionTable.H" -#include "HashSet.H" +#include "makeBasicSource.H" +#include "ExplicitSource.H" -// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - defineTypeNameAndDebug(explicitSource, 0); - addToRunTimeSelectionTable - ( - basicSource, - explicitSource, - dictionary - ); - - - // * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // - - template<> const char* NamedEnum - < - explicitSource::volumeModeType, - 2 - >::names[] = - { - "absolute", - "specific" - }; - - const NamedEnum - explicitSource::volumeModeTypeNames_; -} - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void Foam::explicitSource::setFieldData(const dictionary& dict) -{ - scalarFields_.clear(); - vectorFields_.clear(); - - wordList fieldTypes(dict.toc().size()); - wordList fieldNames(dict.toc().size()); - - forAll(dict.toc(), i) - { - const word& fieldName = dict.toc()[i]; - IOobject io - ( - fieldName, - this->mesh().time().timeName(), - this->mesh(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ); - if (io.headerOk()) - { - fieldTypes[i] = io.headerClassName(); - fieldNames[i] = dict.toc()[i]; - } - else - { - FatalErrorIn - ( - "explicitSource::setFieldData" - ) << "header not OK " << io.name() - << exit(FatalError); - } - } - - addField(scalarFields_, fieldTypes, fieldNames, dict); - addField(vectorFields_, fieldTypes, fieldNames, dict); -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::explicitSource::explicitSource -( - const word& name, - const word& modelType, - const dictionary& dict, - const fvMesh& mesh -) -: - basicSource(name, modelType, dict, mesh), - coeffs_(dict.subDict(modelType + "Coeffs")), - volumeMode_(volumeModeTypeNames_.read(coeffs_.lookup("volumeMode"))) -{ - setFieldData(dict_.subDict("fieldData")); -} - - -void Foam::explicitSource::addSu(fvMatrix& Eqn) -{ - addSource(Eqn, scalarFields_[Eqn.psi().name()]); -} - - -void Foam::explicitSource::addSu(fvMatrix& Eqn) -{ - addSource(Eqn, vectorFields_[Eqn.psi().name()]); + makeBasicSource(ExplicitSource, scalar); + makeBasicSource(ExplicitSource, vector); + makeBasicSource(ExplicitSource, sphericalTensor); + makeBasicSource(ExplicitSource, symmTensor); + makeBasicSource(ExplicitSource, tensor); } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceTemplates.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceTemplates.C deleted file mode 100644 index 92b94c3b16..0000000000 --- a/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/explicitSourceTemplates.C +++ /dev/null @@ -1,104 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -template -void Foam::explicitSource::addSource -( - fvMatrix& Eqn, - const Type& sourceData -) const -{ - Type data = sourceData; - if (volumeMode_ == vmAbsolute) - { - // Convert to specific quantity - data /= V_; - } - - DimensionedField rhs - ( - IOobject - ( - "rhs", - Eqn.psi().mesh().time().timeName(), - Eqn.psi().mesh(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - Eqn.psi().mesh(), - dimensioned - ( - "zero", - Eqn.dimensions()/dimVolume, - pTraits::zero - ) - ); - UIndirectList(rhs, this->cells()) = data; - - Eqn -= rhs; -} - - -template -void Foam::explicitSource::addField -( - HashTable& fields, - const wordList& fieldTypes, - const wordList& fieldNames, - const dictionary& fieldDataDict -) -{ - typedef GeometricField geometricField; - - forAll (fieldTypes, fieldI) - { - word fieldName = fieldNames[fieldI]; - word fieldType = fieldTypes[fieldI]; - - if - ( - ( - fieldType - == GeometricField::typeName - ) && - ( - this->mesh().foundObject(fieldName) - ) - ) - { - Type fieldValue = fieldDataDict.lookupOrDefault - ( - fieldName, - pTraits::zero - ); - - fields.insert(fieldName, fieldValue); - } - } -} - - -// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/timeActivatedExplicitSource.H b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/makeBasicSource.H similarity index 53% rename from src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/timeActivatedExplicitSource.H rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/makeBasicSource.H index 00b26abdb3..4d8c787487 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/timeActivatedExplicitSource.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/explicitSource/makeBasicSource.H @@ -21,43 +21,28 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Typedef - Foam::timeActivatedExplicitSource - \*---------------------------------------------------------------------------*/ -#ifndef timeActivatedExplicitSource_H -#define timeActivatedExplicitSource_H +#ifndef makeBasicSource_H +#define makeBasicSource_H -#include "TimeActivatedExplicitSource.H" -#include "TimeActivatedExplicitSourceList.H" +#include "basicSource.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - typedef TimeActivatedExplicitSource - scalarTimeActivatedExplicitSource; - typedef TimeActivatedExplicitSource - vectorTimeActivatedExplicitSource; - typedef TimeActivatedExplicitSource - sphericalTensorTimeActivatedExplicitSource; - typedef TimeActivatedExplicitSource - symmTensorTimeActivatedExplicitSource; - typedef TimeActivatedExplicitSource - tensorTimeActivatedExplicitSource; +#define makeBasicSource(Source, Type) \ + \ + defineTemplateTypeNameAndDebugWithName \ + ( \ + Source, \ + #Type#Source, \ + 0 \ + ); \ + \ + basicSource::adddictionaryConstructorToTable > \ + add##Source##Type##dictionary##ConstructorTobasicSourceTable_ - typedef TimeActivatedExplicitSourceList - scalarTimeActivatedExplicitSourceList; - typedef TimeActivatedExplicitSourceList - vectorTimeActivatedExplicitSourceList; - typedef TimeActivatedExplicitSourceList - sphericalTensorTimeActivatedExplicitSourceList; - typedef TimeActivatedExplicitSourceList - symmTensorTimeActivatedExplicitSourceList; - typedef TimeActivatedExplicitSourceList - tensorTimeActivatedExplicitSourceList; -} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/cfdTools/general/fieldSources/pressureGradientExplicitSource/pressureGradientExplicitSource.C b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C similarity index 56% rename from src/finiteVolume/cfdTools/general/fieldSources/pressureGradientExplicitSource/pressureGradientExplicitSource.C rename to src/finiteVolume/cfdTools/general/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C index d2c9912eff..d6b708f6c6 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/pressureGradientExplicitSource/pressureGradientExplicitSource.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C @@ -26,10 +26,23 @@ License #include "pressureGradientExplicitSource.H" #include "volFields.H" #include "IFstream.H" +#include "addToRunTimeSelectionTable.H" + +namespace Foam +{ + defineTypeNameAndDebug(pressureGradientExplicitSourceNew, 0); + + addToRunTimeSelectionTable + ( + basicSource, + pressureGradientExplicitSourceNew, + dictionary + ); +} // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::pressureGradientExplicitSource::writeGradP() const +void Foam::pressureGradientExplicitSourceNew::writeGradP() const { // Only write on output time if (mesh_.time().outputTime()) @@ -38,7 +51,7 @@ void Foam::pressureGradientExplicitSource::writeGradP() const ( IOobject ( - sourceName_ + "Properties", + name_ + "Properties", mesh_.time().timeName(), "uniform", mesh_, @@ -52,65 +65,77 @@ void Foam::pressureGradientExplicitSource::writeGradP() const } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::pressureGradientExplicitSource::pressureGradientExplicitSource -( - const word& sourceName, - volVectorField& U -) -: - sourceName_(sourceName), - mesh_(U.mesh()), - U_(U), - dict_ - ( - IOobject - ( - sourceName + "Properties", - mesh_.time().constant(), - mesh_, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ), - Ubar_(dict_.lookup("Ubar")), - gradPini_(dict_.lookup("gradPini")), - gradP_(gradPini_), - flowDir_(Ubar_/mag(Ubar_)), - cellSource_(dict_.lookup("cellSource")), - cellSelector_ - ( - topoSetSource::New - ( - cellSource_, - mesh_, - dict_.subDict(cellSource_ + "Coeffs") - ) - ), - selectedCellSet_ - ( - mesh_, - sourceName_ + "CellSet", - mesh_.nCells()/10 + 1 // Reasonable size estimate. - ) +void Foam::pressureGradientExplicitSourceNew::update() { - // Create the cell set - cellSelector_->applyToSet + volVectorField& U = const_cast ( - topoSetSource::NEW, - selectedCellSet_ + mesh_.lookupObject(UName_) ); - // Give some feedback - Info<< " Selected " - << returnReduce(selectedCellSet_.size(), sumOp