diff --git a/.clang-tidy b/.clang-tidy index 23167e93d0..cf29b759cd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,7 +20,7 @@ CheckOptions: value: 'MPI_Comm' - key: misc-include-cleaner.IgnoreHeaders - value: 'adios2/.*;bits/.*' + value: 'adios2/.*;bits/.*;cpptrace/.*' --- Disabled checks and reasons: diff --git a/.gitmodules b/.gitmodules index 4b33b3b615..2bdbd2a57b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "externalpackages/boutdata"] path = externalpackages/boutdata url = https://github.com/boutproject/boutdata.git +[submodule "externalpackages/cpptrace"] + path = externalpackages/cpptrace + url = https://github.com/ZedThree/cpptrace.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 44d100e444..a5ca6e8717 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -574,18 +574,6 @@ option(BOUT_ENABLE_SIGFPE "Signalling floating point exceptions" OFF) message(STATUS "Signalling floating point exceptions: BOUT_USE_SIGFPE=${BOUT_ENABLE_SIGFPE}") set(BOUT_USE_SIGFPE ${BOUT_ENABLE_SIGFPE}) -option(BOUT_ENABLE_BACKTRACE "Enable backtrace" ON) -if (BOUT_ENABLE_BACKTRACE) - find_program(ADDR2LINE_FOUND addr2line) - if (NOT ADDR2LINE_FOUND) - message(FATAL_ERROR "addr2line not found. Disable backtrace by setting BOUT_ENABLE_BACKTRACE=Off") - endif() - target_link_libraries(bout++ PUBLIC ${CMAKE_DL_LIBS}) - set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -l${CMAKE_DL_LIBS}") -endif() -message(STATUS "Enable backtrace: BOUT_USE_BACKTRACE=${BOUT_ENABLE_BACKTRACE}") -set(BOUT_USE_BACKTRACE ${BOUT_ENABLE_BACKTRACE}) - option(BOUT_ENABLE_METRIC_3D "Enable 3D metric support" OFF) if(BOUT_ENABLE_METRIC_3D) set(BOUT_METRIC_TYPE "3D") @@ -830,6 +818,9 @@ endif() if (NOT BOUT_USE_SYSTEM_FMT) set(FMT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") endif() +if (NOT BOUT_USE_SYSTEM_CPPTRACE) + set(CPPTRACE_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") +endif() set(BOUT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") # We don't need the build include path any more string(REPLACE "-I${CMAKE_CURRENT_BINARY_DIR}/include" "" CONFIG_CFLAGS "${CONFIG_CFLAGS}") @@ -958,7 +949,6 @@ message(" Output coloring : ${BOUT_USE_COLOR} Field name tracking : ${BOUT_USE_TRACK} Floating point exceptions: ${BOUT_USE_SIGFPE} - Backtrace enabled : ${BOUT_USE_BACKTRACE} RAJA enabled : ${BOUT_HAS_RAJA} Umpire enabled : ${BOUT_HAS_UMPIRE} Caliper enabled : ${BOUT_HAS_CALIPER} diff --git a/bin/bout-add-mod-path b/bin/bout-add-mod-path index 9faf1be3de..ee7ea66d25 100755 --- a/bin/bout-add-mod-path +++ b/bin/bout-add-mod-path @@ -104,8 +104,7 @@ def create_mod(modulepath, name, top, build): else: prereq = "" with open(filename, "w") as f: - f.write( - f"""#%Module 1.0 + f.write(f"""#%Module 1.0 # # BOUT++ module for use with 'environment-modules' package # Created by bout-add-mod-path v0.9 @@ -119,17 +118,14 @@ setenv BOUT_TOP {top} prepend-path PATH {top}/bin prepend-path PYTHONPATH {top}/tools/pylib prepend-path IDL_PATH +{top}/tools/idllib:'' -""" - ) +""") if build != top: - f.write( - f"""#%Module 1.0 + f.write(f"""#%Module 1.0 setenv BOUT_BUILD {build} prepend-path PATH {build}/bin prepend-path LD_LIBRARY_PATH {build}/lib prepend-path PYTHONPATH {build}/tools/pylib -""" - ) +""") print(f"created `{filename}`") diff --git a/bin/bout-pylib-cmd-to-bin b/bin/bout-pylib-cmd-to-bin index 8f88a5dbf4..8d6dbed7ae 100755 --- a/bin/bout-pylib-cmd-to-bin +++ b/bin/bout-pylib-cmd-to-bin @@ -126,8 +126,7 @@ def createwrapper(mod, func_name, func, name): out += end f.write(out) - fprint( - """#!/usr/bin/env python3 + fprint("""#!/usr/bin/env python3 # PYTHON_ARGCOMPLETE_OK import argparse @@ -136,8 +135,7 @@ try: except ImportError: argcomplete=None -""" - ) +""") doc = True para = False ret = False @@ -183,19 +181,16 @@ except ImportError: arg_help[curarg].append(esc(blas)) # Print functions that are needed if "str_to_slice" in arg_type.values(): - fprint( - """ + fprint(""" def str_to_slice(sstr): args=[] for s in sstr.split(','): args.append(int(s)) print(args) return slice(*args) -""" - ) +""") if "str_to_bool" in arg_type.values(): - fprint( - """ + fprint(""" def str_to_bool(sstr): low=sstr.lower() # no or false @@ -206,8 +201,7 @@ def str_to_bool(sstr): return True else: raise ArgumentTypeError("Cannot parse %s to bool type"%sstr) -""" - ) +""") # Create the parser fprint("parser = argparse.ArgumentParser(%s)" % (esc(docs))) spec = inspect.signature(func) @@ -247,24 +241,19 @@ def str_to_bool(sstr): pre = "\n " fprint(")") - fprint( - """ + fprint(""" if argcomplete: argcomplete.autocomplete(parser) -# late import for faster auto-complete""" - ) +# late import for faster auto-complete""") fprint("from %s import %s" % (mod, func_name)) - fprint( - """ + fprint(""" args = parser.parse_args() # Call the function %s, using command line arguments %s(**args.__dict__) -""" - % (func_name, func_name) - ) +""" % (func_name, func_name)) # alternative, but I think 0o755 is easier to read # import stat # os.chmod(filename,stat.S_IRWXU|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH) diff --git a/bin/bout-v5-factory-upgrader.py b/bin/bout-v5-factory-upgrader.py index 29fc07db30..ee24572a94 100755 --- a/bin/bout-v5-factory-upgrader.py +++ b/bin/bout-v5-factory-upgrader.py @@ -5,7 +5,6 @@ import difflib import re - # Dictionary of factory methods that may need updating factories = { "Interpolation": { @@ -62,9 +61,7 @@ def find_factory_calls(factory, source): \s*=\s* {factory_name}:: .*{create_method}.* - """.format( - **factory - ), + """.format(**factory), source, re.VERBOSE, ) @@ -75,9 +72,7 @@ def find_type_pointers(factory, source): r""" \b{type_name}\s*\*\s* # Type name and pointer ([\w_]+)\s*; # Variable name - """.format( - **factory - ), + """.format(**factory), source, re.VERBOSE, ) @@ -107,9 +102,7 @@ def fix_declarations(factory, variables, source): (.*?)(class\s*)? # optional "class" keyword \b({type_name})\s*\*\s* # Type-pointer ({variable_name})\s*; # Variable - """.format( - type_name=factory["type_name"], variable_name=variable - ), + """.format(type_name=factory["type_name"], variable_name=variable), r"\1std::unique_ptr<\3> \4{nullptr};", source, flags=re.VERBOSE, @@ -123,9 +116,7 @@ def fix_declarations(factory, variables, source): ({variable_name})\s* # Variable =\s* # Assignment from factory ({factory_name}::.*{create_method}.*); - """.format( - variable_name=variable, **factory - ), + """.format(variable_name=variable, **factory), r"\1auto \4 = \5;", source, flags=re.VERBOSE, @@ -139,9 +130,7 @@ def fix_declarations(factory, variables, source): ({variable_name})\s* # Variable =\s* # Assignment (0|nullptr|NULL); - """.format( - variable_name=variable, **factory - ), + """.format(variable_name=variable, **factory), r"\1std::unique_ptr<\2> \3{nullptr};", source, flags=re.VERBOSE, diff --git a/bin/bout-v5-format-upgrader.py b/bin/bout-v5-format-upgrader.py index 7c7d13ac7f..a534ca240a 100755 --- a/bin/bout-v5-format-upgrader.py +++ b/bin/bout-v5-format-upgrader.py @@ -5,7 +5,6 @@ import difflib import re - format_replacements = { "c": "c", "d": "d", diff --git a/bin/bout-v5-header-upgrader.py b/bin/bout-v5-header-upgrader.py index 49a8fbcbe4..77794ab920 100755 --- a/bin/bout-v5-header-upgrader.py +++ b/bin/bout-v5-header-upgrader.py @@ -9,7 +9,6 @@ from typing import List from subprocess import run - header_shim_sentinel = "// BOUT++ header shim" header_warning = f"""\ @@ -122,8 +121,7 @@ def create_patch(filename, original, modified): if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=textwrap.dedent( - """\ + description=textwrap.dedent("""\ Fix deprecated header locations for BOUT++ v4 -> v5 All BOUT++ headers are now under ``include/bout`` and @@ -142,8 +140,7 @@ def create_patch(filename, original, modified): If you have staged changes, this tool will not work, so to avoid committing undesired or unrelated changes. - """ - ), + """), ) parser.add_argument( diff --git a/bin/bout-v5-input-file-upgrader.py b/bin/bout-v5-input-file-upgrader.py index e2940ff58a..ea979005d5 100755 --- a/bin/bout-v5-input-file-upgrader.py +++ b/bin/bout-v5-input-file-upgrader.py @@ -271,8 +271,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False): if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=textwrap.dedent( - """\ + description=textwrap.dedent("""\ Fix input files for BOUT++ v5+ Please note that this will only fix input options in sections with @@ -300,8 +299,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False): Files that change in this way will have the "canonicalisation" patch presented first. If you choose not to apply this patch, the "upgrade - fixer" patch will still include it.""" - ), + fixer" patch will still include it."""), ) parser.add_argument("files", action="store", nargs="+", help="Input files") diff --git a/bin/bout-v5-macro-upgrader.py b/bin/bout-v5-macro-upgrader.py index 11b4926255..d644fed9e8 100755 --- a/bin/bout-v5-macro-upgrader.py +++ b/bin/bout-v5-macro-upgrader.py @@ -342,8 +342,7 @@ def create_patch(filename, original, modified): if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=textwrap.dedent( - """\ + description=textwrap.dedent("""\ Fix macro defines for BOUT++ v4 -> v5 Please note that this is only slightly better than dumb text replacement. It @@ -359,8 +358,7 @@ def create_patch(filename, original, modified): still replace them in strings or comments. Please check the diff output carefully! - """ - ), + """), ) parser.add_argument("files", action="store", nargs="+", help="Input files") diff --git a/bin/bout-v5-physics-model-upgrader.py b/bin/bout-v5-physics-model-upgrader.py index 26fb8ef6e0..260d1d59ee 100755 --- a/bin/bout-v5-physics-model-upgrader.py +++ b/bin/bout-v5-physics-model-upgrader.py @@ -8,7 +8,6 @@ import textwrap import warnings - PHYSICS_MODEL_INCLUDE = '#include "bout/physicsmodel.hxx"' PHYSICS_MODEL_SKELETON = """ @@ -213,13 +212,11 @@ def fix_bout_constrain(source, error_on_warning): "\n ".join(["{}:{}".format(i, source_lines[i]) for i in line_range]) ) - message = textwrap.dedent( - """\ + message = textwrap.dedent("""\ Some uses of `bout_constrain` remain, but we could not automatically convert them to use `Solver::constraint`. Please fix them before continuing: - """ - ) + """) message += " " + "\n ".join(lines_context) if error_on_warning: @@ -389,8 +386,7 @@ def create_patch(filename, original, modified): if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=textwrap.dedent( - """\ + description=textwrap.dedent("""\ Upgrade legacy physics models to use the PhysicsModel class This will do the bare minimum required to compile, and @@ -403,8 +399,7 @@ def create_patch(filename, original, modified): By default, this will use the file name stripped of file extensions as the name of the new class. Use '--name=' to give a different name. - """ - ), + """), ) parser.add_argument("files", action="store", nargs="+", help="Files to fix") diff --git a/bin/bout-v5-xzinterpolation-upgrader.py b/bin/bout-v5-xzinterpolation-upgrader.py index 37c79e0de8..e70c3c54ae 100755 --- a/bin/bout-v5-xzinterpolation-upgrader.py +++ b/bin/bout-v5-xzinterpolation-upgrader.py @@ -54,9 +54,7 @@ def fix_header_includes(old_header, new_header, source): (<|") ({header}) # Header name (>|") - """.format( - header=old_header - ), + """.format(header=old_header), r"\1\2{header}\4".format(header=new_header), source, flags=re.VERBOSE, @@ -67,9 +65,7 @@ def fix_interpolations(old_interpolation, new_interpolation, source): return re.sub( r""" \b{}\b - """.format( - old_interpolation - ), + """.format(old_interpolation), r"{}".format(new_interpolation), source, flags=re.VERBOSE, @@ -120,9 +116,7 @@ def fix_factories(old_factory, new_factory, source): return re.sub( r""" \b{}\b - """.format( - old_factory - ), + """.format(old_factory), r"{}".format(new_factory), source, flags=re.VERBOSE, diff --git a/bin/update_version_number_in_files.py b/bin/update_version_number_in_files.py index ec9a31bc32..3e9758a8c1 100755 --- a/bin/update_version_number_in_files.py +++ b/bin/update_version_number_in_files.py @@ -158,8 +158,7 @@ def create_patch(filename, original, modified): if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=textwrap.dedent( - """\ + description=textwrap.dedent("""\ Update the software version number to the specified version, to be given in the form major.minor.patch, e.g. 5.10.3 @@ -172,8 +171,7 @@ def create_patch(filename, original, modified): the 'minor' version number of the provided version will be incremented by 1, e.g. 5.10.3 -> 5.11.3 - """ - ), + """), ) parser.add_argument( diff --git a/bout++Config.cmake.in b/bout++Config.cmake.in index d461e58e4b..a8cf041901 100644 --- a/bout++Config.cmake.in +++ b/bout++Config.cmake.in @@ -6,7 +6,6 @@ set(BOUT_USE_SIGNAL @BOUT_USE_SIGNAL@) set(BOUT_USE_COLOR @BOUT_USE_COLOR@) set(BOUT_USE_TRACK @BOUT_USE_TRACK@) set(BOUT_USE_SIGFPE @BOUT_USE_SIGFPE@) -set(BOUT_USE_BACKTRACE @BOUT_USE_BACKTRACE@) set(BOUT_USE_OPENMP @BOUT_USE_OPENMP@) set(BOUT_HAS_CUDA @BOUT_HAS_CUDA@) set(BOUT_HAS_OUTPUT_DEBUG @BOUT_HAS_OUTPUT_DEBUG@) @@ -109,6 +108,14 @@ elseif(EXISTS "@ADIOS2_BINARY_DIR@") # If we downloaded ADIOS2, then we need to add its build directory to our search paths list(APPEND CMAKE_PREFIX_PATH "@ADIOS2_BINARY_DIR@") endif() +if(EXISTS "@cpptrace_ROOT@") + set(cpptrace_ROOT "@cpptrace_ROOT@") +elseif(EXISTS "@cpptrace_BINARY_DIR@") + list(APPEND CMAKE_PREFIX_PATH "@cpptrace_BINARY_DIR@") + list(APPEND CMAKE_PREFIX_PATH "@cpptrace_BINARY_DIR@/cmake") + list(APPEND CMAKE_PREFIX_PATH "@libdwarf_BINARY_DIR@/src/lib/libdwarf") + list(APPEND CMAKE_PREFIX_PATH "@zstd_BINARY_DIR@") +endif() if(@BOUT_USE_SYSTEM_MPARK_VARIANT@) set(mpark_variant_ROOT "@mpark_variant_ROOT@") @@ -160,6 +167,7 @@ if (BOUT_HAS_GETTEXT) endif() find_dependency(mpark_variant @mpark_variant_VERSION@) find_dependency(fmt @fmt_VERSION@) +find_dependency(cpptrace @cpptrace_VERSION@) if (BOUT_HAS_SLEPC) find_dependency(SLEPc @SLEPC_VERSION@) endif() diff --git a/cmake/SetupBOUTThirdParty.cmake b/cmake/SetupBOUTThirdParty.cmake index 1256fbbeba..52b7468012 100644 --- a/cmake/SetupBOUTThirdParty.cmake +++ b/cmake/SetupBOUTThirdParty.cmake @@ -369,3 +369,25 @@ if (BOUT_USE_UUID_SYSTEM_GENERATOR) endif() message(STATUS "UUID_SYSTEM_GENERATOR: ${BOUT_USE_UUID_SYSTEM_GENERATOR}") set(BOUT_HAS_UUID_SYSTEM_GENERATOR ${BOUT_USE_UUID_SYSTEM_GENERATOR}) + +cmake_dependent_option(BOUT_USE_SYSTEM_CPPTRACE "Use external installation of cpptrace" OFF + "BOUT_UPDATE_GIT_SUBMODULE OR EXISTS ${PROJECT_SOURCE_DIR}/externalpackages/cpptrace/CMakeLists.txt" ON) + +if(BOUT_USE_SYSTEM_CPPTRACE) + message(STATUS "Using external cpptrace") + find_package(cpptrace REQUIRED) + get_target_property(CPPTRACE_INCLUDE_PATH cpptrace::cpptrace INTERFACE_INCLUDE_DIRECTORIES) +else() + message(STATUS "Using cpptrace submodule") + bout_update_submodules() + # Need a fork with some fixes for CMake + set(CPPTRACE_LIBDWARF_REPO "https://github.com/ZedThree/libdwarf-lite.git" CACHE STRING "" FORCE) + set(CPPTRACE_LIBDWARF_TAG "ebe10a39afd56b8247de633bfe17666ad50ab95e" CACHE STRING "" FORCE) + add_subdirectory(externalpackages/cpptrace) + if(NOT TARGET cpptrace::cpptrace) + message(FATAL_ERROR "cpptrace not found! Have you disabled the git submodules (BOUT_UPDATE_GIT_SUBMODULE)?") + endif() + set(CPPTRACE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externalpackages/cpptrace/include") +endif() +set(CONFIG_CFLAGS "${CONFIG_CFLAGS} -I\${CPPTRACE_INCLUDE_PATH}") +target_link_libraries(bout++ PUBLIC cpptrace::cpptrace) diff --git a/cmake_build_defines.hxx.in b/cmake_build_defines.hxx.in index 4d63a01b7d..9c73679f29 100644 --- a/cmake_build_defines.hxx.in +++ b/cmake_build_defines.hxx.in @@ -21,7 +21,6 @@ #cmakedefine01 BOUT_HAS_SLEPC #cmakedefine01 BOUT_HAS_SUNDIALS #cmakedefine01 BOUT_HAS_UUID_SYSTEM_GENERATOR -#cmakedefine01 BOUT_USE_BACKTRACE #cmakedefine01 BOUT_USE_COLOR #cmakedefine01 BOUT_USE_OPENMP #cmakedefine01 BOUT_USE_OUTPUT_DEBUG @@ -39,4 +38,7 @@ // CMake build does not support legacy interface #define BOUT_HAS_LEGACY_NETCDF 0 +// We now always turn this on +#define BOUT_USE_BACKTRACE 1 + #endif // BOUT_BUILD_CONFIG_HXX diff --git a/examples/6field-simple/elm_6f.cxx b/examples/6field-simple/elm_6f.cxx index 40e4f7b3b3..24256333df 100644 --- a/examples/6field-simple/elm_6f.cxx +++ b/examples/6field-simple/elm_6f.cxx @@ -273,8 +273,6 @@ class Elm_6f : public PhysicsModel { * This function implements d2/dy2 where y is the poloidal coordinate theta */ - TRACE("Grad2_par2new( Field3D )"); - Field3D result = D2DY2(f); #if BOUT_USE_TRACK @@ -342,8 +340,6 @@ class Elm_6f : public PhysicsModel { // Parallel gradient along perturbed field-line Field3D Grad_parP(const Field3D& f, CELL_LOC loc = CELL_DEFAULT) { - TRACE("Grad_parP"); - Field3D result; if (parallel_lagrange || parallel_project) { diff --git a/examples/elm-pb-outerloop/elm_pb_outerloop.cxx b/examples/elm-pb-outerloop/elm_pb_outerloop.cxx index 4ff8e90dcb..3cc5227b30 100644 --- a/examples/elm-pb-outerloop/elm_pb_outerloop.cxx +++ b/examples/elm-pb-outerloop/elm_pb_outerloop.cxx @@ -39,7 +39,6 @@ #include #include #include -#include #include #include // Defines BOUT_FOR_RAJA #include diff --git a/examples/elm-pb/elm_pb.cxx b/examples/elm-pb/elm_pb.cxx index fe18a756ae..643f36f5bb 100644 --- a/examples/elm-pb/elm_pb.cxx +++ b/examples/elm-pb/elm_pb.cxx @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/examples/invertable_operator/invertable_operator.cxx b/examples/invertable_operator/invertable_operator.cxx index 57f9e24b08..99db7f7a1e 100644 --- a/examples/invertable_operator/invertable_operator.cxx +++ b/examples/invertable_operator/invertable_operator.cxx @@ -1,5 +1,4 @@ #include -#include #include #include @@ -26,7 +25,7 @@ class HW : public PhysicsModel { // Drop C term for now Field3D operator()(const Field3D& input) { - TRACE("myLaplacian::operator()"); + Timer timer("invertable_operator_operate"); Field3D result = A * input + D * Delp2(input); @@ -43,7 +42,7 @@ class HW : public PhysicsModel { // Drop C term for now Field3D operator()(const Field3D& input) { - TRACE("myLaplacian::operator()"); + Timer timer("invertable_operator_operate"); Field3D result = A * input + B * Laplace_perp(input); if (withDiv) { diff --git a/externalpackages/cpptrace b/externalpackages/cpptrace new file mode 160000 index 0000000000..027f9aee2d --- /dev/null +++ b/externalpackages/cpptrace @@ -0,0 +1 @@ +Subproject commit 027f9aee2d34dbe1c98f26224e1fbe1654cb4aae diff --git a/include/bout/bout_enum_class.hxx b/include/bout/bout_enum_class.hxx index 585e5b020e..6f632747ed 100644 --- a/include/bout/bout_enum_class.hxx +++ b/include/bout/bout_enum_class.hxx @@ -22,13 +22,12 @@ #ifndef BOUT_ENUM_CLASS_H #define BOUT_ENUM_CLASS_H -#include "bout/boutexception.hxx" +#include "bout/boutexception.hxx" // IWYU pragma: keep #include "bout/macro_for_each.hxx" -#include "bout/msg_stack.hxx" -#include "bout/options.hxx" +#include "bout/options.hxx" // IWYU pragma: keep -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep /// Create some macro magic similar to bout/macro_for_each.hxx, but allowing for the enum /// class name to be passed through to each _call @@ -70,7 +69,7 @@ enum class enumname { __VA_ARGS__ }; \ \ inline std::string toString(enumname e) { \ - AUTO_TRACE(); \ + \ const static std::map toString_map = { \ BOUT_ENUM_CLASS_MAP_ARGS(BOUT_ENUM_CLASS_STR, enumname, __VA_ARGS__)}; \ auto found = toString_map.find(e); \ @@ -81,16 +80,17 @@ } \ \ inline enumname BOUT_MAKE_FROMSTRING_NAME(enumname)(const std::string& s) { \ - AUTO_TRACE(); \ + \ const static std::map fromString_map = { \ BOUT_ENUM_CLASS_MAP_ARGS(BOUT_STR_ENUM_CLASS, enumname, __VA_ARGS__)}; \ auto found = fromString_map.find(s); \ if (found == fromString_map.end()) { \ - std::string valid_values {}; \ + std::string valid_values{}; \ for (auto const& entry : fromString_map) { \ valid_values += std::string(" ") + entry.first; \ } \ - throw BoutException("Did not find enum {:s}. Valid values: {:s}", s, valid_values); \ + throw BoutException("Did not find enum {:s}. Valid values: {:s}", s, \ + valid_values); \ } \ return found->second; \ } \ diff --git a/include/bout/boutexception.hxx b/include/bout/boutexception.hxx index ffd4a03a6c..565eb6b46d 100644 --- a/include/bout/boutexception.hxx +++ b/include/bout/boutexception.hxx @@ -1,9 +1,6 @@ #ifndef BOUT_EXCEPTION_H #define BOUT_EXCEPTION_H -#include "bout/build_defines.hxx" - -#include #include #include #include @@ -35,14 +32,13 @@ public: /// backtrace (if available) std::string getBacktrace() const; + static void enableBacktrace() { show_backtrace = true; } + static void disableBacktrace() { show_backtrace = false; } + private: std::string message; -#if BOUT_USE_BACKTRACE - static constexpr unsigned int TRACE_MAX = 128; - std::array trace{}; - int trace_size; - char** messages; -#endif + + static bool show_backtrace; }; class BoutRhsFail : public BoutException { diff --git a/include/bout/coordinates.hxx b/include/bout/coordinates.hxx index d7c80ed8bc..e7ead42ee5 100644 --- a/include/bout/coordinates.hxx +++ b/include/bout/coordinates.hxx @@ -33,10 +33,11 @@ #ifndef BOUT_COORDINATES_H #define BOUT_COORDINATES_H -#include "bout/bout_types.hxx" -#include "bout/field2d.hxx" -#include "bout/field3d.hxx" -#include "bout/paralleltransform.hxx" +#include +#include +#include +#include +#include class Mesh; diff --git a/include/bout/cyclic_reduction.hxx b/include/bout/cyclic_reduction.hxx index d4c0920910..cf54b63059 100644 --- a/include/bout/cyclic_reduction.hxx +++ b/include/bout/cyclic_reduction.hxx @@ -47,7 +47,6 @@ //#define DIAGNOSE 1 #include "mpi.h" -#include "bout/msg_stack.hxx" #include "bout/utils.hxx" #include @@ -118,7 +117,6 @@ public: /// @param[in] b Diagonal values. Should have size [nsys][N] /// @param[in] c Right diagonal. Should have size [nsys][N] void setCoefs(const Matrix& a, const Matrix& b, const Matrix& c) { - TRACE("CyclicReduce::setCoefs"); int nsys = std::get<0>(a.shape()); @@ -169,7 +167,7 @@ public: /// @param[in] rhs Matrix storing Values of the rhs for each system /// @param[out] x Matrix storing the result for each system void solve(const Matrix& rhs, Matrix& x) { - TRACE("CyclicReduce::solve"); + ASSERT2(static_cast(std::get<0>(rhs.shape())) == Nsys); ASSERT2(static_cast(std::get<0>(x.shape())) == Nsys); ASSERT2(static_cast(std::get<1>(rhs.shape())) == N); diff --git a/include/bout/deriv_store.hxx b/include/bout/deriv_store.hxx index 6dc44c76ad..b2b7928c2e 100644 --- a/include/bout/deriv_store.hxx +++ b/include/bout/deriv_store.hxx @@ -29,6 +29,7 @@ #ifndef __DERIV_STORE_HXX__ #define __DERIV_STORE_HXX__ +#include #include #include #include @@ -38,7 +39,6 @@ #include #include -#include #include /// Here we have a templated singleton that is used to store DerivativeFunctions @@ -75,21 +75,14 @@ struct DerivativeStore { } /// Report if store has any registered methods - bool isEmpty() const { - AUTO_TRACE(); - return registeredMethods.empty(); - }; + bool isEmpty() const { return registeredMethods.empty(); }; /// Report if store has any registered methods for specific type determined by key - bool isEmpty(std::size_t key) const { - AUTO_TRACE(); - return registeredMethods.count(key) == 0; - } + bool isEmpty(std::size_t key) const { return registeredMethods.count(key) == 0; } /// Report if store has any registered methods for specific type bool isEmpty(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); // Get the key auto key = getKey(direction, stagger, toString(derivType)); @@ -100,7 +93,6 @@ struct DerivativeStore { /// specified derivative type, direction and stagger. std::set getAvailableMethods(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); // Get the key auto key = getKey(direction, stagger, toString(derivType)); @@ -115,7 +107,6 @@ struct DerivativeStore { /// specified derivative type, direction and stagger. void listAvailableMethods(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); // Introductory information output_info << "Available methods for derivative type '"; @@ -134,7 +125,7 @@ struct DerivativeStore { /// depends on the derivType input. void registerDerivative(standardFunc func, DERIV derivType, DIRECTION direction, STAGGER stagger, std::string methodName) { - AUTO_TRACE(); + const auto key = getKey(direction, stagger, methodName); switch (derivType) { @@ -176,7 +167,7 @@ struct DerivativeStore { /// depends on the derivType input. void registerDerivative(upwindFunc func, DERIV derivType, DIRECTION direction, STAGGER stagger, std::string methodName) { - AUTO_TRACE(); + const auto key = getKey(direction, stagger, methodName); switch (derivType) { @@ -210,14 +201,14 @@ struct DerivativeStore { template void registerDerivative(standardFunc func, Direction direction, Stagger stagger, Method method) { - AUTO_TRACE(); + registerDerivative(func, method.meta.derivType, direction.lookup(), stagger.lookup(), method.meta.key); } template void registerDerivative(upwindFunc func, Direction direction, Stagger stagger, Method method) { - AUTO_TRACE(); + registerDerivative(func, method.meta.derivType, direction.lookup(), stagger.lookup(), method.meta.key); } @@ -231,7 +222,6 @@ struct DerivativeStore { STAGGER stagger = STAGGER::None, DERIV derivType = DERIV::Standard) const { - AUTO_TRACE(); const auto realName = nameLookup( name, defaultMethods.at(getKey(direction, stagger, toString(derivType)))); const auto key = getKey(direction, stagger, realName); @@ -262,20 +252,20 @@ struct DerivativeStore { standardFunc getStandard2ndDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); + return getStandardDerivative(name, direction, stagger, DERIV::StandardSecond); }; standardFunc getStandard4thDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); + return getStandardDerivative(name, direction, stagger, DERIV::StandardFourth); }; flowFunc getFlowDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None, DERIV derivType = DERIV::Upwind) const { - AUTO_TRACE(); + const auto realName = nameLookup( name, defaultMethods.at(getKey(direction, stagger, toString(derivType)))); const auto key = getKey(direction, stagger, realName); @@ -305,18 +295,17 @@ struct DerivativeStore { upwindFunc getUpwindDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); + return getFlowDerivative(name, direction, stagger, DERIV::Upwind); }; fluxFunc getFluxDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); + return getFlowDerivative(name, direction, stagger, DERIV::Flux); }; void initialise(Options* options) { - AUTO_TRACE(); // To replicate the existing behaviour we first search for a section called //"dd?" and if the option isn't in there we search a section called "diff" @@ -490,7 +479,7 @@ private: std::string getMethodName(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const { - AUTO_TRACE(); + return name + " (" + toString(direction) + ", " + toString(stagger) + ")"; }; @@ -506,7 +495,7 @@ private: /// methods with the same function interface in the same map, which /// might be nice. std::size_t getKey(DIRECTION direction, STAGGER stagger, std::string key) const { - AUTO_TRACE(); + // Note this key is indepedent of the field type (and hence the // key is the same for 3D/2D fields) as we have to use different // maps to store the different field types as the signature is @@ -524,7 +513,7 @@ private: /// that can be used to account for run-time choices template std::size_t getKey() const { - AUTO_TRACE(); + // Note this key is indepedent of the field type (and hence the // key is the same for 3D/2D fields) as we have to use different // maps to store the different field types as the signature is diff --git a/include/bout/field.hxx b/include/bout/field.hxx index 61edff6723..4e41aa3632 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -30,14 +30,12 @@ class Field; #define FIELD_H #include -#include #include #include "bout/bout_types.hxx" #include "bout/boutcomm.hxx" #include "bout/boutexception.hxx" #include "bout/field_data.hxx" -#include "bout/msg_stack.hxx" #include "bout/region.hxx" #include "bout/traits.hxx" #include "bout/utils.hxx" @@ -239,7 +237,6 @@ namespace bout { template inline void checkFinite(const T& f, const std::string& name = "field", const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); if (!f.isAllocated()) { throw BoutException("{:s} is not allocated", name); @@ -263,7 +260,6 @@ inline void checkFinite(const T& f, const std::string& name = "field", template inline void checkPositive(const T& f, const std::string& name = "field", const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); if (!f.isAllocated()) { throw BoutException("{:s} is not allocated", name); @@ -307,7 +303,6 @@ inline T fromFieldAligned(const T& f, const std::string& region = "RGN_ALL") { template > inline BoutReal min(const T& f, bool allpe = false, const std::string& rgn = "RGN_NOBNDRY") { - AUTO_TRACE(); checkData(f); @@ -392,7 +387,6 @@ inline BoutReal getUniform(const T& f, [[maybe_unused]] bool allpe = false, template > inline BoutReal max(const T& f, bool allpe = false, const std::string& rgn = "RGN_NOBNDRY") { - AUTO_TRACE(); checkData(f); @@ -426,7 +420,6 @@ inline BoutReal max(const T& f, bool allpe = false, template > inline BoutReal mean(const T& f, bool allpe = false, const std::string& rgn = "RGN_NOBNDRY") { - AUTO_TRACE(); checkData(f); @@ -457,7 +450,6 @@ inline BoutReal mean(const T& f, bool allpe = false, /// If CHECK >= 3 then the result will be checked for non-finite numbers template > T pow(const T& lhs, const T& rhs, const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); ASSERT1(areFieldsCompatible(lhs, rhs)); @@ -471,7 +463,6 @@ T pow(const T& lhs, const T& rhs, const std::string& rgn = "RGN_ALL") { template > T pow(const T& lhs, BoutReal rhs, const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); // Check if the inputs are allocated checkData(lhs); @@ -487,7 +478,6 @@ T pow(const T& lhs, BoutReal rhs, const std::string& rgn = "RGN_ALL") { template > T pow(BoutReal lhs, const T& rhs, const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); // Check if the inputs are allocated checkData(lhs); @@ -524,7 +514,7 @@ T pow(BoutReal lhs, const T& rhs, const std::string& rgn = "RGN_ALL") { #define FIELD_FUNC(name, func) \ template > \ inline T name(const T& f, const std::string& rgn = "RGN_ALL") { \ - AUTO_TRACE(); \ + \ /* Check if the input is allocated */ \ checkData(f); \ /* Define and allocate the output result */ \ @@ -632,7 +622,6 @@ FIELD_FUNC(tanh, ::tanh) /// default (can be changed using the \p rgn argument template > inline bool finite(const T& f, const std::string& rgn = "RGN_ALL") { - AUTO_TRACE(); if (!f.isAllocated()) { return false; diff --git a/include/bout/fv_ops.hxx b/include/bout/fv_ops.hxx index 94007a57a2..ce98e03008 100644 --- a/include/bout/fv_ops.hxx +++ b/include/bout/fv_ops.hxx @@ -5,11 +5,11 @@ #ifndef BOUT_FV_OPS_H #define BOUT_FV_OPS_H +#include "bout/build_defines.hxx" #include "bout/field3d.hxx" #include "bout/globals.hxx" -#include "bout/vector2d.hxx" - #include "bout/utils.hxx" +#include "bout/vector2d.hxx" #include namespace FV { diff --git a/include/bout/hypre_interface.hxx b/include/bout/hypre_interface.hxx index ae392de4f3..65d8875a9a 100644 --- a/include/bout/hypre_interface.hxx +++ b/include/bout/hypre_interface.hxx @@ -444,19 +444,19 @@ public: value = matrix->getVal(row, column); } Element& operator=(const Element& other) { - AUTO_TRACE(); + ASSERT3(finite(static_cast(other))); return *this = static_cast(other); } Element& operator=(BoutReal value_) { - AUTO_TRACE(); + ASSERT3(finite(value_)); value = value_; setValues(value); return *this; } Element& operator+=(BoutReal value_) { - AUTO_TRACE(); + ASSERT3(finite(value_)); auto column_position = std::find(cbegin(positions), cend(positions), column); if (column_position != cend(positions)) { diff --git a/include/bout/index_derivs.hxx b/include/bout/index_derivs.hxx index 456f98f8c2..ccce9a7f5e 100644 --- a/include/bout/index_derivs.hxx +++ b/include/bout/index_derivs.hxx @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -84,7 +83,7 @@ class DerivativeType { public: template void standard(const T& var, T& result, const std::string& region) const { - AUTO_TRACE(); + ASSERT2(meta.derivType == DERIV::Standard || meta.derivType == DERIV::StandardSecond || meta.derivType == DERIV::StandardFourth) ASSERT2(var.getMesh()->getNguard(direction) >= nGuards); @@ -98,7 +97,7 @@ public: template void upwindOrFlux(const T& vel, const T& var, T& result, const std::string& region) const { - AUTO_TRACE(); + ASSERT2(meta.derivType == DERIV::Upwind || meta.derivType == DERIV::Flux) ASSERT2(var.getMesh()->getNguard(direction) >= nGuards); @@ -133,7 +132,7 @@ struct registerMethod { template void operator()(Direction, Stagger, FieldTypeContainer, Method) { - AUTO_TRACE(); + using namespace std::placeholders; // Now we want to get the actual field type out of the TypeContainer diff --git a/include/bout/index_derivs_interface.hxx b/include/bout/index_derivs_interface.hxx index 8f7e41a68e..242492c3f8 100644 --- a/include/bout/index_derivs_interface.hxx +++ b/include/bout/index_derivs_interface.hxx @@ -45,7 +45,6 @@ namespace index { template T flowDerivative(const T& vel, const T& f, CELL_LOC outloc, const std::string& method, const std::string& region) { - AUTO_TRACE(); // Checks static_assert(bout::utils::is_Field2D_v || bout::utils::is_Field3D_v, @@ -110,7 +109,6 @@ T flowDerivative(const T& vel, const T& f, CELL_LOC outloc, const std::string& m template T standardDerivative(const T& f, CELL_LOC outloc, const std::string& method, const std::string& region) { - AUTO_TRACE(); // Checks static_assert(bout::utils::is_Field2D_v || bout::utils::is_Field3D_v, @@ -174,14 +172,14 @@ T standardDerivative(const T& f, CELL_LOC outloc, const std::string& method, template T DDX(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } template T D2DX2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } @@ -189,7 +187,7 @@ T D2DX2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T D4DX4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } @@ -199,7 +197,7 @@ T D4DX4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T DDY(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + if (f.hasParallelSlices()) { ASSERT1(f.getDirectionY() == YDirectionType::Standard); return standardDerivative(f, outloc, @@ -216,7 +214,7 @@ T DDY(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "D template T D2DY2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + if (f.hasParallelSlices()) { ASSERT1(f.getDirectionY() == YDirectionType::Standard); return standardDerivative( @@ -233,7 +231,7 @@ T D2DY2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T D4DY4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + if (f.hasParallelSlices()) { ASSERT1(f.getDirectionY() == YDirectionType::Standard); return standardDerivative( @@ -251,14 +249,14 @@ T D4DY4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T DDZ(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } template T D2DZ2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } @@ -266,7 +264,7 @@ T D2DZ2(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T D4DZ4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return standardDerivative(f, outloc, method, region); } @@ -291,14 +289,14 @@ T D4DZ4(const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = template T VDDX(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return flowDerivative(vel, f, outloc, method, region); } template T FDDX(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return flowDerivative(vel, f, outloc, method, region); } @@ -307,7 +305,6 @@ T FDDX(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, template T VDDY(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); // Note the following chunk is copy+pasted from flowDerivative // above. Not pulled out as a separate function due the number of @@ -363,7 +360,7 @@ T VDDY(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, template T FDDY(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + const bool fHasParallelSlices = (f.hasParallelSlices()); const bool velHasParallelSlices = (vel.hasParallelSlices()); if (fHasParallelSlices && velHasParallelSlices) { @@ -389,14 +386,14 @@ T FDDY(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, template T VDDZ(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return flowDerivative(vel, f, outloc, method, region); } template T FDDZ(const T& vel, const T& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY") { - AUTO_TRACE(); + return flowDerivative(vel, f, outloc, method, region); } diff --git a/include/bout/interpolation.hxx b/include/bout/interpolation.hxx index 2c7df4472d..1753dfe0c0 100644 --- a/include/bout/interpolation.hxx +++ b/include/bout/interpolation.hxx @@ -56,7 +56,7 @@ inline BoutReal interp(const stencil& s) { */ template const T interp_to(const T& var, CELL_LOC loc, const std::string region = "RGN_ALL") { - AUTO_TRACE(); + static_assert(bout::utils::is_Field2D_v || bout::utils::is_Field3D_v, "interp_to must be templated with one of Field2D or Field3D."); ASSERT1(loc != CELL_DEFAULT); // doesn't make sense to interplote to CELL_DEFAULT diff --git a/include/bout/interpolation_xz.hxx b/include/bout/interpolation_xz.hxx index 6c7419f7e4..79e959b3af 100644 --- a/include/bout/interpolation_xz.hxx +++ b/include/bout/interpolation_xz.hxx @@ -24,6 +24,7 @@ #ifndef BOUT_INTERP_XZ_H #define BOUT_INTERP_XZ_H +#include "bout/build_defines.hxx" #include "bout/mask.hxx" #define USE_NEW_WEIGHTS 1 diff --git a/include/bout/invertable_operator.hxx b/include/bout/invertable_operator.hxx index 9b9dbba41a..d61c258654 100644 --- a/include/bout/invertable_operator.hxx +++ b/include/bout/invertable_operator.hxx @@ -42,7 +42,6 @@ class InvertableOperator; #include #include #include -#include #include #include #include @@ -61,14 +60,14 @@ namespace inversion { /// No-op function to use as a default -- may wish to remove once testing phase complete template T identity(const T& in) { - AUTO_TRACE(); + return in; }; /// Pack a PetscVec from a Field template PetscErrorCode fieldToPetscVec(const T& in, Vec out) { - TRACE("fieldToPetscVec"); + Timer timer("invertable_operator_packing"); PetscScalar* vecData; @@ -93,7 +92,7 @@ PetscErrorCode fieldToPetscVec(const T& in, Vec out) { /// Pack a Field from a PetscVec template PetscErrorCode petscVecToField(Vec in, T& out) { - TRACE("petscVecToField"); + Timer timer("invertable_operator_packing"); const PetscScalar* vecData; @@ -136,13 +135,12 @@ public: : operatorFunction(func), preconditionerFunction(func), opt(optIn == nullptr ? Options::getRoot()->getSection("invertableOperator") : optIn), - localmesh(localmeshIn == nullptr ? bout::globals::mesh : localmeshIn), lib(opt) { - AUTO_TRACE(); - }; + localmesh(localmeshIn == nullptr ? bout::globals::mesh : localmeshIn), lib(opt){ + + }; /// Destructor just has to cleanup the PETSc owned objects. ~InvertableOperator() { - TRACE("InvertableOperator::destructor"); KSPDestroy(&ksp); MatDestroy(&matOperator); @@ -157,7 +155,7 @@ public: /// do this they can set alsoSetPreconditioner to false. void setOperatorFunction(const function_signature& func, bool alsoSetPreconditioner = true) { - TRACE("InvertableOperator::setOperatorFunction"); + operatorFunction = func; if (alsoSetPreconditioner) { preconditionerFunction = func; @@ -166,28 +164,21 @@ public: /// Allow the user to override the existing preconditioner function void setPreconditionerFunction(const function_signature& func) { - TRACE("InvertableOperator::setPreconditionerFunction"); + preconditionerFunction = func; } /// Provide a way to apply the operator to a Field - T operator()(const T& input) { - TRACE("InvertableOperator::operator()"); - return operatorFunction(input); - } + T operator()(const T& input) { return operatorFunction(input); } /// Provide a synonym for applying the operator to a Field - T apply(const T& input) { - AUTO_TRACE(); - return operator()(input); - } + T apply(const T& input) { return operator()(input); } /// Sets up the PETSc objects required for inverting the operator /// Currently also takes the functor that applies the operator this class /// represents. Not actually required by any of the setup so this should /// probably be moved to a separate place (maybe the constructor). PetscErrorCode setup() { - TRACE("InvertableOperator::setup"); Timer timer("invertable_operator_setup"); if (doneSetup) { @@ -386,7 +377,7 @@ public: // but suspect it's not as there are KSPGuess objects // to deal with. T invert(const T& rhsField, const T& guess) { - AUTO_TRACE(); + auto ierr = fieldToPetscVec(guess, lhs); CHKERRQ(ierr); return invert(rhsField); @@ -397,7 +388,7 @@ public: /// of the operator we represent. Should probably provide an overload or similar as a /// way of setting the initial guess. T invert(const T& rhsField) { - TRACE("InvertableOperator::invert"); + Timer timer("invertable_operator_invert"); if (!doneSetup) { @@ -444,7 +435,6 @@ public: /// applying the registered function on the calculated inverse gives /// back the initial values. bool verify(const T& rhsIn, BoutReal tol = 1.0e-5) { - TRACE("InvertableOperator::verify"); T result = invert(rhsIn); localmesh->communicate(result); @@ -463,7 +453,7 @@ public: /// that as the Timer "labels" are not unique to an instance the time /// reported is summed across all different instances. static void reportTime() { - TRACE("InvertableOperator::reportTime"); + BoutReal time_setup = Timer::resetTime("invertable_operator_setup"); BoutReal time_invert = Timer::resetTime("invertable_operator_invert"); BoutReal time_packing = Timer::resetTime("invertable_operator_packing"); @@ -503,7 +493,7 @@ private: /// Copies data from v1 into a field of type T, calls the function on this and then /// copies the result into the v2 argument. static PetscErrorCode functionWrapper(Mat m, Vec v1, Vec v2) { - TRACE("InvertableOperator::functionWrapper"); + InvertableOperator* ctx; auto ierr = MatShellGetContext(m, &ctx); T tmpField(ctx->localmesh); @@ -534,7 +524,7 @@ private: /// Copies data from v1 into a field of type T, calls the function on this and then /// copies the result into the v2 argument. static PetscErrorCode preconditionerWrapper(Mat m, Vec v1, Vec v2) { - TRACE("InvertableOperator::functionWrapper"); + InvertableOperator* ctx; auto ierr = MatShellGetContext(m, &ctx); T tmpField(ctx->localmesh); diff --git a/include/bout/mask.hxx b/include/bout/mask.hxx index fd90ae7345..fc5f814676 100644 --- a/include/bout/mask.hxx +++ b/include/bout/mask.hxx @@ -26,7 +26,6 @@ #include "bout/globals.hxx" #include "bout/mesh.hxx" -#include "bout/msg_stack.hxx" /** * 3D array of bools to mask Field3Ds diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index 2e27bed777..0d9471d1d2 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -652,7 +652,7 @@ public: /// Returns the non-CELL_CENTRE location /// allowed as a staggered location static CELL_LOC getAllowedStaggerLoc(DIRECTION direction) { - AUTO_TRACE(); + switch (direction) { case (DIRECTION::X): return CELL_XLOW; @@ -670,7 +670,7 @@ public: /// Returns the number of grid points in the /// particular direction int getNpoints(DIRECTION direction) const { - AUTO_TRACE(); + switch (direction) { case (DIRECTION::X): return LocalNx; @@ -688,7 +688,7 @@ public: /// Returns the number of guard points in the /// particular direction int getNguard(DIRECTION direction) const { - AUTO_TRACE(); + switch (direction) { case (DIRECTION::X): return xstart; diff --git a/include/bout/msg_stack.hxx b/include/bout/msg_stack.hxx index 6d19469e25..1abb26d2c7 100644 --- a/include/bout/msg_stack.hxx +++ b/include/bout/msg_stack.hxx @@ -31,27 +31,13 @@ class MsgStack; #include "bout/build_defines.hxx" -#include "bout/unused.hxx" - #include "fmt/core.h" -#include +#include #include #include #include -/// The __PRETTY_FUNCTION__ variable is defined by GCC (and some other families) but is -/// not a part of the standard. The __func__ variable *is* a part of the c++11 standard so -/// we'd like to fall back to this if possible. However as these are variables/constants -/// and not macros we can't just check if __PRETTY_FUNCITON__ is defined or not. Instead -/// we need to say if we support this or not by defining BOUT_HAS_PRETTY_FUNCTION (to be -/// implemented in configure) -#if BOUT_HAS_PRETTY_FUNCTION -#define __thefunc__ __PRETTY_FUNCTION__ -#else -#define __thefunc__ __func__ -#endif - /*! * Message stack * @@ -94,13 +80,16 @@ public: } void pop() {} - void pop(int UNUSED(id)) {} + void pop(int [[maybe_unused]] id) {} void clear() {} void dump() {} std::string getDump() { return ""; } #endif + /// Current stack size + std::size_t size() const { return position; } + private: std::vector stack; ///< Message stack; std::vector::size_type position{0}; ///< Position in stack @@ -193,23 +182,4 @@ private: #define TRACE(...) #endif -/*! - * The AUTO_TRACE macro provides a convenient way to put messages onto the msg_stack - * It pushes a message onto the stack, and pops it when the scope ends - * The message is automatically derived from the function signature - * as identified by the compiler. This will be PRETTY_FUNCTION if available - * else it will be the mangled form. - * - * This is implemented as a use of the TRACE macro with specific arguments. - * - * Example - * ------- - * - * { - * AUTO_TRACE(); - * - * } // Scope ends, message popped - */ -#define AUTO_TRACE() TRACE(__thefunc__) // NOLINT - #endif // BOUT_MSG_STACK_H diff --git a/include/bout/output.hxx b/include/bout/output.hxx index 823e359753..34b4f19376 100644 --- a/include/bout/output.hxx +++ b/include/bout/output.hxx @@ -29,12 +29,13 @@ class Output; #ifndef BOUT_OUTPUT_H #define BOUT_OUTPUT_H -#include "bout/multiostream.hxx" #include #include #include #include "bout/assert.hxx" +#include "bout/build_defines.hxx" +#include "bout/multiostream.hxx" #include "bout/sys/gettext.hxx" // IWYU pragma: keep for gettext _() macro #include "bout/unused.hxx" diff --git a/include/bout/petsc_interface.hxx b/include/bout/petsc_interface.hxx index 3ae02f41a6..5edd42a441 100644 --- a/include/bout/petsc_interface.hxx +++ b/include/bout/petsc_interface.hxx @@ -363,7 +363,7 @@ public: } } Element& operator=(const Element& other) { - AUTO_TRACE(); + if (this == &other) { return *this; } @@ -372,14 +372,14 @@ public: return *this; } Element& operator=(BoutReal val) { - AUTO_TRACE(); + ASSERT3(finite(val)); value = val; setValues(val, INSERT_VALUES); return *this; } Element& operator+=(BoutReal val) { - AUTO_TRACE(); + ASSERT3(finite(val)); auto columnPosition = std::find(positions.begin(), positions.end(), petscCol); if (columnPosition != positions.end()) { diff --git a/include/bout/physicsmodel.hxx b/include/bout/physicsmodel.hxx index 9fa25d8b0f..e6d34daef9 100644 --- a/include/bout/physicsmodel.hxx +++ b/include/bout/physicsmodel.hxx @@ -418,14 +418,14 @@ private: */ #define BOUTMAIN(ModelClass) \ int main(int argc, char** argv) { \ - int init_err = BoutInitialise(argc, argv); \ - if (init_err < 0) { \ - return 0; \ - } \ - if (init_err > 0) { \ - return init_err; \ - } \ try { \ + int init_err = BoutInitialise(argc, argv); \ + if (init_err < 0) { \ + return 0; \ + } \ + if (init_err > 0) { \ + return init_err; \ + } \ auto model = bout::utils::make_unique(); \ auto solver = Solver::create(); \ solver->setModel(model.get()); \ @@ -433,8 +433,7 @@ private: solver->addMonitor(bout_monitor.get(), Solver::BACK); \ solver->solve(); \ } catch (const BoutException& e) { \ - output << "Error encountered: " << e.what(); \ - output << e.getBacktrace() << endl; \ + output.write("Error encountered: {}\n", e.what()); \ MPI_Abort(BoutComm::get(), 1); \ } \ BoutFinalise(); \ diff --git a/include/bout/scorepwrapper.hxx b/include/bout/scorepwrapper.hxx index 81761530f0..8b37b2ff61 100644 --- a/include/bout/scorepwrapper.hxx +++ b/include/bout/scorepwrapper.hxx @@ -3,7 +3,6 @@ #include "bout/build_defines.hxx" -#include "bout/msg_stack.hxx" #include #if BOUT_HAS_SCOREP @@ -14,13 +13,25 @@ #define SCOREPLVL 0 #endif +/// The __PRETTY_FUNCTION__ variable is defined by GCC (and some other families) but is +/// not a part of the standard. The __func__ variable *is* a part of the c++11 standard so +/// we'd like to fall back to this if possible. However as these are variables/constants +/// and not macros we can't just check if __PRETTY_FUNCITON__ is defined or not. Instead +/// we need to say if we support this or not by defining BOUT_HAS_PRETTY_FUNCTION (to be +/// implemented in configure) +#if BOUT_HAS_PRETTY_FUNCTION +#define _thefunc_ __PRETTY_FUNCTION__ +#else +#define _thefunc_ __func__ +#endif + /// Instrument a function with scorep /// /// The scorep call is identical for all levels, so just define it here. /// If we don't have scorep support then just define a null function #if BOUT_HAS_SCOREP #define SCOREP_BASE_CALL(...) \ - SCOREP_USER_REGION(__thefunc__, SCOREP_USER_REGION_TYPE_FUNCTION) + SCOREP_USER_REGION(_thefunc_, SCOREP_USER_REGION_TYPE_FUNCTION) #else #define SCOREP_BASE_CALL(...) #endif diff --git a/include/bout/sys/timer.hxx b/include/bout/sys/timer.hxx index f3beba27b1..c6a0c9020a 100644 --- a/include/bout/sys/timer.hxx +++ b/include/bout/sys/timer.hxx @@ -7,7 +7,6 @@ #include #include "bout/msg_stack.hxx" -#include "bout/output.hxx" /*! * Timing class for performance benchmarking and diagnosis @@ -133,5 +132,4 @@ public: static void printTimeReport(); }; -#define AUTO_TIME() Timer CONCATENATE(time_, __LINE__)(__thefunc__) #endif // BOUT_TIMER_H diff --git a/include/bout/utils.hxx b/include/bout/utils.hxx index f8d6f08856..04aa0b281d 100644 --- a/include/bout/utils.hxx +++ b/include/bout/utils.hxx @@ -35,7 +35,6 @@ #include "bout/assert.hxx" #include "bout/bout_types.hxx" #include "bout/boutexception.hxx" -#include "bout/msg_stack.hxx" #include "bout/region.hxx" #include "bout/unused.hxx" diff --git a/manual/doxygen/Doxyfile b/manual/doxygen/Doxyfile index e7998854b0..973c5fce58 100644 --- a/manual/doxygen/Doxyfile +++ b/manual/doxygen/Doxyfile @@ -840,7 +840,8 @@ EXCLUDE = ../../examples \ ../../manual/ \ ../../bin/ \ ../../externalpackages/googletest/ \ - ../../tests/ + ../../tests/ \ + ../../build/_deps/ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -2059,13 +2060,11 @@ PREDEFINED = BACKTRACE \ BOUT_HAS_LAPACK \ BOUT_HAS_NETCDF \ BOUT_HAS_PETSC \ - BOUT_HAS_PRETTY_FUNCTION \ BOUT_HAS_PVODE \ BOUT_HAS_SCOREP \ BOUT_HAS_SLEPC \ BOUT_HAS_SUNDIALS \ BOUT_HAS_UUID_SYSTEM_GENERATOR \ - BOUT_USE_BACKTRACE \ BOUT_USE_COLOR \ BOUT_USE_OPENMP \ BOUT_USE_OUTPUT_DEBUG \ diff --git a/manual/doxygen/Doxyfile_readthedocs b/manual/doxygen/Doxyfile_readthedocs index 73060bb6b4..08de92fc79 100644 --- a/manual/doxygen/Doxyfile_readthedocs +++ b/manual/doxygen/Doxyfile_readthedocs @@ -790,7 +790,8 @@ EXCLUDE = ../../examples \ ../../manual/ \ ../../bin/ \ ../../externalpackages/googletest/ \ - ../../tests/ + ../../tests/ \ + ../sphinx/bout_build/_deps/ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1019,13 +1020,11 @@ PREDEFINED = BACKTRACE \ BOUT_HAS_LAPACK \ BOUT_HAS_NETCDF \ BOUT_HAS_PETSC \ - BOUT_HAS_PRETTY_FUNCTION \ BOUT_HAS_PVODE \ BOUT_HAS_SCOREP \ BOUT_HAS_SLEPC \ BOUT_HAS_SUNDIALS \ BOUT_HAS_UUID_SYSTEM_GENERATOR \ - BOUT_USE_BACKTRACE \ BOUT_USE_COLOR \ BOUT_USE_OPENMP \ BOUT_USE_OUTPUT_DEBUG \ diff --git a/manual/sphinx/conf.py b/manual/sphinx/conf.py index 3aa6e94dc3..6046173aef 100755 --- a/manual/sphinx/conf.py +++ b/manual/sphinx/conf.py @@ -72,35 +72,29 @@ def __getattr__(cls, name): sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) print(os.environ) print(sys.argv) - python = sys.argv[0] - pydir = "/".join(python.split("/")[:-2]) os.system("which clang-format") os.system("which clang-format-6.0") - os.system( - "git submodule update --init --recursive ../../externalpackages/mpark.variant" - ) - pwd = "/".join(os.getcwd().split("/")[:-2]) - os.system("git submodule update --init --recursive ../../externalpackages/fmt") + subprocess.run("git submodule update --init --recursive", shell=True) cmake = ( - "cmake . -DBOUT_USE_FFTW=ON" - + " -DBOUT_USE_LAPACK=OFF" - + " -DBOUT_ENABLE_PYTHON=ON" - + " -DBOUT_UPDATE_GIT_SUBMODULE=OFF" - + " -DBOUT_TESTS=OFF" - + " -DBOUT_ALLOW_INSOURCE_BUILD=ON" - + f" -DPython3_ROOT_DIR={pydir}" - + f" -Dmpark_variant_DIR={pwd}/externalpackages/mpark.variant/" - + f" -Dfmt_DIR={pwd}/externalpackages/fmt/" + "cmake -S ../.. " + " -B bout_build" + " -DBOUT_USE_FFTW=ON" + " -DBOUT_USE_LAPACK=OFF" + " -DBOUT_ENABLE_PYTHON=ON" + " -DBOUT_UPDATE_GIT_SUBMODULE=OFF" + " -DBOUT_TESTS=OFF" + " -DBOUT_ALLOW_INSOURCE_BUILD=ON" + f" -DPython3_ROOT_DIR={sys.exec_prefix}" ) - # os.system("mkdir ../../build") - os.system("echo " + cmake) - x = os.system("cd ../.. ;" + cmake) - assert x == 0 - x = os.system("cd ../.. ; make -j 2 -f Makefile") - assert x == 0 + subprocess.run(f"echo {cmake}", shell=True) + subprocess.run(f"{cmake}", shell=True, check=True) + subprocess.run("cmake --build bout_build", shell=True, check=True) + + # Add the build directory to sys.path so that sphinx picks up the built + # Python modules + sys.path.append("bout_build/tools/pylib") -# readthedocs currently runs out of memory if we actually dare to try to do this if has_breathe: # Run doxygen to generate the XML sources if on_readthedocs: diff --git a/manual/sphinx/developer_docs/debugging.rst b/manual/sphinx/developer_docs/debugging.rst index 805cb5409a..f16d0b6a3b 100644 --- a/manual/sphinx/developer_docs/debugging.rst +++ b/manual/sphinx/developer_docs/debugging.rst @@ -34,14 +34,77 @@ To enable the ``output_debug`` messages, configure BOUT++ with a configure BOUT++ with ``-DENABLE_OUTPUT_DEBUG``. When running BOUT++ add a ``-v -v`` flag to see ``output_debug`` messages. +Backtrace +========= + +BOUT++ can also automatically print a backtrace in the event of a crash. This is +very useful to include if you ever need to report a bug to the developers! The +output looks something like this: + +.. code:: text + + ... + Error encountered: Stack trace (most recent call first): + #0 (filtered) + #1 (filtered) + #2 (filtered) + #3 in BoutMesh::createCommunicators() + at BOUT-dev/src/mesh/impls/bout/boutmesh.cxx:709:64 + 707: } + 708: // Unconditional exception for demo purposes + > 709: throw BoutException("Single null outer SOL not correct\n"); + ^ + 710: MPI_Group_free(&group); + 711: } + #4 in BoutMesh::load() + at BOUT-dev/src/mesh/impls/bout/boutmesh.cxx:575:22 + 573: /// Communicator + 574: + > 575: createCommunicators(); + ^ + 576: output_debug << "Got communicators" << endl; + #5 in BoutInitialise(int&, char**&) + at BOUT-dev/src/bout++.cxx:201:28 + 199: bout::globals::mesh = Mesh::create(); + 200: // Load from sources. Required for Field initialisation + > 201: bout::globals::mesh->load(); + ^ + 202: + 203: // time_report options are used in BoutFinalise, i.e. after we + #6 in main + at BOUT-dev/examples/elm-pb/elm_pb.cxx:2161:1 + 2159: }; + 2160: + > 2161: BOUTMAIN(ELMpb); + ^ + #7 (filtered) + #8 (filtered) + #9 (filtered) + + ====== Exception thrown ====== + Single null outer SOL not correct + + +Debug symbols are required to get the filename/line number and code snippets. If +they are missing in either BOUT++ or the physics model, only the function name +and signature will be included for that part. + +Including debug symbols is a configure time ``CMake`` option, set either: +``-DCMAKE_BUILD_TYPE=Debug`` or ``-DCMAKE_BUILD_TYPE=RelWithDebInfo`` (the +default). + +The formatting of this backtrace is controlled in +`BoutException::getBacktrace()` using the `cpptrace +`_ library. + + Message Stack ============= -The second utility BOUT++ has to help debugging is the message stack -using the `TRACE` (and related `AUTO_TRACE`) macro. These are very -useful for when a bug only occurs after a long time of running, and/or -only occasionally. The ``TRACE`` macro can simply be dropped in -anywhere in the code:: +Another utility BOUT++ has to help debugging is the message stack using the +`TRACE` macro. This is very useful for when a bug only occurs after a long time +of running, and/or only occasionally. The ``TRACE`` macro can simply be dropped +in anywhere in the code:: { TRACE("Some message here"); // message pushed @@ -70,14 +133,15 @@ help find where an error occurred. For example, given this snippet:: we would see something like the following output: .. code:: text - - ====== Back trace ====== + + ====== Exception thrown ====== + Something went wrong + + === Additional information === -> 4. Inner-most scope on line 58 of '/path/to/model.cxx' -> 2. Middle scope on line 53 of '/path/to/model.cxx' -> 1. Outer-most scope on line 51 of '/path/to/model.cxx' - ====== Exception thrown ====== - Something went wrong The third ``TRACE`` message doesn't appear in the output because we've left its scope and it's no longer relevant. @@ -94,53 +158,3 @@ If you need to capture runtime information in the message, you can use the ``fmt`` syntax also used by the loggers:: TRACE("Value of i={}, some arbitrary {}", i, "string"); - -There is also an ``AUTO_TRACE`` macro that automatically captures the -name of the function it's used in. This is used throughout the main -library, especially in functions where numerical issues are likely to -arise. - -Backtrace -========= - -Lastly, BOUT++ can also automatically print a backtrace in the event -of a crash. This is a compile-time option in the BOUT++ library -(``-DBOUT_ENABLE_BACKTRACE=ON``, the default, requires the -``addr2line`` program to be installed), and debug symbols to be turned -on (``-DCMAKE_BUILD_TYPE=Debug`` or ``=RelWithDebInfo``) in BOUT++ -_and_ the physics model. If debug symbols are only present in part, the -backtrace will be missing names for the other part. - -The output looks something like this: - -.. code:: text - - ... - Error encountered - ====== Exception path ====== - [bt] #10 ./backtrace() [0x40a27e] - _start at /home/abuild/rpmbuild/BUILD/glibc-2.33/csu/../sysdeps/x86_64/start.S:122 - [bt] #9 /lib64/libc.so.6(__libc_start_main+0xd5) [0x7fecbfa28b25] - __libc_start_main at /usr/src/debug/glibc-2.33-4.1.x86_64/csu/../csu/libc-start.c:332 - [bt] #8 ./backtrace() [0x40a467] - main at /path/to/BOUT-dev/build/../examples/backtrace/backtrace.cxx:32 (discriminator 9) - [bt] #7 /path/to/BOUT-dev/build/libbout++.so(_ZN6Solver8setModelEP12PhysicsModel+0xb5) [0x7fecc0ca2e93] - Solver::setModel(PhysicsModel*) at /path/to/BOUT-dev/build/../src/solver/solver.cxx:94 - [bt] #6 /path/to/BOUT-dev/build/libbout++.so(_ZN12PhysicsModel10initialiseEP6Solver+0xc0) [0x7fecc0cad594] - PhysicsModel::initialise(Solver*) at /path/to/BOUT-dev/build/../include/bout/physicsmodel.hxx:93 (discriminator 5) - [bt] #5 ./backtrace() [0x40a986] - Backtrace::init(bool) at /path/to/BOUT-dev/build/../examples/backtrace/backtrace.cxx:27 - [bt] #4 ./backtrace() [0x40a3cf] - f3() at /path/to/BOUT-dev/build/../examples/backtrace/backtrace.cxx:19 - [bt] #3 ./backtrace() [0x40a3be] - f2(int) at /path/to/BOUT-dev/build/../examples/backtrace/backtrace.cxx:15 - [bt] #2 ./backtrace() [0x40a386] - f1() at /path/to/BOUT-dev/build/../examples/backtrace/backtrace.cxx:13 (discriminator 2) - [bt] #1 ./backtrace(_ZN13BoutExceptionC1IA19_cJEEERKT_DpRKT0_+0xba) [0x40ae16] - BoutException::BoutException(char const (&) [19]) at /path/to/BOUT-dev/build/../include/bout/../boutexception.hxx:28 (discriminator 2) - - -This output tends to be much harder to read than the message stack -from ``TRACE`` macros, but the advantage is that it doesn't require -any modifications to the code to use, and can give you more precise -location information. diff --git a/manual/sphinx/user_docs/installing.rst b/manual/sphinx/user_docs/installing.rst index 10f5d9b9f1..a493f932c4 100644 --- a/manual/sphinx/user_docs/installing.rst +++ b/manual/sphinx/user_docs/installing.rst @@ -332,10 +332,13 @@ The default build configuration options try to be sensible for new users and developers, but there are a few you probably want to set manually for production runs or for debugging: -* ``CMAKE_BUILD_TYPE``: The default is ``RelWithDebInfo``, which - builds an optimised executable with debug symbols included. Change - this to ``Release`` to remove the debug symbols, or ``Debug`` for an - unoptimised build, but better debug experience +* ``CMAKE_BUILD_TYPE``: The default is ``RelWithDebInfo``, which builds an + optimised executable with debug symbols included. This is generally the most + useful, except for developers, who may wish to use ``Debug`` for an + unoptimised build, but better debug experience. There are a couple of other + choices (``Release`` and ``MinSizeRel``) which also produce optimised + executables, but without debug symbols, which is only really useful for + producing smaller binaries. * ``CHECK``: This sets the level of internal runtime checking done in the BOUT++ library, and ranges from 0 to 4 (inclusive). By default, @@ -380,16 +383,32 @@ to read and write this high-performance parallel file format. Bundled Dependencies ~~~~~~~~~~~~~~~~~~~~ -BOUT++ bundles some dependencies, currently `mpark.variant -`_, `fmt `_ and -`googletest `_. If you wish to -use an existing installation of ``mpark.variant``, you can set -``-DBOUT_USE_SYSTEM_MPARK_VARIANT=ON``, and supply the installation -path using ``mpark_variant_ROOT`` via the command line or environment -variable if it is installed in a non standard loction. Similarly for -``fmt``, using ``-DBOUT_USE_SYSTEM_FMT=ON`` and ``fmt_ROOT`` -respectively. To turn off both, you can set -``-DBOUT_USE_GIT_SUBMODULE=OFF``. +BOUT++ bundles some dependencies, currently: + +- `mpark.variant `_ +- `fmt `_ +- `cpptrace `_ +- ``googletest `_ (for unit tests) + +Aside from ``googletest``, the others are required dependencies and can either +be built as part of the BOUT++ build, or provided externally. If you wish to use +existing installations of some of these, set the following flags: + ++--------------------+-----------------------------------+------------------------+ +| Name | Flag for external installation | Library path | ++====================+===================================+========================+ +| ``mpark.variant`` | ``BOUT_USE_SYSTEM_MPARK_VARIANT`` | ``mpark_variant_ROOT`` | ++--------------------+-----------------------------------+------------------------+ +| ``fmt`` | ``BOUT_USE_SYSTEM_FMT`` | ``fmt_ROOT`` | ++--------------------+-----------------------------------+------------------------+ +| ``cpptrace`` | ``BOUT_USE_SYSTEM_CPPTRACE`` | ``cpptrace_ROOT`` | ++--------------------+-----------------------------------+------------------------+ + +You can also set ``-DBOUT_USE_GIT_SUBMODULE=OFF`` to not use any of the bundled +versions. + +If the libraries are in non-standard locations, you may also need to supply the +relevant library path flags. The recommended way to use ``googletest`` is to compile it at the same time as your project, therefore there is no option to use an external diff --git a/manual/sphinx/user_docs/invertable_operator.rst b/manual/sphinx/user_docs/invertable_operator.rst index 92b7efd288..8f92796c9c 100644 --- a/manual/sphinx/user_docs/invertable_operator.rst +++ b/manual/sphinx/user_docs/invertable_operator.rst @@ -48,7 +48,6 @@ the ``operator()`` call:: // Drop C term for now Field3D operator()(const Field3D &input) { - TRACE("myLaplacian::operator()"); Timer timer("invertable_operator_operate"); Field3D result = A * input + D * Delp2(input); @@ -68,7 +67,6 @@ A more complete example is :: // Drop C term for now Field3D operator()(const Field3D &input) { - TRACE("myLaplacian::operator()"); Timer timer("invertable_operator_operate"); Field3D result = A * input + D * Delp2(input); diff --git a/src/bout++.cxx b/src/bout++.cxx index 48ab96298b..d6888874c6 100644 --- a/src/bout++.cxx +++ b/src/bout++.cxx @@ -27,7 +27,7 @@ #include "bout/build_config.hxx" -const char DEFAULT_DIR[] = "data"; +static constexpr auto DEFAULT_DIR = "data"; #define GLOBALORIGIN @@ -141,74 +141,68 @@ int BoutInitialise(int& argc, char**& argv) { return 1; } - try { - checkDataDirectoryIsAccessible(args.data_dir); + checkDataDirectoryIsAccessible(args.data_dir); - // Set the command-line arguments - SlepcLib::setArgs(argc, argv); // SLEPc initialisation - PetscLib::setArgs(argc, argv); // PETSc initialisation - Solver::setArgs(argc, argv); // Solver initialisation - BoutComm::setArgs(argc, argv); // MPI initialisation + // Set the command-line arguments + SlepcLib::setArgs(argc, argv); // SLEPc initialisation + PetscLib::setArgs(argc, argv); // PETSc initialisation + Solver::setArgs(argc, argv); // Solver initialisation + BoutComm::setArgs(argc, argv); // MPI initialisation - const int MYPE = BoutComm::rank(); + const int MYPE = BoutComm::rank(); - setupBoutLogColor(args.color_output, MYPE); + setupBoutLogColor(args.color_output, MYPE); - setupOutput(args.data_dir, args.log_file, args.verbosity, MYPE); + setupOutput(args.data_dir, args.log_file, args.verbosity, MYPE); - savePIDtoFile(args.data_dir, MYPE); + savePIDtoFile(args.data_dir, MYPE); #if BOUT_HAS_ADIOS2 - bout::ADIOSInit(BoutComm::get()); + bout::ADIOSInit(BoutComm::get()); #endif - // Print the different parts of the startup info - printStartupHeader(MYPE, BoutComm::size()); - printCompileTimeOptions(); - printCommandLineArguments(args.original_argv); - - // Load settings file - OptionsReader* reader = OptionsReader::getInstance(); - // Ideally we'd use the long options for `datadir` and - // `optionfile` here, but we'd need to call parseCommandLine - // _first_ in order to do that and set the source, etc., but we - // need to call that _second_ in order to override the input file - reader->read(Options::getRoot(), "{}", (args.data_dir / args.opt_file).string()); - - // Get options override from command-line - reader->parseCommandLine(Options::getRoot(), args.argv); - - // Get the variables back out so they count as having been used - // when checking for unused options. They normally _do_ get used, - // but it's possible that only happens in BoutFinalise, which is - // too late for that check. - const auto datadir = Options::root()["datadir"].withDefault(DEFAULT_DIR); - [[maybe_unused]] const auto optionfile = - Options::root()["optionfile"].withDefault(args.opt_file); - const auto settingsfile = - Options::root()["settingsfile"].withDefault(args.set_file); - - setRunStartInfo(Options::root()); - - if (MYPE == 0) { - writeSettingsFile(Options::root(), datadir, settingsfile); - } - - bout::globals::mpi = new MpiWrapper(); + // Print the different parts of the startup info + printStartupHeader(MYPE, BoutComm::size()); + printCompileTimeOptions(); + printCommandLineArguments(args.original_argv); + + // Load settings file + OptionsReader* reader = OptionsReader::getInstance(); + // Ideally we'd use the long options for `datadir` and + // `optionfile` here, but we'd need to call parseCommandLine + // _first_ in order to do that and set the source, etc., but we + // need to call that _second_ in order to override the input file + reader->read(Options::getRoot(), "{}", (args.data_dir / args.opt_file).string()); + + // Get options override from command-line + reader->parseCommandLine(Options::getRoot(), args.argv); + + // Get the variables back out so they count as having been used + // when checking for unused options. They normally _do_ get used, + // but it's possible that only happens in BoutFinalise, which is + // too late for that check. + const auto datadir = Options::root()["datadir"].withDefault(DEFAULT_DIR); + [[maybe_unused]] const auto optionfile = + Options::root()["optionfile"].withDefault(args.opt_file); + const auto settingsfile = + Options::root()["settingsfile"].withDefault(args.set_file); + + setRunStartInfo(Options::root()); + + if (MYPE == 0) { + writeSettingsFile(Options::root(), datadir, settingsfile); + } - // Create the mesh - bout::globals::mesh = Mesh::create(); - // Load from sources. Required for Field initialisation - bout::globals::mesh->load(); + bout::globals::mpi = new MpiWrapper(); - // time_report options are used in BoutFinalise, i.e. after we - // check for unused options - Options::root()["time_report"].setConditionallyUsed(); + // Create the mesh + bout::globals::mesh = Mesh::create(); + // Load from sources. Required for Field initialisation + bout::globals::mesh->load(); - } catch (const BoutException& e) { - output_error.write(_("Error encountered during initialisation: {:s}\n"), e.what()); - throw; - } + // time_report options are used in BoutFinalise, i.e. after we + // check for unused options + Options::root()["time_report"].setConditionallyUsed(); return 0; } @@ -566,8 +560,6 @@ void printCompileTimeOptions() { output_info.write(_("\tNetCDF support {}{}\n"), is_enabled(has_netcdf), netcdf_flavour); output_info.write(_("\tADIOS2 support {}\n"), is_enabled(has_adios2)); output_info.write(_("\tPETSc support {}\n"), is_enabled(has_petsc)); - output_info.write(_("\tPretty function name support {}\n"), - is_enabled(has_pretty_function)); output_info.write(_("\tPVODE support {}\n"), is_enabled(has_pvode)); output_info.write(_("\tScore-P support {}\n"), is_enabled(has_scorep)); output_info.write(_("\tSLEPc support {}\n"), is_enabled(has_slepc)); @@ -696,7 +688,6 @@ void addBuildFlagsToOptions(Options& options) { options["has_umpire"].force(bout::build::has_umpire); options["has_caliper"].force(bout::build::has_caliper); options["has_raja"].force(bout::build::has_raja); - options["has_pretty_function"].force(bout::build::has_pretty_function); options["has_pvode"].force(bout::build::has_pvode); options["has_scorep"].force(bout::build::has_scorep); options["has_slepc"].force(bout::build::has_slepc); diff --git a/src/field/field.cxx b/src/field/field.cxx index 797df6c405..e9b01f0bcb 100644 --- a/src/field/field.cxx +++ b/src/field/field.cxx @@ -27,7 +27,6 @@ #include #include #include -#include #include #include diff --git a/src/field/field2d.cxx b/src/field/field2d.cxx index c8b9ebb689..a046078585 100644 --- a/src/field/field2d.cxx +++ b/src/field/field2d.cxx @@ -25,28 +25,19 @@ * **************************************************************************/ -#include "bout/build_config.hxx" - -#include -#include - -#include // for mesh - -#include - -#include +#include "bout/build_defines.hxx" +#include #include #include - +#include #include +#include +#include // for mesh #include -#include - #include -#include -#include +#include Field2D::Field2D(Mesh* localmesh, CELL_LOC location_in, DirectionTypes directions_in) : Field(localmesh, location_in, directions_in) { @@ -62,7 +53,6 @@ Field2D::Field2D(Mesh* localmesh, CELL_LOC location_in, DirectionTypes direction } Field2D::Field2D(const Field2D& f) : Field(f), data(f.data) { - TRACE("Field2D(Field2D&)"); #if BOUT_USE_TRACK name = f.name; @@ -145,8 +135,6 @@ Field2D& Field2D::operator=(const Field2D& rhs) { return (*this); // skip this assignment } - TRACE("Field2D: Assignment from Field2D"); - Field::operator=(rhs); // Copy the data and data sizes @@ -165,8 +153,6 @@ Field2D& Field2D::operator=(Field2D&& rhs) noexcept { return (*this); // skip this assignment } - TRACE("Field2D: Move assignment from Field2D"); - // Move the data and data sizes nx = rhs.nx; ny = rhs.ny; @@ -185,7 +171,6 @@ Field2D& Field2D::operator=(const BoutReal rhs) { name = ""; #endif - TRACE("Field2D = BoutReal"); allocate(); BOUT_FOR(i, getRegion("RGN_ALL")) { (*this)[i] = rhs; } @@ -196,7 +181,6 @@ Field2D& Field2D::operator=(const BoutReal rhs) { ///////////////////// BOUNDARY CONDITIONS ////////////////// void Field2D::applyBoundary(bool init) { - TRACE("Field2D::applyBoundary()"); #if CHECK > 0 if (init) { @@ -218,7 +202,6 @@ void Field2D::applyBoundary(bool init) { } void Field2D::applyBoundary(BoutReal time) { - TRACE("Field2D::applyBoundary(time)"); #if CHECK > 0 if (not isBoundarySet()) { @@ -234,7 +217,6 @@ void Field2D::applyBoundary(BoutReal time) { } void Field2D::applyBoundary(const std::string& condition) { - TRACE("Field2D::applyBoundary(condition)"); checkData(*this); @@ -268,7 +250,7 @@ void Field2D::applyBoundary(const std::string& condition) { } void Field2D::applyBoundary(const std::string& region, const std::string& condition) { - TRACE("Field2D::applyBoundary(string, string)"); + checkData(*this); /// Get the boundary factory (singleton) @@ -310,7 +292,6 @@ void Field2D::applyBoundary(const std::string& region, const std::string& condit } void Field2D::applyTDerivBoundary() { - TRACE("Field2D::applyTDerivBoundary()"); checkData(*this); ASSERT1(deriv != nullptr); @@ -322,7 +303,6 @@ void Field2D::applyTDerivBoundary() { } void Field2D::setBoundaryTo(const Field2D& f2d) { - TRACE("Field2D::setBoundary(const Field2D&)"); checkData(f2d); diff --git a/src/field/field3d.cxx b/src/field/field3d.cxx index 4c5ffa9748..9821c638f7 100644 --- a/src/field/field3d.cxx +++ b/src/field/field3d.cxx @@ -25,7 +25,7 @@ * **************************************************************************/ -#include "bout/build_config.hxx" +#include "bout/build_defines.hxx" #include #include @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -67,8 +66,6 @@ Field3D::Field3D(const Field3D& f) : Field(f), data(f.data), yup_fields(f.yup_fields), ydown_fields(f.ydown_fields), regionID(f.regionID) { - TRACE("Field3D(Field3D&)"); - if (fieldmesh) { nx = fieldmesh->LocalNx; ny = fieldmesh->LocalNy; @@ -78,8 +75,6 @@ Field3D::Field3D(const Field3D& f) Field3D::Field3D(const Field2D& f) : Field(f) { - TRACE("Field3D: Copy constructor from Field2D"); - nx = fieldmesh->LocalNx; ny = fieldmesh->LocalNy; nz = fieldmesh->LocalNz; @@ -89,15 +84,12 @@ Field3D::Field3D(const Field2D& f) : Field(f) { Field3D::Field3D(const BoutReal val, Mesh* localmesh) : Field3D(localmesh) { - TRACE("Field3D: Copy constructor from value"); - *this = val; } Field3D::Field3D(Array data_in, Mesh* localmesh, CELL_LOC datalocation, DirectionTypes directions_in) : Field(localmesh, datalocation, directions_in), data(std::move(data_in)) { - TRACE("Field3D: Copy constructor from Array and Mesh"); nx = fieldmesh->LocalNx; ny = fieldmesh->LocalNy; @@ -137,7 +129,6 @@ Field3D* Field3D::timeDeriv() { } void Field3D::splitParallelSlices() { - TRACE("Field3D::splitParallelSlices"); if (hasParallelSlices()) { return; @@ -152,7 +143,6 @@ void Field3D::splitParallelSlices() { } void Field3D::clearParallelSlices() { - TRACE("Field3D::clearParallelSlices"); if (!hasParallelSlices()) { return; @@ -245,8 +235,6 @@ Field3D& Field3D::operator=(const Field3D& rhs) { return (*this); // skip this assignment } - TRACE("Field3D: Assignment from Field3D"); - // Copy base slice Field::operator=(rhs); @@ -266,7 +254,6 @@ Field3D& Field3D::operator=(const Field3D& rhs) { } Field3D& Field3D::operator=(Field3D&& rhs) { - TRACE("Field3D: Assignment from Field3D"); // Move parallel slices or delete existing ones. yup_fields = std::move(rhs.yup_fields); @@ -287,7 +274,6 @@ Field3D& Field3D::operator=(Field3D&& rhs) { } Field3D& Field3D::operator=(const Field2D& rhs) { - TRACE("Field3D = Field2D"); /// Check that the data is allocated ASSERT1(rhs.isAllocated()); @@ -314,7 +300,6 @@ Field3D& Field3D::operator=(const Field2D& rhs) { } void Field3D::operator=(const FieldPerp& rhs) { - TRACE("Field3D = FieldPerp"); ASSERT1_FIELDS_COMPATIBLE(*this, rhs); /// Check that the data is allocated @@ -333,7 +318,6 @@ void Field3D::operator=(const FieldPerp& rhs) { } Field3D& Field3D::operator=(const BoutReal val) { - TRACE("Field3D = BoutReal"); // Delete existing parallel slices. We don't copy parallel slices, so any // that currently exist will be incorrect. @@ -355,7 +339,6 @@ Field3D& Field3D::calcParallelSlices() { ///////////////////// BOUNDARY CONDITIONS ////////////////// void Field3D::applyBoundary(bool init) { - TRACE("Field3D::applyBoundary()"); #if CHECK > 0 if (init) { @@ -378,7 +361,6 @@ void Field3D::applyBoundary(bool init) { } void Field3D::applyBoundary(BoutReal t) { - TRACE("Field3D::applyBoundary()"); #if CHECK > 0 if (not isBoundarySet()) { @@ -395,7 +377,6 @@ void Field3D::applyBoundary(BoutReal t) { } void Field3D::applyBoundary(const std::string& condition) { - TRACE("Field3D::applyBoundary(condition)"); checkData(*this); @@ -413,7 +394,7 @@ void Field3D::applyBoundary(const std::string& condition) { } void Field3D::applyBoundary(const std::string& region, const std::string& condition) { - TRACE("Field3D::applyBoundary(string, string)"); + checkData(*this); /// Get the boundary factory (singleton) @@ -439,7 +420,6 @@ void Field3D::applyBoundary(const std::string& region, const std::string& condit } void Field3D::applyTDerivBoundary() { - TRACE("Field3D::applyTDerivBoundary()"); checkData(*this); ASSERT1(deriv != nullptr); @@ -451,7 +431,6 @@ void Field3D::applyTDerivBoundary() { } void Field3D::setBoundaryTo(const Field3D& f3d) { - TRACE("Field3D::setBoundary(const Field3D&)"); checkData(f3d); @@ -475,8 +454,6 @@ void Field3D::setBoundaryTo(const Field3D& f3d) { void Field3D::applyParallelBoundary() { - TRACE("Field3D::applyParallelBoundary()"); - checkData(*this); if (isFci()) { ASSERT1(hasParallelSlices()); @@ -493,8 +470,6 @@ void Field3D::applyParallelBoundary() { void Field3D::applyParallelBoundary(BoutReal t) { - TRACE("Field3D::applyParallelBoundary(t)"); - checkData(*this); if (isFci()) { ASSERT1(hasParallelSlices()); @@ -511,8 +486,6 @@ void Field3D::applyParallelBoundary(BoutReal t) { void Field3D::applyParallelBoundary(const std::string& condition) { - TRACE("Field3D::applyParallelBoundary(condition)"); - checkData(*this); if (isFci()) { ASSERT1(hasParallelSlices()); @@ -535,8 +508,6 @@ void Field3D::applyParallelBoundary(const std::string& condition) { void Field3D::applyParallelBoundary(const std::string& region, const std::string& condition) { - TRACE("Field3D::applyParallelBoundary(region, condition)"); - checkData(*this); if (isFci()) { ASSERT1(hasParallelSlices()); @@ -562,8 +533,6 @@ void Field3D::applyParallelBoundary(const std::string& region, void Field3D::applyParallelBoundary(const std::string& region, const std::string& condition, Field3D* f) { - TRACE("Field3D::applyParallelBoundary(region, condition, f)"); - checkData(*this); if (isFci()) { ASSERT1(hasParallelSlices()); @@ -599,7 +568,7 @@ Field3D operator-(const Field3D& f) { return -1.0 * f; } //////////////// NON-MEMBER FUNCTIONS ////////////////// Field3D pow(const Field3D& lhs, const Field2D& rhs, const std::string& rgn) { - TRACE("pow(Field3D, Field2D)"); + // Check if the inputs are allocated checkData(lhs); checkData(rhs); @@ -615,7 +584,6 @@ Field3D pow(const Field3D& lhs, const Field2D& rhs, const std::string& rgn) { } FieldPerp pow(const Field3D& lhs, const FieldPerp& rhs, const std::string& rgn) { - TRACE("pow(Field3D, FieldPerp)"); checkData(lhs); checkData(rhs); @@ -635,7 +603,6 @@ FieldPerp pow(const Field3D& lhs, const FieldPerp& rhs, const std::string& rgn) // Friend functions Field3D filter(const Field3D& var, int N0, const std::string& rgn) { - TRACE("filter(Field3D, int)"); checkData(var); @@ -681,7 +648,6 @@ Field3D filter(const Field3D& var, int N0, const std::string& rgn) { // Fourier filter in z with zmin Field3D lowPass(const Field3D& var, int zmax, bool keep_zonal, const std::string& rgn) { - TRACE("lowPass(Field3D, {}, {})", zmax, keep_zonal); checkData(var); int ncz = var.getNz(); @@ -731,7 +697,7 @@ Field3D lowPass(const Field3D& var, int zmax, bool keep_zonal, const std::string * Use FFT to shift by an angle in the Z direction */ void shiftZ(Field3D& var, int jx, int jy, double zangle) { - TRACE("shiftZ"); + checkData(var); var.allocate(); // Ensure that var is unique Mesh* localmesh = var.getMesh(); @@ -800,7 +766,6 @@ void checkData(const Field3D& f, const std::string& region) { #endif Field2D DC(const Field3D& f, const std::string& rgn) { - TRACE("DC(Field3D)"); checkData(f); diff --git a/src/field/field_data.cxx b/src/field/field_data.cxx index b95c0462d9..b925cb1426 100644 --- a/src/field/field_data.cxx +++ b/src/field/field_data.cxx @@ -15,7 +15,6 @@ namespace bout { /// Throws if checks are enabled and trying to use a staggered /// location on a non-staggered mesh CELL_LOC normaliseLocation(CELL_LOC location, Mesh* mesh) { - AUTO_TRACE(); // CELL_DEFAULT always means CELL_CENTRE if (location == CELL_DEFAULT) { @@ -216,7 +215,6 @@ Mesh* FieldData::getMesh() const { } FieldData& FieldData::setLocation(CELL_LOC new_location) { - AUTO_TRACE(); location = bout::normaliseLocation(new_location, getMesh()); @@ -228,10 +226,7 @@ FieldData& FieldData::setLocation(CELL_LOC new_location) { return *this; } -CELL_LOC FieldData::getLocation() const { - AUTO_TRACE(); - return location; -} +CELL_LOC FieldData::getLocation() const { return location; } Coordinates* FieldData::getCoordinates() const { auto fieldCoordinates_shared = fieldCoordinates.lock(); diff --git a/src/field/field_factory.cxx b/src/field/field_factory.cxx index b93a39eeda..188a64cf0c 100644 --- a/src/field/field_factory.cxx +++ b/src/field/field_factory.cxx @@ -188,7 +188,6 @@ Field2D FieldFactory::create2D(const std::string& value, const Options* opt, Field2D FieldFactory::create2D(FieldGeneratorPtr gen, Mesh* localmesh, CELL_LOC loc, BoutReal t) const { - AUTO_TRACE(); if (localmesh == nullptr) { if (fieldmesh == nullptr) { @@ -220,7 +219,6 @@ Field3D FieldFactory::create3D(const std::string& value, const Options* opt, Field3D FieldFactory::create3D(FieldGeneratorPtr gen, Mesh* localmesh, CELL_LOC loc, BoutReal t) const { - AUTO_TRACE(); if (localmesh == nullptr) { if (fieldmesh == nullptr) { @@ -271,7 +269,6 @@ FieldPerp FieldFactory::createPerp(const std::string& value, const Options* opt, FieldPerp FieldFactory::createPerp(FieldGeneratorPtr gen, Mesh* localmesh, CELL_LOC loc, BoutReal t) const { - AUTO_TRACE(); if (localmesh == nullptr) { if (fieldmesh == nullptr) { diff --git a/src/field/fieldperp.cxx b/src/field/fieldperp.cxx index ca9bdc0397..d74a986473 100644 --- a/src/field/fieldperp.cxx +++ b/src/field/fieldperp.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include FieldPerp::FieldPerp(Mesh* localmesh, CELL_LOC location_in, int yindex_in, @@ -51,7 +50,6 @@ FieldPerp::FieldPerp(Array data_in, Mesh* localmesh, CELL_LOC location int yindex_in, DirectionTypes directions) : Field(localmesh, location_in, directions), yindex(yindex_in), nx(fieldmesh->LocalNx), nz(fieldmesh->LocalNz), data(std::move(data_in)) { - TRACE("FieldPerp: Copy constructor from Array and Mesh"); ASSERT1(data.size() == nx * nz); } @@ -97,7 +95,6 @@ FieldPerp& FieldPerp::operator=(const FieldPerp& rhs) { } FieldPerp& FieldPerp::operator=(const BoutReal rhs) { - TRACE("FieldPerp = BoutReal"); allocate(); diff --git a/src/field/gen_fieldops.py b/src/field/gen_fieldops.py index 29631ff7aa..3e07d6fec4 100755 --- a/src/field/gen_fieldops.py +++ b/src/field/gen_fieldops.py @@ -11,7 +11,6 @@ """ - from __future__ import print_function from builtins import object diff --git a/src/field/initialprofiles.cxx b/src/field/initialprofiles.cxx index ded5aa9882..2c34caa6e1 100644 --- a/src/field/initialprofiles.cxx +++ b/src/field/initialprofiles.cxx @@ -42,10 +42,8 @@ #include #include #include -#include void initial_profile(const std::string& name, Field3D& var) { - AUTO_TRACE(); Mesh* localmesh = var.getMesh(); @@ -65,7 +63,6 @@ void initial_profile(const std::string& name, Field3D& var) { } void initial_profile(const std::string& name, Field2D& var) { - AUTO_TRACE(); Mesh* localmesh = var.getMesh(); @@ -85,7 +82,6 @@ void initial_profile(const std::string& name, Field2D& var) { } void initial_profile(const std::string& name, Vector2D& var) { - AUTO_TRACE(); if (var.covariant) { initial_profile(name + "_x", var.x); @@ -99,7 +95,6 @@ void initial_profile(const std::string& name, Vector2D& var) { } void initial_profile(const std::string& name, Vector3D& var) { - AUTO_TRACE(); if (var.covariant) { initial_profile(name + "_x", var.x); diff --git a/src/field/vecops.cxx b/src/field/vecops.cxx index 5f34e2af02..1677187fcd 100644 --- a/src/field/vecops.cxx +++ b/src/field/vecops.cxx @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -39,7 +38,7 @@ **************************************************************************/ Vector2D Grad(const Field2D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Grad( Field2D )"); + SCOREP0(); CELL_LOC outloc_x, outloc_y, outloc_z; if (outloc == CELL_VSHIFT) { @@ -68,7 +67,7 @@ Vector2D Grad(const Field2D& f, CELL_LOC outloc, const std::string& method) { } Vector3D Grad(const Field3D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Grad( Field3D )"); + SCOREP0(); CELL_LOC outloc_x, outloc_y, outloc_z; if (outloc == CELL_VSHIFT) { @@ -97,7 +96,7 @@ Vector3D Grad(const Field3D& f, CELL_LOC outloc, const std::string& method) { } Vector3D Grad_perp(const Field3D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Grad_perp( Field3D )"); + SCOREP0(); ASSERT1(outloc == CELL_DEFAULT || outloc == f.getLocation()); @@ -119,7 +118,7 @@ Vector3D Grad_perp(const Field3D& f, CELL_LOC outloc, const std::string& method) } Vector2D Grad_perp(const Field2D& f, CELL_LOC outloc, const std::string& method) { - AUTO_TRACE(); + SCOREP0(); ASSERT1(outloc == CELL_DEFAULT || outloc == f.getLocation()); @@ -145,7 +144,7 @@ Vector2D Grad_perp(const Field2D& f, CELL_LOC outloc, const std::string& method) Coordinates::FieldMetric Div(const Vector2D& v, CELL_LOC outloc, const std::string& method) { - TRACE("Div( Vector2D )"); + SCOREP0(); if (outloc == CELL_DEFAULT) { outloc = v.getLocation(); @@ -170,7 +169,7 @@ Coordinates::FieldMetric Div(const Vector2D& v, CELL_LOC outloc, } Field3D Div(const Vector3D& v, CELL_LOC outloc, const std::string& method) { - TRACE("Div( Vector3D )"); + SCOREP0(); if (outloc == CELL_DEFAULT) { outloc = v.getLocation(); @@ -209,7 +208,7 @@ Field3D Div(const Vector3D& v, CELL_LOC outloc, const std::string& method) { Coordinates::FieldMetric Div(const Vector2D& v, const Field2D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Div( Vector2D, Field2D )"); + SCOREP0(); if (outloc == CELL_DEFAULT) { outloc = v.getLocation(); @@ -236,7 +235,6 @@ Coordinates::FieldMetric Div(const Vector2D& v, const Field2D& f, CELL_LOC outlo Field3D Div(const Vector3D& v, const Field3D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Div( Vector3D, Field3D )"); if (outloc == CELL_DEFAULT) { outloc = v.getLocation(); @@ -265,8 +263,6 @@ Field3D Div(const Vector3D& v, const Field3D& f, CELL_LOC outloc, Vector2D Curl(const Vector2D& v) { - TRACE("Curl( Vector2D )"); - ASSERT1(v.getLocation() != CELL_VSHIFT); Mesh* localmesh = v.getMesh(); auto metric = v.x.getCoordinates(); @@ -292,7 +288,7 @@ Vector2D Curl(const Vector2D& v) { } Vector3D Curl(const Vector3D& v) { - TRACE("Curl( Vector3D )"); + SCOREP0(); ASSERT1(v.getLocation() != CELL_VSHIFT); @@ -323,7 +319,7 @@ Vector3D Curl(const Vector3D& v) { * Upwinding operators **************************************************************************/ Coordinates::FieldMetric V_dot_Grad(const Vector2D& v, const Field2D& f) { - TRACE("V_dot_Grad( Vector2D , Field2D )"); + SCOREP0(); // Get contravariant components of v @@ -334,7 +330,7 @@ Coordinates::FieldMetric V_dot_Grad(const Vector2D& v, const Field2D& f) { } Field3D V_dot_Grad(const Vector2D& v, const Field3D& f) { - TRACE("V_dot_Grad( Vector2D , Field3D )"); + SCOREP0(); // Get contravariant components of v @@ -345,7 +341,7 @@ Field3D V_dot_Grad(const Vector2D& v, const Field3D& f) { } Field3D V_dot_Grad(const Vector3D& v, const Field2D& f) { - TRACE("V_dot_Grad( Vector3D , Field2D )"); + SCOREP0(); // Get contravariant components of v @@ -356,7 +352,7 @@ Field3D V_dot_Grad(const Vector3D& v, const Field2D& f) { } Field3D V_dot_Grad(const Vector3D& v, const Field3D& f) { - TRACE("V_dot_Grad( Vector3D , Field3D )"); + SCOREP0(); // Get contravariant components of v @@ -370,7 +366,7 @@ Field3D V_dot_Grad(const Vector3D& v, const Field3D& f) { // operation (addition) between the two input types. template R V_dot_Grad(const T& v, const F& a) { - AUTO_TRACE(); + SCOREP0(); ASSERT1(v.getLocation() == a.getLocation()); ASSERT1(v.getLocation() != CELL_VSHIFT); diff --git a/src/field/vector2d.cxx b/src/field/vector2d.cxx index 74d3a88a22..ab2d993549 100644 --- a/src/field/vector2d.cxx +++ b/src/field/vector2d.cxx @@ -429,7 +429,7 @@ CELL_LOC Vector2D::getLocation() const { Vector2D& Vector2D::setLocation(CELL_LOC loc) { SCOREP0(); - TRACE("Vector2D::setLocation"); + if (loc == CELL_DEFAULT) { loc = CELL_CENTRE; } diff --git a/src/field/vector3d.cxx b/src/field/vector3d.cxx index 56124595b3..7fb4a88918 100644 --- a/src/field/vector3d.cxx +++ b/src/field/vector3d.cxx @@ -551,7 +551,7 @@ CELL_LOC Vector3D::getLocation() const { Vector3D& Vector3D::setLocation(CELL_LOC loc) { SCOREP0(); - TRACE("Vector3D::setLocation"); + if (loc == CELL_DEFAULT) { loc = CELL_CENTRE; } diff --git a/src/invert/laplace/impls/cyclic/cyclic_laplace.cxx b/src/invert/laplace/impls/cyclic/cyclic_laplace.cxx index 837ac3755f..99aacea4f8 100644 --- a/src/invert/laplace/impls/cyclic/cyclic_laplace.cxx +++ b/src/invert/laplace/impls/cyclic/cyclic_laplace.cxx @@ -304,7 +304,6 @@ FieldPerp LaplaceCyclic::solve(const FieldPerp& rhs, const FieldPerp& x0) { } Field3D LaplaceCyclic::solve(const Field3D& rhs, const Field3D& x0) { - TRACE("LaplaceCyclic::solve(Field3D, Field3D)"); ASSERT1(rhs.getLocation() == location); ASSERT1(x0.getLocation() == location); diff --git a/src/invert/laplace/impls/iterative_parallel_tri/iterative_parallel_tri.cxx b/src/invert/laplace/impls/iterative_parallel_tri/iterative_parallel_tri.cxx index 5255ea939d..926facd9e6 100644 --- a/src/invert/laplace/impls/iterative_parallel_tri/iterative_parallel_tri.cxx +++ b/src/invert/laplace/impls/iterative_parallel_tri/iterative_parallel_tri.cxx @@ -234,7 +234,6 @@ FieldPerp LaplaceIPT::solve(const FieldPerp& b, const FieldPerp& x0) { ASSERT1(localmesh == b.getMesh() && localmesh == x0.getMesh()); ASSERT1(b.getLocation() == location); ASSERT1(x0.getLocation() == location); - TRACE("LaplaceIPT::solve(const, const)"); FieldPerp x{emptyFrom(b)}; diff --git a/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx b/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx index 04c8c7e0c9..4be5bfbad3 100644 --- a/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx +++ b/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx @@ -33,7 +33,6 @@ #if not BOUT_USE_METRIC_3D #include -#include #include #if BOUT_USE_OPENMP @@ -46,8 +45,6 @@ LaplaceMultigrid::LaplaceMultigrid(Options* opt, const CELL_LOC loc, Mesh* mesh_ Solver* UNUSED(solver)) : Laplacian(opt, loc, mesh_in), A(0.0), C1(1.0), C2(1.0), D(1.0) { - TRACE("LaplaceMultigrid::LaplaceMultigrid(Options *opt)"); - // periodic x-direction not handled: see MultigridAlg::communications ASSERT1(!localmesh->periodicX); @@ -223,8 +220,6 @@ LaplaceMultigrid::LaplaceMultigrid(Options* opt, const CELL_LOC loc, Mesh* mesh_ FieldPerp LaplaceMultigrid::solve(const FieldPerp& b_in, const FieldPerp& x0) { - TRACE("LaplaceMultigrid::solve(const FieldPerp, const FieldPerp)"); - ASSERT1(localmesh == b_in.getMesh() && localmesh == x0.getMesh()); ASSERT1(b_in.getLocation() == location); ASSERT1(x0.getLocation() == location); @@ -578,7 +573,6 @@ FieldPerp LaplaceMultigrid::solve(const FieldPerp& b_in, const FieldPerp& x0) { } void LaplaceMultigrid::generateMatrixF(int level) { - TRACE("LaplaceMultigrid::generateMatrixF(int)"); // Set (fine-level) matrix entries diff --git a/src/invert/laplace/impls/pcr/pcr.cxx b/src/invert/laplace/impls/pcr/pcr.cxx index b619d80100..60169c6eb4 100644 --- a/src/invert/laplace/impls/pcr/pcr.cxx +++ b/src/invert/laplace/impls/pcr/pcr.cxx @@ -308,7 +308,6 @@ FieldPerp LaplacePCR::solve(const FieldPerp& rhs, const FieldPerp& x0) { } Field3D LaplacePCR::solve(const Field3D& rhs, const Field3D& x0) { - TRACE("LaplacePCR::solve(Field3D, Field3D)"); ASSERT1(rhs.getLocation() == location); ASSERT1(x0.getLocation() == location); diff --git a/src/invert/laplace/impls/pcr_thomas/pcr_thomas.cxx b/src/invert/laplace/impls/pcr_thomas/pcr_thomas.cxx index b48b20f246..600166aa6b 100644 --- a/src/invert/laplace/impls/pcr_thomas/pcr_thomas.cxx +++ b/src/invert/laplace/impls/pcr_thomas/pcr_thomas.cxx @@ -304,7 +304,6 @@ FieldPerp LaplacePCR_THOMAS::solve(const FieldPerp& rhs, const FieldPerp& x0) { } Field3D LaplacePCR_THOMAS::solve(const Field3D& rhs, const Field3D& x0) { - TRACE("LaplacePCR_THOMAS::solve(Field3D, Field3D)"); ASSERT1(rhs.getLocation() == location); ASSERT1(x0.getLocation() == location); diff --git a/src/invert/laplace/impls/petsc/petsc_laplace.cxx b/src/invert/laplace/impls/petsc/petsc_laplace.cxx index 5f417d4faa..65c80ec48c 100644 --- a/src/invert/laplace/impls/petsc/petsc_laplace.cxx +++ b/src/invert/laplace/impls/petsc/petsc_laplace.cxx @@ -336,7 +336,6 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b) { return solve(b, b); } * \returns sol The solution x of the problem Ax=b. */ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) { - TRACE("LaplacePetsc::solve"); ASSERT1(localmesh == b.getMesh() && localmesh == x0.getMesh()); ASSERT1(b.getLocation() == location); diff --git a/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx b/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx index efca1d70be..3be5e43e63 100644 --- a/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx +++ b/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx @@ -174,7 +174,6 @@ void setBC(PetscVector& rhs, const Field3D& b_in, } Field3D LaplacePetsc3dAmg::solve(const Field3D& b_in, const Field3D& x0) { - AUTO_TRACE(); // Timing reported in the log files. Includes any matrix construction. // The timing for just the solve phase can be retrieved from the "petscsolve" diff --git a/src/invert/laplace/invert_laplace.cxx b/src/invert/laplace/invert_laplace.cxx index 4032499781..e96248ef7e 100644 --- a/src/invert/laplace/invert_laplace.cxx +++ b/src/invert/laplace/invert_laplace.cxx @@ -33,11 +33,11 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -155,7 +155,6 @@ void Laplacian::cleanup() { instance.reset(); } **********************************************************************************/ Field3D Laplacian::solve(const Field3D& b) { - TRACE("Laplacian::solve(Field3D)"); ASSERT1(b.getLocation() == location); ASSERT1(localmesh == b.getMesh()); @@ -216,7 +215,6 @@ Field2D Laplacian::solve(const Field2D& b) { * \returns x All the y-slices of x_slice in the equation A*x_slice = b_slice */ Field3D Laplacian::solve(const Field3D& b, const Field3D& x0) { - TRACE("Laplacian::solve(Field3D, Field3D)"); ASSERT1(b.getLocation() == location); ASSERT1(x0.getLocation() == location); diff --git a/src/invert/laplacexz/impls/cyclic/laplacexz-cyclic.cxx b/src/invert/laplacexz/impls/cyclic/laplacexz-cyclic.cxx index a242bf3432..dc987edc75 100644 --- a/src/invert/laplacexz/impls/cyclic/laplacexz-cyclic.cxx +++ b/src/invert/laplacexz/impls/cyclic/laplacexz-cyclic.cxx @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -61,7 +60,7 @@ LaplaceXZcyclic::LaplaceXZcyclic(Mesh* m, Options* options, const CELL_LOC loc) } void LaplaceXZcyclic::setCoefs(const Field2D& A2D, const Field2D& B2D) { - TRACE("LaplaceXZcyclic::setCoefs"); + Timer timer("invert"); ASSERT1(A2D.getMesh() == localmesh); diff --git a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx index 769e797352..be23d8d014 100644 --- a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx +++ b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx @@ -15,10 +15,8 @@ #if BOUT_HAS_PETSC // Requires PETSc #include -#include - -#include #include +#include LaplaceXZpetsc::LaplaceXZpetsc(Mesh* m, Options* opt, const CELL_LOC loc) : LaplaceXZ(m, opt, loc), lib(opt == nullptr ? &(Options::root()["laplacexz"]) : opt), @@ -97,8 +95,6 @@ LaplaceXZpetsc::LaplaceXZpetsc(Mesh* m, Options* opt, const CELL_LOC loc) * given by b */ - TRACE("LaplaceXZpetsc::LaplaceXZpetsc"); - if (opt == nullptr) { // If no options supplied, use default opt = &(Options::root())["laplacexz"]; @@ -260,8 +256,6 @@ LaplaceXZpetsc::LaplaceXZpetsc(Mesh* m, Options* opt, const CELL_LOC loc) LaplaceXZpetsc::~LaplaceXZpetsc() { - TRACE("LaplaceXZpetsc::~LaplaceXZpetsc"); - PetscBool petsc_is_finalised; PetscFinalized(&petsc_is_finalised); @@ -293,8 +287,6 @@ void LaplaceXZpetsc::setCoefs(const Field3D& Ain, const Field3D& Bin) { * Bin - The B coefficient in div(A grad_perp(B)) + Bf = b */ - TRACE("LaplaceXZpetsc::setCoefs"); - ASSERT1(Ain.getMesh() == localmesh); ASSERT1(Bin.getMesh() == localmesh); ASSERT1(Ain.getLocation() == location); @@ -767,8 +759,6 @@ Field3D LaplaceXZpetsc::solve(const Field3D& bin, const Field3D& x0in) { * result - The solved x (returned as a Field3D) in the matrix problem Ax=b */ - TRACE("LaplaceXZpetsc::solve"); - ASSERT1(bin.getMesh() == localmesh); ASSERT1(x0in.getMesh() == localmesh); ASSERT1(bin.getLocation() == location); diff --git a/src/invert/parderiv/impls/cyclic/cyclic.cxx b/src/invert/parderiv/impls/cyclic/cyclic.cxx index 5a798ca1d5..61d23be823 100644 --- a/src/invert/parderiv/impls/cyclic/cyclic.cxx +++ b/src/invert/parderiv/impls/cyclic/cyclic.cxx @@ -46,10 +46,8 @@ #include #include #include -#include -#include - #include +#include #include @@ -63,7 +61,7 @@ InvertParCR::InvertParCR(Options* opt, CELL_LOC location, Mesh* mesh_in) } const Field3D InvertParCR::solve(const Field3D& f) { - TRACE("InvertParCR::solve(Field3D)"); + ASSERT1(localmesh == f.getMesh()); ASSERT1(location == f.getLocation()); diff --git a/src/invert/pardiv/impls/cyclic/pardiv_cyclic.cxx b/src/invert/pardiv/impls/cyclic/pardiv_cyclic.cxx index be65d5ab0b..d4e773f017 100644 --- a/src/invert/pardiv/impls/cyclic/pardiv_cyclic.cxx +++ b/src/invert/pardiv/impls/cyclic/pardiv_cyclic.cxx @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -59,7 +58,7 @@ InvertParDivCR::InvertParDivCR(Options* opt, CELL_LOC location, Mesh* mesh_in) } Field3D InvertParDivCR::solve(const Field3D& f) { - TRACE("InvertParDivCR::solve(Field3D)"); + ASSERT1(localmesh == f.getMesh()); ASSERT1(location == f.getLocation()); diff --git a/src/mesh/boundary_standard.cxx b/src/mesh/boundary_standard.cxx index 8f2c7df5ec..4019fc4eea 100644 --- a/src/mesh/boundary_standard.cxx +++ b/src/mesh/boundary_standard.cxx @@ -1,12 +1,12 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -29,8 +29,6 @@ using bout::generator::Context; */ #if CHECK > 0 void verifyNumPoints(BoundaryRegion* region, int ptsRequired) { - TRACE("Verifying number of points available for BC"); - int ptsAvailGlobal, ptsAvailLocal, ptsAvail; std::string side, gridType; Mesh* mesh = region->localmesh; @@ -3605,7 +3603,6 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { } void BoundaryRelax::apply_ddt(Field2D & f) { - TRACE("BoundaryRelax::apply_ddt(Field2D)"); // Make a copy of f Field2D g = f; @@ -3621,7 +3618,6 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { } void BoundaryRelax::apply_ddt(Field3D & f) { - TRACE("BoundaryRelax::apply_ddt(Field3D)"); Mesh* mesh = bndry->localmesh; ASSERT1(mesh == f.getMesh()); diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 3dfee6a553..8453a5205f 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -5,9 +5,9 @@ **************************************************************************/ #include +#include #include #include -#include #include #include #include @@ -931,7 +931,7 @@ const Field2D& Coordinates::zlength() const { int Coordinates::geometry(bool recalculate_staggered, bool force_interpolate_from_centre) { - TRACE("Coordinates::geometry"); + localmesh->communicate_no_slices(dx, dy, dz, g11, g22, g33, g12, g13, g23, g_11, g_22, g_33, g_12, g_13, g_23, J, Bxy); @@ -1201,7 +1201,6 @@ int Coordinates::geometry(bool recalculate_staggered, } int Coordinates::calcCovariant(const std::string& region) { - TRACE("Coordinates::calcCovariant"); // Make sure metric elements are allocated g_11.allocate(); @@ -1264,7 +1263,6 @@ int Coordinates::calcCovariant(const std::string& region) { } int Coordinates::calcContravariant(const std::string& region) { - TRACE("Coordinates::calcContravariant"); // Make sure metric elements are allocated g11.allocate(); @@ -1319,7 +1317,7 @@ int Coordinates::calcContravariant(const std::string& region) { } int Coordinates::jacobian() { - TRACE("Coordinates::jacobian"); + // calculate Jacobian using g^-1 = det[g^ij], J = sqrt(g) const bool extrapolate_x = not localmesh->sourceHasXBoundaryGuards(); @@ -1521,7 +1519,7 @@ Field3D Coordinates::DDZ(const Field3D& f, CELL_LOC outloc, const std::string& m Coordinates::FieldMetric Coordinates::Grad_par(const Field2D& var, [[maybe_unused]] CELL_LOC outloc, const std::string& UNUSED(method)) { - TRACE("Coordinates::Grad_par( Field2D )"); + ASSERT1(location == outloc || (outloc == CELL_DEFAULT && location == var.getLocation())); @@ -1530,7 +1528,7 @@ Coordinates::FieldMetric Coordinates::Grad_par(const Field2D& var, Field3D Coordinates::Grad_par(const Field3D& var, CELL_LOC outloc, const std::string& method) { - TRACE("Coordinates::Grad_par( Field3D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); return ::DDY(var, outloc, method) * invSg(); @@ -1560,7 +1558,7 @@ Field3D Coordinates::Vpar_Grad_par(const Field3D& v, const Field3D& f, CELL_LOC Coordinates::FieldMetric Coordinates::Div_par(const Field2D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Coordinates::Div_par( Field2D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); // Need Bxy at location of f, which might be different from location of this @@ -1572,7 +1570,7 @@ Coordinates::FieldMetric Coordinates::Div_par(const Field2D& f, CELL_LOC outloc, Field3D Coordinates::Div_par(const Field3D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Coordinates::Div_par( Field3D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); // Need Bxy at location of f, which might be different from location of this @@ -1601,7 +1599,7 @@ Field3D Coordinates::Div_par(const Field3D& f, CELL_LOC outloc, Coordinates::FieldMetric Coordinates::Grad2_par2(const Field2D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Coordinates::Grad2_par2( Field2D )"); + ASSERT1(location == outloc || (outloc == CELL_DEFAULT && location == f.getLocation())); auto result = Grad2_par2_DDY_invSg(outloc, method) * DDY(f, outloc, method) @@ -1612,7 +1610,7 @@ Coordinates::FieldMetric Coordinates::Grad2_par2(const Field2D& f, CELL_LOC outl Field3D Coordinates::Grad2_par2(const Field3D& f, CELL_LOC outloc, const std::string& method) { - TRACE("Coordinates::Grad2_par2( Field3D )"); + if (outloc == CELL_DEFAULT) { outloc = f.getLocation(); } @@ -1636,7 +1634,7 @@ Field3D Coordinates::Grad2_par2(const Field3D& f, CELL_LOC outloc, Coordinates::FieldMetric Coordinates::Delp2(const Field2D& f, CELL_LOC outloc, bool UNUSED(useFFT)) { - TRACE("Coordinates::Delp2( Field2D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); auto result = G1 * DDX(f, outloc) + g11 * D2DX2(f, outloc); @@ -1645,7 +1643,6 @@ Coordinates::FieldMetric Coordinates::Delp2(const Field2D& f, CELL_LOC outloc, } Field3D Coordinates::Delp2(const Field3D& f, CELL_LOC outloc, bool useFFT) { - TRACE("Coordinates::Delp2( Field3D )"); if (outloc == CELL_DEFAULT) { outloc = f.getLocation(); @@ -1711,7 +1708,6 @@ Field3D Coordinates::Delp2(const Field3D& f, CELL_LOC outloc, bool useFFT) { } FieldPerp Coordinates::Delp2(const FieldPerp& f, CELL_LOC outloc, bool useFFT) { - TRACE("Coordinates::Delp2( FieldPerp )"); if (outloc == CELL_DEFAULT) { outloc = f.getLocation(); @@ -1788,7 +1784,7 @@ Field3D Coordinates::Laplace_par(const Field3D& f, CELL_LOC outloc) { Coordinates::FieldMetric Coordinates::Laplace(const Field2D& f, CELL_LOC outloc, const std::string& dfdy_boundary_conditions, const std::string& dfdy_dy_region) { - TRACE("Coordinates::Laplace( Field2D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); auto result = G1 * DDX(f, outloc) + G2 * DDY(f, outloc) + g11 * D2DX2(f, outloc) @@ -1803,7 +1799,7 @@ Coordinates::FieldMetric Coordinates::Laplace(const Field2D& f, CELL_LOC outloc, Field3D Coordinates::Laplace(const Field3D& f, CELL_LOC outloc, const std::string& dfdy_boundary_conditions, const std::string& dfdy_dy_region) { - TRACE("Coordinates::Laplace( Field3D )"); + ASSERT1(location == outloc || outloc == CELL_DEFAULT); Field3D result = G1 * ::DDX(f, outloc) + G2 * ::DDY(f, outloc) + G3 * ::DDZ(f, outloc) @@ -1822,7 +1818,7 @@ Field3D Coordinates::Laplace(const Field3D& f, CELL_LOC outloc, // solver Field2D Coordinates::Laplace_perpXY([[maybe_unused]] const Field2D& A, [[maybe_unused]] const Field2D& f) { - TRACE("Coordinates::Laplace_perpXY( Field2D )"); + #if not(BOUT_USE_METRIC_3D) Field2D result; result.allocate(); diff --git a/src/mesh/coordinates_accessor.cxx b/src/mesh/coordinates_accessor.cxx index aff546c2b0..0ce4b664b5 100644 --- a/src/mesh/coordinates_accessor.cxx +++ b/src/mesh/coordinates_accessor.cxx @@ -1,4 +1,5 @@ #include "bout/coordinates_accessor.hxx" +#include #include "bout/mesh.hxx" diff --git a/src/mesh/data/gridfromfile.cxx b/src/mesh/data/gridfromfile.cxx index 5078882136..10f6f6926e 100644 --- a/src/mesh/data/gridfromfile.cxx +++ b/src/mesh/data/gridfromfile.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -20,7 +19,6 @@ GridFile::GridFile(std::string gridfilename) : GridDataSource(true), data(bout::OptionsIO::create(gridfilename)->read()), filename(std::move(gridfilename)) { - TRACE("GridFile constructor"); // Get number of y-boundary guard cells saved in the grid file grid_yguards = data["y_boundary_guards"].withDefault(0); @@ -60,7 +58,7 @@ bool GridFile::hasVar(const std::string& name) { return data.isSet(name); } bool GridFile::get(Mesh* UNUSED(m), std::string& sval, const std::string& name, const std::string& def) { Timer timer("io"); - TRACE("GridFile::get(std::string)"); + const bool success = data.isSet(name); if (not success) { // Override any previously set defaults @@ -93,7 +91,7 @@ bool GridFile::get(Mesh* UNUSED(m), std::string& sval, const std::string& name, */ bool GridFile::get(Mesh* UNUSED(m), int& ival, const std::string& name, int def) { Timer timer("io"); - TRACE("GridFile::get(int)"); + const bool success = data.isSet(name); if (not success) { // Override any previously set defaults @@ -110,7 +108,7 @@ bool GridFile::get(Mesh* UNUSED(m), int& ival, const std::string& name, int def) bool GridFile::get(Mesh* UNUSED(m), BoutReal& rval, const std::string& name, BoutReal def) { Timer timer("io"); - TRACE("GridFile::get(BoutReal)"); + const bool success = data.isSet(name); if (not success) { // Override any previously set defaults @@ -143,7 +141,6 @@ bool GridFile::getField(Mesh* m, T& var, const std::string& name, BoutReal def, "templated GridFile::getField only works for Field2D, Field3D or FieldPerp"); Timer timer("io"); - AUTO_TRACE(); if (not data.isSet(name)) { // Variable not found @@ -473,7 +470,6 @@ bool GridFile::get([[maybe_unused]] Mesh* m, [[maybe_unused]] std::vector& [[maybe_unused]] const std::string& name, [[maybe_unused]] int len, [[maybe_unused]] int offset, [[maybe_unused]] GridDataSource::Direction dir) { - TRACE("GridFile::get(vector)"); if (not data.isSet(name)) { return false; @@ -499,7 +495,6 @@ bool GridFile::get([[maybe_unused]] Mesh* m, [[maybe_unused]] std::vector& bool GridFile::get(Mesh* UNUSED(m), std::vector& var, const std::string& name, int len, int offset, GridDataSource::Direction UNUSED(dir)) { - TRACE("GridFile::get(vector)"); if (not data.isSet(name)) { return false; diff --git a/src/mesh/difops.cxx b/src/mesh/difops.cxx index 42fa4d6ca5..9084f90465 100644 --- a/src/mesh/difops.cxx +++ b/src/mesh/difops.cxx @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -458,8 +457,6 @@ Field2D Laplace_perpXY(const Field2D& A, const Field2D& f) { Coordinates::FieldMetric b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, CELL_LOC outloc) { - TRACE("b0xGrad_dot_Grad( Field2D , Field2D )"); - if (outloc == CELL_DEFAULT) { outloc = A.getLocation(); } @@ -489,7 +486,6 @@ Coordinates::FieldMetric b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, } Field3D b0xGrad_dot_Grad(const Field2D& phi, const Field3D& A, CELL_LOC outloc) { - TRACE("b0xGrad_dot_Grad( Field2D , Field3D )"); if (outloc == CELL_DEFAULT) { outloc = A.getLocation(); @@ -531,7 +527,6 @@ Field3D b0xGrad_dot_Grad(const Field2D& phi, const Field3D& A, CELL_LOC outloc) } Field3D b0xGrad_dot_Grad(const Field3D& p, const Field2D& A, CELL_LOC outloc) { - TRACE("b0xGrad_dot_Grad( Field3D , Field2D )"); if (outloc == CELL_DEFAULT) { outloc = A.getLocation(); @@ -566,7 +561,6 @@ Field3D b0xGrad_dot_Grad(const Field3D& p, const Field2D& A, CELL_LOC outloc) { } Field3D b0xGrad_dot_Grad(const Field3D& phi, const Field3D& A, CELL_LOC outloc) { - TRACE("b0xGrad_dot_Grad( Field3D , Field3D )"); if (outloc == CELL_DEFAULT) { outloc = A.getLocation(); @@ -614,7 +608,6 @@ Field3D b0xGrad_dot_Grad(const Field3D& phi, const Field3D& A, CELL_LOC outloc) Coordinates::FieldMetric bracket(const Field2D& f, const Field2D& g, BRACKET_METHOD method, CELL_LOC outloc, Solver* UNUSED(solver)) { - TRACE("bracket(Field2D, Field2D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); if (outloc == CELL_DEFAULT) { @@ -637,7 +630,6 @@ Coordinates::FieldMetric bracket(const Field2D& f, const Field2D& g, Field3D bracket(const Field3D& f, const Field2D& g, BRACKET_METHOD method, CELL_LOC outloc, Solver* solver) { - TRACE("bracket(Field3D, Field2D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); if (outloc == CELL_DEFAULT) { @@ -826,7 +818,6 @@ Field3D bracket(const Field3D& f, const Field2D& g, BRACKET_METHOD method, Field3D bracket(const Field2D& f, const Field3D& g, BRACKET_METHOD method, CELL_LOC outloc, Solver* solver) { - TRACE("bracket(Field2D, Field3D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); if (outloc == CELL_DEFAULT) { @@ -863,8 +854,6 @@ Field3D bracket(const Field2D& f, const Field3D& g, BRACKET_METHOD method, Field3D bracket(const Field3D& f, const Field3D& g, BRACKET_METHOD method, CELL_LOC outloc, [[maybe_unused]] Solver* solver) { - TRACE("Field3D, Field3D"); - ASSERT1_FIELDS_COMPATIBLE(f, g); if (outloc == CELL_DEFAULT) { outloc = g.getLocation(); diff --git a/src/mesh/fv_ops.cxx b/src/mesh/fv_ops.cxx index fe5422b4d1..a0a6e1d3c1 100644 --- a/src/mesh/fv_ops.cxx +++ b/src/mesh/fv_ops.cxx @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -181,7 +180,6 @@ Field3D Div_a_Grad_perp(const Field3D& a, const Field3D& f) { const Field3D Div_par_K_Grad_par(const Field3D& Kin, const Field3D& fin, bool bndry_flux) { - TRACE("FV::Div_par_K_Grad_par"); ASSERT2(Kin.getLocation() == fin.getLocation()); diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index 8917fa3753..8eb09f84ec 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -431,7 +431,6 @@ void BoutMesh::setDerivedGridSizes() { } int BoutMesh::load() { - TRACE("BoutMesh::load()"); output_progress << _("Loading mesh") << endl; @@ -1363,7 +1362,6 @@ comm_handle BoutMesh::sendY(FieldGroup& g, comm_handle handle) { } int BoutMesh::wait(comm_handle handle) { - TRACE("BoutMesh::wait(comm_handle)"); if (handle == nullptr) { return 1; diff --git a/src/mesh/index_derivs.cxx b/src/mesh/index_derivs.cxx index add67a77c8..48284c3536 100644 --- a/src/mesh/index_derivs.cxx +++ b/src/mesh/index_derivs.cxx @@ -25,7 +25,6 @@ #include "bout/traits.hxx" #include #include -#include #include /******************************************************************************* @@ -34,7 +33,6 @@ /// Initialise the derivative methods. Must be called before any derivatives are used void Mesh::derivs_init(Options* options) { - TRACE("Initialising derivatives"); // For each direction need to set what the default method is for each type // of derivative. DerivativeStore::getInstance().initialise(options); @@ -45,7 +43,6 @@ void Mesh::derivs_init(Options* options) { STAGGER Mesh::getStagger(const CELL_LOC inloc, const CELL_LOC outloc, const CELL_LOC allowedStaggerLoc) const { - TRACE("Mesh::getStagger -- three arguments"); ASSERT1(outloc == inloc || (outloc == CELL_CENTRE && inloc == allowedStaggerLoc) || (outloc == allowedStaggerLoc && inloc == CELL_CENTRE)); @@ -61,7 +58,6 @@ STAGGER Mesh::getStagger(const CELL_LOC inloc, const CELL_LOC outloc, STAGGER Mesh::getStagger(const CELL_LOC vloc, [[maybe_unused]] const CELL_LOC inloc, const CELL_LOC outloc, const CELL_LOC allowedStaggerLoc) const { - TRACE("Mesh::getStagger -- four arguments"); ASSERT1(inloc == outloc); ASSERT1(vloc == inloc || (vloc == CELL_CENTRE && inloc == allowedStaggerLoc) || (vloc == allowedStaggerLoc && inloc == CELL_CENTRE)); @@ -423,7 +419,7 @@ class FFTDerivativeType { public: template void standard(const T& var, T& result, const std::string& region) const { - AUTO_TRACE(); + ASSERT2(meta.derivType == DERIV::Standard) ASSERT2(var.getMesh()->getNguard(direction) >= nGuards); ASSERT2(direction == DIRECTION::Z); // Only in Z for now @@ -479,7 +475,7 @@ class FFTDerivativeType { template void upwindOrFlux(const T& UNUSED(vel), const T& UNUSED(var), T& UNUSED(result), const std::string& UNUSED(region)) const { - AUTO_TRACE(); + throw BoutException("The FFT METHOD isn't available in upwind/Flux"); } static constexpr metaData meta{"FFT", 0, DERIV::Standard}; @@ -489,7 +485,7 @@ class FFT2ndDerivativeType { public: template void standard(const T& var, T& result, const std::string& region) const { - AUTO_TRACE(); + ASSERT2(meta.derivType == DERIV::StandardSecond); ASSERT2(var.getMesh()->getNguard(direction) >= nGuards); ASSERT2(direction == DIRECTION::Z); // Only in Z for now @@ -536,7 +532,7 @@ class FFT2ndDerivativeType { template void upwindOrFlux(const T& UNUSED(vel), const T& UNUSED(var), T& UNUSED(result), const std::string& UNUSED(region)) const { - AUTO_TRACE(); + throw BoutException("The FFT METHOD isn't available in upwind/Flux"); } static constexpr metaData meta{"FFT", 0, DERIV::StandardSecond}; @@ -552,14 +548,14 @@ class SplitFluxDerivativeType { public: template void standard(const T&, T&, const std::string) const { - AUTO_TRACE(); + throw BoutException("The SPLIT method isn't available for standard"); } template void upwindOrFlux(const T& vel, const T& var, T& result, const std::string region) const { - AUTO_TRACE(); + // Split into an upwind and a central differencing part // d/dx(v*f) = v*d/dx(f) + f*d/dx(v) result = bout::derivatives::index::flowDerivative( diff --git a/src/mesh/interpolation_xz.cxx b/src/mesh/interpolation_xz.cxx index f7f0b457f2..a58554dc82 100644 --- a/src/mesh/interpolation_xz.cxx +++ b/src/mesh/interpolation_xz.cxx @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -36,7 +35,6 @@ const char* strLocation(CELL_LOC loc) { return toString(loc).c_str(); } const Field3D interpolate(const Field3D& f, const Field3D& delta_x, const Field3D& delta_z) { - TRACE("Interpolating 3D field"); XZLagrange4pt interpolateMethod{f.getMesh()}; return interpolateMethod.interpolate(f, delta_x, delta_z); } @@ -47,8 +45,6 @@ const Field3D interpolate(const Field2D& f, const Field3D& delta_x, } const Field3D interpolate(const Field2D& f, const Field3D& delta_x) { - TRACE("interpolate(Field2D, Field3D)"); - Mesh* mesh = f.getMesh(); ASSERT1(mesh == delta_x.getMesh()); Field3D result{emptyFrom(delta_x)}; diff --git a/src/mesh/invert3x3.hxx b/src/mesh/invert3x3.hxx index c011f55bf7..746765d913 100644 --- a/src/mesh/invert3x3.hxx +++ b/src/mesh/invert3x3.hxx @@ -37,7 +37,6 @@ /// return. Otherwise, an empty `std::optional` is return namespace bout { inline std::optional invert3x3(Matrix& a) { - TRACE("invert3x3"); // Calculate the first co-factors const BoutReal A = a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1); diff --git a/src/mesh/mesh.cxx b/src/mesh/mesh.cxx index 1d3f3b0dbe..8964a6b797 100644 --- a/src/mesh/mesh.cxx +++ b/src/mesh/mesh.cxx @@ -298,7 +298,6 @@ bool Mesh::sourceHasYBoundaryGuards() { return source->hasYBoundaryGuards(); } **************************************************************************/ void Mesh::communicateXZ(FieldGroup& g) { - TRACE("Mesh::communicate(FieldGroup&)"); // Send data comm_handle h = sendX(g); @@ -308,7 +307,6 @@ void Mesh::communicateXZ(FieldGroup& g) { } void Mesh::communicateYZ(FieldGroup& g) { - TRACE("Mesh::communicate(FieldGroup&)"); // Send data comm_handle h = sendY(g); @@ -325,7 +323,6 @@ void Mesh::communicateYZ(FieldGroup& g) { } void Mesh::communicate(FieldGroup& g) { - TRACE("Mesh::communicate(FieldGroup&)"); if (include_corner_cells) { // Send data in y-direction diff --git a/src/mesh/parallel/fci.cxx b/src/mesh/parallel/fci.cxx index e8d3af1cdb..08e56584e1 100644 --- a/src/mesh/parallel/fci.cxx +++ b/src/mesh/parallel/fci.cxx @@ -251,7 +251,6 @@ FCIMap::FCIMap(Mesh& mesh, const Coordinates::FieldMetric& UNUSED(dy), Options& } Field3D FCIMap::integrate(Field3D& f) const { - TRACE("FCIMap::integrate"); ASSERT1(f.getDirectionY() == YDirectionType::Standard); ASSERT1(&map_mesh == f.getMesh()); @@ -315,7 +314,6 @@ void FCITransform::checkInputGrid() { } void FCITransform::calcParallelSlices(Field3D& f) { - TRACE("FCITransform::calcParallelSlices"); ASSERT1(f.getDirectionY() == YDirectionType::Standard); // Only have forward_map/backward_map for CELL_CENTRE, so can only deal with @@ -333,7 +331,6 @@ void FCITransform::calcParallelSlices(Field3D& f) { } void FCITransform::integrateParallelSlices(Field3D& f) { - TRACE("FCITransform::integrateParallelSlices"); ASSERT1(f.getDirectionY() == YDirectionType::Standard); // Only have forward_map/backward_map for CELL_CENTRE, so can only deal with diff --git a/src/mesh/parallel/shiftedmetricinterp.cxx b/src/mesh/parallel/shiftedmetricinterp.cxx index 7f3637e79c..4543c4c3fb 100644 --- a/src/mesh/parallel/shiftedmetricinterp.cxx +++ b/src/mesh/parallel/shiftedmetricinterp.cxx @@ -211,7 +211,6 @@ void ShiftedMetricInterp::checkInputGrid() { * Calculate the Y up and down fields */ void ShiftedMetricInterp::calcParallelSlices(Field3D& f) { - AUTO_TRACE(); // Ensure that yup and ydown are different fields f.splitParallelSlices(); diff --git a/src/physics/physicsmodel.cxx b/src/physics/physicsmodel.cxx index f4be3bde2a..a1bde18248 100644 --- a/src/physics/physicsmodel.cxx +++ b/src/physics/physicsmodel.cxx @@ -164,7 +164,6 @@ void PhysicsModel::bout_solve(Vector3D& var, const char* name, } int PhysicsModel::postInit(bool restarting) { - TRACE("PhysicsModel::postInit"); if (restarting) { solver->readEvolvingVariablesFromOptions(restart_options); diff --git a/src/physics/smoothing.cxx b/src/physics/smoothing.cxx index 0a1391907f..309fff1542 100644 --- a/src/physics/smoothing.cxx +++ b/src/physics/smoothing.cxx @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -46,7 +45,6 @@ // Smooth using simple 1-2-1 filter const Field3D smooth_x(const Field3D& f) { - TRACE("smooth_x"); Mesh* mesh = f.getMesh(); Field3D result{emptyFrom(f)}; @@ -76,7 +74,6 @@ const Field3D smooth_x(const Field3D& f) { } const Field3D smooth_y(const Field3D& f) { - TRACE("smooth_y"); Mesh* mesh = f.getMesh(); Field3D result{emptyFrom(f)}; @@ -117,7 +114,6 @@ const Field3D smooth_y(const Field3D& f) { so no processor/branch cuts in X */ const Field2D averageX(const Field2D& f) { - TRACE("averageX(Field2D)"); Mesh* mesh = f.getMesh(); int ngx = mesh->LocalNx; @@ -176,8 +172,6 @@ const Field2D averageX(const Field2D& f) { */ const Field3D averageX(const Field3D& f) { - TRACE("averageX(Field3D)"); - Mesh* mesh = f.getMesh(); int ngx = mesh->LocalNx; @@ -230,8 +224,6 @@ const Field3D averageX(const Field3D& f) { } const Field2D averageY(const Field2D& f) { - TRACE("averageY(Field2D)"); - Mesh* mesh = f.getMesh(); int ngx = mesh->LocalNx; int ngy = mesh->LocalNy; @@ -275,8 +267,6 @@ const Field2D averageY(const Field2D& f) { } const Field3D averageY(const Field3D& f) { - TRACE("averageY(Field3D)"); - Mesh* mesh = f.getMesh(); int ngx = mesh->LocalNx; @@ -352,7 +342,7 @@ BoutReal Average_XY(const Field2D& var) { BoutReal Vol_Integral(const Field2D& var) { #if BOUT_USE_METRIC_3D - AUTO_TRACE(); + throw BoutException("Vol_Intregral currently incompatible with 3D metrics"); #else Mesh* mesh = var.getMesh(); @@ -431,7 +421,7 @@ void nl_filter(rvec& f, BoutReal w) { } const Field3D nl_filter_x(const Field3D& f, BoutReal w) { - TRACE("nl_filter_x( Field3D )"); + Mesh* mesh = f.getMesh(); Field3D result{emptyFrom(f)}; @@ -453,7 +443,6 @@ const Field3D nl_filter_x(const Field3D& f, BoutReal w) { } const Field3D nl_filter_y(const Field3D& f, BoutReal w) { - TRACE("nl_filter_x( Field3D )"); Mesh* mesh = f.getMesh(); @@ -481,7 +470,6 @@ const Field3D nl_filter_y(const Field3D& f, BoutReal w) { } const Field3D nl_filter_z(const Field3D& fs, BoutReal w) { - TRACE("nl_filter_z( Field3D )"); Mesh* mesh = fs.getMesh(); Field3D result{emptyFrom(fs)}; diff --git a/src/physics/sourcex.cxx b/src/physics/sourcex.cxx index 1cfc2fdc6e..659abbf409 100644 --- a/src/physics/sourcex.cxx +++ b/src/physics/sourcex.cxx @@ -2,15 +2,13 @@ * radial source and mask operators **************************************************************/ -#include -#include - #include +#include #include -#include #include +#include -#include "bout/unused.hxx" +#include BoutReal TanH(BoutReal a) { BoutReal temp = exp(a); @@ -77,7 +75,6 @@ const Field3D sink_tanhx(const Field2D& UNUSED(f0), const Field3D& f, BoutReal s // create radial buffer zones to set jpar zero near radial boundaries const Field3D mask_x(const Field3D& f, bool UNUSED(BoutRealspace)) { - TRACE("mask_x"); Mesh* localmesh = f.getMesh(); @@ -101,7 +98,6 @@ const Field3D mask_x(const Field3D& f, bool UNUSED(BoutRealspace)) { // create radial buffer zones to set jpar zero near radial boundaries const Field3D sink_tanhxl(const Field2D& UNUSED(f0), const Field3D& f, BoutReal swidth, BoutReal slength, bool UNUSED(BoutRealspace)) { - TRACE("sink_tanhx"); Mesh* localmesh = f.getMesh(); @@ -123,7 +119,6 @@ const Field3D sink_tanhxl(const Field2D& UNUSED(f0), const Field3D& f, BoutReal // create radial buffer zones to set jpar zero near radial boundaries const Field3D sink_tanhxr(const Field2D& UNUSED(f0), const Field3D& f, BoutReal swidth, BoutReal slength, bool UNUSED(BoutRealspace)) { - TRACE("sink_tanhxr"); Mesh* localmesh = f.getMesh(); @@ -144,7 +139,6 @@ const Field3D sink_tanhxr(const Field2D& UNUSED(f0), const Field3D& f, BoutReal // create radial buffer zones to damp Psi to zero near radial boundaries const Field3D buff_x(const Field3D& f, bool UNUSED(BoutRealspace)) { - TRACE("buff_x"); Mesh* localmesh = f.getMesh(); diff --git a/src/solver/impls/adams_bashforth/adams_bashforth.cxx b/src/solver/impls/adams_bashforth/adams_bashforth.cxx index 79161fcdbf..51fff4fe6a 100644 --- a/src/solver/impls/adams_bashforth/adams_bashforth.cxx +++ b/src/solver/impls/adams_bashforth/adams_bashforth.cxx @@ -4,17 +4,11 @@ #include #include -#include -#include - #include -#include - namespace { BoutReal lagrange_at_position_denominator(const std::deque& grid, const int position, const int order) { - AUTO_TRACE(); const auto xj = grid[position]; @@ -28,7 +22,7 @@ BoutReal lagrange_at_position_denominator(const std::deque& grid, BoutReal lagrange_at_position_numerator(const BoutReal varX, const std::deque& grid, const int position, const int order) { - AUTO_TRACE(); + BoutReal result = 1.0; for (int i = 0; i < order; i++) { result *= (i != position) ? (varX - grid[i]) : 1.0; @@ -55,7 +49,7 @@ BoutReal lagrange_interpolate(BoutReal start, BoutReal end, BoutReal integrate_lagrange_curve_nc9(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 9; constexpr BoutReal fac = 4.0 / 14175.0; constexpr std::array facs{989.0 * fac, 5888.0 * fac, -928.0 * fac, @@ -68,7 +62,7 @@ BoutReal integrate_lagrange_curve_nc9(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc8(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 8; constexpr BoutReal fac = 7.0 / 17280.0; constexpr std::array facs{751.0 * fac, 3577.0 * fac, 1323.0 * fac, @@ -81,7 +75,7 @@ BoutReal integrate_lagrange_curve_nc8(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc7(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 7; constexpr BoutReal fac = 1.0 / 140.0; constexpr std::array facs{41.0 * fac, 216.0 * fac, 27.0 * fac, @@ -94,7 +88,7 @@ BoutReal integrate_lagrange_curve_nc7(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc6(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 6; constexpr BoutReal fac = 5.0 / 288.0; constexpr std::array facs{19.0 * fac, 75.0 * fac, 50.0 * fac, @@ -106,7 +100,7 @@ BoutReal integrate_lagrange_curve_nc6(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc5(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 5; constexpr BoutReal fac = 2.0 / 45.0; constexpr std::array facs{7.0 * fac, 32.0 * fac, 12.0 * fac, 32.0 * fac, @@ -118,7 +112,7 @@ BoutReal integrate_lagrange_curve_nc5(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc4(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 4; constexpr BoutReal fac = 3.0 / 8.0; constexpr std::array facs{1.0 * fac, 3.0 * fac, 3.0 * fac, 1.0 * fac}; @@ -129,7 +123,7 @@ BoutReal integrate_lagrange_curve_nc4(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc3(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 3; constexpr BoutReal fac = 1.0 / 3.0; constexpr std::array facs{1.0 * fac, 4.0 * fac, 1.0 * fac}; @@ -140,7 +134,7 @@ BoutReal integrate_lagrange_curve_nc3(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve_nc2(const BoutReal start, const BoutReal end, const std::deque& points, const int position) { - AUTO_TRACE(); + constexpr std::size_t size = 2; constexpr BoutReal fac = 1.0 / 2.0; constexpr std::array facs{1.0 * fac, 1.0 * fac}; @@ -151,7 +145,6 @@ BoutReal integrate_lagrange_curve_nc2(const BoutReal start, const BoutReal end, BoutReal integrate_lagrange_curve(const BoutReal start, const BoutReal end, const std::deque& points, const int position, const int order) { - AUTO_TRACE(); switch (order) { case 1: @@ -179,7 +172,7 @@ BoutReal integrate_lagrange_curve(const BoutReal start, const BoutReal end, std::vector get_adams_bashforth_coefficients(const BoutReal nextPoint, const std::deque& points, const int order) { - AUTO_TRACE(); + ASSERT2(static_cast(order) <= points.size()); std::vector result; @@ -235,7 +228,7 @@ BoutReal get_timestep_limit(const BoutReal error, const BoutReal tolerance, /// over all processors. BoutReal get_error(const Array& stateApprox, const Array& stateAccurate) { - AUTO_TRACE(); + BoutReal local_result = 0.0; BoutReal err = 0.0; @@ -287,12 +280,12 @@ AdamsBashforthSolver::AdamsBashforthSolver(Options* options) .withDefault(getOutputTimestep())), timestep( (*options)["timestep"].doc("Starting timestep").withDefault(max_timestep)) { - AUTO_TRACE(); + canReset = true; } void AdamsBashforthSolver::setMaxTimestep(BoutReal dt) { - AUTO_TRACE(); + if (dt > timestep) { return; // Already less than this } @@ -306,8 +299,6 @@ void AdamsBashforthSolver::setMaxTimestep(BoutReal dt) { int AdamsBashforthSolver::init() { - TRACE("Initialising AdamsBashforth solver"); - Solver::init(); output << "\n\tAdams-Bashforth (explicit) multistep solver\n"; @@ -345,7 +336,6 @@ int AdamsBashforthSolver::init() { } void AdamsBashforthSolver::resetInternalFields() { - AUTO_TRACE(); // History and times history.clear(); @@ -360,7 +350,6 @@ void AdamsBashforthSolver::resetInternalFields() { } int AdamsBashforthSolver::run() { - AUTO_TRACE(); // Just for developer diagnostics int nwasted = 0; @@ -563,7 +552,6 @@ int AdamsBashforthSolver::run() { BoutReal AdamsBashforthSolver::take_step(const BoutReal timeIn, const BoutReal dt, const int order, Array& current, Array& result) { - AUTO_TRACE(); Array full_update = AB_integrate(nlocal, timeIn + dt, times, history, order); diff --git a/src/solver/impls/arkode/arkode.cxx b/src/solver/impls/arkode/arkode.cxx index 0151f90167..804e67a803 100644 --- a/src/solver/impls/arkode/arkode.cxx +++ b/src/solver/impls/arkode/arkode.cxx @@ -188,7 +188,6 @@ ArkodeSolver::~ArkodeSolver() { **************************************************************************/ int ArkodeSolver::init() { - TRACE("Initialising ARKODE solver"); Solver::init(); @@ -507,8 +506,6 @@ int ArkodeSolver::init() { **************************************************************************/ int ArkodeSolver::run() { - TRACE("ArkodeSolver::run()"); - if (!initialised) { throw BoutException("ArkodeSolver not initialised\n"); } diff --git a/src/solver/impls/cvode/cvode.cxx b/src/solver/impls/cvode/cvode.cxx index 8b81a66f6d..4f72e65933 100644 --- a/src/solver/impls/cvode/cvode.cxx +++ b/src/solver/impls/cvode/cvode.cxx @@ -177,7 +177,6 @@ CvodeSolver::~CvodeSolver() { **************************************************************************/ int CvodeSolver::init() { - TRACE("Initialising CVODE solver"); Solver::init(); @@ -346,7 +345,6 @@ int CvodeSolver::init() { } } else { output_info.write("\tUsing Newton iteration\n"); - TRACE("Setting preconditioner"); const auto prectype = use_precon ? (rightprec ? SUN_PREC_RIGHT : SUN_PREC_LEFT) : SUN_PREC_NONE; @@ -486,7 +484,6 @@ CvodeSolver::create_constraints(const std::vector>& fields) { **************************************************************************/ int CvodeSolver::run() { - TRACE("CvodeSolver::run()"); if (!cvode_initialised) { throw BoutException("CvodeSolver not initialised\n"); @@ -814,7 +811,7 @@ void CvodeSolver::loop_vector_option_values_op(Ind2D UNUSED(i2d), BoutReal* opti } void CvodeSolver::resetInternalFields() { - TRACE("CvodeSolver::resetInternalFields"); + save_vars(N_VGetArrayPointer(uvec)); if (CVodeReInit(cvode_mem, simtime, uvec) != CV_SUCCESS) { diff --git a/src/solver/impls/euler/euler.cxx b/src/solver/impls/euler/euler.cxx index 3976f4402c..a3911e78d6 100644 --- a/src/solver/impls/euler/euler.cxx +++ b/src/solver/impls/euler/euler.cxx @@ -3,12 +3,7 @@ #include #include -#include #include -#include - -#include - #include EulerSolver::EulerSolver(Options* options) @@ -33,7 +28,6 @@ void EulerSolver::setMaxTimestep(BoutReal dt) { } int EulerSolver::init() { - TRACE("Initialising Euler solver"); Solver::init(); @@ -63,7 +57,6 @@ int EulerSolver::init() { } int EulerSolver::run() { - TRACE("EulerSolver::run()"); for (int s = 0; s < getNumberOutputSteps(); s++) { BoutReal target = simtime + getOutputTimestep(); diff --git a/src/solver/impls/ida/ida.cxx b/src/solver/impls/ida/ida.cxx index e0354e8b57..84a0bd4abd 100644 --- a/src/solver/impls/ida/ida.cxx +++ b/src/solver/impls/ida/ida.cxx @@ -100,8 +100,6 @@ IdaSolver::~IdaSolver() { int IdaSolver::init() { - TRACE("Initialising IDA solver"); - Solver::init(); output.write("Initialising IDA solver\n"); @@ -233,7 +231,6 @@ int IdaSolver::init() { **************************************************************************/ int IdaSolver::run() { - TRACE("IDA IdaSolver::run()"); if (!initialised) { throw BoutException("IdaSolver not initialised\n"); diff --git a/src/solver/impls/imex-bdf2/imex-bdf2.cxx b/src/solver/impls/imex-bdf2/imex-bdf2.cxx index 07188110ab..062979b59a 100644 --- a/src/solver/impls/imex-bdf2/imex-bdf2.cxx +++ b/src/solver/impls/imex-bdf2/imex-bdf2.cxx @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -136,8 +135,6 @@ static PetscErrorCode imexbdf2PCapply(PC pc, Vec x, Vec y) { */ int IMEXBDF2::init() { - TRACE("Initialising IMEX-BDF2 solver"); - Solver::init(); output << "\n\tIMEX-BDF2 time-integration solver\n"; @@ -741,7 +738,6 @@ void IMEXBDF2::constructSNES(SNES* snesIn) { } int IMEXBDF2::run() { - TRACE("IMEXBDF2::run()"); // Multi-step scheme, so first steps are different int order = 1; diff --git a/src/solver/impls/petsc/petsc.cxx b/src/solver/impls/petsc/petsc.cxx index d0535f069d..41e43c31ed 100644 --- a/src/solver/impls/petsc/petsc.cxx +++ b/src/solver/impls/petsc/petsc.cxx @@ -325,8 +325,6 @@ PetscSolver::~PetscSolver() { int PetscSolver::init() { - TRACE("Initialising PETSc-dev solver"); - Solver::init(); int nlocal = getLocalN(); // Number of evolving variables on this processor @@ -970,7 +968,6 @@ PetscErrorCode PetscSolver::formFunction(Vec U, Vec F) { // Matrix-free preconditioner function PetscErrorCode PetscSolver::pre(Vec x, Vec y) { - TRACE("PetscSolver::pre()"); BoutReal* data; diff --git a/src/solver/impls/power/power.cxx b/src/solver/impls/power/power.cxx index 888338b94c..5dfccfedda 100644 --- a/src/solver/impls/power/power.cxx +++ b/src/solver/impls/power/power.cxx @@ -3,19 +3,16 @@ #include "power.hxx" #include -#include +#include #include #include -#include - PowerSolver::PowerSolver(Options* opts) : Solver(opts), curtime((*options)["curtime"].doc("Simulation time (fixed)").withDefault(0.0)) {} int PowerSolver::init() { - TRACE("Initialising Power solver"); Solver::init(); output << "\n\tPower eigenvalue solver\n"; @@ -44,7 +41,6 @@ int PowerSolver::init() { } int PowerSolver::run() { - TRACE("PowerSolver::run()"); // Make sure that f0 has a norm of 1 divide(f0, norm(f0)); diff --git a/src/solver/impls/pvode/pvode.cxx b/src/solver/impls/pvode/pvode.cxx index 63d3c11753..cb6e81d80a 100644 --- a/src/solver/impls/pvode/pvode.cxx +++ b/src/solver/impls/pvode/pvode.cxx @@ -90,7 +90,6 @@ PvodeSolver::~PvodeSolver() { **************************************************************************/ int PvodeSolver::init() { - TRACE("Initialising PVODE solver"); int mudq, mldq, mukeep, mlkeep; boole optIn; @@ -218,7 +217,6 @@ int PvodeSolver::init() { **************************************************************************/ int PvodeSolver::run() { - TRACE("PvodeSolver::run()"); if (!pvode_initialised) { throw BoutException("PvodeSolver not initialised\n"); diff --git a/src/solver/impls/rk3-ssp/rk3-ssp.cxx b/src/solver/impls/rk3-ssp/rk3-ssp.cxx index e13d996c00..7c00d44b34 100644 --- a/src/solver/impls/rk3-ssp/rk3-ssp.cxx +++ b/src/solver/impls/rk3-ssp/rk3-ssp.cxx @@ -3,10 +3,8 @@ #include #include -#include #include #include -#include #include @@ -28,7 +26,6 @@ void RK3SSP::setMaxTimestep(BoutReal dt) { } int RK3SSP::init() { - TRACE("Initialising RK3 SSP solver"); Solver::init(); output << "\n\tRunge-Kutta 3rd-order SSP solver\n"; @@ -63,7 +60,6 @@ int RK3SSP::init() { } int RK3SSP::run() { - TRACE("RK3SSP::run()"); for (int s = 0; s < getNumberOutputSteps(); s++) { BoutReal target = simtime + getOutputTimestep(); diff --git a/src/solver/impls/rk4/rk4.cxx b/src/solver/impls/rk4/rk4.cxx index 0e7a942a45..35b3cc2268 100644 --- a/src/solver/impls/rk4/rk4.cxx +++ b/src/solver/impls/rk4/rk4.cxx @@ -3,14 +3,12 @@ #include #include -#include #include +#include #include #include -#include - RK4Solver::RK4Solver(Options* opts) : Solver(opts), atol((*options)["atol"].doc("Absolute tolerance").withDefault(1.e-5)), rtol((*options)["rtol"].doc("Relative tolerance").withDefault(1.e-3)), @@ -39,8 +37,6 @@ void RK4Solver::setMaxTimestep(BoutReal dt) { int RK4Solver::init() { - TRACE("Initialising RK4 solver"); - Solver::init(); output << "\n\tRunge-Kutta 4th-order solver\n"; @@ -77,8 +73,6 @@ int RK4Solver::init() { } int RK4Solver::run() { - TRACE("RK4Solver::run()"); - for (int s = 0; s < getNumberOutputSteps(); s++) { BoutReal target = simtime + getOutputTimestep(); diff --git a/src/solver/impls/rkgeneric/rkgeneric.cxx b/src/solver/impls/rkgeneric/rkgeneric.cxx index 1c332d26de..edf8ed50e3 100644 --- a/src/solver/impls/rkgeneric/rkgeneric.cxx +++ b/src/solver/impls/rkgeneric/rkgeneric.cxx @@ -4,12 +4,8 @@ #include #include -#include -#include - -#include - #include +#include RKGenericSolver::RKGenericSolver(Options* opts) : Solver(opts), atol((*options)["atol"].doc("Absolute tolerance").withDefault(1.e-5)), @@ -40,8 +36,6 @@ void RKGenericSolver::setMaxTimestep(BoutReal dt) { int RKGenericSolver::init() { - TRACE("Initialising RKGeneric solver"); - Solver::init(); output << "\n\tRunge-Kutta generic solver with scheme type " << scheme->getType() << "\n"; @@ -86,8 +80,6 @@ void RKGenericSolver::resetInternalFields() { } int RKGenericSolver::run() { - TRACE("RKGenericSolver::run()"); - for (int s = 0; s < getNumberOutputSteps(); s++) { BoutReal target = simtime + getOutputTimestep(); diff --git a/src/solver/impls/slepc/slepc.cxx b/src/solver/impls/slepc/slepc.cxx index 13657a4553..2c52cb3b38 100644 --- a/src/solver/impls/slepc/slepc.cxx +++ b/src/solver/impls/slepc/slepc.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -241,8 +240,6 @@ SlepcSolver::~SlepcSolver() { int SlepcSolver::init() { - TRACE("Initialising SLEPc solver"); - // Report initialisation output.write("Initialising SLEPc solver\n"); if (selfSolve) { diff --git a/src/solver/impls/snes/snes.cxx b/src/solver/impls/snes/snes.cxx index 311bc371fe..e1ef477105 100644 --- a/src/solver/impls/snes/snes.cxx +++ b/src/solver/impls/snes/snes.cxx @@ -1,4 +1,4 @@ -#include "bout/build_config.hxx" +#include "bout/build_defines.hxx" #if BOUT_HAS_PETSC @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -18,8 +18,6 @@ #include #include -#include - #include "petscerror.h" #include "petscmat.h" #include "petscpc.h" @@ -607,9 +605,6 @@ SNESSolver::SNESSolver(Options* opts) .withDefault(false)) {} int SNESSolver::init() { - - TRACE("Initialising SNES solver"); - Solver::init(); output << "\n\tSNES steady state solver\n"; @@ -829,8 +824,6 @@ int SNESSolver::init() { } int SNESSolver::run() { - TRACE("SNESSolver::run()"); - // Set initial guess at the solution from variables { BoutReal* xdata = nullptr; diff --git a/src/solver/impls/split-rk/split-rk.cxx b/src/solver/impls/split-rk/split-rk.cxx index cd6bd1718c..fd9a99a6c5 100644 --- a/src/solver/impls/split-rk/split-rk.cxx +++ b/src/solver/impls/split-rk/split-rk.cxx @@ -35,7 +35,6 @@ SplitRK::SplitRK(Options* opts) } int SplitRK::init() { - AUTO_TRACE(); Solver::init(); output.write(_("\n\tSplit Runge-Kutta-Legendre and SSP-RK3 solver\n")); @@ -79,7 +78,6 @@ int SplitRK::init() { } int SplitRK::run() { - AUTO_TRACE(); for (int step = 0; step < getNumberOutputSteps(); step++) { // Take an output step diff --git a/src/solver/solver.cxx b/src/solver/solver.cxx index a3f6a874f6..ac3d632419 100644 --- a/src/solver/solver.cxx +++ b/src/solver/solver.cxx @@ -636,7 +636,7 @@ std::string Solver::createRunID() const { } std::string Solver::getRunID() const { - AUTO_TRACE(); + if (run_id == default_run_id) { throw BoutException("run_id not set!"); } @@ -644,7 +644,7 @@ std::string Solver::getRunID() const { } std::string Solver::getRunRestartFrom() const { - AUTO_TRACE(); + // Check against run_id, because this might not be a restarted run if (run_id == default_run_id) { throw BoutException("run_restart_from not set!"); @@ -664,9 +664,6 @@ void Solver::writeToModelOutputFile(const Options& options) { **************************************************************************/ int Solver::init() { - - TRACE("Solver::init()"); - if (initialised) { throw BoutException(_("ERROR: Solver is already initialised\n")); } diff --git a/src/sys/bout_types.cxx b/src/sys/bout_types.cxx index 35d37f11be..b27fab7ae7 100644 --- a/src/sys/bout_types.cxx +++ b/src/sys/bout_types.cxx @@ -1,12 +1,12 @@ #include #include -#include + #include namespace { template const std::string& safeAt(const std::map& mymap, T t) { - AUTO_TRACE(); + auto found = mymap.find(t); if (found == mymap.end()) { throw BoutException("Did not find enum {:d}", static_cast(t)); @@ -16,7 +16,7 @@ const std::string& safeAt(const std::map& mymap, T t) { template const T& safeAt(const std::map& mymap, const std::string& s) { - AUTO_TRACE(); + auto found = mymap.find(s); if (found == mymap.end()) { throw BoutException("Did not find enum {:s}", s); @@ -26,7 +26,7 @@ const T& safeAt(const std::map& mymap, const std::string& s) { } // namespace std::string toString(CELL_LOC location) { - AUTO_TRACE(); + const static std::map CELL_LOCtoString = { ENUMSTR(CELL_DEFAULT), ENUMSTR(CELL_CENTRE), ENUMSTR(CELL_XLOW), ENUMSTR(CELL_YLOW), ENUMSTR(CELL_ZLOW), ENUMSTR(CELL_VSHIFT)}; @@ -35,7 +35,7 @@ std::string toString(CELL_LOC location) { } CELL_LOC CELL_LOCFromString(const std::string& location_string) { - AUTO_TRACE(); + const static std::map stringtoCELL_LOC = { STRENUM(CELL_DEFAULT), STRENUM(CELL_CENTRE), STRENUM(CELL_XLOW), STRENUM(CELL_YLOW), STRENUM(CELL_ZLOW), STRENUM(CELL_VSHIFT)}; @@ -44,7 +44,7 @@ CELL_LOC CELL_LOCFromString(const std::string& location_string) { } std::string toString(DIFF_METHOD location) { - AUTO_TRACE(); + const static std::map DIFF_METHODtoString = { {DIFF_DEFAULT, "DEFAULT"}, {DIFF_U1, "U1"}, {DIFF_U2, "U2"}, {DIFF_U3, "U3"}, {DIFF_C2, "C2"}, {DIFF_C4, "C4"}, {DIFF_S2, "S2"}, {DIFF_W2, "W2"}, @@ -54,7 +54,7 @@ std::string toString(DIFF_METHOD location) { } std::string toString(REGION region) { - AUTO_TRACE(); + const static std::map REGIONtoString = { ENUMSTR(RGN_ALL), ENUMSTR(RGN_NOBNDRY), ENUMSTR(RGN_NOX), ENUMSTR(RGN_NOY), ENUMSTR(RGN_NOZ)}; @@ -62,7 +62,7 @@ std::string toString(REGION region) { } std::string toString(DIRECTION direction) { - AUTO_TRACE(); + const static std::map DIRECTIONtoString = { {DIRECTION::X, "X"}, {DIRECTION::Y, "Y"}, @@ -116,7 +116,7 @@ bool areDirectionsCompatible(const DirectionTypes& d1, const DirectionTypes& d2) } std::string toString(STAGGER stagger) { - AUTO_TRACE(); + const static std::map STAGGERtoString = { {STAGGER::None, "No staggering"}, {STAGGER::C2L, "Centre to Low"}, @@ -126,7 +126,7 @@ std::string toString(STAGGER stagger) { } std::string toString(DERIV deriv) { - AUTO_TRACE(); + const static std::map DERIVtoString = { {DERIV::Standard, "Standard"}, {DERIV::StandardSecond, "Standard -- second order"}, @@ -138,7 +138,7 @@ std::string toString(DERIV deriv) { } std::string toString(YDirectionType d) { - AUTO_TRACE(); + const static std::map YDirectionTypeToString = { {YDirectionType::Standard, "Standard"}, {YDirectionType::Aligned, "Aligned"}}; @@ -146,7 +146,7 @@ std::string toString(YDirectionType d) { } YDirectionType YDirectionTypeFromString(const std::string& y_direction_string) { - AUTO_TRACE(); + const static std::map stringToYDirectionType = { {"Standard", YDirectionType::Standard}, {"Aligned", YDirectionType::Aligned}}; @@ -154,7 +154,7 @@ YDirectionType YDirectionTypeFromString(const std::string& y_direction_string) { } std::string toString(ZDirectionType d) { - AUTO_TRACE(); + const static std::map ZDirectionTypeToString = { {ZDirectionType::Standard, "Standard"}, {ZDirectionType::Average, "Average"}}; @@ -162,7 +162,7 @@ std::string toString(ZDirectionType d) { } ZDirectionType ZDirectionTypeFromString(const std::string& z_direction_string) { - AUTO_TRACE(); + const static std::map stringToZDirectionType = { {"Standard", ZDirectionType::Standard}, {"Average", ZDirectionType::Average}}; diff --git a/src/sys/boutexception.cxx b/src/sys/boutexception.cxx index e81e395bf8..b5ea01d231 100644 --- a/src/sys/boutexception.cxx +++ b/src/sys/boutexception.cxx @@ -1,5 +1,3 @@ -#include "bout/build_defines.hxx" - #include #include #include @@ -7,22 +5,17 @@ #include -#if BOUT_USE_BACKTRACE -#include -#include -#include -#endif +#include // IWYU pragma: keep +#include +#include -#include #include #include #include #include -namespace { -const std::string header{"====== Exception thrown ======\n"}; -} +bool BoutException::show_backtrace = true; void BoutParallelThrowRhsFail(int status, const char* message) { int allstatus = 0; @@ -33,16 +26,15 @@ void BoutParallelThrowRhsFail(int status, const char* message) { } } -BoutException::BoutException(std::string msg) - : message(std::move(msg)) -#if BOUT_USE_BACKTRACE - , - trace_size(backtrace(trace.data(), TRACE_MAX)), - messages(backtrace_symbols(trace.data(), trace_size)) -#endif -{ - if (std::getenv("BOUT_SHOW_BACKTRACE") != nullptr) { - message = fmt::format("{}\n{}", getBacktrace(), message); +BoutException::BoutException(std::string msg) : message(std::move(msg)) { + const char* show_backtrace_env_var = std::getenv("BOUT_SHOW_BACKTRACE"); + const auto should_show_backtrace = + show_backtrace + and ((show_backtrace_env_var == nullptr) + or (show_backtrace_env_var != nullptr + and std::string{show_backtrace_env_var} != "0")); + if (should_show_backtrace) { + message = getBacktrace(); } } @@ -51,62 +43,36 @@ BoutException::~BoutException() { // up the msg_stack. We also won't know how many messages to pop, so // just clear everything msg_stack.clear(); -#if BOUT_USE_BACKTRACE - // Call required for memory allocated by `backtrace_symbols` - free(messages); // NOLINT -#endif } std::string BoutException::getBacktrace() const { - std::string backtrace_message; -#if BOUT_USE_BACKTRACE - backtrace_message = "====== Exception path ======\n"; - // skip first stack frame (points here) - for (int i = trace_size - 1; i > 1; --i) { - backtrace_message = fmt::format(FMT_STRING("{}[bt] #{:d} {:s}\n"), backtrace_message, - i - 1, messages[i]); - // find first occurence of '(' or ' ' in message[i] and assume - // everything before that is the file name. (Don't go beyond 0 though - // (string terminator) - int p = 0; // snprintf %.*s expects int - while (messages[i][p] != '(' && messages[i][p] != ' ' && messages[i][p] != 0) { - ++p; - } + using namespace cpptrace; - // If we are compiled as PIE, need to get base pointer of .so and substract - Dl_info info; - const void* ptr = trace[i]; - if (dladdr(ptr, &info) != 0) { - // Additionally, check whether this is the default offset for an executable - if (info.dli_fbase != reinterpret_cast(0x400000)) { - ptr = reinterpret_cast(reinterpret_cast(ptr) - - reinterpret_cast(info.dli_fbase)); - } - } + const auto colours = isatty(stdout_fileno) || isatty(stderr_fileno) + ? formatter::color_mode::always + : formatter::color_mode::none; - // Pipe stderr to /dev/null to avoid cluttering output - // when addr2line fails or is not installed - const auto syscom = fmt::format( - FMT_STRING("addr2line {:p} -Cfpie {:.{}s} 2> /dev/null"), ptr, messages[i], p); - // last parameter is the file name of the symbol - FILE* file = popen(syscom.c_str(), "r"); - if (file != nullptr) { - std::array out{}; - const char* retstr = nullptr; - std::string buf; - while ((retstr = fgets(out.data(), out.size() - 1, file)) != nullptr) { - buf += retstr; - } - int const status = pclose(file); - if (status == 0) { - backtrace_message = fmt::format("{}{}", backtrace_message, buf); - } - } - } -#else - backtrace_message = "Stacktrace not enabled.\n"; -#endif + auto formatter = cpptrace::formatter{} + .addresses(formatter::address_mode::none) + .break_before_filename(true) + .colors(colours) + .snippets(true) + .symbols(formatter::symbol_mode::pretty) + .filter([](const stacktrace_frame& frame) { + return ( + // Don't include our exception machinery + (frame.symbol.find("BoutException::") == std::string::npos) + // Don't include pre-main functions + and (frame.symbol.find("__libc_start") == std::string::npos) + and (frame.symbol != "_start")); + }); - return fmt::format("{}{}\n{}{}\n", backtrace_message, msg_stack.getDump(), header, - message); + std::string backtrace_message = + fmt::format("{}\n\n====== Exception thrown ======\n{}", + formatter.format(generate_trace()), message); + + if (msg_stack.size() > 0) { + return fmt::format("{}\n\n{}", backtrace_message, msg_stack.getDump()); + } + return backtrace_message; } diff --git a/src/sys/derivs.cxx b/src/sys/derivs.cxx index ee9bcbcc2c..aab75b8f19 100644 --- a/src/sys/derivs.cxx +++ b/src/sys/derivs.cxx @@ -38,19 +38,15 @@ * **************************************************************************/ +#include #include #include #include #include #include -#include -#include -#include - -#include - #include #include +#include /******************************************************************************* * First central derivatives diff --git a/src/sys/msg_stack.cxx b/src/sys/msg_stack.cxx index 502836324c..3dbd7c2797 100644 --- a/src/sys/msg_stack.cxx +++ b/src/sys/msg_stack.cxx @@ -27,7 +27,7 @@ #include "bout/openmpwrap.hxx" #include #include -#include + #include #if BOUT_USE_OPENMP @@ -91,7 +91,7 @@ void MsgStack::dump() { } std::string MsgStack::getDump() { - std::string res = "====== Back trace ======\n"; + std::string res = "=== Additional information ===\n"; for (int i = position - 1; i >= 0; i--) { if (stack[i] != "") { res += " -> "; diff --git a/src/sys/options.cxx b/src/sys/options.cxx index 077b2a6d85..bb4c920b90 100644 --- a/src/sys/options.cxx +++ b/src/sys/options.cxx @@ -106,8 +106,6 @@ Options::Options(InitializerList values, Options* parent_instance, } Options& Options::operator[](const std::string& name) { - TRACE("Options::operator[]"); - if (isValue()) { throw BoutException(_("Trying to index Option '{0}' with '{1}', but '{0}' is a " "value, not a section.\n" @@ -145,8 +143,6 @@ Options& Options::operator[](const std::string& name) { } const Options& Options::operator[](const std::string& name) const { - TRACE("Options::operator[] const"); - if (isValue()) { throw BoutException(_("Trying to index Option '{0}' with '{1}', but '{0}' is a " "value, not a section.\n" diff --git a/src/sys/options/options_ini.cxx b/src/sys/options/options_ini.cxx index d1889f993b..939e100f1b 100644 --- a/src/sys/options/options_ini.cxx +++ b/src/sys/options/options_ini.cxx @@ -50,12 +50,10 @@ **************************************************************************/ #include "options_ini.hxx" + #include -#include #include -#include - using namespace std; /************************************************************************** @@ -151,8 +149,6 @@ void OptionINI::read(Options* options, const string& filename) { } void OptionINI::write(Options* options, const std::string& filename) { - TRACE("OptionsINI::write"); - std::ofstream fout; fout.open(filename, ios::out | ios::trunc); diff --git a/src/sys/optionsreader.cxx b/src/sys/optionsreader.cxx index 8624f646df..e16df31c97 100644 --- a/src/sys/optionsreader.cxx +++ b/src/sys/optionsreader.cxx @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -23,7 +22,6 @@ OptionsReader* OptionsReader::getInstance() { } void OptionsReader::read(Options* options, const std::string& filename) { - TRACE("OptionsReader::read"); if (filename.empty()) { throw BoutException("OptionsReader::read passed empty filename\n"); } @@ -34,7 +32,6 @@ void OptionsReader::read(Options* options, const std::string& filename) { } void OptionsReader::write(Options* options, const std::string& filename) { - TRACE("OptionsReader::write"); if (filename.empty()) { throw BoutException("OptionsReader::write passed empty filename\n"); } diff --git a/src/sys/timer.cxx b/src/sys/timer.cxx index 314d599905..410cffad94 100644 --- a/src/sys/timer.cxx +++ b/src/sys/timer.cxx @@ -1,5 +1,7 @@ #include "bout/sys/timer.hxx" +#include + #include #include diff --git a/tests/MMS/GBS/runtest-slab2d b/tests/MMS/GBS/runtest-slab2d index 97c7e11459..221c34e815 100755 --- a/tests/MMS/GBS/runtest-slab2d +++ b/tests/MMS/GBS/runtest-slab2d @@ -11,7 +11,6 @@ from boutdata.collect import collect from numpy import sqrt, max, abs, mean, array, log, concatenate - build_and_log("MMS test") diff --git a/tests/MMS/GBS/runtest-slab3d b/tests/MMS/GBS/runtest-slab3d index f193583e47..45acd53af7 100755 --- a/tests/MMS/GBS/runtest-slab3d +++ b/tests/MMS/GBS/runtest-slab3d @@ -14,7 +14,6 @@ from numpy import sqrt, max, abs, mean, array, log, concatenate import pickle - build_and_log("MMS test") # List of NX values to use diff --git a/tests/MMS/advection/runtest b/tests/MMS/advection/runtest index 1290a4c247..9a0a691287 100755 --- a/tests/MMS/advection/runtest +++ b/tests/MMS/advection/runtest @@ -20,7 +20,6 @@ import pickle import time - if __name__ == "__main__": build_and_log("MMS advection") diff --git a/tests/MMS/diffusion/runtest b/tests/MMS/diffusion/runtest index a25b3519a6..ef6b335f70 100755 --- a/tests/MMS/diffusion/runtest +++ b/tests/MMS/diffusion/runtest @@ -15,7 +15,6 @@ from boutdata.collect import collect from numpy import sqrt, max, abs, mean, array, log - build_and_log("MMS diffusion test") # List of NX values to use diff --git a/tests/MMS/diffusion2/Z/plot_error.py b/tests/MMS/diffusion2/Z/plot_error.py index 5c4e1164c1..4b4b666758 100644 --- a/tests/MMS/diffusion2/Z/plot_error.py +++ b/tests/MMS/diffusion2/Z/plot_error.py @@ -4,6 +4,7 @@ @author: yolen """ + import boutdata import matplotlib.pyplot as plt diff --git a/tests/MMS/diffusion2/runtest b/tests/MMS/diffusion2/runtest index 546be3b2c1..d1b8072fc8 100755 --- a/tests/MMS/diffusion2/runtest +++ b/tests/MMS/diffusion2/runtest @@ -20,7 +20,6 @@ from numpy import sqrt, max, abs, mean, array, log from os.path import join - build_and_log("MMS diffusion test") # List of input directories diff --git a/tests/MMS/fieldalign/runtest.broken b/tests/MMS/fieldalign/runtest.broken index e09fbeccd5..bfb2023c1d 100755 --- a/tests/MMS/fieldalign/runtest.broken +++ b/tests/MMS/fieldalign/runtest.broken @@ -18,7 +18,6 @@ from os.path import join import time - build_and_log("MMS test") # nxlist = [256, 128, 64, 32, 16, 8] # do in reverse order to save disk space diff --git a/tests/MMS/hw/runtest b/tests/MMS/hw/runtest index b6abadc3b9..62740fcbbd 100755 --- a/tests/MMS/hw/runtest +++ b/tests/MMS/hw/runtest @@ -15,7 +15,6 @@ from boutdata.collect import collect from numpy import sqrt, max, abs, mean, array, log, concatenate - build_and_log("MMS test") # List of NX values to use diff --git a/tests/MMS/laplace/runtest b/tests/MMS/laplace/runtest index 98eb62da87..80c8bf08af 100755 --- a/tests/MMS/laplace/runtest +++ b/tests/MMS/laplace/runtest @@ -14,7 +14,6 @@ from boutdata.collect import collect from numpy import sqrt, max, abs, mean, array, log, concatenate - build_and_log("MMS test") # List of NX values to use diff --git a/tests/MMS/spatial/diffusion/runtest b/tests/MMS/spatial/diffusion/runtest index 000cf8f09b..8d4e759d59 100755 --- a/tests/MMS/spatial/diffusion/runtest +++ b/tests/MMS/spatial/diffusion/runtest @@ -22,7 +22,6 @@ from os.path import join import matplotlib.pyplot as plt - build_and_log("MMS diffusion test") # List of input directories diff --git a/tests/MMS/wave-1d-y/runtest b/tests/MMS/wave-1d-y/runtest index 9a4de5a3bb..332d6864b0 100755 --- a/tests/MMS/wave-1d-y/runtest +++ b/tests/MMS/wave-1d-y/runtest @@ -20,7 +20,6 @@ from sys import stdout from numpy import sqrt, max, abs, mean, array, log, concatenate, pi - build_and_log("Making MMS wave test") # List of NX values to use diff --git a/tests/MMS/wave-1d/runtest b/tests/MMS/wave-1d/runtest index f13fb7bd11..1adb7c7d6d 100755 --- a/tests/MMS/wave-1d/runtest +++ b/tests/MMS/wave-1d/runtest @@ -15,7 +15,6 @@ from boutdata.collect import collect from numpy import sqrt, max, abs, mean, array, log, concatenate - build_and_log("Making MMS wave test") # List of NX values to use diff --git a/tests/integrated/test-backtrace/CMakeLists.txt b/tests/integrated/test-backtrace/CMakeLists.txt index b20262f1b1..579f4863ac 100644 --- a/tests/integrated/test-backtrace/CMakeLists.txt +++ b/tests/integrated/test-backtrace/CMakeLists.txt @@ -1,6 +1,4 @@ bout_add_integrated_test(test-backtrace SOURCES boutexcept.cxx - REQUIRES BOUT_USE_BACKTRACE - CONFLICTS CMAKE_SYSTEM_NAME MATCHES "FreeBSD" USE_RUNTEST - ) +) diff --git a/tests/integrated/test-backtrace/boutexcept.cxx b/tests/integrated/test-backtrace/boutexcept.cxx index bd965a9c2b..3019c690a9 100644 --- a/tests/integrated/test-backtrace/boutexcept.cxx +++ b/tests/integrated/test-backtrace/boutexcept.cxx @@ -1,18 +1,12 @@ #include "bout/boutexception.hxx" -#include "bout/msg_stack.hxx" -void troublemaker() { - AUTO_TRACE(); - throw BoutException("test"); -} -void f() { - AUTO_TRACE(); - troublemaker(); -} -void e() { - AUTO_TRACE(); - f(); -} +// Can't use anonymous namespace, or the compiler will inline everything, +// defeating the point of this test. +// NOLINTBEGIN(misc-use-internal-linkage) +void troublemaker() { throw BoutException("test"); } +void f() { troublemaker(); } +void e() { f(); } +// NOLINTEND(misc-use-internal-linkage) int main() { e(); diff --git a/tests/integrated/test-backtrace/runtest b/tests/integrated/test-backtrace/runtest index b41506175e..c4020e6d99 100755 --- a/tests/integrated/test-backtrace/runtest +++ b/tests/integrated/test-backtrace/runtest @@ -17,17 +17,21 @@ except KeyError: success = True errors = [] -_, output = shell("./boutexcept", pipe=True) +_, output = shell("BOUT_SHOW_BACKTRACE=0 ./boutexcept", pipe=True) if "troublemaker" in output: success = False - print("Fail: detected offending function name in output when not expected") + print( + f"Fail: detected offending function name in output when not expected:\n{output}" + ) -_, output = shell("BOUT_SHOW_BACKTRACE=yes ./boutexcept", pipe=True) +_, output = shell("./boutexcept", pipe=True) if "troublemaker" not in output: success = False - print("Fail: did not detect offending function name in output when expected") + print( + f"Fail: did not detect offending function name in output when expected:\n{output}" + ) if success: print("=> All BoutException backtrace tests passed") diff --git a/tests/integrated/test-command-args/runtest b/tests/integrated/test-command-args/runtest index 39939bb105..a8dc3f020c 100755 --- a/tests/integrated/test-command-args/runtest +++ b/tests/integrated/test-command-args/runtest @@ -7,7 +7,6 @@ import shutil import unittest import platform - OUTPUT_FILE = "stdout.log" if platform.system() == "FreeBSD" else "stderr.log" diff --git a/tests/integrated/test-cyclic/runtest b/tests/integrated/test-cyclic/runtest index 5e31da6239..c68f9b033e 100755 --- a/tests/integrated/test-cyclic/runtest +++ b/tests/integrated/test-cyclic/runtest @@ -17,7 +17,6 @@ from boututils.run_wrapper import build_and_log, shell, launch from boutdata.collect import collect from sys import stdout, exit - build_and_log("Cyclic Reduction test") flags = ["", "nsys=2", "nsys=5 periodic", "nsys=7 n=10"] diff --git a/tests/integrated/test-griddata/runtest b/tests/integrated/test-griddata/runtest index 1c57bf5be7..6aef955023 100755 --- a/tests/integrated/test-griddata/runtest +++ b/tests/integrated/test-griddata/runtest @@ -13,7 +13,6 @@ from boutdata.collect import collect import numpy as np from sys import stdout, exit - build_and_log("griddata test") for nproc in [1]: diff --git a/tests/integrated/test-gyro/runtest b/tests/integrated/test-gyro/runtest index 52ab0de4ab..7a0209fa57 100755 --- a/tests/integrated/test-gyro/runtest +++ b/tests/integrated/test-gyro/runtest @@ -25,7 +25,6 @@ from boutdata.collect import collect import numpy as np from sys import stdout, exit - build_and_log("Gyro-average inversion test") # Read benchmark values diff --git a/tests/integrated/test-invertable-operator/invertable_operator.cxx b/tests/integrated/test-invertable-operator/invertable_operator.cxx index 3c99c3dbbd..9f00fad304 100644 --- a/tests/integrated/test-invertable-operator/invertable_operator.cxx +++ b/tests/integrated/test-invertable-operator/invertable_operator.cxx @@ -1,5 +1,4 @@ #include -#include #include #include @@ -16,7 +15,7 @@ class InvertableOperatorTest : public PhysicsModel { // Drop C term for now Field3D operator()(const Field3D& input) { - TRACE("myLaplacian::operator()"); + Field3D result = A * input + D * Delp2(input); // Ensure boundary points are set appropriately as given by the input field. diff --git a/tests/integrated/test-invpar/runtest b/tests/integrated/test-invpar/runtest index de7f028528..53f6015fe9 100755 --- a/tests/integrated/test-invpar/runtest +++ b/tests/integrated/test-invpar/runtest @@ -12,7 +12,6 @@ from boututils.run_wrapper import build_and_log, shell, launch from boutdata.collect import collect from sys import stdout, exit - build_and_log("parallel inversion test") flags_src = [ diff --git a/tests/integrated/test-laplace/runtest b/tests/integrated/test-laplace/runtest index e54e46d0d8..d1e9c3d1c9 100755 --- a/tests/integrated/test-laplace/runtest +++ b/tests/integrated/test-laplace/runtest @@ -41,7 +41,6 @@ from boutdata.collect import collect import numpy as np from sys import stdout, exit - build_and_log("Laplacian inversion test") # Read benchmark values diff --git a/tests/integrated/test-multigrid_laplace/runtest b/tests/integrated/test-multigrid_laplace/runtest index 4a7455f80b..f325185c46 100755 --- a/tests/integrated/test-multigrid_laplace/runtest +++ b/tests/integrated/test-multigrid_laplace/runtest @@ -22,7 +22,6 @@ from boututils.run_wrapper import build_and_log, shell, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("multigrid Laplacian inversion test") print("Running multigrid Laplacian inversion test") diff --git a/tests/integrated/test-multigrid_laplace/runtest_multiple_grids b/tests/integrated/test-multigrid_laplace/runtest_multiple_grids index 6817120b13..739d15f7d4 100755 --- a/tests/integrated/test-multigrid_laplace/runtest_multiple_grids +++ b/tests/integrated/test-multigrid_laplace/runtest_multiple_grids @@ -18,7 +18,6 @@ from boututils.run_wrapper import shell, build_and_log, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("Multigrid Laplacian inversion test") print("Running multigrid Laplacian inversion test") diff --git a/tests/integrated/test-multigrid_laplace/runtest_unsheared b/tests/integrated/test-multigrid_laplace/runtest_unsheared index cda68f2167..d0dca3a808 100755 --- a/tests/integrated/test-multigrid_laplace/runtest_unsheared +++ b/tests/integrated/test-multigrid_laplace/runtest_unsheared @@ -18,7 +18,6 @@ from boututils.run_wrapper import shell, build_and_log, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("Making multigrid Laplacian inversion test") print("Running multigrid Laplacian inversion test") diff --git a/tests/integrated/test-naulin-laplace/runtest b/tests/integrated/test-naulin-laplace/runtest index f972eab6cc..145257c23b 100755 --- a/tests/integrated/test-naulin-laplace/runtest +++ b/tests/integrated/test-naulin-laplace/runtest @@ -22,7 +22,6 @@ from boututils.run_wrapper import build_and_log, shell, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("LaplaceNaulin inversion test") print("Running LaplaceNaulin inversion test") diff --git a/tests/integrated/test-naulin-laplace/runtest_multiple_grids b/tests/integrated/test-naulin-laplace/runtest_multiple_grids index c0281c3a4e..f56a80677e 100755 --- a/tests/integrated/test-naulin-laplace/runtest_multiple_grids +++ b/tests/integrated/test-naulin-laplace/runtest_multiple_grids @@ -18,7 +18,6 @@ from boututils.run_wrapper import shell, build_and_log, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("Making LaplaceNaulin inversion test") print("Running LaplaceNaulin inversion test") diff --git a/tests/integrated/test-naulin-laplace/runtest_unsheared b/tests/integrated/test-naulin-laplace/runtest_unsheared index 8f47f33026..a845a9d92f 100755 --- a/tests/integrated/test-naulin-laplace/runtest_unsheared +++ b/tests/integrated/test-naulin-laplace/runtest_unsheared @@ -18,7 +18,6 @@ from boututils.run_wrapper import shell, build_and_log, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("LaplaceNaulin inversion test") print("Running LaplaceNaulin inversion test") diff --git a/tests/integrated/test-petsc_laplace/runtest b/tests/integrated/test-petsc_laplace/runtest index ac248c4ce7..83e1006338 100755 --- a/tests/integrated/test-petsc_laplace/runtest +++ b/tests/integrated/test-petsc_laplace/runtest @@ -30,7 +30,6 @@ from boutdata.collect import collect # import numpy as np from sys import stdout, exit - build_and_log("PETSc Laplacian inversion test") print("Running PETSc Laplacian inversion test") diff --git a/tests/integrated/test-petsc_laplace_MAST-grid/runtest b/tests/integrated/test-petsc_laplace_MAST-grid/runtest index 5a4cbf875a..3be39949c3 100755 --- a/tests/integrated/test-petsc_laplace_MAST-grid/runtest +++ b/tests/integrated/test-petsc_laplace_MAST-grid/runtest @@ -28,7 +28,6 @@ from boututils.run_wrapper import build_and_log, shell, launch_safe from boutdata.collect import collect from sys import stdout, exit - build_and_log( "PETSc Laplacian inversion test with non-identity metric (taken from grid for MAST SOL)" ) diff --git a/tests/integrated/test-region-iterator/runtest b/tests/integrated/test-region-iterator/runtest index e5825285de..2277ef15e9 100755 --- a/tests/integrated/test-region-iterator/runtest +++ b/tests/integrated/test-region-iterator/runtest @@ -17,7 +17,6 @@ from boututils.run_wrapper import build_and_log, launch_safe from boutdata.collect import collect from sys import exit - build_and_log("Region Iterator test") flags = [""] diff --git a/tests/integrated/test-restarting/runtest b/tests/integrated/test-restarting/runtest index 262aa818b6..daf19ebac6 100755 --- a/tests/integrated/test-restarting/runtest +++ b/tests/integrated/test-restarting/runtest @@ -5,7 +5,6 @@ from boutdata.collect import collect import numpy as np from sys import stdout, exit - build_and_log("restart test") # Run once for 10 timesteps diff --git a/tests/integrated/test-smooth/runtest b/tests/integrated/test-smooth/runtest index bd7296341a..91ae793164 100755 --- a/tests/integrated/test-smooth/runtest +++ b/tests/integrated/test-smooth/runtest @@ -16,7 +16,6 @@ from boutdata.collect import collect import numpy as np from sys import stdout, exit - build_and_log("smoothing operator test") # Read benchmark values diff --git a/tests/integrated/test-squash/runtest b/tests/integrated/test-squash/runtest index 2f35e00589..8bf358ee8e 100755 --- a/tests/integrated/test-squash/runtest +++ b/tests/integrated/test-squash/runtest @@ -9,7 +9,6 @@ import argparse import re import os.path - # requires: all_tests # requires: netcdf # cores: 4 diff --git a/tests/integrated/test-vec/testVec.cxx b/tests/integrated/test-vec/testVec.cxx index bd0e5f2b80..905ffac01a 100644 --- a/tests/integrated/test-vec/testVec.cxx +++ b/tests/integrated/test-vec/testVec.cxx @@ -14,13 +14,11 @@ class VecTest : public PhysicsModel { }; int VecTest::init(bool UNUSED(restarting)) { - TRACE("Halt in VecTest::init"); SOLVE_FOR(n); return 0; } int VecTest::rhs(BoutReal UNUSED(t)) { - TRACE("Halt in VecTest::rhs"); mesh->communicate(n); gradPerpN = Grad_perp(n); mesh->communicate(gradPerpN); diff --git a/tests/integrated/test-yupdown/runtest b/tests/integrated/test-yupdown/runtest index 34fcd36496..13d7365b53 100755 --- a/tests/integrated/test-yupdown/runtest +++ b/tests/integrated/test-yupdown/runtest @@ -6,7 +6,6 @@ from sys import exit from numpy import max, abs - build_and_log("parallel slices test") failed = False diff --git a/tests/unit/bout_test_main.cxx b/tests/unit/bout_test_main.cxx index 999b5b0dc3..09aeeed0ea 100644 --- a/tests/unit/bout_test_main.cxx +++ b/tests/unit/bout_test_main.cxx @@ -1,6 +1,7 @@ #include #include "bout/array.hxx" +#include "bout/boutexception.hxx" #include "bout/fft.hxx" #include "bout/globalindexer.hxx" #include "bout/output.hxx" @@ -22,6 +23,10 @@ GTEST_API_ int main(int argc, char** argv) { printf("Running main() from bout_test_main.cxx\n"); testing::InitGoogleTest(&argc, argv); + // We throw and catch a bunch of exceptions as part of running the tests, and + // the backtrace generation can _significantly_ slow them down + BoutException::disableBacktrace(); + // Explicitly setup and teardown PETSc to avoid reentry problems // with certain MPI implementations (see #1916 for details) output.disable(); diff --git a/tests/unit/field/test_vector2d.cxx b/tests/unit/field/test_vector2d.cxx index df438c3dbf..de662c7df8 100644 --- a/tests/unit/field/test_vector2d.cxx +++ b/tests/unit/field/test_vector2d.cxx @@ -1,8 +1,8 @@ -#include "gtest/gtest.h" +#include -#include "bout/boutexception.hxx" #if not(BOUT_USE_METRIC_3D) #include "test_extras.hxx" +#include "bout/boutexception.hxx" #include "bout/mesh.hxx" #include "bout/mpi_wrapper.hxx" #include "bout/output.hxx" @@ -11,6 +11,8 @@ #include "fake_mesh.hxx" +#include "gtest/gtest.h" + // The unit tests use the global mesh using namespace bout::globals; diff --git a/tests/unit/include/bout/test_single_index_ops.cxx b/tests/unit/include/bout/test_single_index_ops.cxx index 4359d1d282..a809ae3683 100644 --- a/tests/unit/include/bout/test_single_index_ops.cxx +++ b/tests/unit/include/bout/test_single_index_ops.cxx @@ -2,6 +2,7 @@ #include "test_extras.hxx" +#include "bout/build_defines.hxx" #include "bout/derivs.hxx" #include "bout/difops.hxx" #include "bout/single_index_ops.hxx" diff --git a/tests/unit/mesh/data/test_gridfromoptions.cxx b/tests/unit/mesh/data/test_gridfromoptions.cxx index 8d3dbfebdf..b821d2e225 100644 --- a/tests/unit/mesh/data/test_gridfromoptions.cxx +++ b/tests/unit/mesh/data/test_gridfromoptions.cxx @@ -1,13 +1,13 @@ #include "gtest/gtest.h" #include "test_extras.hxx" +#include "bout/build_defines.hxx" #include "bout/constants.hxx" #include "bout/griddata.hxx" #include "bout/mesh.hxx" #include "bout/options.hxx" #include "bout/output.hxx" -#include #include #include diff --git a/tests/unit/solver/test_solver.cxx b/tests/unit/solver/test_solver.cxx index 2e29fd90bc..e9a612103c 100644 --- a/tests/unit/solver/test_solver.cxx +++ b/tests/unit/solver/test_solver.cxx @@ -4,6 +4,7 @@ #include "test_extras.hxx" #include "test_fakesolver.hxx" #include "bout/boutexception.hxx" +#include "bout/build_defines.hxx" #include "bout/field2d.hxx" #include "bout/field3d.hxx" #include "bout/physicsmodel.hxx" diff --git a/tests/unit/sys/test_boutexception.cxx b/tests/unit/sys/test_boutexception.cxx index 322c7d6e42..7cde2f57a1 100644 --- a/tests/unit/sys/test_boutexception.cxx +++ b/tests/unit/sys/test_boutexception.cxx @@ -1,5 +1,3 @@ -#include "bout/build_defines.hxx" - #include "test_extras.hxx" #include "bout/boutexception.hxx" #include "gtest/gtest.h" @@ -7,52 +5,51 @@ #include #include -#include #include -TEST(BoutExceptionTest, ThrowCorrect) { +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +struct BoutExceptionTest : public ::testing::Test { + BoutExceptionTest() { BoutException::enableBacktrace(); } + ~BoutExceptionTest() override { BoutException::disableBacktrace(); } +}; + +TEST_F(BoutExceptionTest, ThrowCorrect) { EXPECT_THROW(throw BoutException("test"), BoutException); } -TEST(BoutExceptionTest, What) { +TEST_F(BoutExceptionTest, What) { std::string test_message{"Test message"}; try { throw BoutException(test_message); } catch (const BoutException& e) { - EXPECT_EQ(e.what(), test_message); + EXPECT_TRUE(IsSubString(e.what(), test_message)); } try { throw BoutException("this is {}", "second"); } catch (const BoutException& e) { std::string message(e.what()); - EXPECT_EQ(message, "this is second"); + EXPECT_TRUE(IsSubString(message, "this is second")); } } -TEST(BoutExceptionTest, GetBacktrace) { +TEST_F(BoutExceptionTest, GetBacktrace) { std::string test_message{"Test message"}; try { throw BoutException(test_message); } catch (const BoutException& e) { - std::string expected_1{"[bt] #1"}; - std::string expected_2{"serial_tests"}; -#if BOUT_USE_BACKTRACE // Should be able to find something about backtrace - EXPECT_TRUE(IsSubString(e.getBacktrace(), expected_1)); - EXPECT_TRUE(IsSubString(e.getBacktrace(), expected_2)); -#else - // Should *not* be able to find something about backtrace - EXPECT_FALSE(IsSubString(e.getBacktrace(), expected_1)); - EXPECT_FALSE(IsSubString(e.getBacktrace(), expected_2)); -#endif + EXPECT_TRUE(IsSubString(e.what(), "#2")); + // We should be able to see either the main source file or the executable name + EXPECT_TRUE(IsSubString(e.what(), "bout_test_main") + || IsSubString(e.what(), "serial_tests")); } } -TEST(BoutExceptionTest, FmtJoin) { +TEST_F(BoutExceptionTest, FmtJoin) { const std::vector things = {1, 2, 3, 4}; - constexpr std::string_view expected = "list: 1, 2, 3, 4"; + const std::string expected = "list: 1, 2, 3, 4"; const BoutException exception{"list: {}", fmt::join(things, ", ")}; - EXPECT_EQ(exception.what(), expected); + EXPECT_TRUE(IsSubString(std::string{exception.what()}, expected)); } TEST(BoutRhsFailTest, ThrowCorrect) { diff --git a/tests/unit/sys/test_output.cxx b/tests/unit/sys/test_output.cxx index 959823ede3..2f13df9cb7 100644 --- a/tests/unit/sys/test_output.cxx +++ b/tests/unit/sys/test_output.cxx @@ -1,7 +1,7 @@ #include "test_tmpfiles.hxx" -#include "bout/boutexception.hxx" +#include "bout/build_defines.hxx" #include "bout/output.hxx" -#include "bout/output_bout_types.hxx" +#include "bout/output_bout_types.hxx" // IWYU pragma: keep #include "gtest/gtest.h" #include diff --git a/tests/unit/test_extras.cxx b/tests/unit/test_extras.cxx index 332a53089b..b1caf038d3 100644 --- a/tests/unit/test_extras.cxx +++ b/tests/unit/test_extras.cxx @@ -14,7 +14,8 @@ ::testing::AssertionResult IsSubString(const std::string& str, if (str.find(substring) != std::string::npos) { return ::testing::AssertionSuccess(); } else { - return ::testing::AssertionFailure() << '"' << substring << "\" not found in " << str; + return ::testing::AssertionFailure() + << '"' << substring << "\" not found in \"" << str << '"'; } } diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 31a4694d10..9e305b3048 100755 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -176,7 +176,7 @@ def build_sdist(sdist_directory, config_settings=None): print(config_settings, sdist_directory) enable_gz = True enable_xz = False - external = {"fmt", "mpark.variant"} + external = {"fmt", "mpark.variant", "cpptrace"} if config_settings is not None: global useLocalVersion, pkgname for k, v in config_settings.items(): @@ -212,12 +212,10 @@ def build_sdist(sdist_directory, config_settings=None): run(f"rm {tmp}") with open(tmp, "w") as f: - f.write( - f"""Metadata-Version: 2.1 + f.write(f"""Metadata-Version: 2.1 Name: {pkgname} Version: {getversion()} -""" - ) +""") with open("LICENSE") as src: pre = "License: " for l in src: @@ -269,23 +267,19 @@ def prepare_metadata_for_build_wheel( distinfo = f"{metadata_directory}/{thisdir}" mkdir_p(distinfo) with open(f"{distinfo}/METADATA", "w") as f: - f.write( - f"""Metadata-Version: 2.1 + f.write(f"""Metadata-Version: 2.1 Name: {pkgname} Version: {getversion()} License-File: COPYING -""" - ) +""") run(f"cp LICENSE {distinfo}/COPYING") run(f"cp LICENSE.GPL {distinfo}/COPYING.GPL") with open(f"{distinfo}/WHEEL", "w") as f: - f.write( - f"""Wheel-Version: 1.0 + f.write(f"""Wheel-Version: 1.0 Generator: boutpp_custom_build_wheel ({getversion()}) Root-Is-Purelib: false Tag: {gettag()} -""" - ) +""") if record: with open(f"{distinfo}/RECORD", "w") as f: