Skip to content
Open
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
6 changes: 4 additions & 2 deletions avaframe/ana5Utils/distanceTimeAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def extractFrontAndMeanValuesTT(cfgRangeTime, flowF, demHeader, mtiInfo):
return mtiInfo


def initializeRangeTime(modName, cfg, dem, simHash):
def initializeRangeTime(modName, cfg, dem, simHash, configDir):
""" initialize generation of range-time diagram for visualizing simulation data

Parameters
Expand All @@ -572,6 +572,8 @@ def initializeRangeTime(modName, cfg, dem, simHash):
dictionary with DEM header and data
simHash: str
unique simulation ID
configDir: str or pathlib path
path to configuration directory - optional if not provided has to be empty string

Returns
--------
Expand All @@ -583,7 +585,7 @@ def initializeRangeTime(modName, cfg, dem, simHash):
"""

# fetch configuration and add info
cfgRangeTime = cfgUtils.getModuleConfig(modName)
cfgRangeTime = cfgUtils.getModuleConfig(modName, configDir)

cfgRangeTime['GENERAL']['tEnd'] = cfg['GENERAL']['tEnd']
cfgRangeTime['GENERAL']['avalancheDir'] = cfg['GENERAL']['avalancheDir']
Expand Down
3 changes: 2 additions & 1 deletion avaframe/avaframeCfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[MAIN]
# Path to avalanche directory
avalancheDir = data/avaParabola

# OPTIONAL Path to configuration file directory
configurationDir =
# number of CPU cores to use for the computation of com1DFA
# possible values are:
# - auto -> takes up to CPUPercent (see below) % of the available CPU cores
Expand Down
26 changes: 16 additions & 10 deletions avaframe/com1DFA/com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def com1DFAPreprocess(cfgMain, typeCfgInfo, cfgInfo):

# read initial configuration
if typeCfgInfo in ["cfgFromFile", "cfgFromDefault"]:
cfgStart = cfgUtils.getModuleConfig(com1DFA, fileOverride=cfgInfo, toPrint=False)
cfgStart = cfgUtils.getModuleConfig(com1DFA, cfgMain['MAIN']['configurationDir'], fileOverride=cfgInfo, toPrint=False)
elif typeCfgInfo == "cfgFromObject":
cfgStart = cfgInfo

Expand Down Expand Up @@ -167,7 +167,7 @@ def com1DFAMain(cfgMain, cfgInfo=""):
nCPU = cfgUtils.getNumberOfProcesses(cfgMain, len(simDict))

# Supply compute task with inputs
com1DFACoreTaskWithInput = partial(com1DFACoreTask, simDict, inputSimFiles, avalancheDir, outDir)
com1DFACoreTaskWithInput = partial(com1DFACoreTask, simDict, inputSimFiles, cfgMain, outDir)

# Create parallel pool and run
# with multiprocessing.Pool(processes=nCPU) as pool:
Expand Down Expand Up @@ -200,11 +200,13 @@ def com1DFAMain(cfgMain, cfgInfo=""):
return 0, {}, [], ""


def com1DFACoreTask(simDict, inputSimFiles, avalancheDir, outDir, cuSim):
def com1DFACoreTask(simDict, inputSimFiles, cfgMain, outDir, cuSim):
"""This is a subdivision of com1DFAMain to allow for parallel execution.
Please read this in the context of the com1DFAMain function.
"""

avalancheDir = cfgMain['MAIN']['avalancheDir']

simDF = pd.DataFrame()
tCPUDF = pd.DataFrame()

Expand Down Expand Up @@ -232,7 +234,7 @@ def com1DFACoreTask(simDict, inputSimFiles, avalancheDir, outDir, cuSim):
cfgFinal,
tCPU,
particlesList,
) = com1DFA.com1DFACore(cfg, avalancheDir, cuSim, inputSimFiles, outDir, simHash=simHash)
) = com1DFA.com1DFACore(cfg, cfgMain, cuSim, inputSimFiles, outDir, simHash=simHash)

simDF.at[simHash, "nPart"] = str(int(particlesList[0]["nPart"]))

