from ...conesFunctions import printCones
from ..conesParams import conesParams
from ...conesErrors import conesPathNotFound
from .conesSettingsAbstract import conesSettingsAbstract
import sys
[docs]
class conesSettings_OF(conesSettingsAbstract):
"""
A class that groups settings for cones
"""
def __init__(self, case_path, model, nens, n_model_procs):
""" Initialize the class
:parameter case_path: the path of the source OpenFOAM case
:type case_path: str
:param model: the coupled model, always 'OF' for this settings class
:type model: str
:param nens: the number of ensemble members
:type nens: int
:param n_model_procs: the number of processors used by each OpenFOAM simulation
:type n_model_procs: int
"""
super(conesSettings_OF, self).__init__(case_path, model, nens, n_model_procs)
self.controlDict = self.case_path + "system/controlDict"
self.conesDict = self.case_path + "system/conesDict"
self.obs_file = self.case_path + self.get_option("obsFile", self.conesDict)
self.checkPath(self.obs_file)
self.global_cells = self.setGlobalCells()
self.local_cells = self.setLocalCells()
self.regions = []
self.globalStateCells = []
self.localStateCells = []
self.stateVar = self.get_option("stateVar", self.conesDict)
self.obs_var = self.get_option("obsVar", self.conesDict)
self.obs_dof = len(self.obs_var)
self.nParams = int(self.get_option("numberParameters", self.conesDict))
self.stateEstSwitch = self.get_option("stateEstSwitch", self.conesDict) == "true"
self.paramEstSwitch = self.get_option("paramEstSwitch", self.conesDict) == "true"
self.inflationType = self.get_option("inflationType", self.conesDict)
self.stateInflation = float(self.get_option("stateInflation", self.conesDict))
self.parametersInflation = float(self.get_option("parametersInflation", self.conesDict))
self.stateCovarianceLocalisation = self.get_option("stateCovarianceLocalisation", self.conesDict) == "true"
if (self.stateCovarianceLocalisation):
self.localisationLength = float(self.get_option("localisationLength", self.conesDict))
# This is provisional and not used yet
self.params = []
for i in range(0, self.nParams):
self.params.append(conesParams())
# We get clips by default
self.Clips = self.get_clippings() # self.get_Global_clippings()
# We merge those clips that shares cells
self.mergedClips = self.mergeClips()
self.obsWindow = int(self.get_option("observationWindow", self.conesDict))
self.obsType = self.get_option("obsType", self.conesDict) or "instantaneous"
_oaw = self.get_option("obsAverageWindow", self.conesDict)
self.obsAverageWindow = int(_oaw) if _oaw else self.obsWindow
self.endTimeSim = float(self.get_option("endTime", self.controlDict))
self.deltaTSim = float(self.get_option("deltaT", self.controlDict))
self.total_it = int(self.endTimeSim / (self.obsWindow * self.deltaTSim))
mda_iterations_opt = self.get_option("mdaIterations", self.conesDict)
self.mda_iterations = int(mda_iterations_opt) if mda_iterations_opt else 1
return
[docs]
def get_option(self, keyword, dictionary):
""" A function to get options in an OpenFOAM dictionary
:param keyword: the name of the option to get
:type keyword: str
:param dictionary: the name of the dictionary that contains the keyword
:type dictionary: str
:returns: The value set for the keyword
"""
value = str()
# Check file exist
try:
self.checkPath(dictionary)
except conesPathNotFound as e:
print(e, file=sys.stderr)
if (self.verbose):
printCones(" Looking for", keyword, "in", dictionary)
with open(dictionary, 'r') as file:
lines = file.readlines()
for line in lines:
# if the line contains the keyword
if line.find(keyword) != -1:
# if the keyword is an option and not an entry
if line.strip().replace(';', '').split(" ")[0] == keyword:
value = line.strip().replace(';', '').split(" ")[-1]
if (value[0] == "\""):
value = value[1:-1]
if (self.verbose):
printCones("Found ", keyword, " = ", value)
return value