Repository: sympy/sympy
Pull request: Function to calculate Polar moment of inertia of a 3D Beam
<!-- 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 . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
fixes #16392

#### Brief description of what is fixed or changed

New function in Beam/Beam3D
#### Other comments

Currently calculates polar moment only along x-axis
#### 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 a new function polar_moment()
<!-- END RELEASE NOTES -->


Problem statement:
No function for calculating polar moment of inertia and section modulus in continuum_mechanics in beam.py
There is currently no function to calculate polar moment of inertia and section modulus of the beam . Both of these quantities are important in further future works in this module.

Hints from issue discussion:
Can I work on this?

Sure, feel free.
Here the Beam is 2D, so along what axis should the polar moment be? Usually it is along the beam, right?
@arooshiverma There is a separate class for 3D beams. Checkout from line no 1493. I think you'll have to calculate it in all 3 directions.
Yeah got it. Will do it.

Commit message: Removed the axis parameter from polar_moment() function

Patch to review:
diff --git a/sympy/physics/continuum_mechanics/beam.py b/sympy/physics/continuum_mechanics/beam.py
index 35db899e9bcd..49932c37df7f 100644
--- a/sympy/physics/continuum_mechanics/beam.py
+++ b/sympy/physics/continuum_mechanics/beam.py
@@ -1664,6 +1664,30 @@ def boundary_conditions(self):
         """
         return self._boundary_conditions
 
+
+    def polar_moment(self):
+        """
+        This function calculates the Polar moment of Inertia of the beam about the x axis.
+
+        Examples
+        ========
+
+        >>> from sympy.physics.continuum_mechanics.beam import Beam3D
+        >>> from sympy import symbols
+        >>> l, E, G, I, A = symbols('l, E, G, I, A')
+        >>> b = Beam3D(l, E, G, I, A)
+        >>> b.polar_moment()
+        2*I
+        >>> I1 = [9, 15]
+        >>> b = Beam3D(l, E, G, I1, A)
+        >>> b.polar_moment()
+        24
+        """
+        if isinstance(self.second_moment, int) or isinstance(self.second_moment, Symbol):
+            return 2*self.second_moment
+        return self.second_moment[0] + self.second_moment[1]
+
+
     def apply_load(self, value, start, order, dir="y"):
         """
         This method adds up the force load to a particular beam object.
diff --git a/sympy/physics/continuum_mechanics/tests/test_beam.py b/sympy/physics/continuum_mechanics/tests/test_beam.py
index 2e8bdf0ca0b6..fe59f43357e2 100644
--- a/sympy/physics/continuum_mechanics/tests/test_beam.py
+++ b/sympy/physics/continuum_mechanics/tests/test_beam.py
@@ -502,6 +502,7 @@ def test_Beam3D():
     b.bc_deflection = [(0, [0, 0, 0]), (l, [0, 0, 0])]
     b.solve_slope_deflection()
 
+    assert b.polar_moment()==2*I
     assert b.shear_force() == [0, -q*x, 0]
     assert b.bending_moment() == [0, 0, -m*x + q*x**2/2]
     expected_deflection = (-l**2*q*x**2/(12*E*I) + l**2*x**2*(A*G*l*(l*q - 2*m)
@@ -543,6 +544,13 @@ def test_Beam3D():
     b3.solve_for_reaction_loads(R1, R2, R3, R4)
     assert b3.reaction_loads == {R1: -120, R2: -120, R3: -1350, R4: -2700}
 
+def test_polar_moment_Beam3D():
+    l, E, G, A, I1, I2 = symbols('l, E, G, A, I1, I2')
+    R1, R2, R3, R4 = symbols('R1, R2, R3, R4')
+    I=[I1, I2]
+
+    b = Beam3D(l, E, G, I, A)
+    assert b.polar_moment() == I1 + I2
 
 def test_parabolic_loads():
 


Code review comments:
diff_hunk: @@ -1664,6 +1664,30 @@ def boundary_conditions(self):
         """
         return self._boundary_conditions
 
+
+    def polar_moment(self):
+        """
+        This function calculates the Polar moment of Inertia of the beam about the x axis.
path: sympy/physics/continuum_mechanics/beam.py
text: @user1:
Change to "Returns the polar moment of area of the beam about the X axis with respect to the centroid."

diff_hunk: @@ -1664,6 +1664,30 @@ def boundary_conditions(self):
         """
         return self._boundary_conditions
 
+
+    def polar_moment(self):
+        """
+        This function calculates the Polar moment of Inertia of the beam about the x axis.
+
+        Examples
+        ========
+
+        >>> from sympy.physics.continuum_mechanics.beam import Beam3D
+        >>> from sympy import symbols
+        >>> l, E, G, I, A = symbols('l, E, G, I, A')
+        >>> b = Beam3D(l, E, G, I, A)
+        >>> b.polar_moment()
+        2*I
+        >>> I1 = [9, 15]
+        >>> b = Beam3D(l, E, G, I1, A)
+        >>> b.polar_moment()
+        24
+        """
+        if isinstance(self.second_moment, int) or isinstance(self.second_moment, Symbol):
path: sympy/physics/continuum_mechanics/beam.py
text: @user1:
This is not a good check. You should check if it iterable or if it has a length of 2 to know if there is a unique Ix and Iy.