Source code for openmdao.test_suite.components.options_feature_lincomb

A component that computes y = a*x + b, where a and b
are given as an option of type 'numpy.ScalarType'.
import numpy as np

import openmdao.api as om

[docs]class LinearCombinationComp(om.ExplicitComponent):
[docs] def initialize(self): self.options.declare('a', default=1., types=np.ScalarType) self.options.declare('b', default=1., types=np.ScalarType)
[docs] def setup(self): self.add_input('x') self.add_output('y')
[docs] def setup_partials(self): self.declare_partials('y', 'x', val=self.options['a'])
[docs] def compute(self, inputs, outputs): outputs['y'] = self.options['a'] * inputs['x'] + self.options['b']