Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pycodegen
lbmpy
Commits
1913fa42
Commit
1913fa42
authored
Jan 23, 2017
by
Martin Bauer
Browse files
boundary generatlization
parent
fde2c8ce
Changes
5
Hide whitespace changes
Inline
Side-by-side
boundaries/boundaryconditions.py
View file @
1913fa42
...
...
@@ -9,6 +9,8 @@ def noSlip(pdfField, direction, lbmMethod):
def
ubb
(
pdfField
,
direction
,
lbmMethod
,
velocity
):
assert
len
(
velocity
)
==
lbmMethod
.
dim
,
\
"Dimension of velocity (%d) does not match dimension of LB method (%d)"
%
(
len
(
velocity
,
lbmMethod
.
dim
))
neighbor
=
offsetFromDir
(
direction
,
lbmMethod
.
dim
)
inverseDir
=
invDir
(
direction
)
...
...
boundaries/boundaryhandling.py
View file @
1913fa42
...
...
@@ -6,7 +6,7 @@ from pystencils.ast import Block, SympyAssignment, LoopOverCoordinate, KernelFun
from
pystencils.transformations
import
moveConstantsBeforeLoop
,
resolveFieldAccesses
,
typingFromSympyInspection
,
\
typeAllEquations
from
pystencils.cpu
import
makePythonFunction
from
lbmpy.boundaries.createindexlist
import
createBoundaryIndexList
INV_DIR_SYMBOL
=
TypedSymbol
(
"invDir"
,
"int"
)
WEIGHTS_SYMBOL
=
TypedSymbol
(
"weights"
,
"double"
)
...
...
@@ -41,16 +41,16 @@ class BoundaryHandling:
def
getFlag
(
self
,
name
):
return
2
**
self
.
_nameToIndex
[
name
]
def
setBoundary
(
self
,
name
,
indexExpr
,
clearOtherBoundaries
=
True
):
if
not
isinstance
(
name
,
str
):
function
=
name
if
hasattr
(
function
,
'
__
name
__
'
):
name
=
function
.
__
name
__
else
:
name
=
function
.
name
def
setBoundary
(
self
,
function
,
indexExpr
,
clearOtherBoundaries
=
True
):
if
hasattr
(
function
,
'__name__'
):
name
=
function
.
__
name
__
el
if
hasattr
(
function
,
'name'
):
name
=
function
.
name
else
:
raise
ValueError
(
"Boundary function has to have a '__name__' or 'name' attribute"
)
if
function
not
in
self
.
_boundaryFunctions
:
self
.
addBoundary
(
function
,
name
)
if
function
not
in
self
.
_boundaryFunctions
:
self
.
addBoundary
(
function
,
name
)
flag
=
self
.
getFlag
(
name
)
if
clearOtherBoundaries
:
...
...
@@ -66,8 +66,8 @@ class BoundaryHandling:
def
prepare
(
self
):
self
.
invalidateIndexCache
()
for
boundaryIdx
,
boundaryFunc
in
enumerate
(
self
.
_boundaryFunctions
):
idxField
=
createBoundaryIndexList
(
self
.
flagField
,
self
.
_ghostLayers
,
self
.
_latticeModel
.
stencil
,
2
**
boundaryIdx
,
self
.
_fluidFlag
)
idxField
=
createBoundaryIndexList
(
self
.
flagField
,
self
.
_latticeModel
.
stencil
,
2
**
boundaryIdx
,
self
.
_fluidFlag
,
self
.
_ghostLayers
)
ast
=
generateBoundaryHandling
(
self
.
_symbolicPdfField
,
idxField
,
self
.
_latticeModel
,
boundaryFunc
)
self
.
_boundarySweeps
.
append
(
makePythonFunction
(
ast
,
{
'indexField'
:
idxField
}))
...
...
@@ -99,14 +99,14 @@ def weightOfDirection(dirIdx):
# ------------------------------------- Kernel Generation --------------------------------------------------------------
class
L
atticeModel
Info
(
CustomCppCode
):
def
__init__
(
self
,
l
atticeModel
):
stencil
=
l
atticeModel
.
stencil
symbolsDefined
=
set
(
offsetSymbols
(
l
atticeModel
.
dim
)
+
[
INV_DIR_SYMBOL
,
WEIGHTS_SYMBOL
])
class
L
bmMethod
Info
(
CustomCppCode
):
def
__init__
(
self
,
l
bMethod
):
stencil
=
l
bMethod
.
stencil
symbolsDefined
=
set
(
offsetSymbols
(
l
bMethod
.
dim
)
+
[
INV_DIR_SYMBOL
,
WEIGHTS_SYMBOL
])
offsetSym
=
offsetSymbols
(
l
atticeModel
.
dim
)
offsetSym
=
offsetSymbols
(
l
bMethod
.
dim
)
code
=
"
\n
"
for
i
in
range
(
l
atticeModel
.
dim
):
for
i
in
range
(
l
bMethod
.
dim
):
offsetStr
=
", "
.
join
([
str
(
d
[
i
])
for
d
in
stencil
])
code
+=
"const int %s [] = { %s };
\n
"
%
(
offsetSym
[
i
].
name
,
offsetStr
)
...
...
@@ -116,9 +116,9 @@ class LatticeModelInfo(CustomCppCode):
invDirs
.
append
(
str
(
stencil
.
index
(
inverseDir
)))
code
+=
"static const int %s [] = { %s };
\n
"
%
(
INV_DIR_SYMBOL
.
name
,
", "
.
join
(
invDirs
))
weights
=
[
str
(
w
.
evalf
())
for
w
in
l
atticeModel
.
weights
]
weights
=
[
str
(
w
.
evalf
())
for
w
in
l
bMethod
.
weights
]
code
+=
"static const double %s [] = { %s };
\n
"
%
(
WEIGHTS_SYMBOL
.
name
,
","
.
join
(
weights
))
super
(
L
atticeModel
Info
,
self
).
__init__
(
code
,
symbolsRead
=
set
(),
symbolsDefined
=
symbolsDefined
)
super
(
L
bmMethod
Info
,
self
).
__init__
(
code
,
symbolsRead
=
set
(),
symbolsDefined
=
symbolsDefined
)
def
generateBoundaryHandling
(
pdfField
,
indexArr
,
latticeModel
,
boundaryFunctor
):
...
...
@@ -158,7 +158,7 @@ def generateBoundaryHandling(pdfField, indexArr, latticeModel, boundaryFunctor):
for
node
in
additionalNodes
:
loop
.
body
.
append
(
node
)
functionBody
.
insertFront
(
L
atticeModel
Info
(
latticeModel
))
functionBody
.
insertFront
(
L
bmMethod
Info
(
latticeModel
))
fixedCoordinateMapping
=
{
f
.
name
:
coordinateSymbols
[:
dim
]
for
f
in
fieldsAccessed
}
resolveFieldAccesses
(
ast
,
set
([
'indexField'
]),
fieldToFixedCoordinates
=
fixedCoordinateMapping
)
...
...
boundaries/createindexlist.py
View file @
1913fa42
import
numpy
as
np
import
itertools
#try:
if
True
:
try
:
import
pyximport
;
pyximport
.
install
()
from
lbmpy.boundaries.createindexlistcython
import
createBoundaryIndexList2D
,
createBoundaryIndexList3D
cythonFuncsAvailable
=
True
#
except Exception:
#
cythonFuncsAvailable = False
#
createBoundaryIndexList2D = None
#
createBoundaryIndexList3D = None
except
Exception
:
cythonFuncsAvailable
=
False
createBoundaryIndexList2D
=
None
createBoundaryIndexList3D
=
None
def
_createBoundaryIndexListPython
(
flagFieldArr
,
nrOfGhostLayers
,
boundaryMask
,
fluidMask
,
stencil
):
...
...
methods/momentbased.py
View file @
1913fa42
...
...
@@ -144,12 +144,14 @@ class MomentBasedLbmMethod(AbstractLbmMethod):
"Can not determine their relaxation rate automatically"
)
def
getEquilibrium
(
self
):
sp
.
factor
D
=
sp
.
eye
(
len
(
self
.
_relaxationRates
))
return
self
.
_getCollisionRuleWithRelaxationMatrix
(
D
)
def
getCollisionRule
(
self
):
D
=
sp
.
diag
(
*
self
.
_relaxationRates
)
eqColl
=
self
.
_getCollisionRuleWithRelaxationMatrix
(
D
)
relaxationRateSubExpressions
,
D
=
self
.
_generateRelaxationMatrix
(
D
)
eqColl
=
self
.
_getCollisionRuleWithRelaxationMatrix
(
D
,
relaxationRateSubExpressions
)
if
self
.
_forceModel
is
not
None
:
forceModelTerms
=
self
.
_forceModel
(
self
)
newEqs
=
[
sp
.
Eq
(
eq
.
lhs
,
eq
.
rhs
+
fmt
)
for
eq
,
fmt
in
zip
(
eqColl
.
mainEquations
,
forceModelTerms
)]
...
...
@@ -160,13 +162,11 @@ class MomentBasedLbmMethod(AbstractLbmMethod):
def
conservedQuantityComputation
(
self
):
return
self
.
_conservedQuantityComputation
def
_getCollisionRuleWithRelaxationMatrix
(
self
,
D
):
def
_getCollisionRuleWithRelaxationMatrix
(
self
,
D
,
additionalSubexpressions
=
[]
):
f
=
sp
.
Matrix
(
self
.
preCollisionPdfSymbols
)
M
=
self
.
_momentMatrix
m_eq
=
self
.
_equilibriumMoments
relaxationRateSubExpressions
,
D
=
self
.
_generateRelaxationMatrix
(
D
)
collisionRule
=
f
+
M
.
inv
()
*
D
*
(
m_eq
-
M
*
f
)
collisionEqs
=
[
sp
.
Eq
(
lhs
,
rhs
)
for
lhs
,
rhs
in
zip
(
self
.
postCollisionPdfSymbols
,
collisionRule
)]
...
...
@@ -175,7 +175,7 @@ class MomentBasedLbmMethod(AbstractLbmMethod):
simplificationHints
.
update
(
self
.
_conservedQuantityComputation
.
definedSymbols
())
simplificationHints
[
'relaxationRates'
]
=
D
.
atoms
(
sp
.
Symbol
)
allSubexpressions
=
relaxationRate
Sub
E
xpressions
+
eqValueEqs
.
subexpressions
+
eqValueEqs
.
mainEquations
allSubexpressions
=
additional
Sub
e
xpressions
+
eqValueEqs
.
subexpressions
+
eqValueEqs
.
mainEquations
return
LbmCollisionRule
(
self
,
collisionEqs
,
allSubexpressions
,
simplificationHints
)
...
...
simplificationfactory.py
View file @
1913fa42
...
...
@@ -36,6 +36,7 @@ def createSimplificationStrategy(lbmMethod, doCseInOpposingDirections=False, doO
return
s
if
__name__
==
'__main__'
:
from
lbmpy.stencils
import
getStencil
from
lbmpy.methods.momentbased
import
createOrthogonalMRT
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment