예제 #1
0
    def test_solve(self):
        # Create model and solver parameters.
        mp = solver.ModelParams()
        mp.k_on = 0
        mp.k_off = 0
        mp.t_cut = 1

        sp = solver.SolverParams()
        sp.n = 100
        sp.m = 10

        # Define initial values.
        def const(x):
            return 1.0

        # Initialise tracers.
        x = np.array(np.linspace(0, 1, num=5))

        # Run solver.
        rho, ca, v, sigma, x, idx = solver.solve(mp, sp, const, const, x)

        # Check returned arrays.
        const_exp = np.vectorize(const)(np.zeros((sp.m + 1, sp.n)))

        np.testing.assert_equal(rho.shape, (sp.m + 1, sp.n))
        np.testing.assert_equal(ca.shape, (sp.m + 1, sp.n))
        np.testing.assert_allclose(rho, const_exp, atol=1e-7)
        np.testing.assert_allclose(ca, const_exp, atol=1e-7)
        np.testing.assert_allclose(v,
                                   np.zeros((sp.m + 1, sp.n + 1)),
                                   atol=1e-7)
예제 #2
0
    plt.plot(v)
    k = k + 1

plt.show()
plt.close()

plt.figure()
plt.imshow(vvec)
plt.show()
plt.close()

# Initialise tracers.
x = np.array(np.linspace(0, 1, num=25))

# Run solver.
rho, ca, v, sigma, x, idx = solver.solve(mp, sp, rho_init, ca_init, x, vel=vel)

# Compute mean from staggered grid.
v = (v[:, 0:-1] + v[:, 1:]) / 2

# Compute source.
source = mp.k_on - mp.k_off * ca * rho

# Set name and create folder.
name = 'mechanical_model'
resfolder = os.path.join(resultpath, name)
if not os.path.exists(resfolder):
    os.makedirs(resfolder)

# Plot and save figures.
ph.saveimage(resfolder, '{0}-rho'.format(name), rho)