Skip to content
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

Iterator for a variable at all times in Collocation class #22

Open
drewm1980 opened this issue Mar 25, 2013 · 1 comment
Open

Iterator for a variable at all times in Collocation class #22

drewm1980 opened this issue Mar 25, 2013 · 1 comment

Comments

@drewm1980
Copy link
Contributor

It would be nice if the collocation class had a built-in iterator that returns the variable over the whole range...

i.e. instead of something like:

obj = 0
for k in range(N):
for j in range(ocp.deg+1):
obj += ocp('abspos',timestep=k,degIdx=j)
obj += ocp('abspos',timestep=N,degIdx=0)

user does something like:

obj = 0
for abspos in ocp.timeIteratorForVariable('abspos'):
obj += abspos

or maybe ocp.iterValueForAllTimes('abspos')

perhaps the time should be returned too, i.e.:

obj = 0
for (abspos,t) in ocp.timeIteratorForVariable('abspos'):
obj += someTimeVaryingFunction(abspos,t)

@ghorn
Copy link
Owner

ghorn commented Apr 5, 2013

See also #6

One way would be for
for pos in ocp('pos')
to loop over timestep, degIdx, intermediateControlIdx
for pos in ocp('pos',timestep=5)
to loop over degIdx, intermediateControlIdx
etc

Maybe it would be easier to just have ocp('pos') to return an ndarray that the user could slice manually. But even then, some variables are undefined at some nodes, for example algebraic variables are undefined at degIdx=0, nothing is defined at timestep=N except differential states, nothing at all is defined for timestepN, degIdx>0 or intermediateControlIdx>0

This is not so simple to handle generally but also intuitively for the user. Maybe this functionality should be pushed into a higher level Ocp class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants