Source code for openmdao.test_suite.components.ae_tests

"""
Some classes that are used to test Analysis Errors on multiple processes.
"""

import openmdao.api as om
from openmdao.core.driver import Driver


[docs]class AEComp(om.ExplicitComponent):
[docs] def setup(self): self.add_input('x', val=0.0) self.add_output('y', val=0.0)
[docs] def compute(self, inputs, outputs): """ This will error if x is more than 2. """ x = inputs['x'] if x > 2.0: raise om.AnalysisError('Try again.') outputs['y'] = x*x + 2.0
[docs]class AEDriver(Driver): """ Handle an Analysis Error from below. """
[docs] def run(self): """ Just handle it and return an error state. """ try: self._run_solve_nonlinear() except om.AnalysisError: return True return False