-
Notifications
You must be signed in to change notification settings - Fork 20
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
Mississippi steamboat on a lake #208
Mississippi steamboat on a lake #208
Conversation
Error:
|
# - :math:`A_S`: body fixed frame of the steamboat | ||
# - :math:`A_{LW}`: body fixed frame of the left wheel | ||
# - :math:`A_{RW}`: body fixed frame of the right wheel | ||
# - :math:`Dmc_S`: center of the steamboat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "mc" supposed to be a subscript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "mc" supposed to be a subscript?
No, Sir. I always use, if possible Dmc to be the ceter of mass of some body. I must have copied this from some example a long time ago. If I have Dmc in a name in my code I know it is a center of mass of something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking more because the math renders awkwardly, not because I don't like your naming conventions. You have these symbols as proper math, so I would expect them to have proper super and subscripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking more because the math renders awkwardly, not because I don't like your naming conventions. You have these symbols as proper math, so I would expect them to have proper super and subscripts.
If I understand you correctly, something like
Would DmcS be better? (I do not want to give up Dmc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect something more like:
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically use A o or A ∗ for the mass center of rigid body A .
I thought capital A was 'reserved' for body fixed frames?
So, I could change to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use any letter you want for a frame, I meant that if you have a frame
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use any letter you want for a frame, I meant that if you have a frame X , then the mass center is X o or X ∗ .
So, if the body fixed frame of my steamboat is
In the code AS would be the frame and AoS the center of gravity. Should I change the designation like this?
# - :math:`FP_{RW}`: point where the force due to rotation of the right | ||
# wheel is applied | ||
|
||
N, AS, ALW, ARW = sm.symbols('N, AS, ALW, ARW', cls = me.ReferenceFrame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N, AS, ALW, ARW = sm.symbols('N, AS, ALW, ARW', cls = me.ReferenceFrame) | |
N, AS, ALW, ARW = sm.symbols('N, AS, ALW, ARW', cls=me.ReferenceFrame) |
PEP8: no space around kwarg equals signs.
# Set up the drag forces acting on the boat. | ||
# | ||
# The drag force acting on a body moving in a fluid is given by | ||
# :math:`F_D = -c \cdot A \cdot | \bar v|^2 \cdot \dfrac{\bar v}{| \bar v|}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drag force is more typically:
where
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my article, which I will remove and replace, there was the 'suggestion' to lump
Hence I did it.
# vector of the body and :math:`A` is the cross section area of the body facing | ||
# the flow. This may be found here: | ||
# | ||
# https://courses.lumenlearning.com/suny-physics/chapter/5-2-drag-forces/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this link, as it is a textbook equation. Or better link to a wikipedia article about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this link, as it is a textbook equation. Or better link to a wikipedia article about it.
this one o.k.?
https://en.wikipedia.org/wiki/Drag_(physics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a whole page about the "drag equation": https://en.wikipedia.org/wiki/Drag_equation
# ( :math:`\circ` denotes the inner product) | ||
# | ||
# :math:`F_{D_x} = -c \cdot A \cdot (A.x \circ \bar v)^2 \cdot \operatorname{sgn}(A.x \circ \bar v) \cdot A.x` | ||
# :math:`F_{D_y} = -c \cdot A \cdot (A.y \circ \bar v)^2 \cdot \operatorname{sgn}(A.y \circ \bar v) \cdot A.y` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I typically use \cdot
for dot product and do not use a symbol for scalar multiplication, e.g.
Also, sympy prints unit vectors like: \hat{\mathbf{a}}_x
.
# As an (infinitely often) differentiable approximation of the sign function, | ||
# I will use the fairly standard approximation: | ||
# | ||
# :math:`\operatorname{sgn}(x) \approx \tanh( \alpha \cdot x )` with :math:`\alpha \gg 1` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you specify all the variables to have correct assumptions (for example real=True
or nonegative=True
, then you can use Abs()
and it will differentiate once and print with the C printers. I don't think you have to use this tangent function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you specify all the variables to have correct assumptions (for example
real=True
ornonegative=True
, then you can useAbs()
and it will differentiate once and print with the C printers. I don't think you have to use this tangent function.
Mathematically abs(x-a) is not differentiable at x=a, or so I understand it. How does sympy go around this?
(I had a problem with opty and abs before, but I do not think, I declared the variables to be real)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [1]: import sympy as sm
In [2]: t = sm.symbols('t', real=True, nonnegative=True)
In [3]: v = sm.Function('v', real=True)(t)
In [4]: f = sm.Abs(v)
In [5]: f
Out[5]: Abs(v(t))
In [6]: f.diff(t)
Out[6]: sign(v(t))*Derivative(v(t), t)
In [7]: f.diff(v)
Out[7]: sign(v(t))*Derivative(v(t), v(t))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This means, sympy defines
Out[7] is not differentiable at v(t) = 0.
Would opty not 'prefer' functions whose derivatives are smooth, or does this not affect convergence?
(my gut feeling is that the more often the functions are differentiable the better the convergence - but my gut feeling was off before!!)
Should I try with sm.Abs(....)?
You wrote; t = sm.symbols('t', real=True, nonnegative=True)
I recall you told me it is better to use t = me.dynamicsymbols._t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just leave it as the tanh function.
I recall you told me it is better to use t = me.dynamicsymbols._t
That is required if you use the default symbol for t in sympy.physics.mechanics. But you can set t to any variable you want.
I (hopefully) made all the corrections you suggested, except I did not dare replacing the tanh(x) expression with the equivalent abs(x) expression. opty does not 'like' functions which are not differentiable, you told me at least once before. NB: Let me look at my other two PRs and correct what you suggested here, before you waste your time telling me the same mistakes which I made here. |
Here is a trick for using Abs() (but not required for this example). https://github.com/csu-hmc/gait2d/blob/master/pygait2d/segment.py#L444 |
I used the link to drag force you gave. |
I renamed the mass centers as follows: |
Now I remember, clever! I believe you showed this no me in another context, it was this trick: Would it be a sound rule of thumb for opty to avoid function which are not differentiable at certain points unless one is sure, these points will never be close to the optimum solution of opty? |
Hold off with this one, please. |
These two commits are the same, I just had some problem (I am still not very perfect with this github stuff), so I committed again. |
I made some error in github!
Thanks, merged! |
Thank you! :-) |
I just follow PEP8 on Python module filenames:
|
Clear! |
No, they all use underscores. If you name a file |
so, either thisisapackage or this_is_a_package |
yes |
A boat is on a lake. It has a water wheel on each side to drive and to stir it, hence the name Mississippi. The control variables are the torques applied to each wheel. The goal is to get it from A to B. the objective function is a linear combination of minimizing the energy and minimizing the time needed. the drag force on a body with speed$\bar v$ is modeled as
$F_D = -c \cdot A \cdot | \bar v |^2 \cdot \dfrac{\bar v}{| \bar v |}$ , where c is the drag coefficient and A is the surface facing the flow.
I do not print the EOMs as they have around 850 operations. Else, I hope all close to examples-gallery standards.