Skip to content

Commit

Permalink
Processing review comments, reformatting python test with black and r…
Browse files Browse the repository at this point in the history
…emoving SQ code smells
  • Loading branch information
rfaasse committed Feb 21, 2025
1 parent 18ea4ea commit 2a95bfb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class GeoMechanicsSchemeTester
mModel.CreateModelPart("dummy", 2);
}

template <class T, typename AddComponentToModelPartLambda>
template <class T, typename AddComponentToModelPartCallable, typename InitializeComponentsInModelPartCallable>
void TestFunctionCalledOnComponent_IsCalledOnActiveAndInactiveComponents(
AddComponentToModelPartLambda AddComponentTo,
std::function<void(ConcreteGeoMechanicsTimeIntegrationScheme&, ModelPart&)> InitializeComponents)
const AddComponentToModelPartCallable& rAddComponentTo,
const InitializeComponentsInModelPartCallable& rInitializeComponentsInModelPart)
{
typename T::EquationIdVectorType r_equation_id_vector;
ProcessInfo r_process_info;
Expand All @@ -72,8 +72,8 @@ class GeoMechanicsSchemeTester
inactive_component->Set(ACTIVE, false);

auto& r_model_part = mModel.GetModelPart("dummy");
AddComponentTo(r_model_part, active_component);
AddComponentTo(r_model_part, inactive_component);
rAddComponentTo(r_model_part, active_component);
rAddComponentTo(r_model_part, inactive_component);

EXPECT_CALL(*active_component, EquationIdVector(testing::_, testing::_)).Times(1);
mScheme.EquationId(*active_component.get(), r_equation_id_vector, r_process_info);
Expand All @@ -89,7 +89,7 @@ class GeoMechanicsSchemeTester

EXPECT_CALL(*inactive_component, Initialize(testing::_)).Times(1);
EXPECT_CALL(*active_component, Initialize(testing::_)).Times(1);
InitializeComponents(mScheme, r_model_part);
rInitializeComponentsInModelPart(mScheme, r_model_part);
}

template <class T>
Expand Down Expand Up @@ -203,8 +203,7 @@ KRATOS_TEST_CASE_IN_SUITE(FunctionCalledOnCondition_IsCalledOnActiveAndInactiveC
[](auto& rScheme, auto& rModelPart) { rScheme.InitializeConditions(rModelPart); });
}

KRATOS_TEST_CASE_IN_SUITE(FunctionCalledOnElement_IsCalledOnActiveAndInactiveConditions,
KratosGeoMechanicsFastSuiteWithoutKernel)
KRATOS_TEST_CASE_IN_SUITE(FunctionCalledOnElement_IsCalledOnActiveAndInactiveElements, KratosGeoMechanicsFastSuiteWithoutKernel)
{
GeoMechanicsSchemeTester tester;
tester.TestFunctionCalledOnComponent_IsCalledOnActiveAndInactiveComponents<SpyElement>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"RETENTION_LAW" : "SaturatedBelowPhreaticLevelLaw",
"SATURATED_SATURATION" : 1.0,
"RESIDUAL_SATURATION" : 1e-10,
"MINIMUM_RELATIVE_PERMEABILITY" : 0.0001,
"K0_MAIN_DIRECTION" : 1,
"K0_NC" : 0.5
"MINIMUM_RELATIVE_PERMEABILITY" : 0.0001
}
}
},{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
"residual_absolute_tolerance" : 1e-9,
"min_iterations" : 6,
"max_iterations" : 15,
"number_cycles" : 100,
"number_cycles" : 1,
"reduction_factor" : 0.5,
"increase_factor" : 2.0,
"desired_iterations" : 4,
"calculate_reactions" : true,
"calculate_reactions" : false,
"rotation_dofs" : true,
"newmark_beta" : 0.25,
"newmark_gamma" : 0.5,
"newmark_theta" : 0.5,
"problem_domain_sub_model_part_list" : ["Soil","truss"],
"processes_sub_model_part_list" : ["BottomFixed"],
"processes_sub_model_part_list" : ["BottomFixed", "NormalLoad"],
"body_domain_sub_model_part_list" : ["Soil","truss"],
"linear_solver_settings" : {
"solver_type" : "skyline_lu_factorization",
Expand All @@ -67,6 +67,18 @@
"value" : [0.0,0.0,0.0],
"table" : [0,0,0]
}
},{
"python_module" : "apply_vector_constraint_table_process",
"kratos_module" : "KratosMultiphysics.GeoMechanicsApplication",
"process_name" : "ApplyVectorConstraintTableProcess",
"Parameters" : {
"model_part_name" : "PorousDomain.porous_computational_model_part",
"variable_name" : "DISPLACEMENT",
"active" : [true,false,false],
"is_fixed" : [true,false,false],
"value" : [0.0,0.0,0.0],
"table" : [0,0,0]
}
},{
"python_module" : "apply_scalar_constraint_table_process",
"kratos_module" : "KratosMultiphysics.GeoMechanicsApplication",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import glob

import KratosMultiphysics.GeoMechanicsApplication
from KratosMultiphysics.GeoMechanicsApplication.geomechanics_analysis import GeoMechanicsAnalysis
from KratosMultiphysics.GeoMechanicsApplication.geomechanics_analysis import (
GeoMechanicsAnalysis,
)


class KratosGeoMechanicsDeactivationWithStructuralTest(KratosUnittest.TestCase):
"""
Expand All @@ -14,12 +17,11 @@ class KratosGeoMechanicsDeactivationWithStructuralTest(KratosUnittest.TestCase):
"""

def test_deactivation_with_structural_element(self):
test_name = 'deactivation_with_structural_element'
test_name = "deactivation_with_structural_element"
project_path = test_helper.get_file_path(test_name)

file_pattern = os.path.join(project_path, "ProjectParameters_stage*.json")
stage_files = glob.glob(file_pattern)
print(stage_files)

cwd = os.getcwd()
os.chdir(project_path)
Expand All @@ -31,16 +33,29 @@ def test_deactivation_with_structural_element(self):
expected_y_displacements_node_3 = [0.05, -0.1]
expected_y_displacements_node_4 = [0.05, -0.05]

for parameter_file, expected_y_displacement_node_3, expected_y_displacement_node_4 in zip(stage_files, expected_y_displacements_node_3, expected_y_displacements_node_4):
with open(parameter_file,'r') as parameter_file:
for (
parameter_file_path,
expected_y_displacement_node_3,
expected_y_displacement_node_4,
) in zip(
stage_files,
expected_y_displacements_node_3,
expected_y_displacements_node_4,
):
with open(parameter_file_path, "r") as parameter_file:
parameters = KratosMultiphysics.Parameters(parameter_file.read())
simulation = GeoMechanicsAnalysis(model,parameters)
simulation = GeoMechanicsAnalysis(model, parameters)
simulation.Run()
displacements = test_helper.get_displacement(simulation)
self.assertAlmostEqual(displacements[2][1], expected_y_displacement_node_3, 4)
self.assertAlmostEqual(displacements[3][1], expected_y_displacement_node_4, 4)
self.assertAlmostEqual(
displacements[2][1], expected_y_displacement_node_3, 4
)
self.assertAlmostEqual(
displacements[3][1], expected_y_displacement_node_4, 4
)

os.chdir(cwd)

if __name__ == '__main__':

if __name__ == "__main__":
KratosUnittest.main()

0 comments on commit 2a95bfb

Please sign in to comment.