def test_dissolution_mass_balance(oil, temp, wind_speed, num_elems, expected_mb, on): ''' Test a single dissolution step. - for this, we need a dispersion weatherer to give us a droplet size distribution. Fuel Oil #6 does not exist... ''' waves = build_waves_obj(wind_speed, 'knots', 270, temp) wind = waves.wind water = waves.water disp = NaturalDispersion(waves, water) diss = Dissolution(waves, wind) all_array_types = diss.array_types.union(disp.array_types) (sc, time_step) = weathering_data_arrays(all_array_types, water, num_elements=num_elems, units='kg', amount_per_element=1.0 )[:2] print 'time_step: {}'.format(time_step) print 'num spills:', len(sc.spills) print 'spill[0] amount: {} {}'.format(sc.spills[0].amount, sc.spills[0].units) print 'temperature = ', temp print 'wind = ', print '\n'.join(['\t{} {}'.format(ts[1][0], waves.wind.units) for ts in waves.wind.timeseries]) print # we don't want to query the oil database, but get the sample oil #assert sc.spills[0].substance.record.id is None initial_amount = sc.spills[0].amount model_time = (sc.spills[0].release_time + timedelta(seconds=time_step)) disp.on = on disp.prepare_for_model_run(sc) disp.initialize_data(sc, sc.num_released) diss.on = on diss.prepare_for_model_run(sc) diss.initialize_data(sc, sc.num_released) disp.prepare_for_model_step(sc, time_step, model_time) diss.prepare_for_model_step(sc, time_step, model_time) disp.weather_elements(sc, time_step, model_time) diss.weather_elements(sc, time_step, model_time) if on: print ('fraction dissolved: {}' .format(sc.mass_balance['dissolution'] / initial_amount) ) print ('fraction dissolved: {:.2%}' .format(sc.mass_balance['dissolution'] / initial_amount) ) print sc.mass_balance['dissolution'], expected_mb assert np.isclose(sc.mass_balance['dissolution'], expected_mb, rtol=1e-4) else: assert 'dissolution' not in sc.mass_balance
def test_dissolution_mass_balance(oil, temp, wind_speed, num_elems, expected_mb, on): ''' Test a single dissolution step. - for this, we need a dispersion weatherer to give us a droplet size distribution. Fuel Oil #6 does not exist... ''' et = floating(substance=oil) waves = build_waves_obj(wind_speed, 'knots', 270, temp) water = waves.water disp = NaturalDispersion(waves, water) diss = Dissolution(waves) all_array_types = diss.array_types.union(disp.array_types) (sc, time_step) = weathering_data_arrays(all_array_types, water, element_type=et, num_elements=num_elems, units='kg', amount_per_element=1.0 )[:2] print 'time_step: {}'.format(time_step) print 'num spills:', len(sc.spills) print 'spill[0] amount: {} {}'.format(sc.spills[0].amount, sc.spills[0].units) print 'temperature = ', temp print 'wind = ', print '\n'.join(['\t{} {}'.format(ts[1][0], waves.wind.units) for ts in waves.wind.timeseries]) print # we don't want to query the oil database, but get the sample oil assert sc.spills[0].element_type.substance.record.id is None initial_amount = sc.spills[0].amount model_time = (sc.spills[0].release_time + timedelta(seconds=time_step)) disp.on = on disp.prepare_for_model_run(sc) disp.initialize_data(sc, sc.num_released) diss.on = on diss.prepare_for_model_run(sc) diss.initialize_data(sc, sc.num_released) disp.prepare_for_model_step(sc, time_step, model_time) diss.prepare_for_model_step(sc, time_step, model_time) disp.weather_elements(sc, time_step, model_time) diss.weather_elements(sc, time_step, model_time) if on: print ('fraction dissolved: {}' .format(sc.mass_balance['dissolution'] / initial_amount) ) print ('fraction dissolved: {:.2%}' .format(sc.mass_balance['dissolution'] / initial_amount) ) print sc.mass_balance['dissolution'], expected_mb assert np.isclose(sc.mass_balance['dissolution'], expected_mb) else: assert 'dissolution' not in sc.mass_balance
from gnome.weatherers import (Evaporation, NaturalDispersion, Dissolution, WeatheringData, weatherer_sort) from conftest import weathering_data_arrays, build_waves_obj from ..conftest import (sample_model_weathering, sample_model_weathering2) from pprint import PrettyPrinter pp = PrettyPrinter(indent=2, width=120) # also test with lower wind no dispersion waves = build_waves_obj(15., 'knots', 270, 300.0) water = waves.water wind = waves.wind def test_init(): 'test initialization' wind = constant_wind(15., 0) waves = Waves(wind, Water()) diss = Dissolution(waves) print diss.array_types assert all([(at in diss.array_types) for at in ('mass', 'viscosity', 'density')])
from gnome.outputters import WeatheringOutput from gnome.spill.elements import floating from gnome.weatherers import (Evaporation, NaturalDispersion, Dissolution, weatherer_sort) from conftest import weathering_data_arrays, build_waves_obj from ..conftest import (sample_model_weathering, sample_model_weathering2) from pprint import PrettyPrinter pp = PrettyPrinter(indent=2, width=120) # also test with lower wind no dispersion waves = build_waves_obj(15., 'knots', 270, 300.0) water = waves.water wind = waves.wind def test_init(): 'test sort order for Dissolution weatherer' wind = constant_wind(15., 0) waves = Waves(wind, Water()) diss = Dissolution(waves) print diss.array_types assert all([(at in diss.array_types) for at in ('mass', 'viscosity', 'density')])