[WIP] Multiple Coordinate System #12020

Open
wants to merge 4 commits into
from
+784 −387

None yet

3 participants

Contributor

This PR is related to implementing multiple coordinate system in SymPy. So far I have implemented classes `CoordinateSystem` (Super class for remaining coordinate systems), `CartesianCoordinateSystem` and `SphericalCoordinateSystem` using Lamè parameters. Using Lamè parameters , other orthogonal coordinate systems(such as `CylindricalCoordinateSystem`, `ParabolicCoordinateSystem`) can be easily implemented.

Sample Program

```>>> from sympy import *
>>> from sympy.vector.coordsys import SphericalCoordinateSystem
>>> Sph = SphericalCoordinateSystem('Sph')
>>> e_r, e_theta, e_phi = Sph.base_vectors()
>>> r, theta, phi = Sph.base_scalars()
>>> s_delop = Sph.delop
>>> w = r*theta*phi * (e_r + e_theta + e_phi)
>>> pprint(((s_delop ^ w).doit()))
⎛2⋅Sph_phi⋅Sph_r⋅Sph_theta - Sph_phi⋅Sph_r⎞ Sph_e_phi + ⎛
⎜─────────────────────────────────────────⎟             ⎜sin(Sph_theta)⋅Sph_ph
⎝                  Sph_r                  ⎠             ⎜─────────────────────
⎜
⎝

2                               2                  2          ⎞ Sph_e_r
i⋅Sph_r  + cos(Sph_theta)⋅Sph_phi⋅Sph_r ⋅Sph_theta - Sph_r ⋅Sph_theta⎟
─────────────────────────────────────────────────────────────────────⎟
2                                   ⎟
sin(Sph_theta)⋅Sph_r                                    ⎠

+ ⎛-2⋅sin(Sph_theta)⋅Sph_phi⋅Sph_r⋅Sph_theta + Sph_r⋅Sph_theta⎞ Sph_e_theta
⎜───────────────────────────────────────────────────────────⎟
⎝                    sin(Sph_theta)⋅Sph_r                   ⎠

>>> w = r*e_r + theta*e_theta + phi*e_phi
>>> pprint((s_delop & w).doit())
sin(Sph_theta)⋅Sph_r + cos(Sph_theta)⋅Sph_r⋅Sph_theta                1
───────────────────────────────────────────────────── + 3 + ──────────────────
2                       sin(Sph_theta)⋅Sph
sin(Sph_theta)⋅Sph_r

──
_r

>>> pprint(s_delop(r*theta*phi).doit())
⎛  Sph_theta   ⎞ Sph_e_phi + (Sph_phi⋅Sph_theta) Sph_e_r + (Sph_phi) Sph_e_the
⎜──────────────⎟
⎝sin(Sph_theta)⎠

ta
```

The results in the above examples are correct and results can be verified here.

• The API remains same for `CartesianCoordinateSystem`.

Todo

• Update Documentation.
• Complete implementation of class `SphericalCoordinateSystem`.

I wanted to get as much feedback as possible from the commumity to improve my work and get `SphericalCoordinateSystem` implementation right before implementing remaining coordinate systems.

 parsoyaarihant `Implemented class SphericalCoordinateSystem using Lame Coeffecients` `2a7eb0e`
reviewed
 + Process can be slow for less common coordinate systems, use + built-in systems when you can. + + built-in : 'cartesian', 'spherical', 'cylindrical',
Member

It seems that this and the following lines are not rendered as expected. Apparently Sphinx does not know what should be done.

 parsoyaarihant `Added tests for SphericalCoordinateSystem` `07527c0`
Contributor
 @Upabjojr , @jbbskinny , ping.
Contributor
 @moorepants , @vasdommes , ping.
reviewed
 @@ -5,10 +5,10 @@ Essential Classes in sympy.vector (doctrings) CoordSysCartesian
Member

Should this title be changed, too?

