-
Notifications
You must be signed in to change notification settings - Fork 57
Updating old examples for Diagnostic Variables changes
In GRChombo#119, we have added a new diagnostic variables feature which allows separating out diagnostic variables (quantities that are not part of your evolution system of equations) from evolution variables. The advantage of this separation is that these variables are no longer interpolated in time (which is a relatively expensive procedure) but in order to make it work we have had to rewrite code which will break existing examples so this page explains how to update them to make them compatible with the changes if you wish to merge the changes into your examples' branch.
There are also some optional changes which we made in GRChombo#124 if you use CCZ4 variables at the end of this page.
- As a reference this is the file for the BinaryBH example:
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/
#ifndef USERVARIABLES_HPP
#define USERVARIABLES_HPP
#include "ArrayTools.hpp"
#include "CCZ4UserVariables.hpp"
#include "DiagnosticVariables.hpp"
/// This enum gives the index of every variable stored in the grid
enum
{
// Note that it is important that the first enum value is set to 1 more than
// the last CCZ4 var enum
NUM_VARS = NUM_CCZ4_VARS,
};
namespace UserVariables
{
static const std::array<std::string, NUM_VARS> variable_names =
ccz4_variable_names;
} // namespace UserVariables
#include "UserVariables.inc.hpp"
#endif /* USERVARIABLES_HPP */-
You will either need to include an example-specific
DiagnosticVariables.hppfile (more complicated: see this section) orEmptyDiagnosticVariables.hpp(easier: see this section):#include "DiagnosticVariables.hpp"
-
You will need to change the type of
UserVariables::variable_namesi.e. replacestatic constexpr char const *variable_names[NUM_VARS] = {
with
static const std::array<std::string, NUM_VARS> variable_names = {
Note that you might need to add
#include <array> #include <string>
at the start of the file to make it work (the above example does not have this as these are included already in
CCZ4UserVariables.hpp). -
You will need to include
UserVariables.inc.hppat the end of the file:#include "UserVariables.inc.hpp"
- If present you will need to remove the declaration of the
specificWritePlotHeaderfunction. This interface is no longer supported and you should instead use theplot_varsparameter to specify which variables are in plot files.
-
As for the header file, remove the definition of
specificWritePlotHeaderif present. -
If you use the
WeylExtractionclass, note that it will assume thatWeyl4_ReandWeyl4_Imare diagnostic variables so make sure that these have been converted (see the Converting variables to diagnostic variables section) and thatBoxLoops::loops have been modified accordingly.
- If you have no variables you wish to convert to diagnostic variables or just want the quickest fix, and you don't use
WeylExtraction, you can just includeEmptyDiagnosticVariables.hppinstead of creating an example-specificDiagnosticVariables.hpp:#include "EmptyDiagnosticVariables.hpp"
-
As a reference, this is the file for the BinaryBH example:
/* GRChombo * Copyright 2012 The GRChombo collaboration. * Please refer to LICENSE in GRChombo's root directory. */ #ifndef DIAGNOSTICVARIABLES_HPP #define DIAGNOSTICVARIABLES_HPP // assign an enum to each variable enum { c_Ham, c_Mom1, c_Mom2, c_Mom3, c_Weyl4_Re, c_Weyl4_Im, NUM_DIAGNOSTIC_VARS }; namespace DiagnosticVariables { static const std::array<std::string, NUM_DIAGNOSTIC_VARS> variable_names = { "Ham", "Mom1", "Mom2", "Mom3", "Weyl4_Re", "Weyl4_Im"}; } #endif /* DIAGNOSTICVARIABLES_HPP */
-
If you wish to convert a variable to a diagnostic variable. you just need to remove its enumerator (e.g.
c_Weyl4_Re) from the enumeration inUserVariables.hppand add it to the enumeration inDiagnosticVariables.hpp. Make sure to remove the name fromUserVariables::variable_namesand add it toDiagnosticVariables::variable_namestoo in the corresponding place. -
The last enumerator in the
DiagnosticVariables.hppenumeration should beNUM_DIAGNOSTIC_VARSwhich is also what the length ofDiagnosticVariables::variable_namesshould be.
-
If you convert a variable to a diagnostic variable, check every
BoxLoops::loopwhere this variable is computed to ensure that theLevelData<FArrayBox> &outargument (third argument) ism_state_diagnostics. For example inBinaryBHLevel.cpp, the diagnostic variablesWeyl4_ReandWeyl4_Imare computed in:BoxLoops::loop(Weyl4(m_p.extraction_params.center, m_dx), m_state_new, m_state_diagnostics, EXCLUDE_GHOST_CELLS); -
This may mean that some compute packs will need to be split in order to loop separately with
m_state_newasout(for evolution variables) andm_state_diagnosticsasout(for diagnostic variables). -
There is no need to set diagnostic variables to zero initially as may have done previously (since the NaN checker probably only checks evolution variables in
m_state_new) so remove anySetValue(0.0,...)for them.
- Note that if you use the
AMRInterpolatorto interpolate variables which you have converted to diagnostic variables, you will need to specify this in the fourth argument when callingaddCompfor anInterpolationQuery. For example, if I wished to interpolateHamfor the BinaryBH example, I would use something likeint num_points = 100; std::vector<double> interp_out(num_points); InterpolationQuery query(num_points); query.addComp(c_Ham, interp_out.data(), Derivative::LOCAL, VariableType::diagnostic); ...
- If you use
SurfaceExtractionto interpolate, on a surface, variables which you have converted to diagnostic variables, you will need to specify this in the second argument when callingadd_var, for exampleadd_var(c_Ham, VariableType::diagnostic);
- Diagnostic variables are not saved in checkpoint files (since you don't need them for a restart) but you may save them in plot files by specifying the variable names in the
plot_varsparameter. - If you use the standard CCZ4 variables, you can include the
CCZ4UserVariables.hppfile in yourUserVariables.hppfile instead of specifying them all in your examples' enumeration.- The first normal evolution variable (or
NUM_VARSif there aren't any others) in the enumeration should be assigned the valueNUM_CCZ4_VARS. - If there are additional evolution variables (unlike the BinaryBH example e.g. matter variables), you can create
UserVariables::variable_namesby concatenatingccz4_variable_nameswithUserVariables::user_variable_namesusingArrayTools::concatenate(in theArrayTools.hppheader). For example, below isUserVariables.hppfor the ScalarField example:/* GRChombo * Copyright 2012 The GRChombo collaboration. * Please refer to LICENSE in GRChombo's root directory. */ #ifndef USERVARIABLES_HPP #define USERVARIABLES_HPP #include "ArrayTools.hpp" #include "CCZ4UserVariables.hpp" #include "DiagnosticVariables.hpp" // assign an enum to each variable enum { // Note that it is important that the first enum value is set to 1 more than // the last CCZ4 var enum c_phi = NUM_CCZ4_VARS, // matter field added c_Pi, //(minus) conjugate momentum NUM_VARS }; namespace UserVariables { static const std::array<std::string, NUM_VARS - NUM_CCZ4_VARS> user_variable_names = {"phi", "Pi"}; static const std::array<std::string, NUM_VARS> variable_names = ArrayTools::concatenate(ccz4_variable_names, user_variable_names); } // namespace UserVariables #include "UserVariables.inc.hpp" #endif /* USERVARIABLES_HPP */
- The first normal evolution variable (or
Copyright GRChombo 2018. Contact us for further details.