pycopm.utils.files_writer module

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

pycopm.utils.files_writer._identify_removed_pillars(cfg: ConfigViaTOML) tuple[NDArray, NDArray]

Find COORD and ZCORN indices removed by TOML coarsening.

Parameters:

cfg – TOML configuration containing axis coarsening arrays.

Returns:

Indices to remove from the reference grid arrays.

Return type:

coord_indices, zcorn_indices

pycopm.utils.files_writer._render_template(template_path: Path, output_path: Path, **variables: Any) None

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.

pycopm.utils.files_writer._write_ert_files(cfg: ConfigViaTOML, number_tables: int) None

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

pycopm.utils.files_writer._write_grid_files(cfg: ConfigViaTOML) None

Write the OPM grid-related files.

pycopm.utils.files_writer._write_let_tables(cfg: ConfigViaTOML, number_tables: int) None

Write the LET saturation-function tables.

pycopm.utils.files_writer.format_opm_compact_values(v: NDArray) list[str]

Convert values to OPM repeated-value notation.

Parameters:

v – One-dimensional values to compact.

Returns:

Values formatted as n*value where consecutive values repeat.

Return type:

list[str]

pycopm.utils.files_writer.round_like_e(values: NDArray | list, significant_digits: int) NDArray

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:

Rounded values with the original shape.

Return type:

NDArray

pycopm.utils.files_writer.write_coarsened_model_files(cfg: ConfigViaTOML, number_tables: int) None

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.

pycopm.utils.files_writer.write_compact_property_file(preprocessing_path: Path, property_name: str, values: NDArray, num_dig) None

Write one compacted OPM property to a file.

pycopm.utils.files_writer.write_dual_properties(dck: ConfigViaDeck, coarsening, number_values: int, modified_deck: list[str]) None

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.

pycopm.utils.files_writer.write_grid(cfg: ConfigViaDeck | ConfigViaTOML, cr: NDArray, zc: NDArray, dual: bool) None

Write a corner-point grid in GRDECL syntax.

Parameters:
  • cfg – Deck or TOML configuration containing output dimensions and precision.

  • cr – Flattened COORD and ZCORN arrays.

  • zc – Flattened COORD and ZCORN arrays.

  • dual – Extend the j dimension for a dual-porosity grid.

pycopm.utils.files_writer.write_include(output_path: Path, text: str) None

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.

pycopm.utils.files_writer.write_porv(dck: ConfigViaDeck, modified_deck: list[str]) None

Write the OPM grid-related files.

pycopm.utils.files_writer.write_property(output_path: Path, keyword: str, values: NDArray, num_dig) None

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.

pycopm.utils.files_writer.write_property_inc(dck: ConfigViaDeck, property_name: str, property_values: NDArray, number_values: int, modified_deck: list[str], allow_inline: bool = False, file_suffix: str = '') bool

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:

True when the property was inlined, otherwise False.

Return type:

bool

pycopm.utils.files_writer.write_reference_to_coarse_map(dck: ConfigViaDeck, reftocoa: NDArray) None

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.