Example #1
0
    def get_problem(self,
                    read_inputs: bool = False,
                    auto_scaling: bool = False) -> FASTOADProblem:
        """
        Builds the OpenMDAO problem from current configuration.

        :param read_inputs: if True, the created problem will already be fed
                            with variables from the input file
        :param auto_scaling: if True, automatic scaling is performed for design
                             variables and constraints
        :return: the problem instance
        """
        if not self._conf_dict:
            raise RuntimeError("read configuration file first")

        problem = FASTOADProblem(self._build_model())

        problem.input_file_path = self.input_file_path
        problem.output_file_path = self.output_file_path

        driver = self._conf_dict.get(KEY_DRIVER, "")
        if driver:
            problem.driver = _om_eval(driver)

        if self.get_optimization_definition():
            self._add_constraints(problem.model, auto_scaling)
            self._add_objectives(problem.model)

        if read_inputs:
            problem.read_inputs()
            self._add_design_vars(problem.model, auto_scaling)

        return problem
Example #2
0
    def get_problem(self,
                    read_inputs: bool = False,
                    auto_scaling: bool = False) -> FASTOADProblem:
        """
        Builds the OpenMDAO problem from current configuration.

        :param read_inputs: if True, the created problem will already be fed
                            with variables from the input file
        :param auto_scaling: if True, automatic scaling is performed for design
                             variables and constraints
        :return: the problem instance
        """
        if self._serializer.data is None:
            raise RuntimeError("read configuration file first")

        if read_inputs:
            problem_with_no_inputs = self.get_problem(
                auto_scaling=auto_scaling)
            problem_with_no_inputs.setup()
            input_ivc, unused_variables = self._get_problem_inputs(
                problem_with_no_inputs)
        else:
            input_ivc = unused_variables = None

        problem = FASTOADProblem(self._build_model(input_ivc))
        problem.input_file_path = self.input_file_path
        problem.output_file_path = self.output_file_path
        problem.additional_variables = unused_variables

        driver = self._serializer.data.get(KEY_DRIVER, "")
        if driver:
            problem.driver = _om_eval(driver)

        if self.get_optimization_definition():
            self._add_constraints(problem.model, auto_scaling)
            self._add_objectives(problem.model)

        if read_inputs:
            self._add_design_vars(problem.model, auto_scaling)

        if self._configuration_modifier:
            self._configuration_modifier.modify(problem)

        return problem