-
Notifications
You must be signed in to change notification settings - Fork 876
[WIP] fix volume names #2079
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: develop
Are you sure you want to change the base?
[WIP] fix volume names #2079
Conversation
There are some other find_last_of lines as well, if all filenames are supposed to be given without any file extension, then these should all be removed. |
In principle sounds good, it will probably break lots of cases, optimization scripts and what not. We'll see, we are not leaving this inconsistent though, all or nothing. |
I agree. |
…always the same Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
# restart = restart.split(".")[0] | ||
# solution = solution.split(".")[0] | ||
|
||
pass |
Check warning
Code scanning / CodeQL
Unnecessary pass Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 16 days ago
To fix the issue, the pass
statement on line 1181 should be removed. This will eliminate the unnecessary code without altering the functionality of the program. The block already contains valid statements, so removing pass
will not affect the execution of the code.
@@ -1180,3 +1180,2 @@ | ||
solution = config.SOLUTION_FILENAME | ||
pass | ||
|
SU2_CFD/src/output/CMeshOutput.cpp
Outdated
volumeFilename = config->GetMesh_Out_FileName(); | ||
volumeFilename = config->GetMesh_Out_FileName() + ".su2"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the hard-coded extensions everywhere.
We should encapsulate this name giving and extensions into the function to retrieve the name.
This encapsulation should also make it possible to handle names both with and without extensions, forcing everyone to remove extensions from their config is a large break of backwards compatibility and I don't want to release version 9 for something as trivial as one user complaining that the named without extension didn'e work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we accept "restart" as well as "restart.dat" etc...?
But we check if the extension is actually the correct one, so restart.csv will not be stripped, but seen as having 'no extension'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but that would be an user error so I think it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our tests don't cover history files, breakdown files, etc. how do we know those are still output with the expected names?
flowIter = nFlowIter - iter; | ||
unsigned short lastindex = DV_Filename.find_last_of('.'); | ||
DV_Filename = DV_Filename.substr(0, lastindex); | ||
if ((SU2_TYPE::Int(flowIter) >= 0) && (SU2_TYPE::Int(flowIter) < 10)) | ||
SPRINTF(buffer, "_0000%d.dat", SU2_TYPE::Int(flowIter)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
} else { | ||
/*--- Forward time for the direct problem ---*/ | ||
flowIter = iter; | ||
unsigned short lastindex = DV_Filename.find_last_of('.'); | ||
DV_Filename = DV_Filename.substr(0, lastindex); | ||
if ((SU2_TYPE::Int(flowIter) >= 0) && (SU2_TYPE::Int(flowIter) < 10)) | ||
SPRINTF(buffer, "_0000%d.dat", SU2_TYPE::Int(flowIter)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same... this logic needs to be contained in helper functions, it will be a pain to get rid of the bugs this way... we'll have to reason about extensions in every area which is the opposite of what you are trying to achieve here I think.
auto str = config[ZONE_0]->GetMesh_Out_FileName(); | ||
unsigned short lastindex = str.find_last_of('.'); | ||
str = str.substr(0, lastindex) + ".su2"; | ||
//unsigned short lastindex = str.find_last_of('.'); | ||
str += ".su2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should return the name with extension and the callers of the function should not need to make further ad-hoc modifications
SU2_CFD/src/drivers/CDriver.cpp
Outdated
|
||
unsigned short lastindex = filename.find_last_of('.'); | ||
filename = filename.substr(0, lastindex); | ||
|
||
if (nZone > 1) | ||
filename = config->GetMultizone_FileName(filename, iZone, ".dat"); | ||
filename = config->GetMultizone_FileName(filename, iZone, ""); | ||
|
||
/*--- At the moment we stay consistent with the default extension .dat for all input files. ---*/ | ||
filename += ".dat"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function should handle the extension, not the client
auto fileName = config->GetBreakdown_FileName(); | ||
if (unsteady) { | ||
const auto lastindex = fileName.find_last_of('.'); | ||
const auto ext = fileName.substr(lastindex, fileName.size()); | ||
fileName = fileName.substr(0, lastindex); | ||
fileName = config->GetFilename(fileName, ext, curTimeIter); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems wrong
SU2_CFD/src/output/COutput.cpp
Outdated
|
||
string hist_ext = ".csv"; | ||
if (config->GetTabular_FileFormat() == TAB_OUTPUT::TAB_TECPLOT) hist_ext = ".dat"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, move the entire name logic into a helper function
direct_name = direct_name + ".csv" | ||
adjoint_name = adjoint_name + ".csv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea to keep things backwards compatible is:
direct_name = direct_name + ".csv" | |
adjoint_name = adjoint_name + ".csv" | |
direct_name = direct_name + ("" if direct_name.endswith(".csv") else ".csv") | |
adjoint_name = adjoint_name + ".csv" |
SU2_CFD/src/output/COutput.cpp
Outdated
string hist_ext = ".csv"; | ||
if (config->GetTabular_FileFormat() == TAB_OUTPUT::TAB_TECPLOT) hist_ext = ".dat"; | ||
|
||
/*--- Append the zone ID ---*/ | ||
/*--- Retrieve the history filename ---*/ | ||
|
||
historyFilename = config->GetConv_FileName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcarruscag so we add the hist_ext stuff to GetConv_Filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that and any logic to suffix with number of iterations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever a given file name (like the history or breakdown) is only used for a particular type of file, the accessor to get the file name can return it with extension.
The for output files whose extension depends on the type of format being output, we can add an accessor per file type, or make it clear in the name accessor that the name is without extension. However, it should contain everything else in the name that we need, zone idx, time step, etc.
I think this is the safest way to make this change while providing backward compatibility easily in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,
I move the entire filename construction into GetConv_FileName.
I strip ".dat" and ".csv" only and keep other extensions. Users can still use "history.dat", but using "history" or "history.1.2.3.old" will now work.
//const auto iZone = config->GetiZone(); | ||
//const auto nZone = config->GetnZone(); |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 20 hours ago
To fix the issue, we need to either remove the commented-out code entirely or reinstate it into the active codebase. Since the purpose of the commented-out code is unclear from the provided snippet, the best approach is to remove it to improve code clarity and maintainability. If the code is needed in the future, it can be retrieved from version control.
The specific lines to address are:
//const auto iZone = config->GetiZone();
//const auto nZone = config->GetnZone();
These lines should be removed from the file SU2_CFD/src/solvers/CSolver.cpp
.
-
Copy modified lines R3567-R3568
@@ -3566,4 +3566,4 @@ | ||
|
||
//const auto iZone = config->GetiZone(); | ||
//const auto nZone = config->GetnZone(); | ||
|
||
|
||
|
|
||
if (nZone > 1) filename_ = config->GetMultizone_FileName(filename_, iZone, ".dat"); | ||
// // nijso: this is inconsistent with line 70, nZone<= 1! | ||
if (nZone > 1) filename_ = config->GetMultizone_FileName(filename_, iZone, ""); |
Check warning
Code scanning / CodeQL
Comparison result is always the same Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 9 hours ago
To fix the issue, the redundant comparison if (nZone > 1)
on line 76 should be removed. Since the condition nZone <= 1
is already enforced by the outer if
statement on line 70, the block of code dependent on nZone > 1
will never execute. Removing this comparison will eliminate the logical inconsistency and improve code clarity.
@@ -74,4 +74,2 @@ | ||
auto filename_ = config->GetSolution_FileName(); | ||
// // nijso: this is inconsistent with line 70, nZone<= 1! | ||
if (nZone > 1) filename_ = config->GetMultizone_FileName(filename_, iZone, ""); | ||
|
Proposed Changes
For volume names, we assume that the filename is filename.ext and we strip the extension using find_last_of('.')
But:
I think we should simply remove the find_last_of lines. There are more of those, for now I have simply removed the one connected to #2074
Related Work
Issue: #2074
PR Checklist