From 9a021a99fc9029f4c023f3afedc1456f3836c7d2 Mon Sep 17 00:00:00 2001 From: Ruizhi Yu Date: Wed, 20 Nov 2024 11:01:25 +0800 Subject: [PATCH] test: add minmod tests --- SolMuseum/num_api/pde/test/__init__.py | 0 SolMuseum/num_api/pde/test/test_minmod.py | 24 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 SolMuseum/num_api/pde/test/__init__.py create mode 100644 SolMuseum/num_api/pde/test/test_minmod.py diff --git a/SolMuseum/num_api/pde/test/__init__.py b/SolMuseum/num_api/pde/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SolMuseum/num_api/pde/test/test_minmod.py b/SolMuseum/num_api/pde/test/test_minmod.py new file mode 100644 index 0000000..9bdead6 --- /dev/null +++ b/SolMuseum/num_api/pde/test/test_minmod.py @@ -0,0 +1,24 @@ +import numpy as np +from ..minmod_limiter import minmod, minmod_flag, switch_minmod + + +def test_minmod(): + a = np.array([-1, 1, 2, 4.]) + b = np.array([-3, 2, 0, 0]) + c = np.array([-5, 3, -1, 1.]) + np.testing.assert_allclose(minmod(a, b, c), np.array([-1, 1, 0, 0.])) + + +def test_minmod_flag(): + a = np.array([-1, 3, 2, -4, 5, 10]) + b = np.array([-3, 2, 1, -2, 0, -1]) + c = np.array([-5, 1, 1, -5.4, 1, 2]) + np.testing.assert_allclose(minmod_flag(a, b, c), np.array([1, 3, 2, 2, 0, 0])) + + +def test_switch_minmod(): + a = np.array([-1, 3, 2, -4, 5, 10]) + b = np.array([-3, 2, 1, -2, 0, -1]) + c = np.array([-5, 1, 1, -5.4, 1, 2]) + flag = minmod_flag(a, b, c) + np.testing.assert_allclose(switch_minmod(a, b, c, flag), np.array([-1, 1, 1, -2, 0, 0.0]))