Ejemplo n.º 1
0
    def __init__(self, project_parameters, model_part_controller, external_analyzer):
        self.external_analyzer = external_analyzer

        if self.__IsInternalAnalyzerRequired(project_parameters["optimization_settings"]):
            from analyzer_internal import KratosInternalAnalyzer
            self.internal_analyzer = KratosInternalAnalyzer(project_parameters, model_part_controller.GetOptimizationModelPart())
        else:
            from analyzer_empty import EmptyAnalyzer
            self.internal_analyzer = EmptyAnalyzer()
            if isinstance(external_analyzer, EmptyAnalyzer):
                raise RuntimeError("Neither an internal nor an external analyzer is defined!")
Ejemplo n.º 2
0
    def __init__(self, optimization_settings, model_part_controller, external_analyzer):
        self.model_part_controller = model_part_controller
        self.external_analyzer = external_analyzer

        if self.__IsInternalAnalyzerRequired(optimization_settings):
            from analyzer_internal import KratosInternalAnalyzer
            self.internal_analyzer = KratosInternalAnalyzer(optimization_settings, model_part_controller)
        else:
            from analyzer_empty import EmptyAnalyzer
            self.internal_analyzer = EmptyAnalyzer()
            if isinstance(external_analyzer, EmptyAnalyzer):
                raise RuntimeError("Neither an internal nor an external analyzer is defined!")
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
class Analyzer:
    # --------------------------------------------------------------------------
    def __init__(self, optimization_settings, model_part_controller, external_analyzer):
        self.model_part_controller = model_part_controller
        self.external_analyzer = external_analyzer

        if self.__IsInternalAnalyzerRequired(optimization_settings):
            from analyzer_internal import KratosInternalAnalyzer
            self.internal_analyzer = KratosInternalAnalyzer(optimization_settings, model_part_controller)
        else:
            from analyzer_empty import EmptyAnalyzer
            self.internal_analyzer = EmptyAnalyzer()
            if isinstance(external_analyzer, EmptyAnalyzer):
                raise RuntimeError("Neither an internal nor an external analyzer is defined!")

    # --------------------------------------------------------------------------
    def InitializeBeforeOptimizationLoop(self):
        self.internal_analyzer.InitializeBeforeOptimizationLoop()
        self.external_analyzer.InitializeBeforeOptimizationLoop()

    # --------------------------------------------------------------------------
    def AnalyzeDesignAndReportToCommunicator(self, current_design, unique_iterator, communicator):
        self.internal_analyzer.AnalyzeDesignAndReportToCommunicator(current_design, unique_iterator, communicator)
        self.external_analyzer.AnalyzeDesignAndReportToCommunicator(current_design, unique_iterator, communicator)

        self.__ResetPossibleShapeModificationsFromAnalysis()

    # --------------------------------------------------------------------------
    def FinalizeAfterOptimizationLoop(self):
        self.internal_analyzer.FinalizeAfterOptimizationLoop()
        self.external_analyzer.FinalizeAfterOptimizationLoop()

    # --------------------------------------------------------------------------
    def __IsInternalAnalyzerRequired(self, optimization_settings):
        for objective_number in range(optimization_settings["objectives"].size()):
            if optimization_settings["objectives"][objective_number]["use_kratos"].GetBool():
                return True

        for constraint_number in range(optimization_settings["constraints"].size()):
            if optimization_settings["constraints"][constraint_number]["use_kratos"].GetBool():
                return True
        return False

    # --------------------------------------------------------------------------
    def __ResetPossibleShapeModificationsFromAnalysis( self ):
        self.model_part_controller.SetMeshToReferenceMesh()
        self.model_part_controller.SetDeformationVariablesToZero()
Ejemplo n.º 5
0
class Analyzer:
    # --------------------------------------------------------------------------
    def __init__(self, project_parameters, model_part_controller, external_analyzer):
        self.external_analyzer = external_analyzer

        if self.__IsInternalAnalyzerRequired(project_parameters["optimization_settings"]):
            from analyzer_internal import KratosInternalAnalyzer
            self.internal_analyzer = KratosInternalAnalyzer(project_parameters, model_part_controller.GetOptimizationModelPart())
        else:
            from analyzer_empty import EmptyAnalyzer
            self.internal_analyzer = EmptyAnalyzer()
            if isinstance(external_analyzer, EmptyAnalyzer):
                raise RuntimeError("Neither an internal nor an external analyzer is defined!")

    # --------------------------------------------------------------------------
    def InitializeBeforeOptimizationLoop(self):
        self.external_analyzer.InitializeBeforeOptimizationLoop()
        self.internal_analyzer.InitializeBeforeOptimizationLoop()

    # --------------------------------------------------------------------------
    def AnalyzeDesignAndReportToCommunicator(self, current_design, unique_iterator, communicator):
        self.external_analyzer.AnalyzeDesignAndReportToCommunicator(current_design, unique_iterator, communicator)
        self.internal_analyzer.AnalyzeDesignAndReportToCommunicator(current_design, unique_iterator, communicator)

    # --------------------------------------------------------------------------
    def FinalizeAfterOptimizationLoop(self):
        self.external_analyzer.FinalizeAfterOptimizationLoop()
        self.internal_analyzer.FinalizeAfterOptimizationLoop()

    # --------------------------------------------------------------------------
    def __IsInternalAnalyzerRequired(self, optimization_settings):
        for objective_number in range(optimization_settings["objectives"].size()):
            if optimization_settings["objectives"][objective_number]["use_kratos"].GetBool():
                return True

        for constraint_number in range(optimization_settings["constraints"].size()):
            if optimization_settings["constraints"][constraint_number]["use_kratos"].GetBool():
                return True
        return False
Ejemplo n.º 6
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)