cholla-hydro / cholla

A GPU-based hydro code
https://github.com/cholla-hydro/cholla/wiki
MIT License
60 stars 32 forks source link

Add a function to check that the configuration is correct #256

Closed bcaddy closed 1 year ago

bcaddy commented 1 year ago

General

I added a new function Check_Configuration to error_handling.cpp that checks that the compile configuration of Cholla and the parameter file are all correct. Currently it has some general checks and then all the checks for MHD but I suggest that we add more checks for different modules/build types.

Assertions

I used a couple main kinds of assertion or assertion like statements that I want to highlight for future additions

// Compile time assertion. Will throw a compiler error if it fails
static_assert(condition, message)

// Run time assertion. Will cause the program to abort if it fails. This doesn't 
// support a message explicitly but that can be worked around by adding a 
// message at the end with an `and` statement
assert(condition && "message")

// Compile time error for macros
#ifndef MACRO_HERE  // or any other #if like statement
  #error "message"
#endif  //! MACRO_HERE

// Compile time warning for macros
// #warning is technically only required by the C++23 standard however it is widely
// supported by compilers. If this gets to be a problem we can address it later
#ifndef MACRO_HERE  // or any other #if like statement
  #warning "message"  
#endif  //! MACRO_HERE

// Run time warning. Will print a message to standard error at run time
if (condition)
{
  std::cerr << message << std::endl;
}