Professional Documents
Culture Documents
Tomislav Maric
Disclaimer
Jens Hpken, Tomislav Maric and sourceflux 2015. Unauthorized use and/or
duplication of this material without express and written permission from this
blogs author and/or owner is strictly prohibited. Excerpts and links may be used,
provided that full and clear credit is given to Jens Hpken, Tomislav Maric and
sourceflux with appropriate and specific direction to the original content.
Outline
Prerequisites
Outline
Learning goals
A generic BC library
A generic BC library
Templates!
A generic BC library
A generic BC library
An oscillating BC : specification
What do we know
Oscillation : extends behavior of a BC.
Oscillating BC is a BC.
Why would we publicly inherit from fvPatchField?
It needs to know about the underlying BC:
Initialize the underlying BC.
Update the underlying BC.
Modify its values to account for oscillation.
A generic BC library
An oscillating BC : design
A generic BC library
No worries. . .
fvPatchField 1..2
updateCoeffs()
fixedValueFvPatchField oscillatingFvPatchField
updateCoeffs() updateCoeffs()
A generic BC library
f ,w = 0f ,w cos(t)
f ,d = f ,w
A generic BC library
A generic BC library
We will use the mighty cavity test case for test driven development.
?> cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity cavityOscillating
?> cd !$
Edit: 0/U
boundaryField
{
movingWall
{
type oscillating;
wrappedType
{
type fixedValue;
value uniform (1 0 0);
}
}
Execute: blockMesh, then icoFoam in the case directory.
A generic BC library
73
(
SRFFreestreamVelocity
SRFVelocity
activeBaffleVelocity
activePressureForceBaffleVelocity
advective
calculated
codedFixedValue
A generic BC library
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools
A generic BC library
Edit: Make/files
oscillatingFvPatchField/oscillatingFvPatchFields.C
LIB = $(FOAM_USER_LIBBIN)/libextendedBoundaryConditions
A generic BC library
A generic BC library
A generic BC library
Edit: oscillatingFvPatchField.H
Delete existing include statements.
Add
#include "fvPatchField.H"
A generic BC library
A generic BC library
Edit: oscillatingFvPatchField.H
Delete all arithmetic operators coming from fvPatchField.
Delete the member function bodies of:
valueInternalCoeffs
valueBoundaryCoeffs
gradientInternalCoeffs
gradientBoundaryCoeffs
fvPatchField is a class template: check the macros at the EOF.
They generate the definition of the virtual type() m-function.
They initialize the debug flag (class-static label).
They generate the definition for the internal RTS table class.
Now delete those macros : they are also re-used from fvPatchField.
A generic BC library
A generic BC library
An oscillating BC : implementation
Edit: oscillatingFvPatchField.C
Forward all constructor calls:
namespace Foam {
template<class Type>
oscillatingFvPatchField<Type>::oscillatingFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
fvPatchField<Type>(p, iF),
wrappedTmp_(new fvPatchField<Type>(p, iF)),
wrappedInitialTmp_(new fvPatchField<Type>(p, iF))
{}
We have one base and two wrapped BCs to initialize.
Repeat for all constructors.
Extend Foam namespace and save time in typing Foam::.
Boundary Conditions Training Decorating Boundary conditions (BC)s A generic BC library 23
Decorating Boundary conditions (BC)s
A generic BC library
An oscillating BC : implementation
We could have also left this one out, since we are assigning values to
Decorator.
A generic BC library
An oscillating BC : implementation
Edit: oscillatingFvPatchField.C
Implement:
valueInternalCoeffs
valueBoundaryCoeffs
gradientInternalCoeffs
gradientBoundaryCoeffs
You will behave as the modified (decorated) wrapped BC:
template<class Type>
tmp<Field<Type> >
oscillatingFvPatchField<Type>::valueInternalCoeffs
(
const tmp<scalarField>& tsf
) const
{
return wrappedTmp_->valueInternalCoeffs(tsf);
}
Repeat for other m-functions.
Boundary Conditions Training Decorating Boundary conditions (BC)s A generic BC library 25
Decorating Boundary conditions (BC)s
A generic BC library
A generic BC library
A generic BC library
#include "oscillatingFvPatchFields.H"
#include "fvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
namespace Foam
{
makePatchFields(oscillating);
}
A generic BC library
A generic BC library
A generic BC library
namespace Foam
{
makePatchTypeFieldTypedefs(oscillating);
A generic BC library
Edit : oscillatingFvPatchFieldsFwd.H
#include "fieldTypes.H"
makePatchTypeFieldTypedefs(oscillatingFvPatchField);
#endif
A generic BC library
A generic BC library
Edit: system/controlDict
libs ("libextendedBoundaryConditions.so");
A generic BC library
A generic BC library
endTime 6;
deltaT 0.01;
writeControl runTime;
writeInterval 0.1;
A generic BC library
wallUp
{
type oscillating;
wrappedType
{
type fixedValue;
value uniform (1 0 0);
}
}
wallRight
{
type oscillating;
wrappedType
{
type zeroGradient;
}
}
A generic BC library
code
#{
const fvPatch& boundaryPatch = patch();
const vectorField& Cf = boundaryPatch.Cf();
forAll(Cf, faceI)
{
// Quadratic ramp.
bcField[faceI] =
vector(-Foam::pow(Cf[faceI].x(), 2), 0, 0);
}
#};
}
}
Boundary Conditions Training Decorating Boundary conditions (BC)s A generic BC library 38
Decorating Boundary conditions (BC)s
A generic BC library
Conclusions
A generic BC library