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
9a440cab
Commit
9a440cab
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Plain Diff
Merge branch 'fluctuating' into 'master'
Fluctuating MRT: use the correct prefactors See merge request
!11
parents
4203fa7f
a77e80fa
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Fluctuating MRT: use the correct prefactors
Pipeline
#19562
canceled
5 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lbmpy/fluctuatinglb.py
+13
-12
13 additions, 12 deletions
lbmpy/fluctuatinglb.py
with
13 additions
and
12 deletions
lbmpy/fluctuatinglb.py
+
13
−
12
View file @
9a440cab
...
...
@@ -12,31 +12,32 @@ from pystencils.rng import PhiloxFourFloats, random_symbol
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
),
rng_node
=
PhiloxFourFloats
,
c_s_sq
=
sp
.
Rational
(
1
,
3
)):
""""""
if
not
(
temperature
and
not
varianc
es
)
or
(
temperature
and
varianc
es
):
raise
ValueError
(
"
Fluctuating LBM: Pass either
'
temperature
'
or
'
varianc
es
'
.
"
)
if
not
(
temperature
and
not
amplitud
es
)
or
(
temperature
and
amplitud
es
):
raise
ValueError
(
"
Fluctuating LBM: Pass either
'
temperature
'
or
'
amplitud
es
'
.
"
)
method
=
collision_rule
.
method
if
not
varianc
es
:
varianc
es
=
fluctuati
ng_varianc
e_from_temperature
(
method
,
temperature
,
c_s_sq
)
if
not
amplitud
es
:
amplitud
es
=
fluctuati
on_amplitud
e_from_temperature
(
method
,
temperature
,
c_s_sq
)
if
block_offsets
==
'
walberla
'
:
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_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
):
collision_rule
.
main_assignments
[
i
]
=
Assignment
(
collision_rule
.
main_assignments
[
i
].
lhs
,
collision_rule
.
main_assignments
[
i
].
rhs
+
corr
)
def
fluctuating_variance_from_temperature
(
method
,
temperature
,
c_s_sq
=
sp
.
Symbol
(
"
c_s
"
)
**
2
):
"""
Produces variance equations according to (3.54) in Schiller08
"""
normalization_factors
=
abs
(
method
.
moment_matrix
)
*
sp
.
Matrix
(
method
.
weights
)
def
fluctuation_amplitude_from_temperature
(
method
,
temperature
,
c_s_sq
=
sp
.
Symbol
(
"
c_s
"
)
**
2
):
"""
Produces amplitude equations according to (2.60) and (3.54) in Schiller08
"""
normalization_factors
=
sp
.
matrix_multiply_elementwise
(
method
.
moment_matrix
,
method
.
moment_matrix
)
*
\
sp
.
Matrix
(
method
.
weights
)
density
=
method
.
zeroth_order_equilibrium_moment_symbol
if
method
.
conserved_quantity_computation
.
zero_centered_pdfs
:
density
+=
1
...
...
@@ -45,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
)]
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
"""
conserved_moments
=
{
sp
.
sympify
(
1
),
*
MOMENT_SYMBOLS
}
# 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
)
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
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