Skip to content
Snippets Groups Projects
Commit a52302db authored by Martin Bauer's avatar Martin Bauer
Browse files

lbmpy: bugfixes in macroscopic value computation

parent b423e493
Branches
Tags
No related merge requests found
...@@ -12,7 +12,7 @@ def noSlip(pdfField, direction, lbMethod): ...@@ -12,7 +12,7 @@ def noSlip(pdfField, direction, lbMethod):
return [sp.Eq(pdfField[neighbor](inverseDir), pdfField(direction))] return [sp.Eq(pdfField[neighbor](inverseDir), pdfField(direction))]
def ubb(pdfField, direction, lbMethod, velocity): def ubb(pdfField, direction, lbMethod, velocity, adaptVelocityToForce=False):
"""Velocity bounce back boundary condition, enforcing specified velocity at obstacle""" """Velocity bounce back boundary condition, enforcing specified velocity at obstacle"""
assert len(velocity) == lbMethod.dim, \ assert len(velocity) == lbMethod.dim, \
...@@ -20,7 +20,11 @@ def ubb(pdfField, direction, lbMethod, velocity): ...@@ -20,7 +20,11 @@ def ubb(pdfField, direction, lbMethod, velocity):
neighbor = offsetFromDir(direction, lbMethod.dim) neighbor = offsetFromDir(direction, lbMethod.dim)
inverseDir = invDir(direction) inverseDir = invDir(direction)
# TODO adapt velocity to force if adaptVelocityToForce:
cqc = lbMethod.conservedQuantityComputation
shiftedVelEqs = cqc.equilibriumInputEquationsFromInitValues(velocity=velocity)
velocity = [eq.rhs for eq in shiftedVelEqs.extract(cqc.firstOrderMomentSymbols).mainEquations]
c_s_sq = sp.Rational(1, 3) c_s_sq = sp.Rational(1, 3)
velTerm = 2 / c_s_sq * sum([d_i * v_i for d_i, v_i in zip(neighbor, velocity)]) * weightOfDirection(direction) velTerm = 2 / c_s_sq * sum([d_i * v_i for d_i, v_i in zip(neighbor, velocity)]) * weightOfDirection(direction)
......
...@@ -140,6 +140,7 @@ def generateBoundaryHandling(pdfField, indexArr, lbMethod, boundaryFunctor): ...@@ -140,6 +140,7 @@ def generateBoundaryHandling(pdfField, indexArr, lbMethod, boundaryFunctor):
cellLoop = LoopOverCoordinate(cellLoopBody, coordinateToLoopOver=0, start=0, stop=indexArr.shape[0]) cellLoop = LoopOverCoordinate(cellLoopBody, coordinateToLoopOver=0, start=0, stop=indexArr.shape[0])
indexField = Field.createFromNumpyArray("indexField", indexArr, indexDimensions=1) indexField = Field.createFromNumpyArray("indexField", indexArr, indexDimensions=1)
indexField.isIndexField = True
coordinateSymbols = [TypedSymbol(name, "int") for name in ['x', 'y', 'z']] coordinateSymbols = [TypedSymbol(name, "int") for name in ['x', 'y', 'z']]
for d in range(dim): for d in range(dim):
......
...@@ -16,10 +16,14 @@ class Simple: ...@@ -16,10 +16,14 @@ class Simple:
def __init__(self, force): def __init__(self, force):
self._force = force self._force = force
def __call__(self, lbmMethod, **kwargs): def __call__(self, lbMethod, **kwargs):
assert len(self._force) == lbmMethod.dim assert len(self._force) == lbMethod.dim
return [3 * w_i * sum([d_i * f_i for d_i, f_i in zip(direction, self._force)])
for direction, w_i in zip(lbmMethod.stencil, lbmMethod.weights)] def scalarProduct(a, b):
return sum(a_i * b_i for a_i, b_i in zip(a, b))
return [3 * w_i * scalarProduct(self._force, direction)
for direction, w_i in zip(lbMethod.stencil, lbMethod.weights)]
class Luo: class Luo:
...@@ -35,12 +39,12 @@ class Luo: ...@@ -35,12 +39,12 @@ class Luo:
def __init__(self, force): def __init__(self, force):
self._force = force self._force = force
def __call__(self, lbmMethod): def __call__(self, lbMethod):
u = sp.Matrix(lbmMethod.firstOrderEquilibriumMomentSymbols) u = sp.Matrix(lbMethod.firstOrderEquilibriumMomentSymbols)
force = sp.Matrix(self._force) force = sp.Matrix(self._force)
result = [] result = []
for direction, w_i in zip(lbmMethod.stencil, lbmMethod.weights): for direction, w_i in zip(lbMethod.stencil, lbMethod.weights):
direction = sp.Matrix(direction) direction = sp.Matrix(direction)
result.append(3 * w_i * force.dot(direction - u + 3 * direction * direction.dot(u))) result.append(3 * w_i * force.dot(direction - u + 3 * direction * direction.dot(u)))
return result return result
...@@ -62,11 +66,11 @@ class Guo: ...@@ -62,11 +66,11 @@ class Guo:
def __init__(self, force): def __init__(self, force):
self._force = force self._force = force
def __call__(self, lbmMethod): def __call__(self, lbMethod):
luo = Luo(self._force) luo = Luo(self._force)
shearRelaxationRate = lbmMethod.getShearRelaxationRate() shearRelaxationRate = lbMethod.getShearRelaxationRate()
correctionFactor = (1 - sp.Rational(1, 2) * shearRelaxationRate) correctionFactor = (1 - sp.Rational(1, 2) * shearRelaxationRate)
return [correctionFactor * t for t in luo(lbmMethod)] return [correctionFactor * t for t in luo(lbMethod)]
def macroscopicVelocityShift(self, density): def macroscopicVelocityShift(self, density):
return defaultVelocityShift(density, self._force) return defaultVelocityShift(density, self._force)
......
import sympy as sp
from copy import deepcopy from copy import deepcopy
from pystencils.field import Field, getLayoutFromNumpyArray from pystencils.field import Field, getLayoutFromNumpyArray
from lbmpy.simplificationfactory import createSimplificationStrategy from lbmpy.simplificationfactory import createSimplificationStrategy
...@@ -30,14 +29,24 @@ def compileMacroscopicValuesGetter(lbMethod, outputQuantities, pdfArr=None, fiel ...@@ -30,14 +29,24 @@ def compileMacroscopicValuesGetter(lbMethod, outputQuantities, pdfArr=None, fiel
pdfField = Field.createGeneric('pdfs', lbMethod.dim, indexDimensions=1, layout=fieldLayout) pdfField = Field.createGeneric('pdfs', lbMethod.dim, indexDimensions=1, layout=fieldLayout)
else: else:
pdfField = Field.createFromNumpyArray('pdfs', pdfArr, indexDimensions=1) pdfField = Field.createFromNumpyArray('pdfs', pdfArr, indexDimensions=1)
fieldLayout = getLayoutFromNumpyArray(pdfArr, indexDimensionIds=[len(pdfField.shape)-1])
outputMapping = {} outputMapping = {}
for outputQuantity in outputQuantities: for outputQuantity in outputQuantities:
numberOfElements = cqc.conservedQuantities[outputQuantity] numberOfElements = cqc.conservedQuantities[outputQuantity]
assert numberOfElements >= 1 assert numberOfElements >= 1
outputField = Field.createGeneric(outputQuantity, lbMethod.dim, layout=fieldLayout,
indexDimensions=0 if numberOfElements <= 1 else 1) indDims = 0 if numberOfElements <= 1 else 1
if pdfArr is None:
fieldLayout = getLayoutFromNumpyArray(pdfArr, indexDimensionIds=[len(pdfField.shape) - 1])
outputField = Field.createGeneric(outputQuantity, lbMethod.dim, layout=fieldLayout, indexDimensions=indDims)
else:
outputFieldShape = pdfArr.shape[:-1]
if indDims > 0:
outputFieldShape += (numberOfElements,)
fieldLayout = getLayoutFromNumpyArray(pdfArr)
else:
fieldLayout = getLayoutFromNumpyArray(pdfArr, indexDimensionIds=[len(pdfField.shape) - 1])
outputField = Field.createFixedSize(outputQuantity, outputFieldShape, indDims, pdfArr.dtype, fieldLayout)
outputMapping[outputQuantity] = [outputField(i) for i in range(numberOfElements)] outputMapping[outputQuantity] = [outputField(i) for i in range(numberOfElements)]
if len(outputMapping[outputQuantity]) == 1: if len(outputMapping[outputQuantity]) == 1:
......
...@@ -90,7 +90,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation): ...@@ -90,7 +90,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
@property @property
def conservedQuantities(self): def conservedQuantities(self):
return {'density': 1, return {'density': 1,
'velocity': 3} 'velocity': len(self._stencil[0])}
def definedSymbols(self, order='all'): def definedSymbols(self, order='all'):
if order == 'all': if order == 'all':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment