def InitializeOptimizationLoop(self): self.model_part_controller.Initialize() self.analyzer.InitializeBeforeOptimizationLoop() self.design_surface = self.model_part_controller.GetDesignSurface() self.mapper = mapper_factory.CreateMapper(self.design_surface, self.design_surface, self.mapper_settings) self.mapper.Initialize() self.data_logger = data_logger_factory.CreateDataLogger( self.model_part_controller, self.communicator, self.optimization_settings) self.data_logger.InitializeDataLogging() self.optimization_utilities = KSO.OptimizationUtilities( self.design_surface, self.optimization_settings)
def InitializeOptimizationLoop(self): self.model_part_controller.Initialize() self.model_part_controller.SetMinimalBufferSize(2) self.analyzer.InitializeBeforeOptimizationLoop() self.design_surface = self.model_part_controller.GetDesignSurface() self.mapper = mapper_factory.CreateMapper(self.design_surface, self.design_surface, self.mapper_settings) self.mapper.Initialize() if self.filter_penalty_term: penalty_filter_radius = self.algorithm_settings[ "penalty_filter_radius"].GetDouble() filter_radius = self.mapper_settings["filter_radius"].GetDouble() if abs(filter_radius - penalty_filter_radius) > 1e-9: penalty_filter_settings = self.mapper_settings.Clone() penalty_filter_settings["filter_radius"].SetDouble( self.algorithm_settings["penalty_filter_radius"].GetDouble( )) self.penalty_filter = mapper_factory.CreateMapper( self.design_surface, self.design_surface, penalty_filter_settings) self.penalty_filter.Initialize() else: self.penalty_filter = self.mapper self.data_logger = data_logger_factory.CreateDataLogger( self.model_part_controller, self.communicator, self.optimization_settings) self.data_logger.InitializeDataLogging() self.optimization_utilities = KSO.OptimizationUtilities( self.design_surface, self.optimization_settings) # Identify fixed design areas KM.VariableUtils().SetFlag(KM.BOUNDARY, False, self.optimization_model_part.Nodes) radius = self.mapper_settings["filter_radius"].GetDouble() search_based_functions = KSO.SearchBasedFunctions(self.design_surface) for itr in range(self.algorithm_settings["fix_boundaries"].size()): sub_model_part_name = self.algorithm_settings["fix_boundaries"][ itr].GetString() node_set = self.optimization_model_part.GetSubModelPart( sub_model_part_name).Nodes search_based_functions.FlagNodesInRadius(node_set, KM.BOUNDARY, radius) # Specify bounds and assign starting values for ALPHA if self.bead_side == "positive": KM.VariableUtils().SetScalarVar(KSO.ALPHA, 0.5, self.design_surface.Nodes, KM.BOUNDARY, False) self.lower_bound = 0.0 self.upper_bound = 1.0 elif self.bead_side == "negative": KM.VariableUtils().SetScalarVar(KSO.ALPHA, -0.5, self.design_surface.Nodes, KM.BOUNDARY, False) self.lower_bound = -1.0 self.upper_bound = 0.0 elif self.bead_side == "both": KM.VariableUtils().SetScalarVar(KSO.ALPHA, 0.0, self.design_surface.Nodes, KM.BOUNDARY, False) self.lower_bound = -1.0 self.upper_bound = 1.0 else: raise RuntimeError("Specified bead direction mode not supported!") # Initialize ALPHA_MAPPED according to initial ALPHA values self.mapper.Map(KSO.ALPHA, KSO.ALPHA_MAPPED) # Specify bead direction bead_direction = self.algorithm_settings["bead_direction"].GetVector() if len(bead_direction) == 0: self.model_part_controller.ComputeUnitSurfaceNormals() for node in self.design_surface.Nodes: normalized_normal = node.GetSolutionStepValue( KSO.NORMALIZED_SURFACE_NORMAL) node.SetValue(KSO.BEAD_DIRECTION, normalized_normal) elif len(bead_direction) == 3: norm = math.sqrt(bead_direction[0]**2 + bead_direction[1]**2 + bead_direction[2]**2) normalized_bead_direction = [ value / norm for value in bead_direction ] KM.VariableUtils().SetNonHistoricalVectorVar( KSO.BEAD_DIRECTION, normalized_bead_direction, self.design_surface.Nodes) else: raise RuntimeError( "Wrong definition of bead direction. Options are: 1) [] -> takes surface normal, 2) [x.x,x.x,x.x] -> takes specified vector." )