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
a77e80fa
Commit
a77e80fa
authored
5 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
Fluctuating MRT: variance is actually standard deviation (or amplitude)
parent
d4ee5d55
No related branches found
No related tags found
1 merge request
!11
Fluctuating MRT: use the correct prefactors
Pipeline
#19555
failed
5 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lbmpy/fluctuatinglb.py
+11
-11
11 additions, 11 deletions
lbmpy/fluctuatinglb.py
with
11 additions
and
11 deletions
lbmpy/fluctuatinglb.py
+
11
−
11
View file @
a77e80fa
...
@@ -12,30 +12,30 @@ from pystencils.rng import PhiloxFourFloats, random_symbol
...
@@ -12,30 +12,30 @@ from pystencils.rng import PhiloxFourFloats, random_symbol
from
pystencils.simp.assignment_collection
import
SymbolGen
from
pystencils.simp.assignment_collection
import
SymbolGen
def
add_fluctuations_to_collision_rule
(
collision_rule
,
temperature
=
None
,
varianc
es
=
(),
def
add_fluctuations_to_collision_rule
(
collision_rule
,
temperature
=
None
,
amplitud
es
=
(),
block_offsets
=
(
0
,
0
,
0
),
seed
=
TypedSymbol
(
"
seed
"
,
np
.
uint32
),
block_offsets
=
(
0
,
0
,
0
),
seed
=
TypedSymbol
(
"
seed
"
,
np
.
uint32
),
rng_node
=
PhiloxFourFloats
,
c_s_sq
=
sp
.
Rational
(
1
,
3
)):
rng_node
=
PhiloxFourFloats
,
c_s_sq
=
sp
.
Rational
(
1
,
3
)):
""""""
""""""
if
not
(
temperature
and
not
varianc
es
)
or
(
temperature
and
varianc
es
):
if
not
(
temperature
and
not
amplitud
es
)
or
(
temperature
and
amplitud
es
):
raise
ValueError
(
"
Fluctuating LBM: Pass either
'
temperature
'
or
'
varianc
es
'
.
"
)
raise
ValueError
(
"
Fluctuating LBM: Pass either
'
temperature
'
or
'
amplitud
es
'
.
"
)
method
=
collision_rule
.
method
method
=
collision_rule
.
method
if
not
varianc
es
:
if
not
amplitud
es
:
varianc
es
=
fluctuati
ng_varianc
e_from_temperature
(
method
,
temperature
,
c_s_sq
)
amplitud
es
=
fluctuati
on_amplitud
e_from_temperature
(
method
,
temperature
,
c_s_sq
)
if
block_offsets
==
'
walberla
'
:
if
block_offsets
==
'
walberla
'
:
block_offsets
=
tuple
(
TypedSymbol
(
"
block_offset_{}
"
.
format
(
i
),
np
.
uint32
)
for
i
in
range
(
3
))
block_offsets
=
tuple
(
TypedSymbol
(
"
block_offset_{}
"
.
format
(
i
),
np
.
uint32
)
for
i
in
range
(
3
))
rng_symbol_gen
=
random_symbol
(
collision_rule
.
subexpressions
,
seed
,
rng_symbol_gen
=
random_symbol
(
collision_rule
.
subexpressions
,
seed
,
rng_node
=
rng_node
,
dim
=
method
.
dim
,
offsets
=
block_offsets
)
rng_node
=
rng_node
,
dim
=
method
.
dim
,
offsets
=
block_offsets
)
correction
=
fluctuation_correction
(
method
,
rng_symbol_gen
,
varianc
es
)
correction
=
fluctuation_correction
(
method
,
rng_symbol_gen
,
amplitud
es
)
for
i
,
corr
in
enumerate
(
correction
):
for
i
,
corr
in
enumerate
(
correction
):
collision_rule
.
main_assignments
[
i
]
=
Assignment
(
collision_rule
.
main_assignments
[
i
].
lhs
,
collision_rule
.
main_assignments
[
i
]
=
Assignment
(
collision_rule
.
main_assignments
[
i
].
lhs
,
collision_rule
.
main_assignments
[
i
].
rhs
+
corr
)
collision_rule
.
main_assignments
[
i
].
rhs
+
corr
)
def
fluctuati
ng_varianc
e_from_temperature
(
method
,
temperature
,
c_s_sq
=
sp
.
Symbol
(
"
c_s
"
)
**
2
):
def
fluctuati
on_amplitud
e_from_temperature
(
method
,
temperature
,
c_s_sq
=
sp
.
Symbol
(
"
c_s
"
)
**
2
):
"""
Produces
varianc
e equations according to (2.60) and (3.54) in Schiller08
"""
"""
Produces
amplitud
e equations according to (2.60) and (3.54) in Schiller08
"""
normalization_factors
=
sp
.
matrix_multiply_elementwise
(
method
.
moment_matrix
,
method
.
moment_matrix
)
*
\
normalization_factors
=
sp
.
matrix_multiply_elementwise
(
method
.
moment_matrix
,
method
.
moment_matrix
)
*
\
sp
.
Matrix
(
method
.
weights
)
sp
.
Matrix
(
method
.
weights
)
density
=
method
.
zeroth_order_equilibrium_moment_symbol
density
=
method
.
zeroth_order_equilibrium_moment_symbol
...
@@ -46,14 +46,14 @@ def fluctuating_variance_from_temperature(method, temperature, c_s_sq=sp.Symbol(
...
@@ -46,14 +46,14 @@ def fluctuating_variance_from_temperature(method, temperature, c_s_sq=sp.Symbol(
for
norm
,
rr
in
zip
(
normalization_factors
,
method
.
relaxation_rates
)]
for
norm
,
rr
in
zip
(
normalization_factors
,
method
.
relaxation_rates
)]
def
fluctuation_correction
(
method
,
rng_generator
,
varianc
es
=
SymbolGen
(
"
variance
"
)):
def
fluctuation_correction
(
method
,
rng_generator
,
amplitud
es
=
SymbolGen
(
"
phi
"
)):
"""
Returns additive correction terms to be added to the the collided pdfs
"""
"""
Returns additive correction terms to be added to the the collided pdfs
"""
conserved_moments
=
{
sp
.
sympify
(
1
),
*
MOMENT_SYMBOLS
}
conserved_moments
=
{
sp
.
sympify
(
1
),
*
MOMENT_SYMBOLS
}
# A diagonal matrix containing the random fluctuations
# A diagonal matrix containing the random fluctuations
random_matrix
=
sp
.
Matrix
([
0
if
m
in
conserved_moments
else
(
next
(
rng_generator
)
-
0.5
)
*
sp
.
sqrt
(
12
)
random_matrix
=
sp
.
Matrix
([
0
if
m
in
conserved_moments
else
(
next
(
rng_generator
)
-
0.5
)
*
sp
.
sqrt
(
12
)
for
m
in
method
.
moments
])
for
m
in
method
.
moments
])
random_variance
=
sp
.
diag
(
*
[
v
for
v
,
_
in
zip
(
iter
(
varianc
es
),
method
.
moments
)])
amplitude_matrix
=
sp
.
diag
(
*
[
v
for
v
,
_
in
zip
(
iter
(
amplitud
es
),
method
.
moments
)])
# corrections are applied in real space hence we need to convert to real space here
# corrections are applied in real space hence we need to convert to real space here
return
method
.
moment_matrix
.
inv
()
*
random_variance
*
random_matrix
return
method
.
moment_matrix
.
inv
()
*
amplitude_matrix
*
random_matrix
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