KratosStatisticsApplication 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/KratosStatisticsApplication.so +0 -0
- KratosMultiphysics/.libs/libKratosStatisticsCore.dylib +0 -0
- KratosMultiphysics/StatisticsApplication/__init__.py +7 -0
- KratosMultiphysics/StatisticsApplication/method_utilities.py +28 -0
- KratosMultiphysics/StatisticsApplication/spatial_statistics_process.py +320 -0
- KratosMultiphysics/StatisticsApplication/spatial_utilities.py +226 -0
- KratosMultiphysics/StatisticsApplication/temporal_statistics_process.py +121 -0
- KratosMultiphysics/StatisticsApplication/temporal_utilities.py +62 -0
- KratosMultiphysics/StatisticsApplication/test_utilities.py +164 -0
- kratosstatisticsapplication-10.4.4.dist-info/METADATA +806 -0
- kratosstatisticsapplication-10.4.4.dist-info/RECORD +16 -0
- kratosstatisticsapplication-10.4.4.dist-info/WHEEL +6 -0
- kratosstatisticsapplication.dylibs/libKratosCore.dylib +4 -0
- kratosstatisticsapplication.dylibs/libgcc_s.1.1.dylib +0 -0
- kratosstatisticsapplication.dylibs/libgomp.1.dylib +0 -0
- kratosstatisticsapplication.dylibs/libstdc++.6.dylib +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Application dependent names and paths
|
|
2
|
+
from KratosMultiphysics import _ImportApplication
|
|
3
|
+
from KratosStatisticsApplication import *
|
|
4
|
+
application = KratosStatisticsApplication()
|
|
5
|
+
application_name = "KratosStatisticsApplication"
|
|
6
|
+
|
|
7
|
+
_ImportApplication(application, application_name)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
def GetNormTypeContainer(item_container, norm_type):
|
|
2
|
+
if (norm_type == "none"):
|
|
3
|
+
return item_container.ValueMethods
|
|
4
|
+
else:
|
|
5
|
+
return item_container.NormMethods
|
|
6
|
+
|
|
7
|
+
def GetAvailableMethods(item_norm_container):
|
|
8
|
+
method_info_list = []
|
|
9
|
+
for method in dir(item_norm_container):
|
|
10
|
+
if (not method.startswith("__")):
|
|
11
|
+
method_info_list.append([method.lower(), method])
|
|
12
|
+
|
|
13
|
+
method_names_list = [method_info[0] for method_info in method_info_list]
|
|
14
|
+
method_list = [method_info[1] for method_info in method_info_list]
|
|
15
|
+
|
|
16
|
+
return method_names_list, method_list
|
|
17
|
+
|
|
18
|
+
def GetMethod(item_norm_container, method_name):
|
|
19
|
+
method_names_list, method_list = GetAvailableMethods(item_norm_container)
|
|
20
|
+
|
|
21
|
+
if method_name not in method_names_list:
|
|
22
|
+
msg = "Unknown method name requested for the container " + str(item_norm_container) + ". [ \"method_name\" = \"" + method_name + "\" ]\n"
|
|
23
|
+
msg += "Allowed method names are:\n "
|
|
24
|
+
msg += "\n ".join(sorted(method_names_list))
|
|
25
|
+
raise Exception(msg)
|
|
26
|
+
|
|
27
|
+
return getattr(item_norm_container,
|
|
28
|
+
method_list[method_names_list.index(method_name)])
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import KratosMultiphysics as Kratos
|
|
2
|
+
from KratosMultiphysics.process_factory import KratosProcessFactory
|
|
3
|
+
|
|
4
|
+
from KratosMultiphysics.StatisticsApplication.method_utilities import GetAvailableMethods
|
|
5
|
+
from KratosMultiphysics.StatisticsApplication.method_utilities import GetNormTypeContainer
|
|
6
|
+
from KratosMultiphysics.StatisticsApplication.spatial_utilities import GetItemContainer
|
|
7
|
+
from KratosMultiphysics.StatisticsApplication.spatial_utilities import GetFormattedValue
|
|
8
|
+
from KratosMultiphysics.time_based_ascii_file_writer_utility import TimeBasedAsciiFileWriterUtility
|
|
9
|
+
|
|
10
|
+
import KratosMultiphysics.StatisticsApplication.spatial_utilities as SpatialUtilities
|
|
11
|
+
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def Factory(settings, model):
|
|
16
|
+
if (not isinstance(model, Kratos.Model)):
|
|
17
|
+
raise Exception(
|
|
18
|
+
"expected input shall be a Model object, encapsulating a json string"
|
|
19
|
+
)
|
|
20
|
+
if (not isinstance(settings, Kratos.Parameters)):
|
|
21
|
+
raise Exception(
|
|
22
|
+
"expected input shall be a Parameters object, encapsulating a json string"
|
|
23
|
+
)
|
|
24
|
+
return SpatialStatisticsProcess(model, settings["Parameters"])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SpatialStatisticsProcess(Kratos.Process):
|
|
28
|
+
"""A process to calculate spatial statistics on Kratos containers
|
|
29
|
+
|
|
30
|
+
This process calculates spatial statistics for given variables in a given container.
|
|
31
|
+
|
|
32
|
+
This process is compatible with OpenMP and MPI with restart
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
model (Kratos.Model): Model used in problem
|
|
36
|
+
settings (Kratos.Parameters): Kratos parameter settings for process
|
|
37
|
+
"""
|
|
38
|
+
def __init__(self, model, settings):
|
|
39
|
+
Kratos.Process.__init__(self)
|
|
40
|
+
|
|
41
|
+
default_parameters = Kratos.Parameters("""
|
|
42
|
+
{
|
|
43
|
+
"model_part_name" : "PLEASE_SPECIFY_MODEL_PART_NAME",
|
|
44
|
+
"echo_level" : 0,
|
|
45
|
+
"computation_processes" : [],
|
|
46
|
+
"computation_points" : [
|
|
47
|
+
"ExecuteInitialize",
|
|
48
|
+
"ExecuteInitializeSolutionStep",
|
|
49
|
+
"Execute",
|
|
50
|
+
"ExecuteFinalizeSolutionStep"
|
|
51
|
+
],
|
|
52
|
+
"input_variable_settings" : [
|
|
53
|
+
{
|
|
54
|
+
"variable_names" : [],
|
|
55
|
+
"norm_type" : "none",
|
|
56
|
+
"container" : "nodal_historical"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"statistics_methods": [
|
|
60
|
+
{
|
|
61
|
+
"method_name" : "",
|
|
62
|
+
"method_settings": {}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"output_settings" : {
|
|
66
|
+
"interval" : [0.0, "End"],
|
|
67
|
+
"output_control_variable": "STEP",
|
|
68
|
+
"output_time_interval" : 1,
|
|
69
|
+
"write_kratos_version" : false,
|
|
70
|
+
"write_time_stamp" : false,
|
|
71
|
+
"output_value_precision" : 5,
|
|
72
|
+
"output_value_length" : 14,
|
|
73
|
+
"output_file_settings" : {
|
|
74
|
+
"file_name" : "<model_part_name>.dat",
|
|
75
|
+
"output_path": "spatial_statistics_output",
|
|
76
|
+
"write_buffer_size" : -1
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} """)
|
|
80
|
+
|
|
81
|
+
self.model = model
|
|
82
|
+
self.settings = settings
|
|
83
|
+
self.settings.ValidateAndAssignDefaults(default_parameters)
|
|
84
|
+
self.variables_settings_list = self.settings["input_variable_settings"]
|
|
85
|
+
|
|
86
|
+
self.echo_level = self.settings["echo_level"].GetInt()
|
|
87
|
+
|
|
88
|
+
self.output_settings = self.settings["output_settings"]
|
|
89
|
+
self.output_settings["output_file_settings"].ValidateAndAssignDefaults(default_parameters["output_settings"]["output_file_settings"])
|
|
90
|
+
self.output_settings.RecursivelyValidateAndAssignDefaults(default_parameters["output_settings"])
|
|
91
|
+
|
|
92
|
+
self.model_part_name = self.settings["model_part_name"].GetString()
|
|
93
|
+
|
|
94
|
+
## set the input variavle x methods operations list
|
|
95
|
+
self.list_of_operations = []
|
|
96
|
+
|
|
97
|
+
spatial_output_method_info = []
|
|
98
|
+
for spatial_method_output in dir(SpatialUtilities):
|
|
99
|
+
if (spatial_method_output.startswith("Spatial") and spatial_method_output.endswith("Output")):
|
|
100
|
+
spatial_output_method_info.append([spatial_method_output.lower()[7:-6], spatial_method_output])
|
|
101
|
+
|
|
102
|
+
spatial_method_output_names_ = [method_info[0] for method_info in spatial_output_method_info]
|
|
103
|
+
spatial_method_output = [method_info[1] for method_info in spatial_output_method_info]
|
|
104
|
+
|
|
105
|
+
for variable_settings in self.settings["input_variable_settings"].values():
|
|
106
|
+
variable_settings.ValidateAndAssignDefaults(default_parameters["input_variable_settings"][0])
|
|
107
|
+
|
|
108
|
+
container_type = variable_settings["container"].GetString()
|
|
109
|
+
norm_type = variable_settings["norm_type"].GetString()
|
|
110
|
+
|
|
111
|
+
container = GetItemContainer(container_type)
|
|
112
|
+
norm_container = GetNormTypeContainer(container, norm_type)
|
|
113
|
+
available_methods, _ = GetAvailableMethods(norm_container)
|
|
114
|
+
|
|
115
|
+
for variable_name in variable_settings["variable_names"].GetStringArray():
|
|
116
|
+
if (not Kratos.KratosGlobals.HasVariable(variable_name)):
|
|
117
|
+
raise RuntimeError("Variable not found. [ variable_name = " + variable_name + " ]")
|
|
118
|
+
|
|
119
|
+
for method_settings in self.settings["statistics_methods"].values():
|
|
120
|
+
method_settings.ValidateAndAssignDefaults(default_parameters["statistics_methods"][0])
|
|
121
|
+
|
|
122
|
+
method_name = method_settings["method_name"].GetString()
|
|
123
|
+
if method_name == "":
|
|
124
|
+
raise RuntimeError("Found an empty method name. {:s}".format(method_settings))
|
|
125
|
+
|
|
126
|
+
if method_name not in spatial_method_output_names_:
|
|
127
|
+
msg = "Unknown method name [ \"method_name\" = \"" + method_name + "\" ]\n"
|
|
128
|
+
msg += "Allowed method names are:\n "
|
|
129
|
+
msg += "\n ".join(sorted(spatial_method_output_names_))
|
|
130
|
+
raise RuntimeError(msg)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if not method_name in available_methods:
|
|
134
|
+
Kratos.Logger.PrintInfo(self.__class__.__name__, "Skipping statistics output for {:s} method for {:s} in {:s} because {:s} norm type does not support it.".format(method_name, variable_name, container_type, norm_type))
|
|
135
|
+
else:
|
|
136
|
+
operation_type = getattr(SpatialUtilities, spatial_method_output[spatial_method_output_names_.index(method_name)])
|
|
137
|
+
self.list_of_operations.append(operation_type(container_type, norm_type, variable_name, method_settings["method_settings"]))
|
|
138
|
+
|
|
139
|
+
## set the output controller settings
|
|
140
|
+
self.interval_utility = Kratos.IntervalUtility(self.output_settings)
|
|
141
|
+
output_control_variable_name = self.output_settings["output_control_variable"].GetString()
|
|
142
|
+
if (not Kratos.KratosGlobals.HasVariable(output_control_variable_name)):
|
|
143
|
+
raise RuntimeError("Unknown output control variable. [ \"output_control_variable\" = \"" + output_control_variable_name + "\" ]")
|
|
144
|
+
output_control_variable_type = Kratos.KratosGlobals.GetVariableType(output_control_variable_name)
|
|
145
|
+
if (output_control_variable_type not in ["Integer", "Double"]):
|
|
146
|
+
raise RuntimeError("Unsupported output control variable type for " + output_control_variable_name + " of " + output_control_variable_type + " type. Supported types are Integer and Double only")
|
|
147
|
+
self.output_control_variable = Kratos.KratosGlobals.GetVariable(output_control_variable_name)
|
|
148
|
+
self.output_interval = self.output_settings["output_time_interval"].GetDouble()
|
|
149
|
+
self.output_value_precision = self.output_settings["output_value_precision"].GetInt()
|
|
150
|
+
self.output_value_length = self.output_settings["output_value_length"].GetInt()
|
|
151
|
+
|
|
152
|
+
## set the execution process
|
|
153
|
+
self.computation_points = self.settings["computation_points"].GetStringArray()
|
|
154
|
+
if self.settings["computation_processes"].size() == 0 or len(self.computation_points) == 0:
|
|
155
|
+
self.statistics_computation_processeses = None
|
|
156
|
+
else:
|
|
157
|
+
self.statistics_computation_processeses = KratosProcessFactory(self.model).ConstructListOfProcesses(self.settings["computation_processes"])
|
|
158
|
+
Kratos.Logger.PrintInfo(self.__class__.__name__, "Created statistics computation processes with following parameters: \n{:s}".format(self.settings["computation_processes"].PrettyPrintJsonString()))
|
|
159
|
+
|
|
160
|
+
self.is_headers_written = False
|
|
161
|
+
|
|
162
|
+
Kratos.Logger.PrintInfo("SpatialStatisticsProcess", "Initialized statistics process.")
|
|
163
|
+
|
|
164
|
+
def Check(self):
|
|
165
|
+
if (not self.model.HasModelPart(self.model_part_name)):
|
|
166
|
+
raise RuntimeError(self.model_part_name + " not found.")
|
|
167
|
+
|
|
168
|
+
for variable_settings in self.variables_settings_list.values():
|
|
169
|
+
variable_names_list = variable_settings["variable_names"].GetStringArray()
|
|
170
|
+
|
|
171
|
+
container = variable_settings["container"].GetString()
|
|
172
|
+
if (container == "nodal_historical"):
|
|
173
|
+
for variable_name in variable_names_list:
|
|
174
|
+
variable = Kratos.KratosGlobals.GetVariable(variable_name)
|
|
175
|
+
if (not self.__get_model_part().HasNodalSolutionStepVariable(variable)):
|
|
176
|
+
raise RuntimeError("Variable " + variable_name + " not found in nodal solution step data of " + self.__get_model_part().Name)
|
|
177
|
+
|
|
178
|
+
if self.statistics_computation_processeses is not None:
|
|
179
|
+
for process in self.statistics_computation_processeses:
|
|
180
|
+
process.Check()
|
|
181
|
+
|
|
182
|
+
def ExecuteInitialize(self):
|
|
183
|
+
## set output file path
|
|
184
|
+
self.output_settings["output_file_settings"]["file_name"].SetString(self.output_settings["output_file_settings"]["file_name"].GetString().replace("<model_part_name>", self.__get_model_part().FullName()))
|
|
185
|
+
self.output_settings["output_file_settings"]["output_path"].SetString(self.output_settings["output_file_settings"]["output_path"].GetString().replace("<model_part_name>", self.__get_model_part().FullName()))
|
|
186
|
+
|
|
187
|
+
self.__write_headers()
|
|
188
|
+
|
|
189
|
+
if self.echo_level > 0:
|
|
190
|
+
Kratos.Logger.PrintInfo(self.__class__.__name__, "List of output operations:\n\t" + "\n\t".join([str(operation) for operation in self.list_of_operations]))
|
|
191
|
+
|
|
192
|
+
self.previous_process_info_value = self.__get_model_part().ProcessInfo[self.output_control_variable]
|
|
193
|
+
|
|
194
|
+
def ExecuteFinalizeSolutionStep(self):
|
|
195
|
+
output_control_counter = self.__get_model_part().ProcessInfo[self.output_control_variable]
|
|
196
|
+
|
|
197
|
+
if self.interval_utility.IsInInterval(output_control_counter):
|
|
198
|
+
if (output_control_counter - self.previous_process_info_value) >= self.output_interval:
|
|
199
|
+
|
|
200
|
+
# execute the statistics computation process
|
|
201
|
+
if self.statistics_computation_processeses is not None:
|
|
202
|
+
for process in self.statistics_computation_processeses:
|
|
203
|
+
for computation_point in self.computation_points:
|
|
204
|
+
getattr(process, computation_point)()
|
|
205
|
+
|
|
206
|
+
for operation in self.list_of_operations:
|
|
207
|
+
operation.Evaluate(self.model_part)
|
|
208
|
+
|
|
209
|
+
self.__write_values()
|
|
210
|
+
|
|
211
|
+
if self.echo_level > 1:
|
|
212
|
+
Kratos.Logger.PrintInfo(self.__class__.__name__, "Calculated statistics on {:s}.".format(self.__get_model_part().FullName()))
|
|
213
|
+
|
|
214
|
+
self.previous_process_info_value = output_control_counter
|
|
215
|
+
|
|
216
|
+
def ExecuteFinalize(self):
|
|
217
|
+
if (self.__is_writing_process()):
|
|
218
|
+
self.output_file.file.write("# End of file.")
|
|
219
|
+
self.output_file.file.close()
|
|
220
|
+
|
|
221
|
+
def __write_headers(self):
|
|
222
|
+
if (self.__is_writing_process()):
|
|
223
|
+
kratos_version = "not_given"
|
|
224
|
+
if (self.output_settings["write_kratos_version"].GetBool()):
|
|
225
|
+
kratos_version = str(Kratos.KratosGlobals.Kernel.Version())
|
|
226
|
+
|
|
227
|
+
time_stamp = "not_specified"
|
|
228
|
+
if (self.output_settings["write_time_stamp"].GetBool()):
|
|
229
|
+
time_stamp = str(datetime.now())
|
|
230
|
+
|
|
231
|
+
method_name = ""
|
|
232
|
+
variable_info = ""
|
|
233
|
+
for operation in self.list_of_operations:
|
|
234
|
+
if operation.method_name not in method_name:
|
|
235
|
+
method_name += operation.method_name + ", "
|
|
236
|
+
current_variable_info = "{:s}[{:s}, {:s}], ".format(operation.variable_name, operation.norm_type, operation.container_type)
|
|
237
|
+
if current_variable_info not in variable_info:
|
|
238
|
+
variable_info += current_variable_info
|
|
239
|
+
|
|
240
|
+
self.headers, self.header_lengths = self.__get_headers()
|
|
241
|
+
|
|
242
|
+
msg_header = ""
|
|
243
|
+
msg_header += "# Spatial statistics process output\n"
|
|
244
|
+
msg_header += "# Kratos version : " + kratos_version + "\n"
|
|
245
|
+
msg_header += "# Timestamp : " + time_stamp + "\n"
|
|
246
|
+
msg_header += "# Method name(s) : " + method_name[:-2] + "\n"
|
|
247
|
+
msg_header += "# Variable info(s) : " + variable_info[:-2] + "\n"
|
|
248
|
+
msg_header += "# Modelpart name : " + self.model_part_name + "\n"
|
|
249
|
+
msg_header += "# Output control variable name : " + self.output_control_variable.Name() + "\n"
|
|
250
|
+
msg_header += "# ----------------------------------------------------------------------\n"
|
|
251
|
+
msg_header += "# Headers:\n"
|
|
252
|
+
msg_header += "#" + " ".join([("{:>" + str(header_length) + "s}").format(header) for header, header_length in zip(self.headers, self.header_lengths)]) + "\n"
|
|
253
|
+
|
|
254
|
+
self.output_file = TimeBasedAsciiFileWriterUtility(self.__get_model_part(), self.output_settings["output_file_settings"], msg_header)
|
|
255
|
+
|
|
256
|
+
self.is_headers_written = True
|
|
257
|
+
|
|
258
|
+
def __get_headers(self):
|
|
259
|
+
# check whether only one variable with one
|
|
260
|
+
variable_info = ""
|
|
261
|
+
for operation in self.list_of_operations:
|
|
262
|
+
current_variable_info = "{:s}[{:s}, {:s}], ".format(operation.variable_name, operation.norm_type, operation.container_type)
|
|
263
|
+
if current_variable_info not in variable_info:
|
|
264
|
+
variable_info += current_variable_info
|
|
265
|
+
|
|
266
|
+
headers = ["\"TIME\""]
|
|
267
|
+
header_lengths = [max(6, self.output_value_length)]
|
|
268
|
+
if self.output_control_variable != Kratos.TIME:
|
|
269
|
+
headers.append("\"" + self.output_control_variable.Name() + "\"")
|
|
270
|
+
header_lengths.append(max(len(self.output_control_variable.Name()) + 2, self.output_value_length))
|
|
271
|
+
|
|
272
|
+
# found only one variable type info
|
|
273
|
+
if variable_info.count(",") == 2:
|
|
274
|
+
header_formatting_string = "\"<HEADER_NAME><COMPONENT>\""
|
|
275
|
+
else:
|
|
276
|
+
header_formatting_string = "\"<VARIABLE_NAME><COMPONENT> [ <NORM_TYPE> | <CONTAINER_TYPE> ] <HEADER_NAME>\""
|
|
277
|
+
|
|
278
|
+
variable_components = {
|
|
279
|
+
"Double": [""],
|
|
280
|
+
"Array" : ["_X", "_Y", "_Z"]
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
for operation in self.list_of_operations:
|
|
284
|
+
if operation.norm_type == "none":
|
|
285
|
+
comps_list = variable_components[Kratos.KratosGlobals.GetVariableType(operation.variable.Name())]
|
|
286
|
+
else:
|
|
287
|
+
comps_list = variable_components["Double"]
|
|
288
|
+
|
|
289
|
+
for current_header, current_header_length in zip(operation.GetHeaders(), operation.GetValueLengths(self.output_value_length)):
|
|
290
|
+
for comp in comps_list:
|
|
291
|
+
current_header_name = str(header_formatting_string)
|
|
292
|
+
|
|
293
|
+
current_header_name = current_header_name.replace("<HEADER_NAME>", current_header)
|
|
294
|
+
current_header_name = current_header_name.replace("<VARIABLE_NAME>", operation.variable.Name())
|
|
295
|
+
current_header_name = current_header_name.replace("<COMPONENT>", comp)
|
|
296
|
+
current_header_name = current_header_name.replace("<NORM_TYPE>", operation.norm_type)
|
|
297
|
+
current_header_name = current_header_name.replace("<CONTAINER_TYPE>", operation.container_type)
|
|
298
|
+
|
|
299
|
+
headers.append(current_header_name)
|
|
300
|
+
header_lengths.append(max(len(current_header_name), current_header_length))
|
|
301
|
+
|
|
302
|
+
return headers, header_lengths
|
|
303
|
+
|
|
304
|
+
def __write_values(self):
|
|
305
|
+
if (self.__is_writing_process()):
|
|
306
|
+
values = [GetFormattedValue(self.__get_model_part().ProcessInfo[Kratos.TIME], self.output_value_length, self.output_value_precision)[0]]
|
|
307
|
+
if self.output_control_variable != Kratos.TIME:
|
|
308
|
+
values.append(GetFormattedValue(self.__get_model_part().ProcessInfo[self.output_control_variable], self.output_value_length, self.output_value_precision)[0])
|
|
309
|
+
for operation in self.list_of_operations:
|
|
310
|
+
values.extend(operation.GetValues(self.output_value_length, self.output_value_precision))
|
|
311
|
+
self.output_file.file.write(" " + " ".join([("{:>" + str(header_length) + "s}").format(value) for value, header_length in zip(values, self.header_lengths)]) + "\n")
|
|
312
|
+
|
|
313
|
+
def __get_model_part(self):
|
|
314
|
+
if (not hasattr(self, "model_part")):
|
|
315
|
+
self.model_part = self.model[self.model_part_name]
|
|
316
|
+
|
|
317
|
+
return self.model_part
|
|
318
|
+
|
|
319
|
+
def __is_writing_process(self):
|
|
320
|
+
return (self.__get_model_part().GetCommunicator().MyPID() == 0)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import KratosMultiphysics as Kratos
|
|
2
|
+
import KratosMultiphysics.StatisticsApplication as Statistics
|
|
3
|
+
|
|
4
|
+
from KratosMultiphysics.StatisticsApplication.method_utilities import GetNormTypeContainer
|
|
5
|
+
from KratosMultiphysics.StatisticsApplication.method_utilities import GetMethod
|
|
6
|
+
|
|
7
|
+
def GetFormattedValue(value, length: int, precision: int) -> str:
|
|
8
|
+
if isinstance(value, int):
|
|
9
|
+
fixed_format = ("{: " + str(length) + ".0f}").format(value)
|
|
10
|
+
if len(fixed_format) <= length:
|
|
11
|
+
return [fixed_format]
|
|
12
|
+
else:
|
|
13
|
+
return [("{: " + str(length) + "." + str(precision) + "e}").format(value)]
|
|
14
|
+
elif isinstance(value, float):
|
|
15
|
+
fixed_format = ("{: " + str(length) + "." + str(precision) + "f}").format(value)
|
|
16
|
+
if len(fixed_format) <= length:
|
|
17
|
+
return [fixed_format]
|
|
18
|
+
else:
|
|
19
|
+
return [("{: " + str(length) + "." + str(precision) + "e}").format(value)]
|
|
20
|
+
|
|
21
|
+
elif isinstance(value, Kratos.Array3):
|
|
22
|
+
return [GetFormattedValue(value[0], length, precision)[0], GetFormattedValue(value[1], length, precision)[0], GetFormattedValue(value[2], length, precision)[0]]
|
|
23
|
+
|
|
24
|
+
def GetItemContainer(item_container_name):
|
|
25
|
+
item_container_types = [
|
|
26
|
+
["nodal_historical", Statistics.SpatialMethods.Historical],
|
|
27
|
+
["nodal_non_historical", Statistics.SpatialMethods.NonHistorical.Nodes],
|
|
28
|
+
["element_non_historical", Statistics.SpatialMethods.NonHistorical.Elements],
|
|
29
|
+
["condition_non_historical", Statistics.SpatialMethods.NonHistorical.Conditions],
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
item_container_names_list = [item_container_types[i][0] for i in range(len(item_container_types))]
|
|
33
|
+
item_container_types_list = [item_container_types[i][1] for i in range(len(item_container_types))]
|
|
34
|
+
|
|
35
|
+
if (item_container_name not in item_container_names_list):
|
|
36
|
+
msg = "Unknown container [ \"container\" = \"" + item_container_name + "\" ]\n"
|
|
37
|
+
msg += "Allowed containers are:\n "
|
|
38
|
+
msg += "\n ".join(sorted(item_container_names_list))
|
|
39
|
+
raise Exception(msg)
|
|
40
|
+
|
|
41
|
+
return item_container_types_list[item_container_names_list.index(item_container_name)]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def GetVariableHeaders(norm_type, variable_name):
|
|
45
|
+
if (norm_type == "none"):
|
|
46
|
+
variable_type = Kratos.KratosGlobals.GetVariableType(variable_name)
|
|
47
|
+
if (variable_type == "Double"):
|
|
48
|
+
return [variable_name]
|
|
49
|
+
elif (variable_type == "Array" and Kratos.KratosGlobals.GetVariableType(variable_name + "_X") == "Double"):
|
|
50
|
+
return [variable_name + "_X", variable_name + "_Y", variable_name + "_Z"]
|
|
51
|
+
else:
|
|
52
|
+
raise Exception("Unsupported variable type " + variable_type)
|
|
53
|
+
else:
|
|
54
|
+
return [variable_name]
|
|
55
|
+
|
|
56
|
+
class SpatialMethodOutput:
|
|
57
|
+
def __init__(self, method_name, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
58
|
+
self.method_name = method_name
|
|
59
|
+
self.container_type = container_type
|
|
60
|
+
self.norm_type = norm_type
|
|
61
|
+
self.variable_name = variable_name
|
|
62
|
+
self.method_settings = method_settings
|
|
63
|
+
self.variable = Kratos.KratosGlobals.GetVariable(self.variable_name)
|
|
64
|
+
|
|
65
|
+
self.container = GetItemContainer(self.container_type)
|
|
66
|
+
self.norm_type_container = GetNormTypeContainer(self.container, norm_type)
|
|
67
|
+
method = GetMethod(self.norm_type_container, self.method_name)
|
|
68
|
+
|
|
69
|
+
if method_settings.IsEquivalentTo(Kratos.Parameters("""{}""")):
|
|
70
|
+
if norm_type == "none":
|
|
71
|
+
self.norm_type_container = self.container.ValueMethods
|
|
72
|
+
self.method = lambda model_part: method(model_part, self.variable)
|
|
73
|
+
else:
|
|
74
|
+
self.norm_type_container = self.container.NormMethods
|
|
75
|
+
self.method = lambda model_part: method(model_part, self.variable, norm_type)
|
|
76
|
+
else:
|
|
77
|
+
if norm_type == "none":
|
|
78
|
+
self.norm_type_container = self.container.ValueMethods
|
|
79
|
+
self.method = lambda model_part: method(model_part, self.variable, method_settings)
|
|
80
|
+
else:
|
|
81
|
+
self.norm_type_container = self.container.NormMethods
|
|
82
|
+
self.method = lambda model_part: method(model_part, self.variable, norm_type, method_settings)
|
|
83
|
+
|
|
84
|
+
def Evaluate(self, model_part):
|
|
85
|
+
self.data = self.method(model_part)
|
|
86
|
+
|
|
87
|
+
def GetValues(self, length, precision):
|
|
88
|
+
if isinstance(self.data, float):
|
|
89
|
+
return GetFormattedValue(self.data, length, precision)
|
|
90
|
+
else:
|
|
91
|
+
values = []
|
|
92
|
+
for v in self.data:
|
|
93
|
+
values.extend(GetFormattedValue(v, length, precision))
|
|
94
|
+
return values
|
|
95
|
+
|
|
96
|
+
def GetValueLengths(self, value_length):
|
|
97
|
+
return [value_length]
|
|
98
|
+
|
|
99
|
+
def __str__(self):
|
|
100
|
+
return self.__class__.__name__ + "(container: {:s}, norm_type: {:s}, variable: {:s})".format(self.container_type, self.norm_type, self.variable_name)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class SpatialSumOutput(SpatialMethodOutput):
|
|
104
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
105
|
+
super().__init__("sum", container_type, norm_type, variable_name)
|
|
106
|
+
|
|
107
|
+
def GetHeaders(self):
|
|
108
|
+
return ["sum"]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class SpatialMeanOutput(SpatialMethodOutput):
|
|
112
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
113
|
+
super().__init__("mean", container_type, norm_type, variable_name)
|
|
114
|
+
|
|
115
|
+
def GetHeaders(self):
|
|
116
|
+
return ["mean"]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class SpatialRootMeanSquareOutput(SpatialMethodOutput):
|
|
120
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
121
|
+
super().__init__("rootmeansquare", container_type, norm_type, variable_name)
|
|
122
|
+
|
|
123
|
+
def GetHeaders(self):
|
|
124
|
+
return ["rootmeansquare"]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class SpatialMinOutput(SpatialMethodOutput):
|
|
128
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
129
|
+
super().__init__("min", container_type, norm_type, variable_name)
|
|
130
|
+
|
|
131
|
+
def GetHeaders(self):
|
|
132
|
+
return ["min_value", "min_id"]
|
|
133
|
+
|
|
134
|
+
def GetValueLengths(self, value_length):
|
|
135
|
+
return [value_length, value_length]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class SpatialMaxOutput(SpatialMethodOutput):
|
|
139
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
140
|
+
super().__init__("max", container_type, norm_type, variable_name)
|
|
141
|
+
|
|
142
|
+
def GetHeaders(self):
|
|
143
|
+
return ["max_value", "max_id"]
|
|
144
|
+
|
|
145
|
+
def GetValueLengths(self, value_length):
|
|
146
|
+
return [value_length, value_length]
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class SpatialMedianOutput(SpatialMethodOutput):
|
|
150
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
151
|
+
super().__init__("median", container_type, norm_type, variable_name)
|
|
152
|
+
|
|
153
|
+
def GetHeaders(self):
|
|
154
|
+
return ["median"]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class SpatialVarianceOutput(SpatialMethodOutput):
|
|
158
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings = Kratos.Parameters("""{}""")):
|
|
159
|
+
super().__init__("variance", container_type, norm_type, variable_name)
|
|
160
|
+
|
|
161
|
+
def GetHeaders(self):
|
|
162
|
+
return ["mean", "variance"]
|
|
163
|
+
|
|
164
|
+
def GetValueLengths(self, value_length):
|
|
165
|
+
return [value_length, value_length]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class SpatialDistributionOutput(SpatialMethodOutput):
|
|
169
|
+
def __init__(self, container_type, norm_type, variable_name, method_settings):
|
|
170
|
+
super().__init__("distribution", container_type, norm_type, variable_name, method_settings)
|
|
171
|
+
default_parameters = Kratos.Parameters("""{ "number_of_value_groups": 10 }""")
|
|
172
|
+
self.method_settings.AddMissingParameters(default_parameters)
|
|
173
|
+
|
|
174
|
+
self.write_min_value = True
|
|
175
|
+
if self.method_settings.Has("min_value") and self.method_settings["min_value"].IsDouble():
|
|
176
|
+
self.write_min_value = False
|
|
177
|
+
|
|
178
|
+
self.write_max_value = True
|
|
179
|
+
if self.method_settings.Has("max_value") and self.method_settings["max_value"].IsDouble():
|
|
180
|
+
self.write_max_value = False
|
|
181
|
+
|
|
182
|
+
def Evaluate(self, *args):
|
|
183
|
+
super().Evaluate(*args)
|
|
184
|
+
(self.min_value, self.max_value, self.group_upper_values, self.group_histogram, self.group_percentage_distribution, self.group_means, self.group_variances) = self.data
|
|
185
|
+
|
|
186
|
+
def GetHeaders(self):
|
|
187
|
+
number_of_groups = self.method_settings["number_of_value_groups"].GetInt()
|
|
188
|
+
headers = []
|
|
189
|
+
if self.write_min_value:
|
|
190
|
+
headers.append("min")
|
|
191
|
+
if self.write_max_value:
|
|
192
|
+
headers.append("max")
|
|
193
|
+
|
|
194
|
+
headers.append("group_below_min {mean|variance}")
|
|
195
|
+
headers.extend(["group_{:d}".format(i+1) + " {mean|variance}" for i in range(number_of_groups)])
|
|
196
|
+
headers.append("group_above_max {mean|variance}")
|
|
197
|
+
return headers
|
|
198
|
+
|
|
199
|
+
def GetValues(self, length, precision):
|
|
200
|
+
values = []
|
|
201
|
+
if self.write_min_value:
|
|
202
|
+
values.append(GetFormattedValue(self.min_value, length, precision)[0])
|
|
203
|
+
if self.write_max_value:
|
|
204
|
+
values.append(GetFormattedValue(self.max_value, length, precision)[0])
|
|
205
|
+
|
|
206
|
+
def get_formatted_group_value(hist_v, percentage_v, upper_v, mean_v, variance_v):
|
|
207
|
+
s = "{:s} [#] = {:s} [%] < {:s}".format(GetFormattedValue(hist_v, length, precision)[0], GetFormattedValue(percentage_v * 100.0, length, precision)[0], GetFormattedValue(upper_v, length, precision)[0])
|
|
208
|
+
s += " { " + GetFormattedValue(mean_v, length, precision)[0] + " | " + GetFormattedValue(variance_v, length, precision)[0] + " }"
|
|
209
|
+
return s
|
|
210
|
+
values.extend([get_formatted_group_value(hist_v, percentage_v, upper_v, mean_v, variance_v) for hist_v, percentage_v, upper_v, mean_v, variance_v in zip(self.group_histogram, self.group_percentage_distribution, self.group_upper_values, self.group_means, self.group_variances)])
|
|
211
|
+
values[-1] = values[-1].replace(" <", ">=")
|
|
212
|
+
return values
|
|
213
|
+
|
|
214
|
+
def GetValueLengths(self, value_length):
|
|
215
|
+
values_per_header = []
|
|
216
|
+
if self.write_min_value:
|
|
217
|
+
values_per_header.append(value_length)
|
|
218
|
+
if self.write_max_value:
|
|
219
|
+
values_per_header.append(value_length)
|
|
220
|
+
|
|
221
|
+
number_of_groups = self.method_settings["number_of_value_groups"].GetInt()
|
|
222
|
+
for _ in range(number_of_groups + 2):
|
|
223
|
+
values_per_header.append(22 + value_length * 5)
|
|
224
|
+
return values_per_header
|
|
225
|
+
|
|
226
|
+
|