From 864df46bb3bb7b0b053222082e194150e9aaacf3 Mon Sep 17 00:00:00 2001
From: Markus Holzer <markus.holzer@fau.de>
Date: Sat, 2 Jul 2022 16:02:09 +0200
Subject: [PATCH] Fix longruns

---
 .gitlab-ci.yml                                | 49 +++++++++----------
 lbmpy/boundaries/boundaryconditions.py        |  2 +
 lbmpy/forcemodels.py                          |  8 ++-
 lbmpy_tests/test_chapman_enskog.py            |  2 +-
 ...onserved_quantity_relaxation_invariance.py |  5 +-
 lbmpy_tests/test_diffusion.py                 |  4 +-
 lbmpy_tests/test_force.py                     |  2 +-
 lbmpy_tests/test_vectorization.py             |  3 +-
 8 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2df37c8a..5fba098a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -36,6 +36,27 @@ tests-and-coverage:
       cobertura: coverage.xml
       junit: report.xml
 
+# Normal test with longruns
+tests-and-coverage-with-longrun:
+  stage: test
+  when: manual
+  allow_failure: true
+  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
+  script:
+    # - pip install sympy --upgrade
+    - export NUM_CORES=$(nproc --all)
+    - mkdir -p ~/.config/matplotlib
+    - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
+    - mkdir public
+    - pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
+    - env
+    - pip list
+    - py.test -v -n $NUM_CORES
+  tags:
+    - docker
+    - cuda11
+    - AVX
+
 minimal-conda:
   stage: pretest
   except:
@@ -88,32 +109,6 @@ latest-python:
     reports:
       junit: report.xml
 
-# Nightly test  - runs "long run" jobs only
-test-longrun:
-  stage: test
-  only:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
-  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
-  script:
-    - env 
-    - pip list
-    - export NUM_CORES=$(nproc --all)
-    - mkdir -p ~/.config/matplotlib
-    - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
-    - pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
-    - py.test -v -n $NUM_CORES --cov-report html --cov-report term --cov=. --junitxml=report.xml
-  tags:
-    - docker
-    - cuda11
-    - AVX
-  artifacts:
-    when: always
-    paths:
-      - coverage_report
-    reports:
-      junit: report.xml
-
 # Minimal tests in windows environment
 minimal-windows:
   stage: test
@@ -201,7 +196,7 @@ pycodegen-integration:
     - make -j $NUM_CORES MicroBenchmarkGpuLbm LbCodeGenerationExample
     - cd apps/benchmarks/UniformGridGPU
     - make -j $NUM_CORES
-    - cd ../UniformGridGenerated
+    - cd ../UniformGridCPU
     - make -j $NUM_CORES
 
   tags:
diff --git a/lbmpy/boundaries/boundaryconditions.py b/lbmpy/boundaries/boundaryconditions.py
index f3aee27c..626ef72b 100644
--- a/lbmpy/boundaries/boundaryconditions.py
+++ b/lbmpy/boundaries/boundaryconditions.py
@@ -626,6 +626,8 @@ class DiffusionDirichlet(LbBoundary):
         return [LbmWeightInfo(lb_method, self._data_type)]
 
     def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
