|
11 | 11 | // |
12 | 12 |
|
13 | 13 | #ifdef INCLUDE_MMG |
| 14 | + |
14 | 15 | // System includes |
15 | 16 | #include<iostream> |
16 | 17 |
|
|
26 | 27 | #include "meshing_application_variables.h" |
27 | 28 | #include "custom_io/mmg/mmg_io.h" |
28 | 29 |
|
29 | | -namespace Kratos |
| 30 | +namespace Kratos::Testing |
| 31 | +{ |
| 32 | +/** |
| 33 | +* Checks the correct work of the level set MMG IO |
| 34 | +* Test triangle |
| 35 | +*/ |
| 36 | +KRATOS_TEST_CASE_IN_SUITE(MMGIO1, KratosMeshingApplicationFastSuite) |
| 37 | +{ |
| 38 | + Model this_model; |
| 39 | + ModelPart& r_model_part = this_model.CreateModelPart("Main", 2); |
| 40 | + |
| 41 | + Properties::Pointer p_elem_prop = r_model_part.CreateNewProperties(0); |
| 42 | + |
| 43 | + auto& process_info = r_model_part.GetProcessInfo(); |
| 44 | + process_info[STEP] = 1; |
| 45 | + process_info[NL_ITERATION_NUMBER] = 1; |
| 46 | + |
| 47 | + CppTestsUtilities::Create2DGeometry(r_model_part, "Element2D3N"); |
| 48 | + |
| 49 | + // Set DISTANCE and other variables |
| 50 | + Vector ref_metric(3); |
| 51 | + ref_metric[0] = 1.0; |
| 52 | + ref_metric[1] = 1.0; |
| 53 | + ref_metric[2] = 0.0; |
| 54 | + for (std::size_t i_node = 0; i_node < r_model_part.Nodes().size(); ++i_node) { |
| 55 | + auto it_node = r_model_part.Nodes().begin() + i_node; |
| 56 | + it_node->SetValue(METRIC_TENSOR_2D, ref_metric); |
| 57 | + } |
| 58 | + |
| 59 | + // Auxiliar submodelpart to check colors |
| 60 | + auto& r_sub = r_model_part.CreateSubModelPart("AuxiliarSubModelPart"); |
| 61 | + |
| 62 | + // Now we create the conditions |
| 63 | + r_sub.AddNode(r_model_part.pGetNode(1)); |
| 64 | + r_sub.AddNode(r_model_part.pGetNode(2)); |
| 65 | + auto p_cond = r_sub.CreateNewCondition("LineCondition2D2N", 1, {{1,2}}, p_elem_prop); |
| 66 | + |
| 67 | + // Compute read/write |
| 68 | + Parameters params = Parameters(R"({ "echo_level" : 0 })" ); |
| 69 | + MmgIO<MMGLibrary::MMG2D> mmg_io(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d"})); |
| 70 | + mmg_io.WriteModelPart(r_model_part); |
| 71 | + |
| 72 | + Model this_aux_model; |
| 73 | + ModelPart& r_aux_model_part = this_aux_model.CreateModelPart("Main", 2); |
| 74 | + |
| 75 | + mmg_io.ReadModelPart(r_aux_model_part); |
| 76 | + |
| 77 | + KRATOS_EXPECT_EQ(r_model_part.NumberOfNodes(), r_aux_model_part.NumberOfNodes()); |
| 78 | + KRATOS_EXPECT_EQ(r_model_part.NumberOfElements(), r_aux_model_part.NumberOfElements()); |
| 79 | + |
| 80 | + for (auto& r_sub_model_part_name : r_model_part.GetSubModelPartNames()) { |
| 81 | + KRATOS_EXPECT_TRUE(r_aux_model_part.HasSubModelPart(r_sub_model_part_name)); |
| 82 | + } |
| 83 | + |
| 84 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.mesh"})).c_str()); |
| 85 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.sol"})).c_str()); |
| 86 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.json"})).c_str()); |
| 87 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.cond.ref.json"})).c_str()); |
| 88 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.elem.ref.json"})).c_str()); |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | +* Checks the correct work of the level set MMG IO |
| 93 | +* Test tetrahedra |
| 94 | +*/ |
| 95 | +KRATOS_TEST_CASE_IN_SUITE(MMGIO2, KratosMeshingApplicationFastSuite) |
30 | 96 | { |
31 | | - namespace Testing |
32 | | - { |
33 | | - /** |
34 | | - * Checks the correct work of the level set MMG IO |
35 | | - * Test triangle |
36 | | - */ |
37 | | - KRATOS_TEST_CASE_IN_SUITE(MMGIO1, KratosMeshingApplicationFastSuite) |
38 | | - { |
39 | | - Model this_model; |
40 | | - ModelPart& r_model_part = this_model.CreateModelPart("Main", 2); |
41 | | - |
42 | | - Properties::Pointer p_elem_prop = r_model_part.CreateNewProperties(0); |
43 | | - |
44 | | - auto& process_info = r_model_part.GetProcessInfo(); |
45 | | - process_info[STEP] = 1; |
46 | | - process_info[NL_ITERATION_NUMBER] = 1; |
47 | | - |
48 | | - CppTestsUtilities::Create2DGeometry(r_model_part, "Element2D3N"); |
49 | | - |
50 | | - // Set DISTANCE and other variables |
51 | | - Vector ref_metric(3); |
52 | | - ref_metric[0] = 1.0; |
53 | | - ref_metric[1] = 1.0; |
54 | | - ref_metric[2] = 0.0; |
55 | | - for (std::size_t i_node = 0; i_node < r_model_part.Nodes().size(); ++i_node) { |
56 | | - auto it_node = r_model_part.Nodes().begin() + i_node; |
57 | | - it_node->SetValue(METRIC_TENSOR_2D, ref_metric); |
58 | | - } |
59 | | - |
60 | | - // Auxiliar submodelpart to check colors |
61 | | - auto& r_sub = r_model_part.CreateSubModelPart("AuxiliarSubModelPart"); |
62 | | - |
63 | | - // Now we create the conditions |
64 | | - r_sub.AddNode(r_model_part.pGetNode(1)); |
65 | | - r_sub.AddNode(r_model_part.pGetNode(2)); |
66 | | - auto p_cond = r_sub.CreateNewCondition("LineCondition2D2N", 1, {{1,2}}, p_elem_prop); |
67 | | - |
68 | | - // Compute read/write |
69 | | - Parameters params = Parameters(R"({ "echo_level" : 0 })" ); |
70 | | - MmgIO<MMGLibrary::MMG2D> mmg_io(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d"})); |
71 | | - mmg_io.WriteModelPart(r_model_part); |
72 | | - |
73 | | - Model this_aux_model; |
74 | | - ModelPart& r_aux_model_part = this_aux_model.CreateModelPart("Main", 2); |
75 | | - |
76 | | - mmg_io.ReadModelPart(r_aux_model_part); |
77 | | - |
78 | | - KRATOS_EXPECT_EQ(r_model_part.NumberOfNodes(), r_aux_model_part.NumberOfNodes()); |
79 | | - KRATOS_EXPECT_EQ(r_model_part.NumberOfElements(), r_aux_model_part.NumberOfElements()); |
80 | | - |
81 | | - for (auto& r_sub_model_part_name : r_model_part.GetSubModelPartNames()) { |
82 | | - KRATOS_EXPECT_TRUE(r_aux_model_part.HasSubModelPart(r_sub_model_part_name)); |
83 | | - } |
84 | | - |
85 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.mesh"})).c_str()); |
86 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.sol"})).c_str()); |
87 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.json"})).c_str()); |
88 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.cond.ref.json"})).c_str()); |
89 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_2d.elem.ref.json"})).c_str()); |
90 | | - } |
91 | | - |
92 | | - /** |
93 | | - * Checks the correct work of the level set MMG IO |
94 | | - * Test tetrahedra |
95 | | - */ |
96 | | - KRATOS_TEST_CASE_IN_SUITE(MMGIO2, KratosMeshingApplicationFastSuite) |
97 | | - { |
98 | | - Model this_model; |
99 | | - ModelPart& r_model_part = this_model.CreateModelPart("Main", 2); |
100 | | - |
101 | | - r_model_part.AddNodalSolutionStepVariable(DISTANCE); |
102 | | - r_model_part.AddNodalSolutionStepVariable(DISTANCE_GRADIENT); |
103 | | - |
104 | | - Properties::Pointer p_elem_prop = r_model_part.CreateNewProperties(0); |
105 | | - |
106 | | - auto& process_info = r_model_part.GetProcessInfo(); |
107 | | - process_info[STEP] = 1; |
108 | | - process_info[NL_ITERATION_NUMBER] = 1; |
109 | | - |
110 | | - CppTestsUtilities::Create3DGeometry(r_model_part, "Element3D4N"); |
111 | | - |
112 | | - // Set DISTANCE and other variables |
113 | | - array_1d<double, 6> ref_metric = ZeroVector(6); |
114 | | - ref_metric[0] = 1.0; |
115 | | - ref_metric[1] = 1.0; |
116 | | - ref_metric[2] = 1.0; |
117 | | - for (std::size_t i_node = 0; i_node < r_model_part.Nodes().size(); ++i_node) { |
118 | | - auto it_node = r_model_part.Nodes().begin() + i_node; |
119 | | - it_node->SetValue(METRIC_TENSOR_3D, ref_metric); |
120 | | - } |
121 | | - |
122 | | - // Auxiliar submodelpart to check colors |
123 | | - auto& r_sub = r_model_part.CreateSubModelPart("AuxiliarSubModelPart"); |
124 | | - |
125 | | - // Now we create the conditions |
126 | | - r_sub.AddNode(r_model_part.pGetNode(1)); |
127 | | - r_sub.AddNode(r_model_part.pGetNode(2)); |
128 | | - r_sub.AddNode(r_model_part.pGetNode(3)); |
129 | | - auto p_cond = r_sub.CreateNewCondition("SurfaceCondition3D3N", 1, {{1,2,3}}, p_elem_prop); |
130 | | - |
131 | | - // Compute read/write |
132 | | - Parameters params = Parameters(R"({ "echo_level" : 0 })" ); |
133 | | - MmgIO<MMGLibrary::MMG3D> mmg_io(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d"})); |
134 | | - mmg_io.WriteModelPart(r_model_part); |
135 | | - |
136 | | - Model this_aux_model; |
137 | | - ModelPart& r_aux_model_part = this_aux_model.CreateModelPart("Main", 2); |
138 | | - |
139 | | - mmg_io.ReadModelPart(r_aux_model_part); |
140 | | - |
141 | | - KRATOS_EXPECT_EQ(r_model_part.NumberOfNodes(), r_aux_model_part.NumberOfNodes()); |
142 | | - KRATOS_EXPECT_EQ(r_model_part.NumberOfElements(), r_aux_model_part.NumberOfElements()); |
143 | | - |
144 | | - for (auto& r_sub_model_part_name : r_model_part.GetSubModelPartNames()) { |
145 | | - KRATOS_EXPECT_TRUE(r_aux_model_part.HasSubModelPart(r_sub_model_part_name)); |
146 | | - } |
147 | | - |
148 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.mesh"})).c_str()); |
149 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.sol"})).c_str()); |
150 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.json"})).c_str()); |
151 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.cond.ref.json"})).c_str()); |
152 | | - std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.elem.ref.json"})).c_str()); |
153 | | - } |
154 | | - } // namespace Testing |
155 | | -} // namespace Kratos. |
| 97 | + Model this_model; |
| 98 | + ModelPart& r_model_part = this_model.CreateModelPart("Main", 2); |
| 99 | + |
| 100 | + r_model_part.AddNodalSolutionStepVariable(DISTANCE); |
| 101 | + r_model_part.AddNodalSolutionStepVariable(DISTANCE_GRADIENT); |
| 102 | + |
| 103 | + Properties::Pointer p_elem_prop = r_model_part.CreateNewProperties(0); |
| 104 | + |
| 105 | + auto& process_info = r_model_part.GetProcessInfo(); |
| 106 | + process_info[STEP] = 1; |
| 107 | + process_info[NL_ITERATION_NUMBER] = 1; |
| 108 | + |
| 109 | + CppTestsUtilities::Create3DGeometry(r_model_part, "Element3D4N"); |
| 110 | + |
| 111 | + // Set DISTANCE and other variables |
| 112 | + array_1d<double, 6> ref_metric = ZeroVector(6); |
| 113 | + ref_metric[0] = 1.0; |
| 114 | + ref_metric[1] = 1.0; |
| 115 | + ref_metric[2] = 1.0; |
| 116 | + for (std::size_t i_node = 0; i_node < r_model_part.Nodes().size(); ++i_node) { |
| 117 | + auto it_node = r_model_part.Nodes().begin() + i_node; |
| 118 | + it_node->SetValue(METRIC_TENSOR_3D, ref_metric); |
| 119 | + } |
| 120 | + |
| 121 | + // Auxiliar submodelpart to check colors |
| 122 | + auto& r_sub = r_model_part.CreateSubModelPart("AuxiliarSubModelPart"); |
| 123 | + |
| 124 | + // Now we create the conditions |
| 125 | + r_sub.AddNode(r_model_part.pGetNode(1)); |
| 126 | + r_sub.AddNode(r_model_part.pGetNode(2)); |
| 127 | + r_sub.AddNode(r_model_part.pGetNode(3)); |
| 128 | + auto p_cond = r_sub.CreateNewCondition("SurfaceCondition3D3N", 1, {{1,2,3}}, p_elem_prop); |
| 129 | + |
| 130 | + // Compute read/write |
| 131 | + Parameters params = Parameters(R"({ "echo_level" : 0 })" ); |
| 132 | + MmgIO<MMGLibrary::MMG3D> mmg_io(FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d"})); |
| 133 | + mmg_io.WriteModelPart(r_model_part); |
| 134 | + |
| 135 | + Model this_aux_model; |
| 136 | + ModelPart& r_aux_model_part = this_aux_model.CreateModelPart("Main", 2); |
| 137 | + |
| 138 | + mmg_io.ReadModelPart(r_aux_model_part); |
| 139 | + |
| 140 | + KRATOS_EXPECT_EQ(r_model_part.NumberOfNodes(), r_aux_model_part.NumberOfNodes()); |
| 141 | + KRATOS_EXPECT_EQ(r_model_part.NumberOfElements(), r_aux_model_part.NumberOfElements()); |
| 142 | + |
| 143 | + for (auto& r_sub_model_part_name : r_model_part.GetSubModelPartNames()) { |
| 144 | + KRATOS_EXPECT_TRUE(r_aux_model_part.HasSubModelPart(r_sub_model_part_name)); |
| 145 | + } |
| 146 | + |
| 147 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.mesh"})).c_str()); |
| 148 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.sol"})).c_str()); |
| 149 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.json"})).c_str()); |
| 150 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.cond.ref.json"})).c_str()); |
| 151 | + std::filesystem::remove((FilesystemExtensions::JoinPaths({FilesystemExtensions::CurrentWorkingDirectory(), "mmg_output_3d.elem.ref.json"})).c_str()); |
| 152 | +} |
| 153 | + |
| 154 | +} // namespace Kratos::Testing. |
156 | 155 | #endif |
0 commit comments