File: inhomog.c

package info (click to toggle)
inhomog 0.1.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,476 kB
  • sloc: ansic: 10,454; sh: 4,380; makefile: 173
file content (280 lines) | stat: -rw-r--r-- 8,941 bytes parent folder | download
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
/*
   inhomog - biscale kinematical backreaction analytical evolution

   Copyright (C) 2012-2019 Boud Roukema, Jan Ostrowski

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, 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 General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   See also http://www.gnu.org/licenses/gpl.html

*/

#include <stdio.h>
#include <sys/types.h>
#include <argp.h>
#include "config.h"

#include "lib/inhomog.h"
#include "lib/parse_noempty_strtox.h"
#include "lib/biscale_partition.h"


#define EXIT_FAILURE 1

#if ENABLE_NLS
# include <libintl.h>
# define _(Text) gettext (Text)
#else
# define textdomain(Domain)
# define _(Text) Text
#endif
#define N_(Text) Text

#define DEBUG 1
#undef DEBUG

/*
  char *xmalloc ();
  char *xrealloc ();
  char *xstrdup ();
*/

static error_t parse_opt (int key, char *arg, struct argp_state *state);
static void show_version (FILE *stream, struct argp_state *state);

/* argp option keys */
enum {DUMMY_KEY=129
};

/* Option flags and variables.  These are initialized in parse_opt.  */

int want_verbose;               /* --verbose */
enum collapse_types collapse_type;
long collapse_type_long;
double I_inv_double;
double II_inv_double;
double III_inv_double;
double I_inv[N_TWO];
double II_inv[N_TWO];
double III_inv[N_TWO];

int want_expanding;
int want_collapsing;
int want_global;

char *endptr = NULL;  /*  error handling by   strtod, strtol  -  info strtod  */

static struct argp_option options[] =
{
  { "verbose",     'v',           NULL,            0,
    N_("Print more information"), 0 },
  { "biscale",    'b',           N_("COLLAPSE_TYPE"),            0,
    N_("Biscale collapse type ([0] planar, 1 spher, 2 <III>_i=0, 3 <II>_i=0)"), 0 },
  { "I",     '1',           N_("I_D_INIT"),            0,
    N_("initial mean I in domain D"), 0 },
  { "II",     '2',           N_("II_D_INIT"),            0,
    N_("initial mean II in domain D"), 0 },
  { "III",     '3',           N_("III_D_INIT"),            0,
    N_("initial mean III in domain D"), 0 },
  { "expanding",     'e',           NULL,            0,
    N_("output [E]xpanding domain VQZA and Newtonian scale factors"), 0 },
  { "collapsing",     'c',           NULL,            0,
    N_("output Collapsing domain VQZA and Newtonian scale factors"), 0 },
  { "global",     'g',           NULL,            0,
    N_("output Global VQZA and Newtonian scale factors"), 0 },
  { NULL, 0, NULL, 0, NULL, 0 }
};

/* The argp functions examine these global variables.  */
const char *argp_program_bug_address = "boud cosmo.torun.pl";
void (*argp_program_version_hook) (FILE *, struct argp_state *) = show_version;

static struct argp argp =
{
  /* options, parse_opt, N_("[FILE...]"), */
  options, parse_opt, NULL,
  N_("biscale kinematical backreaction analytical evolution\n\nThe inhomog library provides Raychaudhuri integration of cosmological domain-wise average scale factor evolution using an analytical formula for kinematical backreaction Q_D evolution. The inhomog main program illustrates biscale examples. The library routine lib/Omega_D_precalc.c is callable by RAMSES using RAMSES-SCALAV (see Roukema 2018 A&A 610, A51, arXiv:1706.06179).\n\nSource:\ngit clone https://broukema@bitbucket.org/broukema/inhomog.git"),
  NULL, NULL, NULL
};

