l_script (Application)

Python program to write the input parameter file for L1d3.

It is intended for the user to define their particular facility and flow in terms of the data objects defined in this module. As part of its initialization, this program will execute a user-specified job file that contains, in Python, the user’s script that defines both facility geometry and gas-path details.

Usage:

$ l_script.py -f <job>

The simulation control data is then organised via the classes: GlobalData, GasSlug, Piston and Diaphragm. These classes provide places to store the configuration information and their function/method names appear as commands in the user’s job description file.

When setting up a new simulation, first define the tube as a set of (x,d) break-points and identify regions of head-loss and regions where the wall-temperature varies from the nominal value. Create the GasSlugs, Pistons, and Diaphragms that will make up the gas path. Note that places where two GasSlugs join will need a GasInterface to be defined. Once all of the components have been created, assemble the gas path and then set any of the time-stepping parameters for which you want values other than the default.

Here is an example script for the Sod shock-tube problem:

# sod.py
gdata.title = 'Sods ideal shock tube, 06-Jul-05'
select_gas_model(model='ideal gas', species=['air'])

Define the tube walls.
add_break_point(0.0, 0.01)
add_break_point(3.0, 0.01)

# Create the gas-path.
left_wall = VelocityEnd(x0=0.0, v=0.0)
driver_gas = GasSlug(p=100.0e3, u=0.0, T=348.4, nn=100,
                     to_end_R=1, cluster_strength=1.1,
                     hcells=0)
interface = GasInterface(x0=0.5)
driven_gas = GasSlug(p=10.0e3, u=0.0, T=278.7, nn=100,
                     hcells=0)
right_wall = VelocityEnd(x0=1.0, v=0.0)
assemble_gas_path(left_wall, driver_gas, interface, driven_gas, right_wall)

# Set some time-stepping parameters
gdata.dt_init = 1.0e-7
gdata.max_time = 0.6e-3
gdata.max_step = 5000
add_dt_plot(0.0, 10.0e-6, 5.0e-6)
add_history_loc(0.7)

This script should define the gas path:

.       |+----- driver-gas -----+|+----- driven-gas -----+|
.       |                        |                        |
.       |                        |                        |
.   left-wall                interface               right-wall

and can be invoked with the command:

$ l_script.py -f sod

Upon getting to the end of the user’s script, this program should then write a complete simulation parameter file (sod.Lp) in the INI format. Because this program (l_script) just gathers the data in order to write the input parameter file, the old documentation for that file is still (somewhat) relevant despite a few small name changes.

Note that Python is very picky about whitespace. If you cut and paste the example from above, make sure that the lines start in the first column and that indentation is consistent with Python’s syntax rules.

Globally-defined object

  • gdata: Contains the GlobalData information describing the simulation. Note that there is one such variable set up by the main program and the user’s script should directly set the attributes of this variable to adjust settings for the simulation.

Functions and classes for use in your input script

class l_script.GlobalData

Contains the tube and simulation control parameters.

The user’s script should not create one of these but should specify the simulation parameters by altering the attributes of the global object “gdata” that already exists by the time the user’s script executes.

