Hi again,

I believe that I found the proper way to do it, so I am putting this here 
in case it can be of any help to anyone.

import sympy as sp
import sympy.vector as spv
# from IPython.display import Latex # uncomment in Jupyter notebook

S = spv.CoordSysCartesian('S')
n = sp.Function('n')(S.x, S.y, S.z, t)
Lap = S.delop.dot(S.delop(n))
print(sp.latex(Lap))
# Latex('${}$'.format(sp.latex(Lap))) # uncomment in Jupyter notebook

This produces the expected behavior.

Le mardi 24 juillet 2018 19:25:46 UTC+2, Alexis Prel a écrit :
>
> Hi all,
>
> As this is my first message in this group, I will first introduce myself, 
> my actual question starts in the next paragraph. I am a PhD student in 
> physics. I am working on the modelling of organic solar cells by the 
> so-called drift-diffusion approach, hence I plan on using sympy to deal 
> with PDE and some systematic manipulations of them that I do by hand for 
> now. I am quite familiar with python and its mainstream scientific 
> libraries (I teach it as a TA) but I am new to sympy.
>
> One of the first thing I tried to write in sympy was an equation of the 
> following form, where  the divergence of some vector appears:
>
> $$\frac{\partial c }{\partial t} - \vec\nabla . \vec{j_c} = 0 $$
>
> However I found no way of writing this properly in sympy. 
> Indeed, using the vector module does not take into account derivatives the 
> way I expect it to, consider the following code:
> import sympy as sp
> import sympy.vector as spv
>
> # Initialise coordinate system 
> S = spv.CoordSysCartesian('S')
> delop = spv.Del(S)
>
> # Create a new field without explicit expression
> u0, u1, u2 = sp.symbols('u0:3')
> J1 = u0*S.i + u1*S.j + u2* S.k
> J2 = S.x*S.i + S.y*S.j + S.z* S.k
>
> # Derivatives surprised me
> print('div(J1) = ', delop.dot(J1))
> print('div(J2) = ', delop.dot(J2))
> It's output goes as follow:
>
>> div(J1) =  0
>> div(J2) =  Derivative(S.x, S.x) + Derivative(S.y, S.y) + Derivative(S.z, S.z)
>>
>>
> I assumed, however that the output would look like this:
>
>> div(J1) =  Derivative(u0, S.x) + Derivate(u1, S.y) + Derivative(u2, S.z)
>> div(J2) =  Derivative(S.x, S.x) + Derivative(S.y, S.y) + Derivative(S.z, S.z)
>>
>>
> Is there a misunderstanding somewhere on my part or was sympy.vector not 
> designed for this kind of purposes?
>
> Right now I am planning on writing my own set of classes and method to 
> handle these vectorial expressions, but before I do so I would like to be 
> sure that I haven't misunderstood the issue.
>
> Thank you very much for reading through,
> Best regards,
> Alexis Prel
>

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/f9e246e0-48b8-4c82-8103-b3c40c4c7d00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to