Streamer fluid modeling - An overview of ARCoS  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rt.c
Go to the documentation of this file.
1 
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdbool.h>
8 #include <libconfig.h>
9 
10 #include "parameters.h"
11 #include "proto.h"
12 #include "species.h"
13 #include "reaction.h"
14 
15 #define MAX_SPECIES 15
16 #define MAX_REACTIONS 30
17 #define MAX_SEEDS 15
18 
20 reaction_t react_photo = {TRUE, 0, 0, {0}, {0}, {""}, {""}, NULL, NULL, NULL, 0.0, NULL};
21 
26 
30 void
32 {
33  int cnt;
34  const char *filename;
35 
36  read_input_file(kin_input,filename);
37 
38  if (has_photoionization == 1)
39  {
40  react_add(&react_photo);
41  ions = find_species_by_name("dummyplus");
43  }
44 
45  printf("\n");
46  for (cnt = no_reactions; cnt > 0; cnt--)
47  react_add(reaction_index[cnt-1]);
48 
49  electrons = find_species_by_name("electrons");
50 }
51 
54 void
55 read_input_file(const char *f_kinetic_name, const char *filename)
56 {
57  config_t cfg_kinetic;
58  config_setting_t *setting;
59  species_t *temp_s;
60  reaction_t *temp_r;
61  seed_t *temp_se;
62  int i,cnt,cnt2;
63 
64  config_init(&cfg_kinetic);
65 
66  /* Read the file f_kinetic_name. If there is an error, report it and exit. */
67  if(! config_read_file(&cfg_kinetic,f_kinetic_name))
68  {
69  fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg_kinetic),
70  config_error_line(&cfg_kinetic), config_error_text(&cfg_kinetic));
71  config_destroy(&cfg_kinetic);
72  exit(EXIT_FAILURE);
73  }
74 
75  /* Get the program name. */
76  if(config_lookup_string(&cfg_kinetic, "filename", &filename))
77  printf("Example : %s\n\n", filename);
78  else
79  fprintf(stdout, "No ' program name' setting in configuration file.\n");
80 
81  /* Output a list of all species parameters in the file. */
82  setting = config_lookup(&cfg_kinetic, "species");
83  if(setting != NULL)
84  {
86 
87  printf("# species = %i\n",no_species);
88 
89  for(i = 0; i < no_species; ++i)
90  {
91  temp_s = (species_t*) malloc(sizeof(species_t));
92  temp_s->charge = 0.0;
93  temp_s->mass = 0.0;
94  temp_s->name = "";
95  if (read_specie(setting,i,temp_s))
96  spec_index[i]=temp_s;
97  printf("Species '%10s' has mass %10.1e and charge %10.1e\n",
98  spec_index[i]->name,
99  spec_index[i]->mass,
100  spec_index[i]->charge);
101  continue;
102  }
103  }
104 
105  /* Output a list of all seed parameters in the file. */
106  setting = config_lookup(&cfg_kinetic, "seed");
107  if(setting != NULL)
108  {
109  no_seed = config_setting_length(setting);
110 
111  printf("# seed = %i\n",no_seed);
112  printf("\n");
113 
114  for(i = 0; i < no_seed; ++i)
115  {
116  temp_se = (seed_t*) malloc(sizeof(seed_t));
117  temp_se->species = -1;
118  temp_se->value = 0.0;
119  temp_se->type = -1;
120  temp_se->x0 = 0.0;
121  temp_se->y0 = 0.0;
122  temp_se->z0 = 0.0;
123  temp_se->sigma_x = 0.0;
124  temp_se->sigma_y = 0.0;
125  temp_se->sigma_z = 0.0;
126  if (read_seed(setting,i,temp_se))
127  seed_index[i]=temp_se;
128  printf("Found a seed of species %s and type %s\n",
129  seed_index[i]->kind_species,
130  seed_index[i]->kind_type);
131  printf("It has value %10.1e, z-position %10.1e and y-sigma %10.1e\n",
132  seed_index[i]->value,
133  seed_index[i]->z0,
134  seed_index[i]->sigma_y);
135  continue;
136  }
137  }
138 
139  /* Output a list of all reaction parameters in the file. */
140  setting = config_lookup(&cfg_kinetic, "reactions");
141  if(setting != NULL)
142  {
144 
145  printf("# reactions = %i\n",no_reactions);
146 
147  for(i = 0; i < no_reactions; ++i)
148  {
149  temp_r = (reaction_t*) malloc(sizeof(reaction_t));
150  temp_r->is_photo = 0;
151  temp_r->nin = 0;
152  temp_r->nout = 0;
153  temp_r->f = NULL;
154  temp_r->rt = NULL;
155  temp_r->tablefile = "";
156  temp_r->k = 0.0;
157  temp_r->next = NULL;
158  if (read_reaction(setting,i,temp_r))
159  reaction_index[i]=temp_r;
160 
161  continue;
162  }
163  }
164 
165  printf("\n");
166  for (cnt = 0; cnt < no_reactions; cnt++)
167  {
168  printf("Reaction #%i has %i input-species, %i output-species.\n",
169  cnt,reaction_index[cnt]->nin,reaction_index[cnt]->nout);
170  printf("The rates are defined in %s\n",
171  reaction_index[cnt]->tablefile);
172  printf("Input species are:\t");
173  for (cnt2 = 0; cnt2 < reaction_index[cnt]->nin; cnt2++) {
174  printf("(%i) %s\t",
175  reaction_index[cnt]->input[cnt2],
176  reaction_index[cnt]->inname[cnt2]);
177  }
178  printf("\nOutput species are:\t");
179  for (cnt2 = 0; cnt2 < reaction_index[cnt]->nout; cnt2++) {
180  printf("(%i) %s\t",reaction_index[cnt]->output[cnt2],
181  reaction_index[cnt]->outname[cnt2]);
182  }
183  printf("\n");
184  }
185 }