Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Basic field functions for sympy.physics.vector #2922

Merged
merged 6 commits into from Mar 20, 2014

Conversation

Projects
None yet
5 participants
Member

srjoglekar246 commented Feb 17, 2014

Adds following functions to the new vector module -

  1. curl
  2. divergence
  3. gradient
  4. is_conservative
  5. is_solenoidal
  6. scalar_potential
  7. scalar_potential_difference
Member

srjoglekar246 commented Feb 17, 2014

@smichr smichr commented on an outdated diff Feb 17, 2014

sympy/physics/vector/fieldfunctions.py
+ out = S(0)
+ out += diff(vectx, frame[0])
+ out += diff(vecty, frame[1])
+ out += diff(vectz, frame[2])
+ return out
+
+
+def gradient(scalar, frame):
+ """
+ Returns the vector gradient of a scalar field computed wrt the
+ coordinate symbols of the given frame.
+
+ Parameters
+ ==========
+
+ scalar : sympyfiable
@smichr

smichr Feb 17, 2014

Member

2nd y to i as sympifiable

(There are other occurances throughout sympy with sympyfyable that could be changed, too.)

Member

moorepants commented Feb 24, 2014

@srjoglekar246 Tests are failing on Travis.

@moorepants moorepants added the mechanics label Mar 3, 2014

@srjoglekar246 srjoglekar246 commented on the diff Mar 5, 2014

sympy/physics/vector/vector.py
+ def separate(self):
+ """
+ The constituents of this vector in different reference frames,
+ as per its definition.
+
+ Returns a dict mapping each ReferenceFrame to the corresponding
+ constituent Vector.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.vector import ReferenceFrame
+ >>> R1 = ReferenceFrame('R1')
+ >>> R2 = ReferenceFrame('R2')
+ >>> v = R1.x + R2.x
+ >>> v.separate() == {R1: R1.x, R2: R2.x}
@srjoglekar246

srjoglekar246 Mar 5, 2014

Member

@moorepants There seems to be a problem with the printing function. Initially the of this line was on the line below, and it gave an error "Symbol object has no attribute 'x'". Have a look- https://travis-ci.org/sympy/sympy/jobs/19042675. This works fine.

Member

srjoglekar246 commented Mar 6, 2014

@moorepants Seems a timeout error..Okay to merge?

@flacjacket flacjacket added mechanics and removed Mechanics labels Mar 7, 2014

Member

moorepants commented Mar 11, 2014

I restarted it. But yeah, this is probably fine now.

Member

srjoglekar246 commented Mar 12, 2014

Travis passes now.

Member

moorepants commented Mar 14, 2014

Ok, so add this to the 0.7.6 release notes on the wiki. And the next PR should be some Sphinx documentation showing how this stuff works.

+1

Member

moorepants commented Mar 14, 2014

@sympy/mechanics Can I get another +1 from anyone?

@tjl tjl commented on the diff Mar 14, 2014

sympy/physics/vector/tests/test_fieldfunctions.py
+
+def test_solenoidal():
+ assert is_solenoidal(0) is True
+ assert is_solenoidal(R.x) is True
+ assert is_solenoidal(2 * R.x + 3 * R.y + 4 * R.z) is True
+ assert is_solenoidal(R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z) is \
+ True
+ assert is_solenoidal(R[1] * R.y) is False
+ assert is_solenoidal(grad_field) is False
+ assert is_solenoidal(curl_field) is True
+ assert is_solenoidal((-2*R[1] + 3)*R.z) is True
+ assert is_solenoidal(cos(q)*R.x + sin(q)*R.y + cos(q)*P.z) is True
+ assert is_solenoidal(R[2]*P.x + P[0]*R.z) is True
+
+
+def test_scalar_potential():
@tjl

tjl Mar 14, 2014

Member

There should really be a test for a non-conservative field, to test the if statement.

@srjoglekar246

srjoglekar246 Mar 14, 2014

Member

Aah yeah I guess. Will have to take help of raises.

Member

srjoglekar246 commented Mar 18, 2014

@tjl Added the 'raises' test. You +1 to the rest?

Member

tjl commented Mar 18, 2014

Yes, I'm +1 to the rest.

Member

srjoglekar246 commented Mar 19, 2014

@moorepants could you merge this?

Member

moorepants commented Mar 20, 2014

Ok, going in.

moorepants added a commit that referenced this pull request Mar 20, 2014

Merge pull request #2922 from srjoglekar246/newfunctions
Basic field functions for sympy.physics.vector

@moorepants moorepants merged commit 84c3052 into sympy:master Mar 20, 2014

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment