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

[WIP] Add examples of usage of vector integration #20021

Merged
merged 8 commits into from Sep 5, 2020

Conversation

friyaz
Copy link
Member

@friyaz friyaz commented Aug 30, 2020

References to other Issues or PRs

#19320

Brief description of what is fixed or changed

Add examples highlighting the usage of SymPy's vector integration functionality.

Other comments

Release Notes

NO ENTRY

@sympy-bot
Copy link

sympy-bot commented Aug 30, 2020

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

  • No release notes entry will be added for this pull request.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
#19320 

#### Brief description of what is fixed or changed
Add examples highlighting the usage of SymPy's vector integration functionality.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->

@sympy-bot
Copy link

sympy-bot commented Aug 30, 2020

🟠

Hi, I am the SymPy bot (v160). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it.

This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75.

The following commits add new files:

  • fb5695b:
    • doc/src/modules/vector/vector_integration.rst

If these files were added/deleted on purpose, you can ignore this message.

@friyaz friyaz marked this pull request as draft Aug 30, 2020
@friyaz friyaz requested a review from Upabjojr Aug 30, 2020
Copy link
Member

@eric-wieser eric-wieser left a comment

Looks good so far.

doc/src/modules/vector/vector_integration.rst Outdated Show resolved Hide resolved
doc/src/modules/vector/vector_integration.rst Outdated Show resolved Hide resolved
doc/src/modules/vector/vector_integration.rst Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 31, 2020

Codecov Report

Merging #20021 into master will increase coverage by 0.005%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##            master    #20021       +/-   ##
=============================================
+ Coverage   75.849%   75.854%   +0.005%     
=============================================
  Files          670       670               
  Lines       173699    173699               
  Branches     40978     40978               
=============================================
+ Hits        131750    131759        +9     
+ Misses       36209     36199       -10     
- Partials      5740      5741        +1     

>>> sphere = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
... (theta, 0, pi), (phi, 0, pi), (r, 0, 3))
>>> vector_integrate(1, sphere)
-18*pi
Copy link
Contributor

@Upabjojr Upabjojr Aug 31, 2020

Choose a reason for hiding this comment

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

why is this result negative? I would indeed expect 18*pi, the volume of the half-sphere, as you have defined theta to reach pi (instead of 2*pi).

Copy link
Member Author

@friyaz friyaz Sep 1, 2020

Choose a reason for hiding this comment

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

In ParametricIntegral class

variables = cls._bounds_case(parametricregion.limits)
coeff = Matrix(parametricregion.definition).jacobian(variables).det()
integrand = simplify(parametricfield*coeff)
l = [(var, parametricregion.limits[var][0], parametricregion.limits[var][1]) for var in variables]
result = integrate(integrand, *l)

The volume element requires calculating the jacobian. So the sign depends on the order of variables used in the calculation of jacobian. This order is determined by the bounds_case function which topologically sorts the parameters to remove the problem of interdependent bounds.

So in the current form, the order in which the bounds are defined at the initialization of ParametricRegion object does not matter in the calculation of integral. Because in the end, parameters ger sorted by bounds_case function. Is this correct? Or should the result depend on the order of parameters and the sorting should only take place when required?

Copy link
Member Author

@friyaz friyaz Sep 1, 2020

Choose a reason for hiding this comment

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

For example,

sphere1 = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),\
                                                (theta, 0, pi), (phi, 0, pi), (r, 0, 3))
sphere2 = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),\
                                                  (r, 0, 3), (theta, 0, pi), (phi, 0, pi))

In the present implementation, vector_integrate(1, sphere1) and vector_integrate(1, sphere2) returns result with same sign.
Is this desired or should the order matter?

doc/src/modules/vector/vector_integration.rst Outdated Show resolved Hide resolved
@Upabjojr
Copy link
Contributor

Upabjojr commented Sep 2, 2020

Any news?

@Upabjojr
Copy link
Contributor

Upabjojr commented Sep 2, 2020

There are still some examples missing.

@friyaz friyaz requested a review from Upabjojr Sep 2, 2020
doc/src/modules/vector/vector_integration.rst Outdated Show resolved Hide resolved

Consider a triangular lamina 𝑅 with vertices (0,0), (0, 5), (5,0) and with density :math:`\rho(x, y) = xy\:kg/m^2`. Find the total mass.

>>> triangle = ParametricRegion((x, y), (x, 0, 5), (y, 0, 5 - x))
Copy link
Contributor

@Upabjojr Upabjojr Sep 3, 2020

Choose a reason for hiding this comment

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

does this work with the polygon object as well?

Copy link
Member Author

@friyaz friyaz Sep 3, 2020

Choose a reason for hiding this comment

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

No. vector_integrate will perform line integral over the sides of the polygon instead of calculating the area enclosed.

Copy link
Contributor

@Upabjojr Upabjojr Sep 4, 2020

Choose a reason for hiding this comment

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

OK, maybe that's an issue for some future work.

Copy link
Member Author

@friyaz friyaz Sep 4, 2020

Choose a reason for hiding this comment

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

Yes. We can add new classes in geometry module for representing such regions.

Copy link
Member Author

@friyaz friyaz Sep 4, 2020

Choose a reason for hiding this comment

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

I will open an issue for this then.

Copy link
Contributor

@Upabjojr Upabjojr Sep 4, 2020

Choose a reason for hiding this comment

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

It would require an algorithm to decompose the polygon into triangles (or pyramids in the 3D case). Well, maybe for GSoC 2021 :)

Copy link
Member Author

@friyaz friyaz Sep 4, 2020

Choose a reason for hiding this comment

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

Yes, for polygons it will be difficult. But I think adding a class to represent a triangular area will be easier.

@friyaz friyaz requested review from eric-wieser and Upabjojr Sep 4, 2020
@friyaz
Copy link
Member Author

friyaz commented Sep 4, 2020

(Copied from sympy/vector gitter room)

I still have some more things to add to this.

  1. The functionality of finding rational parametrization from the implicit equation is not described anywhere except the docstring of the ParametricRegion class. I think it is a very important addition to SymPy and can be very helpful.

  2. I think the examples will be more helpful if accompanied by figures.

Apart from these points, I think this PR is ready to merge. Perhaps, I will make these changes in a separate PR.

@friyaz friyaz marked this pull request as ready for review Sep 4, 2020
@Upabjojr Upabjojr merged commit e30ade0 into sympy:master Sep 5, 2020
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants