Skip to content
Snippets Groups Projects
Commit b42ea55e authored by Markus Holzer's avatar Markus Holzer
Browse files

Convert notebook to python code

parent 4dffbbd4
No related branches found
No related tags found
1 merge request!70Fix minor issues and remove depricated usage of cumulant LB method
%% Cell type:code id: tags:
``` python
import pytest
pytest.importorskip('skimage')
```
%% Output
<module 'skimage' from '/home/markus/miniconda3/envs/pystencils/lib/python3.8/site-packages/skimage/__init__.py'>
%% Cell type:code id: tags:
``` python
import numpy as np
from lbmpy.session import *
from lbmpy.phasefield.experiments2D import *
from lbmpy.phasefield.post_processing import *
from lbmpy.phasefield.contact_angle_circle_fitting import *
```
%% Cell type:markdown id: tags:
# Testing Neumann angle evaluation based on circle fitting
Set up a 3 phase model to have example data
%% Cell type:code id: tags:
``` python
kappa3 = 0.03
alpha = 1
sc = liquid_lens_setup(domain_size=(150, 60), optimization={'target': 'cpu'},
kappas=(0.01, 0.02, kappa3),
cahn_hilliard_relaxation_rates=[np.nan, 1, 3/2],
cahn_hilliard_gammas=[1, 1, 1/3],
alpha=alpha)
```
%% Cell type:code id: tags:
``` python
sc.run(10000)
```
%% Cell type:code id: tags:
``` python
if 'is_test_run' not in globals():
plt.phase_plot_for_step(sc)
```
%% Output
%% Cell type:code id: tags:
``` python
angles = liquid_lens_neumann_angles(sc.concentration[:, :, :])
assert sum(angles) == 360
angles
```
%% Output
<frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject
<frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject
<frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject
$\displaystyle \left[ 97.3044816152428, \ 120.290780534512, \ 142.404737850245\right]$
[97.30448161524285, 120.29078053451232, 142.40473785024486]
%% Cell type:code id: tags:
``` python
analytic_angles = analytic_neumann_angles([0.01, 0.02, kappa3])
analytic_angles
```
%% Output
$\displaystyle \left[ 90.0, \ 126.869897645844, \ 143.130102354156\right]$
[89.99999999999999, 126.86989764584402, 143.13010235415598]
%% Cell type:code id: tags:
``` python
for ref, simulated in zip(analytic_angles, angles):
assert np.abs(ref - simulated) < 8
```
import pytest
import sympy as sp
import numpy as np
from lbmpy.phasefield.analytical import (
analytic_interface_profile, chemical_potentials_from_free_energy, cosh_integral,
......@@ -7,6 +9,9 @@ from lbmpy.phasefield.analytical import (
symmetric_symbolic_surface_tension)
from pystencils.fd import evaluate_diffs, expand_diff_full
from lbmpy.phasefield.experiments2D import liquid_lens_setup
from lbmpy.phasefield.contact_angle_circle_fitting import liquid_lens_neumann_angles
from lbmpy.phasefield.post_processing import analytic_neumann_angles
def test_analytic_interface_solution():
"""Ensures that the tanh is an analytical solution for the prescribed free energy / chemical potential
......@@ -67,3 +72,27 @@ def test_pressure_tensor():
for f1_i, f2_i in zip(force_chem_pot, force_pressure_tensor):
assert sp.expand(f1_i - f2_i) == 0
def test_neumann_angle():
pytest.importorskip('skimage')
kappa3 = 0.03
alpha = 1
sc = liquid_lens_setup(domain_size=(150, 60), optimization={'target': 'cpu'},
kappas=(0.01, 0.02, kappa3),
cahn_hilliard_relaxation_rates=[np.nan, 1, 3 / 2],
cahn_hilliard_gammas=[1, 1, 1 / 3],
alpha=alpha)
sc.run(10000)
angles = liquid_lens_neumann_angles(sc.concentration[:, :, :])
assert sum(angles) == 360
analytic_angles = analytic_neumann_angles([0.01, 0.02, kappa3])
for ref, simulated in zip(analytic_angles, angles):
assert np.abs(ref - simulated) < 8
# to show the phasefield use:
# plt.phase_plot_for_step(sc)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment