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

Fix divergence in cylindrical coordinates #20047

Merged
merged 2 commits into from Nov 5, 2021

Conversation

lindsayad
Copy link
Contributor

@lindsayad lindsayad commented Sep 4, 2020

This fix is more general than my particular use case, but I wanted to
compute:

from sympy.vector import divergence, gradient, Vector, CoordSys3D
R = CoordSys3D('R', transformation='cylindrical')
divergence(R.i)

The correct solution to this is 1/r, however, sympy returned zero
because it was detecting that no base scalars were in the provided
expression, and then using the special case code, returning zero. A
straight-forward solution to this is removing the special case code, and
simply returning a Derivative instantiation every time.

  • vector
    • Always return Derivative instance from _diff_conditional in operators.py since the coeffs may be functions of the base scalars even if expr is not

@sympy-bot
Copy link

sympy-bot commented Sep 4, 2020

Hi, I am the SymPy bot (v162). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • vector
    • Always return Derivative instance from _diff_conditional in operators.py since the coeffs may be functions of the base scalars even if expr is not (#20047 by @lindsayad and @smichr)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.10.

Click here to see the pull request description that was parsed.
This fix is more general than my particular use case, but I wanted to
compute:

```python
from sympy.vector import divergence, gradient, Vector, CoordSys3D
R = CoordSys3D('R', transformation='cylindrical')
divergence(R.i)
```

The correct solution to this is 1/r, however, sympy returned zero
because it was detecting that no base scalars were in the provided
expression, and then using the special case code, returning zero. A
straight-forward solution to this is removing the special case code, and
simply returning a `Derivative` instantiation every time.

<!-- BEGIN RELEASE NOTES -->
- vector
    - Always return `Derivative` instance from `_diff_conditional` in `operators.py` since the `coeffs` may be functions of the base scalars even if `expr` is not

Update

The release notes on the wiki have been updated.

@friyaz
Copy link
Member

friyaz commented Sep 4, 2020

Looks good. Please add test cases.

friyaz
friyaz previously requested changes Sep 18, 2020
Copy link
Member

@friyaz friyaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lindsayad please fix the flake test. Importing BaseScalar is not needed. I think then we can get this merged.

This fix is more general than my particular use case, but I wanted to
compute:

```python
from sympy.vector import divergence, gradient, Vector, CoordSys3D
R = CoordSys3D('R', transformation='cylindrical')
divergence(R.i)
```

The correct solution to this is 1/r, however, sympy returned zero
because it was detecting that no base scalars were in the provided
expression, and then using the special case code, returning zero. A
straight-forward solution to this is removing the special case code, and
simply returning a `Derivative` instantiation every time.
@czgdp1807
Copy link
Member

@lindsayad Would you like to conclude this PR? Please let us know and do NOT close this PR. Thanks for your contributions.

@lindsayad
Copy link
Contributor Author

I would like to see it concluded. It looks like my change broke this test:

Failed example:
    delop.dot(C.x*C.i)
Expected:
    Derivative(C.x, C.x)
Got:
    Derivative(0, C.y) + Derivative(0, C.z) + Derivative(C.x, C.x)

I'm not surprised by this. I guess from my perspective, I would rather have more verbose output than sometimes have wrong output. If you guys agree, then I will change that test. I'm also open to other suggestions.

@czgdp1807
Copy link
Member

Derivative(0, C.y) + Derivative(0, C.z) + Derivative(C.x, C.x)

This notation seems better to me. At least it makes clear that y and z components are 0. Though what happens if we apply simplify to the above expression i.e., (Derivative(0, C.y) + Derivative(0, C.z) + Derivative(C.x, C.x)).simplify() or simplify(Derivative(0, C.y) + Derivative(0, C.z) + Derivative(C.x, C.x)).

@moorepants Any thoughts on this?

@smichr smichr dismissed friyaz’s stale review November 5, 2021 05:28

changes have been made

@github-actions
Copy link

github-actions bot commented Nov 5, 2021

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [907895ac]       [87cbdd9a]
+      7.47±0.3ms       12.1±0.8ms     1.62  matrices.TimeMatrixPower.time_Case1

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@smichr
Copy link
Member

smichr commented Nov 5, 2021

I will open an issue for adding a test.

@smichr smichr merged commit 0e38ca4 into sympy:master Nov 5, 2021
@lindsayad
Copy link
Contributor Author

Just yesterday I was on a new machine and manually updated this file when doing some MMS testing and I thought to myself that I really need to get this in. Thanks for getting this over the finish line!

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

Successfully merging this pull request may close these issues.

None yet

6 participants