aboutsummaryrefslogtreecommitdiff
path: root/src/patch/patch.cc
blob: d67569a66c789f8e2b894632fa6bd95b2bdda76f (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// patch.cc -- describes a coordinate/grid patch
// $Id$

//
// patch::patch
// patch::~patch
// z_patch::z_patch
// x_patch::x_patch
// y_patch::y_patch
//
// patch::setup_mirror_sym_ghost_zone
// patch::setup_periodic_BC_ghost_zone
// patch::setup_interpatch_ghost_zone
// patch::setup_other_patch_frontier
// patch::setup_patch_frontier
// patch::border_on_edge
//

#include <stdio.h>
#include <assert.h>
#include <math.h>

#include "jt/stdc.h"
#include "jt/util.hh"

#include "policy.hh"
#include "fp.hh"
#include "misc.hh"
#include "coords.hh"
#include "gfa.hh"
#include "gridfn.hh"
#include "grid.hh"
#include "fd_grid.hh"
#include "patch.hh"
#include "patch_bndry.hh"

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

//
// This function constructs a  patch  object.
//
patch::patch(patch_system &my_patch_system_in, int patch_number_in,
	     const char *name_in, bool is_plus_in, char ctype_in,
	     local_coords::coords_set coords_set_rho_in,
				      coords_set_sigma_in,
				      coords_set_tau_in,
	     const grid_arrays::array_pars& grid_array_pars_in,
	     const grid::grid_pars& grid_pars_in,
	     int N_gridfns_in)

	: fd_grid(grid_array_pars_in, gride_pars_in, N_gridfns_in),

	  my_patch_system_(my_patch_system_in), patch_number_(patch_number_in),
	  name_(name_in), is_plus_(is_plus_in), ctype_(ctype_in),

	  coords_set_rho_  (coords_set_rho_in  ),
	  coords_set_sigma_(coords_set_sigma_in),
	  coords_set_tau_  (coords_set_tau_in  ),

	  min_rho_patch_edge_  (*new patch_edge(*this, side_min, side_rho  )),
	  max_rho_patch_edge_  (*new patch_edge(*this, side_max, side_rho  )),
	  min_sigma_patch_edge_(*new patch_edge(*this, side_min, side_sigma)),
	  max_sigma_patch_edge_(*new patch_edge(*this, side_max, side_sigma)),

	  min_rho_patch_frontier_(NULL),
	  max_rho_patch_frontier_(NULL),
	  min_sigma_patch_frontier_(NULL),
	  max_sigma_patch_frontier_(NULL),

	  min_rho_ghost_zone_(NULL),
	  max_rho_ghost_zone_(NULL),
	  min_sigma_ghost_zone_(NULL),
	  max_sigma_ghost_zone_(NULL) // no comma

{ }

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

//
// This function destroys a  patch  object.
//
patch::~patch()
{
// no need to check for null pointers, since  delete NULL  is a silent no-op

delete max_sigma_ghost_zone_;
delete min_sigma_ghost_zone_;
delete max_rho_ghost_zone_;
delete min_rho_ghost_zone_;

delete max_sigma_patch_frontier_;
delete min_sigma_patch_frontier_;
delete max_rho_patch_frontier_;
delete min_rho_patch_frontier_;

delete max_sigma_patch_edge_;
delete min_sigma_patch_edge_;
delete max_rho_patch_edge_;
delete min_rho_patch_edge_;
}

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

//
// This function constructs a  z_patch  object.
//
z_patch::z_patch(patch_system &my_patch_system_in, int patch_number_in,
		 const char *name_in, bool is_plus_in,
		 const grid_arrays::array_pars& grid_array_pars_in,
		 const grid::grid_pars& grid_pars_in,
		 int N_gridfns_in)
	: patch(my_patch_system_in, patch_number_in,
		name_in, is_plus_in, 'z',
		local_coords::set_mu, local_coords::set_nu,
		local_coords::set_phi,
		grid_array_pars_in, pars_in, N_gridfns_in)
{ }

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

//
// This function constructs an  x_patch  object.
//
x_patch::x_patch(patch_system &my_patch_system_in, int patch_number_in,
		 const char *name_in, bool is_plus_in,
		 const grid_arrays::array_pars& grid_array_pars_in,
		 const grid::grid_pars& grid_pars_in,
		 int N_gridfns_in)
	: patch(my_patch_system_in, patch_number_in,
		name_in, is_plus_in, 'x',
		local_coords::set_nu, local_coords::set_phi,
		local_coords::set_mu,
		grid_array_pars_in, pars_in, N_gridfns_in)

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

//
// This function constructs a  y_patch  object.
//
y_patch::y_patch(patch_system &my_patch_system_in, int patch_number_in,
		 const char *name_in, bool is_plus_in,
		 const grid_arrays::array_pars& grid_array_pars_in,
		 const grid::grid_pars& grid_pars_in,
		 int N_gridfns_in)
	: patch(my_patch_system_in, patch_number_in,
		name_in, is_plus_in, 'y',
		local_coords::set_mu, local_coords::set_phi,
		local_coords::set_nu,
		grid_array_pars_in, pars_in, N_gridfns_in)

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

//
// This function sets up a mirror-symmetry angular border of this patch.
//
void patch::setup_mirror_sym_ghost_zone(const patch_edge& edge_in)
{
// make sure we belong to the right patch
assert(& edge_in.this_patch() == this);

symmetry_ghost_zone *temp = new symmetry_ghost_zone(edge_in);
symmetry_ghost_zones_array_[N_symmetry_ghost_zones_++] = temp;

// assignment converts to ptr to base class  ghost_zone::
// FIXME: the decode here is ugly; an array would be cleaner...
if (edge_in.edge_is_min())
   then if (edge_in.edge_is_rho())
	   then min_rho_ghost_zone_   = temp;
	   else min_sigma_ghost_zone_ = temp;
   else if (edge_in.edge_is_rho())
	   then max_rho_ghost_zone_   = temp;
	   else max_sigma_ghost_zone_ = temp;
}

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

//
// This function sets up a periodic-BCs angular border of this patch.
//
void patch::setup_periodic_BC_ghost_zone
	(const patch_edge& this_edge_in, const patch_edge& symmetry_edge_in,
	 int this_edge_sample_ipar, int symmetry_edge_sample_ipar,
	 bool ipar_map_sign)		// one of cpm_map::{plus,minus}_map
{
// make sure we belong to the right patch
assert(& this_edge_in.this_patch() == this);

symmetry_ghost_zone *temp
	= new symmetry_ghost_zone
		      (this_edge_in, symmetry_edge_in,
		       this_edge_sample_ipar, symmetry_edge_sample_ipar,
		       ipar_map_sign);
symmetry_ghost_zones_array_[N_symmetry_ghost_zones_++] = temp;

// assignment converts to ptr to base class  ghost_zone::
// FIXME: the decode here is ugly; an array would be cleaner...
if (this_edge_in.edge_is_min())
   then if (this_edge_in.edge_is_rho())
	   then min_rho_ghost_zone_   = temp;
	   else min_sigma_ghost_zone_ = temp;
   else if (this_edge_in.edge_is_rho())
	   then max_rho_ghost_zone_   = temp;
	   else max_sigma_ghost_zone_ = temp;
}

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

//
// This function sets up an interpatch angular border of this patch.
//
void patch::setup_interpatch_ghost_zone(const patch_edge& this_edge_in,
				    const patch_edge& other_edge_in)
{
// make sure we belong to the right patch
assert(& this_edge_in.this_patch() == this);

interpatch_ghost_zone *temp
	= new interpatch_ghost_zone(this_edge_in, other_edge_in);
interpatch_ghost_zones_array_[N_interpatch_ghost_zones_++] = temp;

// assignment converts to ptr to base class  ghost_zone::
// FIXME: the decode here is ugly; an array would be cleaner...
if (this_edge_in.edge_is_min())
   then if (this_edge_in.edge_is_rho())
	   then min_rho_ghost_zone_ = temp;
	   else min_sigma_ghost_zone_ = temp;
   else if (this_edge_in.edge_is_rho())
	   then max_rho_ghost_zone_ = temp;
	   else max_sigma_ghost_zone_ = temp;
}

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

//
// This function sets an angular frontier of *another* patch from
// which one of this patch's interpatch borders needs to interpolate
// data.
//
void patch::setup_other_patch_frontier
	(const patch_edge& this_edge_in,
	 const patch_edge& other_edge_in,
	 const interpolator_pars& interpolator_pars_in)
{
// make sure we belong to the right patch
assert(& this_edge_in.this_patch() == this);

const patch_frontier& temp
	= other_edge_in
	  .nonconst_this_patch()
	  .setup_patch_frontier(other_edge_in, interpolator_pars_in);

border_on_edge(this_edge_in)
.treat_me_as_nonconst_interpatch_ghost_zone()
.set_other_patch_frontier(temp);
}

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

//
// This function sets up an angular frontier of this patch.
//
const patch_frontier& patch::setup_patch_frontier
	(const patch_edge& edge_in,
	 const interpolator_pars& interpolator_pars_in)
{
// make sure we belong to the right patch
assert(& edge_in.this_patch() == this);

const patch_frontier *temp
	= new patch_frontier(edge_in, interpolator_pars_in);

// FIXME: the decode here is ugly; an array would be cleaner...
if (edge_in.edge_is_min())
   then if (edge_in.edge_is_rho())
	   then min_rho_patch_frontier_ = temp;
	   else min_sigma_patch_frontier_ = temp;
   else if (edge_in.edge_is_rho())
	   then max_rho_patch_frontier_ = temp;
	   else max_sigma_patch_frontier_ = temp;

return *temp;
}

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

//
// This function returns the ghost_zone object on a specified edge
// of this patch.
//
const ghost_zone& patch::border_on_edge(const patch_edge& edge_in)
	const
{
return edge_in.edge_is_min()
       ? ( edge_in.edge_is_rho() ? min_rho_ghost_zone()
				 : min_sigma_ghost_zone() )
       : ( edge_in.edge_is_rho() ? max_rho_ghost_zone()
				 : max_sigma_ghost_zone() );
}