I started some work on the above mentioned idea using 
https://github.com/sympy/sympy/pull/9937 as the starting point. 
The idea mentioned there was to use a curvilinear coordinate system to 
compute Divergence, Curl, etc.

I am attaching the python code for the case of Spherical Coordinate System 
using the curvilinear system idea which defines a vector as 
A = Ar r^ + At theta^ + Ap phi^ where Ar, At, Ap are components in r, theta 
and phi unit vector direction respectively. 
But Ar, At, and Ap all can be functions of r, theta and phi which can help 
in computing the curl and divergence for any vector field in Spherical 
Polar Coordinates.

The issue I am facing is that the sympy function "diff" is not treating Ar, 
At and Ap as functions. 
Could you guide me in this ?  Attached is the Python code. 


On Tuesday, March 21, 2017 at 9:37:35 PM UTC+5:30, brombo wrote:
>
> Start with a vector manifold defined in rectangular coordinates but with 
> components that are functions of the new coordinates.  For spherical 
> coordinates -
>
> [image: \mathbf{R} = 
> r(\cos(\phi)\mathbf{k}+\sin(\phi)(\sin(\theta)\mathbf{i})+\cos(\theta)\mathbf{j})]
>
> [image: \mathbf{R}] defines the vector manifold.  The derivatives of [image: 
> \mathbf{R}] with respect to [image: r], [image: \phi], and [image: \theta] 
> define a set of basis vectors (unnormalized) [image: \mathbf{e}_r], [image: 
> \mathbf{e}_\phi], and [image: \mathbf{e}_\theta]. Likewise the 
> derivatives of 
> [image: \mathbf{e}_r], [image: \mathbf{e}_\phi], and [image: 
> \mathbf{e}_\theta] with respect to [image: r], [image: \phi], and [image: 
> \theta] can be calculated (needed for divergence and curl calculation).  
> Then you need to represent the derivatives of the unnormalized
> basis vectors in terms of a linear combination of the basis vectors.  One 
> way of doing this is to calculate the metric tensor from the dot products 
> of [image: \mathbf{e}_r], [image: \mathbf{e}_\phi], and [image: 
> \mathbf{e}_\theta] and then
> use the Christoffel symbols to calculate the derivatives of the basis 
> vectors.  After all this you probably want to normalize the basis vectors 
> and recalculate (simple scaling) 
> the derivatives of the normalized basis vectors in terms of the normalized 
> basis vectors. 
>
>
>
>
>
>
>
>
> On Mon, Mar 20, 2017 at 9:21 PM, Mikayla Grace <[email protected] 
> <javascript:>> wrote:
>
>> Edit:  I did find the work on dot products, and it looks like the 
>> framework is solid, which means that implementing other coordinate systems 
>> and allowing the function "dot" to accept these other vector 
>> representations would be a great extension to the current project idea that 
>> I would like to pursue.
>>
>>
>> On Sunday, March 12, 2017 at 12:30:22 PM UTC-4, Mikayla Grace wrote:
>>>
>>> I have a strong interest in working with SymPy through Google Summer of 
>>> Code and was looking at your project ideas.  The project that is most 
>>> appealing to me is the one on the implementation of multiple types of 
>>> coordinate systems for vectors.  I was curious to know if you had 
>>> considered creating a function that calculates the dot product. I looked at 
>>> the linked work on *vectors * 
>>> <https://github.com/sympy/sympy/tree/master/sympy/vector>and didn’t see 
>>> any work on that.  If there is work on dot products already, once the 
>>> framework for expressing vectors in other coordinates is solid, then it 
>>> might be useful to develop a dot product calculator that is also able to 
>>> accept different coordinate inputs.  
>>>
>>> Regarding my current skill set, I have taken a CS course at my school, 
>>> University of Vermont, and while I am not enrolled in any programming 
>>> classes this semester, I recently set up my *GitHub account* 
>>> <https://github.com/mikaylazgrace> and am independently working on 
>>> becoming more proficient in Python and Git through Code Academy. I would 
>>> say that by the end of the semester and the start of the program I will be 
>>> a solid beginner in both.  I am a second-year pure math major and would put 
>>> my math level at “intermediate”  I also have an on-site mentor, *Christelle 
>>> Vincent, PhD,* <https://github.com/christellevincent> who would be 
>>> available over the summer.
>>>
>>> I'd love to hear your thoughts about extending the idea of different 
>>> coordinates systems to a dot product calculator. Please let me know if you 
>>> think my current skill set aligns with the project I'm interested in or if 
>>> there's another project I might be better suited for.  Thank you for your 
>>> time, and I look forward to hearing back from you!
>>>
>>> Sincerely,
>>> Mikayla Grace
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sympy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> Visit this group at https://groups.google.com/group/sympy.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/ee9392ca-f485-4bb1-9618-cafec27c6461%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sympy/ee9392ca-f485-4bb1-9618-cafec27c6461%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/11630e9b-ea4f-40b8-b237-47b83284215f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from sympy import *
from sympy.vector import *
C = CoordSysCartesian('C')

r = Symbol('r', positive = True, real = True)
theta = Symbol('theta', positive = True)
phi = Symbol('phi')

#Defining Spherical Polar Coordinates in i, j, k space

R = r*sin(theta)*cos(phi)*C.i + r*sin(theta)*sin(phi)*C.j + r*cos(theta)*C.k
print R.components
print "Magnitude:" + str(simplify(sqrt(R.dot(R))))+"\n"

#h1, h2, h3 are scale factor for r, theta and phi respectively
h1 = diff(R,r)
h2 = diff(R, theta)
h3 = diff(R, phi)

#Scale Factors are Magnitude of Differentiation
print "Scale Factors:"+"\n"
h1 = simplify(sqrt(h1.dot(h1)))
print "for r^: "+ str(h1) +"\n"
h2 = simplify(sqrt(h2.dot(h2)))
print "for theta^: " + str(h2)+"\n"
h3 = simplify(sqrt(h3.dot(h3)))
print "for phi^: " + str(h3)+"\n"

#e1, e2, e3 are the new unit vectors for r, theta and phi respectively
print "Unit Vector in i, j, k Cartesian System"+"\n"
e1 = simplify(diff(R, r)/h1)
print "r^="+str(e1)+"\n"
e2 = simplify(diff(R, theta)/h2)
print "theta^="+str(e2)+"\n"
e3 = simplify(diff(R, phi)/h3)
print "phi^="+str(e3)+"\n"

#A = Ar r^ + At theta^ + Ap phi^
Ar, At, Ap = symbols('Ar At Ap')
A = Ar*e1+At*e2+Ap*e3

new_coord = [r, theta, phi]
scale_factors = [h1, h2, h3]
unit_vectors = [e1, e2, e3]
h = h1*h2*h3

#Computing Divergence in New Coordinates
for i in range(0,3):
    print "Divergence in " + str(new_coord[i]) + " Component"
    multiplier = h/scale_factors[i]
    component = simplify(A.dot(unit_vectors[i]))*multiplier
    print str(diff(component, new_coord[i])/h)+"\n"

Reply via email to