aboutsummaryrefslogtreecommitdiff
path: root/src/patch/coords.hh
blob: b34b257bacfcefa07b6370188d94f2deaf0adfa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// coords.hh -- coordinate systems and conversions
// $Id$
//
// local_coords - conversions between various local coordinate systems
// global_coords - conversions between global and local coordinates
//

//
// prerequisites:
//    "jt/util++.hh"
//    fp.hh
//

//******************************************************************************

//
// We use the following terminology for coordinates:
//	{a,b,c} == any one of (a,b,c) == a | b | c
//	((a,b,c)) == any two of (a,b,c) == (a,b) | (a,c) | (b,c)
//	(r,(a,b,c)) == r and any two of (a,b,c) == (r,a,b) | (r,a,c) | (r,b,c)
//

//
// We use the following coordinates and coordinate systems:
//	global_(x,y,z)	global Cartesian x,y,z coordinates
//			(these are the coordinates Cactus gives us)
//	(x,y,z)		local Cartesian x,y,z coordinates relative to a
//			local origin point (stored in this object);
//			This origin should be chosen to be somewhere
//			at least vaguely in the "middle" of our
//			apparent horizon
//	(r,theta,phi)	polar spherical coordinates about the local
//			origin point
//	(r,(mu,nu,phi))	patch coordinates about the local origin point
//		mu	arctan(y/z) = rotation about local x axis
//		nu	arctan(x/z) = rotation about local y axis
//		phi	arctan(y/x) = rotation about local z axis
//				    = usual polar spherical phi
//	(rho,sigma)	generic patch angular coordinates, these will
//			be whichever two of (mu,nu,phi) are nonsingular
//			throughout the patch
//	tau		the third member of (mu,nu,phi) (the one which
//			is neither rho nor sigma)
//

//*****************************************************************************

//
// The various  local_coords  functions provide conversions between
// different local coordinate systems.
namespace local_coords
	  {
//
// Bugs:
//	These coordinate-conversion functions aren't optimally efficient:
//	they do lots of could-be-optimized away arithmetic and trig calls.
//	But in practice this doesn't matter, since we don't call these
//	functions inside inner loops.  (We cache their values at grid
//	points.)
//

// ((mu,nu,phi)) --> the 3rd
fp phi_of_mu_nu(fp mu, fp nu );
fp nu_of_mu_phi(fp mu, fp phi);
fp mu_of_nu_phi(fp nu, fp phi);

// (r,(mu,nu,phi)) <--> (x,y,z)
// ... on the (local) unit sphere, i.e. r == 1.0
void xyz_of_mu_nu (fp mu, fp nu ,   fp &x, fp &y, fp &z);
void xyz_of_mu_phi(fp mu, fp phi,   fp &x, fp &y, fp &z);
void xyz_of_nu_phi(fp nu, fp phi,   fp &x, fp &y, fp &z);
void  mu_nu_of_xyz(fp x, fp y, fp z,   fp &mu, fp &nu );
void mu_phi_of_xyz(fp x, fp y, fp z,   fp &mu, fp &phi);
void nu_phi_of_xyz(fp x, fp y, fp z,   fp &nu, fp &phi);
// ... with an arbitrary r coordinate
void xyz_of_r_mu_nu (fp r, fp mu, fp nu ,   fp &x, fp &y, fp &z);
void xyz_of_r_mu_phi(fp r, fp mu, fp phi,   fp &x, fp &y, fp &z);
void xyz_of_r_nu_phi(fp r, fp nu, fp phi,   fp &x, fp &y, fp &z);
void  r_mu_nu_of_xyz(fp x, fp y, fp z,   fp &r, fp &mu, fp &nu );
void r_mu_phi_of_xyz(fp x, fp y, fp z,   fp &r, fp &mu, fp &phi);
void r_nu_phi_of_xyz(fp x, fp y, fp z,   fp &r, fp &nu, fp &phi);

// usual polar spherical (r,theta,phi) <--> (x,y,z)
// ... on the (local) unit sphere, i.e. r == 1.0
void xyz_of_theta_phi(fp theta, fp phi,   fp &x, fp &y, fp &z);
void theta_phi_of_xyz(fp x, fp y, fp z,   fp &theta, fp &phi);
// ... with an arbitrary r coordinate
void xyz_of_r_theta_phi(fp r, fp theta, fp phi,   fp &x, fp &y, fp &z);
void r_theta_phi_of_xyz(fp x, fp y, fp z,   fp &r, fp &theta, fp &phi);

// ((mu,nu,phi)) <--> usual polar spherical (theta,phi)
// ... note phi is the same coordinate in both systems
void theta_phi_of_mu_nu (fp mu, fp nu ,   fp &ps_theta, fp &ps_phi);
void theta_phi_of_mu_phi(fp mu, fp phi,   fp &ps_theta, fp &ps_phi);
void theta_phi_of_nu_phi(fp nu, fp phi,   fp &ps_theta, fp &ps_phi);
void  mu_nu_of_theta_phi(fp ps_theta, fp ps_phi,   fp &mu, fp &nu );
void mu_phi_of_theta_phi(fp ps_theta, fp ps_phi,   fp &mu, fp &phi);
void nu_phi_of_theta_phi(fp ps_theta, fp ps_phi,   fp &nu, fp &phi);
	  };

//******************************************************************************

//
// This class stores the origin point of our local coordinates, and
// provides conversions between local and global coordinates.
//
class	global_coords
	{
public:
	// global (x,y,z) --> local (x,y,z)
	fp local_x_of_global_x(fp global_x) const
		{ return global_x - origin_x_; }
	fp local_y_of_global_y(fp global_y) const
		{ return global_y - origin_y_; }
	fp local_z_of_global_z(fp global_z) const
		{ return global_z - origin_z_; }

	// local (x,y,z) --> global (x,y,z)
	fp global_x_of_local_x(fp local_x) const
		{ return origin_x_ + local_x; }
	fp global_y_of_local_y(fp local_y) const
		{ return origin_y_ + local_y; }
	fp global_z_of_local_z(fp local_z) const
		{ return origin_z_ + local_z; }

	// get global (x,y,z) coordinates of local origin point
	fp origin_x() const { return origin_x_; }
	fp origin_y() const { return origin_y_; }
	fp origin_z() const { return origin_z_; }

	// ***** constructor, destructor *****
	// constructor: specify global (x,y,z) coordinates of local origin point
	global_coords(fp origin_x_in, fp origin_y_in, fp origin_z_in)
		: origin_x_(origin_x_in),
		  origin_y_(origin_y_in),
		  origin_z_(origin_z_in)
		{ }
	// destructor: compiler-generated no-op is ok

	// ***** copy constructor, assignment operator *****
private:
	// we forbid copying and passing by value
	// by declaring the copy constructor and assignment operator
	// private, but never defining them
	global_coords(const global_coords &rhs);
	global_coords& operator=(const global_coords &rhs);

	// ***** member variables *****
private:
	// global (x,y,z) coordinates of local origin point
	fp origin_x_, origin_y_, origin_z_;
	};