def test_water_rocket_range_for_docs(self):
        p = om.Problem(model=om.Group())

        traj, phases = new_water_rocket_trajectory(objective='range')
        traj = p.model.add_subsystem('traj', traj)

        _, optimizer = set_pyoptsparse_opt('IPOPT', fallback=False)
        p.driver = om.pyOptSparseDriver(optimizer='IPOPT')
        p.driver.opt_settings['print_level'] = 5
        p.driver.opt_settings['max_iter'] = 1000
        p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'
        p.driver.declare_coloring(tol=1.0E-12)

        # Finish Problem Setup
        p.model.linear_solver = om.DirectSolver()
        # p.driver.add_recorder(om.SqliteRecorder('ex_water_rocket.db'))

        p.setup()
        set_sane_initial_guesses(p, phases)

        p.run_driver()

        summary = summarize_results(p)
        for key, entry in summary.items():
            print(f'{key}: {entry.value:6.4f} {entry.unit}')

        exp_out = traj.simulate(times_per_seg=200)

        # NOTE: only the last figure is shown in the generated docs
        plot_propelled_ascent(p, exp_out)
        plot_trajectory(p, exp_out)
        plot_states(p, exp_out)

        plt.show()

        # Check results (tolerance is relative unless value is zero)
        assert_near_equal(summary['Launch angle'].value, 46, 0.02)
        assert_near_equal(summary['Flight angle at end of propulsion'].value,
                          38, 0.02)
        assert_near_equal(summary['Empty mass'].value, 0.189, 1e-2)
        assert_near_equal(summary['Water volume'].value, 1.026, 1e-2)
        assert_near_equal(summary['Maximum range'].value, 85.11, 1e-2)
        assert_near_equal(summary['Maximum height'].value, 23.08, 1e-2)
        assert_near_equal(summary['Maximum velocity'].value, 41.31, 1e-2)
Example #2
0
    def test_water_rocket_range_for_docs(self):
        p = om.Problem(model=om.Group())

        traj, phases = new_water_rocket_trajectory(objective='range')
        traj = p.model.add_subsystem('traj', traj)

        p.driver = om.ScipyOptimizeDriver()
        p.driver.options['optimizer'] = 'SLSQP'
        p.driver.options['maxiter'] = 1000
        p.driver.options['tol'] = 5e-5
        p.driver.declare_coloring()

        # Finish Problem Setup
        p.model.linear_solver = om.DirectSolver()
        # p.driver.add_recorder(om.SqliteRecorder('ex_water_rocket.db'))

        p.setup()
        set_sane_initial_guesses(p, phases)

        p.run_driver()

        summary = summarize_results(p)
        for key, entry in summary.items():
            print(f'{key}: {entry.value:6.4f} {entry.unit}')

        exp_out = traj.simulate(times_per_seg=200)

        # NOTE: only the last figure is shown in the generated docs
        plot_propelled_ascent(p, exp_out)
        plot_trajectory(p, exp_out)
        plot_states(p, exp_out)

        plt.show()

        # Check results (tolerance is relative unless value is zero)
        assert_near_equal(summary['Launch angle'].value, 38.340175, 1e-3)
        assert_near_equal(summary['Flight angle at end of propulsion'].value,
                          45.029174, 1e-3)
        assert_near_equal(summary['Empty mass'].value, 0.186135, 1e-3)
        assert_near_equal(summary['Water volume'].value, 0.904498, 1e-3)
        assert_near_equal(summary['Maximum range'].value, 86.412652, 1e-3)
        assert_near_equal(summary['Maximum height'].value, 23.51093, 1e-3)
        assert_near_equal(summary['Maximum velocity'].value, 42.413171, 1e-3)
    def test_water_rocket_height_for_docs(self):
        p = om.Problem(model=om.Group())

        traj, phases = new_water_rocket_trajectory(objective='height')
        traj = p.model.add_subsystem('traj', traj)

        _, optimizer = set_pyoptsparse_opt('IPOPT', fallback=False)
        p.driver = om.pyOptSparseDriver(optimizer='IPOPT')
        p.driver.opt_settings['print_level'] = 5
        p.driver.opt_settings['max_iter'] = 1000
        p.driver.declare_coloring()

        # Finish Problem Setup
        p.model.linear_solver = om.DirectSolver()

        p.setup()
        set_sane_initial_guesses(p, phases)

        p.run_driver()

        summary = summarize_results(p)
        for key, entry in summary.items():
            print(f'{key}: {entry.value:6.4f} {entry.unit}')

        exp_out = traj.simulate(times_per_seg=200)

        # NOTE: only the last figure is shown in the generated docs
        plot_propelled_ascent(p, exp_out)
        plot_trajectory(p, exp_out)
        plot_states(p, exp_out)

        plt.show()

        # Check results (tolerance is relative unless value is zero)
        assert_near_equal(summary['Launch angle'].value, 85, .02)
        assert_near_equal(summary['Flight angle at end of propulsion'].value,
                          85, .02)
        assert_near_equal(summary['Empty mass'].value, 0.1425114, 1e-3)
        assert_near_equal(summary['Water volume'].value, 0.868281, 1e-3)
        assert_near_equal(summary['Maximum range'].value, 15.78, 5)
        assert_near_equal(summary['Maximum height'].value, 54.133184, 1e-3)
        assert_near_equal(summary['Maximum velocity'].value, 47.320298, 1e-3)
Example #4
0
    def test_water_rocket_height_for_docs(self):
        import dymos as dm
        p = om.Problem(model=om.Group())

        traj, phases = new_water_rocket_trajectory(objective='height')
        traj = p.model.add_subsystem('traj', traj)

        p.driver = om.pyOptSparseDriver(optimizer='IPOPT', print_results=False)
        p.driver.opt_settings['print_level'] = 5
        p.driver.opt_settings['max_iter'] = 1000
        p.driver.opt_settings['mu_strategy'] = 'monotone'
        p.driver.declare_coloring(tol=1.0E-12)

        # Finish Problem Setup
        p.model.linear_solver = om.DirectSolver()

        p.setup()
        set_sane_initial_guesses(p, phases)

        dm.run_problem(p, run_driver=True, simulate=True)

        summary = summarize_results(p)
        for key, entry in summary.items():
            print(f'{key}: {entry.value:6.4f} {entry.unit}')

        exp_out = traj.simulate(times_per_seg=10)

        # NOTE: only the last figure is shown in the generated docs
        plot_propelled_ascent(p, exp_out)
        plot_trajectory(p, exp_out)
        plot_states(p, exp_out)

        # plt.show()

        # Check results (tolerance is relative unless value is zero)
        assert_near_equal(summary['Launch angle'].value, 85, 0.01)
        assert_near_equal(summary['Empty mass'].value, 0.144, 0.01)
        assert_near_equal(summary['Water volume'].value, 0.98, 0.01)
        assert_near_equal(summary['Maximum height'].value, 53.5, 0.01)