Skip to content

Commit

Permalink
Merge pull request #11659 from KratosMultiphysics/convdiff/test-utili…
Browse files Browse the repository at this point in the history
…ties-creation

[ConvDiff] ConvectionDiffusionApplication testing utilities
  • Loading branch information
rubenzorrilla authored Oct 5, 2023
2 parents f268475 + d3bfc44 commit 2a052f2
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 398 deletions.
5 changes: 4 additions & 1 deletion applications/ConvectionDiffusionApplication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ set( KRATOS_CONVECTION_DIFFUSION_PYTHON_INTERFACE_SOURCES

## define test sources
if(${KRATOS_BUILD_TESTING} MATCHES ON)
file(GLOB_RECURSE KRATOS_CONVECTION_DIFFUSION_TESTING_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp_tests/*.cpp)
file( GLOB_RECURSE KRATOS_CONVECTION_DIFFUSION_TESTING_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp_tests/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_utilities/*.cpp
)
endif(${KRATOS_BUILD_TESTING} MATCHES ON)

###############################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,24 @@

// Application includes
#include "convection_diffusion_application.h"
#include "../test_utilities/convection_diffusion_testing_utilities.h"


namespace Kratos
{
namespace Testing
namespace Kratos::Testing
{
void SetDConvectionDiffusionExplicitTestModelPart(ModelPart &rModelPart)

KRATOS_TEST_CASE_IN_SUITE(DConvectionDiffusionExplicit2D3N, KratosConvectionDiffusionFastSuite)
{
// Set buffer size
rModelPart.SetBufferSize(2);

// Set convection diffusion settings
ConvectionDiffusionSettings::Pointer p_conv_dff_set = Kratos::make_shared<ConvectionDiffusionSettings>();
p_conv_dff_set->SetDensityVariable(DENSITY);
p_conv_dff_set->SetDiffusionVariable(CONDUCTIVITY);
p_conv_dff_set->SetUnknownVariable(TEMPERATURE);
p_conv_dff_set->SetVolumeSourceVariable(HEAT_FLUX);
p_conv_dff_set->SetSurfaceSourceVariable(FACE_HEAT_FLUX);
p_conv_dff_set->SetProjectionVariable(PROJECTED_SCALAR1);
p_conv_dff_set->SetConvectionVariable(CONVECTION_VELOCITY);
p_conv_dff_set->SetMeshVelocityVariable(MESH_VELOCITY);
p_conv_dff_set->SetVelocityVariable(VELOCITY);
p_conv_dff_set->SetSpecificHeatVariable(SPECIFIC_HEAT);
p_conv_dff_set->SetReactionVariable(REACTION_FLUX);
rModelPart.GetProcessInfo().SetValue(CONVECTION_DIFFUSION_SETTINGS, p_conv_dff_set);

// Variables addition
rModelPart.AddNodalSolutionStepVariable(DENSITY);
rModelPart.AddNodalSolutionStepVariable(CONDUCTIVITY);
rModelPart.AddNodalSolutionStepVariable(TEMPERATURE);
rModelPart.AddNodalSolutionStepVariable(HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(FACE_HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(PROJECTED_SCALAR1);
rModelPart.AddNodalSolutionStepVariable(CONVECTION_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(MESH_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(VELOCITY);
rModelPart.AddNodalSolutionStepVariable(SPECIFIC_HEAT);
rModelPart.AddNodalSolutionStepVariable(REACTION_FLUX);

// Create a fake properties container
auto p_elem_prop = rModelPart.CreateNewProperties(0);
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = rModelPart.GetProcessInfo();
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);
r_process_info.SetValue(OSS_SWITCH, 1);
r_process_info.SetValue(RUNGE_KUTTA_STEP, 4);
}

KRATOS_TEST_CASE_IN_SUITE(DConvectionDiffusionExplicit2D3N, KratosConvectionDiffusionFastSuite)
{
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetDConvectionDiffusionExplicitTestModelPart(r_test_model_part);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -115,7 +77,14 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetDConvectionDiffusionExplicitTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);
r_process_info.SetValue(OSS_SWITCH, 1);
r_process_info.SetValue(RUNGE_KUTTA_STEP, 4);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -155,7 +124,14 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetDConvectionDiffusionExplicitTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);
r_process_info.SetValue(OSS_SWITCH, 1);
r_process_info.SetValue(RUNGE_KUTTA_STEP, 4);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -197,7 +173,14 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetDConvectionDiffusionExplicitTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);
r_process_info.SetValue(OSS_SWITCH, 1);
r_process_info.SetValue(RUNGE_KUTTA_STEP, 4);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -233,5 +216,4 @@ namespace Testing
}
}

} // namespace Testing
} // namespace Kratos
} // namespace Kratos::Testing.
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,20 @@
// Application includes
#include "convection_diffusion_application.h"
#include "convection_diffusion_application_variables.h"
#include "../test_utilities/convection_diffusion_testing_utilities.h"


namespace Kratos {
namespace Testing
namespace Kratos::Testing
{
void SetEmbeddedLaplacianElementTestModelPart(ModelPart &rModelPart)
{
// Set buffer size
rModelPart.SetBufferSize(1);

// Set convection diffusion settings
ConvectionDiffusionSettings::Pointer p_conv_dff_set = Kratos::make_shared<ConvectionDiffusionSettings>();
p_conv_dff_set->SetDensityVariable(DENSITY);
p_conv_dff_set->SetDiffusionVariable(CONDUCTIVITY);
p_conv_dff_set->SetUnknownVariable(TEMPERATURE);
p_conv_dff_set->SetVolumeSourceVariable(HEAT_FLUX);
p_conv_dff_set->SetSurfaceSourceVariable(FACE_HEAT_FLUX);
p_conv_dff_set->SetProjectionVariable(PROJECTED_SCALAR1);
p_conv_dff_set->SetConvectionVariable(CONVECTION_VELOCITY);
p_conv_dff_set->SetMeshVelocityVariable(MESH_VELOCITY);
p_conv_dff_set->SetVelocityVariable(VELOCITY);
p_conv_dff_set->SetSpecificHeatVariable(SPECIFIC_HEAT);
p_conv_dff_set->SetReactionVariable(REACTION_FLUX);
rModelPart.GetProcessInfo().SetValue(CONVECTION_DIFFUSION_SETTINGS, p_conv_dff_set);

// Variables addition
rModelPart.AddNodalSolutionStepVariable(DENSITY);
rModelPart.AddNodalSolutionStepVariable(CONDUCTIVITY);
rModelPart.AddNodalSolutionStepVariable(TEMPERATURE);
rModelPart.AddNodalSolutionStepVariable(HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(FACE_HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(PROJECTED_SCALAR1);
rModelPart.AddNodalSolutionStepVariable(CONVECTION_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(MESH_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(VELOCITY);
rModelPart.AddNodalSolutionStepVariable(SPECIFIC_HEAT);
rModelPart.AddNodalSolutionStepVariable(REACTION_FLUX);
rModelPart.AddNodalSolutionStepVariable(DISTANCE);

// Create a fake properties container
auto p_elem_prop = rModelPart.CreateNewProperties(0);
}

KRATOS_TEST_CASE_IN_SUITE(EmbeddedLaplacianElement2D3N, KratosConvectionDiffusionFastSuite)
{
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetEmbeddedLaplacianElementTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Add the DISTANCE variable (not added by SetEntityUnitTestModelPart)
r_test_model_part.AddNodalSolutionStepVariable(DISTANCE);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -98,7 +63,7 @@ namespace Testing
// Set distances for uncut element
p_element->GetGeometry()[0].FastGetSolutionStepValue(DISTANCE) = 1.0;
p_element->GetGeometry()[1].FastGetSolutionStepValue(DISTANCE) = 1.0;
p_element->GetGeometry()[2].FastGetSolutionStepValue(DISTANCE) = 1.0;
p_element->GetGeometry()[2].FastGetSolutionStepValue(DISTANCE) = 1.0;

// Test uncut element
p_element->CalculateLocalSystem(LHS, RHS, r_process_info);
Expand All @@ -109,7 +74,7 @@ namespace Testing
// Set distances for intersected element
p_element->GetGeometry()[0].FastGetSolutionStepValue(DISTANCE) = -1.0;
p_element->GetGeometry()[1].FastGetSolutionStepValue(DISTANCE) = -1.0;
p_element->GetGeometry()[2].FastGetSolutionStepValue(DISTANCE) = 0.5;
p_element->GetGeometry()[2].FastGetSolutionStepValue(DISTANCE) = 0.5;

// Test intersected element
p_element->CalculateLocalSystem(LHS, RHS, r_process_info);
Expand All @@ -118,5 +83,4 @@ namespace Testing
KRATOS_EXPECT_VECTOR_NEAR(RHS, expected_RHS, 1.0e-4);
}

} // namespace Testing
} // namespace Kratos.
} // namespace Kratos::Testing.
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,23 @@

// Application includes
#include "convection_diffusion_application.h"
#include "../test_utilities/convection_diffusion_testing_utilities.h"


namespace Kratos
{
namespace Testing
namespace Kratos::Testing
{
void SetEulerianConvDiffTestModelPart(ModelPart &rModelPart)
{
// Set buffer size
rModelPart.SetBufferSize(2);

// Set convection diffusion settings
ConvectionDiffusionSettings::Pointer p_conv_dff_set = Kratos::make_shared<ConvectionDiffusionSettings>();
p_conv_dff_set->SetDensityVariable(DENSITY);
p_conv_dff_set->SetDiffusionVariable(CONDUCTIVITY);
p_conv_dff_set->SetUnknownVariable(TEMPERATURE);
p_conv_dff_set->SetVolumeSourceVariable(HEAT_FLUX);
p_conv_dff_set->SetSurfaceSourceVariable(FACE_HEAT_FLUX);
p_conv_dff_set->SetProjectionVariable(PROJECTED_SCALAR1);
p_conv_dff_set->SetConvectionVariable(CONVECTION_VELOCITY);
p_conv_dff_set->SetMeshVelocityVariable(MESH_VELOCITY);
p_conv_dff_set->SetVelocityVariable(VELOCITY);
p_conv_dff_set->SetSpecificHeatVariable(SPECIFIC_HEAT);
p_conv_dff_set->SetReactionVariable(REACTION_FLUX);
rModelPart.GetProcessInfo().SetValue(CONVECTION_DIFFUSION_SETTINGS, p_conv_dff_set);

// Variables addition
rModelPart.AddNodalSolutionStepVariable(DENSITY);
rModelPart.AddNodalSolutionStepVariable(CONDUCTIVITY);
rModelPart.AddNodalSolutionStepVariable(TEMPERATURE);
rModelPart.AddNodalSolutionStepVariable(HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(FACE_HEAT_FLUX);
rModelPart.AddNodalSolutionStepVariable(PROJECTED_SCALAR1);
rModelPart.AddNodalSolutionStepVariable(CONVECTION_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(MESH_VELOCITY);
rModelPart.AddNodalSolutionStepVariable(VELOCITY);
rModelPart.AddNodalSolutionStepVariable(SPECIFIC_HEAT);
rModelPart.AddNodalSolutionStepVariable(REACTION_FLUX);

// Create a fake properties container
auto p_elem_prop = rModelPart.CreateNewProperties(0);

// Fill the process info container
auto &r_process_info = rModelPart.GetProcessInfo();
r_process_info.SetValue(TIME_INTEGRATION_THETA, 1.0);
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);
}

KRATOS_TEST_CASE_IN_SUITE(EulerianConvDiff2D3NNullConvection, KratosConvectionDiffusionFastSuite)
{
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetEulerianConvDiffTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(TIME_INTEGRATION_THETA, 1.0);
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -120,7 +82,13 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetEulerianConvDiffTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(TIME_INTEGRATION_THETA, 1.0);
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -169,7 +137,13 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetEulerianConvDiffTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(TIME_INTEGRATION_THETA, 1.0);
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -225,7 +199,13 @@ namespace Testing
// Create the test element
Model model;
auto &r_test_model_part = model.CreateModelPart("TestModelPart");
SetEulerianConvDiffTestModelPart(r_test_model_part);
ConvectionDiffusionTestingUtilities::SetEntityUnitTestModelPart(r_test_model_part);

// Fill the process info container
auto &r_process_info = r_test_model_part.GetProcessInfo();
r_process_info.SetValue(TIME_INTEGRATION_THETA, 1.0);
r_process_info.SetValue(DELTA_TIME, 0.1);
r_process_info.SetValue(DYNAMIC_TAU, 1.0);

// Element creation
r_test_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
Expand Down Expand Up @@ -276,5 +256,4 @@ namespace Testing
KRATOS_EXPECT_MATRIX_NEAR(LHS, expected_LHS, 1.0e-4)
}

} // namespace Testing
} // namespace Kratos.
} // namespace Kratos::Testing.
Loading

0 comments on commit 2a052f2

Please sign in to comment.