The following attributes are available:

  • case_id: (int) Specifies a special case that has custom C-code in the main simulation. See l1d.h for possible values. Use a value of 0 for a generic simulation; this is the usual case. This is not much used in the current code.
  • title: Short title string for embedding in the parameter and solution files.
  • gas_name: the name of the thermo-chemical model (which, in turn, determines the number of species).
  • reacting_flag: If set to 1, Rowan’s finite-rate chemistry will be active. (Default is 0)
  • dt_init: (float) The size of the time-step that will be used for the first few simulation steps. After a few steps, the cfl condition takes over the determination of a suitable time-step.
  • max_time: (float) The simulation will stop if it reaches this time. It is most usual to use this critereon to stop the simulation.
  • max_step: The simulation will be stopped if it reaches this number of steps. This is mostly used to catch the problem of the calculation taking a very long time (measured by one’s patience), possibly because the time-step size has decreased to an extremely small value.
  • cfl: (float) Largest allowable CFL number. The time step is adjusted to ensure that this value is not exceeded in any particular cell. A typical value of 0.25 seems to work well for simulations with sudden events such as diaphragm bursting, while a value as high as 0.5 should be considered only for well-behaved flows.
  • t_order: (int) 1=Euler time-stepping. This is generally cheap and nasty. 2=predictor-corrector time-stepping, nominally second order. This is the default setting. It is, however, twice as CPU intensive as Euler time-stepping.
  • x_order: (int) 1=use cell averages without high-order reconstruction. Use this only if the second-order calculation is showing problems. 2=use limited reconstruction (nominally second order). This is the default selection.
  • dt_plot_list: (list of tuples) Specifies the frequency of writing complete solutions (for later plotting, maybe) and also for the writing of data at history locations. It may be convenient to have different frequencies of writing such output at different stages of the simulation. For example, free-piston driven shock tunnels have a fairly long period during which the piston travels the length of the compression tube and then a relatively short period, following diaphragm rupture, when all the interesting things happen. It is good to have low-frequency output during most of the compression process and higher-frequency output starting just before diaphragm rupture. Arranging good values may require some trial and error. Add entries to this list via the add_dt_plot function.
  • xd_list: List of break-point tuples defining the tube wall. Add elements to the list via the function add_break_point.
  • n: (int) The number of small segments that will be used to describe the tube’s area distribution internal to the simulation. To enable a fast lookup process for the area calculation, the area variation between equally-spaced x-positions is taken to be linear. The default value is 4000 and probably won’t need to be changed except for geometries with rapidly changing cross-sections.
  • T_nominal: (float) The nominal wall temperature (in degrees K) in the absence of a patch of differing temperature.
  • T_patch_list: (list of tuples) Regions of the tube wall that have temperature different to the nominal value can be specified via the function add_T_patch.
  • loss_region_list: (list of tuples) List of head-loss regions, usually associated with sudden changes in tube cross-section and diaphragm stations. Add regions via the function add_loss_region.
  • hloc_list: (list of floats) List of x-coordinates for the history locations. Add entries via the function add_history_loc.
l_script.select_gas_model(model=None, species=None, fname=None)

Selects a gas model for the simulation.

Parameters:
  • model – (string) name of the gas model as shown in the list below.
  • species – list of species names (strings). Note that you could also provide a dictionary with species names as keys and mass-fraction values (and the mass-fractions will be ignored).
  • fname – (string) name of the gas-model file.
Returns:

a list of species names

The new gas models are configured by stand-alone files. This function initialises a gas model for present use in the preparation program (ie. sets it in kernel code) and stores the name for later user at simulation time.

If you already have a gas-model.lua file already set up, give its name as fname.

If you have not already set up the gas-model.lua file, this function is provided as a simple but limited means to do so.

Look-up-table (LUT) gas models and LUT_plus_composite cannot be created directly with this function. If you want a single LUT gas model, just set up the LUT table file externally and supply the name of that file as fname. If you want a LUT-plus-composite gas model, set up the LUT table externally and then set up the rest of the composite gas model using create_gas_file() directly, then select the gas model by specifying the gas file name when calling this function. The create_gas_file() function has the capability of prepending the LUT gas species to the composite gas species list.

l_script.set_reaction_scheme(fname, reacting_flag=1)

Sets the reaction update model and specifies a reacting simulation.

This function sets the name of the input file for the reaction update. It also sets the reacting flag. Note that the user may later reset that flag, possibly to turn off reactions for a particular simulation.

Parameters:
  • fname – (string) name of the file containing the reactions scheme
  • reacting_flag – (int) =1 to activate the reaction scheme; =0 frozen flow.
l_script.add_dt_plot(t_change, dt_plot, dt_his)

Add a dt tuple to the dt_plot tuple list in GlobalData.

Parameters:
  • t_change – (float) The time, in seconds, at which this dt_plot and dt_his should take effect.
  • dt_plot – (float) Time interval between writing whole solutions for later plotting.
  • dt_his – (float) Time interval between writing data to history file.
