diff options
Diffstat (limited to 'src/Setup_Vars.c')
-rw-r--r-- | src/Setup_Vars.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/Setup_Vars.c b/src/Setup_Vars.c new file mode 100644 index 0000000..b09b594 --- /dev/null +++ b/src/Setup_Vars.c @@ -0,0 +1,163 @@ +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" + +#include "util_ErrorCodes.h" +#include "util_Table.h" + + +static const char * rcsid = "$Header$"; + +CCTK_FILEVERSION(Norms_Setup_Vars_c); + + +struct norms_opts { + int active; + int vi; /* variable index */ + int norm_type; +}; + + +static void getopt (int const idx, + const char * const optstring, + void * const opts) +{ + struct norms_opts * norms_opts; + int table; + int cnt; + int ierr; + int norm_type; + + + assert (idx >= 0 && idx < CCTK_NumVars()); + assert (opts); + + norms_opts = &((struct norms_opts *)opts)[idx]; + + assert (! norms_opts->active); + + if (optstring) { + assert (optstring); + table = Util_TableCreateFromString (optstring); + if (table < 0) { + char * fullname = CCTK_FullName (idx); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "The variable \"%s\" is ignored because it has an invalid option specification in the parameter \"Norms::gridfunctions...\"", + fullname); + free (fullname); + return; + } + assert (table >= 0); + } + + norms_opts->active = 1; + norms_opts->vi = idx; + + if (optstring) { + /* XXX norm_type is not used currently !*/ + cnt = Util_TableGetInt (table, &norm_type , "norm_type"); + + if (cnt < 0) { + norms_opts->norm_type = -100; /* XXX magic value */ + } else { + norms_opts->norm_type = norm_type; + } + + ierr = Util_TableDestroy (table); + assert (!ierr); + } + + /* Don't compute norms if not output was requested */ + if (norms_opts->active) { + if (norms_opts->norm_type==-100) { + norms_opts->active = 0; + } + } + +} + + + + + +void Norms_Setup_Vars (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int nvars; + struct norms_opts * norms_opts_1st; + struct norms_opts * norms_opts_2nd; + + int n,i; + + int ierr; + + /* init */ + *nr1stvars=0; + *nr2ndvars=0; + + if (verbose>6) + CCTK_INFO("here we are in Setup_vars"); + + if (verbose>0) + CCTK_VInfo(CCTK_THORNSTRING,"Starting Norms Computation at time %f", + cctkGH->cctk_time); + if (cctk_iteration % out_every != 0) + { + *do_nothing=1; + return; + } + else + *do_nothing=0; + + + nvars = CCTK_NumVars(); + assert (nvars >= 0); + norms_opts_1st = malloc (nvars * sizeof *norms_opts_1st); + norms_opts_2nd = malloc (nvars * sizeof *norms_opts_2nd); + assert (norms_opts_1st); + assert (norms_opts_2nd); + for (n=0; n<nvars; ++n) { + norms_opts_1st[n].active = 0; + norms_opts_2nd[n].active = 0; + } + ierr = CCTK_TraverseString + (gridfunctions_1st, getopt, norms_opts_1st, CCTK_GROUP_OR_VAR); + assert (ierr >= 0); + ierr = CCTK_TraverseString + (gridfunctions_2nd, getopt, norms_opts_2nd, CCTK_GROUP_OR_VAR); + assert (ierr >= 0); + + i=0; + if (verbose>0) + CCTK_INFO("We will compute norms for the following variables"); + for (n=0; n<nvars; ++n) { + if (norms_opts_1st[n].active) { + varindices_1st[i]=norms_opts_1st[n].vi; + if (verbose>0) { + CCTK_VInfo(CCTK_THORNSTRING," %s (1st order var)", + CCTK_FullName(varindices_1st[i])); + } + *nr1stvars=*nr1stvars+1; + } + if (norms_opts_2nd[n].active) { + varindices_2nd[i]=norms_opts_2nd[n].vi; + if (verbose>0) { + CCTK_VInfo(CCTK_THORNSTRING," %s (2nd order var)", + CCTK_FullName(varindices_2nd[i])); + } + *nr2ndvars=*nr2ndvars+1; + } + } + if (verbose>2) + fprintf(stderr," nr1stvars %d nr2ndvars %d\n",*nr1stvars,*nr2ndvars); + + free (norms_opts_1st); + free (norms_opts_2nd); +} |