KratosShapeOptimizationApplication 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/KratosShapeOptimizationApplication.so +0 -0
- KratosMultiphysics/.libs/libKratosShapeOptimizationCore.dylib +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/TemplateMainKratosShapeOptimization.py +31 -0
- KratosMultiphysics/ShapeOptimizationApplication/__init__.py +19 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_base.py +31 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_bead_optimization.py +412 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_factory.py +62 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_gradient_projection.py +317 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_penalized_projection.py +225 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_relaxed_gradient_projection.py +580 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_shape_fraction_optimization.py +622 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_steepest_descent.py +255 -0
- KratosMultiphysics/ShapeOptimizationApplication/algorithms/algorithm_trust_region.py +657 -0
- KratosMultiphysics/ShapeOptimizationApplication/analyzers/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/analyzers/analyzer_base.py +30 -0
- KratosMultiphysics/ShapeOptimizationApplication/analyzers/analyzer_empty.py +21 -0
- KratosMultiphysics/ShapeOptimizationApplication/analyzers/analyzer_factory.py +310 -0
- KratosMultiphysics/ShapeOptimizationApplication/analyzers/analyzer_internal.py +155 -0
- KratosMultiphysics/ShapeOptimizationApplication/communicator_factory.py +259 -0
- KratosMultiphysics/ShapeOptimizationApplication/custom_ios/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/custom_ios/wrl_io.py +82 -0
- KratosMultiphysics/ShapeOptimizationApplication/custom_ios/wrl_reader.py +119 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/data_logger_factory.py +199 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/design_logger_base.py +28 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/design_logger_gid.py +112 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/design_logger_unv.py +73 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/design_logger_vtk.py +96 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/sensitivity_heatmap_logger.py +91 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_base.py +128 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_bead_optimization.py +79 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_gradient_projection.py +80 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_penalized_projection.py +79 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_relaxed_gradient_projection.py +108 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_shape_fraction_optimization.py +92 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_steepest_descent.py +64 -0
- KratosMultiphysics/ShapeOptimizationApplication/loggers/value_logger_trust_region.py +100 -0
- KratosMultiphysics/ShapeOptimizationApplication/mapper_factory.py +100 -0
- KratosMultiphysics/ShapeOptimizationApplication/mapping/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/mapping/in_plane_vertex_morphing_mapper.py +140 -0
- KratosMultiphysics/ShapeOptimizationApplication/mapping/sliding_vertex_morphing_mapper.py +378 -0
- KratosMultiphysics/ShapeOptimizationApplication/mesh_controllers/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/mesh_controllers/mesh_controller_base.py +22 -0
- KratosMultiphysics/ShapeOptimizationApplication/mesh_controllers/mesh_controller_basic_updating.py +35 -0
- KratosMultiphysics/ShapeOptimizationApplication/mesh_controllers/mesh_controller_with_solver.py +237 -0
- KratosMultiphysics/ShapeOptimizationApplication/model_part_controller_factory.py +197 -0
- KratosMultiphysics/ShapeOptimizationApplication/optimizer_factory.py +235 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/airfoil_2d_responses.py +189 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/face_angle.py +140 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/mesh_based_packaging.py +70 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/packaging_response_base.py +156 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/plane_based_packaging.py +61 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/response_function_factory.py +40 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/surface_normal_shape_change.py +125 -0
- KratosMultiphysics/ShapeOptimizationApplication/response_functions/total_volume.py +56 -0
- KratosMultiphysics/ShapeOptimizationApplication/utilities/__init__.py +0 -0
- KratosMultiphysics/ShapeOptimizationApplication/utilities/custom_math.py +443 -0
- KratosMultiphysics/ShapeOptimizationApplication/utilities/custom_sensitivity_heatmap.py +235 -0
- KratosMultiphysics/ShapeOptimizationApplication/utilities/custom_timer.py +47 -0
- KratosMultiphysics/ShapeOptimizationApplication/utilities/custom_variable_utilities.py +54 -0
- kratosshapeoptimizationapplication-10.4.4.dist-info/METADATA +31 -0
- kratosshapeoptimizationapplication-10.4.4.dist-info/RECORD +69 -0
- kratosshapeoptimizationapplication-10.4.4.dist-info/WHEEL +6 -0
- kratosshapeoptimizationapplication.dylibs/libKratosCore.dylib +4 -0
- kratosshapeoptimizationapplication.dylibs/libgcc_s.1.1.dylib +0 -0
- kratosshapeoptimizationapplication.dylibs/libgomp.1.dylib +0 -0
- kratosshapeoptimizationapplication.dylibs/libstdc++.6.dylib +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# ==============================================================================
|
|
14
|
+
class DesignLogger:
|
|
15
|
+
|
|
16
|
+
# --------------------------------------------------------------------------
|
|
17
|
+
def InitializeLogging( self ):
|
|
18
|
+
raise RuntimeError("Design logger base class is called. Please check your implementation of the function >> InitializeLogging << .")
|
|
19
|
+
|
|
20
|
+
# --------------------------------------------------------------------------
|
|
21
|
+
def LogCurrentDesign( self, optimizationIteration ):
|
|
22
|
+
raise RuntimeError("Design logger base class is called. Please check your implementation of the function >> LogCurrentDesign << .")
|
|
23
|
+
|
|
24
|
+
#---------------------------------------------------------------------------
|
|
25
|
+
def FinalizeLogging( self ):
|
|
26
|
+
raise RuntimeError("Design logger base class is called. Please check your implementation of the function >> FinalizeLogging << .")
|
|
27
|
+
|
|
28
|
+
# ==============================================================================
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Kratos Core and Apps
|
|
14
|
+
import KratosMultiphysics as KM
|
|
15
|
+
|
|
16
|
+
# For GID output
|
|
17
|
+
from KratosMultiphysics.gid_output_process import GiDOutputProcess
|
|
18
|
+
|
|
19
|
+
# Import logger base classes
|
|
20
|
+
from KratosMultiphysics.ShapeOptimizationApplication.loggers.design_logger_base import DesignLogger
|
|
21
|
+
|
|
22
|
+
# ==============================================================================
|
|
23
|
+
class DesignLoggerGID( DesignLogger ):
|
|
24
|
+
|
|
25
|
+
# --------------------------------------------------------------------------
|
|
26
|
+
def __init__( self, model_part_controller, optimization_settings ):
|
|
27
|
+
self.output_settings = optimization_settings["output"]
|
|
28
|
+
minimal_gid_parameters = KM.Parameters("""
|
|
29
|
+
{
|
|
30
|
+
"name" : "gid",
|
|
31
|
+
"gid_parameters" : { }
|
|
32
|
+
}""")
|
|
33
|
+
|
|
34
|
+
self.output_settings["output_format"].ValidateAndAssignDefaults(minimal_gid_parameters)
|
|
35
|
+
self.output_settings["output_format"]["gid_parameters"].RecursivelyValidateAndAssignDefaults(GiDOutputProcess.defaults)
|
|
36
|
+
|
|
37
|
+
self.optimization_model_part = model_part_controller.GetOptimizationModelPart()
|
|
38
|
+
self.design_surface = model_part_controller.GetDesignSurface()
|
|
39
|
+
|
|
40
|
+
self.write_design_surface = False
|
|
41
|
+
self.write_optimization_model_part = False
|
|
42
|
+
self.design_history_filename = None
|
|
43
|
+
|
|
44
|
+
self.__DetermineOutputMode()
|
|
45
|
+
self.__ModifySettingsToMatchDefaultGiDOutputProcess()
|
|
46
|
+
self.__CreateGiDIO()
|
|
47
|
+
|
|
48
|
+
# --------------------------------------------------------------------------
|
|
49
|
+
def __DetermineOutputMode( self ):
|
|
50
|
+
output_mode = self.output_settings["design_output_mode"].GetString()
|
|
51
|
+
|
|
52
|
+
if output_mode == "write_design_surface":
|
|
53
|
+
self.write_design_surface = True
|
|
54
|
+
self.design_history_filename = self.design_surface.Name
|
|
55
|
+
elif output_mode == "write_optimization_model_part":
|
|
56
|
+
if self.optimization_model_part.NumberOfElements() == 0:
|
|
57
|
+
raise NameError("Output of optimization model part in Gid-format requires definition of elements. No elements are given in current mdpa! You may change the design output mode.")
|
|
58
|
+
self.write_optimization_model_part = True
|
|
59
|
+
self.design_history_filename = self.optimization_model_part.Name
|
|
60
|
+
else:
|
|
61
|
+
raise NameError("The following design output mode is not defined within a GiD output (name may be misspelled): " + output_mode)
|
|
62
|
+
|
|
63
|
+
# --------------------------------------------------------------------------
|
|
64
|
+
def __ModifySettingsToMatchDefaultGiDOutputProcess( self ):
|
|
65
|
+
gid_parameters = self.output_settings["output_format"]["gid_parameters"]
|
|
66
|
+
|
|
67
|
+
# Add nodal results
|
|
68
|
+
self.output_settings["output_format"]["gid_parameters"]["result_file_configuration"]["nodal_results"] = self.output_settings["nodal_results"]
|
|
69
|
+
|
|
70
|
+
# Set condition flag
|
|
71
|
+
if not gid_parameters["result_file_configuration"]["gidpost_flags"].Has("WriteConditionsFlag"):
|
|
72
|
+
gid_parameters["result_file_configuration"]["gidpost_flags"].AddEmptyValue("WriteConditionsFlag")
|
|
73
|
+
|
|
74
|
+
if self.write_design_surface:
|
|
75
|
+
gid_parameters["result_file_configuration"]["gidpost_flags"]["WriteConditionsFlag"].SetString("WriteConditions")
|
|
76
|
+
elif self.write_optimization_model_part:
|
|
77
|
+
gid_parameters["result_file_configuration"]["gidpost_flags"]["WriteConditionsFlag"].SetString("WriteElementsOnly")
|
|
78
|
+
|
|
79
|
+
# --------------------------------------------------------------------------
|
|
80
|
+
def __CreateGiDIO( self ):
|
|
81
|
+
|
|
82
|
+
gid_config = self.output_settings["output_format"]["gid_parameters"]
|
|
83
|
+
results_directory = self.output_settings["output_directory"].GetString()
|
|
84
|
+
design_history_file_path = results_directory+"/"+self.design_history_filename
|
|
85
|
+
|
|
86
|
+
if self.write_design_surface:
|
|
87
|
+
self.gid_io = GiDOutputProcess(self.design_surface, design_history_file_path, gid_config)
|
|
88
|
+
elif self.write_optimization_model_part:
|
|
89
|
+
self.gid_io = GiDOutputProcess(self.optimization_model_part, design_history_file_path, gid_config)
|
|
90
|
+
|
|
91
|
+
# --------------------------------------------------------------------------
|
|
92
|
+
def InitializeLogging( self ):
|
|
93
|
+
self.gid_io.ExecuteInitialize()
|
|
94
|
+
self.gid_io.ExecuteBeforeSolutionLoop()
|
|
95
|
+
|
|
96
|
+
# --------------------------------------------------------------------------
|
|
97
|
+
def LogCurrentDesign( self, optimizationIteration ):
|
|
98
|
+
OriginalTime = self.optimization_model_part.ProcessInfo[KM.TIME]
|
|
99
|
+
self.optimization_model_part.ProcessInfo[KM.TIME] = optimizationIteration
|
|
100
|
+
|
|
101
|
+
self.gid_io.ExecuteInitializeSolutionStep()
|
|
102
|
+
if(self.gid_io.IsOutputStep()):
|
|
103
|
+
self.gid_io.PrintOutput()
|
|
104
|
+
self.gid_io.ExecuteFinalizeSolutionStep()
|
|
105
|
+
|
|
106
|
+
self.optimization_model_part.ProcessInfo[KM.TIME] = OriginalTime
|
|
107
|
+
|
|
108
|
+
# --------------------------------------------------------------------------
|
|
109
|
+
def FinalizeLogging( self ):
|
|
110
|
+
self.gid_io.ExecuteFinalize()
|
|
111
|
+
|
|
112
|
+
# ==============================================================================
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Kratos Core and Apps
|
|
14
|
+
import KratosMultiphysics.ShapeOptimizationApplication as KSO
|
|
15
|
+
|
|
16
|
+
# Import logger base classes
|
|
17
|
+
from KratosMultiphysics.ShapeOptimizationApplication.loggers.design_logger_base import DesignLogger
|
|
18
|
+
|
|
19
|
+
# ==============================================================================
|
|
20
|
+
class DesignLoggerUNV( DesignLogger ):
|
|
21
|
+
|
|
22
|
+
# --------------------------------------------------------------------------
|
|
23
|
+
def __init__( self, model_part_controller, optimization_settings ):
|
|
24
|
+
self.optimization_model_part = model_part_controller.GetOptimizationModelPart()
|
|
25
|
+
self.design_surface = model_part_controller.GetDesignSurface()
|
|
26
|
+
self.output_settings = optimization_settings["output"]
|
|
27
|
+
|
|
28
|
+
self.write_design_surface = False
|
|
29
|
+
self.write_optimization_model_part = False
|
|
30
|
+
self.design_history_filename = None
|
|
31
|
+
|
|
32
|
+
self.__DetermineOutputMode()
|
|
33
|
+
self.__CreateUNVIO()
|
|
34
|
+
|
|
35
|
+
# --------------------------------------------------------------------------
|
|
36
|
+
def __DetermineOutputMode( self ):
|
|
37
|
+
output_mode = self.output_settings["design_output_mode"].GetString()
|
|
38
|
+
|
|
39
|
+
if output_mode == "write_design_surface":
|
|
40
|
+
self.write_design_surface = True
|
|
41
|
+
self.design_history_filename = self.design_surface.Name
|
|
42
|
+
elif output_mode == "write_optimization_model_part":
|
|
43
|
+
if self.optimization_model_part.NumberOfElements() == 0:
|
|
44
|
+
raise NameError("Output of optimization model part in UNV-format requires definition of elements. No elements are given in current mdpa! You may change the design output mode.")
|
|
45
|
+
self.write_optimization_model_part = True
|
|
46
|
+
self.design_history_filename = self.optimization_model_part.Name
|
|
47
|
+
else:
|
|
48
|
+
raise NameError("The following design output mode is not defined within a UNV output (name may be misspelled): " + OutputMode)
|
|
49
|
+
|
|
50
|
+
# --------------------------------------------------------------------------
|
|
51
|
+
def __CreateUNVIO( self ):
|
|
52
|
+
results_directory = self.output_settings["output_directory"].GetString()
|
|
53
|
+
design_history_file_path = results_directory+"/"+self.design_history_filename
|
|
54
|
+
nodal_results = self.output_settings["nodal_results"]
|
|
55
|
+
|
|
56
|
+
if self.write_design_surface:
|
|
57
|
+
self.UNVIO = KSO.UniversalFileIO( self.design_surface, design_history_file_path, "WriteConditionsOnly", nodal_results )
|
|
58
|
+
elif self.write_optimization_model_part:
|
|
59
|
+
self.UNVIO = KSO.UniversalFileIO( self.optimization_model_part, design_history_file_path, "WriteElementsOnly", nodal_results )
|
|
60
|
+
|
|
61
|
+
# --------------------------------------------------------------------------
|
|
62
|
+
def InitializeLogging( self ):
|
|
63
|
+
self.UNVIO.InitializeLogging()
|
|
64
|
+
|
|
65
|
+
# --------------------------------------------------------------------------
|
|
66
|
+
def LogCurrentDesign( self, OptimizationIteration ):
|
|
67
|
+
self.UNVIO.LogNodalResults( OptimizationIteration )
|
|
68
|
+
|
|
69
|
+
# --------------------------------------------------------------------------
|
|
70
|
+
def FinalizeLogging( self ):
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
# ==============================================================================
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Kratos Core and Apps
|
|
14
|
+
import KratosMultiphysics as KM
|
|
15
|
+
|
|
16
|
+
# Additional imports
|
|
17
|
+
from KratosMultiphysics.ShapeOptimizationApplication.loggers.design_logger_base import DesignLogger
|
|
18
|
+
from KratosMultiphysics.vtk_output_process import VtkOutputProcess
|
|
19
|
+
|
|
20
|
+
# ==============================================================================
|
|
21
|
+
class DesignLoggerVTK( DesignLogger ):
|
|
22
|
+
|
|
23
|
+
# --------------------------------------------------------------------------
|
|
24
|
+
def __init__( self, model_part_controller, optimization_settings ):
|
|
25
|
+
self.output_settings = optimization_settings["output"]
|
|
26
|
+
minimal_vtk_settings = KM.Parameters("""
|
|
27
|
+
{
|
|
28
|
+
"name" : "vtk",
|
|
29
|
+
"vtk_parameters" : {
|
|
30
|
+
"model_part_name" : "PLEASE_SPECIFY_MODEL_PART_NAME",
|
|
31
|
+
"write_ids" : false,
|
|
32
|
+
"file_format" : "binary",
|
|
33
|
+
"output_sub_model_parts" : false,
|
|
34
|
+
"output_path" : "Optimization_Results"
|
|
35
|
+
}
|
|
36
|
+
}""")
|
|
37
|
+
|
|
38
|
+
output_format = self.output_settings["output_format"]
|
|
39
|
+
if not output_format.Has("vtk_parameters"):
|
|
40
|
+
output_format.AddValue("vtk_parameters", minimal_vtk_settings["vtk_parameters"])
|
|
41
|
+
else:
|
|
42
|
+
if output_format["vtk_parameters"].Has("model_part_name"):
|
|
43
|
+
KM.Logger.PrintWarning("ShapeOpt::DesignLoggerVTK", "vtk output parameter `model_part_name` will be overwritten!")
|
|
44
|
+
if output_format["vtk_parameters"].Has("output_path"):
|
|
45
|
+
KM.Logger.PrintWarning("ShapeOpt::DesignLoggerVTK", "vtk output parameter `output_path` will be overwritten!")
|
|
46
|
+
|
|
47
|
+
output_format["vtk_parameters"].ValidateAndAssignDefaults(minimal_vtk_settings["vtk_parameters"])
|
|
48
|
+
|
|
49
|
+
self.model = model_part_controller.GetModel()
|
|
50
|
+
self.optimization_model_part = model_part_controller.GetOptimizationModelPart()
|
|
51
|
+
self.design_surface = model_part_controller.GetDesignSurface()
|
|
52
|
+
|
|
53
|
+
self.vtk_io = self.__CreateVTKIO()
|
|
54
|
+
|
|
55
|
+
# --------------------------------------------------------------------------
|
|
56
|
+
def __CreateVTKIO( self ):
|
|
57
|
+
|
|
58
|
+
vtk_parameters = self.output_settings["output_format"]["vtk_parameters"]
|
|
59
|
+
output_mode = self.output_settings["design_output_mode"].GetString()
|
|
60
|
+
|
|
61
|
+
nodal_results = self.output_settings["nodal_results"]
|
|
62
|
+
vtk_parameters.AddValue("nodal_solution_step_data_variables", nodal_results)
|
|
63
|
+
|
|
64
|
+
if output_mode == "write_design_surface":
|
|
65
|
+
vtk_parameters["model_part_name"].SetString(self.design_surface.FullName())
|
|
66
|
+
elif output_mode == "write_optimization_model_part":
|
|
67
|
+
vtk_parameters["model_part_name"].SetString(self.optimization_model_part.FullName())
|
|
68
|
+
else:
|
|
69
|
+
raise NameError("The following design output mode is not defined within a VTK output (name may be misspelled): " + output_mode)
|
|
70
|
+
|
|
71
|
+
vtk_parameters["output_path"].SetString(self.output_settings["output_directory"].GetString())
|
|
72
|
+
|
|
73
|
+
return VtkOutputProcess(self.model, vtk_parameters)
|
|
74
|
+
|
|
75
|
+
# --------------------------------------------------------------------------
|
|
76
|
+
def InitializeLogging( self ):
|
|
77
|
+
self.vtk_io.ExecuteInitialize()
|
|
78
|
+
self.vtk_io.ExecuteBeforeSolutionLoop()
|
|
79
|
+
|
|
80
|
+
# --------------------------------------------------------------------------
|
|
81
|
+
def LogCurrentDesign( self, optimizationIteration ):
|
|
82
|
+
OriginalTime = self.optimization_model_part.ProcessInfo[KM.TIME]
|
|
83
|
+
self.optimization_model_part.ProcessInfo[KM.TIME] = optimizationIteration
|
|
84
|
+
|
|
85
|
+
self.vtk_io.ExecuteInitializeSolutionStep()
|
|
86
|
+
if(self.vtk_io.IsOutputStep()):
|
|
87
|
+
self.vtk_io.PrintOutput()
|
|
88
|
+
self.vtk_io.ExecuteFinalizeSolutionStep()
|
|
89
|
+
|
|
90
|
+
self.optimization_model_part.ProcessInfo[KM.TIME] = OriginalTime
|
|
91
|
+
|
|
92
|
+
# --------------------------------------------------------------------------
|
|
93
|
+
def FinalizeLogging( self ):
|
|
94
|
+
self.vtk_io.ExecuteFinalize()
|
|
95
|
+
|
|
96
|
+
# ==============================================================================
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Schmölz David, https://github.com/dschmoelz
|
|
8
|
+
#
|
|
9
|
+
# ==============================================================================
|
|
10
|
+
|
|
11
|
+
# importing the Kratos Library
|
|
12
|
+
import KratosMultiphysics as Kratos
|
|
13
|
+
from KratosMultiphysics.ShapeOptimizationApplication.utilities.custom_sensitivity_heatmap import SensitivityHeatmapCalculator
|
|
14
|
+
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
class SensitivityHeatmapLoggerBase:
|
|
17
|
+
|
|
18
|
+
# --------------------------------------------------------------------------
|
|
19
|
+
def __init__( self, model_part_controller, optimization_settings ):
|
|
20
|
+
|
|
21
|
+
default_heatmap_settings = Kratos.Parameters("""
|
|
22
|
+
{
|
|
23
|
+
"norm_type": "l2",
|
|
24
|
+
"sensitivity_weighting": true,
|
|
25
|
+
"mapping" : true,
|
|
26
|
+
"relaxation_method": "reciprocal",
|
|
27
|
+
"relaxation_coefficient": 0.5
|
|
28
|
+
}""")
|
|
29
|
+
|
|
30
|
+
self.heatmap_settings = optimization_settings["output"]["sensitivity_heatmap_settings"]
|
|
31
|
+
if self.heatmap_settings.Has("relaxation_method") and self.heatmap_settings["relaxation_method"].GetString() == "constant":
|
|
32
|
+
if not self.heatmap_settings.Has("relaxation_coefficient"):
|
|
33
|
+
raise RuntimeError("'relaxation_coefficient' is missing for relaxation method 'constant'!")
|
|
34
|
+
self.heatmap_settings.ValidateAndAssignDefaults(default_heatmap_settings)
|
|
35
|
+
|
|
36
|
+
self.optimization_model_part = model_part_controller.GetOptimizationModelPart()
|
|
37
|
+
self.design_surface = model_part_controller.GetDesignSurface()
|
|
38
|
+
|
|
39
|
+
self.objectives = optimization_settings["objectives"]
|
|
40
|
+
self.constraints = optimization_settings["constraints"]
|
|
41
|
+
|
|
42
|
+
self.sensitivity_heatmap_calculator = None
|
|
43
|
+
|
|
44
|
+
# --------------------------------------------------------------------------
|
|
45
|
+
def InitializeLogging ( self ):
|
|
46
|
+
raise RuntimeError("Sensitivity Heatmap logger base class is called. Please check your implementation of the function >> InitializeLogging << .")
|
|
47
|
+
|
|
48
|
+
# --------------------------------------------------------------------------
|
|
49
|
+
def LogSensitivityHeatmap(self, optimization_iteration, mapper):
|
|
50
|
+
self.sensitivity_heatmap_calculator.ComputeHeatmaps(optimization_iteration, mapper)
|
|
51
|
+
|
|
52
|
+
# ==============================================================================
|
|
53
|
+
class SensitivityHeatmapLoggerSteepestDescent(SensitivityHeatmapLoggerBase):
|
|
54
|
+
|
|
55
|
+
def InitializeLogging(self):
|
|
56
|
+
self.heatmap_settings.AddString("design_variable_name", "X")
|
|
57
|
+
self.heatmap_settings.AddInt("design_variable_dimension", 3)
|
|
58
|
+
self.sensitivity_heatmap_calculator = SensitivityHeatmapCalculator(self.design_surface, self.objectives, self.constraints, self.heatmap_settings)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# ==============================================================================
|
|
62
|
+
class SensitivityHeatmapLoggerPenalizedProjection(SensitivityHeatmapLoggerBase):
|
|
63
|
+
|
|
64
|
+
def InitializeLogging(self):
|
|
65
|
+
self.heatmap_settings.AddString("design_variable_name", "X")
|
|
66
|
+
self.heatmap_settings.AddInt("design_variable_dimension", 3)
|
|
67
|
+
self.sensitivity_heatmap_calculator = SensitivityHeatmapCalculator(self.design_surface, self.objectives, self.constraints, self.heatmap_settings)
|
|
68
|
+
|
|
69
|
+
# ==============================================================================
|
|
70
|
+
class SensitivityHeatmapLoggerGradientProjection(SensitivityHeatmapLoggerBase):
|
|
71
|
+
|
|
72
|
+
def InitializeLogging(self):
|
|
73
|
+
self.heatmap_settings.AddString("design_variable_name", "X")
|
|
74
|
+
self.heatmap_settings.AddInt("design_variable_dimension", 3)
|
|
75
|
+
self.sensitivity_heatmap_calculator = SensitivityHeatmapCalculator(self.design_surface, self.objectives, self.constraints, self.heatmap_settings)
|
|
76
|
+
|
|
77
|
+
# ==============================================================================
|
|
78
|
+
class SensitivityHeatmapLoggerTrustRegion(SensitivityHeatmapLoggerBase):
|
|
79
|
+
|
|
80
|
+
def InitializeLogging(self):
|
|
81
|
+
self.heatmap_settings.AddString("design_variable_name", "X")
|
|
82
|
+
self.heatmap_settings.AddInt("design_variable_dimension", 3)
|
|
83
|
+
self.sensitivity_heatmap_calculator = SensitivityHeatmapCalculator(self.design_surface, self.objectives, self.constraints, self.heatmap_settings)
|
|
84
|
+
|
|
85
|
+
# ==============================================================================
|
|
86
|
+
class SensitivityHeatmapLoggerBeadOptimization(SensitivityHeatmapLoggerBase):
|
|
87
|
+
|
|
88
|
+
def InitializeLogging(self):
|
|
89
|
+
self.heatmap_settings.AddString("design_variable_name", "ALPHA")
|
|
90
|
+
self.heatmap_settings.AddInt("design_variable_dimension", 1)
|
|
91
|
+
self.sensitivity_heatmap_calculator = SensitivityHeatmapCalculator(self.design_surface, self.objectives, self.constraints, self.heatmap_settings)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
# importing the Kratos Library
|
|
13
|
+
import KratosMultiphysics as KM
|
|
14
|
+
|
|
15
|
+
# Import additional libraries
|
|
16
|
+
import os
|
|
17
|
+
|
|
18
|
+
# ==============================================================================
|
|
19
|
+
class ValueLogger():
|
|
20
|
+
|
|
21
|
+
# --------------------------------------------------------------------------
|
|
22
|
+
def __init__( self, communicator, optimization_settings ):
|
|
23
|
+
self.communicator = communicator
|
|
24
|
+
self.optimization_settings = optimization_settings
|
|
25
|
+
|
|
26
|
+
self.objectives = optimization_settings["objectives"]
|
|
27
|
+
self.constraints = optimization_settings["constraints"]
|
|
28
|
+
|
|
29
|
+
self.complete_log_file_name = self.__CreateCompleteLogFileName( optimization_settings )
|
|
30
|
+
|
|
31
|
+
self.obj_reference_value = 0
|
|
32
|
+
self.current_index = 0
|
|
33
|
+
self.previos_index = 0
|
|
34
|
+
|
|
35
|
+
self.history = { "response_value" : {},
|
|
36
|
+
"standardized_response_value" : {},
|
|
37
|
+
"abs_change_objective" : {},
|
|
38
|
+
"rel_change_objective" : {} }
|
|
39
|
+
|
|
40
|
+
for itr in range(self.objectives.size()):
|
|
41
|
+
objective_id = self.objectives[itr]["identifier"].GetString()
|
|
42
|
+
self.history["response_value"][objective_id] = {}
|
|
43
|
+
self.history["standardized_response_value"][objective_id] = {}
|
|
44
|
+
|
|
45
|
+
for itr in range(self.constraints.size()):
|
|
46
|
+
constraint_id = self.constraints[itr]["identifier"].GetString()
|
|
47
|
+
self.history["response_value"][constraint_id] = {}
|
|
48
|
+
self.history["standardized_response_value"][constraint_id] = {}
|
|
49
|
+
|
|
50
|
+
self.predefined_keys = list(self.history.keys())
|
|
51
|
+
|
|
52
|
+
# --------------------------------------------------------------------------
|
|
53
|
+
def InitializeLogging( self ):
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
# --------------------------------------------------------------------------
|
|
57
|
+
def LogCurrentValues( self, index, additional_values_dictionary ):
|
|
58
|
+
self.current_index = index
|
|
59
|
+
|
|
60
|
+
self.__LogObjectiveValuesToHistory()
|
|
61
|
+
self.__LogConstraintValuesToHistory()
|
|
62
|
+
self.__LogAdditionalValuesToHistory( additional_values_dictionary )
|
|
63
|
+
|
|
64
|
+
self._WriteCurrentValuesToConsole()
|
|
65
|
+
self._WriteCurrentValuesToFile()
|
|
66
|
+
|
|
67
|
+
self.previos_index = index
|
|
68
|
+
|
|
69
|
+
# --------------------------------------------------------------------------
|
|
70
|
+
def FinalizeLogging( self ):
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
# --------------------------------------------------------------------------
|
|
74
|
+
def GetValues( self, key ):
|
|
75
|
+
return self.history[key]
|
|
76
|
+
|
|
77
|
+
# --------------------------------------------------------------------------
|
|
78
|
+
@staticmethod
|
|
79
|
+
def __CreateCompleteLogFileName( optimization_settings ):
|
|
80
|
+
resultsDirectory = optimization_settings["output"]["output_directory"].GetString()
|
|
81
|
+
optimizationLogFilename = optimization_settings["output"]["optimization_log_filename"].GetString() + ".csv"
|
|
82
|
+
return os.path.join( resultsDirectory, optimizationLogFilename )
|
|
83
|
+
|
|
84
|
+
# --------------------------------------------------------------------------
|
|
85
|
+
def __LogObjectiveValuesToHistory( self ):
|
|
86
|
+
objective_id = self.objectives[0]["identifier"].GetString()
|
|
87
|
+
is_first_log = self.history["response_value"][objective_id] == {}
|
|
88
|
+
|
|
89
|
+
self.history["response_value"][objective_id][self.current_index] = self.communicator.getValue( objective_id )
|
|
90
|
+
self.history["standardized_response_value"][objective_id][self.current_index] = self.communicator.getStandardizedValue( objective_id )
|
|
91
|
+
|
|
92
|
+
if is_first_log:
|
|
93
|
+
self.obj_reference_value = self.communicator.getValue( objective_id )
|
|
94
|
+
|
|
95
|
+
if abs(self.obj_reference_value)<1e-12:
|
|
96
|
+
KM.Logger.PrintWarning("ShapeOpt::ValueLogger", "Objective reference value < 1e-12!! Therefore, standard reference value of 1 is assumed! ")
|
|
97
|
+
self.obj_reference_value = 1.0
|
|
98
|
+
|
|
99
|
+
self.history["abs_change_objective"] = {self.current_index: 0.0}
|
|
100
|
+
self.history["rel_change_objective"] = {self.current_index: 0.0}
|
|
101
|
+
else:
|
|
102
|
+
current_obj_value = self.history["response_value"][objective_id][self.current_index]
|
|
103
|
+
previos_obj_value = self.history["response_value"][objective_id][self.previos_index]
|
|
104
|
+
abs_change = 100*(current_obj_value-self.obj_reference_value) / abs(self.obj_reference_value)
|
|
105
|
+
rel_change = 100*(current_obj_value-previos_obj_value) / abs(self.obj_reference_value)
|
|
106
|
+
|
|
107
|
+
self.history["abs_change_objective"][self.current_index] = abs_change
|
|
108
|
+
self.history["rel_change_objective"][self.current_index] = rel_change
|
|
109
|
+
|
|
110
|
+
# --------------------------------------------------------------------------
|
|
111
|
+
def __LogConstraintValuesToHistory( self ):
|
|
112
|
+
for itr in range(self.constraints.size()):
|
|
113
|
+
constraint_id = self.constraints[itr]["identifier"].GetString()
|
|
114
|
+
self.history["response_value"][constraint_id][self.current_index] = self.communicator.getValue( constraint_id )
|
|
115
|
+
self.history["standardized_response_value"][constraint_id][self.current_index] = self.communicator.getStandardizedValue( constraint_id )
|
|
116
|
+
|
|
117
|
+
# --------------------------------------------------------------------------
|
|
118
|
+
def __LogAdditionalValuesToHistory( self, additional_values_dictionary ):
|
|
119
|
+
for key, value in additional_values_dictionary.items():
|
|
120
|
+
if key in self.predefined_keys:
|
|
121
|
+
raise NameError("ValueLogger: The key \""+key+"\" is already predefined and may not be overwritten! Predefined keys are: "+str(self.predefined_keys))
|
|
122
|
+
|
|
123
|
+
if key not in self.history.keys():
|
|
124
|
+
self.history[key] = {}
|
|
125
|
+
|
|
126
|
+
self.history[key][self.current_index] = value
|
|
127
|
+
|
|
128
|
+
# ==============================================================================
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
# Geiser Armin, https://github.com/armingeiser
|
|
9
|
+
#
|
|
10
|
+
# ==============================================================================
|
|
11
|
+
|
|
12
|
+
# importing the Kratos Library
|
|
13
|
+
import KratosMultiphysics as KM
|
|
14
|
+
|
|
15
|
+
# Import logger base classes
|
|
16
|
+
from KratosMultiphysics.ShapeOptimizationApplication.loggers.value_logger_base import ValueLogger
|
|
17
|
+
|
|
18
|
+
# Import additional libraries
|
|
19
|
+
import csv
|
|
20
|
+
from KratosMultiphysics.ShapeOptimizationApplication.utilities.custom_timer import Timer
|
|
21
|
+
|
|
22
|
+
# ==============================================================================
|
|
23
|
+
class ValueLoggerBeadOptimization( ValueLogger ):
|
|
24
|
+
# --------------------------------------------------------------------------
|
|
25
|
+
def InitializeLogging( self ):
|
|
26
|
+
with open(self.complete_log_file_name, 'w') as csvfile:
|
|
27
|
+
historyWriter = csv.writer(csvfile, delimiter=',',quotechar='|',quoting=csv.QUOTE_MINIMAL)
|
|
28
|
+
row = []
|
|
29
|
+
row.append("{:>12s}".format("overall_itr"))
|
|
30
|
+
row.append("{:>10s}".format("outer_itr"))
|
|
31
|
+
row.append("{:>10s}".format("inner_itr"))
|
|
32
|
+
row.append("{:>13s}".format("l"))
|
|
33
|
+
row.append("{:>13s}".format("dl_rel[%]"))
|
|
34
|
+
row.append("{:>13s}".format("f"))
|
|
35
|
+
row.append("{:>13s}".format("df_abs[%]"))
|
|
36
|
+
row.append("{:>13s}".format("df_rel[%]"))
|
|
37
|
+
row.append("{:>14s}".format("max_norm_dfda"))
|
|
38
|
+
row.append("{:>13s}".format("lambda_p"))
|
|
39
|
+
row.append("{:>13s}".format("p"))
|
|
40
|
+
row.append("{:>13s}".format("p_scaling"))
|
|
41
|
+
row.append("{:>13s}".format("p_fac"))
|
|
42
|
+
row.append("{:>13s}".format("step_size"))
|
|
43
|
+
row.append("{:>25s}".format("time_stamp"))
|
|
44
|
+
historyWriter.writerow(row)
|
|
45
|
+
|
|
46
|
+
# --------------------------------------------------------------------------
|
|
47
|
+
def _WriteCurrentValuesToConsole( self ):
|
|
48
|
+
objective_id = self.objectives[0]["identifier"].GetString()
|
|
49
|
+
KM.Logger.Print("")
|
|
50
|
+
KM.Logger.PrintInfo("ShapeOpt", "Current value of objective = ","{:> .5E}".format(self.history["response_value"][objective_id][self.current_index]))
|
|
51
|
+
|
|
52
|
+
KM.Logger.PrintInfo("ShapeOpt", "Absolut change of objective = ","{:> .5E}".format(self.history["abs_change_objective"][self.current_index])," [%]")
|
|
53
|
+
KM.Logger.PrintInfo("ShapeOpt", "Relative change of objective = ","{:> .5E}".format(self.history["rel_change_objective"][self.current_index])," [%]\n")
|
|
54
|
+
KM.Logger.PrintInfo("ShapeOpt", "Value of penalty term = ","{:> .5E}".format(self.history["penalty_value"][self.current_index]),"\n")
|
|
55
|
+
|
|
56
|
+
# --------------------------------------------------------------------------
|
|
57
|
+
def _WriteCurrentValuesToFile( self ):
|
|
58
|
+
with open(self.complete_log_file_name, 'a') as csvfile:
|
|
59
|
+
historyWriter = csv.writer(csvfile, delimiter=',',quotechar='|',quoting=csv.QUOTE_MINIMAL)
|
|
60
|
+
row = []
|
|
61
|
+
row.append("{:>12d}".format(self.current_index))
|
|
62
|
+
row.append("{:>10d}".format(self.history["outer_iteration"][self.current_index]))
|
|
63
|
+
row.append("{:>10d}".format(self.history["inner_iteration"][self.current_index]))
|
|
64
|
+
objective_id = self.objectives[0]["identifier"].GetString()
|
|
65
|
+
row.append(" {:> .5E}".format(self.history["lagrange_value"][self.current_index]))
|
|
66
|
+
row.append(" {:> .5E}".format(self.history["lagrange_value_relative_change"][self.current_index]))
|
|
67
|
+
row.append(" {:> .5E}".format(self.history["response_value"][objective_id][self.current_index]))
|
|
68
|
+
row.append(" {:> .5E}".format(self.history["abs_change_objective"][self.current_index]))
|
|
69
|
+
row.append(" {:> .5E}".format(self.history["rel_change_objective"][self.current_index]))
|
|
70
|
+
row.append(" {:> .5E}".format(self.history["max_norm_objective_gradient"][self.current_index]))
|
|
71
|
+
row.append(" {:> .5E}".format(self.history["penalty_lambda"][self.current_index]))
|
|
72
|
+
row.append(" {:> .5E}".format(self.history["penalty_value"][self.current_index]))
|
|
73
|
+
row.append(" {:> .5E}".format(self.history["penalty_scaling"][self.current_index]))
|
|
74
|
+
row.append(" {:> .5E}".format(self.history["penalty_factor"][self.current_index]))
|
|
75
|
+
row.append(" {:> .5E}".format(self.history["step_size"][self.current_index]))
|
|
76
|
+
row.append("{:>25}".format(Timer().GetTimeStamp()))
|
|
77
|
+
historyWriter.writerow(row)
|
|
78
|
+
|
|
79
|
+
# ==============================================================================
|