Expand Down Expand Up @@ -323,7 +325,7 @@ def com1DFAPostprocess(simDF, tCPUDF, simDFExisting, cfgMain, dem, reportDictLis
return dem, plotDict, reportDictList, simDFNew


def com1DFACore(cfg, avaDir, cuSimName, inputSimFiles, outDir, simHash=""):
def com1DFACore(cfg, cfgMain, cuSimName, inputSimFiles, outDir, simHash=""):
"""Run main com1DFA model

This will compute a dense flow avalanche with the settings specified in cfg and the name cuSimName
Expand All @@ -332,12 +334,12 @@ def com1DFACore(cfg, avaDir, cuSimName, inputSimFiles, outDir, simHash=""):
----------
cfg : configparser object
configuration object for simulation to be performed
cfgMain: configparser object
main configuration of AvaFrame used here: avalancheDir, configurationDir
cuSimName: str
name of simulation
inputSimFiles: dict
dictionary with input files, release scenario chosen according to inputSimFiles['releaseScenario']
avaDir : str or pathlib object
path to avalanche directory
outDir: str or pathlib object
path to Outputs
simHash: str
Expand All @@ -359,6 +361,8 @@ def com1DFACore(cfg, avaDir, cuSimName, inputSimFiles, outDir, simHash=""):
list of particle dictionaries for all saving time steps
"""

avaDir = cfgMain['MAIN']['avalancheDir']

# select release area input data according to chosen release scenario
inputSimFiles = gI.selectReleaseFile(inputSimFiles, cfg["INPUT"]["releaseScenario"])

Expand Down Expand Up @@ -388,7 +392,7 @@ def com1DFACore(cfg, avaDir, cuSimName, inputSimFiles, outDir, simHash=""):
# ------------------------
# Start time step computation
Tsave, particlesList, fieldsList, infoDict = DFAIterate(
cfg, particles, fields, dem, inputSimLines, simHash=simHash
cfg, particles, fields, dem, inputSimLines, cfgMain['MAIN']['configurationDir'], simHash=simHash
)

# write mass balance to File
Expand Down Expand Up @@ -1657,7 +1661,7 @@ def initializeResistance(cfg, dem, simTypeActual, resLine, reportAreaInfo, thres
return cResRaster, detRaster, reportAreaInfo


def DFAIterate(cfg, particles, fields, dem, inputSimLines, simHash=""):
def DFAIterate(cfg, particles, fields, dem, inputSimLines, configDir, simHash=""):
"""Perform time loop for DFA simulation
Save results at desired intervals

Expand All @@ -1676,6 +1680,8 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, simHash=""):
dictionary with dem information
inputSimLines : dict
dictionary with input data dictionaries (releaseLine, entLine, ...)
configDir: str or pathlib Path
path to configuration directory - optional if not provided has to be empty string

Returns
-------
Expand Down Expand Up @@ -1762,7 +1768,7 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, simHash=""):
# check if range-time diagram should be performed, if yes - initialize
if cfg["VISUALISATION"].getboolean("createRangeTimeDiagram"):
demRT = dtAna.setDemOrigin(dem)
mtiInfo, dtRangeTime, cfgRangeTime = dtAna.initializeRangeTime(dtAna, cfg, demRT, simHash)
mtiInfo, dtRangeTime, cfgRangeTime = dtAna.initializeRangeTime(dtAna, cfg, demRT, simHash, configDir)
# fetch initial time step too
mtiInfo, dtRangeTime = dtAna.fetchRangeTimeInfo(
cfgRangeTime, cfg, dtRangeTime, t, demRT["header"], fields, mtiInfo
Expand Down
3 changes: 2 additions & 1 deletion avaframe/com1DFA/com1DFATools.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def createSimDictFromCfgs(cfgMain, cfgPath):
# loop over all cfgFiles and create simDict
for index, cfgFile in enumerate(cfgFilesAll):
# read configuration
cfgFromFile = cfgUtils.getModuleConfig(com1DFA, fileOverride=cfgFile, toPrint=False)
# configDir is set to '' because fileOverride is provided
cfgFromFile = cfgUtils.getModuleConfig(com1DFA, '', fileOverride=cfgFile, toPrint=False)

# create dictionary with one key for each simulation that shall be performed
# NOTE: sims that are added don't need to be added to the simNameExisting list as
Expand Down
8 changes: 8 additions & 0 deletions avaframe/in3Utils/cfgHandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ def rewriteLocalCfgs(cfgFull, avalancheDir, localCfgPath=''):
optional - path to directory to store local_ cfg ini file to
if not provided - local_ cfg ini file is saved to avalanche directory

Returns
--------
locFilePath: pathlib Path
path to directory where local configuration files are written to derived from override sections

"""

# if a path is provided - save local cfg ini file there
Expand Down Expand Up @@ -576,6 +581,7 @@ def rewriteLocalCfgs(cfgFull, avalancheDir, localCfgPath=''):

cfgModule = cfgUtils.getModuleConfig(
cfgNamePath,
'',
fileOverride="",
modInfo=False,
toPrint=False,
Expand Down Expand Up @@ -606,6 +612,8 @@ def rewriteLocalCfgs(cfgFull, avalancheDir, localCfgPath=''):

log.info("%s CONFIGURATION wrote to %s" % (cfgName, str(cfgF)))

return locFilePath


def _removeCfgItemsNotInOverride(cfgModule, overrideKeys):
""" remove options of cfgModule if not part of overrideKeys
Expand Down
Loading