def test_basics(self, capsys): x0, hx = meshes.origin_and_widths( 1/np.pi, 9*mu_0, 0.0, [-1, 1], stretching=[1, 1], verb=1) out, _ = capsys.readouterr() assert_allclose(x0, -20) assert_allclose(np.ones(40), hx) assert "Skin depth [m] : 3.0 [corr." in out assert "Survey dom. DS [m] : -1.0 - 1.0" in out assert "Comp. dom. DC [m] : -19.8 - 19.8" in out assert "Final extent [m] : -20.0 - 20.0" in out assert "Cell widths [m] : 1.0 / 1.0 / 1.0 [min(DS) / m" in out assert "Number of cells : 40 (4 / 36 / 0) [Total (DS/" in out assert "Max stretching : 1.000 (1.000) / 1.000 [DS (" in out _ = meshes.origin_and_widths( 1/np.pi, [8.9*mu_0, 9*mu_0], 0.0, [-1, 1], stretching=[1, 1], verb=1) out, _ = capsys.readouterr() assert "2.98 / 3.00 [corr. to `properties`]" in out _ = meshes.origin_and_widths( 1/np.pi, [8.9*mu_0, 9*mu_0, 9.1*mu_0], 0.0, [-1, 1], stretching=[1, 1], verb=1) out, _ = capsys.readouterr() assert "2.98 / 3.00 / 3.02 [corr. to `properties`]" in out
def test_compare_to_gow3(self): x0, hx = meshes.origin_and_widths( 0.2, [1, 1], -423, [-3333, 222], min_width_limits=20) y0, hy = meshes.origin_and_widths( 0.2, [1.0, 2.0], 16, [-1234, 8956], min_width_limits=20) z0, hz = meshes.origin_and_widths( 0.2, [1.0, 3.0], -33.3333, [-100, 100], min_width_limits=20) m = meshes.construct_mesh( frequency=0.2, properties=[1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0], center=(-423, 16, -33.3333), domain=([-3333, 222], [-1234, 8956], [-100, 100]), min_width_limits=20, ) assert_allclose(m.origin, (x0, y0, z0), atol=1e-3) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz) # As dict. m = meshes.construct_mesh( frequency=0.2, properties=[1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0], center=(-423, 16, -33.3333), domain={'x': [-3333, 222], 'y': [-1234, 8956], 'z': [-100, 100]}, min_width_limits=20, ) assert_allclose(m.origin, (x0, y0, z0), atol=1e-3) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz)
def test_compare_to_gow1(self): f = 1/np.pi p = 9*mu_0 c = (1, 2, 3) d = [-1, 1] x0, hx = meshes.origin_and_widths(f, p, c[0], d, stretching=[1, 1.3]) y0, hy = meshes.origin_and_widths(f, p, c[1], d, stretching=[1.5, 1]) z0, hz = meshes.origin_and_widths(f, p, c[2], d, stretching=[1, 1]) m = meshes.construct_mesh( f, [p, p, p, p], c, d, stretching=([1, 1.3], [1.5, 1], [1, 1])) assert_allclose(m.origin, (x0, y0, z0)) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz) # As dict m = meshes.construct_mesh( f, [p, p, p, p], c, d, stretching={'x': [1, 1.3], 'y': [1.5, 1], 'z': [1, 1]}) assert_allclose(m.origin, (x0, y0, z0)) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz)
def test_seasurface(self): x01, hx1 = meshes.origin_and_widths( 1/np.pi, 9*mu_0, 0.0, [-1, 1], stretching=[1, 1]) x02, hx2 = meshes.origin_and_widths( 1/np.pi, 9*mu_0, -0.5, [-1, 0], seasurface=0.0, stretching=[1, 1]) assert_allclose(x01, x02) assert_allclose(hx1, hx2)
def test_domain_vector(self): x01, hx1 = meshes.origin_and_widths( 1/np.pi, 9*mu_0, 0.0, [-1, 1], stretching=[1, 1]) x02, hx2 = meshes.origin_and_widths( 1/np.pi, 9*mu_0, 0.0, vector=np.array([-1, 0, 1]), stretching=[1, 1]) assert_allclose(x01, x02) assert_allclose(hx1, hx2) x03, hx3 = meshes.origin_and_widths( 1/np.pi, 9*mu_0, 0.0, distance=[1, 1], stretching=[1, 1]) assert_allclose(x01, x03) assert_allclose(hx1, hx3)
def test_compare_to_gow2(self): vz = np.arange(100)[::-1]*-20 x0, hx = meshes.origin_and_widths( 0.77, [0.3, 1, 2], 0, [-1000, 1000], min_width_limits=[20, 40]) y0, hy = meshes.origin_and_widths( 0.77, [0.3, 2, 1], 0, [-2000, 2000], min_width_limits=[20, 40]) z0, hz = meshes.origin_and_widths( 0.77, [0.3, 2, 1e8], 0, vector=vz, min_width_limits=[20, 40]) m = meshes.construct_mesh( frequency=0.77, properties=[0.3, 1, 2, 2, 1, 2, 1e8], center=(0, 0, 0), domain=([-1000, 1000], [-2000, 2000], None), vector=(None, None, vz), min_width_limits=[20, 40], ) assert_allclose(m.origin, (x0, y0, z0)) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz) # As dict m = meshes.construct_mesh( frequency=0.77, properties=[0.3, 1, 2, 2, 1, 2, 1e8], center=(0, 0, 0), domain={'x': [-1000, 1000], 'y': [-2000, 2000], 'z': None}, vector={'x': None, 'y': None, 'z': vz}, min_width_limits=[20, 40], ) assert_allclose(m.origin, (x0, y0, z0)) assert_allclose(m.h[0], hx) assert_allclose(m.h[1], hy) assert_allclose(m.h[2], hz)
def test_status_quo_with_all(self, capsys): # Defaults. meshes.origin_and_widths( frequency=0.2, properties=[0.3, 1, 50], center=-950, domain=[-2000, -1000], verb=1, ) out, _ = capsys.readouterr() assert "Skin depth [m] : 616 / 1125 / 7958" in out assert "Survey dom. DS [m] : -2000 - -1000" in out assert "Comp. dom. DC [m] : -9071 - 49000" in out assert "Final extent [m] : -10223 - 50988" in out assert "Cell widths [m] : 205 / 205 / 11769" in out assert "Number of cells : 32 (7 / 25 / 0)" in out assert "Max stretching : 1.000 (1.000) / 1.288" in out # All set. meshes.origin_and_widths( frequency=0.2, properties=[3.3, 1, 500], center=-950, domain=[-2000, -1000], vector=-np.arange(20)[::-1]*100-600, seasurface=-500, stretching=[1.2, 1.5], min_width_limits=[20, 500], min_width_pps=5, lambda_factor=20, lambda_from_center=True, max_buffer=10000, mapping='Conductivity', cell_numbers=[20, 40, 80, 160], verb=1, raise_error=False, ) out, _ = capsys.readouterr() assert "Skin depth [m] : 620 / 1125 / 50" in out assert "Survey dom. DS [m] : -2000 - -1000" in out assert "Comp. dom. DC [m] : -10950 - 5300" in out assert "Final extent [m] : -13850 - 5386" in out assert "Cell widths [m] : 100 / 100 / 3158" in out assert "Number of cells : 40 (20 / 20 / 0)" in out assert "Max stretching : 1.000 (1.000) / 1.369" in out # High frequencies. _, _, out = meshes.origin_and_widths( frequency=1e8, properties=[5, 1, 50], center=0, domain=[-1, 1], verb=-1, ) assert "Skin depth [m] : 0.113 / 0.050 / 0.356" in out assert "Survey dom. DS [m] : -1.000 - 1.000" in out assert "Comp. dom. DC [m] : -1.316 - 3.236" in out assert "Final extent [m] : -1.327 - 3.262" in out assert "Cell widths [m] : 0.038 / 0.038 / 0.234" in out assert "Number of cells : 80 (54 / 26 / 0)" in out assert "Max stretching : 1.000 (1.000) / 1.096" in out
def test_errors(self, capsys): with pytest.raises(TypeError, match='Unexpected '): meshes.origin_and_widths(1, 1, 0, [-1, 1], unknown=True) with pytest.raises(ValueError, match="At least one of `domain`, `d"): meshes.origin_and_widths(1, 1, 0) with pytest.raises(ValueError, match="Provided vector MUST at least"): meshes.origin_and_widths(1, 1, 0, [-1, 1], np.array([0, 1, 2])) with pytest.raises(ValueError, match="The `seasurface` must be bigge"): meshes.origin_and_widths(1, 1, 0, [-1, 1], seasurface=-2) # No suitable grid warning. with pytest.raises(RuntimeError, match="No suitable grid found; "): meshes.origin_and_widths(1, 1, 0, [-100, 100], cell_numbers=[1, ]) out = meshes.origin_and_widths( 1, 1, 0, [-100, 100], cell_numbers=[1, ], raise_error=False, verb=1) outstr, _ = capsys.readouterr() assert out[0] is None assert out[1] is None assert "No suitable grid found; relax your criteria." in outstr # Stretching warning. meshes.origin_and_widths( 1/np.pi, 9*mu_0, -0.2, [-1, 2], stretching=[1, 1], seasurface=1.2, verb=3) out, _ = capsys.readouterr() assert "Note: Stretching in DS >> 1.0.\nThe reason " in out