Skip to content

Commit

Permalink
Option to specify number of leading zeros in solution filename number (
Browse files Browse the repository at this point in the history
…#345)

* New option for digits in solution filename numbering

* Fixed incorrect option name

* Specified solution digits for failed mesh too
  • Loading branch information
eytanadler committed Feb 29, 2024
1 parent c163509 commit f9acfc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions adflow/pyADflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,8 @@ def __call__(self, aeroProblem, **kwargs):
)

if self.adflow.killsignals.fatalfail:
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:03}.cgns"
numDigits = self.getOption("writeSolutionDigits")
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:0{numDigits}}.cgns"
self.pp(f"Fatal failure during mesh warp! Bad mesh is written in output directory as {fileName}")
self.writeMeshFile(os.path.join(self.getOption("outputDirectory"), fileName))
self.curAP.fatalFail = True
Expand Down Expand Up @@ -2738,14 +2739,15 @@ def writeSolution(self, outputDir=None, baseName=None, number=None, writeSlices=

# If we are numbering solution, it saving the sequence of
# calls, add the call number
numDigits = self.getOption("writeSolutionDigits")
if number is not None:
# We need number based on the provided number:
baseName = baseName + "_%3.3d" % number
baseName = baseName + f"_%.{numDigits}d" % number
else:
# if number is none, i.e. standalone, but we need to
# number solutions, use internal counter
if self.getOption("numberSolutions"):
baseName = baseName + "_%3.3d" % self.curAP.adflowData.callCounter
baseName = baseName + f"_%.{numDigits}d" % self.curAP.adflowData.callCounter

# Join to get the actual filename root
base = os.path.join(outputDir, baseName)
Expand Down Expand Up @@ -5706,6 +5708,7 @@ def _getDefaultOptions():
"partitionLikeNProc": [int, -1],
# Misc Parameters
"numberSolutions": [bool, True],
"writeSolutionDigits": [int, 3],
"printIterations": [bool, True],
"printTiming": [bool, True],
"printIntro": [bool, True],
Expand Down Expand Up @@ -6199,6 +6202,7 @@ def _getSpecialOptionLists(self):

pythonOptions = {
"numbersolutions",
"writesolutiondigits",
"writetecplotsurfacesolution",
"coupledsolution",
"partitiononly",
Expand Down
5 changes: 5 additions & 0 deletions doc/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,11 @@ numberSolutions:
desc: >
Flag to set whether to attach the numbering of the AeroProblem to the grid solution file.
writeSolutionDigits:
desc: >
Number of digits in the solution output filenames.
A value of 4 will give, for example, 0023, while a value of 3 will give 023.
printIterations:
desc: >
Flag to set whether to print out the monitoring values at each iteration.
Expand Down

0 comments on commit f9acfc1

Please sign in to comment.