KratosStructuralMechanicsApplication 10.4.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. KratosMultiphysics/.libs/KratosStructuralMechanicsApplication.so +0 -0
  2. KratosMultiphysics/.libs/libKratosStructuralMechanicsCore.dylib +0 -0
  3. KratosMultiphysics/StructuralMechanicsApplication/__init__.py +12 -0
  4. KratosMultiphysics/StructuralMechanicsApplication/adaptative_remeshing_structural_mechanics_analysis.py +214 -0
  5. KratosMultiphysics/StructuralMechanicsApplication/adaptative_remeshing_structural_mechanics_implicit_dynamic_solver.py +69 -0
  6. KratosMultiphysics/StructuralMechanicsApplication/adaptative_remeshing_structural_mechanics_static_solver.py +69 -0
  7. KratosMultiphysics/StructuralMechanicsApplication/adaptative_remeshing_structural_mechanics_utilities.py +94 -0
  8. KratosMultiphysics/StructuralMechanicsApplication/automatic_rayleigh_parameters_computation_process.py +190 -0
  9. KratosMultiphysics/StructuralMechanicsApplication/auxiliary_methods_adaptative_solvers.py +37 -0
  10. KratosMultiphysics/StructuralMechanicsApplication/auxiliary_methods_solvers.py +18 -0
  11. KratosMultiphysics/StructuralMechanicsApplication/check_eigenvalues_process.py +38 -0
  12. KratosMultiphysics/StructuralMechanicsApplication/convergence_criteria_factory.py +146 -0
  13. KratosMultiphysics/StructuralMechanicsApplication/displacement_control_with_direction_process.py +88 -0
  14. KratosMultiphysics/StructuralMechanicsApplication/distribute_load_on_surface_process.py +10 -0
  15. KratosMultiphysics/StructuralMechanicsApplication/eigen_solution_input_process.py +45 -0
  16. KratosMultiphysics/StructuralMechanicsApplication/eigen_solution_output_process.py +45 -0
  17. KratosMultiphysics/StructuralMechanicsApplication/element_sensitivity_domain_integration_process.py +120 -0
  18. KratosMultiphysics/StructuralMechanicsApplication/impose_rigid_movement_process.py +112 -0
  19. KratosMultiphysics/StructuralMechanicsApplication/impose_z_strain_process.py +17 -0
  20. KratosMultiphysics/StructuralMechanicsApplication/kratos_main_structural.py +16 -0
  21. KratosMultiphysics/StructuralMechanicsApplication/linear_load_combination_preparation_analysis.py +202 -0
  22. KratosMultiphysics/StructuralMechanicsApplication/linear_load_combination_solution_analysis.py +283 -0
  23. KratosMultiphysics/StructuralMechanicsApplication/link_constraint_process.py +81 -0
  24. KratosMultiphysics/StructuralMechanicsApplication/perturb_geometry_sparse_utility.py +57 -0
  25. KratosMultiphysics/StructuralMechanicsApplication/perturb_geometry_subgrid_utility.py +57 -0
  26. KratosMultiphysics/StructuralMechanicsApplication/postprocess_eigenvalues_process.py +23 -0
  27. KratosMultiphysics/StructuralMechanicsApplication/project_vector_on_surface_process.py +56 -0
  28. KratosMultiphysics/StructuralMechanicsApplication/python_solvers_wrapper_adaptative_remeshing_structural.py +33 -0
  29. KratosMultiphysics/StructuralMechanicsApplication/python_solvers_wrapper_structural.py +115 -0
  30. KratosMultiphysics/StructuralMechanicsApplication/rve_analysis.py +366 -0
  31. KratosMultiphysics/StructuralMechanicsApplication/set_automated_initial_variable_process.py +102 -0
  32. KratosMultiphysics/StructuralMechanicsApplication/set_cartesian_local_axes_process.py +27 -0
  33. KratosMultiphysics/StructuralMechanicsApplication/set_cylindrical_local_axes_process.py +28 -0
  34. KratosMultiphysics/StructuralMechanicsApplication/set_moving_load_process.py +36 -0
  35. KratosMultiphysics/StructuralMechanicsApplication/set_spherical_local_axes_process.py +25 -0
  36. KratosMultiphysics/StructuralMechanicsApplication/simplified_nodal_contact_process.py +184 -0
  37. KratosMultiphysics/StructuralMechanicsApplication/sprism_process.py +104 -0
  38. KratosMultiphysics/StructuralMechanicsApplication/step_controller.py +210 -0
  39. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_adjoint_static_solver.py +166 -0
  40. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_analysis.py +138 -0
  41. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_custom_scipy_base_solver.py +193 -0
  42. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_eigensolver.py +106 -0
  43. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_explicit_dynamic_solver.py +129 -0
  44. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_formfinding_solver.py +81 -0
  45. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_harmonic_analysis_solver.py +180 -0
  46. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_implicit_dynamic_solver.py +123 -0
  47. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_load_stepping_analysis.py +107 -0
  48. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_prebuckling_analysis.py +97 -0
  49. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_prebuckling_solver.py +118 -0
  50. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_solver.py +642 -0
  51. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_static_shifted_boundary_solver.py +67 -0
  52. KratosMultiphysics/StructuralMechanicsApplication/structural_mechanics_static_solver.py +30 -0
  53. KratosMultiphysics/StructuralMechanicsApplication/structural_response.py +437 -0
  54. KratosMultiphysics/StructuralMechanicsApplication/structural_response_function_factory.py +33 -0
  55. KratosMultiphysics/StructuralMechanicsApplication/structural_sequential_orchestrator.py +18 -0
  56. KratosMultiphysics/StructuralMechanicsApplication/trilinos_convergence_criteria_factory.py +69 -0
  57. KratosMultiphysics/StructuralMechanicsApplication/trilinos_structural_mechanics_implicit_dynamic_solver.py +89 -0
  58. KratosMultiphysics/StructuralMechanicsApplication/trilinos_structural_mechanics_solver.py +136 -0
  59. KratosMultiphysics/StructuralMechanicsApplication/trilinos_structural_mechanics_static_solver.py +26 -0
  60. kratosstructuralmechanicsapplication-10.4.4.dist-info/METADATA +98 -0
  61. kratosstructuralmechanicsapplication-10.4.4.dist-info/RECORD +66 -0
  62. kratosstructuralmechanicsapplication-10.4.4.dist-info/WHEEL +6 -0
  63. kratosstructuralmechanicsapplication.dylibs/libKratosCore.dylib +4 -0
  64. kratosstructuralmechanicsapplication.dylibs/libgcc_s.1.1.dylib +0 -0
  65. kratosstructuralmechanicsapplication.dylibs/libgomp.1.dylib +0 -0
  66. kratosstructuralmechanicsapplication.dylibs/libstdc++.6.dylib +0 -0
@@ -0,0 +1,12 @@
1
+ # Application dependent names and paths
2
+ from KratosMultiphysics import _ImportApplication
3
+ from KratosMultiphysics.kratos_utilities import CheckIfApplicationsAvailable
4
+ from KratosStructuralMechanicsApplication import *
5
+ application = KratosStructuralMechanicsApplication()
6
+ application_name = "KratosStructuralMechanicsApplication"
7
+
8
+ _ImportApplication(application, application_name)
9
+
10
+ if CheckIfApplicationsAvailable("ConstitutiveLawsApplication"):
11
+ # if available import the advanced constitutive laws
12
+ import KratosMultiphysics.ConstitutiveLawsApplication
@@ -0,0 +1,214 @@
1
+ # Importing Kratos
2
+ import KratosMultiphysics as KM
3
+ import KratosMultiphysics.StructuralMechanicsApplication as SMA
4
+
5
+ # Other imports
6
+ from KratosMultiphysics.StructuralMechanicsApplication import python_solvers_wrapper_adaptative_remeshing_structural
7
+
8
+ # Import the base structural analysis
9
+ from KratosMultiphysics.StructuralMechanicsApplication.structural_mechanics_analysis import StructuralMechanicsAnalysis as BaseClass
10
+
11
+ class AdaptativeRemeshingStructuralMechanicsAnalysis(BaseClass):
12
+ """
13
+ This class is the main-script of the StructuralMechanicsApplication when using adaptative remeshing put in a class
14
+
15
+ It can be imported and used as "black-box"
16
+ """
17
+ def __init__(self, model, project_parameters):
18
+
19
+ # Construct the base analysis.
20
+ default_params = KM.Parameters("""
21
+ {
22
+ "max_iteration" : 1,
23
+ "analysis_type" : "linear"
24
+ }
25
+ """)
26
+ if project_parameters["solver_settings"].Has("max_iteration"):
27
+ self.non_linear_iterations = project_parameters["solver_settings"]["max_iteration"].GetInt()
28
+ else:
29
+ self.non_linear_iterations = 10
30
+ project_parameters["solver_settings"].AddValue("max_iteration", default_params["max_iteration"])
31
+ if project_parameters["solver_settings"].Has("analysis_type"):
32
+ project_parameters["solver_settings"]["analysis_type"].SetString("linear")
33
+ else:
34
+ project_parameters["solver_settings"].AddValue("analysis_type", default_params["analysis_type"])
35
+ self.process_remesh = False
36
+ if project_parameters.Has("mesh_adaptivity_processes"):
37
+ self.process_remesh = True
38
+ if project_parameters.Has("processes"):
39
+ if project_parameters["processes"].Has("mesh_adaptivity_processes"):
40
+ self.process_remesh = True
41
+ super().__init__(model, project_parameters)
42
+
43
+ def Initialize(self):
44
+ """ Initializing the Analysis """
45
+ super().Initialize()
46
+ computing_model_part = self._GetSolver().GetComputingModelPart()
47
+ if not self.process_remesh:
48
+ convergence_criteria = self._GetSolver()._GetConvergenceCriterion()
49
+ convergence_criteria.Initialize(computing_model_part)
50
+
51
+ # Ensuring to have conditions on the BC before remesh
52
+ is_surface = False
53
+ for elem in computing_model_part.Elements:
54
+ geom = elem.GetGeometry()
55
+ if geom.WorkingSpaceDimension() != geom.LocalSpaceDimension():
56
+ is_surface = True
57
+ break
58
+
59
+ if not is_surface:
60
+ # We need to detect the conditions in the boundary conditions
61
+ list_model_parts = []
62
+ if self.project_parameters.Has("constraints_process_list"):
63
+ constraints_process_list = self.project_parameters["constraints_process_list"]
64
+ for i in range(0,constraints_process_list.size()):
65
+ item = constraints_process_list[i]
66
+ list_model_parts.append(item["Parameters"]["model_part_name"].GetString())
67
+ skin_detection_parameters = KM.Parameters("""
68
+ {
69
+ "list_model_parts_to_assign_conditions" : []
70
+ }
71
+ """)
72
+ for name_mp in list_model_parts:
73
+ skin_detection_parameters["list_model_parts_to_assign_conditions"].Append(name_mp)
74
+
75
+ if computing_model_part.ProcessInfo[KM.DOMAIN_SIZE] == 2:
76
+ detect_skin = KM.SkinDetectionProcess2D(computing_model_part, skin_detection_parameters)
77
+ else:
78
+ detect_skin = KM.SkinDetectionProcess3D(computing_model_part, skin_detection_parameters)
79
+ detect_skin.Execute()
80
+ self._GetSolver().SetEchoLevel(self.echo_level)
81
+
82
+ def RunSolutionLoop(self):
83
+ """This function executes the solution loop of the AnalysisStage
84
+ It can be overridden by derived classes
85
+ """
86
+
87
+ # If we remesh using a process
88
+ computing_model_part = self._GetSolver().GetComputingModelPart()
89
+ root_model_part = computing_model_part.GetRootModelPart()
90
+ if self.process_remesh:
91
+ while self.time < self.end_time:
92
+ self.time = self._GetSolver().AdvanceInTime(self.time)
93
+ # We reinitialize if remeshed previously
94
+ if root_model_part.Is(KM.MODIFIED):
95
+ self._ReInitializeSolver()
96
+ self.InitializeSolutionStep()
97
+ # We reinitialize if remeshed on the InitializeSolutionStep
98
+ if root_model_part.Is(KM.MODIFIED):
99
+ self._ReInitializeSolver()
100
+ self.InitializeSolutionStep()
101
+ self._GetSolver().Predict()
102
+ self._GetSolver().SolveSolutionStep()
103
+ self.FinalizeSolutionStep()
104
+ self.OutputSolutionStep()
105
+ else: # Remeshing adaptively
106
+ metric_process = self._GetSolver().get_metric_process()
107
+ remeshing_process = self._GetSolver().get_remeshing_process()
108
+ convergence_criteria = self._GetSolver()._GetConvergenceCriterion()
109
+ builder_and_solver = self._GetSolver()._GetBuilderAndSolver()
110
+ mechanical_solution_strategy = self._GetSolver()._GetSolutionStrategy()
111
+
112
+ while self.time < self.end_time:
113
+ self.time = self._GetSolver().AdvanceInTime(self.time)
114
+ non_linear_iteration = 1
115
+ while non_linear_iteration <= self.non_linear_iterations:
116
+ if root_model_part.Is(KM.MODIFIED):
117
+ self._ReInitializeSolver()
118
+ if non_linear_iteration == 1 or root_model_part.Is(KM.MODIFIED):
119
+ self.InitializeSolutionStep()
120
+ self._GetSolver().Predict()
121
+ computing_model_part.Set(KM.MODIFIED, False)
122
+ computing_model_part.ProcessInfo.SetValue(KM.NL_ITERATION_NUMBER, non_linear_iteration)
123
+ reform_dofs = mechanical_solution_strategy.GetReformDofSetAtEachStepFlag()
124
+ mechanical_solution_strategy.SetReformDofSetAtEachStepFlag(True)
125
+ is_converged = convergence_criteria.PreCriteria(computing_model_part, builder_and_solver.GetDofSet(), mechanical_solution_strategy.GetSystemMatrix(), mechanical_solution_strategy.GetSolutionVector(), mechanical_solution_strategy.GetSystemVector())
126
+ self._GetSolver().SolveSolutionStep()
127
+ is_converged = convergence_criteria.PostCriteria(computing_model_part, builder_and_solver.GetDofSet(), mechanical_solution_strategy.GetSystemMatrix(), mechanical_solution_strategy.GetSolutionVector(), mechanical_solution_strategy.GetSystemVector())
128
+ self.FinalizeSolutionStep()
129
+ mechanical_solution_strategy.SetReformDofSetAtEachStepFlag(reform_dofs)
130
+ if is_converged:
131
+ KM.Logger.PrintInfo(self._GetSimulationName(), "Adaptative strategy converged in ", non_linear_iteration, "iterations" )
132
+ break
133
+ elif non_linear_iteration == self.non_linear_iterations:
134
+ KM.Logger.PrintInfo(self._GetSimulationName(), "Adaptative strategy not converged after ", non_linear_iteration, "iterations" )
135
+ break
136
+ else:
137
+ metric_process.Execute()
138
+ remeshing_process.Execute()
139
+ computing_model_part.Set(KM.MODIFIED, True)
140
+ non_linear_iteration += 1
141
+ self.OutputSolutionStep()
142
+
143
+ #### Internal functions ####
144
+ def _CreateSolver(self):
145
+ """ Create the Solver (and create and import the ModelPart if it is not already in the model) """
146
+
147
+ # To avoid many prints
148
+ if (self.echo_level == 0):
149
+ KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING)
150
+
151
+ ## Solver construction
152
+ return python_solvers_wrapper_adaptative_remeshing_structural.CreateSolver(self.model, self.project_parameters)
153
+
154
+ def _CreateProcesses(self, parameter_name, initialization_order):
155
+ """Create a list of Processes
156
+ This method is TEMPORARY to not break existing code
157
+ It will be removed in the future
158
+ """
159
+ list_of_processes = super()._CreateProcesses(parameter_name, initialization_order)
160
+
161
+ if parameter_name == "processes":
162
+ processes_block_names = ["mesh_adaptivity_processes"]
163
+ if len(list_of_processes) == 0: # Processes are given in the old format
164
+ KM.Logger.PrintWarning("AdaptativeRemeshingStructuralMechanicsAnalysis", "Using the old way to create the processes, this will be removed!")
165
+ from process_factory import KratosProcessFactory
166
+ factory = KratosProcessFactory(self.model)
167
+ for process_name in processes_block_names:
168
+ if self.project_parameters.Has(process_name):
169
+ list_of_processes += factory.ConstructListOfProcesses(self.project_parameters[process_name])
170
+ else: # Processes are given in the new format
171
+ for process_name in processes_block_names:
172
+ if self.project_parameters.Has(process_name):
173
+ raise Exception("Mixing of process initialization is not allowed!")
174
+ elif parameter_name == "output_processes":
175
+ pass # Already added
176
+ else:
177
+ raise NameError("wrong parameter name")
178
+
179
+ return list_of_processes
180
+
181
+ def _ReInitializeSolver(self):
182
+ """ This reinitializes after remesh """
183
+ self._GetSolver().Clear()
184
+ # WE INITIALIZE THE SOLVER
185
+ self._GetSolver().Initialize()
186
+ # WE RECOMPUTE THE PROCESSES AGAIN
187
+ ## Processes initialization
188
+ for process in self._GetListOfProcesses():
189
+ process.ExecuteInitialize()
190
+ ## Processes before the loop
191
+ for process in self._GetListOfProcesses():
192
+ process.ExecuteBeforeSolutionLoop()
193
+ ## Processes of initialize the solution step
194
+ for process in self._GetListOfProcesses():
195
+ process.ExecuteInitializeSolutionStep()
196
+
197
+ if __name__ == "__main__":
198
+ from sys import argv
199
+
200
+ if len(argv) > 2:
201
+ err_msg = 'Too many input arguments!\n'
202
+ err_msg += 'Use this script in the following way:\n'
203
+ err_msg += '- With default ProjectParameters (read from "ProjectParameters.json"):\n'
204
+ err_msg += ' "python3 contact_structural_mechanics_analysis.py"\n'
205
+ err_msg += '- With custom ProjectParameters:\n'
206
+ err_msg += ' "python3 contact_structural_mechanics_analysis.py CustomProjectParameters.json"\n'
207
+ raise Exception(err_msg)
208
+
209
+ if len(argv) == 2: # ProjectParameters is being passed from outside
210
+ project_parameters_file_name = argv[1]
211
+ else: # using default name
212
+ project_parameters_file_name = "ProjectParameters.json"
213
+
214
+ AdaptativeRemeshingStructuralMechanicsAnalysis(project_parameters_file_name).Run()
@@ -0,0 +1,69 @@
1
+ # Importing the Kratos Library
2
+ import KratosMultiphysics
3
+
4
+ # Import applications
5
+ import KratosMultiphysics.StructuralMechanicsApplication as StructuralMechanicsApplication
6
+
7
+ import KratosMultiphysics.kratos_utilities as kratos_utilities
8
+ if kratos_utilities.CheckIfApplicationsAvailable("MeshingApplication"):
9
+ import KratosMultiphysics.MeshingApplication as MeshingApplication
10
+ missing_meshing_dependencies = True
11
+ else:
12
+ missing_meshing_dependencies = False
13
+
14
+ # Import base class file
15
+ from KratosMultiphysics.StructuralMechanicsApplication import structural_mechanics_implicit_dynamic_solver
16
+
17
+ # Import auxiliary methods
18
+ from KratosMultiphysics.StructuralMechanicsApplication import auxiliary_methods_adaptative_solvers
19
+ from KratosMultiphysics.StructuralMechanicsApplication import adaptative_remeshing_structural_mechanics_utilities
20
+
21
+ def CreateSolver(model, custom_settings):
22
+ return AdaptativeRemeshingImplicitMechanicalSolver(model, custom_settings)
23
+
24
+ class AdaptativeRemeshingImplicitMechanicalSolver(structural_mechanics_implicit_dynamic_solver.ImplicitMechanicalSolver):
25
+ """The structural mechanics implicit dynamic solver. (For adaptative remeshing)
26
+ See structural_mechanics_implicit_dynamic_solver.py for more information.
27
+ """
28
+ def __init__(self, model, custom_settings):
29
+ # Set defaults and validate custom settings.
30
+ self.adaptative_remeshing_utilities = adaptative_remeshing_structural_mechanics_utilities.AdaptativeRemeshingMechanicalUtilities()
31
+
32
+ # Construct the base solver.
33
+ super().__init__(model, custom_settings)
34
+ KratosMultiphysics.Logger.PrintInfo("::[AdaptativeRemeshingImplicitMechanicalSolver]:: ", "Construction finished")
35
+
36
+ #### Private functions ####
37
+
38
+ def AddVariables(self):
39
+ super().AddVariables()
40
+ if not missing_meshing_dependencies:
41
+ self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NODAL_H)
42
+ KratosMultiphysics.Logger.PrintInfo("::[AdaptativeRemeshingImplicitMechanicalSolver]:: ", "Variables ADDED")
43
+
44
+ def get_remeshing_process(self):
45
+ if not hasattr(self, '_remeshing_process'):
46
+ self._remeshing_process = self._create_remeshing_process()
47
+ return self._remeshing_process
48
+
49
+ def _create_remeshing_process(self):
50
+ return auxiliary_methods_adaptative_solvers.CreateRemeshingProcess(self.main_model_part, self.settings)
51
+
52
+ def get_metric_process(self):
53
+ if not hasattr(self, '_metric_process'):
54
+ self._metric_process = self._create_metric_process()
55
+ return self._metric_process
56
+
57
+ def _create_metric_process(self):
58
+ return auxiliary_methods_adaptative_solvers.CreateMetricProcess(self.main_model_part, self.settings)
59
+
60
+ def _CreateConvergenceCriterion(self):
61
+ error_criteria = self.settings["convergence_criterion"].GetString()
62
+ conv_settings = self._get_convergence_criterion_settings()
63
+ return self.adaptative_remeshing_utilities.GetConvergenceCriteria(error_criteria, conv_settings)
64
+
65
+ @classmethod
66
+ def GetDefaultParameters(cls):
67
+ this_defaults = adaptative_remeshing_structural_mechanics_utilities.AdaptativeRemeshingMechanicalUtilities().GetDefaultParameters()
68
+ this_defaults.AddMissingParameters(super().GetDefaultParameters())
69
+ return this_defaults
@@ -0,0 +1,69 @@
1
+ # Importing the Kratos Library
2
+ import KratosMultiphysics
3
+
4
+ # Import applications
5
+ import KratosMultiphysics.StructuralMechanicsApplication as StructuralMechanicsApplication
6
+
7
+ import KratosMultiphysics.kratos_utilities as kratos_utilities
8
+ if kratos_utilities.CheckIfApplicationsAvailable("MeshingApplication"):
9
+ import KratosMultiphysics.MeshingApplication as MeshingApplication
10
+ missing_meshing_dependencies = True
11
+ else:
12
+ missing_meshing_dependencies = False
13
+
14
+ # Import base class file
15
+ from KratosMultiphysics.StructuralMechanicsApplication import structural_mechanics_static_solver
16
+
17
+ # Import auxiliary methods
18
+ from KratosMultiphysics.StructuralMechanicsApplication import auxiliary_methods_adaptative_solvers
19
+ from KratosMultiphysics.StructuralMechanicsApplication import adaptative_remeshing_structural_mechanics_utilities
20
+
21
+ def CreateSolver(model, custom_settings):
22
+ return AdaptativeRemeshingStaticMechanicalSolver(model, custom_settings)
23
+
24
+ class AdaptativeRemeshingStaticMechanicalSolver(structural_mechanics_static_solver.StaticMechanicalSolver):
25
+ """The structural mechanics static solver. (For adaptative remeshing)
26
+ See structural_mechanics_static_solver.py for more information.
27
+ """
28
+ def __init__(self, model, custom_settings):
29
+ # Set defaults and validate custom settings.
30
+ self.adaptative_remeshing_utilities = adaptative_remeshing_structural_mechanics_utilities.AdaptativeRemeshingMechanicalUtilities()
31
+
32
+ # Construct the base solver.
33
+ super().__init__(model, custom_settings)
34
+ KratosMultiphysics.Logger.PrintInfo("::[AdaptativeRemeshingStaticMechanicalSolver]:: ", "Construction finished")
35
+
36
+ #### Private functions ####
37
+
38
+ def AddVariables(self):
39
+ super().AddVariables()
40
+ if not missing_meshing_dependencies:
41
+ self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NODAL_H)
42
+ KratosMultiphysics.Logger.PrintInfo("::[AdaptativeRemeshingStaticMechanicalSolver]:: ", "Variables ADDED")
43
+
44
+ def get_remeshing_process(self):
45
+ if not hasattr(self, '_remeshing_process'):
46
+ self._remeshing_process = self._create_remeshing_process()
47
+ return self._remeshing_process
48
+
49
+ def _create_remeshing_process(self):
50
+ return auxiliary_methods_adaptative_solvers.CreateRemeshingProcess(self.main_model_part, self.settings)
51
+
52
+ def get_metric_process(self):
53
+ if not hasattr(self, '_metric_process'):
54
+ self._metric_process = self._create_metric_process()
55
+ return self._metric_process
56
+
57
+ def _create_metric_process(self):
58
+ return auxiliary_methods_adaptative_solvers.CreateMetricProcess(self.main_model_part, self.settings)
59
+
60
+ def _CreateConvergenceCriterion(self):
61
+ error_criteria = self.settings["convergence_criterion"].GetString()
62
+ conv_settings = self._get_convergence_criterion_settings()
63
+ return self.adaptative_remeshing_utilities.GetConvergenceCriteria(error_criteria, conv_settings)
64
+
65
+ @classmethod
66
+ def GetDefaultParameters(cls):
67
+ this_defaults = adaptative_remeshing_structural_mechanics_utilities.AdaptativeRemeshingMechanicalUtilities().GetDefaultParameters()
68
+ this_defaults.AddMissingParameters(super().GetDefaultParameters())
69
+ return this_defaults
@@ -0,0 +1,94 @@
1
+ # Importing the Kratos Library
2
+ import KratosMultiphysics
3
+
4
+ # Import applications
5
+ import KratosMultiphysics.StructuralMechanicsApplication as StructuralMechanicsApplication
6
+ from KratosMultiphysics.StructuralMechanicsApplication import convergence_criteria_factory
7
+
8
+ try:
9
+ import KratosMultiphysics.MeshingApplication as MeshingApplication
10
+ missing_meshing_dependencies = False
11
+ missing_application = ''
12
+ except ImportError as e:
13
+ missing_meshing_dependencies = True
14
+ # extract name of the missing application from the error message
15
+ import re
16
+ missing_application = re.search(r'''.*'KratosMultiphysics\.(.*)'.*''','{0}'.format(e)).group(1)
17
+
18
+ class AdaptativeRemeshingMechanicalUtilities(object):
19
+ """These are common utilities for adaptative remeshing
20
+ """
21
+
22
+ def __init__(self):
23
+ self.adaptative_remesh_parameters = KratosMultiphysics.Parameters("""
24
+ {
25
+ "compute_error_settings" : {
26
+ "error_mesh_tolerance" : 5.0e-3,
27
+ "error_mesh_constant" : 5.0e-3,
28
+ "compute_error_extra_parameters":
29
+ {
30
+ "stress_vector_variable" : "CAUCHY_STRESS_VECTOR",
31
+ "echo_level" : 0
32
+ }
33
+ },
34
+ "metric_error_parameters" :
35
+ {
36
+ "minimal_size" : 0.01,
37
+ "maximal_size" : 1.0,
38
+ "error_strategy_parameters":
39
+ {
40
+ "target_error" : 0.01,
41
+ "set_target_number_of_elements" : false,
42
+ "target_number_of_elements" : 1000,
43
+ "perform_nodal_h_averaging" : false
44
+ },
45
+ "echo_level" : 0
46
+ },
47
+ "remeshing_parameters":
48
+ {
49
+ "filename" : "out",
50
+ "framework" : "Lagrangian",
51
+ "internal_variables_parameters" :
52
+ {
53
+ "allocation_size" : 1000,
54
+ "bucket_size" : 4,
55
+ "search_factor" : 2,
56
+ "interpolation_type" : "LST",
57
+ "internal_variable_interpolation_list" :[]
58
+ },
59
+ "save_external_files" : false,
60
+ "max_number_of_searchs" : 1000,
61
+ "echo_level" : 0
62
+ }
63
+ }
64
+ """)
65
+
66
+ def GetDefaultParameters(self):
67
+ return self.adaptative_remesh_parameters
68
+
69
+ def SetDefaultParameters(self, settings):
70
+ self.adaptative_remesh_parameters = settings
71
+
72
+ def GetConvergenceCriteria(self, error_criteria, conv_settings):
73
+ if ("_with_adaptative_remesh" in error_criteria):
74
+ conv_settings["convergence_criterion"].SetString(error_criteria.replace("_with_adaptative_remesh", ""))
75
+ # If we just use the adaptative convergence criteria
76
+ if (missing_meshing_dependencies is True):
77
+ if ("adaptative_remesh" in error_criteria):
78
+ raise NameError('The AdaptativeErrorCriteria can not be used without compiling the MeshingApplication')
79
+ else:
80
+ if (error_criteria == "adaptative_remesh_criteria"):
81
+ adaptative_error_criteria = StructuralMechanicsApplication.ErrorMeshCriteria(self.adaptative_remesh_parameters["compute_error_settings"])
82
+ adaptative_error_criteria.SetEchoLevel(conv_settings["echo_level"].GetInt())
83
+ return adaptative_error_criteria
84
+
85
+ # Regular convergence criteria
86
+ convergence_criterion = convergence_criteria_factory.convergence_criterion(conv_settings)
87
+
88
+ # If we combine the regular convergence criteria with adaptative
89
+ if (missing_meshing_dependencies is False):
90
+ if ("_with_adaptative_remesh" in error_criteria):
91
+ adaptative_error_criteria = StructuralMechanicsApplication.ErrorMeshCriteria(self.adaptative_remesh_parameters["compute_error_settings"])
92
+ adaptative_error_criteria.SetEchoLevel(conv_settings["echo_level"].GetInt())
93
+ convergence_criterion.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(convergence_criterion.mechanical_convergence_criterion, adaptative_error_criteria)
94
+ return convergence_criterion.mechanical_convergence_criterion
@@ -0,0 +1,190 @@
1
+ # Importing the Kratos Library
2
+ import KratosMultiphysics as KM
3
+ from KratosMultiphysics import eigen_solver_factory
4
+
5
+ import KratosMultiphysics.StructuralMechanicsApplication as SMA
6
+
7
+ def Factory(settings, Model):
8
+ if not isinstance(settings, KM.Parameters):
9
+ raise Exception("Expected input shall be a Parameters object, encapsulating a json string")
10
+ return AutomaticRayleighComputationProcess(Model, settings["Parameters"])
11
+
12
+ # All the processes python processes should be derived from "Process"
13
+
14
+ class AutomaticRayleighComputationProcess(KM.Process):
15
+ """This class is used in order to compute automatically the Rayleigh damping parameters computing in first place the eigenvalues of the system
16
+
17
+ Only the member variables listed below should be accessed directly.
18
+
19
+ Public member variables:
20
+ Model -- the container of the different model parts.
21
+ settings -- Kratos parameters containing the settings.
22
+ """
23
+
24
+ def __init__(self, Model, settings):
25
+ """ The default constructor of the class
26
+
27
+ Keyword arguments:
28
+ self -- It signifies an instance of a class.
29
+ Model -- the container of the different model parts.
30
+ settings -- Kratos parameters containing solver settings.
31
+ """
32
+ KM.Process.__init__(self)
33
+
34
+ # Settings string in json format
35
+ default_parameters = KM.Parameters("""
36
+ {
37
+ "help" :"This class is used in order to compute automatically the Rayleigh damping parameters computing in first place the eigenvalues of the system",
38
+ "model_part_name" : "Structure",
39
+ "echo_level" : 0,
40
+ "write_on_properties" : true,
41
+ "damping_ratio_0" : 0.0,
42
+ "damping_ratio_1" : -1.0,
43
+ "eigen_values_vector" : [0.0],
44
+ "eigen_system_settings" : {
45
+ "solver_type" : "eigen_eigensystem"
46
+ }
47
+ }
48
+ """)
49
+
50
+ # Setting solver settings
51
+ if settings.Has("eigen_system_settings"):
52
+ if not settings["eigen_system_settings"].Has("solver_type"):
53
+ settings["eigen_system_settings"].AddValue("solver_type", default_parameters["eigen_system_settings"]["solver_type"])
54
+ else:
55
+ settings.AddValue("eigen_system_settings", default_parameters["eigen_system_settings"])
56
+ solver_type = settings["eigen_system_settings"]["solver_type"].GetString()
57
+ eigen_system_settings = self._auxiliary_eigen_settings(solver_type)
58
+ default_parameters["eigen_system_settings"] = eigen_system_settings["eigen_system_settings"]
59
+
60
+ # Overwrite the default settings with user-provided parameters
61
+ self.settings = settings
62
+ self.settings.RecursivelyValidateAndAssignDefaults(default_parameters)
63
+
64
+ # We define the model parts
65
+ self.model = Model
66
+ self.main_model_part = self.model[self.settings["model_part_name"].GetString()]
67
+
68
+ def ExecuteBeforeSolutionLoop(self):
69
+ """ This method is executed before starting the time loop
70
+
71
+ Keyword arguments:
72
+ self -- It signifies an instance of a class.
73
+ """
74
+
75
+ # The general damping ratios
76
+ damping_ratio_0 = self.settings["damping_ratio_0"].GetDouble()
77
+ damping_ratio_1 = self.settings["damping_ratio_1"].GetDouble()
78
+
79
+ # We get the model parts which divide the problem
80
+ current_process_info = self.main_model_part.ProcessInfo
81
+ existing_computation = current_process_info.Has(SMA.EIGENVALUE_VECTOR)
82
+
83
+ # Create auxiliary parameters
84
+ compute_damping_coefficients_settings = KM.Parameters("""
85
+ {
86
+ "echo_level" : 0,
87
+ "damping_ratio_0" : 0.0,
88
+ "damping_ratio_1" : -1.0,
89
+ "eigen_values_vector" : [0.0]
90
+ }
91
+ """)
92
+
93
+ # Setting custom parameters
94
+ compute_damping_coefficients_settings["echo_level"].SetInt(self.settings["echo_level"].GetInt())
95
+ compute_damping_coefficients_settings["damping_ratio_0"].SetDouble(damping_ratio_0)
96
+ compute_damping_coefficients_settings["damping_ratio_1"].SetDouble(damping_ratio_1)
97
+
98
+ # We check if the values are previously defined
99
+ properties = self.main_model_part.GetProperties()
100
+ for prop in properties:
101
+ if prop.Has(SMA.SYSTEM_DAMPING_RATIO):
102
+ self.settings["damping_ratio_0"].SetDouble(prop.GetValue(SMA.SYSTEM_DAMPING_RATIO))
103
+ break
104
+ for prop in properties:
105
+ if prop.Has(SMA.SECOND_SYSTEM_DAMPING_RATIO):
106
+ self.settings["damping_ratio_1"].SetDouble(prop.GetValue(SMA.SECOND_SYSTEM_DAMPING_RATIO))
107
+ break
108
+
109
+ # We have computed already the eigen values
110
+ current_process_info = self.main_model_part.ProcessInfo
111
+ precomputed_eigen_values = self.settings["eigen_values_vector"].GetVector()
112
+ if len(precomputed_eigen_values) > 1:
113
+ compute_damping_coefficients_settings["eigen_values_vector"].SetVector(precomputed_eigen_values)
114
+ else:
115
+ # If not computed eigen values already
116
+ if not existing_computation:
117
+ KM.Logger.PrintInfo("::[MechanicalSolver]::", "EIGENVALUE_VECTOR not previously computed. Computing automatically, take care")
118
+ eigen_linear_solver = eigen_solver_factory.ConstructSolver(self.settings["eigen_system_settings"])
119
+ builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(eigen_linear_solver)
120
+ eigen_scheme = SMA.EigensolverDynamicScheme()
121
+ eigen_solver = SMA.EigensolverStrategy(self.main_model_part, eigen_scheme, builder_and_solver,
122
+ self.mass_matrix_diagonal_value,
123
+ self.stiffness_matrix_diagonal_value)
124
+ eigen_solver.Solve()
125
+
126
+ # Setting the variable RESET_EQUATION_IDS
127
+ current_process_info[SMA.RESET_EQUATION_IDS] = True
128
+
129
+ eigenvalue_vector = current_process_info.GetValue(SMA.EIGENVALUE_VECTOR)
130
+ compute_damping_coefficients_settings["eigen_values_vector"].SetVector(eigenvalue_vector)
131
+
132
+ # We compute the coefficients
133
+ coefficients_vector = SMA.ComputeDampingCoefficients(compute_damping_coefficients_settings)
134
+
135
+ # We set the values
136
+ if self.settings["write_on_properties"].GetBool():
137
+ for prop in self.main_model_part.Properties:
138
+ prop.SetValue(SMA.RAYLEIGH_ALPHA, coefficients_vector[0])
139
+ if current_process_info.Has(KM.COMPUTE_LUMPED_MASS_MATRIX):
140
+ if current_process_info[KM.COMPUTE_LUMPED_MASS_MATRIX]:
141
+ prop.SetValue(SMA.RAYLEIGH_BETA, 0.0)
142
+ else:
143
+ prop.SetValue(SMA.RAYLEIGH_BETA, coefficients_vector[1])
144
+ else:
145
+ prop.SetValue(SMA.RAYLEIGH_BETA, coefficients_vector[1])
146
+ else:
147
+ current_process_info.SetValue(SMA.RAYLEIGH_ALPHA, coefficients_vector[0])
148
+ if current_process_info.Has(KM.COMPUTE_LUMPED_MASS_MATRIX):
149
+ if current_process_info[KM.COMPUTE_LUMPED_MASS_MATRIX]:
150
+ current_process_info.SetValue(SMA.RAYLEIGH_BETA, 0.0)
151
+ else:
152
+ current_process_info.SetValue(SMA.RAYLEIGH_BETA, coefficients_vector[1])
153
+ else:
154
+ current_process_info.SetValue(SMA.RAYLEIGH_BETA, coefficients_vector[1])
155
+
156
+ def _auxiliary_eigen_settings(self, solver_type):
157
+ """ This method returns the settings for the eigenvalues computations
158
+
159
+ Keyword arguments:
160
+ self -- It signifies an instance of a class.
161
+ """
162
+ if solver_type == "feast":
163
+ eigen_system_settings = KM.Parameters("""
164
+ {
165
+ "eigen_system_settings" : {
166
+ "solver_type" : "feast",
167
+ "echo_level" : 0,
168
+ "tolerance" : 1e-10,
169
+ "symmetric" : true,
170
+ "e_min" : 0.0,
171
+ "e_max" : 4.0e5,
172
+ "number_of_eigenvalues" : 2,
173
+ "subspace_size" : 15
174
+ }
175
+ }
176
+ """)
177
+ self.mass_matrix_diagonal_value = 1.0
178
+ self.stiffness_matrix_diagonal_value = -1.0
179
+ else:
180
+ eigen_system_settings = KM.Parameters("""
181
+ {
182
+ "eigen_system_settings" : {
183
+ "solver_type" : "eigen_eigensystem"
184
+ }
185
+ }
186
+ """)
187
+ eigen_system_settings["eigen_system_settings"]["solver_type"].SetString(solver_type)
188
+ self.mass_matrix_diagonal_value = 0.0
189
+ self.stiffness_matrix_diagonal_value = 1.0
190
+ return eigen_system_settings