aboutsummaryrefslogtreecommitdiff
path: root/src/driver/driver.hh
blob: 38efffcc30527a3efbfa42fd404e1a86b95bd649 (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
// driver.hh -- header file for driver code
// $Header$

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

//
// this enum holds the (a) decoded  method  parameter, i.e. it specifies
// our top-level method
//
enum	method
	{
	method__horizon_function,
	method__Jacobian_test,
	method__Jacobian_test_NP_only,
	method__Newton_solve // no comma
	};

//
// this enum holds the (a) decoded  verbose_method  parameter, i.e.
// it specifies which (how many) informational messages we should print
//
enum	verbose_level
	{
	verbose_level__physics_highlights,
	verbose_level__physics_details,
	verbose_level__algorithm_highlights,
	verbose_level__algorithm_details // no comma
	};

//
// this enum holds the (a) decoded  Jacobian_method  parameter,
// i.e. it specifies how we compute the (a) Jacobian matrix
//
enum	Jacobian_method
	{
	Jacobian_method__numerical_perturb,
	Jacobian_method__symbolic_diff_with_FD_dr,
	Jacobian_method__symbolic_diff // no comma
	};

//
// this enum holds the (a) decoded  file_format  parameter,
// i.e. it specifies what format of input/output file(s) we should use
//
enum	file_format
	{
	file_format__ASCII,
	file_format__HDF5 // no comma
	};

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

//
// This struct holds parameters for computing the Jacobian matrix.
//
struct	Jacobian_info
	{
	enum Jacobian_method Jacobian_method;
	enum Jacobian_type   Jacobian_storage_method;
	fp perturbation_amplitude;
	};

//
// This struct holds parameters for solving the H(h) = 0 equations.
//
struct	solver_info
	{
	int max_Newton_iterations;
	fp max_Delta_h_over_h;
	fp H_norm_for_convergence;
	fp Delta_h_norm_for_convergence;
	bool final_H_update_if_exit_x_H_small;
	};

//
// This struct holds info for I/O
//
struct	IO_info
	{
	bool output_initial_guess;
	bool output_h_and_H_at_each_Newton_iteration;
	bool output_h, output_H;
	enum file_format file_format;
	const char* ASCII_file_name_extension;
	const char* HDF5_file_name_extension;
	const char* h_base_file_name;
	const char* H_base_file_name;
	const char* Jacobian_base_file_name;

	// this is used to choose file names
	int time_iteration;	// the Cactus time interation number
				// (cctk_iteration)
	};

//
// This struct holds info describing how verbose we should be
//
struct	verbose_info
	{
	// decoded from verbose_level parameter
	enum verbose_level verbose_level;

	// derived Boolean flags saying whether or not
	// verbose_level is >= the appropriate level
	bool print_physics_highlights;
	bool print_physics_details;
	bool print_algorithm_highlights;
	bool print_algorithm_details;
	};

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

//
// (A single copy of) this struct holds all of our information about
// a single apparent horizon.
//
struct	AH_info
	{
	patch_system* ps_ptr;
	Jacobian* Jac_ptr;

	bool AH_found;
	fp area, mass;
	fp centroid_x, centroid_y, centroid_z;
	};

//
// (A single copy of) this struct holds all of our state that's
// persistent across Cactus scheduler calls.
//
struct	state
	{
	enum method method;
	struct verbose_info verbose_info;
	int timer_handle;
	enum patch::integration_method surface_integral_method;

	struct IO_info IO_info;
	struct Jacobian_info Jac_info;
	struct solver_info solver_info;
	struct cactus_grid_info cgi;
	struct geometry_info gi;

	int N_horizons;

	// this vector is of size N_horizons+1,
	// and is indexed with a "horizon number" hn
	// which is (hopefully) always in the range 1 <= hn <= N_horizons
	std::vector<AH_info *> AH_info_ptrs;
	};

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

//
// prototypes for functions visible outside their source files
//

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

//
// *** routines called from the Cactus scheduler ***
//

// setup.cc
extern "C"
  void AHFinderDirect_setup(CCTK_ARGUMENTS);

// initial_guess.cc
extern "C"
  void AHFinderDirect_initial_guess(CCTK_ARGUMENTS);

// find_horizons.cc
extern "C"
  void AHFinderDirect_find_horizons(CCTK_ARGUMENTS);

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

// Newton.cc
// returns true for success, false for failure to converge
bool Newton_solve(patch_system& ps,
		  Jacobian& Jac,
		  const struct cactus_grid_info& cgi,
		  const struct geometry_info& gi,
		  const struct Jacobian_info& Jacobian_info,
		  const struct solver_info& solver_info,
		  struct IO_info& IO_info,
		  int hn, const struct verbose_info& verbose_info);

// horizon_Jacobian.cc
// returns true for successful computation, false for failure
bool horizon_Jacobian(patch_system& ps,
		      Jacobian& Jac,
		      const struct cactus_grid_info& cgi,
		      const struct geometry_info& gi,
		      const struct Jacobian_info& Jacobian_info,
		      bool print_msg_flag);

// io.cc
void input_gridfn(patch_system& ps, int unknown_gfn,
		  struct IO_info& IO_info, const char base_file_name[],
		  int hn, bool print_msg_flag, int AHF_iteration = 0);
void output_gridfn(patch_system& ps, int unknown_gfn,
		   struct IO_info& IO_info, const char base_file_name[],
		   int hn, bool print_msg_flag, int AHF_iteration = 0);
void print_Jacobians(const patch_system& ps,
		     const Jacobian* Jac_NP, const Jacobian* Jac_SD_FDdr,
		     struct IO_info& IO_info, const char base_file_name[],
		     int hn, bool print_msg_flag, int AHF_iteration = 0);