Files
@ b7792cb187f7
Branch filter:
Location: MD/arcos/src/main.c
b7792cb187f7
6.2 KiB
text/x-csrc
Edited file README via RhodeCode
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 | /**i @file main.c
* @brief Code regarding input of parameters + starting of the code. */
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
//#include <getopt.h>
#include <math.h>
#include "cdr.h"
#include "cstream.h"
#include "grid.h"
#include "parameters.h"
#include "proto.h"
#include "species.h"
int main (int argc, char *argv[]);
void start_process (cdr_grid_t *cdr);
void output_tree (cdr_grid_t *cdr, int step, double t);
void check_params (void);
/** @brief The main program */
int
main (int argc, char *argv[])
{
// param_t **p;
// char *s;
// struct option *opt;
// struct option *long_options;
// int c;
cdr_grid_t *cdr;
int count,count_user;
static const char *output_file;
config_t cfg,cfg_user;
config_setting_t *setting,*setting_user;
const char *prog_name,*f_defname,*f_username;
f_defname = "input/default.cfg";
f_username = "input/user_init.cfg";
output_file = "input/user_continue.cfg";
/* Open configuration cfg */
config_init(&cfg);
/* Read the default file.
* The default file might be a result of a previous run, containing values
* for all global variables.
* If there is an error, report it and exit. */
if(! config_read_file(&cfg, f_defname))
{
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return(EXIT_FAILURE);
}
/* Get the program name. */
if(config_lookup_string(&cfg, "name", &prog_name))
printf("Example : %s\n\n", prog_name);
else
fprintf(stderr, "No ' program name' setting in configuration file.\n");
/* Output a list of all parameters in the file. */
setting = config_lookup(&cfg, "param");
if(setting != NULL)
{
int i;
count = config_setting_length(setting);
fprintf(stdout, "# params: count=%i\n",count);
for(i = 0; i < count; ++i)
{
if (read_parameter(setting,setting,i,count,FALSE))
continue;
}
/* Write out the updated configuration. */
if(! config_write_file(&cfg, output_file))
{
fprintf(stderr, "Error while writing file.\n");
config_destroy(&cfg);
return(EXIT_FAILURE);
}
putchar('\n');
}
fprintf(stdout, "Default configuration successfully written to: %s\n",
output_file);
/* ========================================================================== */
/* Open configuration cfg_user */
config_init(&cfg_user);
/* Read the file made by the user, with adapted values.
* This file does not have to contain entries for variables which remain
* unchanged.
* If there is an error, report it and exit. */
if(! config_read_file(&cfg_user, f_username))
{
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg_user),
config_error_line(&cfg_user), config_error_text(&cfg_user));
config_destroy(&cfg_user);
return(EXIT_FAILURE);
}
/* Output a list of all parameters in the file. */
setting_user = config_lookup(&cfg_user, "param");
if(setting_user)
{
int i;
count_user = config_setting_length(setting_user);
fprintf(stdout, "# params: count_user=%i\n",count_user);
for(i = 0; i < count_user; ++i)
{
if (read_parameter(setting,setting_user,i,count,TRUE))
continue;
}
/* Write out the updated configuration. */
if(! config_write_file(&cfg, output_file))
{
fprintf(stderr, "Error while writing file.\n");
config_destroy(&cfg);
return(EXIT_FAILURE);
} else {
fprintf(stdout, "Updated configuration successfully written to: %s\n",
output_file);
}
putchar('\n');
}
check_params ();
cstream_init ();
if (restart) {
if (0 == strcmp (load_file, "")) {
printf("restart file is empty\n");
return 1;
} else
cdr = cdr_load_tree_r (output_dir, load_file, NULL);
} else
cdr = cdr_scratch_init ();
start_process(cdr);
/* Destroy both configurations */
config_destroy(&cfg_user);
config_destroy(&cfg);
return 0;
}
/** @brief Starts a given run on a given @a cdr tree. */
void
start_process (cdr_grid_t *cdr)
{
int i, i0;
double t, dt;
double t0, t1;
struct timeval tv;
FILE *fp;
i0 = (int) (start_t / output_dt);
debug(1,"before loop :start_t= %e; t = %e; dt = %e\n",start_t,t, dt);
/* This is the main loop of the code. */
for (i = i0, t = start_t; t < end_t; t += dt)
{
debug(1,"inside loop: i, t, dt : %d %e %e\n",i,t,dt);
/* Set the field and the fixed charge when we have time-dependent
external fields (controled by rise_time) */
cstream_set_field_at_time (t);
dt = cdr_rk2 (cdr, attempt_dt, t);
cdr_update_refined (&cdr);
printf("t = %lf\tdt = %lf\tnext output at: %lf\n",t,dt,i * output_dt);
if (output_dt <= 0.0 || t >= output_dt * i)
{
output_tree (cdr, i, t);
if (cdr->ntheta > 1)
{
dft_out_weights (cdr, output_dir, t);
}
i++;
}
}
cdr_dump (cdr, output_dir, "C");
cdr_free_r (cdr);
cstream_end ();
}
/** @brief Outputs the tree contained in cdr.
*
* If pois_output (global parameter) is true, it also dumps the Poisson tree.
*/
void
output_tree (cdr_grid_t *cdr, int step, double t)
{
char *gname;
pois_grid_t **pois_modes;
FILE *fp;
char logfile[100];
asprintf (&gname, "C%.3d", step);
cdr_set_ext_bnd_r (cdr);
/* !!!!!!!!!!!! */
if (1 || t > start_t || 0 == strcmp (load_file, "")) {
cdr_dump_r (cdr, output_dir, gname, NULL, t);
cdr_dump_frames (cdr, output_dir, gname);
printf ("CDR grid %s saved\n", gname);
}
free (gname);
if (pois_output) {
int mode;
pois_modes = cdr_calc_field_r (cdr, TRUE);
for (mode = 0; mode < max_ntheta; mode++) {
asprintf (&gname, "P%.3d%.2d", step, mode);
pois_dump_r (pois_modes[mode], output_dir, gname);
pois_free_r (pois_modes[mode]);
printf ("Poisson grid %s saved\n", gname);
free (gname);
}
free (pois_modes);
}
}
/** @brief Checks for some errors in the parameters that will produce
* nonsense output.
*/
void
check_params ()
{
if ((gridpoints_z % 4) != 0 && pois_inhom == 1) {
fatal ("To use inhomogeneous fields, gridpoints_z must be a"
" multiple of 4\n");
}
}
|