Exemple #1
0
def test_modelparams_obj():
    """
    Test the behavior of the `ModelParams` object
    
    Test the instantiation and attribute data for the `ModelParams object of
    the `stratified_plume_model` module.
    
    """
    # Get the ambient CTD data
    profile = get_profile()

    # Initialize the ModelParams object
    p = stratified_plume_model.ModelParams(profile)

    # Check if the attributes are set correctly
    assert_approx_equal(p.rho_r, 1031.035855535142, significant=6)
    assert p.alpha_1 == 0.055
    assert p.alpha_2 == 0.110
    assert p.alpha_3 == 0.110
    assert p.lambda_2 == 1.00
    assert p.epsilon == 0.015
    assert p.qdis_ic == 0.1
    assert p.c1 == 0.
    assert p.c2 == 1.
    assert p.fe == 0.1
    assert p.gamma_i == 1.10
    assert p.gamma_o == 1.10
    assert p.Fr_0 == 1.6
    assert p.Fro_0 == 0.1
    assert p.nwidths == 1
    assert p.naverage == 1
    assert p.g == 9.81
    assert p.Ru == 8.314510
Exemple #2
0
def test_plume_objs():
    """
    Test the object behavior for the `InnerPlume` and `OuterPlume` objects
    
    Test the instantiation and attribute data for the `InnerPlume` object of 
    the `stratified_plume_model` module and the `OuterPlume` object.
    
    This test does many of the calculations in `Model.Simulate`, but does
    not perform the simulation.  These calculations are needed to create 
    reasonable `InnerPlume` and `OuterPlume` objects that can be tested.
    
    """
    # Get the model parameters
    (profile, particles, z0, R, maxit, toler, delta_z) = get_sim_data()
    p = stratified_plume_model.ModelParams(profile)

    # Get the initial conditions for this plume
    z0, y0, chem_names = simp.main_ic(profile, particles, p, z0, R)

    # Create the `InnerPlume` object:
    yi = stratified_plume_model.InnerPlume(z0, y0, profile, particles, p,
                                           chem_names)

    # Validate the values in yi
    assert yi.z0 == z0
    assert_array_almost_equal(yi.y0, y0, decimal=6)
    for i in range(len(chem_names)):
        assert yi.chem_names[i] == chem_names[i]
    assert yi.len == y0.shape[0]
    assert yi.nchems == len(chem_names)
    assert yi.np == len(particles)
    assert yi.z == z0
    assert_array_almost_equal(yi.y, y0, decimal=6)
    assert_approx_equal(yi.Q, 0.071595618494002422, significant=8)
    assert_approx_equal(yi.J, 0.072517111934455133, significant=8)
    assert_approx_equal(yi.S, 2.54372236947938290, significant=8)
    assert_approx_equal(yi.H, 84252240.034169987, significant=8)
    assert_array_almost_equal(yi.M_p[0],
                              np.array([0.0587744, 0., 0.]),
                              decimal=6)
    assert_array_almost_equal(yi.M_p[1], np.array([50.]), decimal=6)
    assert_array_almost_equal(yi.H_p,
                              np.array([33541.29892424, 28533906.99805339]),
                              decimal=6)
    assert_array_almost_equal(yi.C, np.array([0.00029302, 0., 0.]), decimal=6)
    assert_approx_equal(yi.Ta, 285.52466101019053, significant=8)
    assert_approx_equal(yi.Sa, 35.52902290651307, significant=8)
    assert_approx_equal(yi.P, 3123785.3190075322, significant=8)
    assert_approx_equal(yi.rho_a, 1028.32228185795, significant=8)
    assert_array_almost_equal(yi.ca, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yi.u, 1.0128708077370672, significant=8)
    assert_approx_equal(yi.b, 0.14999999999999999, significant=8)
    assert_approx_equal(yi.s, 35.52902290651307, significant=8)
    assert_approx_equal(yi.T, 285.52466101019047, significant=8)
    assert_array_almost_equal(yi.c, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yi.rho, 1028.32228185795, significant=8)
    assert_array_almost_equal(yi.xi,
                              np.array([0.01896933, 0.9054897]),
                              decimal=6)
    assert_array_almost_equal(yi.fb,
                              np.array([13.50017158, 83.04871004]),
                              decimal=6)
    assert_approx_equal(yi.Xi, 0.92445903017296149, significant=8)
    assert_approx_equal(yi.Fb, 96.548881624595595, significant=8)
    assert_approx_equal(yi.Ep, 0.0, significant=8)

    # Get similar initial conditions for the outer plume
    y0[0] = 100. * y0[0]
    yi = stratified_plume_model.InnerPlume(z0, y0, profile, particles, p,
                                           chem_names)
    yo_z0, yo_y0 = simp.outer_surf(yi, p)

    # Create the outer plume object
    yo = stratified_plume_model.OuterPlume(yo_z0, yo_y0, profile, p,
                                           chem_names, 0.15)

    # Validate the values in yi
    assert yo.z0 == yo_z0
    assert_array_almost_equal(yo.y0, yo_y0, decimal=6)
    for i in range(len(chem_names)):
        assert yo.chem_names[i] == chem_names[i]
    assert yo.len == yo_y0.shape[0]
    assert yo.nchems == len(chem_names)
    assert yo.z == yo_z0
    assert_array_almost_equal(yo.y, yo_y0, decimal=6)
    assert_approx_equal(yo.Q, -7.875518034340268, significant=8)
    assert_approx_equal(yo.J, 1.6304314421135921, significant=8)
    assert_approx_equal(yo.S, -27.980946064273212, significant=8)
    assert_approx_equal(yo.H, -926774640.37586987, significant=8)
    assert_array_almost_equal(yo.C,
                              np.array([-0.00322321, -0., -0.]),
                              decimal=6)
    assert_approx_equal(yo.Ta, 285.52466101019053, significant=8)
    assert_approx_equal(yo.Sa, 35.52902290651307, significant=8)
    assert_approx_equal(yo.P, 3123785.3190075322, significant=8)
    assert_approx_equal(yo.rho_a, 1028.32228185795, significant=8)
    assert_array_almost_equal(yo.ca, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yo.u, -0.20702529471766656, significant=8)
    assert_approx_equal(yo.b, 3.4830205511945413, significant=8)
    # The next four lines give non-physical results due to the way y0 was
    # manipulated above.  Nonetheless, the test is still checking the right
    # behavior.
    assert_approx_equal(yo.s, 3.5529022906513066, significant=8)
    assert_approx_equal(yo.T, 28.552466101019053, significant=8)
    assert_array_almost_equal(yo.c, np.array([0.00040927, 0., 0.]), decimal=6)
    assert_approx_equal(yo.rho, -10624.710049806243, significant=8)

    # Turn off the inner plume flow rate
    y0[0] = 0.
    yi.update(z0, y0, particles, profile, p)
    assert_approx_equal(yi.Q, 0.0, significant=8)
    assert_approx_equal(yi.J, 0.072517111934455133, significant=8)
    assert_approx_equal(yi.S, 2.5437223694793829, significant=8)
    assert_approx_equal(yi.H, 84252240.034169987, significant=8)
    assert_array_almost_equal(yi.M_p[0],
                              np.array([0.05877446, 0., 0.]),
                              decimal=6)
    assert_array_almost_equal(yi.M_p[1], np.array([50.]), decimal=6)
    assert_array_almost_equal(yi.H_p,
                              np.array([33541.29892424, 28533906.99805339]),
                              decimal=6)
    assert_array_almost_equal(yi.C, np.array([0.00029302, 0., 0.]), decimal=6)
    assert_approx_equal(yi.Ta, 285.52466101019053, significant=8)
    assert_approx_equal(yi.Sa, 35.52902290651307, significant=8)
    assert_approx_equal(yi.P, 3123785.3190075322, significant=8)
    assert_approx_equal(yi.rho_a, 1028.32228185795, significant=8)
    assert_array_almost_equal(yi.ca, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yi.u, 0., significant=8)
    assert_approx_equal(yi.b, 0., significant=8)
    assert_approx_equal(yi.s, 35.52902290651307, significant=8)
    assert_approx_equal(yi.T, 285.52466101019053, significant=8)
    assert_array_almost_equal(yi.c, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yi.rho, 1028.32228185795, significant=8)
    assert_array_almost_equal(yi.xi, np.array([0., 0.]), decimal=6)
    assert_array_almost_equal(yi.fb, np.array([0., 0.]), decimal=6)
    assert_approx_equal(yi.Xi, 0., significant=8)
    assert_approx_equal(yi.Fb, 0., significant=8)
    assert_approx_equal(yi.Ep, 0., significant=8)

    # Turn off the outer plume flow rate
    yo_y0[0] = 0.
    yo.update(yo_z0, yo_y0, profile, p, 0.15)
    assert_approx_equal(yo.Q, 0., significant=8)
    assert_approx_equal(yo.J, 1.6304314421135921, significant=8)
    assert_approx_equal(yo.S, -27.980946064273212, significant=8)
    assert_approx_equal(yo.H, -926774640.37586987, significant=8)
    assert_array_almost_equal(yo.C,
                              np.array([-0.00322321, -0., -0.]),
                              decimal=6)
    assert_approx_equal(yo.Ta, 285.52466101019053, significant=8)
    assert_approx_equal(yo.Sa, 35.52902290651307, significant=8)
    assert_approx_equal(yo.P, 3123785.3190075322, significant=8)
    assert_approx_equal(yo.rho_a, 1028.32228185795, significant=8)
    assert_array_almost_equal(yo.ca, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yo.u, 0., significant=8)
    assert_approx_equal(yo.b, 0., significant=8)
    assert_approx_equal(yo.s, 35.52902290651307, significant=8)
    assert_approx_equal(yo.T, 285.52466101019053, significant=8)
    assert_array_almost_equal(yo.c, np.array([0.00409269, 0., 0.]), decimal=6)
    assert_approx_equal(yo.rho, 1028.32228185795, significant=8)