resdata icon indicating copy to clipboard operation
resdata copied to clipboard

How to generate Eclipse output files in python

Open ming-origen opened this issue 4 years ago • 2 comments

Are there existing functionality for generating output (e.g. .UNRST, .SMSPEC, and .UNSMRY) files for Eclipse? Assuming I already have the 3D grid data and properties (e.g. stored as pytorch tensor).

ming-origen avatar Sep 18 '20 14:09 ming-origen

Here is some code snippet of what I have tried:

rst_file = "export.UNRST"
timesteps = [1, 50, 100, 150, 200]
_, _, nx, ny, nz = output_data[0].size()
n_data_entries = output_data[0].nelement()
day_count = 1
with openFortIO(rst_file, FortIO.WRITE_MODE) as f:
    for idx, timestep in enumerate(timesteps):
        # 1 by 1 by nx by ny by nz
        output = output_data[idx].cpu().numpy()
        seqnum_kw = EclKW("SEQNUM", 1, EclDataType.ECL_INT)
        seqnum_kw[0] = timestep
        seqnum_kw.fwrite(f)
        intehead_kw = EclKW("INTEHEAD", 3, EclDataType.ECL_INT)
        # TODO: what's the proper value to use for INTEHEAD???
        intehead_kw[0] = day_count
        intehead_kw[1] = 1
        intehead_kw[2] = 2020
        day_count += 1
        intehead_kw.fwrite(f)
        swat_kw = EclKW("SWAT", n_data_entries, EclDataType.ECL_DOUBLE)
        for k in range(nz):
            for j in range(ny):
                for i in range(nx):
                    index = k * nz + j * ny + i
                    swat_kw[index] = output[0, 0, i, j, k]
       swat_kw.fwrite(f)

I am not sure what should go inside keyword INTEHEAD. Is this supposed to be the date? I am using some made-up dates (day, month, year) as described in lib/ecl/ecl_file_view.cpp. However, when I try to import the corresponding .EGRID file (with this .UNRST file in the same folder) in Resinsight, it just straight up crashes.

Could you give me some insight as for what I am doing wrong here? Thanks!

ming-origen avatar Oct 02 '20 06:10 ming-origen

Hi @ming-origen,

I thought there were some examples within libecl, but didn't see them right away.

We do however create dummy UNRST files in other projects for unit tests: https://github.com/equinor/semeio/blob/9be403dcdb2ef5803bc1a1a9d1e89a07fcb745ab/tests/jobs/overburden_timeshift/ots_util.py#L19

You might not need everything that is there, but it should be a fairly simple setup.

In terms of your issues in ResInsight, is there any other error than util_abort?

lars-petter-hauge avatar Oct 16 '20 08:10 lars-petter-hauge