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

Improvement to the beam sphinx docs #15310

Merged
merged 16 commits into from
Oct 2, 2018

Conversation

moorepants
Copy link
Member

@moorepants moorepants commented Sep 29, 2018

References to other Issues or PRs

#15304 needs to be merged before this one.

Brief description of what is fixed or changed

I added the matplotlib sphinx directive to the sphinx config file so that we can use the plot directive to display plots from sympy.plot() or matplotlib directly. I made use of it to improve the first beam bending example. The following screenshot shows the results:
screenshot_2018-09-29 solving beam bending problems using singularity functions sympy 1 4 dev documentation

Other comments

  • Figure out doctest outputs for matplotlib plot directives.
  • Add matplotlib to the doc build on travis.

Release Notes

  • physics.continuum_mechanics
    • Added text and plots to the beam sphinx docs.

@sympy-bot
Copy link

sympy-bot commented Sep 29, 2018

Hi, I am the SymPy bot (v134). 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:

  • physics.continuum_mechanics

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

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://github.com/blog/1506-closing-issues-via-pull-requests .-->

#15304  needs to be merged before this one.

#### Brief description of what is fixed or changed

I added the matplotlib sphinx directive to the sphinx config file so that we can use the plot directive to display plots from sympy.plot() or matplotlib directly. I made use of it to improve the first beam bending example. The following screenshot shows the results:
![screenshot_2018-09-29 solving beam bending problems using singularity functions sympy 1 4 dev documentation](https://user-images.githubusercontent.com/276007/46239818-021da800-c353-11e8-8ea2-861ab51ae0af.png)

#### Other comments

- [x] Figure out doctest outputs for matplotlib plot directives.
- [x] Add matplotlib to the doc build on travis.

#### 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 -->
* physics.continuum_mechanics
  * Added text and plots to the beam sphinx docs.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@moorepants
Copy link
Member Author

The matplolib plot directive seems to create an output on Travis that I don't see locally. I thought the trailing semicolon would suppress that:

**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 199, in beam_problems.rst
Failed example:
    b.plot_shear_force();
Expected nothing
Got:
                                                                                                                   Plot object containing:                                                                                                                
    [0]: cartesian line: -258*SingularityFunction(x, 0, -1) + 52*SingularityFunction(x, 0, 0) - 8*SingularityFunction(x, 0, 1) + 50*SingularityFunction(x, 5, -1) + 8*SingularityFunction(x, 5, 1) - 12*SingularityFunction(x, 9, 0) for x over (0.0, 9.0)
**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 200, in beam_problems.rst
Failed example:
    b.plot_bending_moment();
Expected nothing
Got:
                                                                                                                  Plot object containing:                                                                                                               
    [0]: cartesian line: -258*SingularityFunction(x, 0, 0) + 52*SingularityFunction(x, 0, 1) - 4*SingularityFunction(x, 0, 2) + 50*SingularityFunction(x, 5, 0) + 4*SingularityFunction(x, 5, 2) - 12*SingularityFunction(x, 9, 1) for x over (0.0, 9.0)
**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 233, in beam_problems.rst
Failed example:
    b.plot_slope(subs={E: 20E9, I: 3.25E-6});
Expected nothing
Got:
                                                                                                                                                                Plot object containing:                                                                                                                                                            
    [0]: cartesian line: -0.00396923076923077*SingularityFunction(x, 0, 1) + 0.0004*SingularityFunction(x, 0, 2) - 2.05128205128205e-5*SingularityFunction(x, 0, 3) + 0.000769230769230769*SingularityFunction(x, 5, 1) + 2.05128205128205e-5*SingularityFunction(x, 5, 3) - 9.23076923076923e-5*SingularityFunction(x, 9, 2) for x over (0.0, 9.0)
**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 234, in beam_problems.rst
Failed example:
    b.plot_deflection(subs={E: 20E9, I: 3.25E-6});
Expected nothing
Got:
                                                                                                                                                                       Plot object containing:                                                                                                                                                                   
    [0]: cartesian line: -0.00198461538461538*SingularityFunction(x, 0, 2) + 0.000133333333333333*SingularityFunction(x, 0, 3) - 5.12820512820513e-6*SingularityFunction(x, 0, 4) + 0.000384615384615385*SingularityFunction(x, 5, 2) + 5.12820512820513e-6*SingularityFunction(x, 5, 4) - 3.07692307692308e-5*SingularityFunction(x, 9, 3) for x over (0.0, 9.0)
**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 243, in beam_problems.rst
Failed example:
    b.plot_loading_results(subs={E: 20E9, I: 3.25E-6});
Exception raised:
    Traceback (most recent call last):
      File "/opt/python/3.6.3/lib/python3.6/doctest.py", line 1330, in __run
        compileflags, 1), test.globs)
      File "<doctest beam_problems.rst[27]>", line 1, in <module>
        b.plot_loading_results(subs={E: 20E9, I: 3.25E-6});
      File "/home/travis/build/sympy/sympy/sympy/physics/continuum_mechanics/beam.py", line 1432, in plot_loading_results
        plt = matplotlib.pyplot
    AttributeError: 'NoneType' object has no attribute 'pyplot'
