Skip to content

Commit 3acda87

Browse files
authored
Cleanup file extensions (#2557)
* use helper, fix ffd writing bug * move add-extension to meshwrite * add missing adjoint filenames
1 parent deece11 commit 3acda87

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

Common/include/CConfig.hpp

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5564,10 +5564,8 @@ class CConfig {
55645564
string meshFilename = Mesh_FileName;
55655565

55665566
/*--- strip the extension, only if it is .su2 or .cgns ---*/
5567-
auto extIndex = meshFilename.rfind(".su2");
5568-
if (extIndex != std::string::npos) meshFilename.resize(extIndex);
5569-
extIndex = meshFilename.rfind(".cgns");
5570-
if (extIndex != std::string::npos) meshFilename.resize(extIndex);
5567+
PrintingToolbox::TrimExtension(".su2",meshFilename);
5568+
PrintingToolbox::TrimExtension(".cgns",meshFilename);
55715569

55725570
switch (GetMesh_FileFormat()) {
55735571
case SU2:
@@ -5597,10 +5595,8 @@ class CConfig {
55975595
string meshFilename = Mesh_Out_FileName;
55985596

55995597
/*--- strip the extension, only if it is .su2 or .cgns ---*/
5600-
auto extIndex = meshFilename.rfind(".su2");
5601-
if (extIndex != std::string::npos) meshFilename.resize(extIndex);
5602-
extIndex = meshFilename.rfind(".cgns");
5603-
if (extIndex != std::string::npos) meshFilename.resize(extIndex);
5598+
PrintingToolbox::TrimExtension(".su2",meshFilename);
5599+
PrintingToolbox::TrimExtension(".cgns",meshFilename);
56045600

56055601
return meshFilename;
56065602
}
@@ -5614,10 +5610,8 @@ class CConfig {
56145610
string solutionFilename = Solution_FileName;
56155611

56165612
/*--- strip the extension, only if it is .dat or .csv ---*/
5617-
auto extIndex = solutionFilename.rfind(".dat");
5618-
if (extIndex != std::string::npos) solutionFilename.resize(extIndex);
5619-
extIndex = solutionFilename.rfind(".csv");
5620-
if (extIndex != std::string::npos) solutionFilename.resize(extIndex);
5613+
PrintingToolbox::TrimExtension(".dat",solutionFilename);
5614+
PrintingToolbox::TrimExtension(".csv",solutionFilename);
56215615

56225616
/*--- return the stripped filename base, without extension. ---*/
56235617
return solutionFilename;
@@ -5629,7 +5623,17 @@ class CConfig {
56295623
* \return Name of the file with the solution of the adjoint flow problem with
56305624
* drag objective function.
56315625
*/
5632-
string GetSolution_AdjFileName(void) const { return Solution_AdjFileName; }
5626+
string GetSolution_AdjFileName(void) const {
5627+
/*--- we keep the original Solution_FileName ---*/
5628+
string solutionAdjFilename = Solution_AdjFileName;
5629+
5630+
/*--- strip the extension, only if it is .dat or .csv ---*/
5631+
PrintingToolbox::TrimExtension(".dat",solutionAdjFilename);
5632+
PrintingToolbox::TrimExtension(".csv",solutionAdjFilename);
5633+
5634+
/*--- return the stripped filename base, without extension. ---*/
5635+
return solutionAdjFilename;
5636+
}
56335637

56345638
/*!
56355639
* \brief Get the format of the input/output grid.
@@ -5665,10 +5669,8 @@ class CConfig {
56655669
string historyFilename = Conv_FileName;
56665670

56675671
/*--- strip the extension, only if it is .dat or .csv ---*/
5668-
auto extIndex = historyFilename.rfind(".dat");
5669-
if (extIndex != std::string::npos) historyFilename.resize(extIndex);
5670-
extIndex = historyFilename.rfind(".csv");
5671-
if (extIndex != std::string::npos) historyFilename.resize(extIndex);
5672+
PrintingToolbox::TrimExtension(".dat", historyFilename);
5673+
PrintingToolbox::TrimExtension(".csv", historyFilename);
56725674

56735675
/*--- Multizone problems require the number of the zone to be appended. ---*/
56745676
if (GetMultizone_Problem())
@@ -5699,10 +5701,8 @@ class CConfig {
56995701
string inletProfileFilename = Inlet_Filename;
57005702

57015703
/*--- strip the extension, only if it is .dat or .csv ---*/
5702-
auto extIndex = inletProfileFilename.rfind(".dat");
5703-
if (extIndex != std::string::npos) inletProfileFilename.resize(extIndex);
5704-
extIndex = inletProfileFilename.rfind(".csv");
5705-
if (extIndex != std::string::npos) inletProfileFilename.resize(extIndex);
5704+
PrintingToolbox::TrimExtension(".dat", inletProfileFilename);
5705+
PrintingToolbox::TrimExtension(".csv", inletProfileFilename);
57065706

57075707
/*--- Multizone problems require the number of the zone to be appended. ---*/
57085708
if (GetMultizone_Problem())
@@ -5792,13 +5792,35 @@ class CConfig {
57925792
* \brief Get the name of the restart file for the flow variables.
57935793
* \return Name of the restart file for the flow variables.
57945794
*/
5795-
string GetRestart_FileName(void) const { return Restart_FileName; }
5795+
string GetRestart_FileName(void) const {
5796+
5797+
/*--- we keep the original Restart_FileName ---*/
5798+
string restartFilename = Restart_FileName;
5799+
5800+
/*--- strip the extension, only if it is .dat or .csv ---*/
5801+
PrintingToolbox::TrimExtension(".dat", restartFilename);
5802+
PrintingToolbox::TrimExtension(".csv", restartFilename);
5803+
5804+
/*--- return the stripped filename base, without extension. ---*/
5805+
return restartFilename;
5806+
}
57965807

57975808
/*!
57985809
* \brief Get the name of the restart file for the adjoint variables (drag objective function).
57995810
* \return Name of the restart file for the adjoint variables (drag objective function).
58005811
*/
5801-
string GetRestart_AdjFileName(void) const { return Restart_AdjFileName; }
5812+
string GetRestart_AdjFileName(void) const {
5813+
5814+
/*--- we keep the original Restart_FileName ---*/
5815+
string restartAdjFilename = Restart_AdjFileName;
5816+
5817+
/*--- strip the extension, only if it is .dat or .csv ---*/
5818+
PrintingToolbox::TrimExtension(".dat", restartAdjFilename);
5819+
PrintingToolbox::TrimExtension(".csv", restartAdjFilename);
5820+
5821+
/*--- return the stripped filename base, without extension. ---*/
5822+
return restartAdjFilename;
5823+
}
58025824

58035825
/*!
58045826
* \brief Get the name of the file with the adjoint variables.
@@ -5843,7 +5865,7 @@ class CConfig {
58435865
string GetVolSens_FileName(void) const { return VolSens_FileName; }
58445866

58455867
/*!
5846-
* \brief Augment the input filename with the iteration number for an unsteady file.
5868+
* \brief Append the input filename with the iteration number for an unsteady file.
58475869
* \param[in] val_filename - String value of the base filename.
58485870
* \param[in] val_iter - Unsteady iteration number or time instance.
58495871
* \param[in] ext - the filename extension.

Common/src/CConfig.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8452,8 +8452,7 @@ CConfig::~CConfig() {
84528452
string CConfig::GetFilename(string filename, const string& ext, int timeIter) const {
84538453

84548454
/*--- strip the extension in case it is still there ---*/
8455-
auto extIndex = filename.rfind(ext);
8456-
if (extIndex != std::string::npos) filename.resize(extIndex);
8455+
PrintingToolbox::TrimExtension(ext, filename);
84578456

84588457
/*--- Append the zone number if multizone problems ---*/
84598458
if (Multizone_Problem && Multizone_Adapt_FileName)

Common/src/grid_movement/CSurfaceMovement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5046,7 +5046,7 @@ void CSurfaceMovement::WriteFFDInfo(CSurfaceMovement** surface_movement, CGeomet
50465046
if (rank == MASTER_NODE) {
50475047
/*--- Read the name of the output file ---*/
50485048

5049-
auto str = config[ZONE_0]->GetMesh_Out_FileName();
5049+
auto str = config[ZONE_0]->GetMesh_Out_FileName() + ".su2";
50505050

50515051
output_file.precision(15);
50525052
output_file.open(str, ios::out | ios::app);

0 commit comments

Comments
 (0)