Skip to content

Commit

Permalink
Allow users without equilibrium to run ert with FLOW simulator.
Browse files Browse the repository at this point in the history
Create flow_config.yml config file if it is not found in the env variables.
  • Loading branch information
DanSava committed Aug 12, 2024
1 parent 9ccd528 commit ffa6632
Show file tree
Hide file tree
Showing 2 changed files with 35 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
27 changes: 27 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,33 @@ 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 locate_flow_binary() -> str:
"""Locate the path for a flow executable.
Returns the empty string if there is nothing to be found in $PATH."""
foundpath = shutil.which("flow")
if foundpath is not None:
return foundpath
return ""

@staticmethod
def init_flow_config() -> str:
binary_path = FlowConfig.locate_flow_binary()
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 ffa6632

Please sign in to comment.