File:/home/sbrandt/cactus/Cactus/arrangements/EinsteinInitialData/IDFileADM/src/IDFileADM_ParamCheck.c
1:/* $Header$ */
2:
3:#include <assert.h>
4:#include <stdlib.h>
5:
6:#include "cctk.h"
7:#include "cctk_Arguments.h"
8:#include "cctk_Parameters.h"
9:
10:static void callback (int idx, const char * optstring, void * callback_arg);
11:
12:/** Ensure that all ADMBase initial data that are supposed to be read
13:    from a file are actually scheduled for the file reader.  */
14:void IDFileADM_ParamCheck (CCTK_ARGUMENTS)
15:{
16:  DECLARE_CCTK_ARGUMENTS;
17:  DECLARE_CCTK_PARAMETERS;
18:  
19:  char * variable_is_read;
20:  int i;
21:  int nvars;
22:  
23:  variable_is_read = malloc (CCTK_NumVars());
24:  assert (variable_is_read);
25:  for (i=0; i<CCTK_NumVars(); ++i) {
26:    variable_is_read[i] = 0;
27:  }
28:  
29:  nvars = CCTK_TraverseString
30:    (filereader_ID_vars, callback, variable_is_read, CCTK_GROUP_OR_VAR);
31:  assert (nvars >= 0);
32:  
33:  if (CCTK_EQUALS(initial_lapse, "read from file")) {
34:    int const ialp = CCTK_VarIndex ("ADMBase::alp");
35:    assert (ialp >= 0);
36:    if (! variable_is_read[ialp]) {
37:      CCTK_PARAMWARN ("The lapse is initialised using the file reader, but the group ADMBase::lapse has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
38:    }
39:  }
40:  
41:  if (CCTK_EQUALS(initial_shift, "read from file")) {
42:    int const ibetax = CCTK_VarIndex ("ADMBase::betax");
43:    int const ibetay = CCTK_VarIndex ("ADMBase::betay");
44:    int const ibetaz = CCTK_VarIndex ("ADMBase::betaz");
45:    assert (ibetax >= 0);
46:    assert (ibetay >= 0);
47:    assert (ibetaz >= 0);
48:    if (! variable_is_read[ibetax]
49:        || ! variable_is_read[ibetay]
50:        || ! variable_is_read[ibetaz]) {
51:      CCTK_PARAMWARN ("The shift is initialised using the file reader, but the group ADMBase::shift has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
52:    }
53:  }
54:  
55:  if (CCTK_EQUALS(initial_data, "read from file")) {
56:    int const igxx = CCTK_VarIndex ("ADMBase::gxx");
57:    int const igxy = CCTK_VarIndex ("ADMBase::gxy");
58:    int const igxz = CCTK_VarIndex ("ADMBase::gxz");
59:    int const igyy = CCTK_VarIndex ("ADMBase::gyy");
60:    int const igyz = CCTK_VarIndex ("ADMBase::gyz");
61:    int const igzz = CCTK_VarIndex ("ADMBase::gzz");
62:    int const ikxx = CCTK_VarIndex ("ADMBase::kxx");
63:    int const ikxy = CCTK_VarIndex ("ADMBase::kxy");
64:    int const ikxz = CCTK_VarIndex ("ADMBase::kxz");
65:    int const ikyy = CCTK_VarIndex ("ADMBase::kyy");
66:    int const ikyz = CCTK_VarIndex ("ADMBase::kyz");
67:    int const ikzz = CCTK_VarIndex ("ADMBase::kzz");
68:    int const ipsi = CCTK_VarIndex ("StaticConformal::psi");
69:    int const ipsix = CCTK_VarIndex ("StaticConformal::psix");
70:    int const ipsiy = CCTK_VarIndex ("StaticConformal::psiy");
71:    int const ipsiz = CCTK_VarIndex ("StaticConformal::psiz");
72:    int const ipsixx = CCTK_VarIndex ("StaticConformal::psixx");
73:    int const ipsixy = CCTK_VarIndex ("StaticConformal::psixy");
74:    int const ipsixz = CCTK_VarIndex ("StaticConformal::psixz");
75:    int const ipsiyy = CCTK_VarIndex ("StaticConformal::psiyy");
76:    int const ipsiyz = CCTK_VarIndex ("StaticConformal::psiyz");
77:    int const ipsizz = CCTK_VarIndex ("StaticConformal::psizz");
78:    assert (igxx >= 0);
79:    assert (igxy >= 0);
80:    assert (igxz >= 0);
81:    assert (igyy >= 0);
82:    assert (igyz >= 0);
83:    assert (igzz >= 0);
84:    if (! variable_is_read[igxx]
85:        || ! variable_is_read[igxy]
86:        || ! variable_is_read[igxz]
87:        || ! variable_is_read[igyy]
88:        || ! variable_is_read[igyz]
89:        || ! variable_is_read[igzz]) {
90:      CCTK_PARAMWARN ("The metric is initialised using the file reader, but the group ADMBase::metric has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
91:    }
92:    assert (ikxx >= 0);
93:    assert (ikxy >= 0);
94:    assert (ikxz >= 0);
95:    assert (ikyy >= 0);
96:    assert (ikyz >= 0);
97:    assert (ikzz >= 0);
98:    if (! variable_is_read[ikxx]
99:        || ! variable_is_read[ikxy]
100:        || ! variable_is_read[ikxz]
101:        || ! variable_is_read[ikyy]
102:        || ! variable_is_read[ikyz]
103:        || ! variable_is_read[ikzz]) {
104:      CCTK_PARAMWARN ("The metric is initialised using the file reader, but the group ADMBase::curv has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
105:    }
106:    if (CCTK_EQUALS (metric_type, "physical")) {
107:      /* do nothing */
108:    } else if (CCTK_EQUALS (metric_type, "static conformal")) {
109:      if (CCTK_EQUALS (conformal_storage, "factor")) {
110:        assert (ipsi >= 0);
111:        if (! variable_is_read[ipsi]) {
112:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor\", but the group StaticConformal::confac has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
113:        }
114:      } else if (CCTK_EQUALS (conformal_storage, "factor+derivs")) {
115:        assert (ipsi >= 0);
116:        if (! variable_is_read[ipsi]) {
117:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor+derivs\", but the group StaticConformal::confac has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
118:        }
119:        if (! variable_is_read[ipsix]
120:            || ! variable_is_read[ipsiy]
121:            || ! variable_is_read[ipsiz]) {
122:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor+derivs\", but the group StaticConformal::confac_1derivs has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
123:        }
124:      } else if (CCTK_EQUALS (conformal_storage, "factor+derivs+2nd derivs")) {
125:        assert (ipsi >= 0);
126:        if (! variable_is_read[ipsi]) {
127:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor+derivs+2nd derivs\", but the group StaticConformal::confac has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
128:        }
129:        if (! variable_is_read[ipsix]
130:            || ! variable_is_read[ipsiy]
131:            || ! variable_is_read[ipsiz]) {
132:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor+derivs+2nd derivs\", but the group StaticConformal::confac_1derivs has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
133:        }
134:        if (! variable_is_read[ipsixx]
135:            || ! variable_is_read[ipsixy]
136:            || ! variable_is_read[ipsixz]
137:            || ! variable_is_read[ipsiyy]
138:            || ! variable_is_read[ipsiyz]
139:            || ! variable_is_read[ipsizz]) {
140:          CCTK_PARAMWARN ("The metric is initialised using the file reader, and the metric_type is \"static conformal\", and the conformal_storage is \"factor+derivs+2nd derivs\", but the group StaticConformal::confac_2derivs has not been scheduled to be read.  Please set the parameter \"IO::filereader_ID_vars\" accordingly.");
141:        }
142:      } else {
143:        CCTK_PARAMWARN ("Unknown conformal_storage type");
144:      }
145:    } else {
146:      CCTK_PARAMWARN ("Unknown metric type");
147:    }
148:  }
149:  
150:  free (variable_is_read);
151:}
152:
153:/** Mark a variable as to be read from the file reader.  */
154:static void callback (int idx, const char * optstring, void * callback_arg)
155:{
156:  assert (idx>=0 && idx<CCTK_NumVars());
157:  ((char *)callback_arg)[idx] = 1;
158:}