-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtestSelectOutput.c
186 lines (158 loc) · 6.16 KB
/
testSelectOutput.c
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
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (C) 2015 Matthieu Schaller ([email protected]).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
/* Some standard headers. */
#include <config.h>
/* Includes. */
#include "swift.h"
void select_output_engine_init(struct engine *e, struct space *s,
struct cosmology *cosmo,
struct swift_params *params,
struct output_options *output,
struct cooling_function_data *cooling,
struct hydro_props *hydro_properties) {
/* set structures */
e->s = s;
e->cooling_func = cooling;
e->parameter_file = params;
e->output_options = output;
e->cosmology = cosmo;
e->policy = engine_policy_hydro;
e->hydro_properties = hydro_properties;
/* initialization of threadpool */
threadpool_init(&e->threadpool, 1);
/* set parameters */
e->verbose = 1;
e->time = 0;
e->snapshot_output_count = 0;
e->snapshot_compression = 0;
};
void select_output_space_init(struct space *s, double *dim, int periodic,
size_t Ngas, size_t Nspart, size_t Ngpart,
struct part *parts, struct spart *sparts,
struct gpart *gparts) {
s->periodic = periodic;
for (int i = 0; i < 3; i++) {
s->dim[i] = dim[i];
}
/* init space particles */
s->nr_parts = Ngas;
s->nr_sparts = Nspart;
s->nr_gparts = Ngpart;
s->parts = parts;
s->gparts = gparts;
s->sparts = sparts;
/* Allocate the extra parts array for the gas particles. */
if (posix_memalign((void **)&s->xparts, xpart_align,
Ngas * sizeof(struct xpart)) != 0)
error("Failed to allocate xparts.");
bzero(s->xparts, Ngas * sizeof(struct xpart));
};
void select_output_space_clean(struct space *s) { free(s->xparts); };
void select_output_engine_clean(struct engine *e) {
threadpool_clean(&e->threadpool);
}
int main(int argc, char *argv[]) {
/* Initialize CPU frequency, this also starts time. */
unsigned long long cpufreq = 0;
clocks_set_cpufreq(cpufreq);
// const char *base_name = "testSelectOutput";
size_t Ngas = 0, Ngpart = 0, Ngpart_background = 0, Nspart = 0, Nbpart = 0,
Nsink = 0, Nnupart = 0;
int flag_entropy_ICs = -1;
int periodic = 1;
double dim[3];
struct part *parts = NULL;
struct gpart *gparts = NULL;
struct spart *sparts = NULL;
struct bpart *bparts = NULL;
struct sink *sinks = NULL;
struct ic_info ics_metadata;
strcpy(ics_metadata.group_name, "NoSUCH");
/* parse parameters */
message("Reading parameters.");
struct swift_params param_file;
const char *input_file = "selectOutputParameters.yml";
parser_read_file(input_file, ¶m_file);
struct output_options output_options;
output_options_init(¶m_file, 0, &output_options);
/* Default unit system */
message("Initialization of the unit system.");
struct unit_system us;
units_init_cgs(&us);
/* Default physical constants */
message("Initialization of the physical constants.");
struct phys_const prog_const;
phys_const_init(&us, ¶m_file, &prog_const);
/* Read data */
message("Reading initial conditions.");
read_ic_single("input.hdf5", &us, dim, &parts, &gparts, &sinks, &sparts,
&bparts, &Ngas, &Ngpart, &Ngpart_background, &Nnupart, &Nsink,
&Nspart, &Nbpart, &flag_entropy_ICs,
/*with_hydro=*/1,
/*with_gravity=*/0,
/*with_sink=*/0,
/*with_stars=*/0,
/*with_black_holes=*/0,
/*with_cosmology=*/0,
/*cleanup_h=*/0,
/*cleanup_sqrt_a=*/0,
/*h=*/1., /*a=*/1., /*n_threads=*/1, /*dry_run=*/0,
/*remap_ids=*/0, &ics_metadata);
/* pseudo initialization of the space */
message("Initialization of the space.");
struct space s;
select_output_space_init(&s, dim, periodic, Ngas, Nspart, Ngpart, parts,
sparts, gparts);
/* initialization of cosmology */
message("Initialization of the cosmology.");
struct cosmology cosmo;
cosmology_init_no_cosmo(&cosmo);
/* pseudo initialization of cooling */
message("Initialization of the cooling.");
struct cooling_function_data cooling;
/* pseudo initialization of hydro */
message("Initialization of the hydro.");
struct hydro_props hydro_properties;
hydro_props_init(&hydro_properties, &prog_const, &us, ¶m_file);
/* pseudo initialization of the engine */
message("Initialization of the engine.");
struct engine e;
e.physical_constants = &prog_const;
sprintf(e.snapshot_base_name, "testSelectOutput");
sprintf(e.run_name, "Select Output Test");
select_output_engine_init(&e, &s, &cosmo, ¶m_file, &output_options,
&cooling, &hydro_properties);
/* check output selection */
message("Checking output parameters.");
io_prepare_output_fields(&output_options, /*with_cosmology=*/0,
/*with_fof=*/0,
/*with_structure_finding=*/0,
/*verbose=*/1);
/* write output file */
message("Writing output.");
write_output_single(&e, &us, &us, /*fof=*/0);
/* Clean-up */
message("Cleaning memory.");
select_output_engine_clean(&e);
select_output_space_clean(&s);
cosmology_clean(&cosmo);
free(parts);
free(gparts);
return 0;
}