Skip to content
58 changes: 45 additions & 13 deletions avaframe/com3Hybrid/com3Hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
# import config and init tools
import avaframe.in2Trans.shpConversion as shpConv
from avaframe.in3Utils import cfgUtils
from avaframe.in3Utils import cfgHandling
from avaframe.in3Utils import fileHandlerUtils as fU
from avaframe.in1Data import getInput
import avaframe.in3Utils.initializeProject as initProj

# import computation modules
from avaframe.com1DFA import com1DFA, particleTools
import avaframe.ana5Utils.DFAPathGeneration as DFAPath
from avaframe.com2AB import com2AB
from avaframe.com3Hybrid import com3Hybrid

# import analysis tools
from avaframe.out3Plot import outAB
Expand All @@ -41,11 +45,32 @@ def maincom3Hybrid(cfgMain, cfgHybrid):
"""
avalancheDir = cfgMain['MAIN']['avalancheDir']
demOri = getInput.readDEM(avalancheDir)
# get comDFA configuration path for hybrid model
hybridModelDFACfg = pathlib.Path('com3Hybrid', 'hybridModel_com1DFACfg.ini')

# setup outputs folder and work folder
workPath = pathlib.Path(avalancheDir, 'Work', 'com3Hybrid')
oPath = pathlib.Path(avalancheDir, 'Outputs', 'com3Hybrid')
fU.makeADir(workPath)
fU.makeADir(oPath)

# ++++++++++ set configurations for all the used modules and override ++++++++++++
# get comDFA configuration and save to file
com1DFACfg = cfgUtils.getModuleConfig(com1DFA, fileOverride='', modInfo=False, toPrint=False,
onlyDefault=cfgHybrid['com1DFA_override']['defaultConfig'])
com1DFACfg, cfgHybrid = cfgHandling.applyCfgOverride(com1DFACfg, cfgHybrid, com1DFA, addModValues=False)
com1DFACfgFile = cfgUtils.writeCfgFile(avalancheDir, com1DFA, com1DFACfg, fileName='com1DFA_settings', filePath=workPath)

# fetch configuration for DFAPathGeneration
DFAPathGenerationCfg= cfgUtils.getModuleConfig(DFAPath, fileOverride='', modInfo=False, toPrint=False,
onlyDefault=cfgHybrid['DFAPathGeneration_override']['defaultConfig'])
DFAPathGenerationCfg, cfgHybrid = cfgHandling.applyCfgOverride(DFAPathGenerationCfg, cfgHybrid, DFAPath, addModValues=False)

# first create configuration object for com2AB
com2ABCfg = cfgUtils.getModuleConfig(com2AB, fileOverride='', modInfo=False, toPrint=False,
onlyDefault=cfgHybrid['com1DFA_override']['defaultConfig'])
com2ABCfg, cfgHybrid = cfgHandling.applyCfgOverride(com2ABCfg, cfgHybrid, com2AB, addModValues=False)

# get initial mu value
muArray = np.array([cfgHybrid.getfloat('DFA', 'mu')])
muArray = np.array([cfgHybrid.getfloat('com1DFA_override', 'mu')])
alphaArray = np.array([np.degrees(np.arctan(muArray[0]))])

# prepare for iterating
Expand All @@ -54,21 +79,27 @@ def maincom3Hybrid(cfgMain, cfgHybrid):
iterate = True
resultsHybrid = {}
while iteration < nIterMax and iterate:
# update the com1DFA mu value
# update the com1DFA mu value in configuration file
updater = ConfigUpdater()
updater.read(hybridModelDFACfg)
updater.read(com1DFACfgFile)
updater['GENERAL']['mu'].value = ('%.4f' % muArray[-1])
updater.update_file()

log.info('Mu is set to: %f' % muArray[-1])
# ++++++++++ RUN COM1DFA +++++++++++
# Run dense flow with coulomb friction
dem, _, _, simDF = com1DFA.com1DFAMain(avalancheDir, cfgMain, cfgFile=hybridModelDFACfg)
# Clean input directory of old work and output files from module
initProj.cleanModuleFiles(avalancheDir, com1DFA, deleteOutput=False)
dem, _, _, simDF = com1DFA.com1DFAMain(avalancheDir, cfgMain, cfgFile=com1DFACfgFile)
simID = simDF.index[0]
particlesList, timeStepInfo = particleTools.readPartFromPickle(avalancheDir, simName=simID, flagAvaDir=True,
comModule='com1DFA')

# ++++++++++ GENERATE PATH +++++++++++
# postprocess to extract path and energy line
avaProfileMass = DFAPath.getDFAPathFromPart(particlesList, addVelocityInfo=True)
# make a copy because extendDFAPathKernel might modify avaProfileMass
avaProfileMassExt = DFAPath.extendDFAPath(cfgHybrid['PATH'], avaProfileMass.copy(), dem, particlesList[0])
avaProfileMassExt = DFAPath.extendDFAPath(DFAPathGenerationCfg['PATH'], avaProfileMass.copy(), dem, particlesList[0])
avaProfileMassExtOri = copy.deepcopy(avaProfileMassExt)
avaProfileMassExtOri['x'] = avaProfileMassExtOri['x'] + demOri['header']['xllcenter']
avaProfileMassExtOri['y'] = avaProfileMassExtOri['y'] + demOri['header']['yllcenter']
Expand All @@ -77,15 +108,13 @@ def maincom3Hybrid(cfgMain, cfgHybrid):
name = 'massAvaPath'
shpConv.writeLine2SHPfile(avaProfileMassExtOri, name, pathAB)

# Run Alpha Beta
hybridModelABCfg = pathlib.Path('com3Hybrid', 'hybridModel_com2ABCfg.ini')
cfgAB = cfgUtils.getModuleConfig(com2AB, fileOverride=hybridModelABCfg)
cfgAB['ABSETUP']['path2Line'] = str(pathAB) + '.shp'
# ++++++++++ RUN COM2AB +++++++++++
com2ABCfg['ABSETUP']['path2Line'] = str(pathAB) + '.shp'
# take the path extracted from the DFA model as input
pathDict, demAB, splitPoint, eqParams, resAB = com2AB.com2ABMain(cfgAB, avalancheDir)
pathDict, demAB, splitPoint, eqParams, resAB = com2AB.com2ABMain(com2ABCfg, avalancheDir)
# make AB plot
reportDictList = []
_, plotFile, writeFile = outAB.writeABpostOut(pathDict, demAB, splitPoint, eqParams, resAB, cfgAB, reportDictList)
_, plotFile, writeFile = outAB.writeABpostOut(pathDict, demAB, splitPoint, eqParams, resAB, com2ABCfg, reportDictList)

# make custom com3 profile plot
alpha = resAB[name]['alpha']
Expand Down Expand Up @@ -113,6 +142,9 @@ def maincom3Hybrid(cfgMain, cfgHybrid):
outCom3Plots.hybridProfilePlot(avalancheDir, resultsHybrid)
outCom3Plots.hybridPathPlot(avalancheDir, dem, resultsHybrid, fields[0], particlesList[-1], muArray)

# write com3HYbrid configuration settings to file for reproduction use
com3HybridCfgFile = cfgUtils.writeCfgFile(avalancheDir, com3Hybrid, cfgHybrid, fileName='com3Hybrid_settings', filePath=oPath)

log.debug('Alpha array is %s' % alphaArray)
log.debug('mu array is %s' % muArray)

Expand Down
90 changes: 80 additions & 10 deletions avaframe/com3Hybrid/com3HybridCfg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,99 @@ nIterMax = 4
alphaThreshold = 0.1


# settings for path finding (these setting are used for path generation, as set in ana5Utils/DFAPathGenerationCfg.ini)
[PATH]
[DFAPathGeneration_override]
# use default DFAPathGeneration config as base configuration (True) and override following parameters
# if False and local is available use local
defaultConfig = True
# the path extracted from the com1DFA simulation is re-sampled
# re-sampling step size is defined resampleDistance = nCellsResample x cellSize)
# this results in a path with a horizontal distance between points <= resampleDistance
nCellsResample = 5

# extension method at the top
# option 0: take the highest particle in the release
# option 1: find the point that will lead to the longest runout
extTopOption = 1

# for extending the path at the bottom, extend path towards the bottom of the runout in the
# direction extracted form the first/last points of the path (all points at a distance
# nCellsMinExtend x cellSize < distance < nCellsMaxExtend x cellSize from the start/end)
nCellsMinExtend = 2
nCellsMaxExtend = 20

# for the extrapolation at the bottom, add factBottomExt * sMax to the path
factBottomExt = 0.2
maxIterationExtBot = 10
nBottomExtPrecision = 10

[DFA]
# starting value for bottom bed friction
[com1DFA_override]
# use default com1DFA config as base configuration (True) and override following parameters
# if False and local is available use local
defaultConfig = True
#++++++++++++++++ Simulation type
# list of simulations that shall be performed (null, ent, res, entres, available (use all available input data))
simTypeList = null

#+++++++++++++ Output++++++++++++
# desired result Parameters (ppr, pft, pfv, pta, FT, FV, P, Vx, Vy, Vz, TA, particles) - separated by |
resType = particles
# saving time step, i.e. time in seconds (first and last time step are always saved)
# 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 = 0:5

#+++++Release thickness++++
# True if release thickness should be read from shapefile file; if False - relTh read from ini file
relThFromShp = False
# release thickness (only considered if relThFromShp=False)
relTh = 1
#+++++Entrainment thickness++++
# True if entrainment thickness should be read from shapefile file; if False - entTh read from ini file
entThFromShp = True
# entrainment thickness (only considered if entThFromShp=False)
entTh =

#++++++++++++Time stepping parameters
# to use a variable time step (time step depends on kernel radius)
sphKernelRadiusTimeStepping = True
# courant number if option cflTimeStepping is chosen.
# Upper time step limit coefficient if option sphKernelRadiusTimeStepping is chosen.
cMax = 0.02
# stopCriterion (based on massFlowing or kinEnergy)
stopCritType = massFlowing
# if based on massFlowing, specify the velocity threshold for flowing mass (m/s)
uFlowingThreshold = 0.0

#+++++++++++++SPH parameters
# SPH gradient option
# 0) No pressure gradients computed
# 1) SamosAT style (no reprojecion on the surface, dz = 0 and gz is used)
# 2) SamosAT done in the cartesian coord system (reprojecion on the surface, dz != 0 and g3 is used)
# 3) SamosAT but done in the local coord system (will hopefully allow us to add the earth pressure coef)
# and this time reprojecion on the surface, dz not 0 and g3 is used
sphOption = 2

#++++++++++++++++ Particles
# number of particles defined by: MPPDIR= mass per particle direct, MPPDH= mass per particles through release thickness,
# MPPKR= mass per particles through number of particles per kernel radius
massPerParticleDeterminationMethod = MPPKR

#+++++++++++++Flow model parameters+++++++++
# curvature acceleration coefficient
# take curvature term into account in the gravity acceleration term
# 0 if deactivated, 1 if activated
curvAcceleration = 0

#++++++++++++Friction model
# add the friction using an explicit formulation (1)
# 0 use an implicit method
explicitFriction = 1
# friction type (samosAT, Coulomb, Voellmy)
frictModel = Coulomb
#+++++++++++++General Friction parameters
# tan of bed friction angle used for: samosAT, Coulomb, Voellmy
mu = 0.4

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


[com2AB_override]
# use default com2AB config as base configuration (True) and override following parameters
# if False and local is available use local
defaultConfig = True
103 changes: 0 additions & 103 deletions avaframe/com3Hybrid/hybridModel_com1DFACfg.ini

This file was deleted.

14 changes: 0 additions & 14 deletions avaframe/com3Hybrid/hybridModel_com2ABCfg.ini

This file was deleted.

Loading