SWAK
againswak4Foam
swak4Foam
PyFoam
swak4Foam
swak
swak4Foam
From http://openfoamwiki.net/index.php/Contrib/swak4Foam
swak4Foam
stands for SWiss Army Knife for Foam. Like that knife it
rarely is the best tool for any given task, but sometimes it is more
convenient to get it out of your pocket than going to the tool-shed to
get the chain-saw.
and has grown since
swak4Foam
swak4Foam
is a collection of parsers (subroutines
that read a string and interpret it) for expressions on
OpenFOAM
-types
faceSet
, cellZone
etc)
swak4foam
tries to reduce the need for throwaway C++ programs
for case setup and postprocessing
Similar in scope to this presentation. But with a different feature-set
Despite the title also uses swak4Foam for evaluations
Describes several advanced features of OpenFOAM using one case
Until now the parsers were available for
Name | Where it worked | Main use |
---|---|---|
field | internal field | funkySetFields |
patch | on a patch | groovyBC |
set | sampled set | swakExpression |
surface | sampled surface | swakExpression |
sets & zones | cell/face/point sets/zones | swakExpression |
but not for …
A swakExpression
-function object with specifications like this
valueType cloud; cloudName someCloudName; expression "(mass0-mass)/mass0"; accumulations (min max);
will print biggest and smallest relative change in particle mass
mass0
and mass
The first time a parser is used a list like this is printed to the terminal
Driver for cloud limestoneCloud1 of type Cloud<basicThermoParcel> (Proxy type: CloudProxy) List of functions: Name | Type | Description -------------------------------------------------------------- Pr | scalar | Default carrier Prandtl number (constant) T | scalar | Temperature T0 | scalar | Initial temperature (constant) TMin | scalar | Minimum temperature (constant) U | vector | Velocity UTurb | vector | Turbulent velocity fluctuations active | bool | Is this parcel active? areaP | scalar | Particle projected area areaS | scalar | Particle surface area cell | scalar | number of the cell cp | scalar | Specific heat capacity cp0 | scalar | Specific heat capacity (constant) currentTime | scalar | current time of the particle d | scalar | Diameter epsilon0 | scalar | Particle emissivity (constant) f0 | scalar | Particle scattering factor (constant) face | scalar | number of the face
A swakExpression
like this
valueType cloud; cloudName someCloudName; expression "T-fluidPhase(T)"; accumulations (min max); interpolationSchemes { T cell; }
calculates the differences of the particle temperatures to the fluid temperatures interpoalted to the particle positions.
simplifiedSiwek
-case for the coalChemistryFoam
-solver
that comes with OpenFOAM
funkySetLagrangianField
funkySetField
:
funkySetLagrangianField -time 0: -expression "T-fluidPhase(T)" -field TDiff -create -cloud aCloud -defaultInterpolation cell
ParaView
funkySetLagrangianField
funkySetFields
createCloud
is specified in funkySetLagrangianFieldDict
then
expressions
-list will be executed to add even
more fields to the cloud
BTW: you don't necessarily have to use the cloud for simulation. You can also use it as a fancy (but flexible) way to add Glyphs in ParaView
These are the clouds:
simplifiedSiewek
runningMovies are fine, but we want numbers …
This entry in controlDict
coalMassChange { type swakExpression; outputControlMode timeStep; verbose true; valueType cloud; cloudName coalCloud1; expression "max(mass0-mass,1e-15)"; accumulations ( min max weightedAverage weightedMedian weightedQuantile0.05 weightedQuantile0.95 ); }
Produces this data
Until now swak
only provided the accumulations that were
implemented by OpenFOAM
But the inclusion of distributions in the last release made several more possible
average
quantile0.25
for instance is the value for which
25% of the distribution are smaller than it
range0.9
gives the
range in which 90% of the values are (from the quantile
5% to 95%)
smaller
weight()
has been added to the parsers
weighted
that takes the weight into account
expression "T*vol()/sum(vol())"; accumulations ( sum )
to get a proper average temperature one can now write
expression "T"; accumulations ( weightedAverage )
fieldReport
bringsSimply calling this utility like this
fieldReport T -time 0:
Generates output like this
Time = 0 Reading Field T of type volScalarField Internal field: Size | Weight Sum 2500 | 0.0275 Range (min-max) 350.5 | 449.5 Average | weighted 380 | 379.5454545 Sum | weighted 950000 | 10.4375 Median | weighted 377.3777778 | 377.1
fieldReport T -time 0: -doBoundary -fractionSmallerThan 350 -fractionBiggerThan 1000 -csvName TFieldValues.csv -nrOfQuantiles 10 -distributionsDirectory TFieldDist Time = 0.75 Reading Field T of type volScalarField Writing distributions to "TFieldDist/0.75" Patch field: top Size | Weight Sum 5 | 0.005 Range (min-max) 323.3613936 | 345.5260693 Average | weighted 333.9216142 | 333.9216142 Sum | weighted 1669.608071 | 1.669608071 Median | weighted 331.15 | 331.15 0.1 quantile | weighted 323.35 | 323.35 0.2 quantile | weighted 323.4 | 323.4 0.3 quantile | weighted 326 | 326 0.4 quantile | weighted 328.6 | 328.6 0.5 quantile | weighted 331.15 | 331.15 0.6 quantile | weighted 333.7 | 333.7 0.7 quantile | weighted 336.15 | 336.15 0.8 quantile | weighted 338.6 | 338.6 0.9 quantile | weighted 342.1 | 342.1 x <= 350 | weighted 1 | 1 x > 1000 | weighted 0 | 0
Python
funkyPythonPostproc
was written with this kind of
application in mind
Python
-interpreter and runs an initial script
numpy
-arrays
The real action happens in line 2
times.append(runTime) r=stats.linregress(positions,diameter) slopes.append(r[0]) offsets.append(r[1]) f=pyplot.figure() pyplot.title("Diameters at t=%f" % runTime) pyplot.xlabel('y-direction [m]') pyplot.ylabel('diameter [m]') data=pyplot.plot(positions,diameter,'b.',label="Data") xLine=numpy.array([0.,1.]) line=pyplot.plot(xLine,r[1]+r[0]*xLine,'r',label="Fit") a=line[0].get_axes() text="d = %f * y + %f" % r[:2] pyplot.text(0.1,0.1,text,transform=a.transAxes) pyplot.legend() pyplot.savefig("Diameter_%04d.png" % index)
The end-script plots the coefficients of the regression as a function of time:
pyplot.figure() pyplot.xlabel("Time [s]") pyplot.subplot(2,1,1) pyplot.title("Development of parameters over time") pyplot.plot(times,offsets,"r") pyplot.ylabel("Offset [m]") pyplot.subplot(2,1,2) pyplot.plot(times,slopes,"g") pyplot.ylabel("Slope [m/m]") pyplot.xlabel("Time [s]")
swakExpressionAverageDistribution
that could be used for looking at this
plotDistributions { type swakExpressionAverageDistribution; verbose true; outputControlMode timeStep; outputInterval 1; expression "d"; weight "weight()"; mask "true"; abscissa "pos().y"; valueType cloud; cloudName limestoneCloud1; binNumber 20; valueIfZero 0; }
swak4Foam
-release 0.3.0
I keep forgetting and have to check the README
myself
mask
-expression in swakExpression
(and friends) to select
values before accumulation
IPython
-inclusion etc)
Was written with
HTML5
-framework for presentation