diff --git a/src/lagrangian/intermediate/submodels/CloudSubModelBase.C b/src/lagrangian/intermediate/submodels/CloudSubModelBase.C new file mode 100644 index 0000000000000000000000000000000000000000..83098ec87c41531c456ebfee52249d935c26b717 --- /dev/null +++ b/src/lagrangian/intermediate/submodels/CloudSubModelBase.C @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2013 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "CloudSubModelBase.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class CloudType> +Foam::CloudSubModelBase<CloudType>::CloudSubModelBase(CloudType& owner) +: + subModelBase(owner.outputProperties()), + owner_(owner) +{} + + +template<class CloudType> +Foam::CloudSubModelBase<CloudType>::CloudSubModelBase +( + CloudType& owner, + const dictionary& dict, + const word& baseName, + const word& modelType, + const word& dictExt +) +: + subModelBase + ( + owner.outputProperties(), + dict, + baseName, + modelType, + dictExt + ), + owner_(owner) +{} + + +template<class CloudType> +Foam::CloudSubModelBase<CloudType>::CloudSubModelBase +( + const word& modelName, + CloudType& owner, + const dictionary& dict, + const word& baseName, + const word& modelType +) +: + subModelBase + ( + modelName, + owner.outputProperties(), + dict, + baseName, + modelType + ), + owner_(owner) +{} + + +template<class CloudType> +Foam::CloudSubModelBase<CloudType>::CloudSubModelBase +( + const CloudSubModelBase<CloudType>& smb +) +: + subModelBase(smb), + owner_(smb.owner_) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class CloudType> +Foam::CloudSubModelBase<CloudType>::~CloudSubModelBase() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class CloudType> +const CloudType& Foam::CloudSubModelBase<CloudType>::owner() const +{ + return owner_; +} + + +template<class CloudType> +CloudType& Foam::CloudSubModelBase<CloudType>::owner() +{ + return owner_; +} + + +template<class CloudType> +bool Foam::CloudSubModelBase<CloudType>::outputTime() const +{ + return + active() + && owner_.solution().transient() + && owner_.db().time().outputTime(); +} + + +template<class CloudType> +void Foam::CloudSubModelBase<CloudType>::write(Ostream& os) const +{ + os.writeKeyword("owner") << owner_.name() << token::END_STATEMENT + << nl; + + subModelBase::write(os); +} + + +// ************************************************************************* // diff --git a/src/lagrangian/intermediate/submodels/CloudSubModelBase.H b/src/lagrangian/intermediate/submodels/CloudSubModelBase.H new file mode 100644 index 0000000000000000000000000000000000000000..443612e018d6870f853c9bcd33efe5366f05cd6b --- /dev/null +++ b/src/lagrangian/intermediate/submodels/CloudSubModelBase.H @@ -0,0 +1,138 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2013 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 <http://www.gnu.org/licenses/>. + +Class + Foam::CloudSubModelBase + +Description + Base class for cloud sub-models + +SourceFiles + CloudSubModelBase.C + +\*---------------------------------------------------------------------------*/ + +#ifndef CloudSubModelBase_H +#define CloudSubModelBase_H + +#include "subModelBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class CloudSubModelBase Declaration +\*---------------------------------------------------------------------------*/ + +template<class CloudType> +class CloudSubModelBase +: + public subModelBase +{ +protected: + + // Protected Data + + //- Reference to the cloud + CloudType& owner_; + + +public: + + // Constructors + + //- Construct null from owner cloud + CloudSubModelBase(CloudType& owner); + + //- Construct from owner cloud without name + CloudSubModelBase + ( + CloudType& owner, + const dictionary& dict, + const word& baseName, + const word& modelType, + const word& dictExt = "Coeffs" + ); + + //- Construct from owner cloud with name + CloudSubModelBase + ( + const word& modelName, + CloudType& owner, + const dictionary& dict, + const word& baseName, + const word& modelType + ); + + //- Construct as copy + CloudSubModelBase(const CloudSubModelBase<CloudType>& smb); + + + //- Destructor + virtual ~CloudSubModelBase(); + + //- Type of cloud this model was instantiated for + typedef CloudType cloudType; + + + // Member Functions + + // Access + + //- Return const access to the owner cloud + const CloudType& owner() const; + + //- Flag to indicate when to write a property + virtual bool outputTime() const; + + + // Edit + + //- Return non-const access to the owner cloud for manipulation + CloudType& owner(); + + + // I-O + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "CloudSubModelBase.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/lagrangian/intermediate/submodels/SubModelBase.C b/src/lagrangian/intermediate/submodels/SubModelBase.C deleted file mode 100644 index 2df1f5207c08f0327bcca6a83cb50c6a59168927..0000000000000000000000000000000000000000 --- a/src/lagrangian/intermediate/submodels/SubModelBase.C +++ /dev/null @@ -1,394 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 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 <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "SubModelBase.H" - -// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // - -template<class CloudType> -bool Foam::SubModelBase<CloudType>::SubModelBase::inLine() const -{ - return (modelName_ != word::null); -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template<class CloudType> -Foam::SubModelBase<CloudType>::SubModelBase(CloudType& owner) -: - owner_(owner), - dict_(dictionary::null), - baseName_(word::null), - modelType_(word::null), - modelName_(word::null), - coeffDict_(dictionary::null) -{} - - -template<class CloudType> -Foam::SubModelBase<CloudType>::SubModelBase -( - CloudType& owner, - const dictionary& dict, - const word& baseName, - const word& modelType, - const word& dictExt -) -: - owner_(owner), - dict_(dict), - baseName_(baseName), - modelType_(modelType), - modelName_(word::null), - coeffDict_(dict.subDict(modelType + dictExt)) -{} - - -template<class CloudType> -Foam::SubModelBase<CloudType>::SubModelBase -( - const word& modelName, - CloudType& owner, - const dictionary& dict, - const word& baseName, - const word& modelType -) -: - owner_(owner), - dict_(dict), - baseName_(baseName), - modelType_(modelType), - modelName_(modelName), - coeffDict_(dict) -{} - - -template<class CloudType> -Foam::SubModelBase<CloudType>::SubModelBase(const SubModelBase<CloudType>& smb) -: - owner_(smb.owner_), - dict_(smb.dict_), - baseName_(smb.baseName_), - modelType_(smb.modelType_), - modelName_(smb.modelName_), - coeffDict_(smb.coeffDict_) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template<class CloudType> -Foam::SubModelBase<CloudType>::~SubModelBase() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template<class CloudType> -const CloudType& Foam::SubModelBase<CloudType>::owner() const -{ - return owner_; -} - - -template<class CloudType> -const Foam::dictionary& Foam::SubModelBase<CloudType>::dict() const -{ - return dict_; -} - - -template<class CloudType> -const Foam::word& Foam::SubModelBase<CloudType>::modelType() const -{ - return modelType_; -} - - -template<class CloudType> -const Foam::word& Foam::SubModelBase<CloudType>::baseName() const -{ - return baseName_; -} - - -template<class CloudType> -const Foam::word& Foam::SubModelBase<CloudType>::modelName() const -{ - return modelName_; -} - - -template<class CloudType> -const Foam::dictionary& Foam::SubModelBase<CloudType>::coeffDict() const -{ - return coeffDict_; -} - - -template<class CloudType> -bool Foam::SubModelBase<CloudType>::defaultCoeffs(const bool printMsg) const -{ - bool def = coeffDict_.lookupOrDefault<bool>("defaultCoeffs", false); - if (printMsg && def) - { - Info<< incrIndent; - Info<< indent << "Employing default coefficients" << endl; - Info<< decrIndent; - } - - return def; -} - - -template<class CloudType> -CloudType& Foam::SubModelBase<CloudType>::owner() -{ - return owner_; -} - - -template<class CloudType> -bool Foam::SubModelBase<CloudType>::active() const -{ - return true; -} - - -template<class CloudType> -void Foam::SubModelBase<CloudType>::cacheFields(const bool) -{ - // do nothing -} - - -template<class CloudType> -bool Foam::SubModelBase<CloudType>::outputTime() const -{ - return - active() - && owner_.solution().transient() - && owner_.db().time().outputTime(); -} - - -template<class CloudType> -template<class Type> -Type Foam::SubModelBase<CloudType>::getBaseProperty -( - const word& entryName, - const Type& defaultValue -) const -{ - Type result = defaultValue; - - const dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - const dictionary& baseDict = properties.subDict(baseName_); - baseDict.readIfPresent(entryName, result); - } - - return result; -} - - -template<class CloudType> -template<class Type> -void Foam::SubModelBase<CloudType>::getBaseProperty -( - const word& entryName, - Type& value -) const -{ - const dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - const dictionary& baseDict = properties.subDict(baseName_); - baseDict.readIfPresent(entryName, value); - } -} - - -template<class CloudType> -template<class Type> -void Foam::SubModelBase<CloudType>::setBaseProperty -( - const word& entryName, - const Type& value -) -{ - dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - dictionary& baseDict = properties.subDict(baseName_); - baseDict.add(entryName, value, true); - } - else - { - properties.add(baseName_, dictionary()); - properties.subDict(baseName_).add(entryName, value); - } -} - - -template<class CloudType> -template<class Type> -Type Foam::SubModelBase<CloudType>::getModelProperty -( - const word& entryName, - const Type& defaultValue -) const -{ - Type result = defaultValue; - - const dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - const dictionary& baseDict = properties.subDict(baseName_); - - if (inLine() && baseDict.found(modelName_)) - { - baseDict.subDict(modelName_).readIfPresent(entryName, result); - } - else if (baseDict.found(modelType_)) - { - baseDict.subDict(modelType_).readIfPresent(entryName, result); - } - } - - return result; -} - - -template<class CloudType> -template<class Type> -void Foam::SubModelBase<CloudType>::getModelProperty -( - const word& entryName, - Type& value -) const -{ - const dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - const dictionary& baseDict = properties.subDict(baseName_); - - if (inLine() && baseDict.found(modelName_)) - { - baseDict.subDict(modelName_).readIfPresent(entryName, value); - } - else if (baseDict.found(modelType_)) - { - baseDict.subDict(modelType_).readIfPresent(entryName, value); - } - } -} - - -template<class CloudType> -template<class Type> -void Foam::SubModelBase<CloudType>::setModelProperty -( - const word& entryName, - const Type& value -) -{ - dictionary& properties = this->owner().outputProperties(); - - if (properties.found(baseName_)) - { - dictionary& baseDict = properties.subDict(baseName_); - - if (inLine()) - { - if (baseDict.found(modelName_)) - { - baseDict.subDict(modelName_).add(entryName, value, true); - } - else - { - baseDict.add(modelName_, dictionary()); - baseDict.subDict(modelName_).add(entryName, value, true); - } - } - else - { - if (baseDict.found(modelType_)) - { - baseDict.subDict(modelType_).add(entryName, value, true); - } - else - { - baseDict.add(modelType_, dictionary()); - baseDict.subDict(modelType_).add(entryName, value, true); - } - } - } - else - { - properties.add(baseName_, dictionary()); - - if (inLine()) - { - properties.subDict(baseName_).add(modelName_, dictionary()); - properties.subDict(baseName_).subDict(modelName_).add - ( - entryName, - value - ); - } - else - { - properties.subDict(baseName_).add(modelType_, dictionary()); - properties.subDict(baseName_).subDict(modelType_).add - ( - entryName, - value - ); - } - } -} - - -template<class CloudType> -void Foam::SubModelBase<CloudType>::write(Ostream& os) const -{ - os.writeKeyword("owner") << owner_.name() << token::END_STATEMENT - << nl; - - // not writing complete cloud dictionary, only coeffs -// os << dict_; - os << coeffDict_; -} - - -// ************************************************************************* // diff --git a/src/lagrangian/intermediate/submodels/SubModelBase.H b/src/lagrangian/intermediate/submodels/SubModelBase.H deleted file mode 100644 index 608cee614ebd59ec6950bf6ee3e83a950b0f0741..0000000000000000000000000000000000000000 --- a/src/lagrangian/intermediate/submodels/SubModelBase.H +++ /dev/null @@ -1,225 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 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 <http://www.gnu.org/licenses/>. - -Class - Foam::SubModelBase - -Description - Base class for cloud sub-models - -SourceFiles - SubModelBase.C - -\*---------------------------------------------------------------------------*/ - -#ifndef SubModelBase_H -#define SubModelBase_H - -#include "dictionary.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// Forward declaration of classes -template<class CloudType> -class SubModelBase; - -/*---------------------------------------------------------------------------*\ - Class SubModelBase Declaration -\*---------------------------------------------------------------------------*/ - -template<class CloudType> -class SubModelBase -{ -protected: - - // Protected Data - - //- Reference to the cloud - CloudType& owner_; - - //- Reference to the cloud dictionary - const dictionary dict_; - - //- Name of the sub-model base class - const word baseName_; - - //- Type of the sub-model - const word modelType_; - - //- Name of the sub-model - const word modelName_; - - //- Coefficients dictionary - const dictionary coeffDict_; - - - // Protected Member Functions - - //- Flag to indicate whether data is/was read in-line - bool inLine() const; - - -public: - - // Constructors - - //- Construct null from owner cloud - SubModelBase(CloudType& owner); - - //- Construct from owner cloud, dictionary, and model type name - SubModelBase - ( - CloudType& owner, - const dictionary& dict, - const word& baseName, - const word& modelType, - const word& dictExt = "Coeffs" - ); - - //- Construct from owner cloud, dictionary, and model type name - SubModelBase - ( - const word& modelName, - CloudType& owner, - const dictionary& dict, - const word& baseName, - const word& modelType - ); - - //- Construct as copy - SubModelBase(const SubModelBase<CloudType>& smb); - - - //- Destructor - virtual ~SubModelBase(); - - //- Type of cloud this model was instantiated for - typedef CloudType cloudType; - - - // Member Functions - - // Access - - //- Return const access to the owner cloud - const CloudType& owner() const; - - //- Return const access to the cloud dictionary - const dictionary& dict() const; - - //- Return const access to the sub-model type - const word& modelType() const; - - //- Return const access to the base name of the sub-model - const word& baseName() const; - - //- Return const access to the name of the sub-model - const word& modelName() const; - - //- Return const access to the coefficients dictionary - const dictionary& coeffDict() const; - - //- Return const access to the properties dictionary - const IOdictionary& properties() const; - - //- Returns true if defaultCoeffs is true and outputs on printMsg - bool defaultCoeffs(const bool printMsg) const; - - //- Return the model 'active' status - default active = true - virtual bool active() const; - - //- Cache dependant sub-model fields - virtual void cacheFields(const bool store); - - //- Flag to indicate when to write a property - bool outputTime() const; - - - // Edit - - //- Return non-const access to the owner cloud for manipulation - CloudType& owner(); - - // Base properties - - //- Retrieve generic property from the base model - template<class Type> - Type getBaseProperty - ( - const word& entryName, - const Type& defaultValue = pTraits<Type>::zero - ) const; - - //- Retrieve generic property from the base model - template<class Type> - void getBaseProperty(const word& entryName, Type& value) const; - - //- Add generic property to the base model - template<class Type> - void setBaseProperty(const word& entryName, const Type& value); - - - // Model properties - - //- Retrieve generic property from the sub-model - template<class Type> - Type getModelProperty - ( - const word& entryName, - const Type& defaultValue = pTraits<Type>::zero - ) const; - - //- Retrieve generic property from the sub-model - template<class Type> - void getModelProperty(const word& entryName, Type& value) const; - - //- Add generic property to the sub-model - template<class Type> - void setModelProperty(const word& entryName, const Type& value); - - - // I-O - - //- Write - virtual void write(Ostream& os) const; -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository -# include "SubModelBase.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* //