def test_files(): """ Test the input and output of model simulation data Test the methods `save_sim`, `save_txt`, and `load_sim` of the Stratified Plume Model `Model` object. """ # Get the model parameters (profile, particles, z0, R, maxit, toler, delta_z) = get_sim_data() # Initialize a stratified plume model `Model` object spm = stratified_plume_model.Model(profile) # Run the simulation spm.simulate(particles, z0, R, maxit, toler, delta_z, False) # Save the simulation to a netCDF file fname = './output/spm_data.nc' profile_path = './test_BM54.nc' profile_info = 'Results of ./test_spm.py script' spm.save_sim(fname, profile_path, profile_info) # Save the simulation to a text file base_name = './output/spm_data' spm.save_txt(base_name, profile_path, profile_info) # Load the simulation data from the netCDF file spm.load_sim(fname) assert spm.sim_stored == True # Initialize a Model object from the netCDF file spm_load = stratified_plume_model.Model(simfile=fname) assert spm.sim_stored == True
def test_simulate(): """ Test the `Model.simulate()` method of the Stratified Plume Model Run a simulation to test the operation of the `Model.simulate()` method of the Stratified Plume Model. """ # Get the model parameters (profile, particles, z0, R, maxit, toler, delta_z) = get_sim_data() # Initialize a stratified plume model `Model` object spm = stratified_plume_model.Model(profile) # Run the simulation spm.simulate(particles, z0, R, maxit, toler, delta_z, False) # Check that the results are correct assert spm.sim_stored == True
def get_sim_data(): """ Get the input data to the `params.Scales` object Create an `ambient.Profile` object and a list of `stratified_plume_model.Particle` objects as the required input for the `params.Scales` object. Returns ------- profile : `ambient.Profile` object profile object from the BM54 CTD data disp_phases: list list of `stratified_plume_model.Particle` objects describing the blowout dispersed phases. z0 : float depth at the plume model origin (m) """ # Get the netCDF file nc = test_sbm.make_ctd_file() # Create a profile object with all available chemicals in the CTD data profile = ambient.Profile(nc, chem_names='all') # Create the stratified plume model object spm = stratified_plume_model.Model(profile) # Set the release conditions T0 = 273.15 + 35. # Release temperature in K R = 0.15 # Radius of leak source in m # Create the gas phase particles composition = ['methane', 'ethane', 'propane', 'oxygen'] yk = np.array([0.93, 0.05, 0.02, 0.0]) gas = dbm.FluidParticle(composition) z0 = 1000. disp_phases = [] # Larger free gas bubbles mb0 = 8. # total mass flux in kg/s de = 0.025 # bubble diameter in m lambda_1 = 0.85 disp_phases.append( stratified_plume_model.particle_from_mb0(profile, z0, gas, yk, mb0, de, lambda_1, T0)) # Smaller free gas bubbles (note, it is not necessary to have more than # one bubble size) mb0 = 2. # total mass flux in kg/s de = 0.0075 # bubble diameter in m lambda_1 = 0.9 disp_phases.append( stratified_plume_model.particle_from_mb0(profile, z0, gas, yk, mb0, de, lambda_1, T0)) # Liquid hydrocarbon. This could either be a dissolving phase (mixture # of liquid phases) or an inert phase. We demonstrate here the simple # case of an inert oil phase oil = dbm.InsolubleParticle(True, True, rho_p=890., gamma=30., beta=0.0007, co=2.90075e-9) mb0 = 10. # total mass flux in kg/s de = 0.004 # bubble diameter in m lambda_1 = 0.9 disp_phases.append( stratified_plume_model.particle_from_mb0(profile, z0, oil, np.array([1.]), mb0, de, lambda_1, T0)) # Return the simulation data return (profile, disp_phases, z0)
import numpy as np if __name__ == '__main__': # Get the ambient CTD profile data nc = '../../test/output/test_BM54.nc' try: # Open the lake dataset as a Profile object if it exists ctd = ambient.Profile(nc, chem_names='all') except RuntimeError: # Tell the user to create the dataset print('CTD data not available; run test cases in ./test first.') # Create the stratified plume model object spm = stratified_plume_model.Model(ctd) # Set the release conditions T0 = 273.15 + 35. # Release temperature in K R = 0.15 # Radius of leak source in m # Create the gas phase particles composition = ['methane', 'ethane', 'propane', 'oxygen'] yk = np.array([0.93, 0.05, 0.02, 0.0]) gas = dbm.FluidParticle(composition) z0 = 1000. disp_phases = [] # Larger free gas bubbles mb0 = 8. # total mass flux in kg/s de = 0.025 # bubble diameter in m
from tamoc import stratified_plume_model import lake_bub from datetime import datetime from netCDF4 import date2num import numpy as np if __name__ == '__main__': # Create the lake netCDF dataset and get the Profile object lake = lake_bub.get_lake_data() # Create the stratified plume model object spm = stratified_plume_model.Model(lake) # Create the dispersed phase particles sphere = dbm.InsolubleParticle(False, False, rho_p=15.) z0 = 46. particles = [] # Small particle Q_N = 100. / 60. / 60. de = 0.01 lambda_1 = 0.7 particles.append(stratified_plume_model.particle_from_Q(lake, z0, sphere, 1., Q_N, de, lambda_1, 273.15 + 20.)) # Initialize a simulation R = 6.5 / 2.
from tamoc import ambient from tamoc import dbm from tamoc import seawater from tamoc import stratified_plume_model import numpy as np if __name__ == '__main__': # Create a stratified_plume_model.Model object from the lake_bub.py # results stored on the hard drive. Note that the netCDF file is # self-documenting and actually points to the ambient CTD profile data. # If that file does not exist, the post_processing method cannot be # applied as it reads from the ambient data. spm = stratified_plume_model.Model(simfile='../../test/output/spm_gas.nc') # Echo the results to the screen: print('The results of ./bin/spm/lake_bub.py have been loaded into memory') print(' len(zi) : %d' % spm.zi.shape[0]) print(' shape(yi) : %d, %d' % (spm.yi.shape[0], spm.yi.shape[1])) print(' len(zo) : %d' % spm.zo.shape[0]) print(' shape(yo) : %d, %d' % (spm.yo.shape[0], spm.yo.shape[1])) for i in range(len(spm.particles)): print(' composition %d: %s, ' % (i, spm.particles[i].composition)) # You can plot the results of that stored simulation spm.plot_state_space(1) # You an also load stored simulation data to replace the current # simulation