-
Notifications
You must be signed in to change notification settings - Fork 9
[com1]: add option to only save certain particle props #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
| import os | ||
| import pathlib | ||
| import pickle | ||
| import platform | ||
| import re | ||
| import time | ||
| from datetime import datetime | ||
|
|
@@ -2159,7 +2158,7 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si | |
| exportFields(cfg, t, fields, dem, outDir, cuSimName, TSave="initial") | ||
|
|
||
| if "particles" in resTypes: | ||
| savePartToPickle(particles, outDirData, cuSimName) | ||
| savePartToPickle(particles, outDirData, cuSimName, cfg=cfg) | ||
|
|
||
| # Update dtSave to remove the initial timestep we just saved | ||
| dtSave = updateSavingTimeStep(dtSaveOriginal, cfgGen, t) | ||
|
|
@@ -2284,7 +2283,7 @@ def DFAIterate(cfg, particles, fields, dem, inputSimLines, outDir, cuSimName, si | |
|
|
||
| # export particles dictionaries of saving time steps | ||
| if "particles" in resTypes: | ||
|
fso42 marked this conversation as resolved.
|
||
| savePartToPickle(particles, outDirData, cuSimName) | ||
| savePartToPickle(particles, outDirData, cuSimName, cfg=cfg) | ||
|
|
||
| # export particles properties for visulation | ||
| if cfg["VISUALISATION"].getboolean("writePartToCSV"): | ||
|
|
@@ -2416,7 +2415,7 @@ 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) | ||
| savePartToPickle(particles, outDirData, cuSimName, cfg=cfg) | ||
|
|
||
| # save contour line for each sim only if the field is properly computed (not a dummy array) | ||
| contourResType = cfg["VISUALISATION"]["contourResType"] | ||
|
|
@@ -2834,7 +2833,7 @@ def releaseSecRelArea(cfg, particles, fields, dem, zPartArray0, reportAreaInfo): | |
| return particles, zPartArray0, reportAreaInfo | ||
|
|
||
|
|
||
| def savePartToPickle(dictList, outDir, logName): | ||
| def savePartToPickle(dictList, outDir, logName, cfg=""): | ||
| """Save each dictionary from a list to a pickle in outDir; works also for one dictionary instead of list | ||
| Note: particle coordinates are still in com1DFA reference system with origin 0,0 | ||
|
|
||
|
|
@@ -2846,16 +2845,107 @@ def savePartToPickle(dictList, outDir, logName): | |
| path to output directory | ||
| logName : str | ||
| simulation Id | ||
| cfg: str or configparser object | ||
| ['EXPORTS'] and ['GENERAL'] settings to provide particle properties to be saved, | ||
| if empty str all particle properties are saved, t (time info) always appended | ||
| """ | ||
|
|
||
| dictKeys = [ | ||
| "nPart", | ||
| "x", | ||
| "y", | ||
| "trajectoryLengthXY", | ||
| "trajectoryLengthXYCor", | ||
| "trajectoryLengthXYZ", | ||
| "z", | ||
| "m", | ||
| "dmDet", | ||
| "massPerPart", | ||
| "nPPK", | ||
| "mTot", | ||
| "h", | ||
| "ux", | ||
| "uy", | ||
| "uz", | ||
| "uAcc", | ||
| "stoppCriteria", | ||
| "kineticEne", | ||
| "trajectoryAngle", | ||
| "potentialEne", | ||
| "peakKinEne", | ||
| "peakMassFlowing", | ||
| "simName", | ||
| "xllcenter", | ||
| "yllcenter", | ||
| "ID", | ||
| "nID", | ||
| "parentID", | ||
| "t", | ||
| "inCellDEM", | ||
| "indXDEM", | ||
| "indYDEM", | ||
| "indPartInCell", | ||
| "partInCell", | ||
| "secondaryReleaseInfo", | ||
| "iterate", | ||
| "idFixed", | ||
| "peakForceSPH", | ||
| "forceSPHIni", | ||
| "totalEnthalpy", | ||
| "velocityMag", | ||
| "nExitedParticles", | ||
| "tPlot", | ||
| "dmEnt", | ||
| "stoppedParticles", | ||
| "massInitialized", | ||
| "massEntrained", | ||
| "massDetrained", | ||
| "massStopped", | ||
| ] | ||
|
|
||
| # create list of particle properties and append t (time info) | ||
| if isinstance(cfg, configparser.ConfigParser): | ||
| if cfg["EXPORTS"]["exportParticleProperties"] == "": | ||
| particleProperties = "" | ||
| else: | ||
| # first check if particle properties are valid | ||
| nonExisting = [ | ||
| item | ||
| for item in cfg["EXPORTS"]["exportParticleProperties"].split("|") | ||
| if item not in dictKeys | ||
| ] | ||
| if len(nonExisting) > 0: | ||
| message = "These particle properties are not available %s" % nonExisting | ||
| log.error(message) | ||
| raise AttributeError(message) | ||
|
|
||
| particleProperties = list(set(["t"] + cfg["EXPORTS"]["exportParticleProperties"].split("|"))) | ||
| if cfg["TRACKPARTICLES"].getboolean("trackParticles"): | ||
| trackParticleProperties = cfg["TRACKPARTICLES"]["particleProperties"].split("|") | ||
| particleProperties = set( | ||
| ["x", "y", "z", "ux", "uy", "uz", "m", "h"] | ||
| + particleProperties | ||
| + trackParticleProperties | ||
| ) | ||
| else: | ||
| particleProperties = "" | ||
|
|
||
| if isinstance(dictList, list): | ||
| for dict in dictList: | ||
| if particleProperties != "": | ||
| particlesToSave = {key: dict[key] for key in particleProperties} | ||
|
awirb marked this conversation as resolved.
|
||
| else: | ||
| particlesToSave = dict | ||
| fi = open(outDir / ("particles_%s_%09.4f.pickle" % (logName, dict["t"])), "wb") | ||
| pickle.dump(dict, fi) | ||
| pickle.dump(particlesToSave, fi) | ||
| fi.close() | ||
| else: | ||
| if particleProperties != "": | ||
| particlesToSave = {key: dictList[key] for key in particleProperties} | ||
| else: | ||
| particlesToSave = dictList | ||
| fi = open(outDir / ("particles_%s_%09.4f.pickle" % (logName, dictList["t"])), "wb") | ||
| pickle.dump(dictList, fi) | ||
| pickle.dump(particlesToSave, fi) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the above could be written in only one statement after the if/else block
fso42 marked this conversation as resolved.
|
||
| fi.close() | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -524,7 +524,7 @@ thresholdPointInPoly = 0.001 | |
|
|
||
| [TRACKPARTICLES] | ||
| # if particles should be tracked - don't forget to specify the "tSteps" you want to | ||
| # save further up (for example tStep = 0:1 will lead to tracking patiles every 1 second) | ||
| # save further up (for example tStep = 0:1 will lead to tracking particles every 1 second) | ||
| trackParticles = False | ||
| # centerTrackPartPoint of the location of the particles to track (x|y coordinates) | ||
| centerTrackPartPoint = 2933|-4010 | ||
|
|
@@ -570,4 +570,7 @@ exportData = True | |
| exportRasters = False | ||
| # use LZW compression when writing TIFF raster files | ||
| useCompression = True | ||
| # particle properties - list all properties that shall be saved, t is always added | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add info that particle property list can be found in the documentation |
||
| exportParticleProperties = | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.