KratosConvectionDiffusionApplication 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.
- KratosMultiphysics/.libs/KratosConvectionDiffusionApplication.so +0 -0
- KratosMultiphysics/.libs/libKratosConvectionDiffusionCore.dylib +0 -0
- KratosMultiphysics/ConvectionDiffusionApplication/__init__.py +8 -0
- KratosMultiphysics/ConvectionDiffusionApplication/adjoint_diffusion_solver.py +255 -0
- KratosMultiphysics/ConvectionDiffusionApplication/apply_thermal_face_process.py +57 -0
- KratosMultiphysics/ConvectionDiffusionApplication/conjugate_heat_transfer_solver.py +549 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_analysis.py +60 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_explicit_solver.py +91 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_semi_eulerian_solver.py +157 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_solver.py +816 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_stationary_embedded_solver.py +153 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_stationary_matrix_solver.py +85 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_stationary_shifted_boundary_solver.py +115 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_stationary_solver.py +53 -0
- KratosMultiphysics/ConvectionDiffusionApplication/convection_diffusion_transient_solver.py +62 -0
- KratosMultiphysics/ConvectionDiffusionApplication/coupled_fluid_thermal_solver.py +189 -0
- KratosMultiphysics/ConvectionDiffusionApplication/coupled_structural_thermal_solver.py +175 -0
- KratosMultiphysics/ConvectionDiffusionApplication/move_particle_utility_process.py +83 -0
- KratosMultiphysics/ConvectionDiffusionApplication/python_solvers_wrapper_convection_diffusion.py +110 -0
- KratosMultiphysics/ConvectionDiffusionApplication/response_functions/__init__.py +0 -0
- KratosMultiphysics/ConvectionDiffusionApplication/response_functions/convection_diffusion_response.py +145 -0
- KratosMultiphysics/ConvectionDiffusionApplication/response_functions/convection_diffusion_response_function_factory.py +13 -0
- kratosconvectiondiffusionapplication-10.4.4.dist-info/METADATA +50 -0
- kratosconvectiondiffusionapplication-10.4.4.dist-info/RECORD +29 -0
- kratosconvectiondiffusionapplication-10.4.4.dist-info/WHEEL +6 -0
- kratosconvectiondiffusionapplication.dylibs/libKratosCore.dylib +4 -0
- kratosconvectiondiffusionapplication.dylibs/libgcc_s.1.1.dylib +0 -0
- kratosconvectiondiffusionapplication.dylibs/libgomp.1.dylib +0 -0
- kratosconvectiondiffusionapplication.dylibs/libstdc++.6.dylib +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
# Application dependent names and paths
|
|
3
|
+
from KratosMultiphysics import _ImportApplication
|
|
4
|
+
from KratosConvectionDiffusionApplication import *
|
|
5
|
+
application = KratosConvectionDiffusionApplication()
|
|
6
|
+
application_name = "KratosConvectionDiffusionApplication"
|
|
7
|
+
|
|
8
|
+
_ImportApplication(application, application_name)
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import KratosMultiphysics as kratos
|
|
2
|
+
import KratosMultiphysics.ConvectionDiffusionApplication as convdiff
|
|
3
|
+
|
|
4
|
+
from KratosMultiphysics.python_solver import PythonSolver
|
|
5
|
+
|
|
6
|
+
def CreateSolver(model, settings):
|
|
7
|
+
return AdjointDiffusionSolver(model, settings)
|
|
8
|
+
|
|
9
|
+
class AdjointDiffusionSolver(PythonSolver):
|
|
10
|
+
|
|
11
|
+
def __init__(self, model, custom_settings):
|
|
12
|
+
super().__init__(model,custom_settings)
|
|
13
|
+
|
|
14
|
+
self.min_buffer_size = 1
|
|
15
|
+
|
|
16
|
+
model_part_name = self.settings["model_part_name"].GetString()
|
|
17
|
+
if model_part_name == "":
|
|
18
|
+
raise Exception("Empty model_part_name provided")
|
|
19
|
+
|
|
20
|
+
if self.model.HasModelPart(model_part_name):
|
|
21
|
+
self.model_part = self.model.GetModelPart(model_part_name)
|
|
22
|
+
self.solver_imports_model_part = False
|
|
23
|
+
else:
|
|
24
|
+
self.model_part = self.model.CreateModelPart(model_part_name)
|
|
25
|
+
|
|
26
|
+
domain_size = self.settings["domain_size"].GetInt()
|
|
27
|
+
if domain_size not in (2,3):
|
|
28
|
+
raise Exception("Unsupported domain_size: ", domain_size)
|
|
29
|
+
|
|
30
|
+
self.model_part.ProcessInfo[kratos.DOMAIN_SIZE] = domain_size
|
|
31
|
+
self.solver_imports_model_part = True
|
|
32
|
+
|
|
33
|
+
self.DefineConvectionDiffusionSettings(self.settings["convection_diffusion_variables"])
|
|
34
|
+
|
|
35
|
+
self.primal_model_part_name = self.settings["primal_model_part_name"].GetString()
|
|
36
|
+
if self.primal_model_part_name == "":
|
|
37
|
+
raise Exception("No primal_model_part_name provided")
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def GetDefaultParameters(cls):
|
|
41
|
+
|
|
42
|
+
default_settings = kratos.Parameters(r'''{
|
|
43
|
+
"solver_type" : "adjoint_stationary",
|
|
44
|
+
"model_part_name": "",
|
|
45
|
+
"primal_model_part_name" : "",
|
|
46
|
+
"domain_size": 0,
|
|
47
|
+
"model_import_settings" : {
|
|
48
|
+
"input_type" : "mdpa",
|
|
49
|
+
"input_filename" : ""
|
|
50
|
+
},
|
|
51
|
+
"convection_diffusion_variables" : {
|
|
52
|
+
"diffusion_variable" : "CONDUCTIVITY",
|
|
53
|
+
"unknown_variable" : "TEMPERATURE",
|
|
54
|
+
"volume_source_variable" : "HEAT_FLUX",
|
|
55
|
+
"surface_source_variable" : "FACE_HEAT_FLUX"
|
|
56
|
+
},
|
|
57
|
+
"material_import_settings" :{
|
|
58
|
+
"materials_filename": ""
|
|
59
|
+
},
|
|
60
|
+
"linear_solver_settings" : {
|
|
61
|
+
"solver_type" : "amgcl"
|
|
62
|
+
},
|
|
63
|
+
"response_function_settings" : {
|
|
64
|
+
"response_type" : "point_temperature"
|
|
65
|
+
},
|
|
66
|
+
"sensitivity_settings" : {},
|
|
67
|
+
"element_replace_settings" : {
|
|
68
|
+
"element_name" : "AdjointDiffusionElement",
|
|
69
|
+
"condition_name" : "AdjointThermalFace"
|
|
70
|
+
},
|
|
71
|
+
"time_stepping" : {
|
|
72
|
+
"time_step" : 0.0
|
|
73
|
+
},
|
|
74
|
+
"time_integration_method": "implicit"
|
|
75
|
+
}''')
|
|
76
|
+
|
|
77
|
+
default_settings.AddMissingParameters(super().GetDefaultParameters())
|
|
78
|
+
return default_settings
|
|
79
|
+
|
|
80
|
+
def AddVariables(self):
|
|
81
|
+
convection_diffusion_settings = self.model_part.ProcessInfo[kratos.CONVECTION_DIFFUSION_SETTINGS]
|
|
82
|
+
|
|
83
|
+
self.model_part.AddNodalSolutionStepVariable(convection_diffusion_settings.GetUnknownVariable())
|
|
84
|
+
self.model_part.AddNodalSolutionStepVariable(convection_diffusion_settings.GetDiffusionVariable())
|
|
85
|
+
self.model_part.AddNodalSolutionStepVariable(convection_diffusion_settings.GetVolumeSourceVariable())
|
|
86
|
+
self.model_part.AddNodalSolutionStepVariable(convection_diffusion_settings.GetSurfaceSourceVariable())
|
|
87
|
+
self.model_part.AddNodalSolutionStepVariable(convdiff.ADJOINT_HEAT_TRANSFER)
|
|
88
|
+
self.model_part.AddNodalSolutionStepVariable(kratos.SHAPE_SENSITIVITY)
|
|
89
|
+
|
|
90
|
+
def AddDofs(self):
|
|
91
|
+
variable_utils = kratos.VariableUtils()
|
|
92
|
+
variable_utils.AddDof(convdiff.ADJOINT_HEAT_TRANSFER, self.model_part)
|
|
93
|
+
|
|
94
|
+
def ImportModelPart(self):
|
|
95
|
+
# we can use the default implementation in the base class
|
|
96
|
+
if self.solver_imports_model_part:
|
|
97
|
+
self._ImportModelPart(self.model_part,self.settings["model_import_settings"])
|
|
98
|
+
|
|
99
|
+
def PrepareModelPart(self):
|
|
100
|
+
if self.solver_imports_model_part:
|
|
101
|
+
# ensure that the element type is the correct one
|
|
102
|
+
self._set_elements_and_conditions()
|
|
103
|
+
|
|
104
|
+
# check mesh orientation (tetrahedral mesh orientation check)
|
|
105
|
+
throw_errors = False
|
|
106
|
+
kratos.TetrahedralMeshOrientationCheck(self.model_part, throw_errors).Execute()
|
|
107
|
+
|
|
108
|
+
# set the buffer size
|
|
109
|
+
if self.model_part.GetBufferSize() < self.min_buffer_size:
|
|
110
|
+
self.model_part.SetBufferSize(self.min_buffer_size)
|
|
111
|
+
|
|
112
|
+
# initialize the adjoint model part using primal results
|
|
113
|
+
primal_model_part = self.model.GetModelPart(self.primal_model_part_name)
|
|
114
|
+
variable_utils = kratos.VariableUtils()
|
|
115
|
+
variable_utils.CopyModelPartNodalVar(kratos.CONDUCTIVITY, primal_model_part, self.model_part, 0)
|
|
116
|
+
variable_utils.CopyModelPartNodalVar(kratos.TEMPERATURE, primal_model_part, self.model_part, 0)
|
|
117
|
+
variable_utils.CopyModelPartNodalVar(kratos.HEAT_FLUX, primal_model_part, self.model_part, 0)
|
|
118
|
+
variable_utils.CopyModelPartNodalVar(kratos.FACE_HEAT_FLUX, primal_model_part, self.model_part, 0)
|
|
119
|
+
|
|
120
|
+
self.ImportMaterials()
|
|
121
|
+
|
|
122
|
+
def ImportMaterials(self):
|
|
123
|
+
materials_filename = self.settings["material_import_settings"]["materials_filename"].GetString()
|
|
124
|
+
if (materials_filename != ""):
|
|
125
|
+
with open(materials_filename, 'r') as parameter_file:
|
|
126
|
+
materials = kratos.Parameters(parameter_file.read())
|
|
127
|
+
|
|
128
|
+
for i in range(materials["properties"].size()):
|
|
129
|
+
model_part = self.model.GetModelPart(materials["properties"][i]["model_part_name"].GetString())
|
|
130
|
+
mat = materials["properties"][i]["Material"]
|
|
131
|
+
var_utils = kratos.VariableUtils()
|
|
132
|
+
for key, value in mat["Variables"].items():
|
|
133
|
+
var = kratos.KratosGlobals.GetVariable(key)
|
|
134
|
+
#if not model_part.HasNodalSolutionStepVariable(var):
|
|
135
|
+
# raise Exception("Trying to set variable {0} on nodes, but the variable is not in nodal data.".format(var.Name()))
|
|
136
|
+
if model_part.HasNodalSolutionStepVariable(var):
|
|
137
|
+
if value.IsDouble():
|
|
138
|
+
var_utils.SetScalarVar(var, value.GetDouble(), model_part.Nodes)
|
|
139
|
+
elif value.IsVector():
|
|
140
|
+
var_utils.SetVectorVar(var, value.GetVector(), model_part.Nodes)
|
|
141
|
+
else:
|
|
142
|
+
raise ValueError("Type of value is not available")
|
|
143
|
+
else:
|
|
144
|
+
kratos.Logger.PrintWarning("Ignoring variable {0} given by the materials file, since it is not a nodal variable used by this solver.".format(var.Name()))
|
|
145
|
+
|
|
146
|
+
def DefineConvectionDiffusionSettings(self,settings):
|
|
147
|
+
convection_diffusion_settings = kratos.ConvectionDiffusionSettings()
|
|
148
|
+
|
|
149
|
+
convection_diffusion_settings.SetDiffusionVariable(
|
|
150
|
+
kratos.KratosGlobals.GetVariable(settings["diffusion_variable"].GetString()))
|
|
151
|
+
convection_diffusion_settings.SetUnknownVariable(
|
|
152
|
+
kratos.KratosGlobals.GetVariable(settings["unknown_variable"].GetString()))
|
|
153
|
+
convection_diffusion_settings.SetVolumeSourceVariable(
|
|
154
|
+
kratos.KratosGlobals.GetVariable(settings["volume_source_variable"].GetString()))
|
|
155
|
+
convection_diffusion_settings.SetSurfaceSourceVariable(
|
|
156
|
+
kratos.KratosGlobals.GetVariable(settings["surface_source_variable"].GetString()))
|
|
157
|
+
|
|
158
|
+
self.model_part.ProcessInfo.SetValue(kratos.CONVECTION_DIFFUSION_SETTINGS,convection_diffusion_settings)
|
|
159
|
+
|
|
160
|
+
def GetComputingModelPart(self):
|
|
161
|
+
return self.model_part
|
|
162
|
+
|
|
163
|
+
def Initialize(self):
|
|
164
|
+
|
|
165
|
+
if self.settings["response_function_settings"]["response_type"].GetString() == "point_temperature":
|
|
166
|
+
self.response_function = convdiff.LocalTemperatureAverageResponseFunction(self.settings["response_function_settings"]["custom_settings"],self.model_part)
|
|
167
|
+
else:
|
|
168
|
+
raise Exception("invalid response_type: " + self.settings["response_function_settings"]["response_type"].GetString())
|
|
169
|
+
|
|
170
|
+
self.sensitivity_builder = kratos.SensitivityBuilder(self.settings["sensitivity_settings"], self.model_part, self.response_function)
|
|
171
|
+
|
|
172
|
+
import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory
|
|
173
|
+
self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"])
|
|
174
|
+
|
|
175
|
+
self.time_scheme = kratos.ResidualBasedAdjointStaticScheme(self.response_function)
|
|
176
|
+
|
|
177
|
+
builder_and_solver = kratos.ResidualBasedBlockBuilderAndSolver(self.linear_solver)
|
|
178
|
+
|
|
179
|
+
self.solver = kratos.ResidualBasedLinearStrategy(self.model_part,
|
|
180
|
+
self.time_scheme,
|
|
181
|
+
builder_and_solver,
|
|
182
|
+
False,
|
|
183
|
+
False,
|
|
184
|
+
False,
|
|
185
|
+
False)
|
|
186
|
+
|
|
187
|
+
self.solver.SetEchoLevel(self.settings["echo_level"].GetInt())
|
|
188
|
+
|
|
189
|
+
self.solver.Initialize()
|
|
190
|
+
self.response_function.Initialize()
|
|
191
|
+
self.sensitivity_builder.Initialize()
|
|
192
|
+
kratos.Logger.PrintInfo(self.__class__.__name__, "Solver initialization finished.")
|
|
193
|
+
|
|
194
|
+
def InitializeSolutionStep(self):
|
|
195
|
+
self.solver.InitializeSolutionStep()
|
|
196
|
+
self.response_function.InitializeSolutionStep()
|
|
197
|
+
|
|
198
|
+
def Predict(self):
|
|
199
|
+
self.solver.Predict()
|
|
200
|
+
|
|
201
|
+
def SolveSolutionStep(self):
|
|
202
|
+
return self.solver.SolveSolutionStep()
|
|
203
|
+
|
|
204
|
+
def FinalizeSolutionStep(self):
|
|
205
|
+
(self.solver).FinalizeSolutionStep()
|
|
206
|
+
self.response_function.FinalizeSolutionStep()
|
|
207
|
+
self.sensitivity_builder.UpdateSensitivities()
|
|
208
|
+
|
|
209
|
+
def Check(self):
|
|
210
|
+
(self.solver).Check()
|
|
211
|
+
|
|
212
|
+
def Clear(self):
|
|
213
|
+
(self.solver).Clear()
|
|
214
|
+
|
|
215
|
+
def AdvanceInTime(self, current_time):
|
|
216
|
+
dt = self.ComputeDeltaTime()
|
|
217
|
+
new_time = current_time + dt
|
|
218
|
+
self.model_part.ProcessInfo[kratos.STEP] += 1
|
|
219
|
+
self.model_part.CloneTimeStep(new_time)
|
|
220
|
+
|
|
221
|
+
return new_time
|
|
222
|
+
|
|
223
|
+
def ComputeDeltaTime(self):
|
|
224
|
+
return self.settings["time_stepping"]["time_step"].GetDouble()
|
|
225
|
+
|
|
226
|
+
def _set_elements_and_conditions(self):
|
|
227
|
+
|
|
228
|
+
domain_size = self.model_part.ProcessInfo[kratos.DOMAIN_SIZE]
|
|
229
|
+
comm = self.model_part.GetCommunicator().GetDataCommunicator()
|
|
230
|
+
|
|
231
|
+
element_name = self.settings["element_replace_settings"]["element_name"].GetString()
|
|
232
|
+
condition_name = self.settings["element_replace_settings"]["condition_name"].GetString()
|
|
233
|
+
|
|
234
|
+
num_nodes_elements = 0
|
|
235
|
+
for elem in self.model_part.Elements:
|
|
236
|
+
num_nodes_elements = len(elem.GetNodes())
|
|
237
|
+
break
|
|
238
|
+
num_nodes_elements = comm.MaxAll(num_nodes_elements)
|
|
239
|
+
|
|
240
|
+
if element_name == "AdjointDiffusionElement":
|
|
241
|
+
name_string = "{0}{1}D{2}N".format(element_name,domain_size, num_nodes_elements)
|
|
242
|
+
self.settings["element_replace_settings"]["element_name"].SetString(name_string)
|
|
243
|
+
|
|
244
|
+
num_nodes_conditions = 0
|
|
245
|
+
for cond in self.model_part.Conditions:
|
|
246
|
+
num_nodes_conditions = len(cond.GetNodes())
|
|
247
|
+
break
|
|
248
|
+
num_nodes_conditions = comm.MaxAll(num_nodes_conditions)
|
|
249
|
+
|
|
250
|
+
if condition_name == "AdjointThermalFace":
|
|
251
|
+
name_string = "{0}{1}D{2}N".format(condition_name,domain_size, num_nodes_conditions)
|
|
252
|
+
self.settings["element_replace_settings"]["condition_name"].SetString(name_string)
|
|
253
|
+
|
|
254
|
+
## Call the replace elements and conditions process
|
|
255
|
+
kratos.ReplaceElementsAndConditionsProcess(self.model_part, self.settings["element_replace_settings"]).Execute()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import KratosMultiphysics
|
|
2
|
+
import KratosMultiphysics.ConvectionDiffusionApplication as KratosConvDiff
|
|
3
|
+
|
|
4
|
+
def Factory(settings, Model):
|
|
5
|
+
if(type(settings) != KratosMultiphysics.Parameters):
|
|
6
|
+
raise Exception("expected input shall be a Parameters object, encapsulating a json string")
|
|
7
|
+
return ApplyThermalFaceProcess(Model, settings["Parameters"])
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ApplyThermalFaceProcess(KratosMultiphysics.Process):
|
|
11
|
+
def __init__(self, Model, settings):
|
|
12
|
+
KratosMultiphysics.Process.__init__(self)
|
|
13
|
+
|
|
14
|
+
# Compare with default settings
|
|
15
|
+
default_settings = KratosMultiphysics.Parameters(r'''{
|
|
16
|
+
"model_part_name": "",
|
|
17
|
+
"ambient_temperature": 0.0,
|
|
18
|
+
"add_ambient_radiation": false,
|
|
19
|
+
"emissivity": 0.0,
|
|
20
|
+
"add_ambient_convection": false,
|
|
21
|
+
"convection_coefficient": 0.0,
|
|
22
|
+
"interval": [0.0,1e30]
|
|
23
|
+
}''')
|
|
24
|
+
|
|
25
|
+
settings.ValidateAndAssignDefaults(default_settings)
|
|
26
|
+
|
|
27
|
+
# Check input data
|
|
28
|
+
if (settings["model_part_name"].GetString() == ""):
|
|
29
|
+
raise Exception("Empty thermal face model part name string. Set a valid model part name.")
|
|
30
|
+
if not settings["ambient_temperature"].IsDouble():
|
|
31
|
+
raise Exception("Ambient temperature must be a constant value. Time dependency not implemented yet.")
|
|
32
|
+
|
|
33
|
+
# Search for the maximum property id in the current model
|
|
34
|
+
# Note that this operation is required to be performed after
|
|
35
|
+
# the properties have been already set by reading the materials.json
|
|
36
|
+
max_prop_id = -1
|
|
37
|
+
model_part_names = Model.GetModelPartNames()
|
|
38
|
+
model_part = Model.GetModelPart(settings["model_part_name"].GetString())
|
|
39
|
+
for model_part_name in model_part_names:
|
|
40
|
+
for prop in Model.GetModelPart(model_part_name).Properties:
|
|
41
|
+
if prop.Id > max_prop_id:
|
|
42
|
+
max_prop_id = prop.Id
|
|
43
|
+
max_prop_id = model_part.GetCommunicator().GetDataCommunicator().MaxAll(max_prop_id)
|
|
44
|
+
|
|
45
|
+
# Create a new property with the user defined interface parameters
|
|
46
|
+
thermal_interface_prop = KratosMultiphysics.Properties(max_prop_id + 1)
|
|
47
|
+
emissivity = settings["emissivity"].GetDouble() if settings["add_ambient_radiation"].GetBool() else 0.0
|
|
48
|
+
convection_coefficient = settings["convection_coefficient"].GetDouble() if settings["add_ambient_convection"].GetBool() else 0.0
|
|
49
|
+
ambient_temperature = settings["ambient_temperature"].GetDouble() if (settings["add_ambient_convection"].GetBool() or settings["add_ambient_radiation"]) else 0.0
|
|
50
|
+
thermal_interface_prop.SetValue(KratosMultiphysics.EMISSIVITY, emissivity)
|
|
51
|
+
thermal_interface_prop.SetValue(KratosMultiphysics.CONVECTION_COEFFICIENT, convection_coefficient)
|
|
52
|
+
thermal_interface_prop.SetValue(KratosMultiphysics.AMBIENT_TEMPERATURE, ambient_temperature)
|
|
53
|
+
|
|
54
|
+
# Set the new property in the thermal face model part
|
|
55
|
+
model_part.AddProperties(thermal_interface_prop)
|
|
56
|
+
for condition in model_part.Conditions:
|
|
57
|
+
condition.Properties = thermal_interface_prop
|