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
121 stars 121 forks source link

PYACTION shut.well #4813

Open soulstealer-star opened 1 year ago

soulstealer-star commented 1 year ago

Hi,

I am now trying to use schedule.shut_well to shut down the well. And I set to shut the well for very report step. However, when see the results in ResInsight, it shows that only in the first few steps the well is turned off, after that the wells are turned on, is there any reason for this?

My PYACTION code is:

def run(ecl_state, schedule, report_step, summary_state,actionx_callback):
    shut=False
    for well in summary_state.wells:
        schedule.shut_well(well, report_step)
        shut=True

    return shut    #MUST HAVE THE RETURN

And the deck for PYACTION part is:

PYACTION
    'shuttest'  'UNLIMITED' /
    'shuttest.py' /
blattms commented 9 months ago

@soulstealer-star I came across this when reviewing our release note.

My general recommendation would be to never directly modify wells (or other parts of the Schedule) via PYACTION as the simulator may miss this. For many of these changes the simulator will need to react somehow. This will not happen if we just modify the schedule.

The recommended way to change the schedule would be to do these changes to via a "dummy" ACTIONX statement that is otherwise never executed. When the ACTIONX is run the simulator will be modified of this (well, unless there is a bug).

You will find an example for this in section 3.3 of an old ACTIONX/PYACTION documentation and I outline it below.

You have an actionx that is never run and closes all matching wells

ACTIONX
CLOSEWELLS 0 / -- Action never run automatically
/
WELOPEN
’?’ ’CLOSE’ / -- close all matching wells
/
ENDACTIO

and call that one from your python code:

def run(ecl_state, schedule, report_step, summary_state, actionx_callback):
  close_wells = []
  for well in summary_state.wells:
    if summary_state.well_var(well, ’WOPR’) < 1000:
      close_wells.append(well)
  if close_wells:
    actionx_callback(’CLOSEWELLS’, close_wells)