Skip to content

Commit a40eff9

Browse files
Refactor C#
1 parent ff3e00e commit a40eff9

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

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+
file_path = std::filesystem::current_path() / "file.json";
90+
buffer.open(file_path.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

0 commit comments

Comments
 (0)