Load a deck and change a control
"""Load a deck, change one control from a date, see exactly what changed, write the deck back.
SPE1 produces at an oil target of 20,000 stb/d. From day 365 on the target drops to 10,000 stb/d:one dated ``ps.Adjust`` keeps the rest of the control (its BHP limit), ``m.control`` reads what isin force on a date, and ``m.diff`` lists every address the edit changed. The deck is written whole,the loaded schedule kept, with the new target at its date.
Flow keywords it exercises: the whole of SPE1 (a three-phase black oil with dissolved gas: PVTO,PVDG, SGOF, EQUIL with RSVD), plus WELTARG at the new date.
Run it with ``python examples/load_and_edit.py [DECK]``. DECK defaults to SPE1 in the opm-testscorpus at ``opm-tests/`` (``git clone https://github.com/OPM/opm-tests``); it writes``out/load_and_edit/``."""
import datetimeimport sys
import petroscript as ps
path = sys.argv[1] if len(sys.argv) > 1 else "opm-tests/spe1/SPE1CASE1.DATA"WELL = "PROD" # SPE1's producer; name another deck'sm = ps.load(path)print(m.name, "starts", m.start, "with wells", [well.name for well in m.wells])
one_year = m.start + datetime.timedelta(days=365) # m.start is a datetime.dateprint("in force on", one_year, ":", m.control(WELL, at=one_year))
edited = m.at(one_year, ps.Adjust(well=WELL, oil_rate=10_000.0))for change in m.diff(edited): # address, before, after print(change.address, change.before, "->", change.after)
deck = ps.compile(edited)deck.write("out/load_and_edit")
if ps.simulators(): run = deck.run(folder="out/load_and_edit/run") oil = run.wells("oil_production_rate").filter(well=WELL) day = oil["date"].dt.date() before = oil.filter(day <= one_year)["value"].max() # the steps that end by the date after = oil.filter(day > one_year)["value"].max() unit = oil["unit"][-1] print(f"{WELL} oil rate: {before:.0f} {unit} before {one_year}, " f"at most {after:.0f} {unit} from it")else: print("no simulator found (set PETROSCRIPT_FLOW, or put flow on PATH); the deck is in " "out/load_and_edit")PetroScript is licensed under the Apache License 2.0. © 2026 Blauweiss EDV LLC. PetroScript by Blauweiss AI.For AI agents: llms.txt