**********************************************************************
File "/home/travis/build/sympy/sympy/doc/src/modules/physics/continuum_mechanics/beam_problems.rst", line 884, in beam_problems.rst
Failed example:
    plot(b.load, (x, 0, 10*n))
Expected nothing
Got:
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Plot object containing:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    [0]: cartesian line: 1.0*SingularityFunction(x, 5, 0) - 1.0*SingularityFunction(x, 10, 0) + 0.2*SingularityFunction(x, 15, 1) - 1.0*SingularityFunction(x, 20, 0) - 0.2*SingularityFunction(x, 20, 1) + 0.04*SingularityFunction(x, 25, 2) - 1.0*SingularityFunction(x, 30, 0) - 0.4*SingularityFunction(x, 30, 1) - 0.04*SingularityFunction(x, 30, 2) + 0.008*SingularityFunction(x, 35, 3) - 1.0*SingularityFunction(x, 40, 0) - 0.6*SingularityFunction(x, 40, 1) - 0.12*SingularityFunction(x, 40, 2) - 0.008*SingularityFunction(x, 40, 3) + 0.0016*SingularityFunction(x, 45, 4) - 1.0*SingularityFunction(x, 50, 0) - 0.8*SingularityFunction(x, 50, 1) - 0.24*SingularityFunction(x, 50, 2) - 0.032*SingularityFunction(x, 50, 3) - 0.0016*SingularityFunction(x, 50, 4) + 0.00032*SingularityFunction(x, 55, 5) - 1.0*SingularityFunction(x, 60, 0) - 1.0*SingularityFunction(x, 60, 1) - 0.4*SingularityFunction(x, 60, 2) - 0.08*SingularityFunction(x, 60, 3) - 0.008*SingularityFunction(x, 60, 4) - 0.00032*SingularityFunction(x, 60, 5) for x over (0.0, 60.0)
**********************************************************************

@moorepants
Copy link
Member Author

@asmeurer Curious if you are fine adding the matplotlib sphinx directive extension so that we can show plots in the sympy docs? (before I do more work on this)

@jashan498
Copy link
Member

jashan498 commented Sep 30, 2018

I am getting errors locally. Just writing the Plot object under the plotting functions(like below) got rid of error.

>>> b.plot_shear_force()
   Plot object containing:                                                                                                                
   [0]: cartesian line: -258*SingularityFunction(x, 0, -1) + 52*SingularityFunction(x, 0, 0) - 8*SingularityFunction(x, 0, 1) + 50*SingularityFunction(x, 5, -1) + 8*SingularityFunction(x, 5, 1) - 12*SingularityFunction(x, 9, 0) for x over (0.0, 9.0)

@moorepants
Copy link
Member Author

This is ready for a review. Tests seem to be passing.

@moorepants
Copy link
Member Author

@jashan498 Can you review?

@jashan498
Copy link
Member

jashan498 commented Oct 2, 2018

Shouldn't deflection and slope curves also be added for truncated polynomial load example?
Rest looks good to me.

@moorepants
Copy link
Member Author

Yes, more can always be added. I think that it is sufficient as is to demonstrate that the loading work correctly (from fixes in #15304). All of the examples can be improved. Just wanted to get matplotlib extension working and have at least one example showing that off. Gonna merge for now and open issues for further improvements.

@moorepants moorepants merged commit 27390f4 into sympy:master Oct 2, 2018
@moorepants moorepants deleted the improve-beam-docs branch October 2, 2018 18:25
@asmeurer
Copy link
Member

asmeurer commented Oct 2, 2018

This looks nice. I would suggest replacing the ASCII art with an SVG image (it shouldn't be too hard to recreate in Inkscape).

\\\\|V V V V V V V V V |
\\\\|________________|_______________V
\\\\| | |
\\\\o - - - - - - - -⭯ 50 kN-m - - - | - - -> x
Copy link
Member

Choose a reason for hiding this comment

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

Worth noting that this ⭯ character doesn't render for me on my phone (it just comes out as a blank space).

@moorepants
Copy link
Member Author

This looks nice. I would suggest replacing the ASCII art with an SVG image (it shouldn't be too hard to recreate in Inkscape).

Yes, it would be nice to have SVG diagrams. We can open an issue for that. Drawing them will take some time.

Worth noting that this ⭯ character doesn't render for me on my phone (it just comes out as a blank space).

I guess this is a system font thing? Not sure how to know what unicode characters are generally supported.

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.

4 participants