aboutsummaryrefslogtreecommitdiff
path: root/src/ParamCheck.c
blob: c46343aa4d183e331ea642708a25130e597dd856 (plain)
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
 /*@@
   @file      ParamCheck.c
   @date      Mon May 20 09:50:55 2002
   @author    Ian Hawke
   @desc 
   Basic parameter checking for thorn MoL.
   @enddesc 
   @version   $Header$
 @@*/

#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(CactusBase_MoL_ParamCheck_c);

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 ***************** Scheduled Routine Prototypes *********************
 ********************************************************************/

void MoL_ParamCheck(CCTK_ARGUMENTS);

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    MoL_ParamCheck
   @date       Mon May 20 09:56:05 2002
   @author     Ian Hawke
   @desc 
   Basic parameter checking.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

void MoL_ParamCheck(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  CCTK_INT options_table, ierr, GenericIntermediateSteps;

  if (CCTK_Equals(ODE_Method, "Generic"))
  {
    if (MoL_Num_Scratch_Levels < MoL_Intermediate_Steps - 1)
    {
      CCTK_PARAMWARN("When using a generic solver the number "
                     "of scratch levels must be at least the "
                     "number of intermediate steps - 1");
    }
    if ( (CCTK_Equals(Generic_Type, "Classic RK3"))&&
         ((!(MoL_Intermediate_Steps == 3))||(!(MoL_Num_Scratch_Levels > 1))) )
    {
      CCTK_PARAMWARN("When using the classic RK3 evolver the "
                     "number of intermediate steps must be 3 "
                     "and the number of scratch levels at least 2");
    }
    if (CCTK_Equals(Generic_Type, "Table"))
    {
      options_table =
        Util_TableCreateFromString(Generic_Method_Descriptor);
      if (options_table < 0)
      {
        CCTK_WARN(0, "Failed to create table from "
                  "Generic_Method_Descriptor!");
      }
      ierr = Util_TableGetInt(options_table,
                              &GenericIntermediateSteps,
                              "GenericIntermediateSteps");
      if (ierr < 1)
      {
        if (ierr == UTIL_ERROR_TABLE_NO_SUCH_KEY)
        {
          CCTK_WARN(0, "When using the generic table options "
                    "you must set \"GenericIntermediateSteps\" in "
                    "the options table");
        }
        else
        {
          CCTK_WARN(0, "Table error - check with Ian.");
        }
      }
      if (MoL_Intermediate_Steps != GenericIntermediateSteps)
      {
        CCTK_PARAMWARN("The number of intermediate steps must "
                       "equal the number specified in the table options!");
      }
      ierr = Util_TableDestroy(options_table);
    }
  }

  if ( (CCTK_Equals(ODE_Method, "Euler"))&&(!(MoL_Intermediate_Steps == 1)) )
  {
    CCTK_PARAMWARN("When using the Euler evolver the "
                   "number of intermediate steps must be 1");
  }

  if ( (CCTK_Equals(ODE_Method, "RK2"))&&(!(MoL_Intermediate_Steps == 2)) )
  {
    CCTK_PARAMWARN("When using the efficient RK2 evolver the "
                   "number of intermediate steps must be 2");
  }

  if ( (CCTK_Equals(ODE_Method, "RK3"))&&(!(MoL_Intermediate_Steps == 3)) )
  {
    CCTK_PARAMWARN("When using the efficient RK3 evolver the "
                   "number of intermediate steps must be 3");
  }

  if ( (CCTK_Equals(ODE_Method, "RK4")) && ( (!(MoL_Intermediate_Steps == 4))
       || (!(MoL_Num_Scratch_Levels > 0)) ) )
  {
    CCTK_PARAMWARN("When using the efficient RK4 evolver the "
                   "number of intermediate steps must be 4, and"
                   " the number of scratch levels at least 1");
  }

  if ( (CCTK_Equals(ODE_Method, "RK45") || CCTK_Equals(ODE_Method, "RK45CK")) &&
       ( !((MoL_Intermediate_Steps == 6)&&(MoL_Num_Scratch_Levels > 5)) ) )
  {
    CCTK_PARAMWARN("When using the RK45 or RK45CK evolver, the "
                   "number of intermediate steps must be 6 " 
                   "and the number of scratch levels at least 6.");
  }

  if ( (CCTK_Equals(ODE_Method, "RK65")) &&
       ( !((MoL_Intermediate_Steps == 8)&&(MoL_Num_Scratch_Levels > 7)) ) )
  {
    CCTK_PARAMWARN("When using the RK65 evolver the "
                   "number of intermediate steps must be 8 " 
                   "and the number of scratch levels at least 8.");
  }

  if ( (CCTK_Equals(ODE_Method, "RK87")) &&
       ( !((MoL_Intermediate_Steps == 13)&&(MoL_Num_Scratch_Levels > 12)) ) )
  {
    CCTK_PARAMWARN("When using the RK87 evolver the "
                   "number of intermediate steps must be 13 " 
                   "and the number of scratch levels at least 13.");
  }
  
  if ( (CCTK_Equals(ODE_Method, "AB"))&&(!(MoL_Intermediate_Steps == 1)) )
  {
    CCTK_PARAMWARN("When using the Adams-Bashforth evolver the "
                   "number of intermediate steps must be 1");
  }

  if ( (CCTK_Equals(ODE_Method, "RK2-MR-2:1"))&&
       ( !((MoL_Intermediate_Steps == 5) && (MoL_Num_Scratch_Levels > 4))) )
  {
    CCTK_PARAMWARN("When using the multirate 2-1 RK2 evolver the "
                   "number of intermediate steps must be 5 and the number of scratch levels at least 5");
  }

  if ( (CCTK_Equals(ODE_Method, "RK4-MR-2:1"))&&
       ( !((MoL_Intermediate_Steps == 10) && (MoL_Num_Scratch_Levels > 9))) )
  {
    CCTK_PARAMWARN("When using the multirate 2-1 RK4 evolver the "
                   "number of intermediate steps must be 10 and the number of scratch levels at least 10");
  }

  if ( (CCTK_Equals(ODE_Method, "RK4-RK2"))&&
       ( !((MoL_Intermediate_Steps == 4) && (MoL_Num_Scratch_Levels > 0))) )
  {
    CCTK_PARAMWARN("When using the multirate RK4-RK2 evolver the "
                   "number of intermediate steps must be 4 and the number of scratch levels at least 1");
  }

  if (adaptive_stepsize)
  {
    if (CCTK_Equals(ODE_Method, "RK45")||CCTK_Equals(ODE_Method, "RK45CK")||CCTK_Equals(ODE_Method, "RK65")||CCTK_Equals(ODE_Method, "RK87"))
    {
      /* everything is fine, do nothing */
    }
    else
    {
      CCTK_PARAMWARN("Adaptive time step sizes are only possible with the RK45, RK45CK, RK65, and RK87 solvers");
    }
  }
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/