Skip to content

Commit

Permalink
Allow users without ert-configuration to run ert with FLOW simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Aug 15, 2024
1 parent 83ec3c4 commit 6806191
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/ert/plugins/hook_implementations/forward_model_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,20 @@ def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="simulators.reservoir",
examples="""
The version, number of cpu and whether or not to ignore errors can
be configured in the configuration file when adding the job, as such:
.. code-block:: bash
FORWARD_MODEL FLOW(<ECLBASE>, <VERSION>=xxxx, <OPTS>="--ignore-errors")
FORWARD_MODEL FLOW(<ECLBASE>, <OPTS>="--ignore-errors")
The :code:`OPTS` argument is optional and can be removed, thus running flow
without ignoring errors.
ERT will be able to run with flow only if OPM FLOW simulator is installed and available
in the user $PATH environment varaible.
Currently ERT does not support changing the default options for the flow simulator.
""",
description="""
Forward model for OPM Flow
""",
description="""Forward model for OPM Flow simulator""",
)


Expand Down
23 changes: 23 additions & 0 deletions src/ert/resources/forward-models/res/script/ecl_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import re
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional

import yaml
Expand Down Expand Up @@ -203,8 +205,29 @@ class FlowConfig(EclConfig):

def __init__(self):
config_file = os.getenv("FLOW_SITE_CONFIG", default=self.DEFAULT_CONFIG_FILE)
if not Path(config_file).exists():
config_file = self.init_flow_config()
super().__init__(config_file, simulator_name="flow")

@staticmethod
def init_flow_config() -> str:
binary_path = shutil.which("flow")
if binary_path is None:
raise FileNotFoundError(
"Could not find flow executable!\n"
" Requires flow to be installed in $PATH"
)

conf = {
"default_version": "default",
"versions": {"default": {"scalar": {"executable": binary_path}}},
}
flow_config_yml = Path("flow_config.yml")
flow_config_yml.write_text(yaml.dump(conf), encoding="utf-8")
flow_config_path = str(flow_config_yml.absolute())
os.environ["FLOW_SITE_CONFIG"] = flow_config_path
return flow_config_path


class EclrunConfig:
"""This class contains configurations for using the new eclrun binary
Expand Down

0 comments on commit 6806191

Please sign in to comment.