cfg = cfgUtils.getModuleConfig(com1DFAOrig) startTime = time.time() # Clean input directory(ies) of old work and output files initProj.cleanSingleAvaDir(avalancheDir, keep=logName) # Run Standalone DFA reportDictList = com1DFAOrig.com1DFAOrigMain(cfg, avalancheDir) # Print time needed endTime = time.time() log.info(('Took %s seconds to calculate.' % (endTime - startTime))) # append parameters from logFile for reportD in reportDictList: simName = reportD['simName']['name'] parameterDict, reportD = fU.extractParameterInfo(avalancheDir, simName, reportD) # Generate plots for all peakFiles plotDict = oP.plotAllPeakFields(avalancheDir, cfg, cfgMain['FLAGS'], modName) # Set directory for report reportDir = os.path.join(avalancheDir, 'Outputs', 'com1DFAOrigOrig', 'reports') # write report gR.writeReport(reportDir, reportDictList, cfgMain['FLAGS'], plotDict) # write configuration to file cfgUtils.writeCfgFile(avalancheDir, com1DFAOrig, cfg)
def runCom1DFA(avaDir='', cfgFile='', relThField='', variationDict=''): """ run com1DFA module """ # +++++++++SETUP CONFIGURATION++++++++++++++++++++++++ # log file name; leave empty to use default runLog.log logName = 'runCom1DFA' # Load avalanche directory from general configuration file cfgMain = cfgUtils.getGeneralConfig() if avaDir != '': avalancheDir = avaDir else: avalancheDir = cfgMain['MAIN']['avalancheDir'] # set module name, reqiured as long we are in dev phase # - because need to create e.g. Output folder for com1DFA to distinguish from # current com1DFA modName = 'com1DFA' # Clean input directory(ies) of old work and output files # initProj.cleanSingleAvaDir(avalancheDir, keep=logName, deleteOutput=False) initProj.cleanModuleFiles(avalancheDir, com1DFA, modName) # Start logging log = logUtils.initiateLogger(avalancheDir, logName) log.info('MAIN SCRIPT') log.info('Current avalanche: %s', avalancheDir) # Create output and work directories # - because need to create e.g. Output folder for com1DFA to distinguish from workDir, outDir = inDirs.initialiseRunDirs(avalancheDir, modName) # generate list of simulations from desired configuration if variationDict == '': # Load full configuration modCfg, modInfo = cfgUtils.getModuleConfig(com1DFA, fileOverride=cfgFile, modInfo=True) variationDict = dP.getVariationDict(avalancheDir, modCfg, modInfo) else: # check if variationDict items exist and are provided in correct format # Load standard/ default configuration modCfg = cfgUtils.getDefaultModuleConfig(com1DFA) variationDict = dP.validateVarDict(variationDict, modCfg) log.info('Variations are performed for:') for key in variationDict: log.info('%s: %s' % (key, variationDict[key])) # add avalanche directory info to cfg modCfg['GENERAL']['avalancheDir'] = avalancheDir # fetch input data - dem, release-, entrainment- and resistance areas inputSimFiles = gI.getInputDataCom1DFAPy(avalancheDir, modCfg['FLAGS']) # write full configuration file to file cfgUtils.writeCfgFile(avalancheDir, com1DFA, modCfg, fileName='sourceConfiguration') # create a list of simulations # if need to reproduce exactely the hash - need to be strings with exactely the same number of digits!! simDict = com1DFA.prepareVarSimDict(modCfg, inputSimFiles, variationDict) log.info('The following simulations will be performed') for key in simDict: log.info('Simulation: %s' % key) reportDictList = [] # loop over all simulations for cuSim in simDict: # load configuration dictionary for cuSim cfg = simDict[cuSim]['cfgSim'] # save configuration settings for each simulation simHash = simDict[cuSim]['simHash'] cfgUtils.writeCfgFile(avalancheDir, com1DFA, cfg, fileName=cuSim) # log simulation name log.info('Run simulation: %s' % cuSim) # set release area scenario inputSimFiles['releaseScenario'] = simDict[cuSim]['relFile'] # +++++++++++++++++++++++++++++++++ # ------------------------ particlesList, fieldsList, Tsave, dem, reportDict, cfgFinal = com1DFA.com1DFAMain( cfg, avalancheDir, cuSim, inputSimFiles, outDir, relThField) # +++++++++EXPORT RESULTS AND PLOTS++++++++++++++++++++++++ # Generate plots for all peakFiles plotDict = oP.plotAllPeakFields(avalancheDir, cfg, cfgMain['FLAGS'], modName) reportDictList.append(reportDict) # export for visulation if cfg['VISUALISATION'].getboolean('writePartToCSV'): outDir = os.path.join(avalancheDir, 'Outputs', modName) com1DFA.savePartToCsv(cfg['VISUALISATION']['particleProperties'], particlesList, outDir) # create hash to check if config didnt change simHashFinal = cfgUtils.cfgHash(cfgFinal) if simHashFinal != simHash: log.warning( 'simulation configuration has been changed since start') cfgUtils.writeCfgFile(avalancheDir, com1DFA, cfg, fileName='%s_butModified' % simHash) # Set directory for report reportDir = os.path.join(avalancheDir, 'Outputs', 'com1DFA', 'reports') # write report gR.writeReport(reportDir, reportDictList, cfgMain['FLAGS'], plotDict) # read all simulation configuration files and return dataFrame and write to csv standardCfg = cfgUtils.getDefaultModuleConfig(com1DFA) simDF = cfgUtils.createConfigurationInfo(avalancheDir, standardCfg, writeCSV=True) return particlesList, fieldsList, Tsave, dem, plotDict, reportDictList
##################################################################### # ######################### Run com1DFAOrig ############################## # get module configuration (path to executable...) cfgCom1DFAOrig = cfgUtils.getModuleConfig(com1DFAOrig) # Run Standalone DFA reportDictListcom1DFAOrig = com1DFAOrig.com1DFAOrigMain( cfgCom1DFAOrig, avaDir) for reportD1 in reportDictListcom1DFAOrig: simName1 = reportD1['simName']['name'] parameterDict = fU.extractParameterInfo(avaDir, simName1, reportD1) # Generata plots for all peakFiles modNameOrig = 'com1DFAOrig' plotDictcom1DFAOrig = oP.plotAllPeakFields(avaDir, cfgCom1DFAOrig, cfgMain['FLAGS'], modNameOrig) # Set directory for com1DFA report reportDirOrig = os.path.join(outDir, 'com1DFAOrig', 'reports') # write report gR.writeReport(reportDirOrig, reportDictListcom1DFAOrig, cfgMain['FLAGS'], plotDictcom1DFAOrig) ##################################################################### # ######################### Run Com1DFA ############################# # Run python DFA # call com1DFA to perform simulation - provide configuration file and release thickness function _, _, _, _, plotDictcom1DFA, reportDictListcom1DFA = runCom1DFA.runCom1DFA( avaDir=avaDir, cfgFile='', relThField='') # Set directory for com1DFA report
cfg['GENERAL']['com1Exe'] = com1Exe # Set timing startTime = time.time() # Run Standalone DFA reportDictList = com1DFA.com1DFAMain(cfg, avaDir) modName = 'com1DFA' # Print time needed endTime = time.time() timeNeeded = endTime - startTime log.info(('Took %s seconds to calculate.' % (timeNeeded))) # Generata plots for all peakFiles plotDict = oP.plotAllPeakFields(avaDir, cfg, cfgMain['FLAGS']) # Set directory for report reportDir = os.path.join(avaDir, 'Outputs', 'com1DFA', 'reports') # write report gR.writeReport(reportDir, reportDictList, cfgMain['FLAGS'], plotDict) # Fetch correct reportDict according to flagEntRes for dict in reportDictList: if simNameRefTest == dict['simName']['name']: reportD = dict simNameComp = reportD['simName']['name'] # set result files directory compDir = pathlib.Path(avaDir, 'Outputs', modName, 'peakFiles')
# --- run Com1DFA ----- avaName = os.path.basename(avaDir) avaNameTest = avaName + 'StatsTest' statsSimCfg = os.path.join('..', 'benchmarks', avaNameTest, '%sStats%d_com1DFACfg.ini' % (avaName, count)) cfgDFA = cfgUtils.getModuleConfig(com1DFAOrig, statsSimCfg) cfgDFA['GENERAL']['com1Exe'] = com1Exe # Clean input directory(ies) of old work and output files initProj.cleanSingleAvaDir(avaDir, keep=logName) # Run Standalone DFA reportDictList = com1DFAOrig.com1DFAOrigMain(cfgDFA, avaDir) fU.makeADir(outDir) # Generata plots for all peakFiles plotDict = oP.plotAllPeakFields(avaDir, cfgDFA, cfgMain['FLAGS'], modName) # Set directory for report reportDir = os.path.join(avaDir, 'Outputs', 'com1DFAOrig', 'reports') # write report gR.writeReport(reportDir, reportDictList, cfgMain['FLAGS'], plotDict) if cfg.getboolean('aimec') == True: # run aimec statsAimecCfg = os.path.join('..', 'benchmarks', avaNameTest, '%sStats_ana3AIMECCfg.ini' % (avaName)) cfgAIMEC = cfgUtils.getModuleConfig(ana3AIMEC, statsAimecCfg) cfgAimecSetup = cfgAIMEC['AIMECSETUP'] # Setup input from com1DFA dfa2Aimec.mainDfa2Aimec(avaDir, cfgAimecSetup, modName) # Extract input file locations