Contributor

Yes, because `CoordSysCartesian` class is replaced by `CartesianCoordinateSystem`. I will change it in the next commit.

reviewed
 @@ -44,6 +54,7 @@ def __new__(cls, name, location=None, rotation_matrix=None, Used for simple str printing. """ + from sympy.abc import a, x, y, z
Member

These should probably be dummies instead of public symbols.

Member

Moreover, since these are used to denote angles etc. in some coordinate systems, more 'neutral' names could be better. For example, u, v, w instead of x, y, z.

Jan 10, 2017 edited Contributor

These should probably be dummies instead of public symbols.

I am not aware of the difference it would make. Can you specify any undesired consequences?

Member

It these names are used in the code calling this code, confusion may result. Dummies are unique symbols that are different from any other symbol, even those with the same name.

Contributor

Thanks, I have made the required changes.

reviewed
 + # Handling for different coordinate systems + coord_type_map = { + 'cartesian': [ + Lambda((x, y, z), (1, 1, 1)),
Member

Should this really be the constant map `(1, 1, 1)`?

Jan 10, 2017 edited Contributor

I am storing coordinate relations of other coordinates with respect to `CartesianCoordinateSystem` so coordinate relation of `Cartesian System` should be an identity map.

reviewed
 else: _check_strings('variable_names', vector_names) variable_names = list(variable_names) latex_scalars = [(r"\mathbf{{%s}_{%s}}" % (x, name)) for x in variable_names] pretty_scalars = [(name + '_' + x) for x in variable_names] - obj._x = BaseScalar(variable_names[0], 0, obj, + obj._e1 = BaseScalar(variable_names[0], 0, obj,
Member

`e1, e2, ...` etc. are generally used as base vector names. It would look better to use something else for coordinate scalars, e.g., `x1, x2, ...` (or `xi1, xi2, ...`).

reviewed
 + lame_lambda = _get_lame_lambda(system) + coord_sys_type = name + else: + raise TypeError("see the docs for proper useage")
Member

useage -> usage

Contributor

Thanks !

 parsoyaarihant `Made changes based on suggestions` ```replaced x, y, z with u, v, w * Changed names of base vectors from e1, e2, e3 to x1, x2, x3. * Fixed typo error``` `d1a066b`
reviewed
 @@ -54,8 +55,10 @@ def __new__(cls, name, location=None, rotation_matrix=None, Used for simple str printing. """ - from sympy.abc import a, x, y, z, u, v, w - + a = Dummy('a')
Member

It is also possible to define several dummies on the same line: `c, d = symbols('c,d', cls=Dummy)`.

reviewed
 + # Handling for different coordinate systems + coord_type_map = { + 'cartesian': [ + Lambda((u, v, w), (1, 1, 1)),
Member

Should this be the identity mapping: `Lambda((u, v, w), (u, v, w))`?

Contributor

I am storing coordinate relations of other coordinates with respect to `CartesianCoordinateSystem` so coordinate relation of `Cartesian System` should be an identity map.

Contributor
 That's the problem though. If your base system is Cartesian and you want to transform via matrices there is an inherent slowness to the operation because of Simplify(). My goal was to just have the common systems built-in (cylindrical, spherical, etc.). If the user wanted a general coordinate system then they would need to supply the Lamé coefficients and build it from scratch. I would dig deeper into the way the vector module was built first. The most base functionality is built around Cartesian. The only way to eliminate Simplify() from coordsys.py completely would be to rebuild using the general constructs of vector spaces rather than the narrowness of assuming Cartesian coordinates. There are to many rotations in vector analysis for Simplify() to keep up. Careful thought must be given to build this part Let's fuck! The system correctly. Thanks, Justin …
 parsoyaarihant `Changed public symbols to Dummy symbols` ```Previously, x, y, z variables were public defined. Which could lead to the confusion when the code is called. Hence the variables are changed to dummy variables.``` `0d26265`