你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
Add non-zero test for update_magnetic
这个提交包含在:
@@ -2,6 +2,7 @@ import argparse
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from pytest import MonkeyPatch
|
||||
|
||||
from gprMax import config, gprMax
|
||||
from gprMax.grid import FDTDGrid
|
||||
@@ -11,7 +12,7 @@ from gprMax.pml import CFS
|
||||
from gprMax.updates.cpu_updates import CPUUpdates
|
||||
|
||||
|
||||
def build_grid(nx, ny, nz, dl=0.001, dt=3e-9):
|
||||
def build_grid(nx: int, ny: int, nz: int, dl: float = 0.001, dt: float = 3e-9) -> FDTDGrid:
|
||||
grid = FDTDGrid()
|
||||
grid.nx = nx
|
||||
grid.ny = ny
|
||||
@@ -35,13 +36,13 @@ def build_grid(nx, ny, nz, dl=0.001, dt=3e-9):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_mock(monkeypatch):
|
||||
def _mock_simulation_config():
|
||||
def config_mock(monkeypatch: MonkeyPatch):
|
||||
def _mock_simulation_config() -> config.SimulationConfig:
|
||||
args = argparse.Namespace(**gprMax.args_defaults)
|
||||
args.inputfile = "test.in"
|
||||
return config.SimulationConfig(args)
|
||||
|
||||
def _mock_model_config():
|
||||
def _mock_model_config() -> config.ModelConfig:
|
||||
model_config = config.ModelConfig()
|
||||
model_config.ompthreads = 1
|
||||
return model_config
|
||||
@@ -50,7 +51,7 @@ def config_mock(monkeypatch):
|
||||
monkeypatch.setattr(config, "get_model_config", _mock_model_config)
|
||||
|
||||
|
||||
def test_update_magnetic(config_mock):
|
||||
def test_update_magnetic_zero_grid(config_mock):
|
||||
grid = build_grid(100, 100, 100)
|
||||
|
||||
expected_value = np.zeros((101, 101, 101))
|
||||
@@ -72,6 +73,40 @@ def test_update_magnetic(config_mock):
|
||||
assert np.equal(pml.EPhi2, 0).all()
|
||||
|
||||
|
||||
def test_update_magnetic(config_mock):
|
||||
grid = build_grid(11, 11, 11)
|
||||
|
||||
# Why does fields_updates_normal use i+1, j+1 and k+1 everywhere?
|
||||
grid.updatecoeffsH[1] = 1
|
||||
|
||||
grid.Ex = np.tile(np.array([[[1, 2], [2, 1]], [[2, 1], [1, 2]]], dtype=np.float32), (6, 6, 6))
|
||||
grid.Ey = np.tile(np.array([[[1, 3], [3, 1]], [[3, 1], [1, 3]]], dtype=np.float32), (6, 6, 6))
|
||||
grid.Ez = np.tile(np.array([[[1, 4], [4, 1]], [[4, 1], [1, 4]]], dtype=np.float32), (6, 6, 6))
|
||||
grid.Hx = np.tile(np.array([[[3, 1], [1, 3]], [[1, 3], [3, 1]]], dtype=np.float32), (6, 6, 6))
|
||||
grid.Hy = np.tile(np.array([[[1, 5], [5, 1]], [[5, 1], [1, 5]]], dtype=np.float32), (6, 6, 6))
|
||||
grid.Hz = np.tile(np.array([[[5, 3], [3, 5]], [[3, 5], [5, 3]]], dtype=np.float32), (6, 6, 6))
|
||||
|
||||
expected_Ex = grid.Ex.copy()
|
||||
expected_Ey = grid.Ey.copy()
|
||||
expected_Ez = grid.Ez.copy()
|
||||
expected_Hx = grid.Hx.copy()
|
||||
expected_Hy = grid.Hy.copy()
|
||||
expected_Hz = grid.Hz.copy()
|
||||
expected_Hx[1:, :-1, :-1] = np.tile(np.array([[[2]]], dtype=np.float32), (11, 11, 11))
|
||||
expected_Hy[:-1, 1:, :-1] = np.tile(np.array([[[3]]], dtype=np.float32), (11, 11, 11))
|
||||
expected_Hz[:-1, :-1, 1:] = np.tile(np.array([[[4]]], dtype=np.float32), (11, 11, 11))
|
||||
|
||||
cpu_updates = CPUUpdates(grid)
|
||||
cpu_updates.update_magnetic()
|
||||
|
||||
assert np.equal(grid.Ex, expected_Ex).all()
|
||||
assert np.equal(grid.Ey, expected_Ey).all()
|
||||
assert np.equal(grid.Ez, expected_Ez).all()
|
||||
assert np.equal(grid.Hx, expected_Hx).all()
|
||||
assert np.equal(grid.Hy, expected_Hy).all()
|
||||
assert np.equal(grid.Hz, expected_Hz).all()
|
||||
|
||||
|
||||
def test_update_electric_a_non_dispersive(config_mock):
|
||||
grid = build_grid(100, 100, 100)
|
||||
|
||||
|
在新工单中引用
屏蔽一个用户