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
2a743935
Commit
2a743935
authored
8 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
More Cumulant relaxation schemes
parent
7d7605ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cumulantlatticemodel.py
+63
-11
63 additions, 11 deletions
cumulantlatticemodel.py
plot2d.py
+22
-2
22 additions, 2 deletions
plot2d.py
with
85 additions
and
13 deletions
cumulantlatticemodel.py
+
63
−
11
View file @
2a743935
...
...
@@ -9,7 +9,52 @@ from lbmpy.equilibria import getWeights
from
lbmpy.densityVelocityExpressions
import
getDensityVelocityExpressions
class
SimpleBoltzmannRelaxation
:
def
isHydrodynamic
(
idx
):
return
sum
(
idx
)
==
2
def
relaxationRateFromMagicNumber
(
hydrodynamicOmega
,
magicNumber
):
half
=
sp
.
Rational
(
1
,
2
)
return
1
/
(
magicNumber
/
(
1
/
hydrodynamicOmega
-
half
)
+
half
)
def
relaxationRateFromFactor
(
hydrodynamicOmega
,
factor
):
half
=
sp
.
Rational
(
1
,
2
)
return
1
/
((
1
/
hydrodynamicOmega
-
half
)
/
factor
+
half
)
class
TRTStyleRelaxation
:
def
__init__
(
self
,
omega
,
factorEven
=
1.0
,
factorOdd
=
sp
.
Rational
(
3
,
16
)):
self
.
_omega
=
omega
self
.
_factorEven
=
factorEven
self
.
_factorOdd
=
factorOdd
self
.
addPostCollisionsAsSubexpressions
=
False
def
__call__
(
self
,
preCollisionSymbols
,
indices
):
pre
=
{
a
:
b
for
a
,
b
in
zip
(
indices
,
preCollisionSymbols
)}
post
=
{}
dim
=
len
(
indices
[
0
])
omegaEven
=
relaxationRateFromFactor
(
self
.
_omega
,
self
.
_factorEven
)
omegaOdd
=
relaxationRateFromMagicNumber
(
self
.
_omega
,
self
.
_factorOdd
)
print
(
omegaEven
,
omegaOdd
)
maxwellBoltzmann
=
maxwellBoltzmannEquilibrium
(
dim
,
c_s_sq
=
sp
.
Rational
(
1
,
3
))
for
idx
,
value
in
pre
.
items
():
isEven
=
sum
(
idx
)
%
2
==
0
if
isHydrodynamic
(
idx
):
relaxRate
=
self
.
_omega
elif
isEven
:
relaxRate
=
omegaEven
else
:
relaxRate
=
omegaOdd
post
[
idx
]
=
pre
[
idx
]
+
relaxRate
*
(
continuousCumulant
(
maxwellBoltzmann
,
idx
)
-
pre
[
idx
])
return
[
post
[
idx
]
for
idx
in
indices
]
class
AllSameRelaxation
:
def
__init__
(
self
,
omega
):
self
.
_omega
=
omega
self
.
addPostCollisionsAsSubexpressions
=
False
...
...
@@ -19,21 +64,28 @@ class SimpleBoltzmannRelaxation:
post
=
{}
dim
=
len
(
indices
[
0
])
# conserved quantities
maxwellBoltzmann
=
maxwellBoltzmannEquilibrium
(
dim
,
c_s_sq
=
sp
.
Rational
(
1
,
3
))
for
idx
,
value
in
pre
.
items
():
if
sum
(
idx
)
==
0
or
sum
(
idx
)
==
1
:
post
[
idx
]
=
pre
[
idx
]
post
[
idx
]
=
pre
[
idx
]
+
self
.
_omega
*
(
continuousCumulant
(
maxwellBoltzmann
,
idx
)
-
pre
[
idx
])
return
[
post
[
idx
]
for
idx
in
indices
]
# hydrodynamic relaxation
for
idx
in
indices
:
idxCounter
=
Counter
(
idx
)
if
len
(
idxCounter
.
keys
()
-
set
([
0
,
1
]))
==
0
and
idxCounter
[
1
]
==
2
:
post
[
idx
]
=
(
1
-
self
.
_omega
)
*
pre
[
idx
]
# set remaining values to their equilibrium value (i.e. relaxationRate=1)
class
SimpleBoltzmannRelaxation
:
def
__init__
(
self
,
omega
):
self
.
_omega
=
omega
self
.
addPostCollisionsAsSubexpressions
=
False
def
__call__
(
self
,
preCollisionSymbols
,
indices
):
pre
=
{
a
:
b
for
a
,
b
in
zip
(
indices
,
preCollisionSymbols
)}
post
=
{}
dim
=
len
(
indices
[
0
])
maxwellBoltzmann
=
maxwellBoltzmannEquilibrium
(
dim
,
c_s_sq
=
sp
.
Rational
(
1
,
3
))
for
idx
,
value
in
pre
.
items
():
if
idx
not
in
post
:
if
isHydrodynamic
(
idx
):
post
[
idx
]
=
(
1
-
self
.
_omega
)
*
pre
[
idx
]
else
:
post
[
idx
]
=
continuousCumulant
(
maxwellBoltzmann
,
idx
)
return
[
post
[
idx
]
for
idx
in
indices
]
...
...
This diff is collapsed.
Click to expand it.
plot2d.py
+
22
−
2
View file @
2a743935
...
...
@@ -15,11 +15,31 @@ def vectorField(field, step=2, **kwargs):
def
vectorFieldMagnitude
(
field
,
**
kwargs
):
field
=
norm
(
field
,
axis
=
2
,
ord
=
2
)
scalarField
(
field
,
**
kwargs
)
return
scalarField
(
field
,
**
kwargs
)
def
scalarField
(
field
,
**
kwargs
):
field
=
removeGhostLayers
(
field
)
field
=
np
.
swapaxes
(
field
,
0
,
1
)
imshow
(
field
,
origin
=
'
lower
'
,
**
kwargs
)
return
imshow
(
field
,
origin
=
'
lower
'
,
**
kwargs
)
def
vectorFieldMagnitudeAnimation
(
runFunction
,
plotSetupFunction
=
lambda
:
None
,
plotUpdateFunction
=
lambda
:
None
,
interval
=
30
,
frames
=
180
,
**
kwargs
):
import
matplotlib.animation
as
animation
fig
=
gcf
()
im
=
None
field
=
runFunction
()
im
=
vectorFieldMagnitude
(
field
,
**
kwargs
)
plotSetupFunction
()
def
updatefig
(
*
args
):
field
=
runFunction
()
field
=
norm
(
field
,
axis
=
2
,
ord
=
2
)
field
=
np
.
swapaxes
(
field
,
0
,
1
)
im
.
set_array
(
field
)
plotUpdateFunction
()
return
im
,
return
animation
.
FuncAnimation
(
fig
,
updatefig
,
interval
=
interval
,
frames
=
frames
)
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