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 Jul 17, 2024
1 parent a22daa8 commit c2be884
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/ert/shared/share/ert/forward-models/res/script/ecl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import subprocess
import sys
from typing import Any, Dict, List, Optional

from pathlib import Path
import platform
import shutil
import yaml


Expand Down Expand Up @@ -203,8 +205,39 @@ 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."""
rhel_version = "7"
if "el8" in platform.release():
rhel_version = "8"
candidates = ["flow",
f"/project/res/x86_64_RH_{rhel_version}/bin/flowdaily"]
for candidate in candidates:
foundpath = shutil.which(candidate)
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 c2be884

Please sign in to comment.