def test_simple_integration_forward(self): p = om.Problem(model=om.Group()) phase = dm.Phase(ode_class=TestODE, transcription=dm.RungeKutta(num_segments=200, method='RK4')) p.model.add_subsystem('phase0', subsys=phase) phase.set_time_options(fix_initial=True, fix_duration=True, targets=['t']) phase.add_state('y', fix_initial=True, targets=['y'], rate_source='ydot', units='m') phase.add_timeseries_output('ydot', output_name='state_rate:y', units='m/s') p.setup(check=True, force_alloc_complex=True) p['phase0.t_initial'] = 0.0 p['phase0.t_duration'] = 2.0 p['phase0.states:y'] = 0.5 p.run_model() expected = _test_ode_solution(p['phase0.ode.y'], p['phase0.ode.t']) assert_near_equal(p['phase0.ode.y'], expected, tolerance=1.0E-3)
def test_simple_integration_forward_connected_initial(self): p = Problem(model=Group()) phase = Phase(ode_class=TestODE, transcription=RungeKutta(num_segments=200, method='RK4')) p.model.add_subsystem('phase0', subsys=phase) phase.set_time_options(fix_initial=True, fix_duration=True) phase.set_state_options('y', fix_initial=False, connected_initial=True) phase.add_timeseries_output('ydot', output_name='state_rate:y', units='m/s') p.setup(check=True, force_alloc_complex=True) p['phase0.t_initial'] = 0.0 p['phase0.t_duration'] = 2.0 # The initial guess of states at the segment boundaries p['phase0.states:y'] = 0.0 # The initial value of the states from which the integration proceeds p['phase0.initial_states:y'] = 0.5 p.run_model() expected = _test_ode_solution(p['phase0.ode.y'], p['phase0.ode.t']) assert_rel_error(self, p['phase0.ode.y'], expected, tolerance=1.0E-3)
def test_simple_integration_backward(self): p = Problem(model=Group()) phase = Phase(ode_class=TestODE, transcription=RungeKutta(num_segments=4, method='RK4')) p.model.add_subsystem('phase0', subsys=phase) phase.set_time_options(fix_initial=True, fix_duration=True) phase.set_state_options('y', fix_initial=True) phase.add_timeseries_output('ydot', output_name='state_rate:y', units='m/s') p.setup(check=True, force_alloc_complex=True) p['phase0.t_initial'] = 2.0 p['phase0.t_duration'] = -2.0 p['phase0.states:y'] = 5.305471950534675 p.run_model() expected = np.atleast_2d( _test_ode_solution(p['phase0.ode.y'], p['phase0.ode.t'])).T assert_rel_error(self, p['phase0.timeseries.states:y'], expected, tolerance=1.0E-3)
def test_simple_integration_backward_connected_initial(self): p = om.Problem(model=om.Group()) phase = dm.Phase(ode_class=TestODE, transcription=dm.RungeKutta(num_segments=200, method='RK4')) p.model.add_subsystem('phase0', subsys=phase) phase.set_time_options(fix_initial=True, fix_duration=True, targets=['t']) phase.add_state('y', connected_initial=True, targets=['y'], rate_source='ydot', units='m') phase.add_timeseries_output('ydot', output_name='state_rate:y') p.setup(check=True, force_alloc_complex=True) p['phase0.t_initial'] = 2.0 p['phase0.t_duration'] = -2.0 # The initial guess of state values at the segment boundaries p['phase0.states:y'] = 0 # The initial value of the states from which the integration proceeds p['phase0.initial_states:y'] = 5.305471950534675 p.run_model() expected = np.atleast_2d(_test_ode_solution(p['phase0.ode.y'], p['phase0.timeseries.time'])) assert_near_equal(p['phase0.timeseries.states:y'], expected, tolerance=1.0E-3)