pycopm.utils.files_writer module#

Write OPM Flow decks, corner-point grids, properties, and ERT files.

format_opm_compact_values(v)[source]#

Convert values to OPM repeated-value notation.

Parameters:
v

One-dimensional values to compact.

Returns:
list[str]

Values formatted as n*value where consecutive values repeat.

Parameters:

v (NDArray)

Return type:

list[str]

round_like_e(values, significant_digits)[source]#

Round values to a number of significant digits.

Parameters:
values

Values to round.

significant_digits

Number of significant digits, or zero to preserve machine precision.

Returns:
NDArray

Rounded values with the original shape.

Parameters:
  • values (NDArray | list)

  • significant_digits (int)

Return type:

NDArray

_identify_removed_pillars(cfg)[source]#

Find COORD and ZCORN indices removed by TOML coarsening.

Parameters:
cfg

TOML configuration containing axis coarsening arrays.

Returns:
coord_indices, zcorn_indices

Indices to remove from the reference grid arrays.

Parameters:

cfg (ConfigViaTOML)

Return type:

tuple[NDArray, NDArray]

_render_template(template_path, output_path, **variables)[source]#

Render a Mako template to a UTF-8 file.

Parameters:
template_path

Source template path.

output_path

Destination path.

**variables

Values passed to the template.

Parameters:
  • template_path (Path)

  • output_path (Path)

  • variables (Any)

Return type:

None

write_coarsened_model_files(cfg, number_tables)[source]#

Write grid, deck, schedule, job, observation, and ERT files.

Parameters:
cfg

TOML configuration for the generated project.

number_tables

Number of saturation-function tables to generate.

Parameters:
  • cfg (ConfigViaTOML)

  • number_tables (int)

Return type:

None

_write_ert_files(cfg, number_tables)[source]#

Write the ERT configuration, parameter, job, and observation files.

Parameters:
  • cfg (ConfigViaTOML)

  • number_tables (int)

Return type:

None

_write_let_tables(cfg, number_tables)[source]#

Write the LET saturation-function tables.

Parameters:
  • cfg (ConfigViaTOML)

  • number_tables (int)

Return type:

None

_write_grid_files(cfg)[source]#

Write the OPM grid-related files.

Parameters:

cfg (ConfigViaTOML)

Return type:

None

write_include(output_path, text)[source]#

Write text to an OPM include file with the pycopm header.

Parameters:
output_path

Destination include path.

text

OPM deck text written after the header.

Parameters:
  • output_path (Path)

  • text (str)

Return type:

None

write_property(output_path, keyword, values, num_dig)[source]#

Write one compact OPM property.

Parameters:
output_path

Destination include path.

keyword

OPM property keyword.

values

Property values in global-cell order.

num_dig

Number of significant digits.

Parameters:
  • output_path (Path)

  • keyword (str)

  • values (NDArray)

Return type:

None

write_compact_property_file(preprocessing_path, property_name, values, num_dig)[source]#

Write one compacted OPM property to a file.

Parameters:
  • preprocessing_path (Path)

  • property_name (str)

  • values (NDArray)

Return type:

None

write_porv(dck, modified_deck)[source]#

Write the OPM grid-related files.

Parameters:
  • dck (ConfigViaDeck)

  • modified_deck (list[str])

Return type:

None

write_property_inc(dck, property_name, property_values, number_values, modified_deck, allow_inline=False, file_suffix='')[source]#

Write a property include or inline a constant property.

Parameters:
dck

Deck configuration controlling paths, prefixes, and precision.

property_name

OPM property name.

property_values

Values in output-grid order.

number_values

Expected number of output values.

modified_deck

Deck lines in which a constant property may be inlined.

allow_inline

Inline a property when all values are equal.

file_suffix

Optional suffix added before .INC.

Returns:
bool

True when the property was inlined, otherwise False.

Parameters:
  • dck (ConfigViaDeck)

  • property_name (str)

  • property_values (NDArray)

  • number_values (int)

  • modified_deck (list[str])

  • allow_inline (bool)

  • file_suffix (str)

Return type:

bool

write_grid(cfg, cr, zc, dual)[source]#

Write a corner-point grid in GRDECL syntax.

Parameters:
cfg

Deck or TOML configuration containing output dimensions and precision.

cr, zc

Flattened COORD and ZCORN arrays.

dual

Extend the j dimension for a dual-porosity grid.

Parameters:
  • cfg (ConfigViaDeck | ConfigViaTOML)

  • cr (NDArray)

  • zc (NDArray)

  • dual (bool)

Return type:

None

write_reference_to_coarse_map(dck, reftocoa)[source]#

Write the reference-to-coarse mapping as OPERNUM.

Parameters:
dck

Deck configuration controlling the output path and precision.

reftocoa

Coarse-cell identifier for every reference-grid cell.

Parameters:
  • dck (ConfigViaDeck)

  • reftocoa (NDArray)

Return type:

None

write_dual_properties(dck, coarsening, number_values, modified_deck)[source]#

Finalize property files for a dual-porosity grid.

Parameters:
dck

Deck configuration and generated property names.

coarsening

Coarsening data containing matrix and fracture transmissibilities.

number_values

Number of cells in the extended dual grid.

modified_deck

Deck lines that may receive inlined properties.

Parameters:
  • dck (ConfigViaDeck)

  • number_values (int)

  • modified_deck (list[str])

Return type:

None