ENH Templated and re-worked explicitSetValue field source

This commit is contained in:
andy
2011-11-01 16:50:27 +00:00
parent 175e8bf27e
commit 368dbd2dba
9 changed files with 178 additions and 259 deletions

View File

@ -388,9 +388,7 @@ $(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

View File

@ -0,0 +1,129 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "ExplicitSetValue.H"
#include "fvMesh.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::ExplicitSetValue<Type>::setFieldData(const dictionary& dict)
{
fieldData_.setSize(dict.toc().size());
label i = 0;
forAllConstIter(dictionary, dict, iter)
{
fieldData_[i].first() = iter().keyword();
dict.lookup(iter().keyword()) >> fieldData_[i].second();
i++;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::ExplicitSetValue<Type>::ExplicitSetValue
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
basicSource(name, modelType, dict, mesh),
fieldData_()
{
setFieldData(coeffs_.subDict("fieldData"));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::label Foam::ExplicitSetValue<Type>::applyToField
(
const word& fieldName
) const
{
forAll(fieldData_, i)
{
if (fieldData_[i].first() == fieldName)
{
return i;
}
}
return -1;
}
template<class Type>
void Foam::ExplicitSetValue<Type>::setValue
(
fvMatrix<Type>& eqn,
const label fieldI
)
{
if (debug)
{
Info<< "ExplicitSetValue<"<< pTraits<Type>::typeName
<< ">::setValue for source " << name_ << endl;
}
DimensionedField<Type, volMesh> rhs
(
IOobject
(
name_ + fieldData_[fieldI].first() + "rhs",
eqn.psi().mesh().time().timeName(),
eqn.psi().mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
eqn.psi().mesh(),
dimensioned<Type>
(
"zero",
dimless,
pTraits<Type>::zero
)
);
List<Type> values(cells_.size());
forAll(values, i)
{
values[i] = fieldData_[fieldI].second();
}
eqn.setValues(cells_, values);
}
// ************************************************************************* //

View File

@ -43,13 +43,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef explicitSetValue_H
#define explicitSetValue_H
#ifndef ExplicitSetValue_H
#define ExplicitSetValue_H
#include "cellSet.H"
#include "volFieldsFwd.H"
#include "DimensionedField.H"
#include "basicSource.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -60,33 +58,22 @@ namespace Foam
Class explicitSetValue Declaration
\*---------------------------------------------------------------------------*/
class explicitSetValue
template<class Type>
class ExplicitSetValue
:
public basicSource
{
// Private data
//- List of field types
HashTable<scalar> scalarFields_;
HashTable<vector> vectorFields_;
//- Set value to field
template<class Type>
void setFieldValue(fvMatrix<Type>&, const Type&) const;
//- Add field names and values to field table for types.
template<class Type>
void addField
(
HashTable<Type>& fields,
const wordList& fieldTypes,
const wordList& fieldNames,
const dictionary& dict
);
protected:
// Protected data
typedef Tuple2<word, Type> fieldNameValuePair;
//- Source value per field
List<fieldNameValuePair> fieldData_;
// Protected functions
//- Set the local field data
@ -102,7 +89,7 @@ public:
// Constructors
//- Construct from components
explicitSetValue
ExplicitSetValue
(
const word& name,
const word& modelType,
@ -110,13 +97,6 @@ public:
const fvMesh& mesh
);
//- Return clone
autoPtr<explicitSetValue> clone() const
{
notImplemented("autoPtr<explicitSetValue> clone() const");
return autoPtr<explicitSetValue>(NULL);
}
// Member Functions
@ -129,10 +109,7 @@ public:
// Evaluation
//- Set value on vector field
virtual void setValue(fvMatrix<vector>& eqn, const label fieldI);
//- Set value on scalar field
virtual void setValue(fvMatrix<scalar>& eqn, const label fieldI);
virtual void setValue(fvMatrix<Type>& eqn, const label fieldI);
// I-O
@ -152,7 +129,8 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "explicitSetValueTemplates.C"
# include "ExplicitSetValue.C"
# include "ExplicitSetValueIO.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -23,18 +23,20 @@ License
\*---------------------------------------------------------------------------*/
#include "explicitSetValue.H"
#include "ExplicitSetValue.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::explicitSetValue::writeData(Ostream& os) const
template<class Type>
void Foam::ExplicitSetValue<Type>::writeData(Ostream& os) const
{
os << indent << name_ << endl;
coeffs_.write(os);
}
bool Foam::explicitSetValue::read(const dictionary& dict)
template<class Type>
bool Foam::ExplicitSetValue<Type>::read(const dictionary& dict)
{
if (basicSource::read(dict))
{

View File

@ -23,110 +23,18 @@ License
\*---------------------------------------------------------------------------*/
#include "explicitSetValue.H"
#include "fvMesh.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "HashSet.H"
#include "makeBasicSource.H"
#include "ExplicitSetValue.H"
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(explicitSetValue, 0);
addToRunTimeSelectionTable
(
basicSource,
explicitSetValue,
dictionary
);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::explicitSetValue::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::MUST_READ,
IOobject::NO_WRITE,
false
);
if (io.headerOk())
{
fieldTypes[i] = io.headerClassName();
fieldNames[i] = dict.toc()[i];
}
else
{
FatalErrorIn("explicitSetValue::setFieldData")
<< "header not OK for field " << io.name()
<< abort(FatalError);
}
}
addField(scalarFields_, fieldTypes, fieldNames, dict);
addField(vectorFields_, fieldTypes, fieldNames, dict);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::explicitSetValue::explicitSetValue
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
basicSource(name, modelType, dict, mesh)
{
setFieldData(coeffs_.subDict("fieldData"));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::explicitSetValue::applyToField
(
const word& fieldName
) const
{
notImplemented("Foam::explicitSetValue::applyToField(const word&)");
}
void Foam::explicitSetValue::setValue
(
fvMatrix<scalar>& eqn,
const label
)
{
setFieldValue(eqn, scalarFields_[eqn.psi().name()]);
}
void Foam::explicitSetValue::setValue
(
fvMatrix<vector>& eqn,
const label
)
{
setFieldValue(eqn, vectorFields_[eqn.psi().name()]);
makeBasicSource(ExplicitSetValue, scalar);
makeBasicSource(ExplicitSetValue, vector);
makeBasicSource(ExplicitSetValue, sphericalTensor);
makeBasicSource(ExplicitSetValue, symmTensor);
makeBasicSource(ExplicitSetValue, tensor);
}

View File

@ -1,105 +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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
template <class Type>
void Foam::explicitSetValue::setFieldValue
(
fvMatrix<Type>& Eqn,
const Type& value
) const
{
Type data = value;
DimensionedField<Type, volMesh> rhs
(
IOobject
(
"rhs",
Eqn.psi().mesh().time().timeName(),
Eqn.psi().mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
Eqn.psi().mesh(),
dimensioned<Type>
(
"zero",
dimless,
pTraits<Type>::zero
)
);
List<Type> values(cells_.size());
forAll(values, i)
{
values[i] = data;
}
Eqn.setValues(cells_, values);
}
template <class Type>
void Foam::explicitSetValue::addField
(
HashTable<Type>& fields,
const wordList& fieldTypes,
const wordList& fieldNames,
const dictionary& fieldDataDict
)
{
typedef GeometricField<Type, fvPatchField, volMesh> geometricField;
forAll (fieldTypes, fieldI)
{
word fieldName = fieldNames[fieldI];
word fieldType = fieldTypes[fieldI];
if
(
(
fieldType
== GeometricField<Type, fvPatchField, volMesh>::typeName
) &&
(
this->mesh().foundObject<geometricField>(fieldName)
)
)
{
Type fieldValue = fieldDataDict.lookupOrDefault<Type>
(
fieldName,
pTraits<Type>::zero
);
fields.insert(fieldName, fieldValue);
}
}
}
// ************************************************************************* //

View File

@ -30,7 +30,6 @@ License
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::wordList Foam::ExplicitSource<Type>::
volumeModeTypeNames_
@ -85,6 +84,21 @@ Foam::word Foam::ExplicitSource<Type>::volumeModeTypeToWord
}
template<class Type>
void Foam::ExplicitSource<Type>::setFieldData(const dictionary& dict)
{
fieldData_.setSize(dict.toc().size());
label i = 0;
forAllConstIter(dictionary, dict, iter)
{
fieldData_[i].first() = iter().keyword();
dict.lookup(iter().keyword()) >> fieldData_[i].second();
i++;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -101,15 +115,7 @@ Foam::ExplicitSource<Type>::ExplicitSource
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++;
}
setFieldData(coeffs_.subDict("fieldData"));
// Set volume normalisation
if (volumeMode_ == vmAbsolute)

View File

@ -134,6 +134,9 @@ protected:
//- Helper function to convert from a volumeModeType to a word
word volumeModeTypeToWord(const volumeModeType& vtType) const;
//- Set the local field data
void setFieldData(const dictionary& dict);
public: