Source code for openmdao.test_suite.components.options_feature_function
"""
A component that computes y = func(x), where func
is a function given as an option.
"""
from types import FunctionType
import openmdao.api as om
[docs]class UnitaryFunctionComp(om.ExplicitComponent):
[docs] def initialize(self):
self.options.declare('func', types=FunctionType, recordable=False)
[docs] def setup(self):
self.add_input('x')
self.add_output('y')
[docs] def setup_partials(self):
self.declare_partials('y', 'x', method='fd')
[docs] def compute(self, inputs, outputs):
func = self.options['func']
outputs['y'] = func(inputs['x'])