Skip to content

Commit

Permalink
log the particles exiting the domain
Browse files Browse the repository at this point in the history
  • Loading branch information
awirb authored and fso42 committed Aug 8, 2023
1 parent 9d4ae77 commit 3ab275f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions avaframe/com1DFA/com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ def com1DFACore(cfg, avaDir, cuSimName, inputSimFiles, outDir, simHash=''):
fieldsList[-1][cfg['VISUALISATION']['contourResType']], cfg['VISUALISATION'], cuSimName)
reportDict['contours'] = contDictXY

if particlesList[-1]['nExitedParticles'] != 0.:
log.warning('%d particles have been removed during simulation because they exited the domain' % particlesList[-1]['nExitedParticles'])

return dem, reportDict, cfg, infoDict['tCPU'], particlesList


Expand Down Expand Up @@ -1163,6 +1166,7 @@ def initializeParticles(cfg, releaseLine, dem, inputSimLines='', logName='', rel
particles['simName'] = logName
particles['xllcenter'] = dem['originalHeader']['xllcenter']
particles['yllcenter'] = dem['originalHeader']['yllcenter']
particles['nExitedParticles'] = 0.

# remove particles that might lay outside of the release polygon
if not cfg.getboolean('iniStep') and not cfg.getboolean('initialiseParticlesFromFile'):
Expand Down
3 changes: 3 additions & 0 deletions avaframe/com1DFA/particleTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def removePart(particles, mask, nRemove, reasonString='', snowSlide=0):
"""
if reasonString != '':
log.debug('removed %s particles %s' % (nRemove, reasonString))
if reasonString == 'because they exited the domain':
particles['nExitedParticles'] = particles['nExitedParticles'] + nRemove
nPart = particles['nPart']
if snowSlide == 1:
# if snowSlide is activated, we need to remove the particles as well as the bonds accordingly
Expand All @@ -230,6 +232,7 @@ def removePart(particles, mask, nRemove, reasonString='', snowSlide=0):
particles[key] = np.extract(mask, particles[key])

particles['mTot'] = np.sum(particles['m'])

return particles


Expand Down
29 changes: 27 additions & 2 deletions avaframe/tests/test_com1DFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ def test_prepareInputData(tmp_path):
assert inputSimLines['resLine']['Length'] == np.asarray([5.])
assert inputSimLines['resLine']['Name'] == ['']

# call function to be tested
inputSimFiles = {'entResInfo': {'flagEnt': 'No',
'flagRes': 'Yes', 'flagSecondaryRelease': 'No'}}
dirName = pathlib.Path(__file__).parents[0]
avaDir = dirName / '..' / 'data' / 'avaParabola'
relFile = avaDir / 'Inputs' / 'REL' / 'release1PF.shp'
inputSimFiles['releaseScenario'] = relFile
inputSimFiles['demFile'] = avaDir / 'Inputs' / 'DEM_PF_Topo.asc'
inputSimFiles['resFile'] = avaDir / 'Inputs' / 'RES' / 'resistance1PF.shp'
inputSimFiles['relThFile'] = dirName / 'data' / 'relThFieldTestFile.asc'
cfg['GENERAL']['simTypeActual'] = 'res'
cfg['GENERAL']['relThFromFile'] = 'False'
demOri, inputSimLines = com1DFA.prepareInputData(inputSimFiles, cfg)

assert demOri['header']['ncols'] == 1001
assert demOri['header']['nrows'] == 401
assert inputSimLines['releaseLine']['thickness'] == ['1.0']
assert inputSimLines['entLine'] is None
assert inputSimLines['resLine']['Start'] == np.asarray([0.])
assert inputSimLines['resLine']['Length'] == np.asarray([5.])
assert inputSimLines['resLine']['Name'] == ['']
assert inputSimLines['relThField'] == ''

# call function to be tested
inputSimFiles = {'entResInfo': {'flagEnt': 'No',
Expand All @@ -87,6 +109,7 @@ def test_prepareInputData(tmp_path):
inputSimFiles['resFile'] = avaDir / 'Inputs' / 'RES' / 'resistance1PF.shp'
inputSimFiles['relThFile'] = dirName / 'data' / 'relThFieldTestFile.asc'
cfg['GENERAL']['simTypeActual'] = 'res'
cfg['GENERAL']['relThFromFile'] = 'True'
demOri, inputSimLines = com1DFA.prepareInputData(inputSimFiles, cfg)

print('inputSimLines', inputSimLines)
Expand Down Expand Up @@ -114,6 +137,7 @@ def test_prepareInputData(tmp_path):
IOf.writeResultToAsc(testHeader, testField, testFile, flip=True)
inputSimFiles['relThFile'] = testFile
cfg['GENERAL']['simTypeActual'] = 'res'
cfg['GENERAL']['relThFromFile'] = 'True'

with pytest.raises(AssertionError) as e:
assert com1DFA.prepareInputData(inputSimFiles, cfg)
Expand Down Expand Up @@ -1082,7 +1106,8 @@ def test_initializeParticles():
'xllcenter', 'yllcenter', 'ID', 'nID', 'parentID', 't',
'inCellDEM', 'indXDEM', 'indYDEM', 'indPartInCell',
'partInCell', 'secondaryReleaseInfo', 'iterate', 'idFixed',
'peakForceSPH', 'forceSPHIni', 'totalEnthalpy']
'peakForceSPH', 'forceSPHIni', 'totalEnthalpy',
'nExitedParticles']

# call function to be tested
particles = com1DFA.initializeParticles(cfg['GENERAL'], releaseLine, dem)
Expand Down Expand Up @@ -1645,7 +1670,7 @@ def test_runCom1DFA(tmp_path, caplog):
'inCellDEM', 'indXDEM', 'indYDEM', 'indPartInCell',
'partInCell', 'secondaryReleaseInfo', 'iterate',
'massEntrained', 'idFixed', 'peakForceSPH', 'forceSPHIni', 'gEff', 'curvAcc',
'totalEnthalpy']
'totalEnthalpy', 'nExitedParticles']

# read one particles dictionary
inDir = avaDir / 'Outputs' / 'com1DFA' / 'particles'
Expand Down

0 comments on commit 3ab275f

Please sign in to comment.