Example #1
0
def CreateOptimizer(optimization_settings,
                    model,
                    external_analyzer=EmptyAnalyzer()):

    _ValidateSettings(optimization_settings)

    model_part_controller = model_part_controller_factory.CreateController(
        optimization_settings["model_settings"], model)

    analyzer = analyzer_factory.CreateAnalyzer(optimization_settings,
                                               model_part_controller,
                                               external_analyzer)

    communicator = communicator_factory.CreateCommunicator(
        optimization_settings)

    if optimization_settings["design_variables"]["type"].GetString(
    ) == "vertex_morphing":
        return VertexMorphingMethod(optimization_settings,
                                    model_part_controller, analyzer,
                                    communicator)
    else:
        raise NameError(
            "The following type of design variables is not supported by the optimizer: "
            + variable_type)
Example #2
0
def CreateAlgorithm(OptimizationModelPart, Analyzer, OptimizationSettings):
    AlgorithmName = OptimizationSettings["optimization_algorithm"][
        "name"].GetString()

    DesignSurface = GetDesignSurfaceFromOptimizationModelPart(
        OptimizationModelPart, OptimizationSettings)
    DampingRegions = GetDampingRegionsFromOptimizationModelPart(
        OptimizationModelPart, OptimizationSettings)

    Mapper = mapper_factory.CreateMapper(DesignSurface, OptimizationSettings)
    Communicator = communicator_factory.CreateCommunicator(
        OptimizationSettings)
    DataLogger = optimization_data_logger_factory.CreateDataLogger(
        OptimizationModelPart, DesignSurface, Communicator,
        OptimizationSettings)

    if AlgorithmName == "steepest_descent":
        return AlgorithmSteepestDescent(DesignSurface, DampingRegions,
                                        Analyzer, Mapper, Communicator,
                                        DataLogger, OptimizationSettings)
    elif AlgorithmName == "penalized_projection":
        return AlgorithmPenalizedProjection(DesignSurface, DampingRegions,
                                            Analyzer, Mapper, Communicator,
                                            DataLogger, OptimizationSettings)
    else:
        raise NameError(
            "The following optimization algorithm not supported by the algorithm driver (name may be misspelled): "
            + AlgorithmName)
Example #3
0
def CreateOptimizer(optimization_settings,
                    model,
                    external_analyzer=EmptyAnalyzer()):

    default_settings = Parameters("""
    {
        "model_settings" : { },
        "objectives" : [ ],
        "constraints" : [ ],
        "design_variables" : { },
        "optimization_algorithm" : { },
        "output" : { }
    }""")

    for key in default_settings.keys():
        if not optimization_settings.Has(key):
            raise RuntimeError(
                "CreateOptimizer: Required setting '{}' missing in 'optimization_settings'!"
                .format(key))

    optimization_settings.ValidateAndAssignDefaults(default_settings)

    model_part_controller = model_part_controller_factory.CreateController(
        optimization_settings["model_settings"], model)

    analyzer = analyzer_factory.CreateAnalyzer(optimization_settings,
                                               model_part_controller,
                                               external_analyzer)

    communicator = communicator_factory.CreateCommunicator(
        optimization_settings)

    if optimization_settings["design_variables"]["type"].GetString(
    ) == "vertex_morphing":
        return VertexMorphingMethod(optimization_settings,
                                    model_part_controller, analyzer,
                                    communicator)
    else:
        raise NameError(
            "The following type of design variables is not supported by the optimizer: "
            + variable_type)
Example #4
0
    def optimize( self ):
        
        timer = timer_factory.CreateTimer()
        algorithmName = self.optimizationSettings["optimization_algorithm"]["name"].GetString()

        print("\n> ==============================================================================================================")
        print("> ",timer.getTimeStamp(),": Starting optimization using the following algorithm: ", algorithmName)
        print("> ==============================================================================================================\n")
    
        designSurface = self.__getDesignSurfaceFromInputModelPart()
        dampingRegions = self.__getdampingRegionsFromInputModelPart()

        mapper = mapper_factory.CreateMapper( designSurface, self.optimizationSettings ) 
        communicator = communicator_factory.CreateCommunicator( self.optimizationSettings )

        algorithm = algorithm_factory.CreateAlgorithm( designSurface, dampingRegions, self.analyzer, mapper, communicator, self.optimizationSettings )
        algorithm.execute()       

        print("\n> ==============================================================================================================")
        print("> Finished optimization                                                                                           ")
        print("> ==============================================================================================================\n")