Skip to content

Commit

Permalink
[GeoMechanicsApplication] Move more unit tests to the suite without k…
Browse files Browse the repository at this point in the history
…ernel (#12661)
  • Loading branch information
rfaasse authored Oct 4, 2024
1 parent 3e10ca1 commit b468212
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// Project includes
#include "containers/model.h"
#include "custom_conditions/Pw_normal_flux_condition.hpp"
#include "custom_constitutive/linear_elastic_2D_interface_law.h"
#include "geo_mechanics_fast_suite.h"

namespace Kratos::Testing
{
KRATOS_TEST_CASE_IN_SUITE(CalculateHorizontalNormalFlux, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateHorizontalNormalFlux, KratosGeoMechanicsFastSuiteWithoutKernel)
{

// initialize modelpart
Expand All @@ -33,8 +34,7 @@ namespace Kratos::Testing
auto cond_prop = r_model_part.CreateNewProperties(0);

// set constitutive law
const auto &r_clone_cl = KratosComponents<ConstitutiveLaw>::Get("LinearElastic2DInterfaceLaw");
cond_prop->SetValue(CONSTITUTIVE_LAW, r_clone_cl.Clone());
cond_prop->SetValue(CONSTITUTIVE_LAW, LinearElastic2DInterfaceLaw().Clone());

// Create the test piping element nodes
auto node_1 = r_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand All @@ -54,8 +54,11 @@ namespace Kratos::Testing

// Create the test piping element
std::vector<ModelPart::IndexType> cond_nodes{1, 2};
auto cond = r_model_part.CreateNewCondition("PwNormalFluxCondition2D2N", 1, cond_nodes, cond_prop);
// Initialize the element to initialize the constitutive law
Condition::Pointer cond = Kratos::make_intrusive<PwNormalFluxCondition<2, 2>>(
1, make_shared<Line2D2<Node>>(node_1, node_2), cond_prop);
r_model_part.AddCondition(cond);

// Initialize the condition to initialize the constitutive law
const auto &r_process_info = r_model_part.GetProcessInfo();
cond->Initialize(r_process_info);

Expand All @@ -82,7 +85,7 @@ namespace Kratos::Testing
}
}

KRATOS_TEST_CASE_IN_SUITE(CalculateInclinedNormalFlux, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateInclinedNormalFlux, KratosGeoMechanicsFastSuiteWithoutKernel)
{

// initialize modelpart
Expand All @@ -96,8 +99,7 @@ namespace Kratos::Testing
auto cond_prop = r_model_part.CreateNewProperties(0);

// set constitutive law
const auto &r_clone_cl = KratosComponents<ConstitutiveLaw>::Get("LinearElastic2DInterfaceLaw");
cond_prop->SetValue(CONSTITUTIVE_LAW, r_clone_cl.Clone());
cond_prop->SetValue(CONSTITUTIVE_LAW, LinearElastic2DInterfaceLaw().Clone());

// Create the test piping element nodes
auto node_1 = r_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand All @@ -117,8 +119,9 @@ namespace Kratos::Testing

// Create the test piping element
std::vector<ModelPart::IndexType> cond_nodes{1, 2};
auto cond = r_model_part.CreateNewCondition("PwNormalFluxCondition2D2N", 1, cond_nodes, cond_prop);
// Initialize the element to initialize the constitutive law
Condition::Pointer cond = Kratos::make_intrusive<PwNormalFluxCondition<2, 2>>(
1, make_shared<Line2D2<Node>>(node_1, node_2), cond_prop);
r_model_part.AddCondition(cond); // Initialize the element to initialize the constitutive law
const auto &r_process_info = r_model_part.GetProcessInfo();
cond->Initialize(r_process_info);

Expand All @@ -144,4 +147,4 @@ namespace Kratos::Testing
1.0e-6);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "containers/model.h"
#include "custom_conditions/T_microclimate_flux_condition.h"
#include "geo_mechanics_fast_suite.h"
#include "geometries/line_2d_4.h"
#include "geometries/line_2d_5.h"

#include <boost/numeric/ublas/assignment.hpp>

Expand Down Expand Up @@ -129,19 +131,53 @@ ModelPart& CreateDummyModelPartWithNodes(Model& rModel,
return r_result;
}

intrusive_ptr<Condition> CreateMicroClimateCondition(ModelPart& rModelPart,
intrusive_ptr<Condition> CreateMicroClimateCondition(ModelPart& rModelPart,
shared_ptr<Properties> pProperties,
std::size_t DimensionSize)
std::size_t DimensionSize)
{
constexpr auto condition_id = std::size_t{1};
auto node_ids = std::vector<ModelPart::IndexType>{};
for (const auto& node : rModelPart.Nodes()) {
node_ids.emplace_back(node.Id());
auto r_nodes = rModelPart.Nodes();
auto node_ids = std::vector<ModelPart::IndexType>{};
std::transform(r_nodes.begin(), r_nodes.end(), std::back_inserter(node_ids),
[](const auto& node) { return node.Id(); });

PointerVector<Node> node_pointers(node_ids.size());
std::transform(node_ids.begin(), node_ids.end(), node_pointers.ptr_begin(),
[&rModelPart](auto node_id) { return rModelPart.pGetNode(node_id); });

Condition::Pointer condition = nullptr;
if (DimensionSize == 2 && node_ids.size() == 2) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<2, 2>>(
1, Kratos::make_shared<Line2D2<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 2 && node_ids.size() == 3) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<2, 3>>(
1, Kratos::make_shared<Line2D3<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 2 && node_ids.size() == 4) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<2, 4>>(
1, Kratos::make_shared<Line2D4<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 2 && node_ids.size() == 5) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<2, 5>>(
1, Kratos::make_shared<Line2D5<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 3 && node_ids.size() == 3) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<3, 3>>(
1, Kratos::make_shared<Triangle3D3<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 3 && node_ids.size() == 6) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<3, 6>>(
1, Kratos::make_shared<Triangle3D6<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 3 && node_ids.size() == 4) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<3, 4>>(
1, Kratos::make_shared<Quadrilateral3D4<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 3 && node_ids.size() == 8) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<3, 8>>(
1, Kratos::make_shared<Quadrilateral3D8<Node>>(node_pointers), pProperties);
} else if (DimensionSize == 3 && node_ids.size() == 9) {
condition = make_intrusive<GeoTMicroClimateFluxCondition<3, 9>>(
1, Kratos::make_shared<Quadrilateral3D9<Node>>(node_pointers), pProperties);
}
const auto condition_name = std::string{"GeoTMicroClimateFluxCondition"}
+ std::to_string(DimensionSize) + "D"
+ std::to_string(node_ids.size()) + "N";
return rModelPart.CreateNewCondition(condition_name, condition_id, node_ids, pProperties);

KRATOS_ERROR_IF_NOT(condition) << "Condition could not be created" << std::endl;

rModelPart.AddCondition(condition);
return condition;
}

std::string ExecuteInitializeSolutionStep(intrusive_ptr<Condition> pCondition,
Expand All @@ -165,7 +201,7 @@ constexpr auto absolute_tolerance = 1.0e-3;

namespace Kratos::Testing {

KRATOS_TEST_CASE_IN_SUITE(NoThrowWhenInitializingThermalMicroClimateCondition, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoThrowWhenInitializingThermalMicroClimateCondition, KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart)
Expand All @@ -192,7 +228,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoThrowWhenInitializingThermalMicroClimateCondition, K
KRATOS_EXPECT_FALSE(has_thrown)
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D2N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D2N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -209,7 +246,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D3N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D3N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -226,7 +264,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D4N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D4N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -243,7 +282,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D5N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition2D5N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -260,7 +300,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D3N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D3N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -277,7 +318,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D6N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D6N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -294,7 +336,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D4N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D4N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -310,7 +353,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D8N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D8N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -326,7 +370,8 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D9N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClimateCondition3D9N,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand All @@ -342,7 +387,7 @@ KRATOS_TEST_CASE_IN_SUITE(NoErrorWhenInitializingSolutionStepOnThermalMicroClima
KRATOS_EXPECT_STREQ(error_text.data(), "")
}

KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition2D3N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition2D3N, KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand Down Expand Up @@ -371,7 +416,7 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition2D3
KRATOS_EXPECT_VECTOR_RELATIVE_NEAR(expected_rhs_vector, rhs_vector, relative_tolerance)
}

KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition3D6N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition3D6N, KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand Down Expand Up @@ -404,7 +449,7 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition3D6
KRATOS_EXPECT_VECTOR_NEAR(expected_rhs_vector, rhs_vector, absolute_tolerance)
}

KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition3D8N, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateLocalSystemForThermalMicroClimateCondition3D8N, KratosGeoMechanicsFastSuiteWithoutKernel)
{
Model test_model;
auto create_nodes_func = [](ModelPart& rModelPart){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ using namespace Kratos;
namespace Kratos::Testing
{

KRATOS_TEST_CASE_IN_SUITE(CalculateBMatrixWithValidGeometryReturnsCorrectResults, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateBMatrixWithValidGeometryReturnsCorrectResults, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();

Model model;
auto& r_model_part = ModelSetupUtilities::CreateModelPartWithASingle2D3NElement(model);

Vector Np(3);
Np <<= 1.0, 2.0, 3.0;

Expand All @@ -43,8 +40,8 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateBMatrixWithValidGeometryReturnsCorrectResults
5.0, 6.0;
// clang-format on

const Matrix calculated_matrix =
p_stress_state_policy->CalculateBMatrix(GradNpT, Np, r_model_part.GetElement(1).GetGeometry());
const Matrix calculated_matrix = p_stress_state_policy->CalculateBMatrix(
GradNpT, Np, ModelSetupUtilities::Create2D3NTriangleGeometry());

// clang-format off
Matrix expected_matrix(4, 6);
Expand All @@ -57,27 +54,24 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateBMatrixWithValidGeometryReturnsCorrectResults
KRATOS_CHECK_MATRIX_NEAR(calculated_matrix, expected_matrix, 1e-12)
}

KRATOS_TEST_CASE_IN_SUITE(ReturnCorrectIntegrationCoefficient, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(ReturnCorrectIntegrationCoefficient, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();

Model model;
auto& r_model_part = ModelSetupUtilities::CreateModelPartWithASingle2D3NElement(model);

// The shape function values for this integration point are 0.2, 0.5 and 0.3 for nodes 1, 2 and 3 respectively
Geometry<Node>::IntegrationPointType integration_point(0.5, 0.3, 0.0, 0.5);

const double detJ = 2.0;
const double calculated_coefficient = p_stress_state_policy->CalculateIntegrationCoefficient(
integration_point, detJ, r_model_part.GetElement(1).GetGeometry());
integration_point, detJ, ModelSetupUtilities::Create2D3NTriangleGeometry());

// The expected number is calculated as follows:
// 2.0 * pi * 0.8 (radius) * 2.0 (detJ) * 0.5 (weight) = 5.02655
KRATOS_EXPECT_NEAR(calculated_coefficient, 5.02655, 1e-5);
}

KRATOS_TEST_CASE_IN_SUITE(TestCloneReturnsCorrectType, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(TestCloneReturnsCorrectType, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();
Expand All @@ -86,7 +80,7 @@ KRATOS_TEST_CASE_IN_SUITE(TestCloneReturnsCorrectType, KratosGeoMechanicsFastSui
KRATOS_EXPECT_NE(dynamic_cast<AxisymmetricStressState*>(p_cloned_stress_state_policy.get()), nullptr);
}

KRATOS_TEST_CASE_IN_SUITE(TestCalculateGreenLagrangeStrainThrows, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(TestCalculateGreenLagrangeStrainThrows, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();
Expand All @@ -100,7 +94,7 @@ KRATOS_TEST_CASE_IN_SUITE(TestCalculateGreenLagrangeStrainThrows, KratosGeoMecha
"not implemented for axisymmetric configurations.")
}

KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectVoigtVector, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectVoigtVector, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();
Expand All @@ -111,14 +105,14 @@ KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectVoigtVector, Krato
KRATOS_EXPECT_VECTOR_NEAR(voigt_vector, expected_voigt_vector, 1.E-10)
}

KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectVoigtSize, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectVoigtSize, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();
KRATOS_EXPECT_EQ(p_stress_state_policy->GetVoigtSize(), VOIGT_SIZE_2D_PLANE_STRAIN);
}

KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectStressTensorSize, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_GivesCorrectStressTensorSize, KratosGeoMechanicsFastSuiteWithoutKernel)
{
const std::unique_ptr<StressStatePolicy> p_stress_state_policy =
std::make_unique<AxisymmetricStressState>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Kratos::Testing

using namespace Kratos;

KRATOS_TEST_CASE_IN_SUITE(CalculateIncrementalDisplacementProcess, KratosGeoMechanicsFastSuite)
KRATOS_TEST_CASE_IN_SUITE(CalculateIncrementalDisplacementProcess, KratosGeoMechanicsFastSuiteWithoutKernel)
{
// set up model part
Model model;
Expand Down
Loading

0 comments on commit b468212

Please sign in to comment.