Returns:

the new length of the list

l_script.add_break_point(x, d, transition_flag=0)

Add a break-point tuple to the tube-diameter description contained in GlobalData.

The tube is described as a set of (x,d)-coordinate pairs that define break points in the profile of the tube wall.

Parameters:
  • x – (float) x-coordinate, in metres, of the break point
  • d – (float) diameter, in metres, of the tube wall at the break-point.
  • transition_flag – (int) Indicates the variation in diameter between this break-point and the next. 1=linear, 0=Hermite-cubic.
Returns:

Number of break points defined so far.

l_script.add_loss_region(xL, xR, K)

Add a head-loss region to the tube description in L{GlobalData}.

There is a momentum-sink term much like the so-called minor-loss terms in the fluid mechanics text books. The effect of the loss is spread over a finite region so that the cells are gradually affected as they pass through the region

Parameters:
  • xL – (float) Left-end location, in metres, of the loss region.
  • xR – (float) Right-end location, in metres, of the loss region.
  • K – (float) Head-loss coefficient. A value of 0.25 seems to be good for a reasonably smooth contraction such as the T4 main diaphragm station.
Returns:

Number of loss regions defined so far.

l_script.add_T_patch(xL, xR, T)

Add a temperature patch for a region where the wall temperature is different from the nominal value.

Parameters:
  • xL – (float) Left-end location, in metres, of the loss region.
  • xR – (float) Right-end location, in metres, of the loss region.
  • T – (float) Wall temperature in degrees K.
Returns:

Number of temperature patches defined so far.

l_script.add_history_loc(x)

Add a location to the history-location list in L{GlobalData}.

Parameters:x – (float) x-coordinate, in metres, of the sample point.
Returns:Number of sample points defined so far.
class l_script.GasSlug(p=100000.0, u=0.0, T=[300.0], massf=[1.0], label='', nn=10, to_end_L=0, to_end_R=0, cluster_strength=0.0, viscous_effects=0, adiabatic_flag=0, hcells=[], nnmax=None, adaptive=0, dxmin=0.01, dxmax=0.05)

Contains the gas properties and discretisation for each gas slug.

The user may create more than one gas slug to describe the initial gas properties throughout the facility.

Note that a slug needs to have appropriate end-conditions. This is achieved by creating end-condition objects such as FreeEnd and VelocityEnd objects and then assembling the gas-path via a call to the function assemble_gas_path.

__init__(p=100000.0, u=0.0, T=[300.0], massf=[1.0], label='', nn=10, to_end_L=0, to_end_R=0, cluster_strength=0.0, viscous_effects=0, adiabatic_flag=0, hcells=[], nnmax=None, adaptive=0, dxmin=0.01, dxmax=0.05)

Creates a gas slug with user-specified properties.

Most parameters have default properties so that only the user needs to override the ones that they wish to set differently.

Note that the locations of the ends of the slug are communicated through end-condition objects that are attached during assembly of the gas path.

