Source code for openmdao.test_suite.components.expl_comp_simple

"""Define the explicit test component (simple)."""
import scipy.sparse

from openmdao.core.explicitcomponent import ExplicitComponent

[docs]class TestExplCompSimple(ExplicitComponent):
[docs] def setup(self): self.add_input('length', val=1., desc='length of rectangle') self.add_input('width', val=1., desc='width of rectangle') self.add_output('area', val=1., desc='area of rectangle')
[docs] def setup_partials(self): self.declare_partials('*', '*')
[docs] def compute(self, inputs, outputs): outputs['area'] = inputs['length'] * inputs['width']
[docs]class TestExplCompSimpleDense(TestExplCompSimple):
[docs] def compute_partials(self, inputs, partials): partials['area', 'length'] = inputs['width'] partials['area', 'width'] = inputs['length']
[docs]class TestExplCompSimpleSpmtx(TestExplCompSimple):
[docs] def compute_partials(self, inputs, partials): partials['area', 'length'] = scipy.sparse.csr_matrix( (inputs['width'], (0, 0))) partials['area', 'width'] = scipy.sparse.csr_matrix( (inputs['length'], (0, 0)))
[docs]class TestExplCompSimpleSparse(TestExplCompSimple):
[docs] def compute_partials(self, inputs, partials): partials['area', 'length'] = (inputs['width'], 0, 0) partials['area', 'width'] = (inputs['length'], 0, 0)
[docs]class TestExplCompSimpleJacVec(TestExplCompSimple):
[docs] def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode): length = inputs['length'] width = inputs['width'] d_area = d_outputs['area'] if mode == 'fwd': # TODO: Assignment back into the results vector doesn't work with # intermediate variables (seem commented out line). if 'width' in d_inputs: #d_area += d_inputs['width']*length d_outputs['area'] += d_inputs['width']*length if 'length' in d_inputs: #d_area += d_inputs['length']*width d_outputs['area'] += d_inputs['length']*width else: if 'width' in d_inputs: d_inputs['width'] += d_area*length if 'length' in d_inputs: d_inputs['length'] += d_area*width