import sympy

import os, sys

"""
Explanation: Electromagnetism
cf. Robert G. Jahn. Physics of Electric Propulsion (Dover Books on Physics)  Dover Publications.  May 26, 2006
End of explanation
"""


currentdir = os.getcwd(); currentdir

sys.path.append(currentdir)
sys.path.append('/home/topolo/PropD/Propulsion') # you are going to type in manually the parent directory of the 
# current directory, i.e. the directory "above" the current directory, in absolute path form

"""
Explanation: Get the current directory:
End of explanation
"""


import Physique

from Physique import FundConst
g_0pd = FundConst[ FundConst["Quantity"].str.contains("gravity") ]
g_0pd

g_0pd.Value.get_values()

"""
Explanation: Get the physical constants and unit conversions you need straight from NIST
End of explanation
"""


epsilon_0pd = FundConst[ FundConst['Quantity'].str.contains('electric constant')]
epsilon_0pd

1./(4. * sympy.pi.n() * epsilon_0pd.Value)


from Physique import conv as convDF
convDF.columns

convDF[convDF['to'].str.contains("coulomb ")]
esu_to_Cpd = convDF[convDF['Toconvertfrom'].str.contains("statcoulomb")]
esu_to_Cpd

convDF[convDF['Toconvertfrom'].str.contains("dyne ")]
dyne_to_Npd = convDF.loc[137,:]
dyne_to_Npd

convDF[convDF['Toconvertfrom'].str.contains("farad")]

"""
Explanation: electric constant, electric (vacuum) permittivity $\epsilon_0$
End of explanation
"""


from sympy import symbols, sin, cos, pi, Function
from sympy.diffgeom import Differential, Manifold, Patch, CoordSystem, WedgeProduct
t, r, phi, z = symbols('t, r, phi, z')
M = Manifold('M',4)
Mchart = Patch('P',M)
Cart = CoordSystem('Cart',Mchart)
cylin = CoordSystem('cylin',Mchart)

cylin.connect_to(Cart,[t,r,phi,z],[t,r*cos(phi),r*sin(phi),z])
cylin.jacobian(Cart,[t,r,phi,z])

"""
Explanation: Implementation, using Python sympy, of Electromagnetism in terms of differential geometry
The (sympy documentation for the differential geometry module)[http://docs.sympy.org/dev/modules/diffgeom.html] is poor: there wasn't any explanation that connects that mathematics and physics to the commands - this could be attributed to the medium, in that it's difficult to display LaTeX with the code, but with jupyter notebooks, this could be alleviated.
End of explanation
"""


E_1 = Function('E_1'); E_2 = Function('E_2'); E_3 = Function('E_3')
E_1Cart = E_1(*Cart.coord_functions()); E_2Cart = E_2(*Cart.coord_functions()); E_3Cart = E_3(*Cart.coord_functions())
EformCart = E_1Cart*Cart.base_oneforms()[1]+E_2Cart*Cart.base_oneforms()[2]+E_3Cart*Cart.base_oneforms()[3]

"""
Explanation: Define the Electric Field 1-form.
End of explanation
"""


B_12 = Function('B_12'); B_23 = Function('B_23'); B_31 = Function('B_31')
B_12Cart = B_12(*Cart.coord_functions()); B_23Cart = B_23(*Cart.coord_functions()); 
B_31Cart = B_31(*Cart.coord_functions());

BformCart = B_12Cart*WedgeProduct(Cart.base_oneform(1), Cart.base_oneform(2)) + B_23Cart*WedgeProduct(Cart.base_oneform(2), Cart.base_oneform(3)) + B_31Cart*WedgeProduct(Cart.base_oneform(3), Cart.base_oneform(1)) 

BformCart

F2formCart = BformCart + WedgeProduct(EformCart,Cart.base_oneform(0)) 

# dir(Differential(F2formCart))

sympy.sin( sympy.pi/4) == sympy.cos(sympy.pi/4)

"""
Explanation: Define the magnetic field 2-form.
End of explanation
"""


