def Initialize(self):
        if self.has_automatic_boundary_process:
            KSO.GeometryUtilities(
                self.OptimizationModelPart).ExtractBoundaryNodes(
                    "auto_surface_nodes")

        self._mesh_moving_analysis.Initialize()
    def Initialize(self):
        self.vm_mapper.Initialize()

        in_plane_settings = self.settings["in_plane_morphing_settings"]

        background_main_mesh = self._background_model.GetModelPart("background_mesh")
        if in_plane_settings["model_import_settings"]["input_type"].GetString() == "mdpa":
            model_part_io = KM.ModelPartIO(in_plane_settings["model_import_settings"]["input_filename"].GetString())
            model_part_io.ReadModelPart(background_main_mesh)
        elif in_plane_settings["model_import_settings"]["input_type"].GetString() in ["vrml", "wrl"]:
            model_part_io = WrlIO(in_plane_settings["model_import_settings"]["input_filename"].GetString())
            model_part_io.ReadModelPart(background_main_mesh)

        background_sub_model_part_name = in_plane_settings["background_sub_model_part_name"].GetString()
        if background_sub_model_part_name == "":
            self.background_mesh = background_main_mesh
        else:
            self.background_mesh = background_main_mesh.GetSubModelPart(background_sub_model_part_name)

        background_geometry_utilities = KSO.GeometryUtilities(self.background_mesh)
        background_geometry_utilities.ComputeUnitSurfaceNormals()
        self.spacial_mapper = SpacialMapperFactory.CreateMapper(
            self.background_mesh, self.destination_model_part, in_plane_settings["spacial_mapper_settings"])

        KSO.MeshControllerUtilities(self.background_mesh).WriteCoordinatesToVariable(KSO.BACKGROUND_COORDINATE)
예제 #3
0
    def _CalculateDistances(self):
        geometry_tools = KSO.GeometryUtilities(self.model_part)

        self.signed_distances = []
        self.directions = []

        geometry_tools.ComputeDistancesToBoundingModelPart(
            self.packaging_model_part, self.signed_distances, self.directions)
    def Map(self, origin_variable, destination_variable):
        self.vm_mapper.Map(origin_variable, destination_variable)

        geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
        geometry_utilities.ProjectNodalVariableOnTangentPlane(
            destination_variable, KSO.BACKGROUND_NORMAL)

        self._CorrectOutOfPlanePart(destination_variable)
예제 #5
0
    def UpdateMeshAccordingInputVariable(self, variable):
        KM.Logger.Print("")
        KM.Logger.PrintInfo("ShapeOpt", "Starting to update the mesh...")
        startTime = timer.time()

        time_before_update = self.OptimizationModelPart.ProcessInfo.GetValue(
            KM.TIME)
        step_before_update = self.OptimizationModelPart.ProcessInfo.GetValue(
            KM.STEP)
        delta_time_before_update = self.OptimizationModelPart.ProcessInfo.GetValue(
            KM.DELTA_TIME)

        # Reset step/time iterators such that they match the current iteration after calling RunSolutionLoop (which internally calls CloneTimeStep)
        self.OptimizationModelPart.ProcessInfo.SetValue(
            KM.STEP, step_before_update - 1)
        self.OptimizationModelPart.ProcessInfo.SetValue(
            KM.TIME, time_before_update - 1)
        self.OptimizationModelPart.ProcessInfo.SetValue(KM.DELTA_TIME, 0)

        KM.VariableUtils().CopyVectorVar(variable, KM.MESH_DISPLACEMENT,
                                         self.OptimizationModelPart.Nodes)

        if self.has_automatic_boundary_process and self.is_remeshing_used:
            self.OptimizationModelPart.GetSubModelPart(
                "auto_surface_nodes").GetNodes().clear()
            KSO.GeometryUtilities(
                self.OptimizationModelPart).ExtractBoundaryNodes(
                    "auto_surface_nodes")

        if not self._mesh_moving_analysis.time < self._mesh_moving_analysis.end_time:
            self._mesh_moving_analysis.end_time += 1
        self._mesh_moving_analysis.RunSolutionLoop()

        if self.is_remeshing_used:
            self.OptimizationModelPart.Set(KM.MODIFIED, False)
            self.remeshing_process.ExecuteInitializeSolutionStep()
            self.remeshing_process.ExecuteFinalizeSolutionStep()

        KSO.MeshControllerUtilities(
            self.OptimizationModelPart).LogMeshChangeAccordingInputVariable(
                KM.MESH_DISPLACEMENT)

        self.OptimizationModelPart.ProcessInfo.SetValue(
            KM.STEP, step_before_update)
        self.OptimizationModelPart.ProcessInfo.SetValue(
            KM.TIME, time_before_update)
        self.OptimizationModelPart.ProcessInfo.SetValue(
            KM.DELTA_TIME, delta_time_before_update)

        KM.Logger.PrintInfo("ShapeOpt", "Time needed for updating the mesh = ",
                            round(timer.time() - startTime, 2), "s")
    def _CorrectOutOfPlanePart(self, destination_variable):
        geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
        mesh_utilities = KSO.MeshControllerUtilities(self.destination_model_part)

        mesh_utilities.UpdateMeshAccordingInputVariable(destination_variable)
        mesh_utilities.SetReferenceMeshToMesh()

        self.spacial_mapper.UpdateInterface()
        self.spacial_mapper.Map(KSO.BACKGROUND_COORDINATE, KSO.BACKGROUND_COORDINATE)
        mesh_utilities.SubtractCoordinatesFromVariable(KSO.BACKGROUND_COORDINATE, KSO.OUT_OF_PLANE_DELTA)
        geometry_utilities.ProjectNodalVariableOnDirection(KSO.OUT_OF_PLANE_DELTA, KSO.BACKGROUND_NORMAL)

        mesh_utilities.RevertMeshUpdateAccordingInputVariable(destination_variable)
        mesh_utilities.SetReferenceMeshToMesh()

        mesh_utilities.AddFirstVariableToSecondVariable(KSO.OUT_OF_PLANE_DELTA, destination_variable)
 def ProjectNodalVariableOnUnitSurfaceNormals(self, variable):
     KSO.GeometryUtilities(
         self.GetDesignSurface()).ProjectNodalVariableOnUnitSurfaceNormals(
             variable)
 def ComputeUnitSurfaceNormals(self):
     KSO.GeometryUtilities(
         self.GetDesignSurface()).ComputeUnitSurfaceNormals()
    def InverseMap(self, destination_variable, origin_variable):
        geometry_utilities = KSO.GeometryUtilities(self.destination_model_part)
        geometry_utilities.ProjectNodalVariableOnTangentPlane(
            destination_variable, KSO.BACKGROUND_NORMAL)

        self.vm_mapper.InverseMap(destination_variable, origin_variable)
 def InitializeSolutionStep(self):
     self.previous_value = self.value
     self.value = None
     self.gradient = {}
     KSO.GeometryUtilities(self.model_part).ComputeUnitSurfaceNormals()
예제 #11
0
 def _ComputePerimeter(self, model_part):
     return KSO.GeometryUtilities(model_part).CalculateLength(
         model_part.Conditions)