int
main (int argc, char **argv)
{

  double t_background[N_TIMES];
  double a_FLRW[N_TIMES];
  double a_global_QZA[N_TIMES];
  double a_D[N_TWO][N_TIMES]; /* a_D local QZA */
  double a_D_Newt[N_TWO][N_TIMES]; /* a_D local Newt */

  int32_t i_t;
  int i_warn1=0;

  textdomain(PACKAGE);
  argp_parse(&argp, argc, argv, 0, NULL, NULL);

  if(!want_expanding && !want_collapsing && !want_global)
    want_expanding = 1; /* default */

  biscale_partition(collapse_type,
                    want_verbose,
                    I_inv,
                    II_inv,
                    III_inv,
                    t_background,
                    a_FLRW,
                    a_global_QZA,
                    a_D,
                    a_D_Newt
                    );

  for (i_t=0; i_t<N_TIMES; i_t++){
    if(want_expanding){
      printf("%g %15.10g %15.10g %15.10g\n",
             t_background[i_t],
             a_FLRW[i_t],
             a_D[0][i_t],
             a_D_Newt[0][i_t]);
    }else if(want_collapsing){
      printf("%g %15.10g %15.10g %15.10g\n",
             t_background[i_t],
             a_FLRW[i_t],
             a_D[1][i_t],
             a_D_Newt[1][i_t]);
    }else if(want_global){
      printf("%g %15.10g %15.10g\n",
             t_background[i_t],
             a_FLRW[i_t],
             a_global_QZA[i_t]);
    }else if(i_warn1 < 1){
      printf("Please select an output option.\n");
      i_warn1 ++;
    };
  }; /* for (i_t=0; i_t<N_TIMES; i_t++) */

  exit(0);
}

/* Parse a single option.  */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct argp_state *dummy; /* avoid strict ISO 90 C complaints */
  dummy = state;
  (void)dummy; /* avoid set-but-not-used compile complaint */
  switch (key)
    {
    case ARGP_KEY_INIT:
      /* Set up default values.  */
      want_verbose = 0;
      collapse_type = planar_collapse;
      want_expanding = 0;
      want_collapsing = 0;
      want_global = 0;
      /* Expanding domain initial invariants; some may be overwritten. */
      I_inv[0] = 0.01;
      II_inv[0] = 1e-4;
      III_inv[0] = 1e-6;
      break;

    case 'v':                   /* --verbose */
      want_verbose = 1;
      break;

    case 'b':                   /* --biscale */
      if(arg){  /* are there any parameters given to this option? */
        errno=parse_noempty_strtox(arg, "inhomog:", "--biscale COLLAPSE_TYPE", 'l',0,
                                   &collapse_type_long, &endptr);
        if(0==errno)
          collapse_type = (enum collapse_types)collapse_type_long;

      }; /* if(arg) */
      break;

    case 'e':
      if(want_verbose && (want_collapsing || want_global)){
        printf("Warning: only --expanding option accepted.\n");
      };
      want_expanding = 1;
      break;
    case 'c':
      if(want_verbose && (want_expanding || want_global)){
        printf("Warning: only -collapsing option accepted.\n");
      };
      want_collapsing = 1;
      break;
    case 'g':
      if(want_verbose && (want_collapsing || want_expanding)){
        printf("Warning: only --global option accepted.\n");
      };
      want_global = 1;
      break;

    case '1':                   /* --I */
      if(arg){  /* are there any parameters given to this option? */
        errno=parse_noempty_strtox(arg, "inhomog:", "--I I_INV_INIT", 'd',0,
                                   &I_inv_double, &endptr);
        if(0==errno)
          I_inv[0] = I_inv_double;

      }; /* if(arg) */
      break;

    case '2':                   /* --II */
      if(arg){  /* are there any parameters given to this option? */
        errno=parse_noempty_strtox(arg, "inhomog:", "--II II_INV_INIT", 'd',0,
                                   &II_inv_double, &endptr);
        if(0==errno)
          II_inv[0] = II_inv_double;

      }; /* if(arg) */
      break;

    case '3':                   /* --III */
      if(arg){  /* are there any parameters given to this option? */
        errno=parse_noempty_strtox(arg, "inhomog:", "--III III_INV_INIT", 'd',0,
                                   &III_inv_double, &endptr);
        if(0==errno)
          III_inv[0] = III_inv_double;

      }; /* if(arg) */
      break;

    case ARGP_KEY_ARG:          /* [FILE]... */
      /* TODO: Do something with ARG, or remove this case and make
         main give argp_parse a non-NULL fifth argument.  */
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

/* Show the version number and copyright information.  */
static void
show_version (FILE *stream, struct argp_state *state)
{
  (void) state;
  /* Print in small parts whose localizations can hopefully be copied
     from other programs.  */
  fputs(PACKAGE" "VERSION"\n", stream);
  fprintf(stream, _("Written by %s.\n\n"), "Boud Roukema, Jan Ostrowski");
  fprintf(stream, _("Copyright (C) %s %s\n"), "2012-2019", "Boud Roukema, Jan Ostrowski");
  fputs(_("\
This program is free software; you may redistribute it under the terms of\n\
the GNU General Public License version 2 or later.  This program has absolutely no warranty.\n"),
        stream);
}