aboutsummaryrefslogtreecommitdiff
path: root/src/patch/patch_edge.hh
blob: 233b70bdf55e6c2df445d0854c83de20bc8a25da (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// patch_edge.hh -- perp/par geometry of a patch
// $Id$
//

//
// prerequisites:
//	<stdio.h>
//	<assert.h>
//	<math.h>
//	"jt/util++.hh"
//	"jt/array.hh"
//	"jt/linear_map.hh"
//	fp.hh
//	coords.hh
//	grid.hh
//	fd_grid.hh
//	patch.hh
//

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

//
// patch_edge - geometry of the {min,max}_{rho,sigma} edge of a patch
//
// Note that since  patch_edge  has only  const  member functions
// (and members!), a  patch_edge  object is effectively always  const .
// This means there's no harm in always declaring  patch_edge  objects
// to be  const .
//

class	patch_edge
	{
public:
	//
	// ***** meta-info *****
	//

	// meta-info about patch
	const patch& my_patch() const { return my_patch_; }
	patch& nonconst_my_patch() const	// ... safe only if original
						//     patch ref passed to
						//     ctor was non-const
		{ return const_cast<patch& >(my_patch_); }

	// meta-info about edge
	bool edge_is_rho() const { return edge_is_rho_; }
	bool edge_is_min() const { return edge_is_min_; }
	bool perp_is_rho() const { return edge_is_rho(); }
	bool par_is_rho() const { return ! edge_is_rho(); }

	// human-readable {min,max}_{rho,sigma} name (for debugging etc)
	const char *name() const
		{
		return edge_is_min()
		       ? (edge_is_rho() ? "min_rho" : "min_sigma")
		       : (edge_is_rho() ? "max_rho" : "max_sigma");
		}


	//
	// ***** adjacent edges *****
	//

	// meta-info about adjacent edges to our min/max par corners
	bool min_par_adjacent_edge_is_rho() const { return par_is_rho(); }
	bool max_par_adjacent_edge_is_rho() const { return par_is_rho(); }
	bool min_par_adjacent_edge_is_min() const { return true; }
	bool max_par_adjacent_edge_is_min() const { return false; }

	// get adjacent edges to our min/max par corners
	const patch_edge& min_par_adjacent_edge() const
		{
		return my_patch()
		       .minmax_ang_patch_edge(min_par_adjacent_edge_is_min(),
					      min_par_adjacent_edge_is_rho());
		}
	const patch_edge& max_par_adjacent_edge() const
		{
		return my_patch()
		       .minmax_ang_patch_edge(max_par_adjacent_edge_is_min(),
					      max_par_adjacent_edge_is_rho());
		}


	//
	// ***** coordinate maps *****
	//

	// coordinate maps perpendicular/parallel to the edge
	// ... range is that of the bordered grid
	const linear_map<fp>& perp_map() const
		{ return my_patch().ang_map(perp_is_rho()); }
	const linear_map<fp>& par_map() const
		{ return my_patch().ang_map(par_is_rho()); }

	// meta-info about perp/par coordinates
	// ... as (mu,nu,phi) tensor indices
	local_coords::coords_set coords_set_perp() const
		{
		return perp_is_rho() ? my_patch().coords_set_rho()
				     : my_patch().coords_set_sigma();
		}
	local_coords::coords_set coords_set_par() const
		{
		return par_is_rho() ? my_patch().coords_set_rho()
				    : my_patch().coords_set_sigma();
		}


	//
	// ***** coordinate conversions *****
	//

	// coordinate conversions based on border direction
	// ... (iperp,ipar) <--> (perp,par)
	fp perp_of_iperp(int iperp) const
		{ return my_patch().ang_of_iang(perp_is_rho(), iperp); }
	fp par_of_ipar(int ipar) const
		{ return my_patch().ang_of_iang(par_is_rho(), ipar); }
	fp fp_iperp_of_perp(fp perp) const
		{ return my_patch().fp_iang_of_ang(perp_is_rho(), perp); }
	fp fp_ipar_of_par(fp par) const
		{ return my_patch().fp_iang_of_ang(par_is_rho(), par); }
	int iperp_of_perp(fp perp, linear_map<fp>::noninteger_action
				   nia = linear_map<fp>::error)
		{ return my_patch().iang_of_ang(perp_is_rho(), perp, nia); }
	int ipar_of_par(fp par, linear_map<fp>::noninteger_action
				nia = linear_map<fp>::error)
		{ return my_patch().iang_of_ang(par_is_rho(), par, nia); }

	// ... (perp,par) --> (rho,sigma)
	int irho_of_iperp_ipar(int iperp, int ipar) const
		{ return perp_is_rho() ? iperp : ipar; }
	int isigma_of_iperp_ipar(int iperp, int ipar) const
		{ return perp_is_rho() ? ipar : iperp; }
	fp rho_of_perp_par(fp perp, fp par) const
		{ return perp_is_rho() ? perp : par; }
	fp sigma_of_perp_par(fp perp, fp par) const
		{ return perp_is_rho() ? par : perp; }
	// ... (rho,sigma) --> (perp,par)
	int iperp_of_irho_isigma(int irho, int isigma) const
		{ return perp_is_rho() ? irho : isigma; }
	int ipar_of_irho_isigma(int irho, int isigma) const
		{ return par_is_rho() ? irho : isigma; }
	fp perp_of_rho_sigma(fp rho, fp sigma) const
		{ return perp_is_rho() ? rho : sigma; }
	fp par_of_rho_sigma(fp rho, fp sigma) const
		{ return par_is_rho() ? rho : sigma; }

	// min/max perp of nominal grid on this edge
	fp grid_outer_perp() const
		{
		return my_patch()
		       .minmax_ang(edge_is_min(), edge_is_rho());
		}
	// ... converted to integer grid coordinate
	//     (will be either integer or half-integer)
	fp fp_grid_outer_iperp() const
		{ return fp_iperp_of_perp(grid_outer_perp()); }



	//
	// ***** min/max/size/outer coordinates of edge *****
	//

	// min/max/size ipar of the edge
	// (these are exteme limits for any iperp, a given
	//  frontier/border may have tighter and/or iperp-dependent limits)
	// ... not including corners
	int min_ipar_without_corners() const
		{ return my_patch().min_iang(par_is_rho()); }
	int max_ipar_without_corners() const
		{ return my_patch().max_iang(par_is_rho()); }
	int N_ipar_without_corners() const
		{ return my_patch().N_iang(par_is_rho()); }
	// ... including corners
	int min_ipar_with_corners() const
		{ return my_patch().bordered_min_iang(par_is_rho()); }
	int max_ipar_with_corners() const
		{ return my_patch().bordered_max_iang(par_is_rho()); }
	int N_ipar_with_corners() const
		{ return my_patch().bordered_N_iang(par_is_rho()); }
	// ... of the corners themselves
	int min_ipar_corner__min_ipar() const
		{ return min_ipar_with_corners(); }
	int min_ipar_corner__max_ipar() const
		{ return min_ipar_without_corners() - 1; }
	int max_ipar_corner__min_ipar() const
		{ return max_ipar_without_corners() + 1; }
	int max_ipar_corner__max_ipar() const
		{ return max_ipar_with_corners(); }

	// outer (farthest from patch center) iperp of nominal grid
	int nominal_grid_outer_iperp() const
		{
		return my_patch()
		       .minmax_iang(edge_is_min(), edge_is_rho());
		}


	//
	// ***** constructor, destructor *****
	//

	patch_edge(const patch& my_patch_in,
		   bool edge_is_min_in, bool edge_is_rho_in)
		: my_patch_(my_patch_in),
		  edge_is_min_(edge_is_min_in), edge_is_rho_(edge_is_rho_in)
		{ }

	// compiler-synthesized (no-op) destructor is fine

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

private:
	const patch& my_patch_;
	const bool edge_is_min_, edge_is_rho_;
	};