Commit 68408e68 authored by mattijs's avatar mattijs
Browse files

ENH: near-wall sampling : new 'patchInternalField' sampledSurface, new...

ENH: near-wall sampling : new 'patchInternalField' sampledSurface, new 'nearWallFields' functionObject
parent 6ab8e5a7
......@@ -166,6 +166,18 @@ surfaces
// triangulate false;
}
movingNearWall_interpolated
{
// Sample cell values off patch. Does not need to be the near-wall
// cell, can be arbitrarily far away.
type patchInternalField;
patchName movingWall;
distance 0.0001;
interpolate true;
// Optional: whether to leave as faces (=default) or triangulate
// triangulate false;
}
interpolatedIso
{
// Iso surface for interpolated values only
......
......@@ -142,6 +142,7 @@ $(derivedFvPatchFields)/pressureInletUniformVelocity/pressureInletUniformVelocit
$(derivedFvPatchFields)/pressureInletVelocity/pressureInletVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/rotatingPressureInletOutletVelocity/rotatingPressureInletOutletVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C
$(derivedFvPatchFields)/selfContainedDirectMapped/selfContainedDirectMappedFixedValueFvPatchFields.C
$(derivedFvPatchFields)/slip/slipFvPatchFields.C
$(derivedFvPatchFields)/supersonicFreestream/supersonicFreestreamFvPatchVectorField.C
$(derivedFvPatchFields)/surfaceNormalFixedValue/surfaceNormalFixedValueFvPatchVectorField.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ 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 "selfContainedDirectMappedFixedValueFvPatchField.H"
#include "volFields.H"
#include "interpolationCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
directMappedPatchBase(p.patch()),
fixedValueFvPatchField<Type>(p, iF),
fieldName_(iF.name()),
setAverage_(false),
average_(pTraits<Type>::zero),
interpolationScheme_(interpolationCell<Type>::typeName)
{}
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::selfContainedDirectMappedFixedValueFvPatchField
(
const selfContainedDirectMappedFixedValueFvPatchField<Type>& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
directMappedPatchBase(p.patch(), ptf),
fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
interpolationScheme_(ptf.interpolationScheme_)
{}
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::
selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
directMappedPatchBase(p.patch(), dict),
fixedValueFvPatchField<Type>(p, iF, dict),
fieldName_(dict.lookupOrDefault<word>("fieldName", iF.name())),
setAverage_(readBool(dict.lookup("setAverage"))),
average_(pTraits<Type>(dict.lookup("average"))),
interpolationScheme_(interpolationCell<Type>::typeName)
{
if (mode() == directMappedPatchBase::NEARESTCELL)
{
dict.lookup("interpolationScheme") >> interpolationScheme_;
}
}
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::
selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
// directMappedPatchBase
const word& sampleRegion,
const sampleMode sampleMode,
const word& samplePatch,
const scalar distance,
// My settings
const word& fieldName,
const bool setAverage,
const Type average,
const word& interpolationScheme
)
:
directMappedPatchBase
(
p.patch(),
sampleRegion,
sampleMode,
samplePatch,
distance
),
fixedValueFvPatchField<Type>(p, iF),
fieldName_(fieldName),
setAverage_(setAverage),
average_(average),
interpolationScheme_(interpolationScheme)
{}
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::selfContainedDirectMappedFixedValueFvPatchField
(
const selfContainedDirectMappedFixedValueFvPatchField<Type>& ptf
)
:
directMappedPatchBase(ptf.patch().patch(), ptf),
fixedValueFvPatchField<Type>(ptf),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
interpolationScheme_(ptf.interpolationScheme_)
{}
template<class Type>
selfContainedDirectMappedFixedValueFvPatchField<Type>::selfContainedDirectMappedFixedValueFvPatchField
(
const selfContainedDirectMappedFixedValueFvPatchField<Type>& ptf,
const DimensionedField<Type, volMesh>& iF
)
:
directMappedPatchBase(ptf.patch().patch(), ptf),
fixedValueFvPatchField<Type>(ptf, iF),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
interpolationScheme_(ptf.interpolationScheme_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const GeometricField<Type, fvPatchField, volMesh>&
selfContainedDirectMappedFixedValueFvPatchField<Type>::sampleField() const
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const fvMesh& nbrMesh = refCast<const fvMesh>(sampleMesh());
if (sameRegion())
{
if (fieldName_ == this->dimensionedInternalField().name())
{
// Optimisation: bypass field lookup
return
dynamic_cast<const fieldType&>
(
this->dimensionedInternalField()
);
}
else
{
const fvMesh& thisMesh = this->patch().boundaryMesh().mesh();
return thisMesh.lookupObject<fieldType>(fieldName_);
}
}
else
{
return nbrMesh.lookupObject<fieldType>(fieldName_);
}
}
template<class Type>
const interpolation<Type>&
selfContainedDirectMappedFixedValueFvPatchField<Type>::interpolator() const
{
if (!interpolator_.valid())
{
interpolator_ = interpolation<Type>::New
(
interpolationScheme_,
sampleField()
);
}
return interpolator_();
}
template<class Type>
void selfContainedDirectMappedFixedValueFvPatchField<Type>::updateCoeffs()
{
if (this->updated())
{
return;
}
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const fvMesh& thisMesh = this->patch().boundaryMesh().mesh();
const fvMesh& nbrMesh = refCast<const fvMesh>(sampleMesh());
const mapDistribute& distMap = directMappedPatchBase::map();
// Result of obtaining remote values
Field<Type> newValues;
switch (mode())
{
case NEARESTCELL:
{
if (interpolationScheme_ != interpolationCell<Type>::typeName)
{
// Need to do interpolation so need cells to sample.
// Send back sample points to the processor that holds the cell
vectorField samples(samplePoints());
distMap.reverseDistribute
(
(sameRegion() ? thisMesh.nCells() : nbrMesh.nCells()),
point::max,
samples
);
const interpolation<Type>& interp = interpolator();
newValues.setSize(samples.size(), pTraits<Type>::max);
forAll(samples, cellI)
{
if (samples[cellI] != point::max)
{
newValues[cellI] = interp.interpolate
(
samples[cellI],
cellI
);
}
}
}
else
{
newValues = sampleField();
}
distMap.distribute(newValues);
break;
}
case NEARESTPATCHFACE:
{
const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
(
samplePatch()
);
if (nbrPatchID < 0)
{
FatalErrorIn
(
"void selfContainedDirectMappedFixedValueFvPatchField<Type>::"
"updateCoeffs()"
)<< "Unable to find sample patch " << samplePatch()
<< " in region " << sampleRegion()
<< " for patch " << this->patch().name() << nl
<< abort(FatalError);
}
const fieldType& nbrField = sampleField();
newValues = nbrField.boundaryField()[nbrPatchID];
distMap.distribute(newValues);
break;
}
case NEARESTFACE:
{
Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
const fieldType& nbrField = sampleField();
forAll(nbrField.boundaryField(), patchI)
{
const fvPatchField<Type>& pf =
nbrField.boundaryField()[patchI];
label faceStart = pf.patch().start();
forAll(pf, faceI)
{
allValues[faceStart++] = pf[faceI];
}
}
distMap.distribute(allValues);
newValues.transfer(allValues);
break;
}
default:
{
FatalErrorIn
(
"selfContainedDirectMappedFixedValueFvPatchField<Type>::updateCoeffs()"
)<< "Unknown sampling mode: " << mode()
<< nl << abort(FatalError);
}
}
if (setAverage_)
{
Type averagePsi =
gSum(this->patch().magSf()*newValues)
/gSum(this->patch().magSf());
if (mag(averagePsi)/mag(average_) > 0.5)
{
newValues *= mag(average_)/mag(averagePsi);
}
else
{
newValues += (average_ - averagePsi);
}
}
this->operator==(newValues);
if (debug)
{
Info<< "selfContainedDirectMapped on field:"
<< this->dimensionedInternalField().name()
<< " patch:" << this->patch().name()
<< " avg:" << gAverage(*this)
<< " min:" << gMin(*this)
<< " max:" << gMax(*this)
<< endl;
}
fixedValueFvPatchField<Type>::updateCoeffs();
}
template<class Type>
void selfContainedDirectMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
{
fvPatchField<Type>::write(os);
directMappedPatchBase::write(os);
os.writeKeyword("fieldName") << fieldName_ << token::END_STATEMENT << nl;
os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
os.writeKeyword("interpolationScheme") << interpolationScheme_
<< token::END_STATEMENT << nl;
this->writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ 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::selfContainedDirectMappedFixedValueFvPatchField
Description
Self-contained version of directMapped. Does not use information on
patch, instead holds it locally (and possibly duplicate) so use
normal directMapped in preference and only use this if you cannot
change the underlying patch type to directMapped.
SourceFiles
selfContainedDirectMappedFixedValueFvPatchField.C
\*---------------------------------------------------------------------------*/
#ifndef selfContainedDirectMappedFixedValueFvPatchField_H
#define selfContainedDirectMappedFixedValueFvPatchField_H
#include "directMappedPatchBase.H"
#include "fixedValueFvPatchFields.H"
#include "interpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class selfContainedDirectMappedFixedValueFvPatch Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class selfContainedDirectMappedFixedValueFvPatchField
:
public directMappedPatchBase,
public fixedValueFvPatchField<Type>
{
// Private data
//- Name of field to sample - defaults to field associated with this
// patchField if not specified
word fieldName_;
//- If true adjust the mapped field to maintain average value average_
const bool setAverage_;
//- Average value the mapped field is adjusted to maintain if
// setAverage_ is set true
const Type average_;
//- Interpolation scheme to use for nearestcell mode
word interpolationScheme_;
mutable autoPtr<interpolation<Type> > interpolator_;
// Private Member Functions
//- Field to sample. Either on my or nbr mesh
const GeometricField<Type, fvPatchField, volMesh>& sampleField() const;
//- Access the interpolation method
const interpolation<Type>& interpolator() const;
public:
//- Runtime type information
TypeName("selfContainedDirectMapped");
// Constructors
//- Construct from patch and internal field
selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&
);
//- Construct from patch, internal field and dictionary
selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const dictionary&
);
//- Construct from patch, internal field and distance for normal type
// sampling
selfContainedDirectMappedFixedValueFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
// directMappedPatchBase
const word& sampleRegion,
const sampleMode sampleMode,
const word& samplePatch,
const scalar distance,
// My settings
const word& fieldName,
const bool setAverage,
const Type average,
const word& interpolationScheme
);
//- Construct by mapping given selfContainedDirectMappedFixedValueFvPatchField
// onto a new patch
selfContainedDirectMappedFixedValueFvPatchField
(
const selfContainedDirectMappedFixedValueFvPatchField<Type>&,
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
selfContainedDirectMappedFixedValueFvPatchField
(
const selfContainedDirectMappedFixedValueFvPatchField<Type>&
);
//- Construct and return a clone
virtual tmp<fvPatchField<Type> > clone() const
{
return tmp<fvPatchField<Type> >
(
new selfContainedDirectMappedFixedValueFvPatchField<Type>(*this)