-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GeoMechanicsApplication] ApplyConstantPhreaticMultiLinePressureProce…
…ss checks size of coordinates (#12578) * Check that coordinates in gravity direction are not empty * Check that coordinates in horizontal direction are not empty * Check that at least two coordinates in gravity direction are given * Check that at least two coordinates in horizontal direction are given * No failure when at least two coordinates in gravity direction are given * No failure when at least two coordinates in horizontal direction are given * Replaced some tabs by spaces
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...sApplication/tests/cpp_tests/test_apply_constant_phreatic_multi_line_pressure_process.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// KRATOS___ | ||
// // ) ) | ||
// // ___ ___ | ||
// // ____ //___) ) // ) ) | ||
// // / / // // / / | ||
// ((____/ / ((____ ((___/ / MECHANICS | ||
// | ||
// License: geo_mechanics_application/license.txt | ||
// | ||
// Main authors: Anne van de Graaf | ||
// | ||
#include "containers/model.h" | ||
#include "custom_processes/apply_constant_phreatic_multi_line_pressure_process.h" | ||
#include "geo_mechanics_fast_suite.h" | ||
#include "includes/checks.h" | ||
|
||
using namespace Kratos; | ||
|
||
namespace | ||
{ | ||
|
||
bool CanCreateInstanceOfApplyConstantPhreaticMultiLinePressureProcessWithoutFailure(ModelPart& rModelPart, | ||
const Parameters& rProcessParameters) | ||
{ | ||
try { | ||
ApplyConstantPhreaticMultiLinePressureProcess{rModelPart, rProcessParameters}; | ||
} catch (const Exception&) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace Kratos::Testing | ||
{ | ||
|
||
KRATOS_TEST_CASE_IN_SUITE(ApplyConstantPhreaticMultiLinePressureProcessThrowsWhenLessThanTwoCoordinatesInGravityDirectionAreGiven, | ||
KratosGeoMechanicsFastSuiteWithoutKernel) | ||
{ | ||
auto model = Model{}; | ||
auto& r_model_part = model.CreateModelPart("foo"); | ||
auto test_parameters = Parameters{R"( | ||
{ | ||
"model_part_name": "foo", | ||
"variable_name": "WATER_PRESSURE", | ||
"x_coordinates": [0.0, 1.0], | ||
"y_coordinates": [], | ||
"z_coordinates": [0.0, 0.0], | ||
"gravity_direction": 1 | ||
} )"}; | ||
|
||
KRATOS_EXPECT_EXCEPTION_IS_THROWN( | ||
(ApplyConstantPhreaticMultiLinePressureProcess{r_model_part, test_parameters}), | ||
"At least two coordinates in gravity direction must be given, but got 0") | ||
|
||
test_parameters.RemoveValue("y_coordinates"); | ||
test_parameters.AddVector("y_coordinates", ScalarVector{1, 0.0}); | ||
KRATOS_EXPECT_EXCEPTION_IS_THROWN( | ||
(ApplyConstantPhreaticMultiLinePressureProcess{r_model_part, test_parameters}), | ||
"At least two coordinates in gravity direction must be given, but got 1") | ||
} | ||
|
||
KRATOS_TEST_CASE_IN_SUITE(ApplyConstantPhreaticMultiLinePressureProcessThrowsWhenLessThanTwoCoordinatesInHorizontalDirectionAreGiven, | ||
KratosGeoMechanicsFastSuiteWithoutKernel) | ||
{ | ||
auto model = Model{}; | ||
auto& r_model_part = model.CreateModelPart("foo"); | ||
auto test_parameters = Parameters{R"( | ||
{ | ||
"model_part_name": "foo", | ||
"variable_name": "WATER_PRESSURE", | ||
"x_coordinates": [], | ||
"y_coordinates": [0.0, 1.0], | ||
"z_coordinates": [0.0, 0.0], | ||
"gravity_direction": 1, | ||
"out_of_plane_direction": 2 | ||
} )"}; | ||
|
||
KRATOS_EXPECT_EXCEPTION_IS_THROWN( | ||
(ApplyConstantPhreaticMultiLinePressureProcess{r_model_part, test_parameters}), | ||
"At least two coordinates in horizontal direction must be given, but got 0") | ||
|
||
test_parameters.RemoveValue("x_coordinates"); | ||
test_parameters.AddVector("x_coordinates", ScalarVector{1, 0.0}); | ||
KRATOS_EXPECT_EXCEPTION_IS_THROWN( | ||
(ApplyConstantPhreaticMultiLinePressureProcess{r_model_part, test_parameters}), | ||
"At least two coordinates in horizontal direction must be given, but got 1") | ||
} | ||
|
||
KRATOS_TEST_CASE_IN_SUITE(ApplyConstantPhreaticMultiLinePressureProcessDoesNotThrowWhenAtLeastTwoCoordinatesInGravityDirectionAreGiven, | ||
KratosGeoMechanicsFastSuiteWithoutKernel) | ||
{ | ||
auto model = Model{}; | ||
auto& r_model_part = model.CreateModelPart("foo"); | ||
auto test_parameters = Parameters{R"( | ||
{ | ||
"model_part_name": "foo", | ||
"variable_name": "WATER_PRESSURE", | ||
"x_coordinates": [0.0, 1.0], | ||
"y_coordinates": [1.0, 2.0], | ||
"z_coordinates": [0.0, 0.0], | ||
"gravity_direction": 1 | ||
} )"}; | ||
|
||
KRATOS_EXPECT_TRUE(CanCreateInstanceOfApplyConstantPhreaticMultiLinePressureProcessWithoutFailure( | ||
r_model_part, test_parameters)) | ||
|
||
test_parameters.RemoveValue("y_coordinates"); | ||
test_parameters.AddVector("y_coordinates", ScalarVector{5, 1.0}); | ||
|
||
KRATOS_EXPECT_TRUE(CanCreateInstanceOfApplyConstantPhreaticMultiLinePressureProcessWithoutFailure( | ||
r_model_part, test_parameters)) | ||
} | ||
|
||
KRATOS_TEST_CASE_IN_SUITE(ApplyConstantPhreaticMultiLinePressureProcessDoesNotThrowWhenAtLeastTwoCoordinatesInHorizontalDirectionAreGiven, | ||
KratosGeoMechanicsFastSuiteWithoutKernel) | ||
{ | ||
auto model = Model{}; | ||
auto& r_model_part = model.CreateModelPart("foo"); | ||
auto test_parameters = Parameters{R"( | ||
{ | ||
"model_part_name": "foo", | ||
"variable_name": "WATER_PRESSURE", | ||
"x_coordinates": [1.0, 2.0], | ||
"y_coordinates": [0.0, 1.0], | ||
"z_coordinates": [0.0, 0.0], | ||
"gravity_direction": 1, | ||
"out_of_plane_direction": 2 | ||
} )"}; | ||
|
||
KRATOS_EXPECT_TRUE(CanCreateInstanceOfApplyConstantPhreaticMultiLinePressureProcessWithoutFailure( | ||
r_model_part, test_parameters)) | ||
|
||
test_parameters.RemoveValue("x_coordinates"); | ||
test_parameters.AddVector("x_coordinates", ScalarVector{5, 1.0}); | ||
|
||
KRATOS_EXPECT_TRUE(CanCreateInstanceOfApplyConstantPhreaticMultiLinePressureProcessWithoutFailure( | ||
r_model_part, test_parameters)) | ||
} | ||
|
||
} // namespace Kratos::Testing |