Skip to content
Snippets Groups Projects
Commit ab5816e6 authored by Maja Warlich's avatar Maja Warlich
Browse files

test_sparse_lbm funktioniert, ohne periodicity

parent 30c7ae00
No related merge requests found
Pipeline #34626 failed with stage
in 13 minutes and 55 seconds
......@@ -141,8 +141,11 @@ class SparseLbMapper:
if flag_arr[tuple(inv_neighbor_cell)] & fluid_boundary_mask:
neighbor_cell_idx = self.cell_idx(tuple(inv_neighbor_cell))
result.append(pdf_index(neighbor_cell_idx, direction_idx, len(self)))
#print("write:", cell, "read:", inv_neighbor_cell, "direction:", direction_idx)
elif flag_arr[tuple(inv_neighbor_cell)] & no_slip_flag: # no-slip before periodicity!
#print("no_slip")
result.append(pdf_index(own_cell_idx, inverse_idx(stencil, direction_idx), len(self)))
#print("write:", cell, "read:", cell, "direction:", inverse_idx(stencil, direction_idx))
else:
#This is where we end up if inv_neighbor_cell is not fluid/no_slip/at the border;
at_border = False
......
This source diff could not be displayed because it is too large. You can view the blob instead.
%% Cell type:code id: tags:
``` python
import pytest
# pytest.importorskip('pycuda')
```
%% Cell type:code id: tags:
``` python
from lbmpy.session import *
from lbmpy.sparse import *
from pystencils.field import FieldType
import pystencils as ps
import warnings
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from pystencils.data_types import TypedSymbol
```
%% Cell type:markdown id: tags:
# Sparse (list based) LBM
%% Cell type:code id: tags:
``` python
domain_size = (4, 3)
omega = 1.8
target = 'cpu'
stencil = get_stencil("D2Q9")
ghost_layers = 0
arr_size = tuple(ds + 2 * ghost_layers for ds in domain_size)
```
%% Cell type:code id: tags:
``` python
dh = ps.create_data_handling(domain_size=domain_size, periodicity=(True, True))
src = dh.add_array('src', values_per_cell=len(stencil))
dh.fill('src', 0.0, ghost_layers=True)
dst = dh.add_array('dst', values_per_cell=len(stencil))
dh.fill('dst', 0.0, ghost_layers=True)
velField = dh.add_array('velField', values_per_cell=dh.dim)
dh.fill('velField', 0.0, ghost_layers=True)
```
%% Cell type:code id: tags:
``` python
ps.stencil.plot_2d(stencil)
```
%% Output
%% Cell type:code id: tags:
``` python
noslip = NoSlip()
flags = {
'fluid': 1,
noslip: 2,
}
flag_arr = np.zeros(arr_size, dtype=np.uint16)
flag_arr.fill(flags['fluid'])
plt.scalar_field(flag_arr)
plt.colorbar();
```
%% Output
%% Cell type:markdown id: tags:
### Mappings
%% Cell type:code id: tags:
``` python
mapping = SparseLbMapper(stencil, domain_size, flag_arr, flags['fluid'], flags[noslip], 0) #Warum müssen (dürfen!) hier Nullen stehen?
index_arr = mapping.create_index_array(ghost_layers)
# Arrays
#index_arr = index_arr_linear.reshape([len(method.stencil), mapping.num_fluid_cells])
#index_arr = index_arr.swapaxes(0, 1)
pdf_arr = np.empty((len(mapping), len(stencil)), order='f')
pdf_arr_tmp = np.empty_like(pdf_arr)
vel_arr = np.ones([mapping.num_fluid_cells, len(stencil[0])], order='f')
```
%% Cell type:code id: tags:
``` python
shape_pdf_arr = pdf_arr.shape
num = 0
for x in range(shape_pdf_arr[0]):
for y in range(shape_pdf_arr[1]):
pdf_arr[x, y] = num
num += 1
```
%% Cell type:code id: tags:
``` python
pdf_field, pdf_field_tmp, vel_field = ps.fields("f(9), d(9), u(2): [1D]")
pdf_field.field_type = FieldType.CUSTOM
pdf_field.pdf_field_tmp = FieldType.CUSTOM
```
%% Cell type:code id: tags:
``` python
periodicity_mapper = SparseLbPeriodicityMapper(mapping, dh, pdf_field)
def handle_periodicity():
periodicity_mapper(pdf_arr)
```
%% Cell type:code id: tags:
``` python
pdf_arr
```
%% Output
array([[ 0., 1., 2., 3., 4., 5., 6., 7., 8.],
[ 9., 10., 11., 12., 13., 14., 15., 16., 17.],
[ 18., 19., 20., 21., 22., 23., 24., 25., 26.],
[ 27., 28., 29., 30., 31., 32., 33., 34., 35.],
[ 36., 37., 38., 39., 40., 41., 42., 43., 44.],
[ 45., 46., 47., 48., 49., 50., 51., 52., 53.],
[ 54., 55., 56., 57., 58., 59., 60., 61., 62.],
[ 63., 64., 65., 66., 67., 68., 69., 70., 71.],
[ 72., 73., 74., 75., 76., 77., 78., 79., 80.],
[ 81., 82., 83., 84., 85., 86., 87., 88., 89.],
[ 90., 91., 92., 93., 94., 95., 96., 97., 98.],
[ 99., 100., 101., 102., 103., 104., 105., 106., 107.]])
%% Cell type:code id: tags:
``` python
handle_periodicity()
pdf_arr
```
%% Output
array([[ 0., 19., 2., 3., 85., 50., 105., 7., 98.],
[ 9., 10., 11., 12., 94., 14., 78., 16., 62.],
[ 18., 19., 2., 21., 103., 23., 96., 34., 89.],
[ 27., 46., 29., 30., 31., 77., 24., 34., 35.],
[ 27., 46., 29., 30., 31., 77., 96., 34., 35.],
[ 36., 37., 38., 39., 40., 41., 42., 43., 44.],
[ 45., 46., 29., 48., 49., 50., 51., 61., 8.],
[ 54., 73., 56., 57., 58., 104., 51., 61., 62.],
[ 45., 46., 29., 48., 49., 50., 51., 61., 98.],
[ 54., 73., 56., 57., 58., 14., 51., 61., 62.],
[ 63., 64., 65., 66., 67., 68., 69., 70., 71.],
[ 72., 73., 56., 75., 76., 77., 78., 88., 35.],
[ 72., 73., 56., 75., 76., 77., 78., 16., 35.],
[ 81., 100., 83., 3., 85., 23., 78., 16., 89.],
[ 90., 91., 92., 12., 94., 50., 96., 34., 98.],
[ 99., 100., 83., 21., 103., 14., 105., 7., 62.]])
%% Cell type:code id: tags:
``` python
```
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment