Example #1
0
    def setup(self):
        """ Setup inputs and outputs"""
        declared = []
        spec = mif.get_specs_for_module(self.module_name)

        #Inputs
        for entry in spec.cpacs_inout.inputs:
            if entry.var_name in declared:
                log.info('Already declared')
            elif entry.var_name in optim_var_dict:
                var = optim_var_dict[entry.var_name]
                if entry.var_name in optim_var_dict:
                    self.add_input(entry.var_name, val=var[1][0])
                    declared.append(entry.var_name)

        if declared == []:
            self.add_input(self.module_name + '_in')
        declared = []

        # Outputs
        # To remove
        #is_skf = (self.module_name == 'SkinFriction')

        for entry in spec.cpacs_inout.outputs:
            # Replace special characters from the name of the entry and checks for accronyms
            entry.var_name = tls.change_var_name(entry.var_name)

            if entry.var_name in declared:
                log.info('Already declared')
            elif entry.var_name in optim_var_dict:
                var = optim_var_dict[entry.var_name]
                self.add_output(entry.var_name, val=var[1][0])
                declared.append(entry.var_name)
            elif 'aeromap' in entry.var_name and self.module_name == last_am_module:  #== 'PyTornado':  #not skf^is_skf:
                # Condition to avoid any conflict with skinfriction
                for name in apmf.XSTATES:
                    if name in optim_var_dict:
                        var = optim_var_dict[name]
                        self.add_input(name, val=var[1][0])
                        declared.append(entry.var_name)
                for name in apmf.COEF_LIST:
                    if name in optim_var_dict:
                        var = optim_var_dict[name]
                        if tls.is_digit(var[1][0]):
                            self.add_output(name, val=var[1][0])
                        else:
                            self.add_output(name)
                        declared.append(entry.var_name)

        if declared == []:
            self.add_output(self.module_name + '_out')
Example #2
0
def get_normal_param(tixi, entry, outputs):
    """Add a variable to the optimisation dictionnary.

    It is checked if the variable has a user-specified initial value, else it
    will assign a default value or the variable will be excluded from the
    problem.

    Args:
        tixi (Tixi3 handle): Handle of the current CPACS file.
        entry (object): Current parameter object.

    Returns:
        None.

    """

    value = '-'
    xpath = entry.xpath
    def_val = entry.default_value

    if not def_val:
        if entry.var_type in [float, int]:
            def_val = 0.0
        else:
            def_val = '-'

    if entry.var_name not in banned_entries:
        value = cpsf.get_value_or_default(tixi, xpath, def_val)
        if entry.var_type == int:
            value = int(value)

    if not tls.is_digit(value):
        log.info('Not a digital value')
        value = '-'
    elif entry.var_type == bool:
        log.info('Boolean, not implemented yet')
        value = '-'

    # Ignores values that are not int or float
    if value != '-':
        value = str(value)
        tixi.updateTextElement(xpath, value)

        var['init'].append(value)
        var['xpath'].append(xpath)
        var['Name'].append(entry.var_name)

        tls.add_type(entry, outputs, objective, var)
        tls.add_bounds(value, var)
        log.info('Value : {}'.format(value))
        log.info('Added to variable file')
Example #3
0
    def setup(self):
        """Setup inputs and outputs"""
        declared = []
        spec = mif.get_specs_for_module(self.module_name)

        # Inputs
        for entry in spec.cpacs_inout.inputs:
            if entry.var_name in declared:
                log.info("Already declared")
            elif entry.var_name in Rt.optim_var_dict:
                var = Rt.optim_var_dict[entry.var_name]
                if entry.var_name in Rt.optim_var_dict:
                    self.add_input(entry.var_name, val=var[1][0])
                    declared.append(entry.var_name)

        if declared == []:
            self.add_input(self.module_name + "_in")
        declared = []

        for entry in spec.cpacs_inout.outputs:
            # Replace special characters from the name of the entry and checks for accronyms
            entry.var_name = change_var_name(entry.var_name)

            if entry.var_name in declared:
                log.info("Already declared")
            elif entry.var_name in Rt.optim_var_dict:
                var = Rt.optim_var_dict[entry.var_name]
                self.add_output(entry.var_name, val=var[1][0])
                declared.append(entry.var_name)
            elif (
                "aeromap" in entry.var_name and self.module_name == Rt.last_am_module
            ):  # == 'PyTornado':  #not skf^is_skf:
                # Condition to avoid any conflict with skinfriction
                for name in PARAMS:
                    if name in Rt.optim_var_dict:
                        var = Rt.optim_var_dict[name]
                        self.add_input(name, val=var[1][0])
                        declared.append(entry.var_name)
                for name in COEFS:
                    if name in Rt.optim_var_dict:
                        var = Rt.optim_var_dict[name]
                        if is_digit(var[1][0]):
                            self.add_output(name, val=var[1][0])
                        else:
                            self.add_output(name)
                        declared.append(entry.var_name)

        if declared == []:
            self.add_output(self.module_name + "_out")
Example #4
0
def add_parameters(prob, ivc):
    """Add problem parameters.

    In this function all the problem parameters, namely the constraints,
    design variables and objective functions, are added to the problem model,
    with their respective boundaries if they are given.

    Args:
        prob (om.Problem object): Current problem that is being defined
        ivc (om.IndepVarComp object): Independent variables of the problem

    """

    # Defining constraints and linking design variables to the ivc
    for name, (
        val_type,
        listval,
        minval,
        maxval,
        getcommand,
        setcommand,
    ) in Rt.optim_var_dict.items():
        if val_type == "des" and listval[-1] not in ["True", "False", "-"]:
            if is_digit(minval) and is_digit(maxval):
                prob.model.add_design_var(name, lower=float(minval), upper=float(maxval))
            elif is_digit(minval):
                prob.model.add_design_var(name, lower=float(minval))
            elif is_digit(maxval):
                prob.model.add_design_var(name, upper=float(maxval))
            else:
                prob.model.add_design_var(name)
            ivc.add_output(name, val=listval[-1])
        elif val_type == "const":
            if is_digit(minval) and is_digit(maxval):
                prob.model.add_constraint(name, lower=float(minval), upper=float(maxval))
            elif is_digit(minval):
                prob.model.add_constraint(name, lower=float(minval))
            elif is_digit(maxval):
                prob.model.add_constraint(name, upper=float(maxval))
            else:
                prob.model.add_constraint(name)

    # Adding the objective functions, multiple objectives TBD in SciPyOpt
    # for o in Rt.objective:
    #     prob.model.add_objective('Objective function '+o)
    prob.model.add_objective("Objective function " + Rt.objective[0])
Example #5
0
def get_normal_param(tixi, entry, outputs):
    """Add a variable to the optimisation dictionnary.

    It is checked if the variable has a user-specified initial value, else it
    will assign a default value or the variable will be excluded from the
    problem.

    Args:
        tixi (Tixi3 handle): Handle of the current CPACS file.
        entry (object): Current parameter object.

    """

    value = "-"
    xpath = entry.xpath
    def_val = entry.default_value

    if not def_val:
        if entry.var_type in [float, int]:
            def_val = 0.0
        else:
            def_val = "-"

    if entry.var_name not in BANNED_ENTRIES:
        value = get_value_or_default(tixi, xpath, def_val)
        if entry.var_type == int:
            value = int(value)

    if not is_digit(value):
        log.info("Not a digital value")
        value = "-"
    elif entry.var_type == bool:
        log.info("Boolean, not implemented yet")
        value = "-"

    # Ignores values that are not int or float
    if value != "-":
        value = str(value)
        tixi.updateTextElement(xpath, value)

        var["init"].append(value)
        var["xpath"].append(xpath)
        var["Name"].append(entry.var_name)

        add_type(entry, outputs, objective, var)
        add_bounds(value, var)
        log.info("Value : {}".format(value))
        log.info("Added to variable file")
Example #6
0
    def setup(self):
        """ Setup inputs and outputs"""
        spec = mif.get_specs_for_module(self.module_name)

        #Inputs
        for entry in spec.cpacs_inout.inputs:
            if entry.var_name in optim_var_dict:
                var = optim_var_dict[entry.var_name]
                if var[0] == 'des':
                    self.add_input(entry.var_name, val=var[1][0])
                elif var[0] in ['const', 'obj']:
                    self.add_output(entry.var_name, val=var[1][0])

        # Outputs
        for entry in spec.cpacs_inout.outputs:
            if entry.var_name in optim_var_dict:
                var = optim_var_dict[entry.var_name]
                self.add_output(entry.var_name, val=var[1][0])
            elif 'aeromap' in entry.var_name:
                for name in [
                        'altitude', 'machNumber', 'angleOfAttack',
                        'angleOfSideslip'
                ]:
                    if name in optim_var_dict:
                        var = optim_var_dict[name]
                        self.add_input(name, val=var[1][0])
                for name in ['cl', 'cd', 'cs', 'cml', 'cmd', 'cms']:
                    if name in optim_var_dict:
                        var = optim_var_dict[name]
                        if tls.is_digit(var[1][0]):
                            self.add_output(name, val=var[1][0])
                        else:
                            self.add_output(name)
            # Add output by default as it may be an input for the next module
            else:
                self.add_output(entry.var_name)