Skip to content
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
95 changes: 54 additions & 41 deletions avaframe/com1DFA/com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,8 +1658,11 @@ def initializeFields(cfg, dem, particles, releaseLine):
cfgGen = cfg["GENERAL"]
# what result types are desired as output (we need this to decide which fields we actually need to compute)
resTypes = fU.splitIniValueToArraySteps(cfgGen["resType"])
resTypesReport = fU.splitIniValueToArraySteps(cfg["REPORT"]["plotFields"])
resTypesLast = list(set(resTypes + resTypesReport))
# ensure at least one field type is present for internal computations
# if resTypes only contains particles add pfv
validFieldTypes = [rt for rt in resTypes if rt not in ["particles"]]
if len(validFieldTypes) == 0:
resTypes.append("pfv")
# read dem header
header = dem["header"]
ncols = header["ncols"]
Expand All @@ -1684,7 +1687,7 @@ def initializeFields(cfg, dem, particles, releaseLine):
fields["timeInfo"] = np.zeros((nrows, ncols)) # first time
# for optional fields, initialize with dummys (minimum size array). The cython functions then need something
# even if it is empty to run properly
if ("TA" in resTypesLast) or ("pta" in resTypesLast):
if ("TA" in resTypes) or ("pta" in resTypes):
fields["pta"] = np.zeros((nrows, ncols)) # peak travel angle [°]
fields["TA"] = np.zeros((nrows, ncols)) # travel angle [°]
fields["computeTA"] = True
Expand All @@ -1693,14 +1696,14 @@ def initializeFields(cfg, dem, particles, releaseLine):
fields["pta"] = np.zeros((1, 1))
fields["TA"] = np.zeros((1, 1))
fields["computeTA"] = False
if "pke" in resTypesLast:
if "pke" in resTypes:
fields["pke"] = np.zeros((nrows, ncols)) # peak kinetic energy [kJ/m²]
fields["computeKE"] = True
log.debug("Computing Kinetic energy")
else:
fields["pke"] = np.zeros((1, 1))
fields["computeKE"] = False
if ("P" in resTypesLast) or ("ppr" in resTypesLast):
if ("P" in resTypes) or ("ppr" in resTypes):
fields["P"] = np.zeros((nrows, ncols)) # pressure [kPa]
fields["ppr"] = np.zeros((nrows, ncols)) # peak pressure [kPa]
fields["computeP"] = True
Expand Down Expand Up @@ -2038,10 +2041,11 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
# add particles to the results type if trackParticles option is activated
if cfg.getboolean("TRACKPARTICLES", "trackParticles"):
resTypes = list(set(resTypes + ["particles"]))
# make sure to save all desiered resuts for first and last time step for
# the report
resTypesReport = fU.splitIniValueToArraySteps(cfg["REPORT"]["plotFields"])
resTypesLast = list(set(resTypes + resTypesReport))
# ensure at least one field type is present for internal computations
# if resTypes only contains particles, add pfv
validFieldTypes = [rt for rt in resTypes if rt not in ["particles"]]
if len(validFieldTypes) == 0:
resTypes.append("pfv")
# derive friction type
# turn friction model into integer
frictModelsList = [
Expand Down Expand Up @@ -2080,7 +2084,7 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
pfvTimeMax = []

# setup a result fields info data frame to save max values of fields and avalanche front
resultsDF = setupresultsDF(resTypesLast, cfg["VISUALISATION"].getboolean("createRangeTimeDiagram"))
resultsDF = setupresultsDF(resTypes, cfg["VISUALISATION"].getboolean("createRangeTimeDiagram"))

# Add different time stepping options here
log.debug("Use standard time stepping")
Expand All @@ -2094,15 +2098,27 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
t = particles["t"]
log.debug("Saving results for time step t = %f s", t)

# export initial time step
if cfg["EXPORTS"].getboolean("exportData"):
# Initialize particles output directory if needed
if "particles" in resTypes:
outDirData = outDir / "particles"
fU.makeADir(outDirData)

# Save original dtSave for initial timestep decisions
dtSaveOriginal = dtSave.copy()

# export initial time step only if t=0 is explicitly in dtSaveOriginal
if cfg["EXPORTS"].getboolean("exportData") and (
dtSaveOriginal.size > 0 and np.any(dtSaveOriginal <= 1.0e-8)
):
exportFields(cfg, t, fields, dem, outDir, cuSimName, TSave="initial")

if "particles" in resTypes:
outDirData = outDir / "particles"
fU.makeADir(outDirData)
savePartToPickle(particles, outDirData, cuSimName)

# Update dtSave to remove the initial timestep we just saved
dtSave = updateSavingTimeStep(dtSaveOriginal, cfgGen, t)


# export particles properties for visulation
if cfg["VISUALISATION"].getboolean("writePartToCSV"):
particleTools.savePartToCsv(
Expand All @@ -2128,8 +2144,12 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
)
cfgRangeTime["GENERAL"]["simHash"] = simHash

# add initial time step to Tsave array
Tsave = [0]
# add initial time step to Tsave array only if it was exported
if dtSaveOriginal.size > 0 and np.any(dtSaveOriginal <= 1.0e-8):
Tsave = [0]
else:
Tsave = []

# derive time step for first iteration
if cfgGen.getboolean("sphKernelRadiusTimeStepping"):
dtSPHKR = tD.getSphKernelRadiusTimeStep(dem, cfgGen)
Expand Down Expand Up @@ -2166,7 +2186,7 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
rangeValue = mtiInfo["rangeList"][-1]
else:
rangeValue = ""
resultsDF = addMaxValuesToDF(resultsDF, fields, t, resTypesLast, rangeValue=rangeValue)
resultsDF = addMaxValuesToDF(resultsDF, fields, t, resTypes, rangeValue=rangeValue)

tCPU["nSave"] = nSave
particles["t"] = t
Expand Down Expand Up @@ -2348,25 +2368,19 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si
# export particles dictionaries of saving time steps
if "particles" in resTypes:
savePartToPickle(particles, outDirData, cuSimName)
else:
# fetch contourline info

# save contour line for each sim only if the field is properly computed (not a dummy array)
contourResType = cfg["VISUALISATION"]["contourResType"]
if fields[contourResType].shape != (1, 1):
contourDictXY = outCom1DFA.fetchContCoors(
dem["header"],
fields[cfg["VISUALISATION"]["contourResType"]],
fields[contourResType],
cfg["VISUALISATION"],
cuSimName,
)

# save contour line for each sim
contourDictXY = outCom1DFA.fetchContCoors(
dem["header"],
fields[cfg["VISUALISATION"]["contourResType"]],
cfg["VISUALISATION"],
cuSimName,
)
outDirDataCont = outDir / "contours"
fU.makeADir(outDirDataCont)
saveContToPickle(contourDictXY, outDirDataCont, cuSimName)
outDirDataCont = outDir / "contours"
fU.makeADir(outDirDataCont)
saveContToPickle(contourDictXY, outDirDataCont, cuSimName)

# export particles properties for visulation
if cfg["VISUALISATION"].getboolean("writePartToCSV"):
Expand Down Expand Up @@ -2406,7 +2420,7 @@ def setupresultsDF(resTypes, cfgRangeTime):
# TODO catch empty resTypes
resDict = {"timeStep": [0.0]}
for resT in resTypes:
if resT != "particles" and resT != "FTDet":
if resT != "particles":
resDict["max" + resT] = [0.0]
if cfgRangeTime:
resDict["rangeList"] = [0.0]
Expand Down Expand Up @@ -2440,11 +2454,12 @@ def addMaxValuesToDF(resultsDF, fields, timeStep, resTypes, rangeValue=""):

newLine = []
for resT in resTypes:
if resT != "particles" and resT != "FTDet":
if resT != "particles":
newLine.append(np.nanmax(fields[resT]))

if rangeValue != "":
newLine.append(rangeValue)

resultsDF.loc[timeStep] = newLine

return resultsDF
Expand Down Expand Up @@ -2973,17 +2988,15 @@ def exportFields(
"""

resTypesGen = fU.splitIniValueToArraySteps(cfg["GENERAL"]["resType"])
resTypesReport = fU.splitIniValueToArraySteps(cfg["REPORT"]["plotFields"])
if "particles" in resTypesGen:
resTypesGen.remove("particles")
if "particles" in resTypesReport:
resTypesReport.remove("particles")

if TSave == "final" or TSave == "initial":
# for last time step we need to add the report fields
resTypes = list(set(resTypesGen + resTypesReport))
else:
resTypes = resTypesGen
resTypes = resTypesGen
# ensure at least one field type is present for export
# if resTypes only contains FTDet or is empty, add pfv
validFieldTypes = [rt for rt in resTypes if rt != "particles"]
if len(validFieldTypes) == 0:
resTypes.append("pfv")

if resTypesForced != []:
resTypes = resTypesForced
Expand Down
18 changes: 4 additions & 14 deletions avaframe/com1DFA/com1DFACfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ modelType = dfa
#+++++++++++++ Output++++++++++++
# desired result Parameters (ppr, pft, pfv, pta, FT, FV, P, FM, Vx, Vy, Vz, TA, dmDet, sfcChange, demAdapted, timeInfo, particles) - separated by |
resType = ppr|pft|pfv|timeInfo
# saving time step, i.e. time in seconds (first and last time step are always saved)
# saving time step, i.e. time in seconds (last time step is always saved; initial time step only if explicitly specified)
# option 1: give an interval with start:interval in seconds (tStep = 0:5 - this will save desired results every 5 seconds for the full simulation)
# option 2: explicitly list all desired time steps (closest to actual computational time step) separated by | (example tSteps = 1|50.2|100)
# NOTE: initial and last time step are always saved!
tSteps = 1
# option 2: explicitly list all desired time steps (closest to actual computational time step) separated by | (example tSteps = 1|50.2|100 or tSteps = 0|5|10 to include initial timestep)
# NOTE: last time step is always saved! Initial timestep (t=0) is only saved if explicitly included in tSteps
tSteps =

#++++++++++++++++ particle Initialisation +++++++++
# initial particle distribution, options: random, semirandom, uniform, triangular
Expand Down Expand Up @@ -544,16 +544,6 @@ releaseScenario =
# important for parameter variation through probRun
thFromIni =


[REPORT]
# which result parameters shall be included as plots in report - separated by |
plotFields = ppr|pft|pfv
# units for output variables
unitppr = kPa
unitpft = m
unitpfv = ms-1


[EXPORTS]
# peak files and plots are exported, option to turn off exports when exportData is set to False
# this affects export of peak files and also generation of peak file plots
Expand Down
3 changes: 0 additions & 3 deletions avaframe/com3Hybrid/com3HybridCfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ frictModel = Coulomb
# tan of bed friction angle used for: samosAT, Coulomb, Voellmy
mucoulomb = 0.4

# which result parameters shall be included as plots in report, - separated by |
plotFields = ppr|pft|pfv|TA|pta


[com2AB_com2AB_override]
# use default com2AB config as base configuration (True) and override following parameters
Expand Down
3 changes: 0 additions & 3 deletions avaframe/com6RockAvalanche/com6RockAvalancheCfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,3 @@ frictModel = Voellmy
#+++++++++++++Voellmy friction model
muvoellmy = 0.035
xsivoellmy = 700.

# which result parameters shall be included as plots in report, - separated by |
plotFields = pfv|pft|FT
3 changes: 0 additions & 3 deletions avaframe/in3Utils/fileHandlerUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,6 @@ def splitTimeValueToArrayInterval(cfgValues, endTime):
items = np.array(itemsL, dtype=float)
items = np.sort(items)

# make sure that 0 is not in the array (initial time step is any ways saved)
if items[0] == 0:
items = np.delete(items, 0)
# make sure the array is not empty
# ToDo : make it work without this arbitrary 2*timeEnd
if items.size == 0:
Expand Down
4 changes: 2 additions & 2 deletions avaframe/log2Report/generateReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def writeReport(outDir, reportDictList, reportOneFile, plotDict='', standaloneRe
# Loop through all simulations
for reportD in reportDictList:

if plotDict != '' and ('simName' in reportD):
if plotDict != '' and ('simName' in reportD) and (reportD['simName']['name'] in plotDict):
# add plot info to general report Dict
reportD['Simulation Results'] = plotDict[reportD['simName']['name']]
reportD['Simulation Results'].update({'type': 'image'})
Expand All @@ -222,7 +222,7 @@ def writeReport(outDir, reportDictList, reportOneFile, plotDict='', standaloneRe
# Loop through all simulations
for reportD in reportDictList:

if plotDict != '':
if plotDict != '' and (reportD['simName']['name'] in plotDict):
# add plot info to general report Dict
reportD['Simulation Results'] = plotDict[reportD['simName']['name']]
reportD['Simulation Results'].update({'type': 'image'})
Expand Down
Loading
Loading