ENH: make setAverage optional for mapped patches (issue #943)

This commit is contained in:
Mark Olesen
2018-07-18 12:17:36 +02:00
parent a225d5f87a
commit 956abe3f38
8 changed files with 100 additions and 78 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,10 +34,10 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
field | name of field to be mapped | no | this field name field | Name of field to be mapped | no | this field name
setAverage | flag to activate setting of average value | yes | setAverage | Use average value | no | false |
average | average value to apply if \c setAverage = yes | yes | average | Average value to use if \c setAverage = yes | partly |
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,15 +27,28 @@ License
#include "mappedPatchBase.H" #include "mappedPatchBase.H"
#include "interpolationCell.H" #include "interpolationCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
namespace Foam template<class Type>
Type Foam::mappedPatchFieldBase<Type>::getAverage
(
const dictionary& dict,
const bool mandatory
)
{ {
if (mandatory)
{
return dict.get<Type>("average");
}
return Zero;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
mappedPatchFieldBase<Type>::mappedPatchFieldBase Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
( (
const mappedPatchBase& mapper, const mappedPatchBase& mapper,
const fvPatchField<Type>& patchField, const fvPatchField<Type>& patchField,
@ -55,7 +68,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
template<class Type> template<class Type>
mappedPatchFieldBase<Type>::mappedPatchFieldBase Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
( (
const mappedPatchBase& mapper, const mappedPatchBase& mapper,
const fvPatchField<Type>& patchField, const fvPatchField<Type>& patchField,
@ -72,19 +85,19 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
patchField_.internalField().name() patchField_.internalField().name()
) )
), ),
setAverage_(readBool(dict.lookup("setAverage"))), setAverage_(dict.lookupOrDefault("setAverage", false)),
average_(pTraits<Type>(dict.lookup("average"))), average_(getAverage(dict, setAverage_)),
interpolationScheme_(interpolationCell<Type>::typeName) interpolationScheme_(interpolationCell<Type>::typeName)
{ {
if (mapper_.mode() == mappedPatchBase::NEARESTCELL) if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
{ {
dict.lookup("interpolationScheme") >> interpolationScheme_; dict.read("interpolationScheme", interpolationScheme_);
} }
} }
template<class Type> template<class Type>
mappedPatchFieldBase<Type>::mappedPatchFieldBase Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
( (
const mappedPatchBase& mapper, const mappedPatchBase& mapper,
const fvPatchField<Type>& patchField const fvPatchField<Type>& patchField
@ -100,7 +113,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
template<class Type> template<class Type>
mappedPatchFieldBase<Type>::mappedPatchFieldBase Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
( (
const mappedPatchFieldBase<Type>& mapper const mappedPatchFieldBase<Type>& mapper
) )
@ -115,7 +128,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
template<class Type> template<class Type>
mappedPatchFieldBase<Type>::mappedPatchFieldBase Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
( (
const mappedPatchBase& mapper, const mappedPatchBase& mapper,
const fvPatchField<Type>& patchField, const fvPatchField<Type>& patchField,
@ -134,13 +147,11 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
const GeometricField<Type, fvPatchField, volMesh>& const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&
mappedPatchFieldBase<Type>::sampleField() const Foam::mappedPatchFieldBase<Type>::sampleField() const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> fieldType; typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
if (mapper_.sameRegion()) if (mapper_.sameRegion())
{ {
if (fieldName_ == patchField_.internalField().name()) if (fieldName_ == patchField_.internalField().name())
@ -158,15 +169,15 @@ mappedPatchFieldBase<Type>::sampleField() const
return thisMesh.template lookupObject<fieldType>(fieldName_); return thisMesh.template lookupObject<fieldType>(fieldName_);
} }
} }
else
{ const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
return nbrMesh.template lookupObject<fieldType>(fieldName_); return nbrMesh.template lookupObject<fieldType>(fieldName_);
}
} }
template<class Type> template<class Type>
tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const Foam::tmp<Foam::Field<Type>>
Foam::mappedPatchFieldBase<Type>::mappedField() const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> fieldType; typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
@ -179,8 +190,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh()); const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
// Result of obtaining remote values // Result of obtaining remote values
tmp<Field<Type>> tnewValues(new Field<Type>(0)); auto tnewValues = tmp<Field<Type>>::New();
Field<Type>& newValues = tnewValues.ref(); auto& newValues = tnewValues.ref();
switch (mapper_.mode()) switch (mapper_.mode())
{ {
@ -203,15 +214,14 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
samples samples
); );
autoPtr<interpolation<Type>> interpolator auto interpolator =
(
interpolation<Type>::New interpolation<Type>::New
( (
interpolationScheme_, interpolationScheme_,
sampleField() sampleField()
) );
);
const interpolation<Type>& interp = interpolator(); const auto& interp = *interpolator;
newValues.setSize(samples.size(), pTraits<Type>::max); newValues.setSize(samples.size(), pTraits<Type>::max);
forAll(samples, celli) forAll(samples, celli)
@ -263,10 +273,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
const fieldType& nbrField = sampleField(); const fieldType& nbrField = sampleField();
forAll(nbrField.boundaryField(), patchi) for (const fvPatchField<Type>& pf : nbrField.boundaryField())
{ {
const fvPatchField<Type>& pf =
nbrField.boundaryField()[patchi];
label faceStart = pf.patch().start(); label faceStart = pf.patch().start();
forAll(pf, facei) forAll(pf, facei)
@ -283,8 +291,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
default: default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unknown sampling mode: " << mapper_.mode() << "Unknown sampling mode: " << mapper_.mode() << nl
<< nl << abort(FatalError); << abort(FatalError);
} }
} }
@ -312,17 +320,18 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
template<class Type> template<class Type>
void mappedPatchFieldBase<Type>::write(Ostream& os) const void Foam::mappedPatchFieldBase<Type>::write(Ostream& os) const
{ {
os.writeEntry("field", fieldName_); os.writeEntry("field", fieldName_);
os.writeEntry("setAverage", setAverage_);
os.writeEntry("average", average_); if (setAverage_)
{
os.writeEntry("setAverage", "true");
os.writeEntry("average", average_);
}
os.writeEntry("interpolationScheme", interpolationScheme_); os.writeEntry("interpolationScheme", interpolationScheme_);
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -38,6 +38,14 @@ Description
interpolationScheme cellPoint; // default is cell interpolationScheme cellPoint; // default is cell
} }
\table
Property | Description | Required | Default
field | name of field to be mapped | no | this field name
setAverage | use average value | no | false |
average | average value to apply if \c setAverage = yes | partly |
interpolationScheme | interpolation scheme | partly | cell |
\endtable
SourceFiles SourceFiles
mappedPatchFieldBase.C mappedPatchFieldBase.C
@ -54,6 +62,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations
class mappedPatchBase; class mappedPatchBase;
template<class> class interpolation; template<class> class interpolation;
@ -64,6 +73,10 @@ template<class> class interpolation;
template<class Type> template<class Type>
class mappedPatchFieldBase class mappedPatchFieldBase
{ {
// Private Member Functions
//- Selective retrieval of "average" entry from the dictionary
static Type getAverage(const dictionary& dict, bool mandatory);
protected: protected:
@ -82,7 +95,7 @@ protected:
const bool setAverage_; const bool setAverage_;
//- Average value the mapped field is adjusted to maintain if //- Average value the mapped field is adjusted to maintain if
// setAverage_ is set true //- setAverage_ is set true
const Type average_; const Type average_;
//- Interpolation scheme to use for nearestcell mode //- Interpolation scheme to use for nearestcell mode
@ -135,11 +148,10 @@ public:
//- Destructor //- Destructor
virtual ~mappedPatchFieldBase<Type>() virtual ~mappedPatchFieldBase<Type>() = default;
{}
// Member functions // Member Functions
//- Field to sample. Either on my or nbr mesh //- Field to sample. Either on my or nbr mesh
const GeometricField<Type, fvPatchField, volMesh>& sampleField() const; const GeometricField<Type, fvPatchField, volMesh>& sampleField() const;
@ -148,7 +160,7 @@ public:
virtual tmp<Field<Type>> mappedField() const; virtual tmp<Field<Type>> mappedField() const;
//- Write //- Write
virtual void write(Ostream&) const; virtual void write(Ostream& os) const;
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -33,10 +33,10 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
field | name of field to be mapped | no | this field name field | name of field to be mapped | no | this field name
setAverage | flag to activate setting of average value | yes | setAverage | Use average value | no | false
average | average value to apply if \c setAverage = yes | yes | average | Average value to use if \c setAverage = yes | partly |
\endtable \endtable
\verbatim \verbatim
@ -44,7 +44,7 @@ Usage
{ {
type mappedFixedInternalValue; type mappedFixedInternalValue;
field T; field T;
setAverage no; setAverage false;
average 0; average 0;
value uniform 0; value uniform 0;
} }
@ -155,13 +155,11 @@ public:
// Member functions // Member functions
// Evaluation functions //- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write //- Write
virtual void write(Ostream&) const; virtual void write(Ostream& os) const;
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -33,10 +33,10 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
field | name of field to be mapped | no | this field name field | name of field to be mapped | no | this field name
setAverage | flag to activate setting of average value | yes | setAverage | Use average value | no | false |
average | average value to apply if \c setAverage = yes | yes | average | Average value to use if \c setAverage = yes | partly |
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,11 +36,11 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
field | name of field to be mapped | no | this field name field | Field name to be mapped | no | this field name
setAverage | flag to activate setting of average value | yes | setAverage | Use average value | no | false
average | average value to apply if \c setAverage = yes | yes | average | Average value to use if \c setAverage = yes | partly |
interpolationScheme | type of interpolation scheme | no | interpolationScheme | type of interpolation scheme | partly |
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:

View File

@ -580,7 +580,10 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::write
fieldTableName_ fieldTableName_
); );
os.writeEntryIfDifferent("setAverage", Switch(false), setAverage_); if (setAverage_)
{
os.writeEntry("setAverage", setAverage_);
}
os.writeEntryIfDifferent<scalar>("perturb", 1e-5, perturb_); os.writeEntryIfDifferent<scalar>("perturb", 1e-5, perturb_);

View File

@ -47,13 +47,13 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
setAverage | Switch to activate setting of average value | no | false setAverage | Use average value | no | false
perturb | Perturb points for regular geometries | no | 1e-5 perturb | Perturb points for regular geometries | no | 1e-5
points | Name of points file | no | points points | Name of points file | no | points
fieldTable | Alternative field name to sample | no | this field name fieldTable | Alternative field name to sample | no | this field name
mapMethod | Type of mapping | no | planarInterpolation mapMethod | Type of mapping | no | planarInterpolation
offset | Offset to mapped values | no | Zero offset | Offset to mapped values | no | Zero
\endtable \endtable
\verbatim \verbatim