Skip to content
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

Fixed string formatting styles #347

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions adflow/pyADflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@

if self.adflow.killsignals.fatalfail:
numDigits = self.getOption("writeSolutionDigits")
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:0{numDigits}}.cgns"
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:0{numDigits}d}.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 @@ -2742,12 +2742,12 @@
numDigits = self.getOption("writeSolutionDigits")
if number is not None:
# We need number based on the provided number:
baseName = baseName + f"_%.{numDigits}d" % number
baseName = f"{baseName}_{number:0{numDigits}d}"

Check warning on line 2745 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L2745

Added line #L2745 was not covered by tests
else:
# if number is none, i.e. standalone, but we need to
# number solutions, use internal counter
if self.getOption("numberSolutions"):
baseName = baseName + f"_%.{numDigits}d" % self.curAP.adflowData.callCounter
baseName = f"{baseName}_{self.curAP.adflowData.callCounter:0{numDigits}d}"

# Join to get the actual filename root
base = os.path.join(outputDir, baseName)
Expand Down
28 changes: 0 additions & 28 deletions tests/reg_tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,5 @@ def test_solve(self):
utils.assert_residuals_allclose(self.handler, self.CFDSolver, self.ap, tol=1e-10)


class TestFailedMesh(unittest.TestCase):
N_PROCS = 1

def test_failed_mesh(self):
options = copy.copy(adflowDefOpts)
options.update(
{
"outputdirectory": os.path.join(baseDir, options["outputdirectory"]),
"gridFile": os.path.join(baseDir, "../../input_files/mdo_tutorial_euler_scalar_jst.cgns"),
"mgcycle": "sg",
}
)

# Create the solver
CFDSolver = ADFLOW(options=options)
ap = copy.copy(ap_tutorial_wing)
# pretend mesh warping failed
CFDSolver.adflow.killsignals.fatalfail = True
# Solve
CFDSolver(ap)
self.failed_mesh = os.path.join(options["outputDirectory"], f"failed_mesh_{ap.name}_000.cgns")
self.assertTrue(os.path.isfile(self.failed_mesh))

def tearDown(self):
if os.path.isfile(self.failed_mesh):
os.remove(self.failed_mesh)


if __name__ == "__main__":
unittest.main()
82 changes: 82 additions & 0 deletions tests/unit_tests/test_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import copy
import os
import sys
import unittest
from parameterized import parameterized_class
from adflow import ADFLOW


baseDir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(baseDir, "../reg_tests"))

from reg_aeroproblems import ap_tutorial_wing # noqa E402


@parameterized_class(
[
{
"name": "three_digits",
"writeSolutionDigits": 3,
},
{
"name": "five_digits",
"writeSolutionDigits": 5,
},
]
)
class TestSolutionFileNames(unittest.TestCase):
N_PROCS = 1

def setUp(self):
self.options = {
"outputDirectory": os.path.join(baseDir, "../output_files"),
"writeSolutionDigits": self.writeSolutionDigits,
"gridFile": os.path.join(baseDir, "../../input_files/mdo_tutorial_euler_scalar_jst.cgns"),
"writeSurfaceSolution": False,
}

def test_failed_mesh(self):
# Create the solver
CFDSolver = ADFLOW(options=self.options)
ap = copy.copy(ap_tutorial_wing)

# Pretend mesh warping failed
CFDSolver.adflow.killsignals.fatalfail = True

# Solve
CFDSolver(ap)

if self.writeSolutionDigits == 3:
self.mesh_file = os.path.join(self.options["outputDirectory"], f"failed_mesh_{ap.name}_000.cgns")
elif self.writeSolutionDigits == 5:
self.mesh_file = os.path.join(self.options["outputDirectory"], f"failed_mesh_{ap.name}_00000.cgns")

# Check that a mesh file with this name exists
self.assertTrue(os.path.isfile(self.mesh_file))

def test_volume_solution(self):
# Create the solver
CFDSolver = ADFLOW(options=self.options)

# Set the AeroProblem and call counter
ap = copy.copy(ap_tutorial_wing)
CFDSolver.setAeroProblem(ap)
CFDSolver.curAP.adflowData.callCounter = 5

CFDSolver.writeSolution()

if self.writeSolutionDigits == 3:
self.mesh_file = os.path.join(self.options["outputDirectory"], f"{ap.name}_005_vol.cgns")
elif self.writeSolutionDigits == 5:
self.mesh_file = os.path.join(self.options["outputDirectory"], f"{ap.name}_00005_vol.cgns")

# Check that a mesh file with this name exists
self.assertTrue(os.path.isfile(self.mesh_file))

def tearDown(self):
if os.path.isfile(self.mesh_file):
os.remove(self.mesh_file)


if __name__ == "__main__":
unittest.main()