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)
[docs] def setup(self): self.add_input('x') self.add_output('y') self.declare_partials('y', 'x', method='fd')
[docs] def compute(self, inputs, outputs): func = self.options['func'] outputs['y'] = func(inputs['x'])