aboutsummaryrefslogtreecommitdiff
path: root/src/patch/patch_system.cc
blob: ef62766f1d937028fcb11cced83f5dc83999f0a1 (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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
// patch_system.cc -- describes the (an) entire system of patches
// $Id$
//
// patch_system_info::patch_info::grid_array_pars
// patch_system_info::patch_info::grid_pars
//
// patch_system::patch_system
// patch_system::~patch_system
// patch_system::setup_full_sphere_patch_system
// patch_system::setup_hemisphere_patch_system
// patch_system::setup_quadrant_patch_system
// patch_system::setup_octant_patch_system
//
// patch_system::setup_adjacent_ghost_zones
// patch_system::setup_adjacent_patch_frontiers
// patch_system::assert_all_ghost_zones_fully_setup
//
// patch_system::N_patches_of_type
// patch_system::name_of_type
// patch_system::patch_number_of_name
// 

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

#include "jt/stdc.h"
#include "jt/util.hh"
#include "jt/array.hh"
#include "jt/cpm_map.hh"
#include "jt/linear_map.hh"
#include "jt/interpolate.hh"

using jtutil::error_exit;

#include "fp.hh"
#include "coords.hh"
#include "grid.hh"
#include "fd_grid.hh"
#include "patch.hh"
#include "patch_edge.hh"
#include "ghost_zone.hh"
#include "patch_frontier.hh"
#include "patch_system.hh"

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

//
// This function computes, and returns a reference to, a
// struct grid_arrays::grid_array_pars  from the info in a  struct patch_info .
//
// The result refers to an internal static buffer in this function; the
// usual caveats about lifetimes/overwriting apply.
//
namespace patch_system_info
	  {
const grid_arrays::grid_array_pars& patch_info::grid_array_pars
	(int N_ghost_points, int N_overlap_points, fp delta_drho_dsigma)
	const
{
static struct grid_arrays::grid_array_pars array_pars;

array_pars.min_irho = round<fp>::to_integer(min_drho/delta_drho_dsigma);
array_pars.max_irho
	= array_pars.min_irho
	  + round<fp>::to_integer((max_drho-min_drho) / delta_drho_dsigma);
array_pars.min_irho -= N_overlap_points;
array_pars.max_irho += N_overlap_points;

array_pars.min_isigma = round<fp>::to_integer(min_dsigma/delta_drho_dsigma);
array_pars.max_isigma
	= array_pars.min_isigma
	  + round<fp>::to_integer((max_dsigma-min_dsigma) / delta_drho_dsigma);
array_pars.min_isigma -= N_overlap_points;
array_pars.max_isigma += N_overlap_points;

array_pars.min_rho_N_ghost_points = N_ghost_points;
array_pars.max_rho_N_ghost_points = N_ghost_points;
array_pars.min_sigma_N_ghost_points = N_ghost_points;
array_pars.max_sigma_N_ghost_points = N_ghost_points;

return array_pars;
}
	  }

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

//
// This function computes, and returns a reference to, a
// struct grid::grid_pars  from the info in a  struct patch_info .
//
// The result refers to an internal static buffer in this function; the
// usual caveats about lifetimes/overwriting apply.
//
namespace patch_system_info
	  {
const grid::grid_pars& patch_info::grid_pars
	(int N_overlap_points, fp delta_drho_dsigma)
	const
{
const fp fp_N_overlap = fp(N_overlap_points);
static struct grid::grid_pars grid_pars_buffer;

grid_pars_buffer.  min_drho = min_drho - fp_N_overlap*delta_drho_dsigma;
grid_pars_buffer.delta_drho = delta_drho_dsigma;
grid_pars_buffer.  max_drho = max_drho + fp_N_overlap*delta_drho_dsigma;
grid_pars_buffer.  min_dsigma = min_dsigma - fp_N_overlap*delta_drho_dsigma;
grid_pars_buffer.delta_dsigma = delta_drho_dsigma;
grid_pars_buffer.  max_dsigma = max_dsigma + fp_N_overlap*delta_drho_dsigma;

return grid_pars_buffer;
}
	  }

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

//
// This function constructs a  patch_system  object.
//
patch_system::patch_system(fp origin_x_in, fp origin_y_in, fp origin_z_in,
			   enum patch_system_type type_in,
			   int N_ghost_points, int N_overlap_points,
			   fp delta_drho_dsigma,
			   int min_gfn_in, int max_gfn_in,
			   int interpolator_order)

	: global_coords_(origin_x_in, origin_y_in, origin_z_in),
	  type_(type_in),
	  N_patches_(N_patches_of_type(type_in))
{
all_patches_ = new array1d<patch *>(0, N_patches()-1);

switch	(type_in)
	{
case full_sphere_patch_system:
	setup_full_sphere_patch_system(N_ghost_points, N_overlap_points,
				       delta_drho_dsigma,
				       min_gfn_in, max_gfn_in,
				       interpolator_order);
	break;
case hemisphere_patch_system:
	setup_hemisphere_patch_system(N_ghost_points, N_overlap_points,
				      delta_drho_dsigma,
				      min_gfn_in, max_gfn_in,
				      interpolator_order);
	break;
case quadrant_patch_system:
	setup_quadrant_patch_system(N_ghost_points, N_overlap_points,
				    delta_drho_dsigma,
				    min_gfn_in, max_gfn_in,
				    interpolator_order);
	break;
case octant_patch_system:
	setup_octant_patch_system(N_ghost_points, N_overlap_points,
				  delta_drho_dsigma,
				  min_gfn_in, max_gfn_in,
				  interpolator_order);
	break;
default:
	error_exit(ERROR_EXIT,
"***** patch_system::patch_system(): bad type_in=(int)%d!\n"
,
		   int(type_in));				/*NOTREACHED*/
	}
}

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

//
// This function destroys a  patch_system  object.
//
patch_system::~patch_system()
{
	for (int pn = N_patches()-1 ; pn >= 0 ; --pn)
	{
	delete &ith_patch(pn);
	}

delete all_patches_;
}

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

//
// This function constructs and interlinks the patches for a
// full patch system.
//
void patch_system::setup_full_sphere_patch_system
	(int N_ghost_points, int N_overlap_points, fp delta_drho_dsigma,
	 int min_gfn_in, int max_gfn_in,
	 int interpolator_order)
{
using namespace patch_system_info::full_sphere_patch_system_info;

// create the patches
patch& pz = *new z_patch(*this, plus_z.patch_number,
			 "+z", patch::patch_is_plus,
			 plus_z.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& px = *new x_patch(*this, plus_x.patch_number,
			 "+x", patch::patch_is_plus,
			 plus_x.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& py = *new y_patch(*this, plus_y.patch_number,
			 "+y", patch::patch_is_plus,
			 plus_y.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& mx = *new x_patch(*this, minus_x.patch_number,
			 "-x", patch::patch_is_minus,
			 minus_x.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& my = *new y_patch(*this, minus_y.patch_number,
			 "-y", patch::patch_is_minus,
			 minus_y.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& mz = *new z_patch(*this, minus_z.patch_number,
			 "-z", patch::patch_is_minus,
			 minus_z.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);

// attach the patches to the patch system 
(*all_patches_)(plus_z.patch_number) = & pz;
(*all_patches_)(plus_x.patch_number) = & px;
(*all_patches_)(plus_y.patch_number) = & py;
(*all_patches_)(minus_x.patch_number) = & mx;
(*all_patches_)(minus_y.patch_number) = & my;
(*all_patches_)(minus_z.patch_number) = & mz;

// create the ghost zones
setup_adjacent_ghost_zones(pz, px, N_overlap_points);
setup_adjacent_ghost_zones(pz, py, N_overlap_points);
setup_adjacent_ghost_zones(pz, mx, N_overlap_points);
setup_adjacent_ghost_zones(pz, my, N_overlap_points);
setup_adjacent_ghost_zones(px, py, N_overlap_points);
setup_adjacent_ghost_zones(py, mx, N_overlap_points);
setup_adjacent_ghost_zones(mx, my, N_overlap_points);
setup_adjacent_ghost_zones(my, px, N_overlap_points);
setup_adjacent_ghost_zones(mz, px, N_overlap_points);
setup_adjacent_ghost_zones(mz, py, N_overlap_points);
setup_adjacent_ghost_zones(mz, mx, N_overlap_points);
setup_adjacent_ghost_zones(mz, my, N_overlap_points);

// create the patch frontiers
setup_adjacent_patch_frontiers(pz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, mx, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, my, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(px, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(py, mx, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mx, my, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(my, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, mx, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, my, N_overlap_points, interpolator_order);

assert_all_ghost_zones_fully_setup();
}

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

//
// This function constructs and interlinks the patches for a
// half patch system.
//
void patch_system::setup_hemisphere_patch_system
	(int N_ghost_points, int N_overlap_points, fp delta_drho_dsigma,
	 int min_gfn_in, int max_gfn_in,
	 int interpolator_order)
{
using namespace patch_system_info::hemisphere_patch_system_info;

// create the patches
patch& pz = *new z_patch(*this, plus_z.patch_number,
			 "+z", patch::patch_is_plus,
			 plus_z.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& px = *new x_patch(*this, plus_x.patch_number,
			 "+x", patch::patch_is_plus,
			 plus_x.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& py = *new y_patch(*this, plus_y.patch_number,
			 "+y", patch::patch_is_plus,
			 plus_y.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& mx = *new x_patch(*this, minus_x.patch_number,
			 "-x", patch::patch_is_minus,
			 minus_x.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& my = *new y_patch(*this, minus_y.patch_number,
			 "-y", patch::patch_is_minus,
			 minus_y.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);

// attach the patches to the patch system 
(*all_patches_)(plus_z.patch_number) = & pz;
(*all_patches_)(plus_x.patch_number) = & px;
(*all_patches_)(plus_y.patch_number) = & py;
(*all_patches_)(minus_x.patch_number) = & mx;
(*all_patches_)(minus_y.patch_number) = & my;

// create the ghost zones
setup_adjacent_ghost_zones(pz, px, N_overlap_points);
setup_adjacent_ghost_zones(pz, py, N_overlap_points);
setup_adjacent_ghost_zones(pz, mx, N_overlap_points);
setup_adjacent_ghost_zones(pz, my, N_overlap_points);
setup_adjacent_ghost_zones(px, py, N_overlap_points);
setup_adjacent_ghost_zones(py, mx, N_overlap_points);
setup_adjacent_ghost_zones(mx, my, N_overlap_points);
setup_adjacent_ghost_zones(my, px, N_overlap_points);
px.setup_mirror_symmetry_ghost_zone(px.max_rho_patch_edge());
py.setup_mirror_symmetry_ghost_zone(py.max_rho_patch_edge());
mx.setup_mirror_symmetry_ghost_zone(mx.min_rho_patch_edge());
my.setup_mirror_symmetry_ghost_zone(my.min_rho_patch_edge());

// create the patch frontiers
setup_adjacent_patch_frontiers(pz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, mx, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, my, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(px, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(py, mx, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mx, my, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(my, px, N_overlap_points, interpolator_order);

assert_all_ghost_zones_fully_setup();
}

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

//
// This function constructs and interlinks the patches for a
// quadrant patch system.
//
void patch_system::setup_quadrant_patch_system
	(int N_ghost_points, int N_overlap_points, fp delta_drho_dsigma,
	 int min_gfn_in, int max_gfn_in,
	 int interpolator_order)
{
using namespace patch_system_info::quadrant_patch_system_info;

// create the patches
patch& pz = *new z_patch(*this, plus_z.patch_number,
			 "+z", patch::patch_is_plus,
			 plus_z.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& px = *new x_patch(*this, plus_x.patch_number,
			 "+x", patch::patch_is_plus,
			 plus_x.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& py = *new y_patch(*this, plus_y.patch_number,
			 "+y", patch::patch_is_plus,
			 plus_y.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& mz = *new z_patch(*this, minus_z.patch_number,
			 "-z", patch::patch_is_minus,
			 minus_z.grid_array_pars(N_ghost_points,
						 N_overlap_points,
						 delta_drho_dsigma),
			 minus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);

// attach the patches to the patch system 
(*all_patches_)(plus_z.patch_number) = & pz;
(*all_patches_)(plus_x.patch_number) = & px;
(*all_patches_)(plus_y.patch_number) = & py;
(*all_patches_)(minus_z.patch_number) = & mz;

// create the ghost zones
setup_adjacent_ghost_zones(pz, px, N_overlap_points);
setup_adjacent_ghost_zones(pz, py, N_overlap_points);
setup_adjacent_ghost_zones(px, py, N_overlap_points);
setup_adjacent_ghost_zones(mz, px, N_overlap_points);
setup_adjacent_ghost_zones(mz, py, N_overlap_points);
setup_periodic_symmetry_ghost_zones(pz.min_rho_patch_edge(),
				    pz.min_sigma_patch_edge(),
				    cpm_map::plus_map);
setup_periodic_symmetry_ghost_zones(px.min_sigma_patch_edge(),
				    py.max_sigma_patch_edge(),
				    cpm_map::plus_map);
setup_periodic_symmetry_ghost_zones(mz.max_rho_patch_edge(),
				    mz.max_sigma_patch_edge(),
				    cpm_map::plus_map);

// create the patch frontiers
setup_adjacent_patch_frontiers(pz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(px, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(mz, py, N_overlap_points, interpolator_order);

assert_all_ghost_zones_fully_setup();
}

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

//
// This function constructs and interlinks the patches for a
// octant patch system.
//
void patch_system::setup_octant_patch_system
	(int N_ghost_points, int N_overlap_points, fp delta_drho_dsigma,
	 int min_gfn_in, int max_gfn_in,
	 int interpolator_order)
{
using namespace patch_system_info::octant_patch_system_info;

// create the patches
patch& pz = *new z_patch(*this, plus_z.patch_number,
			 "+z", patch::patch_is_plus,
			 plus_z.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_z.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& px = *new x_patch(*this, plus_x.patch_number,
			 "+x", patch::patch_is_plus,
			 plus_x.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_x.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);
patch& py = *new y_patch(*this, plus_y.patch_number,
			 "+y", patch::patch_is_plus,
			 plus_y.grid_array_pars(N_ghost_points,
						N_overlap_points,
						delta_drho_dsigma),
			 plus_y.grid_pars(N_overlap_points, delta_drho_dsigma),
			 min_gfn_in, max_gfn_in);

// attach the patches to the patch system 
(*all_patches_)(plus_z.patch_number) = & pz;
(*all_patches_)(plus_x.patch_number) = & px;
(*all_patches_)(plus_y.patch_number) = & py;

// create the ghost zones
setup_adjacent_ghost_zones(pz, px, N_overlap_points);
setup_adjacent_ghost_zones(pz, py, N_overlap_points);
setup_adjacent_ghost_zones(px, py, N_overlap_points);
setup_periodic_symmetry_ghost_zones(pz.min_rho_patch_edge(),
				    pz.min_sigma_patch_edge(),
				    cpm_map::plus_map);
setup_periodic_symmetry_ghost_zones(px.min_sigma_patch_edge(),
				    py.max_sigma_patch_edge(),
				    cpm_map::plus_map);

// create the patch frontiers
setup_adjacent_patch_frontiers(pz, px, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(pz, py, N_overlap_points, interpolator_order);
setup_adjacent_patch_frontiers(px, py, N_overlap_points, interpolator_order);

assert_all_ghost_zones_fully_setup();
}

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

//
// This function creates a pair of periodic-symmetry ghost zones.
//
//static
  void patch_system::setup_periodic_symmetry_ghost_zones
	(const patch_edge& ex, const patch_edge& ey,
	 bool ipar_map_sign)		// one of cpm_map::{plus,minus}_map
{
ex.my_patch().setup_periodic_symmetry_ghost_zone(ex, ey, ipar_map_sign);
ey.my_patch().setup_periodic_symmetry_ghost_zone(ey, ex, ipar_map_sign);
}

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

//
// This function automagically figures out which edges of two adjacent
// patches are adjacent, then sets up both patches' ghost zones on those
// edges.
//
//static
  void patch_system::setup_adjacent_ghost_zones(patch &px, patch &py,
						int N_overlap_points)
{
const patch_edge& ex = px.edge_adjacent_to_patch(py, N_overlap_points);
const patch_edge& ey = py.edge_adjacent_to_patch(px, N_overlap_points);

px.setup_interpatch_ghost_zone(ex, ey);
py.setup_interpatch_ghost_zone(ey, ex);
}

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

//
// This function automagically figures out which edges of two adjacent
// patches are adjacent, then up both patches' patch frontiers on those
// edges, and links these frontiers to the opposite patches' ghost zones.
//
//static
  void patch_system::setup_adjacent_patch_frontiers(patch &px, patch &py,
						    int N_overlap_points,
						    int interpolator_order)
{
const patch_edge& ex = px.edge_adjacent_to_patch(py, N_overlap_points);
const patch_edge& ey = py.edge_adjacent_to_patch(px, N_overlap_points);
interpatch_ghost_zone& igx = px.interpatch_ghost_zone_on_edge(ex);
interpatch_ghost_zone& igy = py.interpatch_ghost_zone_on_edge(ey);

patch_frontier& fx
	= px.setup_patch_frontier(ex,
				  igy.other_min_iperp(), igy.other_max_iperp(),
				  interpolator_order);
patch_frontier& fy
	= py.setup_patch_frontier(ey,
				  igx.other_min_iperp(), igx.other_max_iperp(),
				  interpolator_order);

igx.set_other_frontier(fy);
igy.set_other_frontier(fx);
}

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

//
// This function assert()s that all ghost zones (and frontiers, where
// applicable) of all patches have been fully set up.
//
void patch_system::assert_all_ghost_zones_fully_setup() const
{
	for (int pn = 0 ; pn < N_patches() ; ++pn)
	{
	ith_patch(pn).assert_all_ghost_zones_fully_setup();
	}
}

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

//
// This function decodes a patch system's type into N_patches.
//
//static
  int patch_system::N_patches_of_type(enum patch_system_type type_in)
{
switch	(type_in)
	{
case full_sphere_patch_system:
	return patch_system_info::full_sphere_patch_system_info::N_patches;
case hemisphere_patch_system:
	return patch_system_info::hemisphere_patch_system_info::N_patches;
case quadrant_patch_system:
	return patch_system_info::quadrant_patch_system_info::N_patches;
case octant_patch_system:
	return patch_system_info::octant_patch_system_info::N_patches;
default:
	error_exit(PANIC_EXIT,
"***** patch_system::N_patches_of_type(): bad type=(int)%d!\n"
"                                         (this should never happen!)\n",
		   int(type_in));				/*NOTREACHED*/
	}
}

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

//
// This function decodes a patch system's type into a human-readable
// type name (a C string).
//
//static
  const char *patch_system::name_of_type(enum patch_system_type type_in)
{
switch	(type_in)
	{
case full_sphere_patch_system:	return "full";
case hemisphere_patch_system:	return "half";
case quadrant_patch_system:	return "quadrant";
case octant_patch_system:	return "octant";
default:
	error_exit(PANIC_EXIT,
"***** patch_system::name_of_type(): bad type=(int)%d!\n"
"                                    (this should never happen!)\n",
		   int(type_in));				/*NOTREACHED*/
	}
}

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

//
// This function finds a patch from its human-readable name, and returns
// the patch number, or does an error_exit() if no patch is found with
// the specified name.
//
int patch_system::patch_number_of_name(const char *name) const
{
	for (int pn = 0 ; pn < N_patches() ; ++pn)
	{
	if (STRING_EQUAL(ith_patch(pn).name(), name))
	   then return pn;
	}

error_exit(ERROR_EXIT,
"***** patch_system::patch_number_of_name():\n"
"        no patch with name \"%s\"!\n",
	   name);						/*NOTREACHED*/
}