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
d98d0074
Commit
d98d0074
authored
8 years ago
by
Martin Bauer
Committed by
Martin Bauer
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
lbmpy: improved boundary setup + testcase for pressure driven channel
parent
b70791cf
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
boundaries/boundaryhandling.py
+8
-6
8 additions, 6 deletions
boundaries/boundaryhandling.py
boundaries/geometry.py
+23
-0
23 additions, 0 deletions
boundaries/geometry.py
serialscenario.py
+9
-2
9 additions, 2 deletions
serialscenario.py
with
40 additions
and
8 deletions
boundaries/boundaryhandling.py
+
8
−
6
View file @
d98d0074
...
...
@@ -30,6 +30,9 @@ class BoundaryHandling(object):
if
name
is
None
:
name
=
boundaryFunction
.
__name__
if
name
in
self
.
_nameToIndex
:
return
2
**
self
.
_nameToIndex
[
name
]
newIdx
=
len
(
self
.
_boundaryFunctions
)
self
.
_nameToIndex
[
name
]
=
newIdx
self
.
_boundaryFunctions
.
append
(
boundaryFunction
)
...
...
@@ -45,7 +48,7 @@ class BoundaryHandling(object):
def
getFlag
(
self
,
name
):
return
2
**
self
.
_nameToIndex
[
name
]
def
setBoundary
(
self
,
function
,
indexExpr
,
clearOtherBoundaries
=
Tru
e
):
def
setBoundary
(
self
,
function
,
indexExpr
,
maskArr
=
Non
e
):
if
hasattr
(
function
,
'
__name__
'
):
name
=
function
.
__name__
elif
hasattr
(
function
,
'
name
'
):
...
...
@@ -57,13 +60,12 @@ class BoundaryHandling(object):
self
.
addBoundary
(
function
,
name
)
flag
=
self
.
getFlag
(
name
)
if
clearOtherBoundaries
:
if
maskArr
is
None
:
self
.
flagField
[
indexExpr
]
=
flag
else
:
# clear fluid flag
np
.
bitwise_and
(
self
.
flagField
[
indexExpr
],
np
.
invert
(
self
.
_fluidFlag
),
self
.
flagField
[
indexExpr
])
# add new boundary flag
np
.
bitwise_or
(
self
.
flagField
[
indexExpr
],
flag
,
self
.
flagField
[
indexExpr
])
flagFieldView
=
self
.
flagField
[
indexExpr
]
flagFieldView
[
maskArr
]
=
flag
self
.
invalidateIndexCache
()
...
...
This diff is collapsed.
Click to expand it.
boundaries/geometry.py
0 → 100644
+
23
−
0
View file @
d98d0074
import
numpy
as
np
import
scipy.misc
from
pystencils.slicing
import
makeSlice
,
normalizeSlice
,
shiftSlice
class
BlackAndWhiteImageBoundary
:
def
__init__
(
self
,
imagePath
,
boundaryFunction
,
targetSlice
=
makeSlice
[:,
:,
:]):
self
.
imgArr
=
scipy
.
misc
.
imread
(
imagePath
,
flatten
=
True
).
astype
(
int
)
self
.
imgArr
=
np
.
rot90
(
self
.
imgArr
,
3
)
self
.
_boundaryFunction
=
boundaryFunction
self
.
_targetSlice
=
targetSlice
def
__call__
(
self
,
boundaryHandling
,
method
,
domainSize
,
**
kwargs
):
normalizedSlice
=
normalizeSlice
(
self
.
_targetSlice
,
domainSize
)
normalizedSlice
=
shiftSlice
(
normalizedSlice
,
1
)
targetSize
=
[
s
.
stop
-
s
.
start
for
s
in
normalizedSlice
]
img
=
scipy
.
misc
.
imresize
(
self
.
imgArr
,
size
=
targetSize
)
img
[
img
<=
254
]
=
0
img
[
img
>
254
]
=
1
boundaryHandling
.
setBoundary
(
self
.
_boundaryFunction
,
normalizedSlice
,
maskArr
=
(
img
==
0
))
This diff is collapsed.
Click to expand it.
serialscenario.py
+
9
−
2
View file @
d98d0074
...
...
@@ -69,6 +69,9 @@ def createScenario(domainSize, boundarySetupFunction, methodParameters, optimiza
pdfArrays
[
0
],
pdfArrays
[
1
]
=
pdfArrays
[
1
],
pdfArrays
[
0
]
getMacroscopic
(
pdfs
=
pdfArrays
[
0
],
density
=
densityArr
[
0
],
velocity
=
velocityArr
[
0
])
#for vComp in range(velocityArr[0].shape[-1]):
# v = velocityArr[0][..., vComp]
# v[boundaryHandling.flagField != boundaryHandling._fluidFlag] = 0
return
pdfArrays
[
0
],
densityArr
[
0
],
velocityArr
[
0
]
def
gpuTimeLoop
(
timeSteps
):
...
...
@@ -112,7 +115,8 @@ def createLidDrivenCavity(domainSize, lidVelocity=0.005, optimizationParams={},
def
createPressureGradientDrivenChannel
(
dim
,
pressureDifference
,
domainSize
=
None
,
radius
=
None
,
length
=
None
,
lbmKernel
=
None
,
optimizationParams
=
{},
kernelParams
=
{},
**
kwargs
):
lbmKernel
=
None
,
optimizationParams
=
{},
boundarySetupFunctions
=
[],
kernelParams
=
{},
**
kwargs
):
assert
dim
in
(
2
,
3
)
if
radius
is
not
None
:
...
...
@@ -150,6 +154,9 @@ def createPressureGradientDrivenChannel(dim, pressureDifference, domainSize=None
for
direction
in
(
'
N
'
,
'
S
'
,
'
T
'
,
'
B
'
):
boundaryHandling
.
setBoundary
(
noSlip
,
sliceFromDirection
(
direction
,
method
.
dim
))
for
userFunction
in
boundarySetupFunctions
:
userFunction
(
boundaryHandling
,
method
,
domainSize
)
assert
domainSize
is
not
None
return
createScenario
(
domainSize
,
boundarySetupFunction
,
kwargs
,
optimizationParams
,
lbmKernel
=
lbmKernel
,
kernelParams
=
kernelParams
)
...
...
@@ -188,7 +195,7 @@ def createForceDrivenChannel(dim, force, domainSize=None, radius=None, length=No
for
direction
in
(
'
N
'
,
'
S
'
,
'
T
'
,
'
B
'
):
boundaryHandling
.
setBoundary
(
noSlip
,
sliceFromDirection
(
direction
,
method
.
dim
))
for
userFunction
in
boundarySetupFunctions
:
userFunction
(
boundaryHandling
,
method
)
userFunction
(
boundaryHandling
,
method
,
domainSize
)
def
periodicity
(
pdfArr
):
pdfArr
[
0
,
:,
:]
=
pdfArr
[
-
2
,
:,
:]
...
...
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