Parameters:
  • p – (float) Pressure in Pa.
  • u – (float) Velocity in m/s.
  • T – (float or list of floats) Temperature in degrees K.
  • massf – Mass fractions supplied as a list of floats or a dictionary of species names and floats. The number of mass fraction values should match the number of species expected by the selected gas model.
  • label – Optional (string) label for the gas slug.
  • nn – (int) Number of cells within the gas slug.
  • to_end_L – (int) Flag to indicate that cells should be clustered to the left end.
  • to_end_R – (int) Flag to indicate that cells should be clustered to the right end.
  • cluster_strength – (float) As this value approaches 1.0 from above, the clustering gets stronger. A value of zero indicates no clustering.
  • viscous_effects – (int) A nonzero value activates the viscous effects. 0 = inviscid equations only; 1 = include viscous source terms F_wall, loss, q, friction factor for pipe flow; 2 = use Con Doolan’s laminar mass-loss model if the mass within a cell is greater than MINIMUM_MASS as set in l1d.hh; 3 = use Con Doolan’s turbulent mass-loss model if the mass within a cell is greater than MINIMUM_MASS as set in l1d.hh; 4 = include viscous source terms F_wall, loss, q, friction factor for flat plate; 5 = use David Buttsworth’s mass-loss model with pipe-flow friction factor; 6 = use David Buttsworth’s mass-loss model with flat-plate friction factor; 7 = include viscous source terms F_wall, loss, q, friction factor for pipe flow; half heat flux.
  • adiabatic_flag – (int) Flag to indicate that there should be no heat transfer at the tube wall.
  • hcells – Either the index (int) of a single cell or a list of indices of cells for which the data are to be written every dt_his seconds, as set by add_dt_plot. Note that cells are indexed from 0 to nn-1.
  • nnmax – (int) Maximum number of cells that can be carried in the adaptive discretization.
  • adaptive – (int) Flag to indicate that adaptive discretization is to be used (=1).
  • dxmin – (float) Minimum cell size, below which a cell will be fused into its neighbour.
  • dxmax – (float) Maximum cell size, above which a cell will be split into 2.
class l_script.Piston(m, d, xL0, xR0, v0, front_seal_f=0.0, front_seal_area=0.0, back_seal_f=0.0, back_seal_area=0.0, p_restrain=0.0, is_restrain=0, with_brakes=0, brakes_on=0, x_buffer=10000000.0, hit_buffer=0, label='', f_decay=0.0, mass_limit=0.0)

Contains the information for a piston.

  • The left- and right-end positions of the piston are also used to locate the ends of adjoining GasSlugs.
  • The basic piston model has inertia but no friction. To make accurate simulations of a particular facility, it is usually important to have some account of the friction caused by gas-seals and guide-rings that may be present on the piston.
  • The f_decay parameter is used to model secondary diaphragms in expansion tubes as pistons which lose their mass over time.
__init__(m, d, xL0, xR0, v0, front_seal_f=0.0, front_seal_area=0.0, back_seal_f=0.0, back_seal_area=0.0, p_restrain=0.0, is_restrain=0, with_brakes=0, brakes_on=0, x_buffer=10000000.0, hit_buffer=0, label='', f_decay=0.0, mass_limit=0.0)

Create a piston with specified properties.

Parameters:
  • m – (float) Mass in kg.
  • d – (float) Face diameter, metres.
  • xL0 – (float) Initial position of left-end, metres. The initial position of the piston centroid is set midway between xL0 and xR0 while piston length is the difference (xR0 - xL0).
  • xR0 – (float) Initial position of right-end, metres.
  • v0 – (float) Initial velocity (of the centroid), m/s.
  • front_seal_f – (float) friction coefficient. Typical value might be 0.2.
  • front_seal_area – (float) Seal area over which the front-side pressure acts. This is the effective area over which the compressed gas pressed the front-side seal against the tube wall. Friction force is this area multiplied by downstream-pressure by friction coefficient.
  • back_seal_f – (float) friction coefficient. A typical value might be 0.2.
  • back_seal_area – (float) Seal area over which the back-side pressure acts. Friction force is this area multiplied by downstream-pressure by friction coefficient. This is for gun tunnel pistons that have flexible skirts that are pressed onto the tube wall by the pushing gas.
  • p_restrain – (float) Pressure at which restraint will release. Some machines, such as two-stage light-gas guns, will hold the projectile in place with some form of mechanical restraint until the pressure behind the piston reaches a critical value. The piston is then allowed to slide.
  • is_restrain – (int) Status flag for restraint. 0=free-to-move, 1=restrained, 2=predefined trajectory read from external file
  • with_brakes – (int) Flag to indicate the presence of brakes. 0=no-brakes, 1=piston-does-have-brakes. Such brakes, as on the T4 shock tunnel, allow forward motion of the piston but prevent backward motion by locking the piston against the tube wall.
  • brakes_on – (int) Flag to indicate the state of the brakes. 0=off, 1=on.
  • x_buffer – (float) Position of the stopping buffer in metres. This is the location of the piston centroid at which the piston would strike the buffer (or brake, in HEG terminology). Note that it is different to the location of the front of the piston at strike.
  • hit_buffer – (int) Flag to indicate state of buffer interaction. A value of 0 indicates that the piston has not (yet) hit the buffer. A value of 1 indicates that it has. Details of the time and velocity of the strike are recorded in the event file.
  • label – (string) A bit of text for corresponding line in the Lp file.
  • f_decay – (float) dm/dt = m * f_decay, thus a pseudo- time-constant for diaphragm mass decay.
  • mass_limit – (float) Mass limit for decaying diaphragm
class l_script.Diaphragm(x0, p_burst, is_burst=0, dt_hold=0.0, dt_blend=0.0, dx_blend=0.0, RSP_dt=0.0, dxL=0.0, dxR=0.0, label='')

Contains the information for a diaphragm which controls the interaction of two GasSlugs.

__init__(x0, p_burst, is_burst=0, dt_hold=0.0, dt_blend=0.0, dx_blend=0.0, RSP_dt=0.0, dxL=0.0, dxR=0.0, label='')

Creates a diaphragm with specified properties.

The connections to GasSlugs are made later via the function assemble_gas_path.

Parameters:
  • x0 – (float) x-position in the tube, metres. This value is used to determine the end-points of the GasSlugs.
  • p_burst – (float) Pressure, in Pa, at which rupture is triggered.
  • is_burst – (int) Flag to indicate the state of diaphragm. A value of 0 indicates that the diaphragm is intact while a value of 1 indicates that the diaphragm is ruptured and the GasSlugs are interacting.
  • dt_hold – (float) Time delay, in seconds, from rupture trigger to actual rupture.
  • dt_blend – (float) Time delay, in seconds, from rupture to a blend event. This models the mixing of the two gas slugs some time after rupture of the diaphragm. Blending events are seldom used so this is usually set to 0.0.
  • dx_blend – (float) Distance, in metres, over which blending occurs. Set to 0.0 to have no effective blending.
  • dxL – (float) The distance over which p is averaged on left of the diaphragm. The pressure difference between the left- and right-sided of the diaphragm is used to trigger rupture. The default value of 0.0 will cause the pressure in the gas cell immediately adjacent to the diaphragm to be used.
  • dxR – (float) The distance, in metres, over which p is averaged on right-side of the diaphragm.
  • label – A (string) label that will appear in the parameter file for this diaphragm.
class l_script.GasInterface(x0)

Contains the information for an interface between two slugs.

The primary use of this class is to locate the ends of the connected GasSlugs. Implicitly, the logical connections are also made via the function assemble_gas_path.

__init__(x0)

Creates as interface between two L{GasSlug}s at specified location.

Parameters:x0 – (float) Initial position, in metres.
class l_script.FreeEnd(x0)

Contains the information for a free-end condition.

__init__(x0)

Creates a GasSlug end-condition with a specified location.

Parameters:x0 – (float) Initial position, in metres.
class l_script.VelocityEnd(x0, v=0.0)

Contains the information for a fixed-velocity end condition for a GasSlug.

__init__(x0, v=0.0)

Creates a GasSlug end-condition with a specified location and velocity.

Parameters:
  • x0 – (float) Initial position, in metres.
  • v – (float) Velocity, in m/s, of the end-point of the GasSlug.
l_script.assemble_gas_path(*components)

Assembles a gas path by making the logical connections between adjacent components.

The components are assembled left-to-right, as they are supplied to this function.

Parameters:components – An arbitrary number of arguments representing individual components or lists of components. Each component may be a GasSlug, Piston, or any other gas-path object, however, it doesn’t always make sense to connect arbitrary components. For example, connecting a GasSlug to a Piston is reasonable but connecting a Piston to a Diaphragm without an intervening GasSlug does not make sense in the context of this simulation program.

Table Of Contents

Previous topic

L1d3

Next topic

imoc

This Page