From bc0686abb3264a6ae0d2adae5b9f4943a9b0611e Mon Sep 17 00:00:00 2001 From: rhaas Date: Fri, 17 May 2013 17:39:54 +0000 Subject: HydroBase: add paramcheck for "read from file parameters" * add missing "read from file option" to initial_hydro git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinBase/HydroBase/trunk@64 57fe0bb3-ccba-405f-9b23-de0201f165b7 --- param.ccl | 17 +++++++---- schedule.ccl | 14 ++++++++++ src/ParamCheck.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/make.code.defn | 2 +- 4 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 src/ParamCheck.c diff --git a/param.ccl b/param.ccl index 1e109dd..e1001c5 100755 --- a/param.ccl +++ b/param.ccl @@ -4,11 +4,16 @@ SHARES: InitBase USES KEYWORD initial_data_setup_method +SHARES: IO + +USES STRING filereader_ID_vars + RESTRICTED: KEYWORD initial_hydro "The hydro initial data" { "zero" :: "hydro variables are set to vacuum (without atmosphere)" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "zero" KEYWORD evolution_method "The hydro evolution method" @@ -34,7 +39,7 @@ KEYWORD initial_Y_e "Initial value for Y_e" { "none" :: "inactive" "one" :: "initially set to one" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" KEYWORD Y_e_evolution_method "Evolution method for Y_e" @@ -58,21 +63,21 @@ KEYWORD initial_Bvec "Initial value for Bvec" { "none" :: "inactive" "zero" :: "initially set to zero" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" KEYWORD initial_Avec "Initial value for Avec" { "none" :: "inactive" "zero" :: "initially set to zero" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" KEYWORD initial_Aphi "Initial value for Aphi" { "none" :: "inactive" "zero" :: "initially set to zero" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" KEYWORD Bvec_evolution_method "Evolution method for Bvec" @@ -91,14 +96,14 @@ KEYWORD initial_temperature "Initial value for temperature" { "none" :: "inactive" "zero" :: "initially set to zero" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" KEYWORD initial_entropy "Initial value for entropy" { "none" :: "inactive" "zero" :: "initially set to zero" - "read from file" :: "do nothing, filereader will provide data" + "read from file" :: "Read the initial data using the IOUtil file reader. Note that this only allows you to read the data from a file, it does not actually do it. You still have to programme the IOUtil file reader accordingly." } "none" diff --git a/schedule.ccl b/schedule.ccl index 960de04..7cf56a3 100755 --- a/schedule.ccl +++ b/schedule.ccl @@ -114,6 +114,20 @@ schedule HydroBase_StartUp at CCTK_STARTUP LANG: C } "Startup banner" +if(CCTK_EQUALS(initial_hydro, "read from file") || + CCTK_EQUALS(initial_Aphi, "read from file") || + CCTK_EQUALS(initial_Avec, "read from file") || + CCTK_EQUALS(initial_Bvec, "read from file") || + CCTK_EQUALS(initial_Y_e, "read from file") || + CCTK_EQUALS(initial_temperature, "read from file") || + CCTK_EQUALS(initial_entropy, "read from file")) +{ +schedule HydroBase_ParamCheck AT PARAMCHECK +{ + LANG: C +} "check that hydrobase parameters are consistent" +} + schedule group HydroBase_RHS in MoL_CalcRHS { } "Groups for scheduling tasks for calculating RHS of hydro variables" diff --git a/src/ParamCheck.c b/src/ParamCheck.c new file mode 100644 index 0000000..6e1ff22 --- /dev/null +++ b/src/ParamCheck.c @@ -0,0 +1,82 @@ +#include +#include + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" + +#include "util_String.h" + +static void callback (int idx, const char * optstring, void * callback_arg); + +/** Ensure that all HydroBase initial data that are supposed to be read + from a file are actually scheduled for the file reader. */ +void HydroBase_ParamCheck (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + char * variable_is_read; + int i; + int nvars; + + const struct { + const char * paramname; + const char * paramvalue; + const char * varname; + } vars_to_read[] = { + {"initial_hydro", initial_hydro, "HydroBase::rho"}, + {"initial_hydro", initial_hydro, "HydroBase::vel[0]"}, + {"initial_hydro", initial_hydro, "HydroBase::vel[1]"}, + {"initial_hydro", initial_hydro, "HydroBase::vel[2]"}, + {"initial_hydro", initial_hydro, "HydroBase::eps"}, + {"initial_hydro", initial_hydro, "HydroBase::press"}, + {"initial_Aphi", initial_Aphi, "HydroBase::Aphi"}, + {"initial_Avec", initial_Avec, "HydroBase::Avec[0]"}, + {"initial_Avec", initial_Avec, "HydroBase::Avec[1]"}, + {"initial_Avec", initial_Avec, "HydroBase::Avec[2]"}, + {"initial_Bvec", initial_Bvec, "HydroBase::Bvec[0]"}, + {"initial_Bvec", initial_Bvec, "HydroBase::Bvec[1]"}, + {"initial_Bvec", initial_Bvec, "HydroBase::Bvec[2]"}, + {"initial_Y_e", initial_Y_e, "HydroBase::Ye"}, + {"initial_temperature", initial_temperature, "HydroBase::temperature"}, + {"initial_entropy", initial_entropy, "HydroBase::entropy"}, + }; + + variable_is_read = malloc (CCTK_NumVars()); + assert (variable_is_read); + for (i=0; i= 0); + + for (i=0; i<(int)(sizeof(vars_to_read)/sizeof(vars_to_read[0])); ++i) { + if (CCTK_EQUALS(vars_to_read[i].paramvalue, "read from file")) { + int const ivar = CCTK_VarIndex (vars_to_read[i].varname); + assert (ivar >= 0); + if (! variable_is_read[ivar]) { + char * msg; + size_t written = Util_asprintf(&msg, + "'%s' is initialised using the file reader by '%s', but has not been scheduled to be read. Please set the parameter \"IO::filereader_ID_vars\" accordingly.", + vars_to_read[i].varname, + vars_to_read[i].paramname); + assert(written > 0); + CCTK_PARAMWARN (msg); + free(msg); + } + } + } + + free (variable_is_read); +} + +/** Mark a variable as to be read from the file reader. */ +static void callback (int idx, const char * optstring, void * callback_arg) +{ + assert (idx>=0 && idx