KratosFSIApplication 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.
@@ -0,0 +1,36 @@
1
+
2
+ # Importing the Kratos Library
3
+ from KratosMultiphysics import *
4
+
5
+ # Import applications
6
+ from KratosMultiphysics.FSIApplication import *
7
+
8
+ def AddVariables(fluid_model_part, structure_model_part):
9
+ fluid_model_part.AddNodalSolutionStepVariable(PRESSURE)
10
+ fluid_model_part.AddNodalSolutionStepVariable(DISPLACEMENT)
11
+ fluid_model_part.AddNodalSolutionStepVariable(IS_INTERFACE)
12
+
13
+ structure_model_part.AddNodalSolutionStepVariable(PRESSURE)
14
+ structure_model_part.AddNodalSolutionStepVariable(DISPLACEMENT)
15
+ structure_model_part.AddNodalSolutionStepVariable(IS_INTERFACE)
16
+
17
+ print("variables for the mesh solver added correctly")
18
+
19
+
20
+ class Conformant_OneSideMap:
21
+
22
+ def __init__(self, fluid_model_part_nodes, structure_model_part_nodes):
23
+ self.FluidToStructureMapper = SharedPointsMapper(fluid_model_part_nodes, structure_model_part_nodes, 1e-9)
24
+ self.StructureToFluidMapper = SharedPointsMapper(structure_model_part_nodes, fluid_model_part_nodes, 1e-9)
25
+
26
+ def StructureToFluid_VectorMap(self, VectorVar_Origin, VectorVar_Destination):
27
+ (self.StructureToFluidMapper).VectorMap(VectorVar_Origin, VectorVar_Destination)
28
+
29
+ def StructureToFluid_ScalarMap(self, ScalarVar_Origin, ScalarVar_Destination):
30
+ (self.StructureToFluidMapper).ScalarMap(ScalarVar_Origin, ScalarVar_Destination)
31
+
32
+ def FluidToStructure_VectorMap(self, VectorVar_Origin, VectorVar_Destination):
33
+ (self.FluidToStructureMapper).VectorMap(VectorVar_Origin, VectorVar_Destination)
34
+
35
+ def FluidToStructure_ScalarMap(self, ScalarVar_Origin, ScalarVar_Destination):
36
+ (self.FluidToStructureMapper).ScalarMap(ScalarVar_Origin, ScalarVar_Destination)
@@ -0,0 +1,6 @@
1
+ from KratosMultiphysics import _ImportApplication
2
+ from KratosFSIApplication import *
3
+ application = KratosFSIApplication()
4
+ application_name = "KratosFSIApplication"
5
+
6
+ _ImportApplication(application, application_name)
@@ -0,0 +1,83 @@
1
+
2
+ # Importing the Kratos Library
3
+ import KratosMultiphysics
4
+
5
+ # Import applications
6
+ import KratosMultiphysics.FSIApplication as KratosFSI
7
+
8
+ import KratosMultiphysics.kratos_utilities as KratosUtilities
9
+ have_trilinos = KratosUtilities.CheckIfApplicationsAvailable("TrilinosApplication")
10
+ is_distributed = KratosMultiphysics.DataCommunicator.GetDefault().IsDistributed()
11
+ if have_trilinos and is_distributed:
12
+ try:
13
+ import KratosMultiphysics.TrilinosApplication as KratosTrilinos
14
+ except Exception as e:
15
+ raise Exception("Trying to create a Trilinos convergence accelerator, but TrilinosApplication could not be found.")
16
+
17
+ have_linear_solvers = KratosUtilities.CheckIfApplicationsAvailable("LinearSolversApplication")
18
+ if have_linear_solvers:
19
+ import KratosMultiphysics.LinearSolversApplication as KratosLinearSolvers
20
+
21
+ def CreateConvergenceAccelerator(configuration):
22
+
23
+ if(type(configuration) != KratosMultiphysics.Parameters):
24
+ raise Exception("Input is expected to be provided as a Kratos Parameters object.")
25
+
26
+ convergence_accelerator_type = configuration["solver_type"].GetString()
27
+
28
+ if(convergence_accelerator_type == "constant_relaxation"):
29
+ return KratosFSI.ConstantRelaxationConvergenceAccelerator(configuration)
30
+
31
+ elif(convergence_accelerator_type == "Relaxation"):
32
+ return KratosFSI.AitkenConvergenceAccelerator(configuration)
33
+
34
+ elif(convergence_accelerator_type == "MVQN"):
35
+ return KratosFSI.MVQNFullJacobianConvergenceAccelerator(configuration)
36
+
37
+ elif(convergence_accelerator_type == "MVQN_randomized_SVD"):
38
+ if not have_linear_solvers:
39
+ err_msg = "MVQN with randomized SVD Jacobian requires the \'LinearSolversApplication\'."
40
+ raise Exception(err_msg)
41
+ bdc_svd = KratosLinearSolvers.EigenDenseBDCSVD()
42
+ col_piv_qr = KratosLinearSolvers.EigenDenseColumnPivotingHouseholderQRDecomposition()
43
+ return KratosFSI.MVQNRandomizedSVDConvergenceAccelerator(col_piv_qr, bdc_svd, configuration)
44
+
45
+ elif(convergence_accelerator_type == "MVQN_recursive"):
46
+ return KratosFSI.MVQNRecursiveJacobianConvergenceAccelerator(configuration)
47
+
48
+ elif(convergence_accelerator_type == "IBQN_MVQN"):
49
+ return KratosFSI.IBQNMVQNConvergenceAccelerator(configuration)
50
+
51
+ elif(convergence_accelerator_type == "IBQN_MVQN_randomized_SVD"):
52
+ if not have_linear_solvers:
53
+ err_msg = "MVQN with randomized SVD Jacobian requires the \'LinearSolversApplication\'."
54
+ raise Exception(err_msg)
55
+ bdc_svd = KratosLinearSolvers.EigenDenseBDCSVD()
56
+ col_piv_qr = KratosLinearSolvers.EigenDenseColumnPivotingHouseholderQRDecomposition()
57
+ return KratosFSI.IBQNMVQNRandomizedSVDConvergenceAccelerator(col_piv_qr, bdc_svd, configuration)
58
+
59
+ else:
60
+ raise Exception("Convergence accelerator not found. Asking for : " + convergence_accelerator_type)
61
+
62
+ return convergence_accelerator
63
+
64
+ def CreateTrilinosConvergenceAccelerator(interface_model_part, epetra_communicator, configuration):
65
+
66
+ if (type(interface_model_part) != KratosMultiphysics.ModelPart):
67
+ raise Exception("First input in Trilinos convergence accelerator factory is expceted to be provided as a Kratos ModelPart object.")
68
+
69
+ if(type(configuration) != KratosMultiphysics.Parameters):
70
+ raise Exception("Third input in Trilinos convergence accelerator factory is expected to be provided as a Kratos Parameters object.")
71
+
72
+ convergence_accelerator_type = configuration["solver_type"].GetString()
73
+
74
+ if(convergence_accelerator_type == "Relaxation"):
75
+ return KratosTrilinos.TrilinosAitkenConvergenceAccelerator(configuration)
76
+
77
+ elif(convergence_accelerator_type == "MVQN_recursive"):
78
+ return KratosTrilinos.TrilinosMVQNRecursiveJacobianConvergenceAccelerator(interface_model_part, epetra_communicator, configuration)
79
+
80
+ else:
81
+ raise Exception("Trilinos convergence accelerator not found. Asking for : " + convergence_accelerator_type)
82
+
83
+ return convergence_accelerator
@@ -0,0 +1,204 @@
1
+
2
+ import KratosMultiphysics as Kratos
3
+ from KratosMultiphysics.analysis_stage import AnalysisStage
4
+ from KratosMultiphysics.FSIApplication import python_solvers_wrapper_fsi
5
+
6
+ class FsiAnalysis(AnalysisStage):
7
+ '''Main script for FSI simulations using the FSI family of python solvers.'''
8
+
9
+ def Initialize(self):
10
+ '''
11
+ Construct and initialize all classes and tools used in the simulation loop.
12
+ '''
13
+ self._SetUpRestart()
14
+
15
+ if self.load_restart:
16
+ fluid_restart_utility = self._GetFluidRestartUtility()
17
+ structure_restart_utility = self._GetStructureRestartUtility()
18
+ fluid_restart_utility.LoadRestart()
19
+ structure_restart_utility.LoadRestart()
20
+ else:
21
+
22
+ # Modelers
23
+ self._CreateModelers()
24
+ self._ModelersSetupGeometryModel()
25
+ self._ModelersPrepareGeometryModel()
26
+ self._ModelersSetupModelPart()
27
+
28
+ self._GetSolver().ImportModelPart()
29
+ self._GetSolver().PrepareModelPart()
30
+ self._GetSolver().AddDofs()
31
+ self.fluid_main_model_part = self.model.GetModelPart(
32
+ self.project_parameters["solver_settings"]["fluid_solver_settings"]["model_part_name"].GetString())
33
+ self.structure_main_model_part = self.model.GetModelPart(
34
+ self.project_parameters["solver_settings"]["structure_solver_settings"]["model_part_name"].GetString())
35
+
36
+ # This should let eventual derived stages modify the model after reading.
37
+ self.ModifyInitialProperties()
38
+ self.ModifyInitialGeometry()
39
+
40
+ # Initialize the user-provided processes
41
+ self._AnalysisStage__CreateListOfProcesses() # Why name mangling?
42
+ for process in self._GetListOfProcesses():
43
+ process.ExecuteInitialize()
44
+
45
+ self._GetSolver().Initialize()
46
+ self.Check()
47
+
48
+ self.ModifyAfterSolverInitialize()
49
+
50
+ for process in self._GetListOfProcesses():
51
+ process.ExecuteBeforeSolutionLoop()
52
+
53
+ ## Stepping and time settings
54
+ self.end_time = self.project_parameters["problem_data"]["end_time"].GetDouble()
55
+
56
+ fluid_is_restarted = self.fluid_main_model_part.ProcessInfo[Kratos.IS_RESTARTED]
57
+ structure_is_restarted = self.structure_main_model_part.ProcessInfo[Kratos.IS_RESTARTED]
58
+ is_restarted = fluid_is_restarted and structure_is_restarted
59
+
60
+ if is_restarted:
61
+ fluid_time = self.fluid_main_model_part.ProcessInfo[Kratos.TIME]
62
+ structure_time = self.structure_main_model_part.ProcessInfo[Kratos.TIME]
63
+ if (abs(fluid_time - structure_time) > 1.0e-12):
64
+ err_msg = 'Fluid restarting time is:' + str(fluid_time) + '\n'
65
+ err_msg += 'Structure restarting time is:' + \
66
+ str(structure_time) + '\n'
67
+ err_msg += 'Restarting time must coincide between subdomains.\n'
68
+ raise Exception(err_msg)
69
+ self.time = fluid_time
70
+ else:
71
+ self.time = self.project_parameters["problem_data"]["start_time"].GetDouble()
72
+ self.fluid_main_model_part.ProcessInfo[Kratos.TIME] = self.time
73
+ self.structure_main_model_part.ProcessInfo[Kratos.TIME] = self.time
74
+
75
+ ## If the echo level is high enough, print the complete list of settings used to run the simulation
76
+ if self.echo_level > 1:
77
+ with open("ProjectParametersOutput.json", 'w') as parameter_output_file:
78
+ parameter_output_file.write(self.project_parameters.PrettyPrintJsonString())
79
+
80
+ Kratos.Logger.PrintInfo(self._GetSimulationName(), "Analysis -START-")
81
+
82
+ def InitializeSolutionStep(self):
83
+
84
+ # Since no substepping is implemented yet, structure and fluid step/time must match
85
+ step_fluid = self.fluid_main_model_part.ProcessInfo[Kratos.STEP]
86
+ step_structure = self.structure_main_model_part.ProcessInfo[Kratos.STEP]
87
+ if step_fluid != step_structure:
88
+ err_msg = 'Fluid step: '+ str(step_fluid) + '\n'
89
+ err_msg += 'Structure step: '+ str(step_structure) + '\n'
90
+ err_msg += 'No substepping has been implemented yet. Fluid and structure step must match.'
91
+ raise Exception(err_msg)
92
+
93
+ Kratos.Logger.PrintInfo(self._GetSimulationName(),"STEP = ", step_fluid)
94
+ Kratos.Logger.PrintInfo(self._GetSimulationName(),"TIME = ", self.time)
95
+
96
+ self.ApplyBoundaryConditions() #here the processes are called
97
+ self.ChangeMaterialProperties() #this is normally empty
98
+ self._GetSolver().InitializeSolutionStep()
99
+
100
+ def OutputSolutionStep(self):
101
+ super().OutputSolutionStep()
102
+
103
+ if self.save_restart:
104
+ fluid_restart_utility = self._GetFluidRestartUtility()
105
+ structure_restart_utility = self._GetStructureRestartUtility()
106
+ fluid_restart_utility.SaveRestart()
107
+ structure_restart_utility.SaveRestart()
108
+
109
+ def _CreateSolver(self):
110
+ return python_solvers_wrapper_fsi.CreateSolver(self.model, self.project_parameters)
111
+
112
+ def _GetSimulationName(self):
113
+ return self.project_parameters["problem_data"]["problem_name"].GetString()
114
+
115
+ def _GetOrderOfProcessesInitialization(self):
116
+ return ["structure_constraints_process_list",
117
+ "structure_contact_process_list",
118
+ "structure_loads_process_list",
119
+ "fluid_gravity",
120
+ "fluid_initial_conditions_process_list",
121
+ "fluid_boundary_conditions_process_list",
122
+ "fluid_auxiliar_process_list"]
123
+
124
+ def _GetOrderOfOutputProcessesInitialization(self):
125
+ return ["gid_output","vtk_output"]
126
+
127
+ def _SetUpRestart(self):
128
+ """Initialize self.restart_utility as a RestartUtility instance and check if we need to initialize the problem from a restart file."""
129
+ has_restart = self.project_parameters.Has("restart_settings")
130
+
131
+ if has_restart:
132
+ raise Exception("FSI restart not implemented yet.")
133
+ else:
134
+
135
+ self.load_restart = False
136
+ self.save_restart = False
137
+
138
+ def _GetFluidRestartUtility(self):
139
+
140
+ if self.__fluid_restart_utility is not None:
141
+ return self.__fluid_restart_utility
142
+ else:
143
+ if self.parallel_type == "OpenMP":
144
+ from restart_utility import RestartUtility as Restart
145
+ elif self.parallel_type == "MPI":
146
+ from KratosMultiphysics.mpi.distributed_restart_utility import DistributedRestartUtility as Restart
147
+ model_part_name = self.project_parameters["fluid_solver_settings"]["solver_settings"]["model_part_name"].GetString()
148
+ if self.model.HasModelPart(model_part_name):
149
+ model_part = self.model.GetModelPart(model_part_name)
150
+ else:
151
+ model_part = self.model.CreateModelPart(model_part_name)
152
+
153
+ self.__fluid_restart_utility = Restart(
154
+ model_part,
155
+ self.project_parameters["fluid_solver_settings"]["restart_settings"])
156
+
157
+ def _GetStructureRestartUtility(self):
158
+
159
+ if self.__structure_restart_utility is not None:
160
+ return self.__structure_restart_utility
161
+ else:
162
+ if self.parallel_type == "OpenMP":
163
+ from restart_utility import RestartUtility as Restart
164
+ elif self.parallel_type == "MPI":
165
+ from KratosMultiphysics.mpi.distributed_restart_utility import DistributedRestartUtility as Restart
166
+
167
+ model_part_name = self.project_parameters["structure_solver_settings"]["solver_settings"]["model_part_name"].GetString()
168
+ if self.model.HasModelPart(model_part_name):
169
+ model_part = self.model.GetModelPart(model_part_name)
170
+ else:
171
+ model_part = self.model.CreateModelPart(model_part_name)
172
+
173
+ self.__structure_restart_utility = Restart(
174
+ model_part,
175
+ self.project_parameters["structure_solver_settings"]["restart_settings"])
176
+
177
+ #TODO: Remove this when the backwards compatibility period is over
178
+ class FSIAnalysis(FsiAnalysis):
179
+ def __init__(self, model, project_parameters):
180
+ Kratos.Logger.PrintWarning("FSIAnalysis", "\'FSIAnalysis\' is deprecated. Use the \'FsiAnalysis\' one instead.")
181
+
182
+ if __name__ == '__main__':
183
+ from sys import argv
184
+
185
+ if len(argv) > 2:
186
+ err_msg = 'Too many input arguments!\n'
187
+ err_msg += 'Use this script in the following way:\n'
188
+ err_msg += '- With default parameter file (assumed to be called "ProjectParameters.json"):\n'
189
+ err_msg += ' "python fsi_analysis.py"\n'
190
+ err_msg += '- With custom parameter file:\n'
191
+ err_msg += ' "python fsi_analysis.py <my-parameter-file>.json"\n'
192
+ raise Exception(err_msg)
193
+
194
+ if len(argv) == 2: # ProjectParameters is being passed from outside
195
+ parameter_file_name = argv[1]
196
+ else: # using default name
197
+ parameter_file_name = "ProjectParameters.json"
198
+
199
+ with open(parameter_file_name,'r') as parameter_file:
200
+ parameters = KratosMultiphysics.Parameters(parameter_file.read())
201
+
202
+ model = KratosMultiphysics.Model()
203
+ simulation = FSIAnalysis(model, parameters)
204
+ simulation.Run()