mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make setAverage optional for mapped patches (issue #943)
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,10 +34,10 @@ Description
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
field | name of field to be mapped | no | this field name
|
||||
setAverage | flag to activate setting of average value | yes |
|
||||
average | average value to apply if \c setAverage = yes | yes |
|
||||
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 use if \c setAverage = yes | partly |
|
||||
\endtable
|
||||
|
||||
Example of the boundary condition specification:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,15 +27,28 @@ License
|
||||
#include "mappedPatchBase.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 * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
(
|
||||
const mappedPatchBase& mapper,
|
||||
const fvPatchField<Type>& patchField,
|
||||
@ -55,7 +68,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
|
||||
|
||||
template<class Type>
|
||||
mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
(
|
||||
const mappedPatchBase& mapper,
|
||||
const fvPatchField<Type>& patchField,
|
||||
@ -72,19 +85,19 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
patchField_.internalField().name()
|
||||
)
|
||||
),
|
||||
setAverage_(readBool(dict.lookup("setAverage"))),
|
||||
average_(pTraits<Type>(dict.lookup("average"))),
|
||||
setAverage_(dict.lookupOrDefault("setAverage", false)),
|
||||
average_(getAverage(dict, setAverage_)),
|
||||
interpolationScheme_(interpolationCell<Type>::typeName)
|
||||
{
|
||||
if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
|
||||
{
|
||||
dict.lookup("interpolationScheme") >> interpolationScheme_;
|
||||
dict.read("interpolationScheme", interpolationScheme_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
(
|
||||
const mappedPatchBase& mapper,
|
||||
const fvPatchField<Type>& patchField
|
||||
@ -100,7 +113,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
|
||||
|
||||
template<class Type>
|
||||
mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
(
|
||||
const mappedPatchFieldBase<Type>& mapper
|
||||
)
|
||||
@ -115,7 +128,7 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
|
||||
|
||||
template<class Type>
|
||||
mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
Foam::mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
(
|
||||
const mappedPatchBase& mapper,
|
||||
const fvPatchField<Type>& patchField,
|
||||
@ -134,13 +147,11 @@ mappedPatchFieldBase<Type>::mappedPatchFieldBase
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const GeometricField<Type, fvPatchField, volMesh>&
|
||||
mappedPatchFieldBase<Type>::sampleField() const
|
||||
const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&
|
||||
Foam::mappedPatchFieldBase<Type>::sampleField() const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||
|
||||
const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
|
||||
|
||||
if (mapper_.sameRegion())
|
||||
{
|
||||
if (fieldName_ == patchField_.internalField().name())
|
||||
@ -158,15 +169,15 @@ mappedPatchFieldBase<Type>::sampleField() const
|
||||
return thisMesh.template lookupObject<fieldType>(fieldName_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return nbrMesh.template lookupObject<fieldType>(fieldName_);
|
||||
}
|
||||
|
||||
const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
|
||||
return nbrMesh.template lookupObject<fieldType>(fieldName_);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -179,8 +190,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
|
||||
const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
|
||||
|
||||
// Result of obtaining remote values
|
||||
tmp<Field<Type>> tnewValues(new Field<Type>(0));
|
||||
Field<Type>& newValues = tnewValues.ref();
|
||||
auto tnewValues = tmp<Field<Type>>::New();
|
||||
auto& newValues = tnewValues.ref();
|
||||
|
||||
switch (mapper_.mode())
|
||||
{
|
||||
@ -203,15 +214,14 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
|
||||
samples
|
||||
);
|
||||
|
||||
autoPtr<interpolation<Type>> interpolator
|
||||
(
|
||||
auto interpolator =
|
||||
interpolation<Type>::New
|
||||
(
|
||||
interpolationScheme_,
|
||||
sampleField()
|
||||
)
|
||||
);
|
||||
const interpolation<Type>& interp = interpolator();
|
||||
);
|
||||
|
||||
const auto& interp = *interpolator;
|
||||
|
||||
newValues.setSize(samples.size(), pTraits<Type>::max);
|
||||
forAll(samples, celli)
|
||||
@ -263,10 +273,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
|
||||
|
||||
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();
|
||||
|
||||
forAll(pf, facei)
|
||||
@ -283,8 +291,8 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown sampling mode: " << mapper_.mode()
|
||||
<< nl << abort(FatalError);
|
||||
<< "Unknown sampling mode: " << mapper_.mode() << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,17 +320,18 @@ tmp<Field<Type>> mappedPatchFieldBase<Type>::mappedField() const
|
||||
|
||||
|
||||
template<class Type>
|
||||
void mappedPatchFieldBase<Type>::write(Ostream& os) const
|
||||
void Foam::mappedPatchFieldBase<Type>::write(Ostream& os) const
|
||||
{
|
||||
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_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -38,6 +38,14 @@ Description
|
||||
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
|
||||
mappedPatchFieldBase.C
|
||||
|
||||
@ -54,6 +62,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class mappedPatchBase;
|
||||
template<class> class interpolation;
|
||||
|
||||
@ -64,6 +73,10 @@ template<class> class interpolation;
|
||||
template<class Type>
|
||||
class mappedPatchFieldBase
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Selective retrieval of "average" entry from the dictionary
|
||||
static Type getAverage(const dictionary& dict, bool mandatory);
|
||||
|
||||
protected:
|
||||
|
||||
@ -82,7 +95,7 @@ protected:
|
||||
const bool setAverage_;
|
||||
|
||||
//- Average value the mapped field is adjusted to maintain if
|
||||
// setAverage_ is set true
|
||||
//- setAverage_ is set true
|
||||
const Type average_;
|
||||
|
||||
//- Interpolation scheme to use for nearestcell mode
|
||||
@ -135,11 +148,10 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~mappedPatchFieldBase<Type>()
|
||||
{}
|
||||
virtual ~mappedPatchFieldBase<Type>() = default;
|
||||
|
||||
|
||||
// Member functions
|
||||
// Member Functions
|
||||
|
||||
//- Field to sample. Either on my or nbr mesh
|
||||
const GeometricField<Type, fvPatchField, volMesh>& sampleField() const;
|
||||
@ -148,7 +160,7 @@ public:
|
||||
virtual tmp<Field<Type>> mappedField() const;
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream&) const;
|
||||
virtual void write(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,10 +33,10 @@ Description
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
field | name of field to be mapped | no | this field name
|
||||
setAverage | flag to activate setting of average value | yes |
|
||||
average | average value to apply if \c setAverage = yes | yes |
|
||||
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 use if \c setAverage = yes | partly |
|
||||
\endtable
|
||||
|
||||
\verbatim
|
||||
@ -44,7 +44,7 @@ Usage
|
||||
{
|
||||
type mappedFixedInternalValue;
|
||||
field T;
|
||||
setAverage no;
|
||||
setAverage false;
|
||||
average 0;
|
||||
value uniform 0;
|
||||
}
|
||||
@ -155,13 +155,11 @@ public:
|
||||
|
||||
// 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
|
||||
virtual void write(Ostream&) const;
|
||||
virtual void write(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,10 +33,10 @@ Description
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
field | name of field to be mapped | no | this field name
|
||||
setAverage | flag to activate setting of average value | yes |
|
||||
average | average value to apply if \c setAverage = yes | yes |
|
||||
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 use if \c setAverage = yes | partly |
|
||||
\endtable
|
||||
|
||||
Example of the boundary condition specification:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,11 +36,11 @@ Description
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
field | name of field to be mapped | no | this field name
|
||||
setAverage | flag to activate setting of average value | yes |
|
||||
average | average value to apply if \c setAverage = yes | yes |
|
||||
interpolationScheme | type of interpolation scheme | no |
|
||||
Property | Description | Required | Default
|
||||
field | Field name to be mapped | no | this field name
|
||||
setAverage | Use average value | no | false
|
||||
average | Average value to use if \c setAverage = yes | partly |
|
||||
interpolationScheme | type of interpolation scheme | partly |
|
||||
\endtable
|
||||
|
||||
Example of the boundary condition specification:
|
||||
|
||||
@ -580,7 +580,10 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::write
|
||||
fieldTableName_
|
||||
);
|
||||
|
||||
os.writeEntryIfDifferent("setAverage", Switch(false), setAverage_);
|
||||
if (setAverage_)
|
||||
{
|
||||
os.writeEntry("setAverage", setAverage_);
|
||||
}
|
||||
|
||||
os.writeEntryIfDifferent<scalar>("perturb", 1e-5, perturb_);
|
||||
|
||||
|
||||
@ -47,13 +47,13 @@ Description
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
setAverage | Switch to activate setting of average value | no | false
|
||||
perturb | Perturb points for regular geometries | no | 1e-5
|
||||
points | Name of points file | no | points
|
||||
Property | Description | Required | Default
|
||||
setAverage | Use average value | no | false
|
||||
perturb | Perturb points for regular geometries | no | 1e-5
|
||||
points | Name of points file | no | points
|
||||
fieldTable | Alternative field name to sample | no | this field name
|
||||
mapMethod | Type of mapping | no | planarInterpolation
|
||||
offset | Offset to mapped values | no | Zero
|
||||
mapMethod | Type of mapping | no | planarInterpolation
|
||||
offset | Offset to mapped values | no | Zero
|
||||
\endtable
|
||||
|
||||
\verbatim
|
||||
|
||||
Reference in New Issue
Block a user