Professional Documents
Culture Documents
sourceflux
June 2016
Disclaimer
© Jens Höpken, Tomislav Maric and sourceflux 2016. Unauthorized use and/or
duplication of this material without express and written permission from this
blog’s author and/or owner is strictly prohibited. Excerpts and links may be used,
provided that full and clear credit is given to Jens Höpken, Tomislav Maric and
sourceflux with appropriate and specific direction to the original content.
<sarcasm>
3
A brief Introduction to fvOptions References
Outline
Learning goals
Understanding fvOptions
Capabilities
Setup the fvOptions dictionary
Prototype new sources
Fundamentals
Fundamentals
Fundamentals
Supported Solvers
Almost all
Fundamentals
Supported Solvers
Equations affected:
Momentum
Energy
Scalar
Temperature Almost all
Fundamentals
Supported Solvers
Equations affected:
Momentum
Energy
Scalar
Temperature Almost all
Fundamentals
Usage
Defined in system/fvOptions.
Spatially selected using sets or zones.
Any number sources can be used.
Sourceterms are:
calculated at runtime.
usually not written to the case.
composed of explicit and linearized-implicit components.
Fundamentals
Mathematical Background
Source Term S (x )
Fundamentals
Mathematical Background
Source Term S (x )
Explicit part Su
Fundamentals
Mathematical Background
Source Term S (x )
Fundamentals
Mathematical Background
Source Term S (x )
Source terms must be linearized before being discretized Patankar [1980], Jasak
[1996].
S (x ) = Su + Sp x
Fundamentals
Sources are:
applied before solving respective equations.
most commonly used.
Constraints are:
applied after respective transport equation is solved.
overriding specific values in the matrix explicitely.
used less frequently.
interfering with the solution after the equation is solved.
Only 2 exist.
No specific application.
No specific equation.
semiImplicitSource I - Background
template<class Type>
void Foam::fv::SemiImplicitSource<Type>::addSup
(
fvMatrix<Type>& eqn,
const label fieldI
)
{
//...
//...
semiImplicitSource I - Background
template<class Type>
void Foam::fv::SemiImplicitSource<Type>::addSup
(
fvMatrix<Type>& eqn,
const label fieldI
)
{
//...
//...
semiImplicitSource II - Background
semiImplicitSource II - Background
U ( (0 0 0) 0 );
semiImplicit
{
type vectorSemiImplicitSource;
active true;
selectionMode cellZone;
cellZone semi;
vectorSemiImplicitSourceCoeffs
{
volumeMode absolute;
injectionRateSuSp
{
U ((1 1 1) 0);
}
}
}
codedSource I - Background
User coded.
Runtime compiled.
No need for an extra customized library to be compiled.
Somewhat similar to codedFunctionObject and
codedBoundaryCondition.
Deligates compilation to codedBase (very important).
Plugs into hooks, that are called at certain (predefined) points.
codedSource I - Background
User coded.
Runtime compiled.
No need for an extra customized library to be compiled.
Somewhat similar to codedFunctionObject and
codedBoundaryCondition.
Deligates compilation to codedBase (very important).
Plugs into hooks, that are called at certain (predefined) points.
Hooks:
codeInclude
codeCorrect
codeAddSup
codeSetValue
code
tmp<fvVectorMatrix> UEqn
(
fvm::div(phi, U)
+ turbulence->divDevReff(U)
==
fvOptions(U)
);
UEqn().relax();
fvOptions.constrain(UEqn());
solve(UEqn() == -fvc::grad(p));
fvOptions.correct(U);
UEqn().relax();
fvOptions.constrain(UEqn());
solve(UEqn() == -fvc::grad(p));
fvOptions.correct(U);
fvOptions.constrain(UEqn());
solve(UEqn() == -fvc::grad(p));
fvOptions.correct(U);
fvOptions.constrain(UEqn());
solve(UEqn() == -fvc::grad(p));
fvOptions.correct(U)
Corrects the field values, solved for.
fvOptions.correct(U);
energySource
{
type scalarCodedSource;
active true;
selectionMode all;
scalarCodedSourceCoeffs
{
}
sourceTimeCoeffs
{
// Dummy entry
}
}
codedSource IV - Usage
fieldNames (U);
redirectType sourceTime;
codeInclude
#{
#};
codeCorrect
#{
#};
codeAddSup
#{
#};
codeSetValue
#{
#};
code
#{
$codeInclude
$codeCorrect
$codeAddSup
$codeSetValue
#};
codedSource V - Usage
codeInclude
#{
// All required additional includes.
//
// An example for this would be:
#include "scalar.H"
#};
codedSource VI - Usage
codeCorrect
#{
// Code that goes into void correct.
//
// An example for this would be:
Pout<< "I'm correcting now" << endl;
#};
codeAddSup
#{
// Code that goes into void addSup.
// This is where the source terms are added to the RHS.
// Using this creates a "source".
//
// An example for this would be:
scalarField& fooSource = eqn.source();
fooSource -= time.value();
#};
codeSetValue
#{
// Code that goes into void setValue.
// This is where values can be overridden, after solving the
// respective equations. Using this creates a "constraint".
//
// An example for this would be:
Pout<< "I'm setting values now" << endl;
#};
8 exist.
Usually model specific.
MRF got was removed after being encapsulated m(.
tmp<fvVectorMatrix> UEqn
(
fvm::div(phi, U)
+ MRF.DDt(U)
+ turbulence->divDevReff(U)
fvOptions(U)
);
UEqn().relax();
fvOptions.constrain(UEqn());
solve(UEqn() == -fvc::grad(p));
fvOptions.correct(U);
actuationDiskSource I - Background
Vi
S= TE · Uupstream (1)
Vtotal
Coefficient a:
CP
a =1− (3)
CT
actuationDiskSource II - Usage
disk
{
type actuationDiskSource;
active on;
actuationDiskSourceCoeffs
{
cellSet disk;
selectionMode cellSet;
fieldNames (U);
diskDir (1 0 0);
Cp 0.4;
Ct 0.6;
diskArea 1.2;
upstreamPoint (1 1 1);
}
}
actuationDiskSource IV - Example
actuationDiskSource V - Example
Execute topoSet
?> topoSet
You can usually find an example dicionary in the header of the respective fvOption
you are using. Or not.
actuationDiskSource VI - Example
disk
{
type actuationDiskSource;
active on;
selectionMode cellZone;
cellZone disk;
actuationDiskSourceCoeffs
{
fieldNames (U);
diskDir (1 0 0);
Cp 0.4;
Ct 0.6;
diskArea 1.2;
upstreamPoint (5 5 5);
}
}
The Workflow
Use codedSource - it makes your life easier!
The Workflow
Use codedSource - it makes your life easier!
reads calls
system/fvOptions Solver Application codedBase
is linked to
creates sources
Library and compiles to
The Workflow
Use codedSource - it makes your life easier!
reads calls
system/fvOptions Solver Application codedBase
is linked to
creates sources
Library and compiles to
Su = Ut (4)
code
{
type vectorCodedSource;
active true;
Templated on Type.
vectorCodedSourceCoeffs Type basically bassed via type entry.
{ Add actual type as prefix.
selectionMode all;
}
sourceTimeCoeffs
{
// Don't add anything
}
}
code
{
type vectorCodedSource;
active true;
Templated on Type.
vectorCodedSourceCoeffs Type basically bassed via type entry.
{ Add actual type as prefix.
selectionMode all;
}
Only incremental changes shown in the
sourceTimeCoeffs following.
{
// Don't add anything
}
}
vectorCodedSourceCoeffs
{
fieldNames (U);
redirectType sourceTime;
codeInclude
#{
// We don't need any, at this point.
// If we would, these could be added like the following:
// #include "scalar.H"
#};
}
vectorCodedSourceCoeffs
{
// [..]
codeCorrect
#{
// Nothing to add here either, for this applicaition
// If we would, these could be added like the following:
// fld = fld*10;
#};
}
Remember, this hooks into:
virtual void correct(volScalarField& fld);
It provides non-constant access to the respective field.
vectorCodedSourceCoeffs
{
// [..]
codeSetValue
#{
// Not needed for this example
#};
}
Similar to codedFunctionObject.
And now?
?> ls dynamicCode/sourceTime
codedFvOptionTemplate.C codedFvOptionTemplate.dep
codedFvOptionTemplate.H lnInclude/
Make/
?> ls dynamicCode/sourceTime
codedFvOptionTemplate.C codedFvOptionTemplate.dep
codedFvOptionTemplate.H lnInclude/
Make/
2 Rename sourceTimeFvOptionvectorSource to
sledgeHammerFvOptionvectorSource:
?> sed -i "s/sourceTimeFvOptionvectorSource/sledgeHammerFvOptionvectorSource/g" \
*.[C,H]
sledgeHammerFvOptionvectorSource.C
LIB = $(FOAM_USER_LIBBIN)/sledgeHammer
5 Check if it compiles:
?> wmake libso
sledgeHammerFvOptionvectorSource.C
LIB = $(FOAM_USER_LIBBIN)/sledgeHammer
5 Check if it compiles:
?> wmake libso
Hrvoje Jasak. Error analysis and estimation for the finite volume method with
applications to fluid flows. PhD thesis, Imperial College London, 1996.
S. Patankar. Numerical Heat Transfer and Fluid Flow. Series in computational
methods in mechanics and thermal sciences. Taylor & Francis, 1980. ISBN
9780891165224.