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,140 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Geiser Armin, https://github.com/armingeiser
|
|
8
|
+
#
|
|
9
|
+
# ==============================================================================
|
|
10
|
+
|
|
11
|
+
import KratosMultiphysics as KM
|
|
12
|
+
import KratosMultiphysics.ShapeOptimizationApplication as KSO
|
|
13
|
+
try:
|
|
14
|
+
import KratosMultiphysics.MappingApplication as KMA
|
|
15
|
+
SpacialMapperFactory = KMA.MapperFactory
|
|
16
|
+
except ImportError:
|
|
17
|
+
SpacialMapperFactory = None
|
|
18
|
+
from ..custom_ios.wrl_io import WrlIO
|
|
19
|
+
|
|
20
|
+
class InPlaneVertexMorphingMapper():
|
|
21
|
+
"""
|
|
22
|
+
The InPlaneVertexMorphingMapper extends the standard Vertex Morphing approach
|
|
23
|
+
by restricting the shape update of nodes to an in-plane motion only. The nodes
|
|
24
|
+
are only allowed to float on a predefined background mesh.
|
|
25
|
+
The background mesh can be the initial mesh of the design surface, or another mesh
|
|
26
|
+
describing the same geometry (ideally also filling holes in the surface).
|
|
27
|
+
This is especially important if the design surface extends during the optimization.
|
|
28
|
+
|
|
29
|
+
Limitations:
|
|
30
|
+
- Damping can only be used if all cartesian directions (x,y,z) are damped.
|
|
31
|
+
- The projection of gradients on the surface normals has to be deactivated.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, origin_model_part, destination_model_part, settings):
|
|
35
|
+
from KratosMultiphysics.ShapeOptimizationApplication import mapper_factory
|
|
36
|
+
if not SpacialMapperFactory:
|
|
37
|
+
raise Exception("InPlaneVertexMorphingMapper: MappingApplication is required!")
|
|
38
|
+
|
|
39
|
+
self.settings = settings
|
|
40
|
+
self.origin_model_part = origin_model_part
|
|
41
|
+
self.destination_model_part = destination_model_part
|
|
42
|
+
|
|
43
|
+
extracted_vm_settings = settings.Clone()
|
|
44
|
+
extracted_vm_settings["in_plane_morphing"].SetBool(False)
|
|
45
|
+
extracted_vm_settings.RemoveValue("in_plane_morphing_settings")
|
|
46
|
+
self.vm_mapper = mapper_factory.CreateMapper(origin_model_part, destination_model_part, extracted_vm_settings)
|
|
47
|
+
|
|
48
|
+
in_plane_settings = self.settings["in_plane_morphing_settings"]
|
|
49
|
+
in_plane_settings.RecursivelyValidateAndAssignDefaults(self.GetDefaultInPlaneSettings())
|
|
50
|
+
|
|
51
|
+
self._background_model = KM.Model()
|
|
52
|
+
if in_plane_settings["model_import_settings"]["input_type"].GetString() in ["mdpa", "vrml", "wrl"]:
|
|
53
|
+
background_main_mesh = self._background_model.CreateModelPart("background_mesh")
|
|
54
|
+
background_main_mesh.ProcessInfo.SetValue(KM.DOMAIN_SIZE, 3)
|
|
55
|
+
background_main_mesh.AddNodalSolutionStepVariable(KM.NORMAL)
|
|
56
|
+
background_main_mesh.AddNodalSolutionStepVariable(KSO.NORMALIZED_SURFACE_NORMAL)
|
|
57
|
+
background_main_mesh.AddNodalSolutionStepVariable(KSO.BACKGROUND_COORDINATE)
|
|
58
|
+
else:
|
|
59
|
+
raise Exception("Other model part input options are not yet implemented.")
|
|
60
|
+
|
|
61
|
+
self.background_mesh = None # created in Initialize
|
|
62
|
+
self.spacial_mapper = None # created in Initialize
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def GetDefaultInPlaneSettings(cls):
|
|
66
|
+
return KM.Parameters("""{
|
|
67
|
+
"model_import_settings" : {
|
|
68
|
+
"input_type" : "mdpa",
|
|
69
|
+
"input_filename" : "UNKNOWN_NAME"
|
|
70
|
+
},
|
|
71
|
+
"background_sub_model_part_name" : "",
|
|
72
|
+
"spacial_mapper_settings" : {
|
|
73
|
+
"mapper_type": "nearest_element",
|
|
74
|
+
"echo_level" : 0
|
|
75
|
+
}
|
|
76
|
+
}""")
|
|
77
|
+
|
|
78
|
+
def Initialize(self):
|
|
79
|
+
self.vm_mapper.Initialize()
|
|
80
|
+
|
|
81
|
+
in_plane_settings = self.settings["in_plane_morphing_settings"]
|
|
82
|
+
|
|
83
|
+
background_main_mesh = self._background_model.GetModelPart("background_mesh")
|
|
84
|
+
if in_plane_settings["model_import_settings"]["input_type"].GetString() == "mdpa":
|
|
85
|
+
model_part_io = KM.ModelPartIO(in_plane_settings["model_import_settings"]["input_filename"].GetString())
|
|
86
|
+
model_part_io.ReadModelPart(background_main_mesh)
|
|
87
|
+
elif in_plane_settings["model_import_settings"]["input_type"].GetString() in ["vrml", "wrl"]:
|
|
88
|
+
model_part_io = WrlIO(in_plane_settings["model_import_settings"]["input_filename"].GetString())
|
|
89
|
+
model_part_io.ReadModelPart(background_main_mesh)
|
|
90
|
+
|
|
91
|
+
background_sub_model_part_name = in_plane_settings["background_sub_model_part_name"].GetString()
|
|
92
|
+
if background_sub_model_part_name == "":
|
|
93
|
+
self.background_mesh = background_main_mesh
|
|
94
|
+
else:
|
|
95
|
+
self.background_mesh = background_main_mesh.GetSubModelPart(background_sub_model_part_name)
|
|
96
|
+
|
|
97
|
+
background_geometry_utilities = KSO.GeometryUtilities(self.background_mesh)
|
|
98
|
+
background_geometry_utilities.ComputeUnitSurfaceNormals()
|
|
99
|
+
self.spacial_mapper = SpacialMapperFactory.CreateMapper(
|
|
100
|
+
self.background_mesh, self.destination_model_part, in_plane_settings["spacial_mapper_settings"])
|
|
101
|
+
|
|
102
|
+
KSO.MeshControllerUtilities(self.background_mesh).WriteCoordinatesToVariable(KSO.BACKGROUND_COORDINATE)
|
|
103
|
+
|
|
104
|
+
def Update(self):
|
|
105
|
+
self.vm_mapper.Update()
|
|
106
|
+
self.spacial_mapper.UpdateInterface()
|
|
107
|
+
self.spacial_mapper.Map(KSO.NORMALIZED_SURFACE_NORMAL, KSO.BACKGROUND_NORMAL)
|
|
108
|
+
|
|
109
|
+
def Map(self, origin_variable, destination_variable):
|
|
110
|
+
self.vm_mapper.Map(origin_variable, destination_variable)
|
|
111
|
+
|
|
112
|
+
geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
|
|
113
|
+
geometry_utilities.ProjectNodalVariableOnTangentPlane(
|
|
114
|
+
destination_variable, KSO.BACKGROUND_NORMAL)
|
|
115
|
+
|
|
116
|
+
self._CorrectOutOfPlanePart(destination_variable)
|
|
117
|
+
|
|
118
|
+
def InverseMap(self, destination_variable, origin_variable):
|
|
119
|
+
geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
|
|
120
|
+
geometry_utilities.ProjectNodalVariableOnTangentPlane(
|
|
121
|
+
destination_variable, KSO.BACKGROUND_NORMAL)
|
|
122
|
+
|
|
123
|
+
self.vm_mapper.InverseMap(destination_variable, origin_variable)
|
|
124
|
+
|
|
125
|
+
def _CorrectOutOfPlanePart(self, destination_variable):
|
|
126
|
+
geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
|
|
127
|
+
mesh_utilities = KSO.MeshControllerUtilities(self.destination_model_part)
|
|
128
|
+
|
|
129
|
+
mesh_utilities.UpdateMeshAccordingInputVariable(destination_variable)
|
|
130
|
+
mesh_utilities.SetReferenceMeshToMesh()
|
|
131
|
+
|
|
132
|
+
self.spacial_mapper.UpdateInterface()
|
|
133
|
+
self.spacial_mapper.Map(KSO.BACKGROUND_COORDINATE, KSO.BACKGROUND_COORDINATE)
|
|
134
|
+
mesh_utilities.SubtractCoordinatesFromVariable(KSO.BACKGROUND_COORDINATE, KSO.OUT_OF_PLANE_DELTA)
|
|
135
|
+
geometry_utilities.ProjectNodalVariableOnDirection(KSO.OUT_OF_PLANE_DELTA, KSO.BACKGROUND_NORMAL)
|
|
136
|
+
|
|
137
|
+
mesh_utilities.RevertMeshUpdateAccordingInputVariable(destination_variable)
|
|
138
|
+
mesh_utilities.SetReferenceMeshToMesh()
|
|
139
|
+
|
|
140
|
+
mesh_utilities.AddFirstVariableToSecondVariable(KSO.OUT_OF_PLANE_DELTA, destination_variable)
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Schmoelz David, https://github.com/dschmoelz
|
|
8
|
+
#
|
|
9
|
+
# ==============================================================================
|
|
10
|
+
|
|
11
|
+
import KratosMultiphysics as KM
|
|
12
|
+
import KratosMultiphysics.ShapeOptimizationApplication as KSO
|
|
13
|
+
try:
|
|
14
|
+
import KratosMultiphysics.StructuralMechanicsApplication as KSM
|
|
15
|
+
from KratosMultiphysics.StructuralMechanicsApplication.structural_mechanics_analysis import StructuralMechanicsAnalysis
|
|
16
|
+
except ImportError:
|
|
17
|
+
KSM = None
|
|
18
|
+
StructuralMechanicsAnalysis = None
|
|
19
|
+
SpacialMapperFactory = KM.MapperFactory
|
|
20
|
+
|
|
21
|
+
from ..custom_ios.wrl_io import WrlIO
|
|
22
|
+
|
|
23
|
+
class SlidingVertexMorphingMapper():
|
|
24
|
+
"""
|
|
25
|
+
The SlidingVertexMorphingMapper extends the standard Vertex Morphing approach
|
|
26
|
+
by restricting the nodal shape update of a specified model part. The nodes of this model
|
|
27
|
+
part have to lie on a predefined background mesh and are only allowed to float/slide on it.
|
|
28
|
+
SlidingVertexMorphingMapper uses similar techniques as direction damping and
|
|
29
|
+
InPlaneVertexMorphingMapper.
|
|
30
|
+
|
|
31
|
+
Limitations:
|
|
32
|
+
- Damping can only be used if all cartesian directions (x,y,z) are damped.
|
|
33
|
+
- The projection of gradients on the surface normals has to be deactivated.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, origin_model_part, destination_model_part, settings):
|
|
37
|
+
from KratosMultiphysics.ShapeOptimizationApplication import mapper_factory
|
|
38
|
+
if not SpacialMapperFactory:
|
|
39
|
+
raise Exception("SlidingVertexMorphingMapper: MappingApplication is required!")
|
|
40
|
+
if not KSM:
|
|
41
|
+
raise Exception("SlidingVertexMorphingMapper: StructuralMechanicsApplication is required!")
|
|
42
|
+
|
|
43
|
+
self.settings = settings
|
|
44
|
+
self.origin_model_part = origin_model_part
|
|
45
|
+
self.destination_model_part = destination_model_part
|
|
46
|
+
|
|
47
|
+
extracted_vm_settings = settings.Clone()
|
|
48
|
+
extracted_vm_settings["sliding_morphing"].SetBool(False)
|
|
49
|
+
extracted_vm_settings.RemoveValue("sliding_morphing_settings")
|
|
50
|
+
self.vm_mapper = mapper_factory.CreateMapper(origin_model_part, destination_model_part, extracted_vm_settings)
|
|
51
|
+
|
|
52
|
+
in_plane_settings = self.settings["sliding_morphing_settings"]
|
|
53
|
+
in_plane_settings.RecursivelyValidateAndAssignDefaults(self.GetDefaultInPlaneSettings())
|
|
54
|
+
|
|
55
|
+
self._background_model = KM.Model()
|
|
56
|
+
if in_plane_settings["model_import_settings"]["input_type"].GetString() in ["mdpa", "vrml", "wrl"]:
|
|
57
|
+
background_main_mesh = self._background_model.CreateModelPart("background_mesh")
|
|
58
|
+
background_main_mesh.ProcessInfo.SetValue(KM.DOMAIN_SIZE, 3)
|
|
59
|
+
background_main_mesh.AddNodalSolutionStepVariable(KM.NORMAL)
|
|
60
|
+
background_main_mesh.AddNodalSolutionStepVariable(KSO.NORMALIZED_SURFACE_NORMAL)
|
|
61
|
+
background_main_mesh.AddNodalSolutionStepVariable(KSO.BACKGROUND_COORDINATE)
|
|
62
|
+
else:
|
|
63
|
+
raise Exception("Other model part input options are not yet implemented.")
|
|
64
|
+
|
|
65
|
+
self.background_mesh = None # created in Initialize
|
|
66
|
+
self.spacial_mapper = None # created in Initialize
|
|
67
|
+
self.sliding_mesh = None # created in Initialize
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def GetDefaultInPlaneSettings(cls):
|
|
71
|
+
return KM.Parameters("""{
|
|
72
|
+
"model_import_settings" : {
|
|
73
|
+
"input_type" : "mdpa",
|
|
74
|
+
"input_filename" : "UNKNOWN_NAME"
|
|
75
|
+
},
|
|
76
|
+
"sliding_sub_model_part_name" : "",
|
|
77
|
+
"background_sub_model_part_name" : "",
|
|
78
|
+
"spacial_mapper_settings" : {
|
|
79
|
+
"mapper_type": "nearest_element",
|
|
80
|
+
"echo_level" : 0
|
|
81
|
+
}
|
|
82
|
+
}""")
|
|
83
|
+
|
|
84
|
+
def GetStructuralSimilaritySettings(self):
|
|
85
|
+
return KM.Parameters(
|
|
86
|
+
"""{
|
|
87
|
+
"problem_data" : {
|
|
88
|
+
"problem_name" : "structural_similarity",
|
|
89
|
+
"parallel_type" : "OpenMP",
|
|
90
|
+
"start_time" : 0.0,
|
|
91
|
+
"end_time" : 1.0,
|
|
92
|
+
"echo_level" : 0
|
|
93
|
+
},
|
|
94
|
+
"solver_settings" : {
|
|
95
|
+
"solver_type" : "static",
|
|
96
|
+
"analysis_type" : "linear",
|
|
97
|
+
"model_part_name" : "main",
|
|
98
|
+
"domain_size" : 3,
|
|
99
|
+
"time_stepping" : {
|
|
100
|
+
"time_step" : 1.0
|
|
101
|
+
},
|
|
102
|
+
"model_import_settings" : {
|
|
103
|
+
"input_type" : "use_input_model_part"
|
|
104
|
+
},
|
|
105
|
+
"rotation_dofs" : true
|
|
106
|
+
},
|
|
107
|
+
"processes" : {
|
|
108
|
+
"constraints_process_list" : [
|
|
109
|
+
{
|
|
110
|
+
"python_module" : "assign_vector_variable_process",
|
|
111
|
+
"kratos_module" : "KratosMultiphysics",
|
|
112
|
+
"help" : "This process fixes the selected components of a given vector variable",
|
|
113
|
+
"process_name" : "AssignVectorVariableProcess",
|
|
114
|
+
"Parameters" : {
|
|
115
|
+
"model_part_name" : "main.fixed_bc",
|
|
116
|
+
"variable_name" : "DISPLACEMENT",
|
|
117
|
+
"value" : [0.0,0.0,0.0]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
}""")
|
|
123
|
+
|
|
124
|
+
def Initialize(self):
|
|
125
|
+
self.vm_mapper.Initialize()
|
|
126
|
+
|
|
127
|
+
sliding_settings = self.settings["sliding_morphing_settings"]
|
|
128
|
+
|
|
129
|
+
background_main_mesh = self._background_model.GetModelPart("background_mesh")
|
|
130
|
+
if sliding_settings["model_import_settings"]["input_type"].GetString() == "mdpa":
|
|
131
|
+
model_part_io = KM.ModelPartIO(sliding_settings["model_import_settings"]["input_filename"].GetString())
|
|
132
|
+
model_part_io.ReadModelPart(background_main_mesh)
|
|
133
|
+
elif sliding_settings["model_import_settings"]["input_type"].GetString() in ["vrml", "wrl"]:
|
|
134
|
+
model_part_io = WrlIO(sliding_settings["model_import_settings"]["input_filename"].GetString())
|
|
135
|
+
model_part_io.ReadModelPart(background_main_mesh)
|
|
136
|
+
|
|
137
|
+
background_sub_model_part_name = sliding_settings["background_sub_model_part_name"].GetString()
|
|
138
|
+
if background_sub_model_part_name == "":
|
|
139
|
+
self.background_mesh = background_main_mesh
|
|
140
|
+
else:
|
|
141
|
+
self.background_mesh = background_main_mesh.GetSubModelPart(background_sub_model_part_name)
|
|
142
|
+
|
|
143
|
+
sliding_sub_model_part_name = sliding_settings["sliding_sub_model_part_name"].GetString()
|
|
144
|
+
root_model_part = self.destination_model_part.GetRootModelPart()
|
|
145
|
+
self.sliding_mesh = root_model_part.GetSubModelPart(sliding_sub_model_part_name)
|
|
146
|
+
|
|
147
|
+
background_geometry_utilities = KSO.GeometryUtilities(self.background_mesh)
|
|
148
|
+
background_geometry_utilities.ComputeUnitSurfaceNormals()
|
|
149
|
+
self.spacial_mapper = SpacialMapperFactory.CreateMapper(
|
|
150
|
+
self.background_mesh, self.sliding_mesh, sliding_settings["spacial_mapper_settings"])
|
|
151
|
+
|
|
152
|
+
KSO.MeshControllerUtilities(self.background_mesh).WriteCoordinatesToVariable(KSO.BACKGROUND_COORDINATE)
|
|
153
|
+
|
|
154
|
+
def Update(self):
|
|
155
|
+
self.vm_mapper.Update()
|
|
156
|
+
self.spacial_mapper.UpdateInterface()
|
|
157
|
+
self.spacial_mapper.Map(KSO.NORMALIZED_SURFACE_NORMAL, KSO.BACKGROUND_NORMAL)
|
|
158
|
+
|
|
159
|
+
# create structural similarity model and analysis
|
|
160
|
+
self._structural_model = KM.Model()
|
|
161
|
+
self._CreateStructuralModel(self._structural_model)
|
|
162
|
+
|
|
163
|
+
self._structural_model_correction = KM.Model()
|
|
164
|
+
self._CreateStructuralModel(self._structural_model_correction)
|
|
165
|
+
|
|
166
|
+
structural_mechanics_analysis_setings = self.GetStructuralSimilaritySettings()
|
|
167
|
+
# two structural similarity analysis for damping vectors and non-linear correction
|
|
168
|
+
self._structural_mechanics_analysis = StructuralMechanicsAnalysis(self._structural_model, structural_mechanics_analysis_setings)
|
|
169
|
+
self._structural_mechanics_analysis_correction = StructuralMechanicsAnalysis(self._structural_model_correction, structural_mechanics_analysis_setings)
|
|
170
|
+
|
|
171
|
+
# propagate background normal field from sliding mesh to destination
|
|
172
|
+
self._PerformStructuralSimilarityAnalysis(self._structural_mechanics_analysis, self._structural_model, KSO.BACKGROUND_NORMAL)
|
|
173
|
+
|
|
174
|
+
def Map(self, origin_variable, destination_variable):
|
|
175
|
+
self.vm_mapper.Map(origin_variable, destination_variable)
|
|
176
|
+
|
|
177
|
+
geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
|
|
178
|
+
|
|
179
|
+
geometry_utilities.ProjectNodalVariableOnTangentPlane(
|
|
180
|
+
destination_variable, KSO.BACKGROUND_NORMAL)
|
|
181
|
+
|
|
182
|
+
# non-linear correction on sliding mesh
|
|
183
|
+
self._CorrectOutOfPlanePart(destination_variable)
|
|
184
|
+
|
|
185
|
+
mesh_utilities_struct = KSO.MeshControllerUtilities(self._structural_model_correction.GetModelPart("main"))
|
|
186
|
+
|
|
187
|
+
# map linear shape update to structural model
|
|
188
|
+
ne_mapper_settings = KM.Parameters("""{
|
|
189
|
+
"mapper_type": "nearest_element",
|
|
190
|
+
"echo_level" : 0
|
|
191
|
+
}""")
|
|
192
|
+
model_mapper = SpacialMapperFactory.CreateMapper(
|
|
193
|
+
self.destination_model_part, self._structural_model_correction.GetModelPart("main"),
|
|
194
|
+
ne_mapper_settings)
|
|
195
|
+
|
|
196
|
+
model_mapper.Map(destination_variable, destination_variable)
|
|
197
|
+
|
|
198
|
+
# update structural model
|
|
199
|
+
mesh_utilities_struct.UpdateMeshAccordingInputVariable(destination_variable)
|
|
200
|
+
mesh_utilities_struct.SetReferenceMeshToMesh()
|
|
201
|
+
|
|
202
|
+
# propagate non-linear correction from sliding mesh to destination
|
|
203
|
+
self._PerformStructuralSimilarityAnalysis(self._structural_mechanics_analysis_correction, self._structural_model_correction, KSO.OUT_OF_PLANE_DELTA)
|
|
204
|
+
|
|
205
|
+
# revert structural model
|
|
206
|
+
mesh_utilities_struct.RevertMeshUpdateAccordingInputVariable(destination_variable)
|
|
207
|
+
mesh_utilities_struct.SetReferenceMeshToMesh()
|
|
208
|
+
|
|
209
|
+
# add non-linear correction to shape update
|
|
210
|
+
mesh_utilities = KSO.MeshControllerUtilities(self.destination_model_part)
|
|
211
|
+
mesh_utilities.AddFirstVariableToSecondVariable(KSO.OUT_OF_PLANE_DELTA, destination_variable)
|
|
212
|
+
|
|
213
|
+
def InverseMap(self, destination_variable, origin_variable):
|
|
214
|
+
geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
|
|
215
|
+
|
|
216
|
+
geometry_utilities.ProjectNodalVariableOnTangentPlane(
|
|
217
|
+
destination_variable, KSO.BACKGROUND_NORMAL)
|
|
218
|
+
|
|
219
|
+
self.vm_mapper.InverseMap(destination_variable, origin_variable)
|
|
220
|
+
|
|
221
|
+
def _CorrectOutOfPlanePart(self, destination_variable):
|
|
222
|
+
geometry_utilities = KSO.GeometryUtilities(self.sliding_mesh)
|
|
223
|
+
mesh_utilities = KSO.MeshControllerUtilities(self.sliding_mesh)
|
|
224
|
+
|
|
225
|
+
mesh_utilities.UpdateMeshAccordingInputVariable(destination_variable)
|
|
226
|
+
mesh_utilities.SetReferenceMeshToMesh()
|
|
227
|
+
|
|
228
|
+
self.spacial_mapper.UpdateInterface()
|
|
229
|
+
self.spacial_mapper.Map(KSO.BACKGROUND_COORDINATE, KSO.BACKGROUND_COORDINATE)
|
|
230
|
+
mesh_utilities.SubtractCoordinatesFromVariable(KSO.BACKGROUND_COORDINATE, KSO.OUT_OF_PLANE_DELTA)
|
|
231
|
+
geometry_utilities.ProjectNodalVariableOnDirection(KSO.OUT_OF_PLANE_DELTA, KSO.BACKGROUND_NORMAL)
|
|
232
|
+
|
|
233
|
+
mesh_utilities.RevertMeshUpdateAccordingInputVariable(destination_variable)
|
|
234
|
+
mesh_utilities.SetReferenceMeshToMesh()
|
|
235
|
+
|
|
236
|
+
def _PerformStructuralSimilarityAnalysis(self, structural_analysis, structural_model, input_variable):
|
|
237
|
+
|
|
238
|
+
mesh_utilities = KSO.MeshControllerUtilities(structural_model.GetModelPart("main"))
|
|
239
|
+
mesh_prescribed_part = structural_model.GetModelPart("main.prescribed_bc")
|
|
240
|
+
|
|
241
|
+
# nearest element mapping from destination to sliding mesh
|
|
242
|
+
ne_mapper_settings = KM.Parameters("""{
|
|
243
|
+
"mapper_type": "nearest_element",
|
|
244
|
+
"echo_level" : 0
|
|
245
|
+
}""")
|
|
246
|
+
prescribed_mapper = SpacialMapperFactory.CreateMapper(
|
|
247
|
+
self.destination_model_part, mesh_prescribed_part,
|
|
248
|
+
ne_mapper_settings)
|
|
249
|
+
|
|
250
|
+
prescribed_mapper.Map(input_variable, KM.DISPLACEMENT)
|
|
251
|
+
|
|
252
|
+
# fix dbc on sliding mesh
|
|
253
|
+
KM.VariableUtils().ApplyFixity(KM.DISPLACEMENT_X, True, mesh_prescribed_part.Nodes)
|
|
254
|
+
KM.VariableUtils().ApplyFixity(KM.DISPLACEMENT_Y, True, mesh_prescribed_part.Nodes)
|
|
255
|
+
KM.VariableUtils().ApplyFixity(KM.DISPLACEMENT_Z, True, mesh_prescribed_part.Nodes)
|
|
256
|
+
|
|
257
|
+
structural_analysis.Initialize()
|
|
258
|
+
structural_analysis.RunSolutionLoop()
|
|
259
|
+
structural_analysis.Finalize()
|
|
260
|
+
|
|
261
|
+
# nearest element mapping from structural model to destination
|
|
262
|
+
mesh_utilities.RevertMeshUpdateAccordingInputVariable(KM.DISPLACEMENT)
|
|
263
|
+
mesh_utilities.SetReferenceMeshToMesh()
|
|
264
|
+
|
|
265
|
+
ne_mapper_settings = KM.Parameters("""{
|
|
266
|
+
"mapper_type": "nearest_element",
|
|
267
|
+
"echo_level" : 0
|
|
268
|
+
}""")
|
|
269
|
+
main_mapper = SpacialMapperFactory.CreateMapper(
|
|
270
|
+
structural_model.GetModelPart("main"), self.destination_model_part,
|
|
271
|
+
ne_mapper_settings)
|
|
272
|
+
main_mapper.Map(KM.DISPLACEMENT, input_variable)
|
|
273
|
+
|
|
274
|
+
def _CreateStructuralModel(self, structural_model):
|
|
275
|
+
|
|
276
|
+
main_part = structural_model.CreateModelPart("main")
|
|
277
|
+
prescribed_part = main_part.CreateSubModelPart("prescribed_bc")
|
|
278
|
+
fixed_part = main_part.CreateSubModelPart("fixed_bc")
|
|
279
|
+
|
|
280
|
+
# add solution variables necessary for structural mechanics analysis
|
|
281
|
+
main_part.AddNodalSolutionStepVariable(KSO.SHAPE_UPDATE)
|
|
282
|
+
main_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT)
|
|
283
|
+
main_part.AddNodalSolutionStepVariable(KM.ROTATION)
|
|
284
|
+
main_part.AddNodalSolutionStepVariable(KM.REACTION)
|
|
285
|
+
main_part.AddNodalSolutionStepVariable(KM.POSITIVE_FACE_PRESSURE)
|
|
286
|
+
main_part.AddNodalSolutionStepVariable(KM.NEGATIVE_FACE_PRESSURE)
|
|
287
|
+
main_part.AddNodalSolutionStepVariable(KSM.POINT_LOAD)
|
|
288
|
+
main_part.AddNodalSolutionStepVariable(KSM.LINE_LOAD)
|
|
289
|
+
main_part.AddNodalSolutionStepVariable(KSM.SURFACE_LOAD)
|
|
290
|
+
main_part.AddNodalSolutionStepVariable(KM.VOLUME_ACCELERATION)
|
|
291
|
+
main_part.AddNodalSolutionStepVariable(KM.ROTATION)
|
|
292
|
+
main_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT)
|
|
293
|
+
main_part.AddNodalSolutionStepVariable(KSM.POINT_MOMENT)
|
|
294
|
+
main_part.AddNodalSolutionStepVariable(KSO.NORMALIZED_SURFACE_NORMAL)
|
|
295
|
+
|
|
296
|
+
material_properties = main_part.GetProperties()[0]
|
|
297
|
+
self._ApplyMaterialProperties(material_properties)
|
|
298
|
+
|
|
299
|
+
# create nodes of prescribed bc
|
|
300
|
+
prescribed_nodes_added = set()
|
|
301
|
+
for node in self.sliding_mesh.Nodes:
|
|
302
|
+
prescribed_part.CreateNewNode(node.Id, node.X, node.Y, node.Z)
|
|
303
|
+
prescribed_nodes_added.add(node.Id)
|
|
304
|
+
|
|
305
|
+
# Identify mesh motion area / nodes to be damped
|
|
306
|
+
KM.VariableUtils().SetFlag(KM.STRUCTURE, False, main_part.Nodes)
|
|
307
|
+
radius = self.settings["filter_radius"].GetDouble()
|
|
308
|
+
search_based_functions = KSO.SearchBasedFunctions(self.destination_model_part)
|
|
309
|
+
search_based_functions.FlagNodesInRadius(prescribed_part.Nodes, KM.STRUCTURE, 2*radius)
|
|
310
|
+
|
|
311
|
+
# create nodes for main_part
|
|
312
|
+
main_nodes_added = set()
|
|
313
|
+
for node in self.destination_model_part.Nodes:
|
|
314
|
+
if node.Is(KM.STRUCTURE):
|
|
315
|
+
main_part.CreateNewNode(node.Id, node.X, node.Y, node.Z)
|
|
316
|
+
main_nodes_added.add(node.Id)
|
|
317
|
+
|
|
318
|
+
# create elements for main_part
|
|
319
|
+
ele_id = 0
|
|
320
|
+
node_ids_to_remove = []
|
|
321
|
+
fixed_node_ids = []
|
|
322
|
+
for surface_condition in self.destination_model_part.Conditions:
|
|
323
|
+
node_counter = 0
|
|
324
|
+
number_of_nodes = len(surface_condition.GetNodes())
|
|
325
|
+
ele_node_ids = []
|
|
326
|
+
for node in surface_condition.GetNodes():
|
|
327
|
+
if node.Id in main_nodes_added:
|
|
328
|
+
ele_node_ids.append(node.Id)
|
|
329
|
+
node_counter += 1
|
|
330
|
+
if node_counter == number_of_nodes:
|
|
331
|
+
ele_id += 1
|
|
332
|
+
condition_dim = surface_condition.GetGeometry().LocalSpaceDimension()
|
|
333
|
+
if condition_dim != 2:
|
|
334
|
+
raise Exception("SlidingVertexMorphingMapper: Design model part can only be a surface!")
|
|
335
|
+
if number_of_nodes == 3:
|
|
336
|
+
main_part.CreateNewElement("ShellThinElement3D3N", ele_id, ele_node_ids, material_properties)
|
|
337
|
+
elif number_of_nodes == 4:
|
|
338
|
+
main_part.CreateNewElement("ShellThinElement3D4N", ele_id, ele_node_ids, material_properties)
|
|
339
|
+
elif number_of_nodes == 6:
|
|
340
|
+
edge_nodes = ele_node_ids[:3]
|
|
341
|
+
node_ids_to_remove.extend(ele_node_ids[3:])
|
|
342
|
+
main_part.CreateNewElement("ShellThinElement3D3N", ele_id, edge_nodes, material_properties)
|
|
343
|
+
elif number_of_nodes == 8 or number_of_nodes == 9:
|
|
344
|
+
edge_nodes = ele_node_ids[:4]
|
|
345
|
+
node_ids_to_remove.extend(ele_node_ids[4:])
|
|
346
|
+
main_part.CreateNewElement("ShellThinElement3D4N", ele_id, edge_nodes, material_properties)
|
|
347
|
+
else:
|
|
348
|
+
fixed_node_ids.extend(ele_node_ids)
|
|
349
|
+
|
|
350
|
+
# remove nodes if higher order surface conditions have been used
|
|
351
|
+
node_ids_to_remove = list(set(node_ids_to_remove))
|
|
352
|
+
nodes_to_remove = main_part.CreateSubModelPart("nodes_to_remove")
|
|
353
|
+
nodes_to_remove.AddNodes(node_ids_to_remove)
|
|
354
|
+
|
|
355
|
+
KM.VariableUtils().SetFlag(KM.TO_ERASE, True, nodes_to_remove.Nodes)
|
|
356
|
+
main_part.RemoveNodes(KM.TO_ERASE)
|
|
357
|
+
|
|
358
|
+
# add dofs
|
|
359
|
+
KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, main_part)
|
|
360
|
+
KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, main_part)
|
|
361
|
+
KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, main_part)
|
|
362
|
+
|
|
363
|
+
# add fixed nodes to fixed_part
|
|
364
|
+
fixed_node_ids = list(set(fixed_node_ids) - set(node_ids_to_remove))
|
|
365
|
+
fixed_part.AddNodes(fixed_node_ids)
|
|
366
|
+
|
|
367
|
+
def _ApplyMaterialProperties(self, material_properties):
|
|
368
|
+
# define properties
|
|
369
|
+
# artificially high bending stiffness via large thickness
|
|
370
|
+
radius = self.settings["filter_radius"].GetDouble()
|
|
371
|
+
material_properties.SetValue(KM.YOUNG_MODULUS,1.0E+8)
|
|
372
|
+
material_properties.SetValue(KM.POISSON_RATIO,0.0)
|
|
373
|
+
material_properties.SetValue(KM.THICKNESS,2*radius)
|
|
374
|
+
material_properties.SetValue(KM.DENSITY,0.0)
|
|
375
|
+
|
|
376
|
+
constitutive_law = KSM.LinearElasticPlaneStress2DLaw()
|
|
377
|
+
|
|
378
|
+
material_properties.SetValue(KM.CONSTITUTIVE_LAW,constitutive_law)
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
#
|
|
9
|
+
# ==============================================================================
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# ==============================================================================
|
|
13
|
+
class MeshController:
|
|
14
|
+
# --------------------------------------------------------------------------
|
|
15
|
+
def Initialize(self):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
# --------------------------------------------------------------------------
|
|
19
|
+
def UpdateMeshAccordingInputVariable(self, variable):
|
|
20
|
+
raise NotImplementedError("Mesh controller base class is called. Please check your implementation of the function >> UpdateMeshAccordingInputVariable << .")
|
|
21
|
+
|
|
22
|
+
# ==============================================================================
|
KratosMultiphysics/ShapeOptimizationApplication/mesh_controllers/mesh_controller_basic_updating.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# KratosShapeOptimizationApplication
|
|
3
|
+
#
|
|
4
|
+
# License: BSD License
|
|
5
|
+
# license: ShapeOptimizationApplication/license.txt
|
|
6
|
+
#
|
|
7
|
+
# Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
|
|
8
|
+
#
|
|
9
|
+
# ==============================================================================
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# importing the Kratos Library
|
|
13
|
+
import KratosMultiphysics as KM
|
|
14
|
+
import KratosMultiphysics.ShapeOptimizationApplication as KSO
|
|
15
|
+
|
|
16
|
+
# Additional imports
|
|
17
|
+
import time as timer
|
|
18
|
+
from .mesh_controller_base import MeshController
|
|
19
|
+
|
|
20
|
+
# ==============================================================================
|
|
21
|
+
class MeshControllerBasicUpdating(MeshController):
|
|
22
|
+
# --------------------------------------------------------------------------
|
|
23
|
+
def __init__(self, OptimizationModelPart):
|
|
24
|
+
self.OptimizationModelPart = OptimizationModelPart
|
|
25
|
+
|
|
26
|
+
# --------------------------------------------------------------------------
|
|
27
|
+
def UpdateMeshAccordingInputVariable(self, variable):
|
|
28
|
+
KM.Logger.Print("")
|
|
29
|
+
KM.Logger.PrintInfo("ShapeOpt", "Starting to update the mesh")
|
|
30
|
+
startTime = timer.time()
|
|
31
|
+
KSO.MeshControllerUtilities(self.OptimizationModelPart).UpdateMeshAccordingInputVariable(variable)
|
|
32
|
+
KSO.MeshControllerUtilities(self.OptimizationModelPart).LogMeshChangeAccordingInputVariable(variable)
|
|
33
|
+
KM.Logger.PrintInfo("ShapeOpt", "Time needed for updating the mesh = ",round(timer.time() - startTime,2),"s")
|
|
34
|
+
|
|
35
|
+
# ==============================================================================
|