New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Reconstruction constructor in CoordSys3D #13056
Changes from 21 commits
1cf0d8e
bc16490
6cb3a2e
bc6d63d
b227693
165b98c
d08dc10
6925316
181c2a5
705fd5c
e4a29c7
a1628b8
74a491c
ad3b703
00942fb
2fe8fc7
30fdac9
198501b
ef8537b
42783d4
8a517c3
0219eab
ee3226e
8aef7e4
78e9bd4
bebff57
a6fc5bd
c242261
063ab1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,10 @@ def test_coordinate_vars(): | |
""" | ||
A = CoordSys3D('A') | ||
# Note that the name given on the lhs is different from A.x._name | ||
assert BaseScalar('A.x', 0, A, 'A_x', r'\mathbf{{x}_{A}}') == A.x | ||
assert BaseScalar('A.y', 1, A, 'A_y', r'\mathbf{{y}_{A}}') == A.y | ||
assert BaseScalar('A.z', 2, A, 'A_z', r'\mathbf{{z}_{A}}') == A.z | ||
assert BaseScalar('A.x', 0, A, 'A_x', r'\mathbf{{x}_{A}}').__hash__() == A.x.__hash__() | ||
assert BaseScalar(0, A, 'A_x', r'\mathbf{{x}_{A}}') == A.x | ||
assert BaseScalar(1, A, 'A_y', r'\mathbf{{y}_{A}}') == A.y | ||
assert BaseScalar(2, A, 'A_z', r'\mathbf{{z}_{A}}') == A.z | ||
assert BaseScalar(0, A, 'A_x', r'\mathbf{{x}_{A}}').__hash__() == A.x.__hash__() | ||
assert isinstance(A.x, BaseScalar) and \ | ||
isinstance(A.y, BaseScalar) and \ | ||
isinstance(A.z, BaseScalar) | ||
|
@@ -299,84 +299,74 @@ def test_evalf(): | |
assert v.evalf(subs={a:1}) == v.subs(a, 1).evalf() | ||
|
||
|
||
def test_lame_coefficients(): | ||
a = CoordSys3D('a') | ||
a._set_lame_coefficient_mapping('spherical') | ||
assert a.lame_coefficients() == (1, a.x, sin(a.y)*a.x) | ||
a = CoordSys3D('a') | ||
assert a.lame_coefficients() == (1, 1, 1) | ||
a = CoordSys3D('a') | ||
a._set_lame_coefficient_mapping('cartesian') | ||
assert a.lame_coefficients() == (1, 1, 1) | ||
a = CoordSys3D('a') | ||
a._set_lame_coefficient_mapping('cylindrical') | ||
assert a.lame_coefficients() == (1, a.y, 1) | ||
|
||
|
||
def test_transformation_equations(): | ||
from sympy import symbols | ||
|
||
x, y, z = symbols('x y z') | ||
a = CoordSys3D('a') | ||
#r, theta, phi = symbols("r theta phi") | ||
# Str | ||
a._connect_to_standard_cartesian('spherical') | ||
assert a._transformation_equations() == (a.x * sin(a.y) * cos(a.z), | ||
a.x * sin(a.y) * sin(a.z), | ||
a.x * cos(a.y)) | ||
assert a.lame_coefficients() == (1, a.x, a.x * sin(a.y)) | ||
assert a._inverse_transformation_equations() == (sqrt(a.x**2 + a.y**2 +a.z**2), | ||
acos((a.z) / sqrt(a.x**2 + a.y**2 + a.z**2)), | ||
atan2(a.y, a.x)) | ||
a._connect_to_standard_cartesian('cylindrical') | ||
assert a._transformation_equations() == (a.x * cos(a.y), a.x * sin(a.y), a.z) | ||
assert a.lame_coefficients() == (1, a.y, 1) | ||
assert a._inverse_transformation_equations() == (sqrt(a.x**2 + a.y**2), | ||
atan2(a.y, a.x), a.z) | ||
a._connect_to_standard_cartesian('cartesian') | ||
assert a._transformation_equations() == (a.x, a.y, a.z) | ||
a = CoordSys3D('a', transformation='spherical', | ||
variable_names=["r", "theta", "phi"]) | ||
r, theta, phi = a.base_scalars() | ||
|
||
assert r == a.r | ||
assert theta == a.theta | ||
assert phi == a.phi | ||
|
||
raises(AttributeError, lambda: a.x) | ||
raises(AttributeError, lambda: a.y) | ||
raises(AttributeError, lambda: a.z) | ||
|
||
assert a.transformation_to_parent() == ( | ||
r*sin(theta)*cos(phi), | ||
r*sin(theta)*sin(phi), | ||
r*cos(theta) | ||
) | ||
assert a.lame_coefficients() == (1, r, r*sin(theta)) | ||
assert a.transformation_from_parent_function()(x, y, z) == ( | ||
sqrt(x ** 2 + y ** 2 + z ** 2), | ||
acos((z) / sqrt(x**2 + y**2 + z**2)), | ||
atan2(y, x) | ||
) | ||
a = CoordSys3D('a', transformation='cylindrical', | ||
variable_names=["r", "theta", "z"]) | ||
r, theta, z = a.base_scalars() | ||
assert a.transformation_to_parent() == ( | ||
r*cos(theta), | ||
r*sin(theta), | ||
z | ||
) | ||
assert a.lame_coefficients() == (1, a.theta, 1) | ||
assert a.transformation_from_parent_function()(x, y, z) == (sqrt(x**2 + y**2), | ||
atan2(y, x), z) | ||
a = CoordSys3D('a', transformation='cartesian') | ||
assert a.transformation_to_parent() == (a.x, a.y, a.z) | ||
assert a.lame_coefficients() == (1, 1, 1) | ||
assert a._inverse_transformation_equations() == (a.x, a.y, a.z) | ||
assert a.transformation_from_parent_function()(x, y, z) == (x, y, z) | ||
# Variables and expressions | ||
a._connect_to_standard_cartesian(((x, y, z), (x, y, z))) | ||
assert a._transformation_equations() == (a.x, a.y, a.z) | ||
x, y, z = symbols('x y z') | ||
a = CoordSys3D('a', transformation=((x, y, z), (x, y, z))) | ||
a._calculate_inv_trans_equations() | ||
assert a.transformation_to_parent() == (a.x, a.y, a.z) | ||
assert a.lame_coefficients() == (1, 1, 1) | ||
assert a._inverse_transformation_equations() == (a.x, a.y, a.z) | ||
a._connect_to_standard_cartesian(((x, y, z), ((x * cos(y), x * sin(y), z))), inverse=False) | ||
assert a._transformation_equations() == (a.x * cos(a.y), a.x * sin(a.y), a.z) | ||
assert a.transformation_from_parent_function()(x, y, z) == (x, y, z) | ||
a = CoordSys3D('a', transformation=(((x*cos(y), x*sin(y), z)), (x, y, z))) | ||
assert a.transformation_to_parent() == (a.x * cos(a.y), a.x * sin(a.y), a.z) | ||
assert simplify(a.lame_coefficients()) == (1, sqrt(a.x**2), 1) | ||
a._connect_to_standard_cartesian(((x, y, z), (x * sin(y) * cos(z), x * sin(y) * sin(z), x * cos(y))), inverse=False) | ||
assert a._transformation_equations() == (a.x * sin(a.y) * cos(a.z), | ||
a.x * sin(a.y) * sin(a.z), | ||
a.x * cos(a.y)) | ||
assert simplify(a.lame_coefficients()) == (1, sqrt(a.x**2), sqrt(sin(a.y)**2*a.x**2)) | ||
# Equations | ||
a._connect_to_standard_cartesian((a.x*sin(a.y)*cos(a.z), a.x*sin(a.y)*sin(a.z), a.x*cos(a.y)), inverse=False) | ||
assert a._transformation_equations() == (a.x * sin(a.y) * cos(a.z), | ||
a.x * sin(a.y) * sin(a.z), | ||
a.x * cos(a.y)) | ||
assert simplify(a.lame_coefficients()) == (1, sqrt(a.x**2), sqrt(sin(a.y)**2*a.x**2)) | ||
a._connect_to_standard_cartesian((a.x, a.y, a.z)) | ||
assert a._transformation_equations() == (a.x, a.y, a.z) | ||
assert simplify(a.lame_coefficients()) == (1, 1, 1) | ||
assert a._inverse_transformation_equations() == (a.x, a.y, a.z) | ||
a._connect_to_standard_cartesian((a.x * cos(a.y), a.x * sin(a.y), a.z), inverse=False) | ||
assert a._transformation_equations() == (a.x * cos(a.y), a.x * sin(a.y), a.z) | ||
assert simplify(a.lame_coefficients()) == (1, sqrt(a.x**2), 1) | ||
|
||
raises(ValueError, lambda: a._connect_to_standard_cartesian((x, y, z))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can test invalid parameters to the constructor |
||
|
||
|
||
def test_check_orthogonality(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why has this test disappeared? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must did it earlier, but I shouldn't. I will do it |
||
a = CoordSys3D('a') | ||
a._connect_to_standard_cartesian((a.x*sin(a.y)*cos(a.z), a.x*sin(a.y)*sin(a.z), a.x*cos(a.y)), inverse=False) | ||
assert a._check_orthogonality() is True | ||
a._connect_to_standard_cartesian((a.x * cos(a.y), a.x * sin(a.y), a.z)) | ||
assert a._check_orthogonality() is True | ||
a._connect_to_standard_cartesian((cosh(a.x)*cos(a.y), sinh(a.x)*sin(a.y), a.z), inverse=False) | ||
assert a._check_orthogonality() is True | ||
x, y, z = symbols('x y z') | ||
u,v = symbols('u, v') | ||
a = CoordSys3D('a', transformation=((x*sin(y)*cos(z), x*sin(y)*sin(z), x*cos(y)), (x, y, z))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't the tuple That's why I suggest to simply use: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add also support for |
||
assert a._check_orthogonality(a._transformation) is True | ||
a = CoordSys3D('a', transformation=((x * cos(y), x * sin(y), z), (x, y, z))) | ||
assert a._check_orthogonality(a._transformation) is True | ||
a = CoordSys3D('a', transformation=((cosh(u) * cos(v), sinh(u) * sin(v), z), (u, v, z))) | ||
assert a._check_orthogonality(a._transformation) is True | ||
|
||
raises(ValueError, lambda: a._connect_to_standard_cartesian((a.x, a.x, a.z))) | ||
raises(ValueError, lambda: a._connect_to_standard_cartesian( | ||
(a.x*sin(a.y / 2)*cos(a.z), a.x*sin(a.y)*sin(a.z), a.x*cos(a.y)), inverse=False)) | ||
raises(ValueError, lambda: CoordSys3D('a', transformation=((x, x, z), (x, y, z)))) | ||
raises(ValueError, lambda: CoordSys3D('a', transformation=( | ||
(x*sin(y/2)*cos(z), x*sin(y)*sin(z), x*cos(y)), (x, y, z)))) | ||
|
||
|
||
def test_coordsys3d(): | ||
|
@@ -389,27 +379,30 @@ def test_rotation_trans_equations(): | |
a = CoordSys3D('a') | ||
from sympy import symbols | ||
q0 = symbols('q0') | ||
assert a._rotation_trans_equations(a._parent_rotation_matrix) == (a.x, a.y, a.z) | ||
assert a._rotation_trans_equations(a._inverse_rotation_matrix()) == (a.x, a.y, a.z) | ||
assert a._rotation_trans_equations(a._parent_rotation_matrix, a.base_scalars()) == (a.x, a.y, a.z) | ||
assert a._rotation_trans_equations(a._inverse_rotation_matrix(), a.base_scalars()) == (a.x, a.y, a.z) | ||
b = a.orient_new_axis('b', 0, -a.k) | ||
assert b._rotation_trans_equations(b._parent_rotation_matrix) == (b.x, b.y, b.z) | ||
assert b._rotation_trans_equations(b._inverse_rotation_matrix()) == (b.x, b.y, b.z) | ||
assert b._rotation_trans_equations(b._parent_rotation_matrix, b.base_scalars()) == (b.x, b.y, b.z) | ||
assert b._rotation_trans_equations(b._inverse_rotation_matrix(), b.base_scalars()) == (b.x, b.y, b.z) | ||
c = a.orient_new_axis('c', q0, -a.k) | ||
assert c._rotation_trans_equations(c._parent_rotation_matrix) == \ | ||
assert c._rotation_trans_equations(c._parent_rotation_matrix, c.base_scalars()) == \ | ||
(-sin(q0) * c.y + cos(q0) * c.x, sin(q0) * c.x + cos(q0) * c.y, c.z) | ||
assert c._rotation_trans_equations(c._inverse_rotation_matrix()) == \ | ||
assert c._rotation_trans_equations(c._inverse_rotation_matrix(), c.base_scalars()) == \ | ||
(sin(q0) * c.y + cos(q0) * c.x, -sin(q0) * c.x + cos(q0) * c.y, c.z) | ||
|
||
|
||
def test_translation_trans_equations(): | ||
from sympy import symbols | ||
q0 = symbols('q0') | ||
a = CoordSys3D('a') | ||
assert a._translation_trans_equations() == (a.x, a.y, a.z) | ||
assert a._translation_trans_equations(a, a._origin, a.base_scalars()) == (a.x, a.y, a.z) | ||
b = a.locate_new('b', None) | ||
assert b._translation_trans_equations() == (b.x, b.y, b.z) | ||
assert b._translation_trans_equations(inverse=True) == (b.x, b.y, b.z) | ||
assert b._translation_trans_equations(a, b._origin, b.base_scalars()) == (b.x, b.y, b.z) | ||
assert b._translation_trans_equations(a, b._origin, b.base_scalars(), inverse=True) == (b.x, b.y, b.z) | ||
c = a.locate_new('c', (a.i + a.j + a.k)) | ||
assert c._translation_trans_equations() == (c.x + 1, c.y + 1, c.z + 1) | ||
assert c._translation_trans_equations(a, c._origin, c.base_scalars()) ==\ | ||
(c.x + 1, c.y + 1, c.z + 1) | ||
d = a.locate_new('d', (a.i + a.j + Vector.zero)) | ||
assert d._translation_trans_equations() == (d.x + 1, d.y + 1, d.z) | ||
assert d._translation_trans_equations(inverse=True) == (d.x - 1, d.y - 1, d.z) | ||
assert d._translation_trans_equations(a, d._origin, d.base_scalars()) ==\ | ||
(d.x + 1, d.y + 1, d.z) | ||
assert d._translation_trans_equations(a, d._origin, d.base_scalars(), inverse=True) ==\ | ||
(d.x - 1, d.y - 1, d.z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the block from here on still missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not support now these type of
transformation
.Here we mainly tested
_connect_to_standard_cartesian
which now is removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass a lambda to
CoordSys3D
constructor. You added support for this tuples.