Skip to content

[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

Open
wants to merge 74 commits into
base: develop
Choose a base branch
from
Open

[WIP] fix volume names #2079

wants to merge 74 commits into from

Conversation

bigfooted
Copy link
Contributor

Proposed Changes

For volume names, we assume that the filename is filename.ext and we strip the extension using find_last_of('.')
But:

  1. This can lead to unwanted file stripping when you want the filename or folder to be volume.a
  2. We already mention in the documentation that the volume filename should be given without an extension

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

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@bigfooted
Copy link
Contributor Author

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.

@pcarruscag
Copy link
Member

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.

@bigfooted
Copy link
Contributor Author

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.

@pcarruscag pcarruscag changed the title fix volume names [WIP] fix volume names Jul 13, 2023
…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

Unnecessary 'pass' statement.

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.

Suggested changeset 1
SU2_PY/SU2/io/tools.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_PY/SU2/io/tools.py b/SU2_PY/SU2/io/tools.py
--- a/SU2_PY/SU2/io/tools.py
+++ b/SU2_PY/SU2/io/tools.py
@@ -1180,3 +1180,2 @@
         solution = config.SOLUTION_FILENAME
-        pass
 
EOF
@@ -1180,3 +1180,2 @@
solution = config.SOLUTION_FILENAME
pass

Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines 41 to 42
volumeFilename = config->GetMesh_Out_FileName();
volumeFilename = config->GetMesh_Out_FileName() + ".su2";

Copy link
Member

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...

Copy link
Contributor Author

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'?

Copy link
Member

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.

Copy link
Member

@pcarruscag pcarruscag left a 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?

Comment on lines 3516 to 3518
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines 3528 to 3532
} 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));
Copy link
Member

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.

Comment on lines 4920 to 4922
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";
Copy link
Member

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

Comment on lines 2318 to 2326

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";
Copy link
Member

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

Comment on lines 2435 to -2441
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems wrong

Comment on lines 88 to 91

string hist_ext = ".csv";
if (config->GetTabular_FileFormat() == TAB_OUTPUT::TAB_TECPLOT) hist_ext = ".dat";

Copy link
Member

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

Comment on lines +273 to +274
direct_name = direct_name + ".csv"
adjoint_name = adjoint_name + ".csv"
Copy link
Member

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:

Suggested change
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"

Comment on lines 89 to 94
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();
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines +3570 to +3571
//const auto iZone = config->GetiZone();
//const auto nZone = config->GetnZone();

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

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.

Suggested changeset 1
SU2_CFD/src/solvers/CSolver.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp
--- a/SU2_CFD/src/solvers/CSolver.cpp
+++ b/SU2_CFD/src/solvers/CSolver.cpp
@@ -3566,4 +3566,4 @@
 
-  //const auto iZone = config->GetiZone();
-  //const auto nZone = config->GetnZone();
+  
+  
 
EOF
@@ -3566,4 +3566,4 @@

//const auto iZone = config->GetiZone();
//const auto nZone = config->GetnZone();



Copilot is powered by AI and may make mistakes. Always verify output.

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

Comparison is always false because nZone <= 1.

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.


Suggested changeset 1
SU2_CFD/src/solvers/CIncEulerSolver.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/src/solvers/CIncEulerSolver.cpp b/SU2_CFD/src/solvers/CIncEulerSolver.cpp
--- a/SU2_CFD/src/solvers/CIncEulerSolver.cpp
+++ b/SU2_CFD/src/solvers/CIncEulerSolver.cpp
@@ -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, "");
 
EOF
@@ -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, "");

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants