Skip to content
Snippets Groups Projects
Commit f5ff4df4 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Import error in test notebook

parent b1ba7bd7
No related branches found
No related tags found
1 merge request!40Advanced Streaming Extensions
%% Cell type:code id: tags:
```
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
```
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
from pystencils.datahandling import create_data_handling
from pystencils import create_kernel
from pystencils.slicing import slice_from_direction, make_slice
from pystencils.plot import scalar_field, vector_field, vector_field_magnitude
from lbmpy.creationfunctions import create_lb_collision_rule, create_lb_function
from lbmpy.macroscopic_value_kernels import flexible_macroscopic_values_getter, flexible_macroscopic_values_setter
from lbmpy.stencils import get_stencil
from lbmpy.plot import boundary_handling as plot_boundaries
from lbmpy.advanced_streaming import PeriodicityHandling
from lbmpy.boundaries import LatticeBoltzmannBoundaryHandling, NoSlip, UBB
from lbmpy.boundaries.boundaryhandling import create_advanced_streaming_boundary_kernel
from lbmpy.advanced_streaming.utility import is_inplace
from numpy.testing import assert_allclose, assert_array_equal
from test_periodic_pipe_with_force import PeriodicPipeFlow
```
%% Output
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-ff52ef3f43e1> in <module>
9
10 from lbmpy.creationfunctions import create_lb_collision_rule, create_lb_function
---> 11 from lbmpy.macroscopic_value_kernels import flexible_macroscopic_values_getter, flexible_macroscopic_values_setter
12 from lbmpy.stencils import get_stencil
13 from lbmpy.plot import boundary_handling as plot_boundaries
ImportError: cannot import name 'flexible_macroscopic_values_getter' from 'lbmpy.macroscopic_value_kernels' (/home/rzlin/da15siwa/pycodegen/python_includes/lbmpy/macroscopic_value_kernels.py)
%% Cell type:code id: tags:
```
stencil = get_stencil('D2Q9')
streaming_pattern = 'push'
noslip = NoSlip()
ubb = UBB((0.0, 0.0))
noslip_flow = PeriodicPipeFlow(stencil, streaming_pattern, noslip)
ubb_flow = PeriodicPipeFlow(stencil, streaming_pattern, ubb)
noslip_flow.init()
ubb_flow.init()
```
%% Cell type:code id: tags:
```
noslip_flow.run(1)
ubb_flow.run(1)
# The array retrieval somehow stabilizes the simulations
# Without it, they diverge, although they should be functionally equivalent!
noslip_u = noslip_flow.get_trimmed_velocity_array()
ubb_u = ubb_flow.get_trimmed_velocity_array()
```
%% Cell type:code id: tags:
```
noslip_flow.run(100)
noslip_u = noslip_flow.get_trimmed_velocity_array()
vector_field_magnitude(noslip_u)
```
%% Output
<matplotlib.image.AxesImage at 0x7f0390310a90>
<matplotlib.image.AxesImage at 0x7fe3e4272430>
%% Cell type:code id: tags:
```
ubb_flow.run(100)
ubb_u = ubb_flow.get_trimmed_velocity_array()
vector_field_magnitude(ubb_u)
```
%% Output
<matplotlib.image.AxesImage at 0x7f0390208f70>
<matplotlib.image.AxesImage at 0x7fe3e416f910>
%% Cell type:code id: tags:
```
vector_field_magnitude(ubb_u - noslip_u)
```
%% Output
<matplotlib.image.AxesImage at 0x7f165ce4dbb0>
<matplotlib.image.AxesImage at 0x7fe40003f340>
%% Cell type:code id: tags:
```
noslip_force = noslip_flow.bh.force_on_boundary(noslip)
ubb_force = ubb_flow.bh.force_on_boundary(ubb)
noslip_force
```
%% Output
array([5.52793967e-02, 1.89735380e-19])
%% Cell type:code id: tags:
```
ubb_force
```
%% Output
array([5.52793967e-02, 1.89735380e-19])
%% Cell type:code id: tags:
```
import pystencils as ps
from pystencils import Field
from pystencils.boundaries.createindexlist import numpy_data_type_for_boundary_object
ubb_sym_index_field = Field.create_generic('indexField', spatial_dimensions=1,
dtype=numpy_data_type_for_boundary_object(ubb, 2))
noslip_sym_index_field = Field.create_generic('indexField', spatial_dimensions=1,
dtype=numpy_data_type_for_boundary_object(noslip, 2))
```
%% Cell type:code id: tags:
```
ubb_ast = create_advanced_streaming_boundary_kernel(ubb_flow.pdfs, ubb_sym_index_field, ubb_flow.lb_method, ubb,
streaming_pattern=streaming_pattern)
noslip_ast = create_advanced_streaming_boundary_kernel(noslip_flow.pdfs, noslip_sym_index_field, noslip_flow.lb_method,
noslip, streaming_pattern=streaming_pattern)
```
%% Cell type:code id: tags:
```
ind_arr = np.zeros((5,), dtype=numpy_data_type_for_boundary_object(ubb, 2))
ind_arr
```
%% Output
array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)],
dtype={'names':['x','y','dir'], 'formats':['<i4','<i4','<i4'], 'offsets':[0,4,8], 'itemsize':12, 'aligned':True})
%% Cell type:code id: tags:
```
ind_arr['dir'] = - ind_arr['dir']
ind_arr
```
%% Output
array([(0, 0, 4), (0, 0, 4), (0, 0, 4), (0, 0, 4), (0, 0, 4)],
array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)],
dtype={'names':['x','y','dir'], 'formats':['<i4','<i4','<i4'], 'offsets':[0,4,8], 'itemsize':12, 'aligned':True})
%% Cell type:code id: tags:
```
inverse_direction = np.array([4, 3, 2, 1, 0])
ind_arr['dir'] = inverse_direction[ind_arr['dir']]
ind_arr
```
%% Output
array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)],
array([(0, 0, 4), (0, 0, 4), (0, 0, 4), (0, 0, 4), (0, 0, 4)],
dtype={'names':['x','y','dir'], 'formats':['<i4','<i4','<i4'], 'offsets':[0,4,8], 'itemsize':12, 'aligned':True})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment