Skip to content

Commit 4e5da8c

Browse files
Merge pull request #13536 from KratosMultiphysics/several/proper-filesystem-path
[Several] Remove remaining deprecated warning for `std::filesystem`
2 parents 9ede420 + 7978016 commit 4e5da8c

File tree

3 files changed

+154
-148
lines changed

3 files changed

+154
-148
lines changed

applications/CSharpWrapperApplication/tests/cpp_tests/test_calculate.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// |_| |_| |_| |_| |_|
99
//
1010
//
11-
// License: BSD License
12-
// license: CSharpWrapperApplication/license.txt
11+
// License: BSD License
12+
// license: CSharpWrapperApplication/license.txt
1313
//
14-
// Main authors: Vicente Mataix Ferrandiz
14+
// Main authors: Vicente Mataix Ferrandiz
1515
//
1616

1717
// System includes
@@ -28,10 +28,10 @@ namespace Kratos {
2828
namespace Testing {
2929
void CreateMDPAFile() {
3030
std::filebuf buffer;
31-
buffer.open(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.mdpa"}), std::ios::out);
31+
std::filesystem::path file_path = std::filesystem::current_path() / "file.mdpa";
32+
buffer.open(file_path.string().c_str(), std::ios::out);
3233
std::ostream os(&buffer);
33-
os
34-
<< "Begin ModelPartData\nEnd ModelPartData\n\nBegin Properties 0\n DENSITY 2700.000000\n YOUNG_MODULUS 7000000.000000\n POISSON_RATIO 0.300000\n BODY_FORCE [3] (0.000000,0.000000,0.000000)\n THICKNESS 1.000000\nEnd Properties\n\nBegin Nodes\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n 3 1.0 0.0 0.0\n 4 1.0 1.0 0.0\nEnd Nodes\n\nBegin Elements SmallDisplacementElement3D4N\n 1 0 1 2 3 4\nEnd Elements\n\nBegin SubModelPart BasePart // Note that this would be a sub sub modelpart\n Begin SubModelPartNodes\n 1\n 2\n End SubModelPartNodes\n Begin SubModelPart inner_part\n Begin SubModelPartNodes\n 1\n End SubModelPartNodes\n End SubModelPart\nEnd SubModelPart";
34+
os << "Begin ModelPartData\nEnd ModelPartData\n\nBegin Properties 0\n DENSITY 2700.000000\n YOUNG_MODULUS 7000000.000000\n POISSON_RATIO 0.300000\n BODY_FORCE [3] (0.000000,0.000000,0.000000)\n THICKNESS 1.000000\nEnd Properties\n\nBegin Nodes\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n 3 1.0 0.0 0.0\n 4 1.0 1.0 0.0\nEnd Nodes\n\nBegin Elements SmallDisplacementElement3D4N\n 1 0 1 2 3 4\nEnd Elements\n\nBegin SubModelPart BasePart // Note that this would be a sub sub modelpart\n Begin SubModelPartNodes\n 1\n 2\n End SubModelPartNodes\n Begin SubModelPart inner_part\n Begin SubModelPartNodes\n 1\n End SubModelPartNodes\n End SubModelPart\nEnd SubModelPart";
3535
buffer.close();
3636
}
3737

@@ -86,7 +86,8 @@ namespace Kratos {
8686
})");
8787
const std::string &r_json_text = json_parameters.PrettyPrintJsonString();
8888
std::filebuf buffer;
89-
buffer.open(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.json"}), std::ios::out);
89+
std::filesystem::path file_path_json = std::filesystem::current_path() / "file.json";
90+
buffer.open(file_path_json.string().c_str(), std::ios::out);
9091
std::ostream os(&buffer);
9192
os << r_json_text;
9293
buffer.close();
@@ -102,9 +103,9 @@ namespace Kratos {
102103

103104
// Import mdpa
104105
CreateMDPAFile();
105-
const std::string file_name = FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.mdpa"});
106+
std::filesystem::path file_path = std::filesystem::current_path() / "file.mdpa";
106107
CSharpKratosWrapper::KratosWrapper *wrapperInstance = new CSharpKratosWrapper::KratosWrapper();
107-
wrapperInstance->init(file_name.c_str());
108+
wrapperInstance->init(file_path.string().c_str());
108109
CSharpKratosWrapper::ModelPartWrapper *mainModelPart = wrapperInstance->getRootModelPartWrapper();
109110
// Get some API info
110111
mainModelPart->retrieveResults();
@@ -191,7 +192,7 @@ namespace Kratos {
191192
// KRATOS_EXPECT_NEAR(y[3], 1.0, float_epsilon);
192193
// KRATOS_EXPECT_NEAR(z[3], 0.0, float_epsilon);
193194

194-
std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.mdpa"})).c_str());
195+
std::filesystem::remove(file_path);
195196
}
196197

197198
/**
@@ -205,11 +206,11 @@ namespace Kratos {
205206
// Import mdpa
206207
CreateMDPAFile();
207208
CreateJSONFile();
208-
const std::string file_name = FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.mdpa"});
209-
const std::string file_name_json = FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.json"});
209+
std::filesystem::path file_path = std::filesystem::current_path() / "file.mdpa";
210+
std::filesystem::path file_path_json = std::filesystem::current_path() / "file.json";
210211
CSharpKratosWrapper::KratosWrapper *wrapperInstance = new CSharpKratosWrapper::KratosWrapper();
211212

212-
wrapperInstance->init(file_name.c_str(), file_name_json.c_str());
213+
wrapperInstance->init(file_path.string().c_str(), file_path_json.string().c_str());
213214
CSharpKratosWrapper::ModelPartWrapper *mainModelPart = wrapperInstance->getRootModelPartWrapper();
214215

215216
// Get some API info
@@ -297,8 +298,8 @@ namespace Kratos {
297298
// KRATOS_EXPECT_NEAR(y[3], 1.0, float_epsilon);
298299
// KRATOS_EXPECT_NEAR(z[3], 0.0, float_epsilon);
299300

300-
std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.mdpa"})).c_str());
301-
std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "file.json"})).c_str());
301+
std::filesystem::remove(file_path);
302+
std::filesystem::remove(file_path_json);
302303
}
303304

304305
} // namespace Testing

applications/ContactStructuralMechanicsApplication/tests/cpp_tests/linear_solvers/test_mixedulm_linear_solver.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ void CreateAuxiliaryFiles()
6060
const std::string lhs = "%%MatrixMarket matrix coordinate real general\n16 16 184\n1 1 4.00969e+10\n1 2 0\n1 3 0\n1 4 0\n1 7 0\n1 8 0\n2 1 0\n2 2 1.35566e+11\n2 3 0\n2 4 0\n2 7 0\n2 8 0\n3 1 0\n3 2 0\n3 3 1.4559e+11\n3 4 0\n3 5 0\n3 6 0\n3 7 0\n3 8 0\n3 9 0\n3 10 0\n3 11 0\n3 12 0\n3 13 0\n3 14 0\n4 1 0\n4 2 0\n4 3 0\n4 4 2.22633e+10\n4 5 0\n4 6 -1.0345e+11\n4 7 0\n4 8 -6.20547e+09\n4 9 0\n4 10 -1.14853e-05\n4 11 0\n4 12 0.000525451\n4 13 0\n4 14 5.1725e+10\n5 3 0\n5 4 0\n5 5 2.069e+11\n5 6 0\n5 7 0\n5 8 0\n5 9 0\n5 10 0\n5 11 0\n5 12 0\n5 13 0\n5 14 0\n6 3 0\n6 4 -1.0345e+11\n6 5 0\n6 6 0\n6 7 0\n6 8 0\n6 9 0\n6 10 0\n6 11 0\n6 12 0.00103942\n6 13 0\n6 14 1.0345e+11\n7 1 0\n7 2 0\n7 3 0\n7 4 0\n7 5 0\n7 6 0\n7 7 1.4559e+11\n7 8 0\n7 9 0\n7 10 0\n7 11 0\n7 12 0\n7 13 0\n7 14 0\n8 1 0\n8 2 0\n8 3 0\n8 4 -6.20547e+09\n8 5 0\n8 6 0\n8 7 0\n8 8 2.22633e+10\n8 9 0\n8 10 -1.0345e+11\n8 11 0\n8 12 5.1725e+10\n8 13 0\n8 14 5.74263e-06\n9 3 0\n9 4 0\n9 5 0\n9 6 0\n9 7 0\n9 8 0\n9 9 2.069e+11\n9 10 0\n9 11 0\n9 12 0\n9 13 0\n9 14 0\n10 3 0\n10 4 -1.14853e-05\n10 5 0\n10 6 0\n10 7 0\n10 8 -1.0345e+11\n10 9 0\n10 10 0\n10 11 0\n10 12 1.0345e+11\n10 13 0\n10 14 1.14853e-05\n11 3 0\n11 4 0\n11 5 0\n11 6 0\n11 7 0\n11 8 0\n11 9 0\n11 10 0\n11 11 1.45464e+11\n11 12 0\n11 13 0\n11 14 0\n11 15 0\n11 16 0\n12 3 0\n12 4 0.000525451\n12 5 0\n12 6 0.00103942\n12 7 0\n12 8 5.1725e+10\n12 9 0\n12 10 1.0345e+11\n12 11 0\n12 12 2.22572e+10\n12 13 0\n12 14 -6.13145e+09\n12 15 0\n12 16 0\n13 3 0\n13 4 0\n13 5 0\n13 6 0\n13 7 0\n13 8 0\n13 9 0\n13 10 0\n13 11 0\n13 12 0\n13 13 1.45464e+11\n13 14 0\n13 15 0\n13 16 0\n14 3 0\n14 4 5.1725e+10\n14 5 0\n14 6 1.0345e+11\n14 7 0\n14 8 5.74263e-06\n14 9 0\n14 10 1.14853e-05\n14 11 0\n14 12 -6.13145e+09\n14 13 0\n14 14 2.22572e+10\n14 15 0\n14 16 0\n15 11 0\n15 12 0\n15 13 0\n15 14 0\n15 15 4.0137e+10\n15 16 0\n16 11 0\n16 12 0\n16 13 0\n16 14 0\n16 15 0\n16 16 1.35701e+11\n";
6161

6262
std::filebuf buffer_lhs;
63-
buffer_lhs.open(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "A_testing_condensation.mm"}),std::ios::out);
63+
std::filesystem::path file_path = std::filesystem::current_path() / "A_testing_condensation.mm";
64+
buffer_lhs.open(file_path.string().c_str(),std::ios::out);
6465
std::ostream os_lhs(&buffer_lhs);
6566
os_lhs << lhs;
6667
buffer_lhs.close();
6768

6869
const std::string rhs = "%%MatrixMarket matrix array real general\n16 1\n0\n0\n0\n-5.1725e+07\n0\n-1.0345e+08\n0\n-5.1725e+07\n0\n-1.0345e+08\n0\n-6.23386e+08\n0\n-6.23386e+08\n0\n0\n";
6970

7071
std::filebuf buffer_rhs;
71-
buffer_rhs.open(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "b_testing_condensation.rhs"}),std::ios::out);
72+
std::filesystem::path file_path_json = std::filesystem::current_path() / "b_testing_condensation.rhs";
73+
buffer_rhs.open(file_path_json.string().c_str(),std::ios::out);
7274
std::ostream os_rhs(&buffer_rhs);
7375
os_rhs << rhs;
7476
buffer_rhs.close();
@@ -981,12 +983,14 @@ KRATOS_TEST_CASE_IN_SUITE(MixedULMLinearSolverRealSystem, KratosContactStructura
981983

982984
// CHANGE THIS TO ADAPT TO YOUR PROBLEM
983985
CreateAuxiliaryFiles();
984-
const bool read_a = Kratos::ReadMatrixMarketMatrix(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "A_testing_condensation.mm"}).c_str(), A);
985-
const bool read_b = Kratos::ReadMatrixMarketVector(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "b_testing_condensation.rhs"}).c_str(), b);
986+
std::filesystem::path file_path_a = std::filesystem::current_path() / "A_testing_condensation.mm";
987+
const bool read_a = Kratos::ReadMatrixMarketMatrix(file_path_a.string().c_str(), A);
988+
std::filesystem::path file_path_b = std::filesystem::current_path() / "b_testing_condensation.rhs";
989+
const bool read_b = Kratos::ReadMatrixMarketVector(file_path_b.string().c_str(), b);
986990

987991
// Removing files
988-
std::filesystem::remove(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "A_testing_condensation.mm"}));
989-
std::filesystem::remove(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "b_testing_condensation.rhs"}));
992+
std::filesystem::remove(file_path_a);
993+
std::filesystem::remove(file_path_b);
990994

991995
if (read_a && read_b) {
992996
// We solve the reference system
@@ -1005,4 +1009,4 @@ KRATOS_TEST_CASE_IN_SUITE(MixedULMLinearSolverRealSystem, KratosContactStructura
10051009
KRATOS_EXPECT_VECTOR_NEAR(Dx, ref_Dx, tolerance);
10061010
}
10071011
}
1008-
} // namespace Kratos::Testing
1012+
} // namespace Kratos::Testing

0 commit comments

Comments
 (0)