Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wanghy/farm gamma validators #175

Merged
merged 17 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Placeholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def read_input(self, xml):
# magic word for "relative to HERON root"
heron_path = hutils.get_heron_loc()
self._target_file = os.path.abspath(self._source.replace('%HERON%', heron_path))
elif self._source.startswith('%FARM%'):
# magic word for "relative to FARM root"
farm_path = hutils.get_farm_loc()
self._target_file = os.path.abspath(self._source.replace('%FARM%', farm_path))
else:
# check absolute path
rel_interp = os.path.abspath(os.path.join(self._workingDir, self._source))
Expand Down
17 changes: 16 additions & 1 deletion src/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ def get_cashflow_loc(raven_path=None):
"""
if raven_path is None:
raven_path = get_raven_loc()
plugin_handler_dir = path.join(raven_path, '..', 'scripts')
plugin_handler_dir = path.join(raven_path, 'scripts')
sys.path.append(plugin_handler_dir)
plugin_handler = importlib.import_module('plugin_handler')
sys.path.pop()
cf_loc = plugin_handler.getPluginLocation('TEAL')
return cf_loc

def get_farm_loc(raven_path=None): # Added by Haoyu Wang, May 25, 2022
"""
Get FARM location in installed RAVEN
@ In, raven_path, string, optional, if given then start with this path
@ Out, cf_loc, string, location of CashFlow
"""
if raven_path is None:
raven_path = get_raven_loc()
plugin_handler_dir = path.join(raven_path, 'scripts')
sys.path.append(plugin_handler_dir)
plugin_handler = importlib.import_module('plugin_handler')
sys.path.pop()
farm_loc = plugin_handler.getPluginLocation('FARM')
return farm_loc

def get_all_resources(components):
"""
Provides a set of all resources used among all components
Expand Down
21 changes: 21 additions & 0 deletions src/validators/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@
# ALL RIGHTS RESERVED

from .ExampleValidator import Example
import os
import sys

# set up path of raven
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import _utils as hutils
raven_path = hutils.get_raven_loc()

# set up path of farm
farm_loc = hutils.get_farm_loc(raven_path=raven_path)
if farm_loc is not None:
farm_path = os.path.abspath(os.path.join(farm_loc))
sys.path.append(farm_path)
from FARM.src.FARMValidatorsForHeron import FARM_Beta, FARM_Gamma_LTI, FARM_Gamma_FMU

# default known validators
known = {
'Example': Example,
# ModelicaGoverner: TODO,
}

# add farm validators to the known dictionary
if farm_loc is not None:
known['FARM_Beta'] = FARM_Beta
known['FARM_Gamma_LTI'] = FARM_Gamma_LTI
known['FARM_Gamma_FMU'] = FARM_Gamma_FMU

def get_class(typ):
"""
Returns the requested dispatcher type.
Expand Down