OPM / opm-simulators

OPM Flow and experimental simulators, including components such as well models etc.
http://www.opm-project.org
GNU General Public License v3.0
112 stars 122 forks source link

PYACTION and Convergence Failure #4804

Closed mtcanam closed 1 year ago

mtcanam commented 1 year ago

Hi, Seems that I'm having an issue with PYACTION. There's some sort of check on elapsed time happening when the action is set to run, and when the timestep is chopped due to convergence failure (not ideal, but it happens), the check fails as shown in the attached. I've tried using no tuning and our default of 0.5 days, and both seem to have the same issue.

image

bska commented 1 year ago

Hi,

I think it's likely that you've inadvertently identified a programming error in the simulator. That diagnostic ("...must not precede previous...") is emitted in a single location, when we're calculating summary quantities (e.g., field-level oil production rates or well-level gas injection totals) and if the time point happens to be before the time point of the previous summary evaluation time. The assumption is that time will never go backwards during the simulation and if it does then we should stop the run quickly.

Before we're able help with your issue, however, I think we'll need to know a little bit more about your model and possibly how you're using PYACTION. Would you be able to elaborate a little on this topic?

soulstealer-star commented 1 year ago

Hi,

I also met this error before. One of the most likely problems is if there is something wrong with your python code then he will give you timing errors like this. Maybe you can your python code to see if there is any error.

mtcanam commented 1 year ago

The python code is an empty block for now, as when it started failing I tried to eliminate that possibility first. The PYACTION is defined as:

PYACTION
    'WAG' 'SINGLE'
    '/path/to/python/script/WAG.py'

And code is:

import csv
def run(ecl_state, schedule, report_step, summary_state):
    return False

The intended use will be to read a csv file and open/close wells for a WAG schedule (we're using UDTs for it in Eclipse right now, but I wanted to implement in the same way for Flow to compare).

soulstealer-star commented 1 year ago

You can try the python code like this:

 import csv
 def run(ecl_state, schedule, report_step, summary_state,actionx_callback):
     return False
mtcanam commented 1 year ago

The revised code seems to have done the trick in terms of solving the error! It still seems I get this error when my Python script has normal coding errors in it, which could be a bit confusing for more complicated scripts. I think it would be helpful for the above to be in the manual if it's necessary -- unless I just missed it :)

bska commented 1 year ago

The revised code seems to have done the trick in terms of solving the error!

Very good, I'm happy to hear that and thanks a lot to @soulstealer-star for the suggestion. For what it's worth, the actionx_callback parameter was introduced into the development sources in PR OPM/opm-common#2939 and made its debut in a public version of the simulator in the April release of 2022–designation 2022.04, but it was never mentioned in the release notes for that release.

I think it would be helpful for the above to be in the manual if it's necessary

Yes, you're absolutely right. Wrong information in our documentation is worse than no information at all. I will see to it that our manual gets updated in time for the next release, tentatively scheduled for October of this year.

mtcanam commented 1 year ago

Just one additional question: is the schedule.open_well(well_name, report_step) command functional at this time? I'm having some mixed results from it currently. The shut_well seems to work well, and the flow stops, but opening wells that have been shut does not restart flow, and the WMCTL is -1 (parent level oil rate control) for a gas injector. Function below.

import csv
def run(ecl_state, schedule, report_step, summary_state, actionx_callback):
    try:
        cycle_id = {1:['NE2P1','NE2WI1','NE2WI1G'],
                    2:['NE2P2','NE2WI2','NE2WI2G'],
                    3:['NG2P1','NGF2WI1','NGF2WI1G'],
                    4:['NG3P1','NG3WI1','NG3WI1G'],
                    5:['NC2P1','NC2WI1','NC2WI1G'],
                    6:['VE2P1','VE2WI1','VE2WI1G'],
                    7:['VDJ2P1','VDJ2WI1','VDJ2WI1G'],
                    8:['NM2P1','NM2WI1','NM2WI1G']}

        with open('/private/mcana/Documents/opm/eclipse/include/schedule/wag_data.csv', encoding='utf-8') as csvfile:

            wag_list = list(csv.reader(csvfile, delimiter=','))

            month = int(summary_state['TIME'] / 30)
            curr_id = summary_state['FUWAGGI']
            next_id = int(wag_list[month+1][1])
            print('The current cycle is {}, and the next cycle is {}.'.format(curr_id, next_id))
            if curr_id != next_id:
                print('Switching cycle from {} to {}.'.format(curr_id, next_id))
                print('---> Opening {}'.format(cycle_id[next_id][2]))
                schedule.open_well(cycle_id[next_id][2], report_step)
                print('---> Closing {}'.format(cycle_id[next_id][1]))
                schedule.shut_well(cycle_id[next_id][1], report_step)
                print('---> Opening {}'.format(cycle_id[curr_id][1]))
                schedule.open_well(cycle_id[curr_id][1], report_step)
                print('---> Closing {}'.format(cycle_id[curr_id][2]))
                schedule.shut_well(cycle_id[curr_id][2], report_step)
                summary_state.update('FUWAGGI', next_id)

    except Exception as e:
        print(e)

    return False