Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lbmpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
lbmpy
Commits
3e088e59
Commit
3e088e59
authored
7 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Worked on waLBerla kernel generation
parent
61926536
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
creationfunctions.py
+26
-10
26 additions, 10 deletions
creationfunctions.py
macroscopic_value_kernels.py
+2
-2
2 additions, 2 deletions
macroscopic_value_kernels.py
plot2d.py
+9
-0
9 additions, 0 deletions
plot2d.py
updatekernels.py
+46
-4
46 additions, 4 deletions
updatekernels.py
with
83 additions
and
16 deletions
creationfunctions.py
+
26
−
10
View file @
3e088e59
...
@@ -53,6 +53,8 @@ General:
...
@@ -53,6 +53,8 @@ General:
- ``output={}``: a dictionary mapping macroscopic quantites e.g. the strings
'
density
'
and
'
velocity
'
to pystencils
- ``output={}``: a dictionary mapping macroscopic quantites e.g. the strings
'
density
'
and
'
velocity
'
to pystencils
fields. In each timestep the corresponding quantities are written to the given fields.
fields. In each timestep the corresponding quantities are written to the given fields.
- ``velocityInput``: symbolic field where the velocities are read from (for advection diffusion LBM)
- ``velocityInput``: symbolic field where the velocities are read from (for advection diffusion LBM)
- ``kernelType``: supported values:
'
streamPullCollide
'
(default),
'
collideOnly
'
Entropic methods:
Entropic methods:
...
@@ -153,7 +155,8 @@ from lbmpy.methods.relaxationrates import relaxationRateFromMagicNumber
...
@@ -153,7 +155,8 @@ from lbmpy.methods.relaxationrates import relaxationRateFromMagicNumber
from
lbmpy.stencils
import
getStencil
from
lbmpy.stencils
import
getStencil
import
lbmpy.forcemodels
as
forceModels
import
lbmpy.forcemodels
as
forceModels
from
lbmpy.simplificationfactory
import
createSimplificationStrategy
from
lbmpy.simplificationfactory
import
createSimplificationStrategy
from
lbmpy.updatekernels
import
createStreamPullKernel
,
createPdfArray
from
lbmpy.updatekernels
import
createStreamPullCollideKernel
,
createPdfArray
,
createCollideOnlyKernel
,
\
createStreamPullOnlyKernel
from
pystencils.equationcollection.equationcollection
import
EquationCollection
from
pystencils.equationcollection.equationcollection
import
EquationCollection
...
@@ -166,7 +169,7 @@ def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True):
...
@@ -166,7 +169,7 @@ def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True):
'
equilibriumAccuracyOrder
'
:
2
,
'
equilibriumAccuracyOrder
'
:
2
,
'
c_s_sq
'
:
sp
.
Rational
(
1
,
3
),
'
c_s_sq
'
:
sp
.
Rational
(
1
,
3
),
'
forceModel
'
:
'
none
'
,
# can be 'simple', 'luo' or 'guo'
'
forceModel
'
:
'
none
'
,
'
force
'
:
(
0
,
0
,
0
),
'
force
'
:
(
0
,
0
,
0
),
'
useContinuousMaxwellianEquilibrium
'
:
True
,
'
useContinuousMaxwellianEquilibrium
'
:
True
,
'
cumulant
'
:
False
,
'
cumulant
'
:
False
,
...
@@ -178,6 +181,11 @@ def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True):
...
@@ -178,6 +181,11 @@ def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True):
'
output
'
:
{},
'
output
'
:
{},
'
velocityInput
'
:
None
,
'
velocityInput
'
:
None
,
'
kernelType
'
:
'
streamPullCollide
'
,
'
fieldName
'
:
'
src
'
,
'
secondFieldName
'
:
'
dst
'
,
}
}
defaultOptimizationDescription
=
{
defaultOptimizationDescription
=
{
...
@@ -340,23 +348,31 @@ def createLatticeBoltzmannUpdateRule(lbMethod=None, optimizationParams={}, **kwa
...
@@ -340,23 +348,31 @@ def createLatticeBoltzmannUpdateRule(lbMethod=None, optimizationParams={}, **kwa
else
:
else
:
collisionRule
=
addEntropyCondition
(
collisionRule
,
omegaOutputField
=
params
[
'
omegaOutputField
'
])
collisionRule
=
addEntropyCondition
(
collisionRule
,
omegaOutputField
=
params
[
'
omegaOutputField
'
])
kernelCreateArgs
=
{}
if
'
fieldSize
'
in
optParams
and
optParams
[
'
fieldSize
'
]:
if
'
fieldSize
'
in
optParams
and
optParams
[
'
fieldSize
'
]:
npField
=
createPdfArray
(
optParams
[
'
fieldSize
'
],
len
(
stencil
),
layout
=
optParams
[
'
fieldLayout
'
])
npField
=
createPdfArray
(
optParams
[
'
fieldSize
'
],
len
(
stencil
),
layout
=
optParams
[
'
fieldLayout
'
])
updateRule
=
createStreamPullKernel
(
collisionRule
,
numpyField
=
npField
,
kernelCreateArgs
[
'
numpyField
'
]
=
npField
builtinPeriodicity
=
optParams
[
'
builtinPeriodicity
'
])
else
:
else
:
if
'
pdfArr
'
in
optParams
:
if
'
pdfArr
'
in
optParams
:
updateRule
=
createStreamPullKernel
(
collisionRule
,
numpyField
=
optParams
[
'
pdfArr
'
],
kernelCreateArgs
[
'
numpyField
'
]
=
optParams
[
'
pdfArr
'
]
builtinPeriodicity
=
optParams
[
'
builtinPeriodicity
'
])
else
:
else
:
layoutName
=
optParams
[
'
fieldLayout
'
]
layoutName
=
optParams
[
'
fieldLayout
'
]
if
layoutName
==
'
fzyx
'
or
'
zyxf
'
:
if
layoutName
==
'
fzyx
'
or
'
zyxf
'
:
dim
=
len
(
stencil
[
0
])
dim
=
len
(
stencil
[
0
])
layoutName
=
tuple
(
reversed
(
range
(
dim
)))
layoutName
=
tuple
(
reversed
(
range
(
dim
)))
updateRule
=
createStreamPullKernel
(
collisionRule
,
genericLayout
=
layoutName
,
kernelCreateArgs
[
'
genericLayout
'
]
=
layoutName
builtinPeriodicity
=
optParams
[
'
builtinPeriodicity
'
])
if
params
[
'
kernelType
'
]
==
'
streamPullCollide
'
:
return
updateRule
kernelCreateArgs
[
'
srcFieldName
'
]
=
params
[
'
fieldName
'
]
kernelCreateArgs
[
'
dstFieldName
'
]
=
params
[
'
secondFieldName
'
]
kernelCreateArgs
[
'
builtinPeriodicity
'
]
=
optParams
[
'
builtinPeriodicity
'
]
return
createStreamPullCollideKernel
(
collisionRule
,
**
kernelCreateArgs
)
elif
params
[
'
kernelType
'
]
==
'
collideOnly
'
:
kernelCreateArgs
[
'
fieldName
'
]
=
params
[
'
fieldName
'
]
return
createCollideOnlyKernel
(
collisionRule
,
**
kernelCreateArgs
)
else
:
raise
ValueError
(
"
Invalid value of parameter
'
kernelType
'"
,
params
[
'
kernelType
'
])
def
createLatticeBoltzmannMethod
(
**
params
):
def
createLatticeBoltzmannMethod
(
**
params
):
...
...
This diff is collapsed.
Click to expand it.
macroscopic_value_kernels.py
+
2
−
2
View file @
3e088e59
...
@@ -184,9 +184,9 @@ def compileAdvancedVelocitySetter(method, velocityArray, velocityRelaxationRate=
...
@@ -184,9 +184,9 @@ def compileAdvancedVelocitySetter(method, velocityArray, velocityRelaxationRate=
:param optimizationParams: dictionary with optimization hints
:param optimizationParams: dictionary with optimization hints
:return: stream-collide update function
:return: stream-collide update function
"""
"""
from
lbmpy.updatekernels
import
createStreamPullKernel
from
lbmpy.updatekernels
import
createStreamPull
Collide
Kernel
from
lbmpy.creationfunctions
import
createLatticeBoltzmannAst
,
createLatticeBoltzmannFunction
from
lbmpy.creationfunctions
import
createLatticeBoltzmannAst
,
createLatticeBoltzmannFunction
newCollisionRule
=
createAdvancedVelocitySetterCollisionRule
(
method
,
velocityArray
,
velocityRelaxationRate
)
newCollisionRule
=
createAdvancedVelocitySetterCollisionRule
(
method
,
velocityArray
,
velocityRelaxationRate
)
updateRule
=
createStreamPullKernel
(
newCollisionRule
,
pdfArr
,
genericLayout
=
fieldLayout
)
updateRule
=
createStreamPull
Collide
Kernel
(
newCollisionRule
,
pdfArr
,
genericLayout
=
fieldLayout
)
ast
=
createLatticeBoltzmannAst
(
updateRule
,
optimizationParams
)
ast
=
createLatticeBoltzmannAst
(
updateRule
,
optimizationParams
)
return
createLatticeBoltzmannFunction
(
ast
,
optimizationParams
)
return
createLatticeBoltzmannFunction
(
ast
,
optimizationParams
)
This diff is collapsed.
Click to expand it.
plot2d.py
+
9
−
0
View file @
3e088e59
...
@@ -44,6 +44,15 @@ def scalarField(field, **kwargs):
...
@@ -44,6 +44,15 @@ def scalarField(field, **kwargs):
return
res
return
res
def
multipleScalarFields
(
field
,
**
kwargs
):
subPlots
=
field
.
shape
[
-
1
]
for
i
in
range
(
subPlots
):
subplot
(
1
,
subPlots
,
i
+
1
)
title
(
str
(
i
))
scalarField
(
field
[...,
i
])
colorbar
()
def
plotBoundaryHandling
(
boundaryHandling
,
boundaryNameToColor
=
None
):
def
plotBoundaryHandling
(
boundaryHandling
,
boundaryNameToColor
=
None
):
"""
"""
Shows boundary cells
Shows boundary cells
...
...
This diff is collapsed.
Click to expand it.
updatekernels.py
+
46
−
4
View file @
3e088e59
import
numpy
as
np
import
numpy
as
np
import
sympy
as
sp
import
sympy
as
sp
from
pystencils
import
Field
from
pystencils
import
Field
from
pystencils.equationcollection.equationcollection
import
EquationCollection
from
pystencils.field
import
createNumpyArrayWithLayout
,
layoutStringToTuple
from
pystencils.field
import
createNumpyArrayWithLayout
,
layoutStringToTuple
from
pystencils.sympyextensions
import
fastSubs
from
pystencils.sympyextensions
import
fastSubs
from
lbmpy.fieldaccess
import
StreamPullTwoFieldsAccessor
,
Pseudo2DTwoFieldsAccessor
,
PeriodicTwoFieldsAccessor
from
lbmpy.fieldaccess
import
StreamPullTwoFieldsAccessor
,
Pseudo2DTwoFieldsAccessor
,
PeriodicTwoFieldsAccessor
,
\
CollideOnlyInplaceAccessor
# -------------------------------------------- LBM Kernel Creation -----------------------------------------------------
# -------------------------------------------- LBM Kernel Creation -----------------------------------------------------
...
@@ -43,9 +45,9 @@ def createLBMKernel(collisionRule, inputField, outputField, accessor):
...
@@ -43,9 +45,9 @@ def createLBMKernel(collisionRule, inputField, outputField, accessor):
return
result
return
result
def
createStreamPullKernel
(
collisionRule
,
numpyField
=
None
,
srcFieldName
=
"
src
"
,
dstFieldName
=
"
dst
"
,
def
createStreamPull
Collide
Kernel
(
collisionRule
,
numpyField
=
None
,
srcFieldName
=
"
src
"
,
dstFieldName
=
"
dst
"
,
genericLayout
=
'
numpy
'
,
genericFieldType
=
np
.
float64
,
genericLayout
=
'
numpy
'
,
genericFieldType
=
np
.
float64
,
builtinPeriodicity
=
(
False
,
False
,
False
)):
builtinPeriodicity
=
(
False
,
False
,
False
)):
"""
"""
Implements a stream-pull scheme, where values are read from source and written to destination field
Implements a stream-pull scheme, where values are read from source and written to destination field
:param collisionRule: a collision rule created by lbm method
:param collisionRule: a collision rule created by lbm method
...
@@ -78,6 +80,46 @@ def createStreamPullKernel(collisionRule, numpyField=None, srcFieldName="src", d
...
@@ -78,6 +80,46 @@ def createStreamPullKernel(collisionRule, numpyField=None, srcFieldName="src", d
return
createLBMKernel
(
collisionRule
,
src
,
dst
,
accessor
)
return
createLBMKernel
(
collisionRule
,
src
,
dst
,
accessor
)
def
createCollideOnlyKernel
(
collisionRule
,
numpyField
=
None
,
fieldName
=
"
src
"
,
genericLayout
=
'
numpy
'
,
genericFieldType
=
np
.
float64
):
"""
Implements a collision only (no neighbor access) LBM kernel.
For parameters see function ``createStreamPullCollideKernel``
"""
dim
=
collisionRule
.
method
.
dim
if
numpyField
is
not
None
:
assert
len
(
numpyField
.
shape
)
==
dim
+
1
,
"
Field dimension mismatch: dimension is %s, should be %d
"
%
\
(
len
(
numpyField
.
shape
),
dim
+
1
)
if
numpyField
is
None
:
field
=
Field
.
createGeneric
(
fieldName
,
dim
,
indexDimensions
=
1
,
layout
=
genericLayout
,
dtype
=
genericFieldType
)
else
:
field
=
Field
.
createFromNumpyArray
(
fieldName
,
numpyField
,
indexDimensions
=
1
)
return
createLBMKernel
(
collisionRule
,
field
,
field
,
CollideOnlyInplaceAccessor
)
def
createStreamPullOnlyKernel
(
stencil
,
numpyField
=
None
,
srcFieldName
=
"
src
"
,
dstFieldName
=
"
dst
"
,
genericLayout
=
'
numpy
'
,
genericFieldType
=
np
.
float64
):
"""
Creates a stream-pull kernel, without collision
For parameters see function ``createStreamPullCollideKernel``
"""
dim
=
len
(
stencil
[
0
])
if
numpyField
is
None
:
src
=
Field
.
createGeneric
(
srcFieldName
,
dim
,
indexDimensions
=
1
,
layout
=
genericLayout
,
dtype
=
genericFieldType
)
dst
=
Field
.
createGeneric
(
dstFieldName
,
dim
,
indexDimensions
=
1
,
layout
=
genericLayout
,
dtype
=
genericFieldType
)
else
:
src
=
Field
.
createFromNumpyArray
(
srcFieldName
,
numpyField
,
indexDimensions
=
1
)
dst
=
Field
.
createFromNumpyArray
(
dstFieldName
,
numpyField
,
indexDimensions
=
1
)
accessor
=
StreamPullTwoFieldsAccessor
()
eqs
=
[
sp
.
Eq
(
a
,
b
)
for
a
,
b
in
zip
(
accessor
.
write
(
dst
,
stencil
),
accessor
.
read
(
src
,
stencil
))
if
sp
.
Eq
(
a
,
b
)
!=
True
]
return
EquationCollection
(
eqs
,
[])
# ---------------------------------- Pdf array creation for various layouts --------------------------------------------
# ---------------------------------- Pdf array creation for various layouts --------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment