e3_flow

e3_flow.py: Functions for reading flow data for 2D and 3D blocks.

This is a grab-bag of classes and functions that help with data handling while preparing and post-processing the flow field data.

Preparing flow field files

FlowCondition

class e3_flow.FlowCondition(p=100000.0, u=0.0, v=0.0, w=0.0, Bx=0.0, By=0.0, Bz=0.0, psi=0.0, divB=0.0, T=[300.0], massf=None, label='', tke=0.0, omega=1.0, mu_t=0.0, k_t=0.0, S=0, add_to_list=1)

Python class to organise the setting of each flow condition.

Now that all of the interesting code has moved to the C++ module gas.cxx, this class just provides convenient access from the user’s scripts as well as some house-keeping needed for writing the config files.

FlowCondition.__init__(p=100000.0, u=0.0, v=0.0, w=0.0, Bx=0.0, By=0.0, Bz=0.0, psi=0.0, divB=0.0, T=[300.0], massf=None, label='', tke=0.0, omega=1.0, mu_t=0.0, k_t=0.0, S=0, add_to_list=1)

Create a FlowCondition.

Parameters:
  • p – static pressure, Pa
  • u – x-component of velocity, m/s
  • v – y-component of velocity, m/s
  • w – z-component of velocity, m/s
  • Bx – x-component of magnetic field, Tesla
  • By – y-component of magnetic field, Tesla
  • Bz – z-component of magnetic field, Tesla
  • psi – divergence cleaning parameter
  • divB – divergence of B
  • T – list of temperatures (T[0] is static temperature), degrees K The length of the list of temperatures must match the number of individual energies in the gas model.
  • massf

    mass fractions of the component species These may be provided in a number of ways:

    • full list of floats. The length of the list of mass fractions
      must match the number of species in the previously selected gas model.
    • single float or int that gets used as the first element,
      the rest being set 0.0
    • dictionary of species names with mass fraction values,
      the remainder being set 0.0
    • None provided, results in the first element being 1.0
      and the rest 0.0
  • label – (optional) string label
  • tke – turbulence kinetic energy, (m/s)**2
  • omega – turbulence frequency or pseudo-vorticity, 1/s
  • mu_t – turbulence viscosity
  • k_t – turbulence thermal conductivity
  • S

    shock indicator

    • 1 == shock-is-near,
    • 0 == no-shock
  • add_to_list – flag to indicate that this FlowCondition object should be added to the flowList. Sometimes we don’t want to accumulate objects in this list. For example, when using many FlowCondition objects in a user-defined flow evaluation function.
FlowCondition.to_dict()

Returns the flow data in dictionary form, ready to be written for a cell.

FlowCondition.write_to_ini_file(fp)

Writes the information to the specified file in .ini format.

This is used to fill in details in the job.config file.

e3_flow.variable_list_for_cell(gdata)

Returns a list of names for the cell variables that are written by the companion function write_cell_data().

Parameters:gdata – the global-data object (used to control which elements are written)
e3_flow.write_cell_data(fp, data, gdata)

Write the cell data into the specified file (fp).

Parameters:
  • fp – file object
  • data – cell data in dictionary form
  • gdata – the global-data object (used to control which elements are written)

For Eilmer3 data files, it’s all on one line.

StructuredGridFlow

class e3_flow.StructuredGridFlow

Somewhere to keep the cell and flow data for a structured-grid block.

StructuredGridFlow.read(fp, verbosity_level=0)

Read the cell-centre flow data for an entire block, Eilmer3-native format.

Note that this function cannot cope with spaces inside names.

StructuredGridFlow.get_cell_data(i, j, k, x=0.0, y=0.0, z=0.0, vol=0.0, replace_geom=False)

Returns the flow data (as a dictionary) for a single cell from a block.

StructuredGridFlow.find_nearest_cell_centre(x, y, z)

Returns the indices of the cell centre nearest the point (x,y,z).

StructuredGridFlow.add_aux_variables(cmdLineDict, omegaz=None, aux_var_names=None, compute_vars=None, verbosity_level=0)

Adds variables to the data dictionary for each cell in a block.

We assume a lot about the data that has been read in so, we need to skip this function if all is not in place

StructuredGridFlow.write_gnuplot_header(fp)

Write a comment line that is compatible with GNUPlot.

StructuredGridFlow.write_gnuplot_data_for_cell(fp, i, j, k)

Write the flow data for a single cell to the specified file.

House-keeping

e3_flow.read_all_blocks(rootName, nblock, tindx, zipFiles=False, movingGrid=False, verbosity_level=0)

Returns all grids and flow blocks for a single flow solution.

e3_flow.add_auxiliary_variables(nblock, flow, cmdLineDict, omegaz_list=None, aux_var_names=None, compute_vars=None)

Adds variables to the data dictionary for each cell in each block.

e3_flow.locate_cell_and_block(grid, flow, dimensions, i_found, j_found, k_found, jb_found, x, y, z=0.0)

Returns the indices that select a particular cell that contains point (x,y,z) or has cell-centre nearest the point, together with the containing block of flow_data.

Can be used for interpolating flow data from within another solution.

ExistingSolution

class e3_flow.ExistingSolution(rootName, solutionWorkDir, nblock, tindx, dimensions=2, assume_same_grid=0, zipFiles=1, add_velocity=<libprep3.Vector3; proxy of <Swig Object of type 'std::vector< Vector3 * >::value_type' at 0x2aebeaab5e70> >, tke=0.0, omega=1.0)

A place to store an existing solution and to provide interpolated flow data.

A common use case is to transfer a previously computed solution into the initial conditions of a new simulation.

The interpolate_flow_condition() method is the primary way to access the flow data when e3prep.py is filling in the initial flow state for a block. This function returns the flow data in a form suitable for write_cell_data() and can be used in the user’s setup script for e3prep.py.

