-
Couldn't load subscription status.
- Fork 52
Added Dynamic step size feature #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Parent:
Release v1.5
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
df51d89
Initial implementation
teubert b03f575
Added to test
teubert 8a01ba2
Simplified next_time fcn
teubert b788345
return dt instead of t
teubert d7b8c7b
Added example
teubert 742ed00
removed "press key to continue" - broke tests
teubert a4bb070
Fix message in example
teubert 4c71138
Added comment to next_time configuration
teubert c2533d6
Merge branch 'dev' into feature/adaptive_step_size
teubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright © 2021 United States Government as represented by the Administrator of the | ||
| # National Aeronautics and Space Administration. All Rights Reserved. | ||
|
|
||
| __all__ = ['sim', 'sim_valve', 'sim_pump', 'sim_battery_eol', 'model_gen', 'benchmarking', 'new_model', 'sensitivity', 'noise', 'future_loading', 'param_est', 'derived_params', 'state_limits'] | ||
| __all__ = ['sim', 'sim_valve', 'sim_pump', 'sim_battery_eol', 'model_gen', 'benchmarking', 'new_model', 'sensitivity', 'noise', 'future_loading', 'param_est', 'derived_params', 'state_limits', 'dynamic_step_size'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright © 2021 United States Government as represented by the Administrator of the | ||
| # National Aeronautics and Space Administration. All Rights Reserved. | ||
|
|
||
| """ | ||
| Example demonstrating ways to use the dynamic step size feature. This feature allows users to define a time-step that changes with time or state. Run using the command `python -m examples.dynamic_step_size` | ||
| """ | ||
|
|
||
| import prog_models | ||
| from .new_model import ThrownObject | ||
|
|
||
| def run_example(): | ||
| print("EXAMPLE 1: dt of 1 until 8 sec, then 0.5\n\nSetting up...\n") | ||
| # Step 1: Create instance of model | ||
| m = ThrownObject() | ||
|
|
||
| # Step 2: Setup for simulation | ||
| def future_load(t, x=None): | ||
| return {} | ||
|
|
||
| # Step 3: Define dynamic step size function | ||
| # This `next_time` function will specify what the next step of the simulation should be at any state and time. | ||
| # f(x, t) -> (t, dt) | ||
| def next_time(t, x): | ||
| # In this example dt is a function of time. We will use a dt of 1 for the first 8 seconds, then 0.5 | ||
| if t < 8: | ||
| return 1 | ||
| return 0.5 | ||
|
|
||
| # Step 4: Simulate to impact | ||
| # Here we're printing every time step so we can see the step size change | ||
| print('\n\n------------------------------------------------') | ||
| print('Simulating to threshold\n\n') | ||
| (times, inputs, states, outputs, event_states) = m.simulate_to_threshold(future_load, {'x':m.parameters['thrower_height']}, save_freq=1e-99, print=True, dt=next_time, threshold_keys=['impact']) | ||
|
|
||
| # Example 2 | ||
| print("EXAMPLE 2: dt of 1 until impact event state 0.5, then 0.25 \n\nSetting up...\n") | ||
|
|
||
| # Step 3: Define dynamic step size function | ||
| # This `next_time` function will specify what the next step of the simulation should be at any state and time. | ||
| # f(x, t) -> (t, dt) | ||
| def next_time(t, x): | ||
| # In this example dt is a function of state. Uses a dt of 1 until impact event state 0.5, then 0.25 | ||
| event_state = m.event_state(x) | ||
| if event_state['impact'] < 0.5: | ||
| return 0.25 | ||
| return 1 | ||
|
|
||
| # Step 4: Simulate to impact | ||
| # Here we're printing every time step so we can see the step size change | ||
| print('\n\n------------------------------------------------') | ||
| print('Simulating to threshold\n\n') | ||
| (times, inputs, states, outputs, event_states) = m.simulate_to_threshold(future_load, {'x':m.parameters['thrower_height']}, save_freq=1e-99, print=True, dt=next_time, threshold_keys=['impact']) | ||
|
|
||
| # This allows the module to be executed directly | ||
| if __name__ == '__main__': | ||
| run_example() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.