+        assert lb_method.conserved_quantity_computation.zero_centered_pdfs is False, \
+            "DiffusionDirichlet only works for methods with normal pdfs storage -> set zero_centered=False"
         weight_info = LbmWeightInfo(lb_method, self._data_type)
         w_dir = weight_info.weight_of_direction(dir_symbol, lb_method)
         return [Assignment(f_in(inv_dir[dir_symbol]),
diff --git a/lbmpy/forcemodels.py b/lbmpy/forcemodels.py
index dd3296fd..10eab767 100644
--- a/lbmpy/forcemodels.py
+++ b/lbmpy/forcemodels.py
@@ -445,12 +445,16 @@ class EDM(AbstractForceModel):
 
     def __call__(self, lb_method):
         cqc = lb_method.conserved_quantity_computation
-        rho = cqc.density_symbol if cqc.compressible else 1
+        reference_density = cqc.density_symbol if cqc.compressible else 1
+        rho = cqc.density_symbol
+        delta_rho = cqc.density_deviation_symbol
+        rho_0 = cqc.background_density
         u = cqc.velocity_symbols
 
         equilibrium_terms = lb_method.get_equilibrium_terms()
+        equilibrium_terms = equilibrium_terms.subs({delta_rho: rho - rho_0})
 
-        shifted_u = (u_i + f_i / rho for u_i, f_i in zip(u, self._force))
+        shifted_u = (u_i + f_i / reference_density for u_i, f_i in zip(u, self._force))
         shifted_eq = equilibrium_terms.subs({u_i: su_i for u_i, su_i in zip(u, shifted_u)})
         return shifted_eq - equilibrium_terms
 
diff --git a/lbmpy_tests/test_chapman_enskog.py b/lbmpy_tests/test_chapman_enskog.py
index 3858247d..fb064295 100644
--- a/lbmpy_tests/test_chapman_enskog.py
+++ b/lbmpy_tests/test_chapman_enskog.py
@@ -38,7 +38,7 @@ def test_steady_state_silva_paper_comparison():
     eps, tau, lambda_plus, f = sp.symbols("epsilon tau Lambda f")
 
     lbm_config = LBMConfig(stencil=LBStencil(Stencil.D3Q19), compressible=False, relaxation_rate=1 / tau,
-                           continuous_equilibrium=False)
+                           continuous_equilibrium=False, zero_centered=False)
     method = create_lb_method(lbm_config=lbm_config)
     analysis = SteadyStateChapmanEnskogAnalysis(method)
 
diff --git a/lbmpy_tests/test_conserved_quantity_relaxation_invariance.py b/lbmpy_tests/test_conserved_quantity_relaxation_invariance.py
index 8979aa0b..306e4b34 100644
--- a/lbmpy_tests/test_conserved_quantity_relaxation_invariance.py
+++ b/lbmpy_tests/test_conserved_quantity_relaxation_invariance.py
@@ -9,7 +9,7 @@ import sympy as sp
 import math
 
 from lbmpy.enums import Stencil, Method
-from lbmpy.methods import RelaxationInfo, create_srt, create_trt, create_trt_kbc, \
+from lbmpy.methods import create_srt, create_trt, create_trt_kbc, \
     create_with_default_polynomial_cumulants
 from lbmpy.methods.momentbased.momentbasedmethod import MomentBasedLbMethod
 from lbmpy.methods.centeredcumulant.centeredcumulantmethod import CenteredCumulantBasedLbMethod
@@ -32,7 +32,8 @@ def __change_relaxation_rate_of_conserved_moments(method, new_relaxation_rate=sp
     elif isinstance(method, CenteredCumulantBasedLbMethod):
         changed_method = CenteredCumulantBasedLbMethod(method.stencil, method.equilibrium_distribution, rr_dict,
                                                        method.conserved_quantity_computation,
-                                                       force_model=method.force_model)
+                                                       force_model=method.force_model,
+                                                       zero_centered=True)
     else:
         raise ValueError("Not a moment or cumulant-based method")
 
diff --git a/lbmpy_tests/test_diffusion.py b/lbmpy_tests/test_diffusion.py
index df390b94..64653124 100644
--- a/lbmpy_tests/test_diffusion.py
+++ b/lbmpy_tests/test_diffusion.py
@@ -31,7 +31,8 @@ def test_diffusion_boundary():
     dh.add_array('pdfs', values_per_cell=stencil.Q)
     dh.fill("pdfs", 0.0, ghost_layers=True)
 
-    lbm_config = LBMConfig(stencil=stencil, method=Method.SRT, relaxation_rate=1.8, compressible=True)
+    lbm_config = LBMConfig(stencil=stencil, method=Method.SRT, relaxation_rate=1.8,
+                           compressible=True, zero_centered=False)
     method = create_lb_method(lbm_config=lbm_config)
 
     # Boundary Handling
@@ -103,6 +104,7 @@ def test_diffusion():
 
     # Lattice Boltzmann method
     lbm_config = LBMConfig(stencil=stencil, method=Method.MRT, relaxation_rates=[1, 1.5, 1, 1.5, 1],
+                           zero_centered=False,
                            velocity_input=vel_field, output={'density': con_field}, compressible=True,
                            weighted=True, kernel_type='stream_pull_collide')
 
diff --git a/lbmpy_tests/test_force.py b/lbmpy_tests/test_force.py
index f6f7b5a8..32e7a9ee 100644
--- a/lbmpy_tests/test_force.py
+++ b/lbmpy_tests/test_force.py
@@ -275,7 +275,7 @@ def test_modes_central_moment(force_model, compressible):
     F = list(sp.symbols(f"F_:{stencil.D}"))
 
     lbm_config = LBMConfig(method=Method.CENTRAL_MOMENT, stencil=stencil, relaxation_rate=omega_s,
-                           compressible=True, force_model=force_model, force=tuple(F))
+                           compressible=compressible, force_model=force_model, force=tuple(F))
     method = create_lb_method(lbm_config=lbm_config)
 
     subs_dict = method.subs_dict_relxation_rate
diff --git a/lbmpy_tests/test_vectorization.py b/lbmpy_tests/test_vectorization.py
index f583c560..9afb93e8 100644
--- a/lbmpy_tests/test_vectorization.py
+++ b/lbmpy_tests/test_vectorization.py
@@ -52,7 +52,8 @@ def test_lbm_vectorization(instruction_set, aligned_and_padding, nontemporal, do
     ldc2_ref.run(time_steps)
 
     lbm_config = LBMConfig(relaxation_rate=relaxation_rate)
-    config = ps.CreateKernelConfig(data_type="double" if double_precision else "float32",
+    config = ps.CreateKernelConfig(data_type="float64" if double_precision else "float32",
+                                   default_number_float="float64" if double_precision else "float32",
                                    cpu_vectorize_info=vectorization_options)
     lbm_opt_split = LBMOptimisation(cse_global=True, split=True)
     lbm_opt = LBMOptimisation(cse_global=True, split=False)
-- 
GitLab