ExistingSolution.__init__(rootName, solutionWorkDir, nblock, tindx, dimensions=2, assume_same_grid=0, zipFiles=1, add_velocity=<libprep3.Vector3; proxy of <Swig Object of type 'std::vector< Vector3 * >::value_type' at 0x2aebeaab5e70> >, tke=0.0, omega=1.0)

Reads and stores an existing solution.

Parameters:
  • rootName – job name that will be used to build file names
  • solutionWorkDir – the directory where we’ll find our ExistingSolution files.
  • nblock – number of blocks in the ExistingSolution data set
  • tindx – the time index to select 0..9999 Do not specify with leading zeros because the Python interpreter will assume that you want to count the time index in octal.
  • dimensions – number of spatial dimensions for the ExistingSolution
  • assume_same_grid

    decide how to locate corresponding cells

    • 0 == searches for corresponding cells As Rainer found, this can be agonisingly slow for large grids.
    • 1 == omits the search for the corresponding cell For the impatient.
  • zipFiles – to use gzipped files, or not
  • add_velocity – is the value to be aded to the old-solution’s velocity. If it is a float value, it becomes the x-component. Otherwise, a Vector value should be supplied and all components will be used.
  • tke – is the value for the initial tke for the turbulent flow. This is applied when we change our simulations from laminar to turbulent
: param omega: is the value for the initial omega for the turbulent flow.
This is also applied when we change our simulations from laminar to turbulent.
ExistingSolution.interpolate_flow_condition(x, y, z, vol, i, j, k, blk_indx)

Returns the flow data for a given location.

Writing plot files

e3_flow.uflowz(q, tiny=1e-30)

Set very small quantities to zero, exactly.

This is intended primarily to avoid the bad behaviour of VTK when it is reading Float32 values that are too small. We have also come across unreasonably-small float values in the context of reading GridPro files.

e3_flow.write_VTK_XML_unstructured_file(fp, grid, flow, binary_format)

Write the cell-centred flow data from a single block as an unstructured grid of finite-volume cells.

Parameters:
  • fp – reference to a file object
  • grid – single-block grid of vertices
  • flow – single-block of cell-centre flow data
  • binary_format – if True, most of the data will be written as raw binary (appended) else it will be written as ascii (in place). We have not used base64 encoding; too much pain with Paraview.
e3_flow.write_VTK_XML_files(rootName, tindx, nblock, grid, flow, t, binary_format)

Writes the top-level (coordinating) parallel/partitioned-VTK file.

Parameters:
  • rootName – specific file names are built by adding bits to this name
  • tindx – integer or string such as “xxxx”
  • nblock – integer
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects
  • t – simulation time corresponding to the flow data at this tindx
  • binary_format – if True, most of the data will be written as raw binary (appended) else it will be written as ascii (in place).
e3_flow.write_plot3d_files(rootName, tindx, nblock, grid, flow, t)

Write the Plote3D files.

Parameters:
  • rootName – specific file names are built by adding bits to this name
  • tindx – integer
  • nblock – integer
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects
  • t – float value for time (that gets ignored)

Profile extraction and writing

e3_flow.decode_range_from_string(range_str, min_value, max_value)

Returns the first and last indices corresponding to a range (with inclusive limits).

e3_flow.write_profile_data(fileName, slice_list_str, tindx, nblock, grid, flow, verbosity_level=0)

Write selected slices of cell data to a file in GnuPlot format.

Parameters:
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects
e3_flow.convert_string(slice_at_point_str, nblock, grid, flow)

Convert a slice-at-point string to a slice-list string that can be appended to another slice-at-list string.

Parameters:
  • nblock – integer
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects
e3_flow.write_profile_along_line(fileName, slice_line_str, tindx, nblock, grid, flow, dimensions, verbosity_level=0)

Write selected line of cell data to a file (in GnuPlot format).

The line is defined as the straight line between p0 and p1, N sample points. There may be several lines specified, separated by semicolons.

Comparing with a reference function

e3_flow.compute_difference_in_flow_data(f_ref, nblock, grid, flow, t)

Take difference with respect to a reference function.

Parameters:
  • f_ref – function that returns flow data in a dictionary
  • nblock – integer
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects
  • t
e3_flow.compute_difference_in_flow_data2(nblock, grid, flow, grid2, flow2, t)

Take difference with respect to a reference solution (grid2, flow2)

Assumes same block topology (cell count, etc).

e3_flow.compute_volume_weighted_norms(nblock, grid, flow)

Returns a dictionary containing the integrated norms.

This will make it easy to extract just the one or two of interest and might be useful when trying to automate convergence tests.

e3_flow.pretty_print_norms(norms, per_block_norm_list='', global_norm_list='')

Print the norms to stdout so that we can easily find items in the output.

Assume the particular structure of the dictionaries as defined in compute_volume_weighted_norms().

The strings specifying which norms we want can specify several, each tuple separated by semicolons. To select a per-block norm, we specify a tuple “jb,var_name,norm_name”. To select a global norm, we specify a tuple “var_name,norm_name”. Available norms are “L1”, “L2”, “Linf” and “peak_pos”. Of course, “peak_pos” goes with the “Linf” norm.

These strings can also be “none” to indicate that no norms should be printed.

Radiation post-processing

e3_flow.tangent_slab_along_slice(fileName, slice_list_str, tindx, nblock, grid, flow, verbosity_level=1)

Perform a tangent-slab radiation calculation using the slices as the profile

Parameters:
  • grid – list of StructuredGrid objects
  • flow – list of StructuredGridFlow objects

The default verbosity_level=1 so that the printing behaviour is unchanged. [TODO]: Dan you might like to check and update this, if necessary.