Ejemplo n.º 1
0
    def __init__(self, exprs, **kwargs):
        super(ExecComp, self).__init__()

        # if complex step is used for derivatives, this is the stepsize
        self.complex_stepsize = 1.e-6

        if isinstance(exprs, string_types):
            exprs = [exprs]

        self._codes = [compile(expr, expr, 'exec') for expr in exprs]

        outs = set()
        allvars = set()

        # find all of the variables and which ones are outputs
        for expr in exprs:
            lhs, _ = expr.split('=', 1)
            outs.update(parse_for_vars(lhs))
            allvars.update(parse_for_vars(expr, kwargs.keys()))

        for var in sorted(allvars):
            # if user supplied an initial value, use it, otherwise set to 0.0
            val = kwargs.get(var, 0.0)

            if var in outs:
                self.add_output(var, val)
            else:
                self.add_param(var, val)
Ejemplo n.º 2
0
    def __init__(self, exprs, **kwargs):
        super(ExecComp, self).__init__()

        # if complex step is used for derivatives, this is the stepsize
        self.complex_stepsize = 1.e-6

        if isinstance(exprs, string_types):
            exprs = [exprs]

        self._codes = [compile(expr, expr, 'exec') for expr in exprs]

        outs = set()
        allvars = set()

        # find all of the variables and which ones are outputs
        for expr in exprs:
            lhs, _ = expr.split('=', 1)
            outs.update(parse_for_vars(lhs))
            allvars.update(parse_for_vars(expr, kwargs.keys()))

        # make sure all kwargs are legit
        for kwarg in kwargs:
            if kwarg not in allvars:
                raise RuntimeError("Keyword arg '%s' in call to ExecComp() "
                                   "does not refer to any variable in the "
                                   "expressions %s" % (kwarg, exprs))

        for var in sorted(allvars):
            # if user supplied an initial value, use it, otherwise set to 0.0
            val = kwargs.get(var, 0.0)

            if var in outs:
                self.add_output(var, val)
            else:
                self.add_param(var, val)
Ejemplo n.º 3
0
    def __init__(self, exprs, **kwargs):
        super(ExecComp, self).__init__()

        # if complex step is used for derivatives, this is the stepsize
        self.complex_stepsize = 1.e-6

        if isinstance(exprs, string_types):
            exprs = [exprs]

        self._codes = [compile(expr, expr, 'exec') for expr in exprs]

        outs = set()
        allvars = set()

        # find all of the variables and which ones are outputs
        for expr in exprs:
            lhs, _ = expr.split('=', 1)
            outs.update(parse_for_vars(lhs))
            allvars.update(parse_for_vars(expr, kwargs.keys()))

        for var in sorted(allvars):
            # if user supplied an initial value, use it, otherwise set to 0.0
            val = kwargs.get(var, 0.0)

            if var in outs:
                self.add_output(var, val)
            else:
                self.add_param(var, val)
Ejemplo n.º 4
0
    def __init__(self, exprs, **kwargs):
        super(ExecComp, self).__init__()

        # if complex step is used for derivatives, this is the stepsize
        self.complex_stepsize = 1.e-6

        if isinstance(exprs, string_types):
            exprs = [exprs]

        self._codes = [compile(expr, expr, 'exec') for expr in exprs]

        outs = set()
        allvars = set()

        # find all of the variables and which ones are outputs
        for expr in exprs:
            lhs, _ = expr.split('=', 1)
            outs.update(parse_for_vars(lhs))
            allvars.update(parse_for_vars(expr, kwargs.keys()))

        # make sure all kwargs are legit
        for kwarg in kwargs:
            if kwarg not in allvars:
                raise RuntimeError("Keyword arg '%s' in call to ExecComp() "
                                   "does not refer to any variable in the "
                                   "expressions %s" % (kwarg, exprs))

        for var in sorted(allvars):
            # if user supplied an initial value, use it, otherwise set to 0.0
            val = kwargs.get(var, 0.0)

            if var in outs:
                self.add_output(var, val)
            else:
                self.add_param(var, val)