Skip to content

Atomic lint single step methods

hgratten requested to merge atomic_lint_single_step_methods into master

this merge request introduces the clang-tidied single-step methods chapter:

LectureCodes/SingleStepMethods/*:

  • removed cmake_minimum_required(VERSION 2.8), since the cmake version is better handled by the global CMakeLists.txt file
  • introduced const wherever possible
  • wrapped body statement of if-else, for, do while, and while in braces. increases readability and forgetting braces is a common source of bugs for students
  • avoided pointer arithmetic, instead used span, which is safe to index
  • replaced atoi with strtol since, atoi does not check the validity of the conversion and does not detect errors
  • avoided else after exit since it reduces readability of code flow and quickly causes bugs
  • reordered includes as good practice (user header first, then system headers, ordered alphabetically
  • ignored locally bugprone-exception-escape: a subroutine (e.g. rkf45) may throw an exception, but in this case we want the program to exit
  • introduced spaces where it improved readability (e.g. after commas)
  • removed unused main argc, argv
  • modernized function declaration
  • fixed typos
  • added comments or print statements for clarification
  • avoided indexing of std::array by non-const integer expression, since this gives a warning, even though it is logically safe. used std::vector instead
  • modernized return statements of e.g. std::pair with brace initialization instead of re-stating the return type to access its constructor
  • changed user files of ode45.h to accomodate new syntax
  • renamed _norm to defaultnorm since symbols with a leading underscore are reserved for the stdlib implementation
  • wrapped integratior options into a struct to avoid warnings due to easily swappable function parameters. this is less bugprone since the options have to be passed via explicit naming like in python {.T=T, .h0= T / 100, .reltol=rtol[j], .abstol=atol[j], .hmin=T / 1E6}

LectureCodes/SingleStepMethods/ode45/Eigen/ode45.hpp:

LectureCodes/SingleStepMethods/ode45/Eigen_new/ode45.h and /LectureCodes/SingleStepMethods/simpleblowupode45/Eigen/ode45.hpp

  • replaced the whole file by Utils/ode45.hpp or include to it, since they are (supposed to be) the same code

Utils/ode45.hpp:

  • marked function with [[nodiscard]] attribute to throw a warning if result is not used
  • when inheriting from std::exception, replaced deprecated throw() qualifier by noexcept override for the *what() function
  • marked single-argument constructors explicit, to avoid accidental implicit conversion of an argument into class object
  • replaced public member structs (options, statistics) by private members and made structs publicly visible for users. options can be passed by the user upon construction, statistics may be accessed in a read-only fashion after integration. this avoids public mutable members, which are a common source of bugs
  • avoided uninitialized members
  • replaced static const by constexpr to force evaluation at runtime and benefit from inlining
  • replaced static members by const members initialized in the constructor initialization list, which makes the code safer and more elegant
  • moved step size default initialization into its own member function to reduce complexity in the ode45<>::solve function

Merge request reports

Loading