diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..f057bea9e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,587 @@ +--- +Checks: + ' + abseil-cleanup-ctad + ' +WarningsAsErrors: '' +HeaderFileExtensions: + - h + - hh + - hpp + - hxx + - tpp +ImplementationFileExtensions: + - c + - cc + - cpp + - tpp + - cxx +HeaderFilterRegex: '.*/PQ/src/.*' +SystemHeaders: false +FormatStyle: google +# CheckOptions: +# - key: llvmlibc-restrict-system-libc-headers.Includes +# value: 'cstdint' + +# ### allow short variable names +# - key: readability-identifier-length.IgnoredParameterNames +# value: '^(id|it|db|x|y|z|tx)$' +# - key: readability-identifier-length.IgnoredVariableNames +# value: '^(id|it|db|x|y|z|tx)$' + +# ### special member functions +# - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor +# value: true +# - key: hicpp-special-member-functions.AllowSoleDefaultDtor +# value: true + +# ### short line statements +# - key: readability-braces-around-statements.ShortStatementLines +# value: 4 +# - key: google-readability-braces-around-statements.ShortStatementLines +# value: 4 +# - key: hicpp-braces-around-statements.ShortStatementLines +# value: 4 + +# ### necessary for POD-structs! +# - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic +# value: true +... + +### TO BE INCLUDED IN THE FUTURE +# abseil-duration-addition, + # abseil-duration-comparison, + # abseil-duration-conversion-cast, + # abseil-duration-division, + # abseil-duration-factory-float, + # abseil-duration-factory-scale, + # abseil-duration-subtraction, + # abseil-duration-unnecessary-conversion, + # abseil-faster-strsplit-delimiter, + # abseil-no-internal-dependencies, + # abseil-no-namespace, + # abseil-redundant-strcat-calls, + # abseil-str-cat-append, + # abseil-string-find-startswith, + # abseil-string-find-str-contains, + # abseil-time-comparison, + # abseil-time-subtraction, + # abseil-upgrade-duration-conversions, + # altera-id-dependent-backward-branch, + # altera-kernel-name-restriction, + # altera-single-work-item-barrier, + # altera-struct-pack-align, + # altera-unroll-loops, + # android-cloexec-accept, + # android-cloexec-accept4, + # android-cloexec-creat, + # android-cloexec-dup, + # android-cloexec-epoll-create, + # android-cloexec-epoll-create1, + # android-cloexec-fopen, + # android-cloexec-inotify-init, + # android-cloexec-inotify-init1, + # android-cloexec-memfd-create, + # android-cloexec-open, + # android-cloexec-pipe, + # android-cloexec-pipe2, + # android-cloexec-socket, + # android-comparison-in-temp-failure-retry, + # boost-use-to-string, + # bugprone-argument-comment, + # bugprone-assert-side-effect, + # bugprone-assignment-in-if-condition, + # bugprone-bad-signal-to-kill-thread, + # bugprone-bool-pointer-implicit-conversion, + # bugprone-branch-clone, + # bugprone-casting-through-void, + # bugprone-chained-comparison, + # bugprone-compare-pointer-to-member-virtual-function, + # bugprone-copy-constructor-init, + # bugprone-dangling-handle, + # bugprone-dynamic-static-initializers, + # bugprone-easily-swappable-parameters, + # bugprone-empty-catch, + # bugprone-exception-escape, + # bugprone-fold-init-type, + # bugprone-forward-declaration-namespace, + # bugprone-forwarding-reference-overload, + # bugprone-implicit-widening-of-multiplication-result, + # bugprone-inaccurate-erase, + # bugprone-inc-dec-in-conditions, + # bugprone-incorrect-enable-if, + # bugprone-incorrect-roundings, + # bugprone-infinite-loop, + # bugprone-integer-division, + # bugprone-lambda-function-name, + # bugprone-macro-parentheses, + # bugprone-macro-repeated-side-effects, + # bugprone-misplaced-operator-in-strlen-in-alloc, + # bugprone-misplaced-pointer-arithmetic-in-alloc, + # bugprone-misplaced-widening-cast, + # bugprone-move-forwarding-reference, + # bugprone-multi-level-implicit-pointer-conversion, + # bugprone-multiple-new-in-one-expression, + # bugprone-multiple-statement-macro, + # bugprone-narrowing-conversions, + # bugprone-no-escape, + # bugprone-non-zero-enum-to-bool-conversion, + # bugprone-not-null-terminated-result, + # bugprone-optional-value-conversion, + # bugprone-parent-virtual-call, + # bugprone-posix-return, + # bugprone-redundant-branch-condition, + # bugprone-reserved-identifier, + # bugprone-shared-ptr-array-mismatch, + # bugprone-signal-handler, + # bugprone-signed-char-misuse, + # bugprone-sizeof-container, + # bugprone-sizeof-expression, + # bugprone-spuriously-wake-up-functions, + # bugprone-standalone-empty, + # bugprone-string-constructor, + # bugprone-string-integer-assignment, + # bugprone-string-literal-with-embedded-nul, + # bugprone-stringview-nullptr, + # bugprone-suspicious-enum-usage, + # bugprone-suspicious-include, + # bugprone-suspicious-memory-comparison, + # bugprone-suspicious-memset-usage, + # bugprone-suspicious-missing-comma, + # bugprone-suspicious-realloc-usage, + # bugprone-suspicious-semicolon, + # bugprone-suspicious-string-compare, + # bugprone-swapped-arguments, + # bugprone-switch-missing-default-case, + # bugprone-terminating-continue, + # bugprone-throw-keyword-missing, + # bugprone-too-small-loop-variable, + # bugprone-unchecked-optional-access, + # bugprone-undefined-memory-manipulation, + # bugprone-undelegated-constructor, + # bugprone-unhandled-exception-at-new, + # bugprone-unhandled-self-assignment, + # bugprone-unique-ptr-array-mismatch, + # bugprone-unsafe-functions, + # bugprone-unused-local-non-trivial-variable, + # bugprone-unused-raii, + # bugprone-unused-return-value, + # bugprone-use-after-move, + # bugprone-virtual-near-miss, + # cert-con36-c, + # cert-con54-cpp, + # cert-dcl03-c, + # cert-dcl16-c, + # cert-dcl21-cpp, + # cert-dcl37-c, + # cert-dcl50-cpp, + # cert-dcl51-cpp, + # cert-dcl54-cpp, + # cert-dcl58-cpp, + # cert-dcl59-cpp, + # cert-env33-c, + # cert-err09-cpp, + # cert-err33-c, + # cert-err34-c, + # cert-err52-cpp, + # cert-err58-cpp, + # cert-err60-cpp, + # cert-err61-cpp, + # cert-exp42-c, + # cert-fio38-c, + # cert-flp30-c, + # cert-flp37-c, + # cert-mem57-cpp, + # cert-msc24-c, + # cert-msc30-c, + # cert-msc32-c, + # cert-msc33-c, + # cert-msc50-cpp, + # cert-msc51-cpp, + # cert-msc54-cpp, + # cert-oop11-cpp, + # cert-oop54-cpp, + # cert-oop57-cpp, + # cert-oop58-cpp, + # cert-pos44-c, + # cert-pos47-c, + # cert-sig30-c, + # cert-str34-c, + # clang-analyzer-apiModeling.Errno, + # clang-analyzer-apiModeling.TrustNonnull, + # clang-analyzer-apiModeling.TrustReturnsNonnull, + # clang-analyzer-apiModeling.google.GTest, + # clang-analyzer-apiModeling.llvm.CastValue, + # clang-analyzer-apiModeling.llvm.ReturnValue, + # clang-analyzer-core.BitwiseShift, + # clang-analyzer-core.CallAndMessage, + # clang-analyzer-core.CallAndMessageModeling, + # clang-analyzer-core.DivideZero, + # clang-analyzer-core.DynamicTypePropagation, + # clang-analyzer-core.NonNullParamChecker, + # clang-analyzer-core.NonnilStringConstants, + # clang-analyzer-core.NullDereference, + # clang-analyzer-core.StackAddrEscapeBase, + # clang-analyzer-core.StackAddressEscape, + # clang-analyzer-core.UndefinedBinaryOperatorResult, + # clang-analyzer-core.VLASize, + # clang-analyzer-core.builtin.BuiltinFunctions, + # clang-analyzer-core.builtin.NoReturnFunctions, + # clang-analyzer-core.uninitialized.ArraySubscript, + # clang-analyzer-core.uninitialized.Assign, + # clang-analyzer-core.uninitialized.Branch, + # clang-analyzer-core.uninitialized.CapturedBlockVariable, + # clang-analyzer-core.uninitialized.NewArraySize, + # clang-analyzer-core.uninitialized.UndefReturn, + # clang-analyzer-cplusplus.InnerPointer, + # clang-analyzer-cplusplus.Move, + # clang-analyzer-cplusplus.NewDelete, + # clang-analyzer-cplusplus.NewDeleteLeaks, + # clang-analyzer-cplusplus.PlacementNew, + # clang-analyzer-cplusplus.PureVirtualCall, + # clang-analyzer-cplusplus.SelfAssignment, + # clang-analyzer-cplusplus.SmartPtrModeling, + # clang-analyzer-cplusplus.StringChecker, + # clang-analyzer-cplusplus.VirtualCallModeling, + # clang-analyzer-deadcode.DeadStores, + # clang-analyzer-fuchsia.HandleChecker, + # clang-analyzer-nullability.NullPassedToNonnull, + # clang-analyzer-nullability.NullReturnedFromNonnull, + # clang-analyzer-nullability.NullabilityBase, + # clang-analyzer-nullability.NullableDereferenced, + # clang-analyzer-nullability.NullablePassedToNonnull, + # clang-analyzer-nullability.NullableReturnedFromNonnull, + # clang-analyzer-optin.core.EnumCastOutOfRange, + # clang-analyzer-optin.cplusplus.UninitializedObject, + # clang-analyzer-optin.cplusplus.VirtualCall, + # clang-analyzer-optin.mpi.MPI-Checker, + # clang-analyzer-optin.osx.OSObjectCStyleCast, + # clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker, + # clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker, + # clang-analyzer-optin.performance.GCDAntipattern, + # clang-analyzer-optin.performance.Padding, + # clang-analyzer-optin.portability.UnixAPI, + # clang-analyzer-osx.API, + # clang-analyzer-osx.MIG, + # clang-analyzer-osx.NSOrCFErrorDerefChecker, + # clang-analyzer-osx.NumberObjectConversion, + # clang-analyzer-osx.OSObjectRetainCount, + # clang-analyzer-osx.ObjCProperty, + # clang-analyzer-osx.SecKeychainAPI, + # clang-analyzer-osx.cocoa.AtSync, + # clang-analyzer-osx.cocoa.AutoreleaseWrite, + # clang-analyzer-osx.cocoa.ClassRelease, + # clang-analyzer-osx.cocoa.Dealloc, + # clang-analyzer-osx.cocoa.IncompatibleMethodTypes, + # clang-analyzer-osx.cocoa.Loops, + # clang-analyzer-osx.cocoa.MissingSuperCall, + # clang-analyzer-osx.cocoa.NSAutoreleasePool, + # clang-analyzer-osx.cocoa.NSError, + # clang-analyzer-osx.cocoa.NilArg, + # clang-analyzer-osx.cocoa.NonNilReturnValue, + # clang-analyzer-osx.cocoa.ObjCGenerics, + # clang-analyzer-osx.cocoa.RetainCount, + # clang-analyzer-osx.cocoa.RetainCountBase, + # clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak, + # clang-analyzer-osx.cocoa.SelfInit, + # clang-analyzer-osx.cocoa.SuperDealloc, + # clang-analyzer-osx.cocoa.UnusedIvars, + # clang-analyzer-osx.cocoa.VariadicMethodTypes, + # clang-analyzer-osx.coreFoundation.CFError, + # clang-analyzer-osx.coreFoundation.CFNumber, + # clang-analyzer-osx.coreFoundation.CFRetainRelease, + # clang-analyzer-osx.coreFoundation.containers.OutOfBounds, + # clang-analyzer-osx.coreFoundation.containers.PointerSizedValues, + # clang-analyzer-security.FloatLoopCounter, + # clang-analyzer-security.cert.env.InvalidPtr, + # clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, + # clang-analyzer-security.insecureAPI.SecuritySyntaxChecker, + # clang-analyzer-security.insecureAPI.UncheckedReturn, + # clang-analyzer-security.insecureAPI.bcmp, + # clang-analyzer-security.insecureAPI.bcopy, + # clang-analyzer-security.insecureAPI.bzero, + # clang-analyzer-security.insecureAPI.decodeValueOfObjCType, + # clang-analyzer-security.insecureAPI.getpw, + # clang-analyzer-security.insecureAPI.gets, + # clang-analyzer-security.insecureAPI.mkstemp, + # clang-analyzer-security.insecureAPI.mktemp, + # clang-analyzer-security.insecureAPI.rand, + # clang-analyzer-security.insecureAPI.strcpy, + # clang-analyzer-security.insecureAPI.vfork, + # clang-analyzer-unix.API, + # clang-analyzer-unix.DynamicMemoryModeling, + # clang-analyzer-unix.Errno, + # clang-analyzer-unix.Malloc, + # clang-analyzer-unix.MallocSizeof, + # clang-analyzer-unix.MismatchedDeallocator, + # clang-analyzer-unix.StdCLibraryFunctions, + # clang-analyzer-unix.Vfork, + # clang-analyzer-unix.cstring.BadSizeArg, + # clang-analyzer-unix.cstring.CStringModeling, + # clang-analyzer-unix.cstring.NullArg, + # clang-analyzer-valist.CopyToSelf, + # clang-analyzer-valist.Uninitialized, + # clang-analyzer-valist.Unterminated, + # clang-analyzer-valist.ValistBase, + # clang-analyzer-webkit.NoUncountedMemberChecker, + # clang-analyzer-webkit.RefCntblBaseVirtualDtor, + # clang-analyzer-webkit.UncountedLambdaCapturesChecker, + # concurrency-mt-unsafe, + # concurrency-thread-canceltype-asynchronous, + # cppcoreguidelines-avoid-c-arrays, + # cppcoreguidelines-avoid-capturing-lambda-coroutines, + # cppcoreguidelines-avoid-const-or-ref-data-members, + # cppcoreguidelines-avoid-do-while, + # cppcoreguidelines-avoid-goto, + # cppcoreguidelines-avoid-magic-numbers, + # cppcoreguidelines-avoid-non-const-global-variables, + # cppcoreguidelines-avoid-reference-coroutine-parameters, + # cppcoreguidelines-c-copy-assignment-signature, + # cppcoreguidelines-explicit-virtual-functions, + # cppcoreguidelines-init-variables, + # cppcoreguidelines-interfaces-global-init, + # cppcoreguidelines-macro-to-enum, + # cppcoreguidelines-macro-usage, + # cppcoreguidelines-misleading-capture-default-by-value, + # cppcoreguidelines-missing-std-forward, + # cppcoreguidelines-narrowing-conversions, + # cppcoreguidelines-no-malloc, + # cppcoreguidelines-no-suspend-with-lock, + # cppcoreguidelines-noexcept-destructor, + # cppcoreguidelines-noexcept-move-operations, + # cppcoreguidelines-noexcept-swap, + # cppcoreguidelines-non-private-member-variables-in-classes, + # cppcoreguidelines-owning-memory, + # cppcoreguidelines-prefer-member-initializer, + # cppcoreguidelines-pro-bounds-array-to-pointer-decay, + # cppcoreguidelines-pro-bounds-constant-array-index, + # cppcoreguidelines-pro-bounds-pointer-arithmetic, + # cppcoreguidelines-pro-type-const-cast, + # cppcoreguidelines-pro-type-cstyle-cast, + # cppcoreguidelines-pro-type-member-init, + # cppcoreguidelines-pro-type-reinterpret-cast, + # cppcoreguidelines-pro-type-static-cast-downcast, + # cppcoreguidelines-pro-type-union-access, + # cppcoreguidelines-pro-type-vararg, + # cppcoreguidelines-rvalue-reference-param-not-moved, + # cppcoreguidelines-slicing, + # cppcoreguidelines-special-member-functions, + # cppcoreguidelines-use-default-member-init, + # cppcoreguidelines-virtual-class-destructor, + # darwin-avoid-spinlock, + # darwin-dispatch-once-nonstatic, + # fuchsia-default-arguments-calls, + # fuchsia-default-arguments-declarations, + # fuchsia-header-anon-namespaces, + # fuchsia-multiple-inheritance, + # fuchsia-overloaded-operator, + # fuchsia-statically-constructed-objects, + # fuchsia-trailing-return, + # fuchsia-virtual-inheritance, + # google-build-explicit-make-pair, + # google-build-namespaces, + # google-build-using-namespace, + # google-default-arguments, + # google-explicit-constructor, + # google-global-names-in-headers, + # google-objc-avoid-nsobject-new, + # google-objc-avoid-throwing-exception, + # google-objc-function-naming, + # google-objc-global-variable-declaration, + # google-readability-avoid-underscore-in-googletest-name, + # google-readability-braces-around-statements, + # google-readability-casting, + # google-readability-function-size, + # google-readability-namespace-comments, + # google-readability-todo, + # google-runtime-int, + # google-runtime-operator, + # google-upgrade-googletest-case, + # hicpp-avoid-c-arrays, + # hicpp-avoid-goto, + # hicpp-braces-around-statements, + # hicpp-deprecated-headers, + # hicpp-exception-baseclass, + # hicpp-explicit-conversions, + # hicpp-function-size, + # hicpp-ignored-remove-result, + # hicpp-invalid-access-moved, + # hicpp-member-init, + # hicpp-move-const-arg, + # hicpp-multiway-paths-covered, + # hicpp-named-parameter, + # hicpp-new-delete-operators, + # hicpp-no-array-decay, + # hicpp-no-assembler, + # hicpp-no-malloc, + # hicpp-noexcept-move, + # hicpp-signed-bitwise, + # hicpp-special-member-functions, + # hicpp-static-assert, + # hicpp-undelegated-constructor, + # hicpp-uppercase-literal-suffix, + # hicpp-use-auto, + # hicpp-use-emplace, + # hicpp-use-equals-default, + # hicpp-use-equals-delete, + # hicpp-use-noexcept, + # hicpp-use-nullptr, + # hicpp-use-override, + # hicpp-vararg, + # linuxkernel-must-check-errs, + # llvm-else-after-return, + # llvm-header-guard, + # llvm-include-order, + # llvm-namespace-comment, + # llvm-prefer-isa-or-dyn-cast-in-conditionals, + # llvm-prefer-register-over-unsigned, + # llvm-qualified-auto, + # llvm-twine-local, + # llvmlibc-callee-namespace, + # llvmlibc-implementation-in-namespace, + # llvmlibc-inline-function-decl, + # llvmlibc-restrict-system-libc-headers, + # misc-confusable-identifiers, + # misc-const-correctness, + # misc-coroutine-hostile-raii, + # misc-definitions-in-headers, + # misc-header-include-cycle, + # misc-include-cleaner, + # misc-misleading-bidirectional, + # misc-misleading-identifier, + # misc-misplaced-const, + # misc-new-delete-overloads, + # misc-no-recursion, + # misc-non-copyable-objects, + # misc-non-private-member-variables-in-classes, + # misc-redundant-expression, + # misc-static-assert, + # misc-throw-by-value-catch-by-reference, + # misc-unconventional-assign-operator, + # misc-uniqueptr-reset-release, + # misc-unused-alias-decls, + # misc-unused-parameters, + # misc-unused-using-decls, + # misc-use-anonymous-namespace, + # modernize-avoid-bind, + # modernize-avoid-c-arrays, + # modernize-concat-nested-namespaces, + # modernize-deprecated-headers, + # modernize-deprecated-ios-base-aliases, + # modernize-loop-convert, + # modernize-macro-to-enum, + # modernize-make-shared, + # modernize-make-unique, + # modernize-pass-by-value, + # modernize-raw-string-literal, + # modernize-redundant-void-arg, + # modernize-replace-auto-ptr, + # modernize-replace-disallow-copy-and-assign-macro, + # modernize-replace-random-shuffle, + # modernize-return-braced-init-list, + # modernize-shrink-to-fit, + # modernize-type-traits, + # modernize-unary-static-assert, + # modernize-use-auto, + # modernize-use-bool-literals, + # modernize-use-constraints, + # modernize-use-default-member-init, + # modernize-use-emplace, + # modernize-use-equals-default, + # modernize-use-equals-delete, + # modernize-use-nodiscard, + # modernize-use-noexcept, + # modernize-use-nullptr, + # modernize-use-override, + # modernize-use-starts-ends-with, + # modernize-use-std-numbers, + # modernize-use-std-print, + # modernize-use-trailing-return-type, + # modernize-use-transparent-functors, + # modernize-use-uncaught-exceptions, + # modernize-use-using, + # mpi-buffer-deref, + # mpi-type-mismatch, + # objc-assert-equals, + # objc-avoid-nserror-init, + # objc-dealloc-in-category, + # objc-forbidden-subclassing, + # objc-missing-hash, + # objc-nsdate-formatter, + # objc-nsinvocation-argument-lifetime, + # objc-property-declaration, + # objc-super-self, + # openmp-exception-escape, + # openmp-use-default-none, + # performance-avoid-endl, + # performance-enum-size, + # performance-faster-string-find, + # performance-for-range-copy, + # performance-implicit-conversion-in-loop, + # performance-inefficient-algorithm, + # performance-inefficient-string-concatenation, + # performance-inefficient-vector-operation, + # performance-move-const-arg, + # performance-move-constructor-init, + # performance-no-automatic-move, + # performance-no-int-to-ptr, + # performance-noexcept-destructor, + # performance-noexcept-move-constructor, + # performance-noexcept-swap, + # performance-trivially-destructible, + # performance-type-promotion-in-math-fn, + # performance-unnecessary-copy-initialization, + # performance-unnecessary-value-param, + # portability-restrict-system-includes, + # portability-simd-intrinsics, + # portability-std-allocator-const, + # readability-avoid-const-params-in-decls, + # readability-avoid-nested-conditional-operator, + # readability-avoid-return-with-void-value, + # readability-avoid-unconditional-preprocessor-if, + # readability-braces-around-statements, + # readability-const-return-type, + # readability-container-contains, + # readability-container-data-pointer, + # readability-container-size-empty, + # readability-convert-member-functions-to-static, + # readability-delete-null-pointer, + # readability-duplicate-include, + # readability-else-after-return, + # readability-function-cognitive-complexity, + # readability-function-size, + # readability-identifier-length, + # readability-identifier-naming, + # readability-implicit-bool-conversion, + # readability-inconsistent-declaration-parameter-name, + # readability-isolate-declaration, + # readability-magic-numbers, + # readability-make-member-function-const, + # readability-misleading-indentation, + # readability-misplaced-array-index, + # readability-named-parameter, + # readability-non-const-parameter, + # readability-operators-representation, + # readability-qualified-auto, + # readability-redundant-access-specifiers, + # readability-redundant-casting, + # readability-redundant-control-flow, + # readability-redundant-declaration, + # readability-redundant-function-ptr-dereference, + # readability-redundant-inline-specifier, + # readability-redundant-member-init, + # readability-redundant-preprocessor, + # readability-redundant-smartptr-get, + # readability-redundant-string-cstr, + # readability-redundant-string-init, + # readability-reference-to-constructed-temporary, + # readability-simplify-boolean-expr, + # readability-simplify-subscript-expr, + # readability-static-accessed-through-instance, + # readability-static-definition-in-anonymous-namespace, + # readability-string-compare, + # readability-suspicious-call-argument, + # readability-uniqueptr-delete-release, + # readability-uppercase-literal-suffix, + # readability-use-anyofallof, + # zircon-temporary-objects, \ No newline at end of file diff --git a/.cmake/benchmarking.cmake b/.cmake/benchmarking.cmake index d52413811..cc9eef14d 100644 --- a/.cmake/benchmarking.cmake +++ b/.cmake/benchmarking.cmake @@ -13,7 +13,7 @@ FetchContent_Declare( # Keep project warning policy from being applied to third-party sources. set(_CMAKE_CXX_FLAGS_BACKUP "${CMAKE_CXX_FLAGS}") -foreach(flag IN ITEMS "-Wswitch-enum" "-Werror=switch-enum") +foreach(flag IN ITEMS "-Wswitch-enum" "-Werror=switch-enum" "-Werror" "-Wundef") string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endforeach() diff --git a/.github/notworkingworkflows/ci_cuda.yml b/.github/notworkingworkflows/ci_cuda.yml deleted file mode 100644 index d5fddcb7e..000000000 --- a/.github/notworkingworkflows/ci_cuda.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: C/C++ CI - -on: - push: - branches: - - '*' - pull_request: - branches: - - '*' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v3 - - uses: Jimver/cuda-toolkit@v0.2.15 - id: cuda-toolkit - with: - cuda: '12.4.1' - - - name: install gcc13 - run: | - sudo apt update - sudo apt install gcc-13 g++-13 - shell: bash - - - name: setup python - uses: actions/setup-python@v2 - with: - python-version: '3.12' - - - name: install coverage - run: | - python -m pip install coverage - python -m pip install gcovr - shell: bash - - - name: Build and Test Project - run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_GCOVR=ON -DBUILD_WITH_KOKKOS=ON -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_TURING75=ON .. - make -j20 - make coverage_xml - env: - CC: gcc-13 - CXX: g++-13 - - # - name: Upload coverage to Codecov - # uses: codecov/codecov-action@v3 - # with: - # fail_ci_if_error: true # optional (default = false) - # gcov: true - # gcov_executable: gcov-13 - # env: - # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..ea03c8beb --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,80 @@ +name: LINT + +on: + pull_request: + branches: + - '*' + paths: + - '.github/workflows/ci_build.yml' + - '.cmake/**' + - 'apps/**' + - 'include/**' + - 'src/**' + - 'integration_tests/**' + - 'tests/**' + - 'benchmarks/CMakeLists.txt' + - 'benchmarks/src/**' + - 'CMakeLists.txt' + - '.clang-tidy' + - 'scripts/clang_tidy.sh' + - '.github/workflows/lint.yml' + push: + branches: + - dev + - main + paths: + - '.github/workflows/ci_build.yml' + - '.cmake/**' + - 'apps/**' + - 'include/**' + - 'src/**' + - 'integration_tests/**' + - 'CMakeLists.txt' + - '.clang-tidy' + - 'scripts/clang_tidy.sh' + - '.github/workflows/lint.yml' + - 'benchmarks/src/**' + - 'CMakeLists.txt' + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + + - name: Install build tools + run: | + sudo apt update + sudo apt install -y gcc-13 g++-13 mold ninja-build clangd-20 + sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-20 100 + shell: bash + + - name: Setup python + uses: actions/setup-python@v3 + with: + python-version: '3.12' + + - name: install python dependencies + run: | + python -m pip install numpy + shell: bash + + - name: Install clangd-tidy + run: python -m pip install clangd-tidy + shell: bash + + - name: Configure (generate compile_commands.json) + run: | + cmake -S . -B build -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DBUILD_WITH_NATIVE=Off + env: + CC: gcc-13 + CXX: g++-13 + + - name: Run clangd-tidy + run: | + clangd-tidy $(find src/ apps/ include/ -name "*.cpp" -o -name "*.hpp" -o -name "*.tpp" 2>/dev/null) -p=build diff --git a/.gitignore b/.gitignore index ea4adab52..d93c9dd9c 100644 --- a/.gitignore +++ b/.gitignore @@ -64,7 +64,6 @@ examples/**/tm.out examples/**/traj2box examples/**/*.cao - *.gcov googletest @@ -77,3 +76,11 @@ venv .venv env .env + +# local clangd output for checks for ci -- not to be committed +clangd-tidy-report.log + +# sometimes useful to make a syslink into the main dir from the build dir, but not to be committed +compile_commands.json + +CMakePresets.json diff --git a/.vscode/settings.json b/.vscode/settings.json index d4ccad7b4..e118037b5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -143,11 +143,15 @@ "coulombic", "Coulombics", "Coupl", + "Cueq", + "cuequivariance", "datapoints", + "Derivs", "DFTD", "dxyz", "ekin", "equil", + "Fennol", "filterwarnings", "forcexyz", "freset", @@ -214,6 +218,7 @@ "RSTFILEEXCEPTION", "RSTFILEOUTPUT", "SHAKEEXCEPTION", + "Slakos", "sonarlint", "STDOUTOUTPUT", "STREQ", @@ -241,4 +246,4 @@ "esbonio.sphinx.confDir": "", "workbench.colorTheme": "Visual Studio Dark - C++", "sonarlint.pathToCompileCommands": "${workspaceFolder}/.build/compile_commands.json" -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..d022e0c6c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,74 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "clangd-tidy (changed)", + "type": "shell", + "command": "bash", + "args": [ + "-c", + "scripts/clang_tidy.sh" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + { + "owner": "clangd-tidy", + "fileLocation": [ + "absolute" + ], + "pattern": { + "regexp": "^(.*?):(\\d+):(\\d+):\\s*(warning|error|note):\\s*(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ], + "group": "build" + }, + { + "label": "clangd-tidy (all)", + "type": "shell", + "command": "bash", + "args": [ + "-c", + "scripts/clang_tidy.sh --all" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + { + "owner": "clangd-tidy", + "fileLocation": [ + "absolute" + ], + "pattern": { + "regexp": "^(.*?):(\\d+):(\\d+):\\s*(warning|error|note):\\s*(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ], + "group": "build" + }, + { + "type": "cmake", + "label": "CMake: build", + "command": "build", + "targets": [ + "all" + ], + "group": "build", + "problemMatcher": [], + "detail": "CMake template build task" + } + ] +} diff --git a/apps/PQ.cpp b/apps/PQ.cpp index efccffcc9..2aec6011e 100644 --- a/apps/PQ.cpp +++ b/apps/PQ.cpp @@ -20,13 +20,12 @@ ******************************************************************************/ -#include // for EXIT_SUCCESS -#include // for exception -#include // for remove_all -#include // for operator<< -#include // for unique_ptr -#include // for string, char_traits -#include // for vector +#include // for EXIT_SUCCESS +#include // for exception +#include // for operator<< +#include // for unique_ptr +#include // for string, char_traits +#include // for vector #include "commandLineArgs.hpp" // for CommandLineArgs #include "engine.hpp" // for Engine diff --git a/benchmarks/perf/perfBenchSetup.hpp b/benchmarks/perf/perfBenchSetup.hpp index 1976f7da2..82c3647b4 100644 --- a/benchmarks/perf/perfBenchSetup.hpp +++ b/benchmarks/perf/perfBenchSetup.hpp @@ -37,7 +37,6 @@ #include "matrix.hpp" #include "molecule.hpp" #include "simulationBox.hpp" -#include "vector3d.hpp" namespace potential { @@ -72,7 +71,9 @@ namespace benchSetup 0.25 * d }; atom->setPosition(pos); - atom->setPositionOld(pos); // at-rest start (stable for constraints) + atom->setPositionOld( + pos + ); // at-rest start (stable for constraints) atom->setVelocity({0.01 * (d + 1.0), -0.015, 0.02}); atom->setForce({0.1, -0.2, 0.05}); atom->setShiftForce({0.0, 0.0, 0.0}); @@ -94,11 +95,19 @@ namespace benchSetup { auto nonCoulomb = potential::ForceFieldNonCoulomb(); nonCoulomb.setNonCoulombPairsMatrix( - linearAlgebra::Matrix>(2, 2) + linearAlgebra::Matrix>( + 2, + 2 + ) ); - auto pair = - potential::LennardJonesPair(std::size_t(0), std::size_t(1), 12.0, 2.0, 3.0); + auto pair = potential::LennardJonesPair( + std::size_t(0), + std::size_t(1), + 12.0, + 2.0, + 3.0 + ); nonCoulomb.setNonCoulombPairsMatrix(0, 1, pair); nonCoulomb.setNonCoulombPairsMatrix(1, 0, pair); @@ -118,10 +127,12 @@ namespace benchSetup for (std::size_t m = 0; m < nMolecules; ++m) { - auto molecule = makeMolecule(nAtomsPerMol, 3.0 * static_cast(m)); + auto molecule = + makeMolecule(nAtomsPerMol, 3.0 * static_cast(m)); for (std::size_t i = 0; i < nAtomsPerMol; ++i) - box.addAtom(molecule.getAtoms()[i]); // share the atom pointers + box.addAtom(molecule.getAtoms()[i] + ); // share the atom pointers box.addMolecule(molecule); } diff --git a/benchmarks/perf/perfBoxTransforms.cpp b/benchmarks/perf/perfBoxTransforms.cpp index 7f919dab8..3f5f005a3 100644 --- a/benchmarks/perf/perfBoxTransforms.cpp +++ b/benchmarks/perf/perfBoxTransforms.cpp @@ -33,7 +33,6 @@ #include "orthorhombicBox.hpp" #include "triclinicBox.hpp" -#include "vector3d.hpp" static constexpr long ITERATIONS = 20000; diff --git a/benchmarks/perf/perfConstraints.cpp b/benchmarks/perf/perfConstraints.cpp index ab420a176..f85460395 100644 --- a/benchmarks/perf/perfConstraints.cpp +++ b/benchmarks/perf/perfConstraints.cpp @@ -33,13 +33,11 @@ #define CALLGRIND_ZERO_STATS #endif -#include "perfBenchSetup.hpp" #include "bondConstraint.hpp" #include "constraints.hpp" -#include "molecule.hpp" +#include "perfBenchSetup.hpp" #include "simulationBox.hpp" #include "timingsSettings.hpp" -#include "vector3d.hpp" static constexpr long ITERATIONS = 1000; @@ -59,7 +57,13 @@ int main() for (std::size_t m = 0; m < molecules.size(); ++m) constr.addBondConstraint( - constraints::BondConstraint(&molecules[m], &molecules[m], 0, 1, 0.85) + constraints::BondConstraint( + &molecules[m], + &molecules[m], + 0, + 1, + 0.85 + ) ); constr.calculateConstraintBondRefs(box); diff --git a/benchmarks/perf/perfForceKernel.cpp b/benchmarks/perf/perfForceKernel.cpp index bb5bf140e..d989428c5 100644 --- a/benchmarks/perf/perfForceKernel.cpp +++ b/benchmarks/perf/perfForceKernel.cpp @@ -24,7 +24,6 @@ // (Coulomb + non-Coulomb pair evaluation, the per-pair getNonCoulPair lookup // and force accumulation), so callgrind yields a stable instruction count. -#include #include #ifdef PQ_WITH_CALLGRIND @@ -33,10 +32,10 @@ #define CALLGRIND_ZERO_STATS #endif -#include "perfBenchSetup.hpp" #include "coulombShiftedPotential.hpp" #include "intraNonBondedContainer.hpp" #include "intraNonBondedMap.hpp" +#include "perfBenchSetup.hpp" #include "physicalData.hpp" #include "potentialSettings.hpp" #include "simulationBox.hpp" diff --git a/benchmarks/perf/perfKinetics.cpp b/benchmarks/perf/perfKinetics.cpp index 20128ab76..6697839f8 100644 --- a/benchmarks/perf/perfKinetics.cpp +++ b/benchmarks/perf/perfKinetics.cpp @@ -32,7 +32,6 @@ #endif #include "perfBenchSetup.hpp" -#include "vector3d.hpp" static constexpr long ITERATIONS = 1000; diff --git a/benchmarks/perf/perfShiftVector.cpp b/benchmarks/perf/perfShiftVector.cpp index ff8473178..f28b079eb 100644 --- a/benchmarks/perf/perfShiftVector.cpp +++ b/benchmarks/perf/perfShiftVector.cpp @@ -51,7 +51,7 @@ int main() double sink = 0.0; for (long i = 0; i < ITERATIONS; ++i) { - const double x = (i & 127) * 0.3 - 19.0; + const double x = (i & 127) * 0.3 - 19.0; const linearAlgebra::Vec3D v(x, 0.5 * x, -x); sink += norm(ortho.calcShiftVector(v)); diff --git a/benchmarks/src/CMakeLists.txt b/benchmarks/src/CMakeLists.txt index 019d109c7..b5c5ae5e7 100644 --- a/benchmarks/src/CMakeLists.txt +++ b/benchmarks/src/CMakeLists.txt @@ -7,6 +7,7 @@ function(add_pq_benchmark target source) target_link_libraries(${target} PRIVATE benchmark::benchmark_main + simulationBox ${ARGN} ) diff --git a/changes/clang.developer.internal.md b/changes/clang.developer.internal.md new file mode 100644 index 000000000..746bbb684 --- /dev/null +++ b/changes/clang.developer.internal.md @@ -0,0 +1 @@ +- Add first version of CI for static analysis via clangd and clang-tidy (all clangd-tidy checks for now disabled apart a test check) diff --git a/include/engine/engineOutput.hpp b/include/engine/engineOutput.hpp index 3f46782d3..eaa14ff4f 100644 --- a/include/engine/engineOutput.hpp +++ b/include/engine/engineOutput.hpp @@ -90,12 +90,18 @@ namespace engine EngineOutput(); void writeEnergyFile(const size_t step, const pq::PhysicalData &); - void writeInstantEnergyFile(const size_t step, const pq::PhysicalData &); + void writeInstantEnergyFile( + const size_t step, + const pq::PhysicalData & + ); void writeXyzFile(pq::SimBox &); void writeVelFile(pq::SimBox &); void writeForceFile(pq::SimBox &); void writeChargeFile(pq::SimBox &); - void writeInfoFile(const double simulationTime, const pq::PhysicalData &); + void writeInfoFile( + const double simulationTime, + const pq::PhysicalData & + ); void writeRstFile(pq::SimBox &, const pq::Thermostat &, const size_t); void writeOptRstFile(pq::SimBox &, const size_t); @@ -105,12 +111,15 @@ namespace engine void writeBoxFile(const size_t, const pq::Box &); void writeOptFile(const size_t, const pq::Optimizer &); - void writeRingPolymerRstFile(std::vector &, const size_t); + void writeRingPolymerRstFile(std::vector &); void writeRingPolymerXyzFile(std::vector &); void writeRingPolymerVelFile(std::vector &); void writeRingPolymerForceFile(std::vector &); void writeRingPolymerChargeFile(std::vector &); - void writeRingPolymerEnergyFile(const size_t, const std::vector &); + void writeRingPolymerEnergyFile( + const size_t, + const std::vector & + ); void writeTimingsFile(timings::GlobalTimer &); @@ -151,4 +160,4 @@ namespace engine } // namespace engine -#endif // _ENGINE_OUTPUT_HPP_ \ No newline at end of file +#endif // _ENGINE_OUTPUT_HPP_ diff --git a/include/input/parameterFileReader/parameterFileReader.hpp b/include/input/parameterFileReader/parameterFileReader.hpp index 257626e09..bab66a76e 100644 --- a/include/input/parameterFileReader/parameterFileReader.hpp +++ b/include/input/parameterFileReader/parameterFileReader.hpp @@ -52,6 +52,7 @@ namespace input::parameterFile public: ParameterFileReader(const std::string &filename, pq::Engine &engine); + ~ParameterFileReader(); void read(); void deleteSection(const pq::ParamFileSection *section); @@ -72,4 +73,4 @@ namespace input::parameterFile } // namespace input::parameterFile -#endif // _PARAMETER_FILE_READER_HPP_ \ No newline at end of file +#endif // _PARAMETER_FILE_READER_HPP_ diff --git a/include/linearAlgebra/vector3d.hpp b/include/linearAlgebra/vector3d.hpp index d3a79f95c..608b31064 100644 --- a/include/linearAlgebra/vector3d.hpp +++ b/include/linearAlgebra/vector3d.hpp @@ -24,6 +24,7 @@ #define _VECTOR3D_INTERFACE_HPP_ -#include "vector3d/vector3d.hpp" // IWYU pragma: export +#include "vector3d/vector3d.hpp" // IWYU pragma: export +#include "vector3d/vector3dClass.hpp" // IWYU pragma: export -#endif // _VECTOR3D_INTERFACE_HPP_ \ No newline at end of file +#endif // _VECTOR3D_INTERFACE_HPP_ diff --git a/include/opt/optimizer/adam.hpp b/include/opt/optimizer/adam.hpp index d5a4b7e2f..1586a9281 100644 --- a/include/opt/optimizer/adam.hpp +++ b/include/opt/optimizer/adam.hpp @@ -34,7 +34,7 @@ namespace opt * @class Adam * */ - class Adam : public Optimizer + class Adam final : public Optimizer { private: constexpr static size_t _maxHistoryLength = 2; @@ -49,14 +49,14 @@ namespace opt explicit Adam(const size_t nEpochs, const size_t nAtoms); explicit Adam(const size_t, const double, const double, const size_t); - Adam() = default; - ~Adam() final = default; + Adam() = default; + ~Adam() = default; - [[nodiscard]] pq::SharedOptimizer clone() const final; - [[nodiscard]] size_t maxHistoryLength() const final; + [[nodiscard]] pq::SharedOptimizer clone() const; + [[nodiscard]] size_t maxHistoryLength() const; - void update(const double learningRate, const size_t step) final; + void update(const double learningRate, const size_t step); }; } // namespace opt -#endif // _ADAM_HPP_ \ No newline at end of file +#endif // _ADAM_HPP_ diff --git a/include/opt/optimizer/steepestDescent.hpp b/include/opt/optimizer/steepestDescent.hpp index 6cdd965f6..505cbe9cf 100644 --- a/include/opt/optimizer/steepestDescent.hpp +++ b/include/opt/optimizer/steepestDescent.hpp @@ -34,7 +34,7 @@ namespace opt * @brief Steepest Descent optimizer * */ - class SteepestDescent : public Optimizer + class SteepestDescent final : public Optimizer { private: constexpr static size_t _maxHistoryLength = 2; @@ -42,15 +42,15 @@ namespace opt public: explicit SteepestDescent(const size_t nEpochs); - SteepestDescent() = default; - ~SteepestDescent() final = default; + SteepestDescent() = default; + ~SteepestDescent() = default; - [[nodiscard]] pq::SharedOptimizer clone() const final; - [[nodiscard]] size_t maxHistoryLength() const final; + [[nodiscard]] pq::SharedOptimizer clone() const; + [[nodiscard]] size_t maxHistoryLength() const; - void update(const double learningRate, const size_t step) final; + void update(const double learningRate, const size_t step); }; } // namespace opt -#endif // _STEEPEST_DESCENT_HPP_ \ No newline at end of file +#endif // _STEEPEST_DESCENT_HPP_ diff --git a/include/output/ringPolymerRestartFileOutput.hpp b/include/output/ringPolymerRestartFileOutput.hpp index a8d98c90c..b55042c02 100644 --- a/include/output/ringPolymerRestartFileOutput.hpp +++ b/include/output/ringPolymerRestartFileOutput.hpp @@ -24,8 +24,7 @@ #define _RING_POLYMER_RESTART_FILE_OUTPUT_HPP_ -#include // for size_t -#include // for vector +#include // for vector #include "output.hpp" #include "typeAliases.hpp" @@ -43,9 +42,9 @@ namespace output public: using Output::Output; - void write(std::vector &, const size_t); + void write(std::vector &); }; } // namespace output -#endif // _RST_FILE_OUTPUT_HPP_ \ No newline at end of file +#endif // _RST_FILE_OUTPUT_HPP_ diff --git a/include/potential/coulomb_kokkos/coulombWolf_kokkos.hpp b/include/potential/coulomb_kokkos/coulombWolf_kokkos.hpp index cba8d0d80..ace0c79b5 100644 --- a/include/potential/coulomb_kokkos/coulombWolf_kokkos.hpp +++ b/include/potential/coulomb_kokkos/coulombWolf_kokkos.hpp @@ -24,6 +24,8 @@ #define _KOKKOS_COULOMB_WOLF_HPP_ +#ifdef WITH_KOKKOS + #include namespace potential @@ -60,12 +62,18 @@ namespace potential KokkosCoulombWolf() = default; ~KokkosCoulombWolf() = default; - KOKKOS_FUNCTION double calculate(const double, const double, const double, double&) - const; + KOKKOS_FUNCTION double calculate( + const double, + const double, + const double, + double& + ) const; [[nodiscard]] Kokkos::View getCoulombRadiusCutOff() const; }; } // namespace potential +#endif // WITH_KOKKOS + #endif // _KOKKOS_COULOMB_WOLF_HPP_ diff --git a/include/potential/nonCoulomb_kokkos/lennardJones_kokkos.hpp b/include/potential/nonCoulomb_kokkos/lennardJones_kokkos.hpp index 8bb4ddb8f..ea6b3d8fa 100644 --- a/include/potential/nonCoulomb_kokkos/lennardJones_kokkos.hpp +++ b/include/potential/nonCoulomb_kokkos/lennardJones_kokkos.hpp @@ -24,6 +24,8 @@ #define _KOKKOS_LENNARD_JONES_PAIR_HPP_ +#ifdef WITH_KOKKOS + #include #include "typeAliases.hpp" @@ -73,13 +75,21 @@ namespace potential [[nodiscard]] Kokkos::DualView &getC12(); [[nodiscard]] double getC12(const size_t i, const size_t j) const; - KOKKOS_FUNCTION double getRadialCutoff(const size_t, const size_t) - const; - [[nodiscard]] double getEnergyCutoff(const size_t i, const size_t j) - const; - [[nodiscard]] double getForceCutoff(const size_t i, const size_t j) - const; + KOKKOS_FUNCTION double getRadialCutoff( + const size_t, + const size_t + ) const; + [[nodiscard]] double getEnergyCutoff( + const size_t i, + const size_t j + ) const; + [[nodiscard]] double getForceCutoff( + const size_t i, + const size_t j + ) const; }; } // namespace potential -#endif // _KOKKOS_LENNARD_JONES_PAIR_HPP_ \ No newline at end of file +#endif // WITH_KOKKOS + +#endif // _KOKKOS_LENNARD_JONES_PAIR_HPP_ diff --git a/include/potential/potential_kokkos.hpp b/include/potential/potential_kokkos.hpp index afc99dbff..9fca4a589 100644 --- a/include/potential/potential_kokkos.hpp +++ b/include/potential/potential_kokkos.hpp @@ -24,6 +24,8 @@ #define _KOKKOS_POTENTIAL_HPP_ +#ifdef WITH_KOKKOS + #include "timer.hpp" // for Timer #include "typeAliases.hpp" @@ -49,4 +51,6 @@ namespace potential } // namespace potential -#endif // _KOKKOS_POTENTIAL_HPP_ \ No newline at end of file +#endif // WITH_KOKKOS + +#endif // _KOKKOS_POTENTIAL_HPP_ diff --git a/include/simulationBox/simulationBox_kokkos.hpp b/include/simulationBox/simulationBox_kokkos.hpp index a59a8026c..73f535b6c 100644 --- a/include/simulationBox/simulationBox_kokkos.hpp +++ b/include/simulationBox/simulationBox_kokkos.hpp @@ -24,6 +24,8 @@ #define _KOKKOS_SIMULATION_BOX_HPP_ +#ifdef WITH_KOKKOS + #include #include "typeAliases.hpp" @@ -61,7 +63,11 @@ namespace simulationBox KokkosSimulationBox() = default; ~KokkosSimulationBox() = default; - KOKKOS_FUNCTION static void calcShiftVector(const double*, Kokkos::View, double*); + KOKKOS_FUNCTION static void calcShiftVector( + const double*, + Kokkos::View, + double* + ); void initKokkosSimulationBox(pq::SimBox& simBox); void initForces(); @@ -103,4 +109,6 @@ namespace simulationBox }; } // namespace simulationBox -#endif // _KOKKOS_SIMULATION_BOX_HPP_ \ No newline at end of file +#endif // WITH_KOKKOS + +#endif // _KOKKOS_SIMULATION_BOX_HPP_ diff --git a/scripts/clang_tidy.sh b/scripts/clang_tidy.sh new file mode 100755 index 000000000..c9d4d63ba --- /dev/null +++ b/scripts/clang_tidy.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -o pipefail + +LOGFILE="clangd-tidy-report.log" +# Only stdout goes to the log file; stderr (where --tqdm draws its +# progress bar via carriage returns) stays on the terminal only, so +# the log file doesn't fill up with \r-based redraw noise. +exec > >(tee "$LOGFILE") + +echo "Clangd-Tidy:" + +all_files=false +while [[ $# -gt 0 ]]; do + case "$1" in + --all) + all_files=true + shift + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +files=() +if $all_files; then + echo " Mode: all tracked C++ files" + while IFS= read -r f; do + [[ -f "$f" ]] && files+=("$f") + done < <(git ls-files '*.cpp' '*.cxx' '*.cc' '*.c' '*.h' '*.hpp' '*.hxx' -- ':!external') +else + echo " Mode: changed files since origin/dev" + while IFS=$'\t' read -r status old new; do + case "$status" in + D) ;; + R*) [[ -f "$new" ]] && files+=("$new") ;; + *) [[ -f "$old" ]] && files+=("$old") ;; + esac + done < <(git diff --name-status "$(git merge-base HEAD origin/dev)") + + # Filter to C++ files only (changed mode may include non-source files) + # and exclude anything under external/ + cpp_files=() + for f in "${files[@]}"; do + [[ "$f" == external/* ]] && continue + [[ "$f" =~ \.(cpp|cxx|cc|c|h|hpp|hxx)$ ]] && cpp_files+=("$f") + done + files=("${cpp_files[@]}") +fi + +if [[ ${#files[@]} -eq 0 ]]; then + echo " No files to check." + exit 0 +fi + +echo " Files: ${#files[@]}" +clangd-tidy "${files[@]}" -p=. --tqdm -j3 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6fcb6b553..177cabb58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,9 +28,10 @@ add_subdirectory(opt) add_subdirectory(randomNumberGenerator) if(BUILD_WITH_PYTHON_BINDINGS) + add_definitions(-DWITH_WITH_PYTHON_BINDINGS) add_subdirectory(python) endif() if(BUILD_WITH_MPI) add_subdirectory(mpi) -endif() \ No newline at end of file +endif() diff --git a/src/QM/ase/aseMaceRunner.cpp b/src/QM/ase/aseMaceRunner.cpp index cde852239..f0bed9e63 100644 --- a/src/QM/ase/aseMaceRunner.cpp +++ b/src/QM/ase/aseMaceRunner.cpp @@ -22,9 +22,7 @@ #include "aseMaceRunner.hpp" -#include // for fprintf, stderr - -#include "pybind11/embed.h" +#include using QM::AseMaceRunner; diff --git a/src/engine/engineOutput.cpp b/src/engine/engineOutput.cpp index be0bba083..c8e519d91 100644 --- a/src/engine/engineOutput.cpp +++ b/src/engine/engineOutput.cpp @@ -299,13 +299,10 @@ void EngineOutput::writeOptFile( * @param simulationBox * @param step */ -void EngineOutput::writeRingPolymerRstFile( - std::vector &beads, - const size_t step -) +void EngineOutput::writeRingPolymerRstFile(std::vector &beads) { startTimingsSection("RingPolymerRestartFileOutput"); - _rpmdRstFileOutput->write(beads, step); + _rpmdRstFileOutput->write(beads); stopTimingsSection("RingPolymerRestartFileOutput"); } @@ -565,4 +562,4 @@ RingPolymerEnergyOutput &EngineOutput::getRingPolymerEnergyOutput() * * @return TimingsOutput */ -TimingsOutput &EngineOutput::getTimingsOutput() { return *_timingsOutput; } \ No newline at end of file +TimingsOutput &EngineOutput::getTimingsOutput() { return *_timingsOutput; } diff --git a/src/engine/engine_kokkos.cpp b/src/engine/engine_kokkos.cpp index d36de02e8..4a9a02f18 100644 --- a/src/engine/engine_kokkos.cpp +++ b/src/engine/engine_kokkos.cpp @@ -20,14 +20,14 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "engine.hpp" using namespace engine; using namespace simulationBox; using namespace potential; -#ifdef WITH_KOKKOS - /** * @brief get reference to KokkosSimulationBox * @@ -116,4 +116,4 @@ void Engine::initKokkosCoulombWolf( */ void Engine::initKokkosPotential() { _kokkosPotential = KokkosPotential(); } -#endif \ No newline at end of file +#endif diff --git a/src/engine/hessianEngine.cpp b/src/engine/hessianEngine.cpp index 6c319680f..c9b28d0da 100644 --- a/src/engine/hessianEngine.cpp +++ b/src/engine/hessianEngine.cpp @@ -44,10 +44,9 @@ #include "progressbar.hpp" #include "referencesOutput.hpp" #include "settings.hpp" -#include "steepestDescent.hpp" #include "stdoutOutput.hpp" +#include "steepestDescent.hpp" #include "timingsSettings.hpp" -#include "timingsOutput.hpp" using namespace engine; using namespace opt; @@ -66,7 +65,7 @@ void HessianEngine::run() runOptimization(); } - auto builder = setupHessianBuilder(); + auto builder = setupHessianBuilder(); const auto hessian = builder->build(*evaluator, *_simulationBox); @@ -121,7 +120,7 @@ pq::SharedHessianBuilder HessianEngine::setupHessianBuilder() const void HessianEngine::setupOptimization(const pq::SharedEvaluator &evaluator) { - _evaluator = evaluator; + _evaluator = evaluator; _learningRateStrategy = setupLearningRateStrategy(); _optimizer = setupEmptyOptimizer(); @@ -162,10 +161,12 @@ void HessianEngine::runOptimization() } if (!_converged) - throw OptException(std::format( - "Optimizer did not converge after {} epochs.", - _optimizer->getNEpochs() - )); + throw OptException( + std::format( + "Optimizer did not converge after {} epochs.", + _optimizer->getNEpochs() + ) + ); if (_optStopped) { @@ -420,12 +421,14 @@ void HessianEngine::setupMinMaxLearningRate( const auto maxLR = OptimizerSettings::getMaxLearningRate(); if (maxLR.has_value() && minLR >= maxLR.value()) - throw UserInputException(std::format( - "The minimum learning rate {} is greater or equal to the " - "maximum learning rate {}, which is not allowed.", - minLR, - maxLR.value() - )); + throw UserInputException( + std::format( + "The minimum learning rate {} is greater or equal to the " + "maximum learning rate {}, which is not allowed.", + minLR, + maxLR.value() + ) + ); learningRate->setMinLearningRate(minLR); learningRate->setMaxLearningRate(maxLR); @@ -433,18 +436,24 @@ void HessianEngine::setupMinMaxLearningRate( void HessianEngine::writeOptimizationSetupInfo() { - _engineOutput.getLogOutput().writeSetupInfo(std::format( - "Optimize before Hessian: {}", - HessianSettings::optimizeBeforeHessian() ? "true" : "false" - )); - _engineOutput.getLogOutput().writeSetupInfo(std::format( - "Optimizer: {}", - string(OptimizerSettings::getOptimizer()) - )); - _engineOutput.getLogOutput().writeSetupInfo(std::format( - "Learning rate strategy: {}", - string(OptimizerSettings::getLearningRateStrategy()) - )); + _engineOutput.getLogOutput().writeSetupInfo( + std::format( + "Optimize before Hessian: {}", + HessianSettings::optimizeBeforeHessian() ? "true" : "false" + ) + ); + _engineOutput.getLogOutput().writeSetupInfo( + std::format( + "Optimizer: {}", + string(OptimizerSettings::getOptimizer()) + ) + ); + _engineOutput.getLogOutput().writeSetupInfo( + std::format( + "Learning rate strategy: {}", + string(OptimizerSettings::getLearningRateStrategy()) + ) + ); _engineOutput.getLogOutput().writeEmptyLine(); } @@ -453,9 +462,7 @@ void HessianEngine::writeHessian(const pq::HessianMatrix &hessian) const std::ofstream file(HessianSettings::getHessianFile()); if (file.fail()) - throw UserInputException( - "Could not open Hessian file for writing." - ); + throw UserInputException("Could not open Hessian file for writing."); file << std::scientific << std::setprecision(16); diff --git a/src/engine/ringPolymerEngine.cpp b/src/engine/ringPolymerEngine.cpp index 3acd13cf1..67590260a 100644 --- a/src/engine/ringPolymerEngine.cpp +++ b/src/engine/ringPolymerEngine.cpp @@ -75,7 +75,7 @@ void RingPolymerEngine::writeOutput() _engineOutput.writeChargeFile(*_simulationBox); _engineOutput.writeRstFile(*_simulationBox, *_thermostat, effStep); - _engineOutput.writeRingPolymerRstFile(_ringPolymerBeads, effStep); + _engineOutput.writeRingPolymerRstFile(_ringPolymerBeads); _engineOutput.writeRingPolymerXyzFile(_ringPolymerBeads); _engineOutput.writeRingPolymerVelFile(_ringPolymerBeads); _engineOutput.writeRingPolymerForceFile(_ringPolymerBeads); diff --git a/src/forceField/forceFieldClass.cpp b/src/forceField/forceFieldClass.cpp index 1aeee3257..535b6f72e 100644 --- a/src/forceField/forceFieldClass.cpp +++ b/src/forceField/forceFieldClass.cpp @@ -298,8 +298,8 @@ void ForceField::calculateImproperDihedralInteractions( * @param physicalData */ void ForceField::calculateJCouplingInteractions( - const SimulationBox &box, - PhysicalData &physicalData + const SimulationBox & /*box*/, + PhysicalData & /*physicalData*/ ) { if (!_jCouplings.empty()) @@ -618,4 +618,4 @@ const std::vector &ForceField::getImproperTypes() const const std::vector &ForceField::getJCouplTypes() const { return _jCouplingTypes; -} \ No newline at end of file +} diff --git a/src/input/parameterFileReader/parameterFileReader.cpp b/src/input/parameterFileReader/parameterFileReader.cpp index 116132157..65bdb797b 100644 --- a/src/input/parameterFileReader/parameterFileReader.cpp +++ b/src/input/parameterFileReader/parameterFileReader.cpp @@ -68,6 +68,8 @@ ParameterFileReader::ParameterFileReader( _parameterFileSections.push_back(make_unique()); } +ParameterFileReader::~ParameterFileReader() = default; + /** * @brief determines which section of the parameter file the header line belongs * to @@ -86,7 +88,8 @@ ParameterFileSection *ParameterFileReader::determineSection( const auto iterEnd = _parameterFileSections.end(); for (auto section = iterStart; section != iterEnd; ++section) - if ((*section)->keyword() == toLowerAndReplaceDashesCopy(lineElements[0])) + if ((*section)->keyword() == + toLowerAndReplaceDashesCopy(lineElements[0])) return (*section).get(); throw ParameterFileException( @@ -219,4 +222,4 @@ std::vector> &ParameterFileReader:: const std::string &ParameterFileReader::getFilename() const { return _fileName; -} \ No newline at end of file +} diff --git a/src/manostat/manostat.cpp b/src/manostat/manostat.cpp index 789b10055..afaacaa65 100644 --- a/src/manostat/manostat.cpp +++ b/src/manostat/manostat.cpp @@ -22,8 +22,6 @@ #include "manostat.hpp" -#include // for function - #include "constants/internalConversionFactors.hpp" // for _PRESSURE_FACTOR_ #include "manostatSettings.hpp" // for ManostatType, Isotropy #include "physicalData.hpp" // for PhysicalData @@ -72,7 +70,8 @@ void Manostat::calculatePressure(const SimulationBox &box, PhysicalData &data) * @brief rotate mu back into upper diagonal space * * @details first order approximation of mu rotation according to gromacs - * @link https://manual.gromacs.org/current/reference-manual/algorithms/molecular-dynamics.html + * @link + * https://manual.gromacs.org/current/reference-manual/algorithms/molecular-dynamics.html * * @param mu */ @@ -113,4 +112,4 @@ ManostatType Manostat::getManostatType() const { return ManostatType::NONE; } * * @return Isotropy */ -Isotropy Manostat::getIsotropy() const { return Isotropy::NONE; } \ No newline at end of file +Isotropy Manostat::getIsotropy() const { return Isotropy::NONE; } diff --git a/src/mpi/mpi.cpp b/src/mpi/mpi.cpp index 193f1aee4..d4650b656 100644 --- a/src/mpi/mpi.cpp +++ b/src/mpi/mpi.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_MPI + #include "mpi.hpp" #include // for MPI_Comm_rank, MPI_Comm_size, MPI_Init, MPI_Finalize @@ -145,4 +147,6 @@ size_t MPI::getRank() { return _rank; } * * @return size_t */ -size_t MPI::getSize() { return _size; } \ No newline at end of file +size_t MPI::getSize() { return _size; } + +#endif // WITH_MPI diff --git a/src/opt/evaluator/hessianBuilder.cpp b/src/opt/evaluator/hessianBuilder.cpp index ff5238888..83519dee1 100644 --- a/src/opt/evaluator/hessianBuilder.cpp +++ b/src/opt/evaluator/hessianBuilder.cpp @@ -27,7 +27,6 @@ #include "atom.hpp" #include "evaluator.hpp" #include "exceptions.hpp" -#include "simulationBox.hpp" using namespace opt; using namespace settings; @@ -41,10 +40,10 @@ ForceDifferenceHessianBuilder::ForceDifferenceHessianBuilder( } std::vector ForceDifferenceHessianBuilder::evaluateForces( - Evaluator &evaluator, - pq::SimBox &simulationBox, - const size_t coordinateIndex, - const double displacement + Evaluator &evaluator, + pq::SimBox &simulationBox, + const size_t coordinateIndex, + const double displacement ) const { displaceCoordinate(simulationBox, coordinateIndex, displacement); @@ -65,15 +64,15 @@ void ForceDifferenceHessianBuilder::restorePositions( } void ForceDifferenceHessianBuilder::displaceCoordinate( - pq::SimBox &simulationBox, - const size_t coordinateIndex, - const double displacement + pq::SimBox &simulationBox, + const size_t coordinateIndex, + const double displacement ) { const auto atomIndex = coordinateIndex / 3; const auto dimension = coordinateIndex % 3; - auto position = simulationBox.getAtom(atomIndex).getPosition(); + auto position = simulationBox.getAtom(atomIndex).getPosition(); position[dimension] += displacement; simulationBox.getAtom(atomIndex).setPosition(position); @@ -101,19 +100,19 @@ void ForceDifferenceHessianBuilder::symmetrize(pq::HessianMatrix &hessian) for (size_t row = 0; row < hessian.size(); ++row) for (size_t col = row + 1; col < hessian.size(); ++col) { - const auto value = 0.5 * (hessian[row][col] + hessian[col][row]); + const auto value = 0.5 * (hessian[row][col] + hessian[col][row]); hessian[row][col] = value; hessian[col][row] = value; } } pq::HessianMatrix CentralForceDifferenceHessianBuilder::build( - Evaluator &evaluator, - pq::SimBox &simulationBox + Evaluator &evaluator, + pq::SimBox &simulationBox ) const { const auto numberOfCoordinates = 3 * simulationBox.getNumberOfAtoms(); - auto hessian = pq::HessianMatrix( + auto hessian = pq::HessianMatrix( numberOfCoordinates, std::vector(numberOfCoordinates, 0.0) ); @@ -128,8 +127,8 @@ pq::HessianMatrix CentralForceDifferenceHessianBuilder::build( evaluateForces(evaluator, simulationBox, col, -_displacement); for (size_t row = 0; row < numberOfCoordinates; ++row) - hessian[row][col] = -(fPlus[row] - fMinus[row]) / - (2.0 * _displacement); + hessian[row][col] = + -(fPlus[row] - fMinus[row]) / (2.0 * _displacement); restorePositions(simulationBox, originalPositions); } @@ -141,12 +140,12 @@ pq::HessianMatrix CentralForceDifferenceHessianBuilder::build( } pq::HessianMatrix ForwardForceDifferenceHessianBuilder::build( - Evaluator &evaluator, - pq::SimBox &simulationBox + Evaluator &evaluator, + pq::SimBox &simulationBox ) const { const auto numberOfCoordinates = 3 * simulationBox.getNumberOfAtoms(); - auto hessian = pq::HessianMatrix( + auto hessian = pq::HessianMatrix( numberOfCoordinates, std::vector(numberOfCoordinates, 0.0) ); @@ -173,12 +172,12 @@ pq::HessianMatrix ForwardForceDifferenceHessianBuilder::build( } pq::HessianMatrix FivePointForceDifferenceHessianBuilder::build( - Evaluator &evaluator, - pq::SimBox &simulationBox + Evaluator &evaluator, + pq::SimBox &simulationBox ) const { const auto numberOfCoordinates = 3 * simulationBox.getNumberOfAtoms(); - auto hessian = pq::HessianMatrix( + auto hessian = pq::HessianMatrix( numberOfCoordinates, std::vector(numberOfCoordinates, 0.0) ); @@ -198,10 +197,9 @@ pq::HessianMatrix FivePointForceDifferenceHessianBuilder::build( for (size_t row = 0; row < numberOfCoordinates; ++row) { - const auto derivative = ( - -fPlus2[row] + 8.0 * fPlus[row] - 8.0 * fMinus[row] + - fMinus2[row] - ) / (12.0 * _displacement); + const auto derivative = (-fPlus2[row] + 8.0 * fPlus[row] - + 8.0 * fMinus[row] + fMinus2[row]) / + (12.0 * _displacement); hessian[row][col] = -derivative; } @@ -216,8 +214,8 @@ pq::HessianMatrix FivePointForceDifferenceHessianBuilder::build( } pq::HessianMatrix AnalyticHessianBuilder::build( - Evaluator &evaluator, - pq::SimBox & + Evaluator &evaluator, + pq::SimBox & ) const { if (!evaluator.supportsAnalyticHessian()) diff --git a/src/output/ringPolymerRestartFileOutput.cpp b/src/output/ringPolymerRestartFileOutput.cpp index 03074ba92..95afc1ebf 100644 --- a/src/output/ringPolymerRestartFileOutput.cpp +++ b/src/output/ringPolymerRestartFileOutput.cpp @@ -41,10 +41,7 @@ using namespace settings; * @param simBox * @param step */ -void RingPolymerRestartFileOutput::write( - std::vector &beads, - const size_t step -) +void RingPolymerRestartFileOutput::write(std::vector &beads) { std::ostringstream buffer; @@ -88,4 +85,4 @@ void RingPolymerRestartFileOutput::write( // Write the buffer to the file _fp << buffer.str(); _fp << std::flush; -} \ No newline at end of file +} diff --git a/src/potential/coulomb_kokkos/coulombWolf_kokkos.cpp b/src/potential/coulomb_kokkos/coulombWolf_kokkos.cpp index d36489e50..8a7a0127e 100644 --- a/src/potential/coulomb_kokkos/coulombWolf_kokkos.cpp +++ b/src/potential/coulomb_kokkos/coulombWolf_kokkos.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "coulombWolf_kokkos.hpp" using namespace potential; @@ -120,4 +122,6 @@ double KokkosCoulombWolf::calculate( View KokkosCoulombWolf::getCoulombRadiusCutOff() const { return _coulombRadiusCutOff.d_view; -} \ No newline at end of file +} + +#endif // WITH_KOKKOS diff --git a/src/potential/nonCoulomb_kokkos/lennardJones_kokkos.cpp b/src/potential/nonCoulomb_kokkos/lennardJones_kokkos.cpp index 015ae51ec..d7acf6372 100644 --- a/src/potential/nonCoulomb_kokkos/lennardJones_kokkos.cpp +++ b/src/potential/nonCoulomb_kokkos/lennardJones_kokkos.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "lennardJones_kokkos.hpp" #include "lennardJonesPair.hpp" @@ -225,4 +227,6 @@ double KokkosLennardJones::getC6(const size_t i, const size_t j) const double KokkosLennardJones::getC12(const size_t i, const size_t j) const { return _c12.d_view(i, j); -} \ No newline at end of file +} + +#endif // WITH_KOKKOS diff --git a/src/potential/potential_kokkos.cpp b/src/potential/potential_kokkos.cpp index 22f7cbb69..4a51944c4 100644 --- a/src/potential/potential_kokkos.cpp +++ b/src/potential/potential_kokkos.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "potential_kokkos.hpp" #include // for size_t @@ -189,3 +191,5 @@ void KokkosPotential::calculateForces( stopTimingsSection("InterNonBonded - Transfer"); } + +#endif // WITH_KOKKOS diff --git a/src/python/selection.cpp b/src/python/selection.cpp index 7838d7d24..c06cb89ee 100644 --- a/src/python/selection.cpp +++ b/src/python/selection.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_WITH_PYTHON_BINDINGS + #include "selection.hpp" #include @@ -135,4 +137,6 @@ std::vector pq_python::select( ::Py_Finalize(); return result; -} \ No newline at end of file +} + +#endif // WITH_WITH_PYTHON_BINDINGS diff --git a/src/setup/kokkosSetup.cpp b/src/setup/kokkosSetup.cpp index a9934a242..7e545b703 100644 --- a/src/setup/kokkosSetup.cpp +++ b/src/setup/kokkosSetup.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "kokkosSetup.hpp" #include @@ -58,7 +60,7 @@ void setup::setupKokkos(Engine &engine) * * @param engine */ -KokkosSetup::KokkosSetup(Engine &engine) : _engine(engine){}; +KokkosSetup::KokkosSetup(Engine &engine) : _engine(engine) {} /** * @brief setup Kokkos @@ -135,4 +137,6 @@ void KokkosSetup::setup() wolfPotential.getWolfParameter3(), _COULOMB_PREFACTOR_ ); -} \ No newline at end of file +} + +#endif // WITH_KOKKOS diff --git a/src/setup/outputFilesSetup.cpp b/src/setup/outputFilesSetup.cpp index 66ea7b119..c2281cc41 100644 --- a/src/setup/outputFilesSetup.cpp +++ b/src/setup/outputFilesSetup.cpp @@ -123,19 +123,21 @@ void OutputFilesSetup::setup() if (Settings::isRingPolymerMDActivated()) { - const auto RstFile = OutputFileSettings::getRPMDRestartFileName(); - const auto xyzFile = OutputFileSettings::getRPMDTrajFileName(); - const auto velFile = OutputFileSettings::getRPMDVelocityFileName(); - const auto forceFile = OutputFileSettings::getRPMDForceFileName(); - const auto chargeFile = OutputFileSettings::getRPMDChargeFileName(); - const auto energyFile = OutputFileSettings::getRPMDEnergyFileName(); - - mdEngine.getRingPolymerRstFileOutput().setFilename(RstFile); - mdEngine.getRingPolymerXyzOutput().setFilename(xyzFile); - mdEngine.getRingPolymerVelOutput().setFilename(velFile); - mdEngine.getRingPolymerForceOutput().setFilename(forceFile); - mdEngine.getRingPolymerChargeOutput().setFilename(chargeFile); - mdEngine.getRingPolymerEnergyOutput().setFilename(energyFile); + const auto rstFile_ = OutputFileSettings::getRPMDRestartFileName(); + const auto xyzFile_ = OutputFileSettings::getRPMDTrajFileName(); + const auto velFile_ = OutputFileSettings::getRPMDVelocityFileName(); + const auto forceFile_ = OutputFileSettings::getRPMDForceFileName(); + const auto chargeFile_ = + OutputFileSettings::getRPMDChargeFileName(); + const auto energyFile_ = + OutputFileSettings::getRPMDEnergyFileName(); + + mdEngine.getRingPolymerRstFileOutput().setFilename(rstFile_); + mdEngine.getRingPolymerXyzOutput().setFilename(xyzFile_); + mdEngine.getRingPolymerVelOutput().setFilename(velFile_); + mdEngine.getRingPolymerForceOutput().setFilename(forceFile_); + mdEngine.getRingPolymerChargeOutput().setFilename(chargeFile_); + mdEngine.getRingPolymerEnergyOutput().setFilename(energyFile_); } } diff --git a/src/setup/ringPolymerSetup.cpp b/src/setup/ringPolymerSetup.cpp index b6df636ca..34186c2ef 100644 --- a/src/setup/ringPolymerSetup.cpp +++ b/src/setup/ringPolymerSetup.cpp @@ -22,11 +22,9 @@ #include "ringPolymerSetup.hpp" -#include // for __for_each_fn, for_each -#include // for size_t -#include // for string_view +#include // for __for_each_fn, for_each +#include // for size_t -#include "exceptions.hpp" // for InputFileException #include "fileSettings.hpp" // for FileSettings #include "maxwellBoltzmann.hpp" // for MaxwellBoltzmann #include "ringPolymerEngine.hpp" // for RingPolymerEngine @@ -78,8 +76,9 @@ void setup::setupRingPolymer(Engine &engine) * * @param engine */ -RingPolymerSetup::RingPolymerSetup(RingPolymerEngine &engine) - : _engine(engine){}; +RingPolymerSetup::RingPolymerSetup(RingPolymerEngine &engine) : _engine(engine) +{ +} /** * @brief setup a ring polymer simulation diff --git a/src/setup/setup.cpp b/src/setup/setup.cpp index f601b0791..a32f587cb 100644 --- a/src/setup/setup.cpp +++ b/src/setup/setup.cpp @@ -32,7 +32,6 @@ #include "inputFileReader.hpp" // for readInputFile #include "intraNonBondedReader.hpp" // for readIntraNonBondedFile #include "intraNonBondedSetup.hpp" // for setupIntraNonBonded -#include "kokkosSetup.hpp" // for setupKokkos #include "manostatSetup.hpp" // for setupManostat #include "moldescriptorReader.hpp" // for readMolDescriptor #include "optimizerSetup.hpp" // for setupOptimizer @@ -50,6 +49,10 @@ #include "timer.hpp" // for Timings #include "topologyReader.hpp" // for readTopologyFile +#ifdef WITH_KOKKOS +#include "kokkosSetup.hpp" // for setupKokkos +#endif + using namespace engine; using namespace input; using namespace timings; diff --git a/src/setup/simulationBoxSetup.cpp b/src/setup/simulationBoxSetup.cpp index cfcf2f6d0..11651bec2 100644 --- a/src/setup/simulationBoxSetup.cpp +++ b/src/setup/simulationBoxSetup.cpp @@ -118,7 +118,7 @@ void SimulationBoxSetup::setAtomNames() { auto &simBox = _engine.getSimulationBox(); - auto setAtomNamesOfMolecule = [this, &simBox](auto &molecule) + auto setAtomNamesOfMolecule = [&simBox](auto &molecule) { const auto &molType = molecule.getMoltype(); if (molType == 0) @@ -149,7 +149,7 @@ void SimulationBoxSetup::setAtomTypes() { auto &simBox = _engine.getSimulationBox(); - auto setAtomTypesOfMolecule = [this, &simBox](auto &molecule) + auto setAtomTypesOfMolecule = [&simBox](auto &molecule) { const auto &molType = molecule.getMoltype(); @@ -178,7 +178,7 @@ void SimulationBoxSetup::setExternalVDWTypes() { auto &simBox = _engine.getSimulationBox(); - auto setExternalVDWTypesOfMolecule = [this, &simBox](auto &molecule) + auto setExternalVDWTypesOfMolecule = [&simBox](auto &molecule) { const auto &molType = molecule.getMoltype(); @@ -223,7 +223,7 @@ void SimulationBoxSetup::setPartialCharges() { auto &simBox = _engine.getSimulationBox(); - auto setPartialChargesOfMolecule = [this, &simBox](auto &molecule) + auto setPartialChargesOfMolecule = [&simBox](auto &molecule) { const auto &molType = molecule.getMoltype(); diff --git a/src/simulationBox/simulationBox_kokkos.cpp b/src/simulationBox/simulationBox_kokkos.cpp index 3254647ca..639363e3e 100644 --- a/src/simulationBox/simulationBox_kokkos.cpp +++ b/src/simulationBox/simulationBox_kokkos.cpp @@ -20,6 +20,8 @@ ******************************************************************************/ +#ifdef WITH_KOKKOS + #include "simulationBox_kokkos.hpp" #include "simulationBox.hpp" // for SimulationBox @@ -298,7 +300,8 @@ void KokkosSimulationBox::transferBoxDimensionsFromSimulationBox( /** * @brief transfer positions to simulation box */ -void KokkosSimulationBox::transferPositionsToSimulationBox(SimulationBox& simBox +void KokkosSimulationBox::transferPositionsToSimulationBox( + SimulationBox& simBox ) { // copy positions back to host @@ -493,4 +496,6 @@ DualView& KokkosSimulationBox::getPartialCharges() DualView KokkosSimulationBox::getBoxDimensions() { return _boxDimensions; -} \ No newline at end of file +} + +#endif // WITH_KOKKOS diff --git a/tests/include/input/testRestartFileSection.hpp b/tests/include/input/testRestartFileSection.hpp index 202ccaf35..92a490836 100644 --- a/tests/include/input/testRestartFileSection.hpp +++ b/tests/include/input/testRestartFileSection.hpp @@ -22,12 +22,12 @@ #include -#include "atomSection.hpp" -#include "boxSection.hpp" #include "mmmdEngine.hpp" -#include "noseHooverSection.hpp" -#include "restartFileSection.hpp" -#include "stepCountSection.hpp" +#include "restartFileReader/atomSection.hpp" +#include "restartFileReader/boxSection.hpp" +#include "restartFileReader/noseHooverSection.hpp" +#include "restartFileReader/restartFileSection.hpp" +#include "restartFileReader/stepCountSection.hpp" /** * @class TestBoxSection @@ -127,4 +127,4 @@ class TestAtomSection : public ::testing::Test input::restartFile::RestartFileSection *_section; engine::Engine *_engine; -}; \ No newline at end of file +}; diff --git a/tests/include/testUtils/testUtils.hpp b/tests/include/testUtils/testUtils.hpp new file mode 100644 index 000000000..1e2468f53 --- /dev/null +++ b/tests/include/testUtils/testUtils.hpp @@ -0,0 +1,37 @@ +/***************************************************************************** + + + PQ + Copyright (C) 2023-now Jakob Gamper + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + +******************************************************************************/ + +#ifndef _TEST_UTILS_HPP_ + +#define _TEST_UTILS_HPP_ + +#include + +#include + +namespace test +{ + template + void checkType(const T& obj, const std::type_info& expectedType); +} // namespace test + +#endif // _TEST_UTILS_HPP_ diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index 8eed268f8..fdd7b280d 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -21,4 +21,5 @@ add_subdirectory(box) add_subdirectory(kernels) add_subdirectory(opt) add_subdirectory(main) -add_subdirectory(randomNumberGenerator) \ No newline at end of file +add_subdirectory(randomNumberGenerator) +add_subdirectory(testUtils) diff --git a/tests/src/constraints/testBondConstraint.cpp b/tests/src/constraints/testBondConstraint.cpp index b3e87a110..d3c2fb5ff 100644 --- a/tests/src/constraints/testBondConstraint.cpp +++ b/tests/src/constraints/testBondConstraint.cpp @@ -22,8 +22,6 @@ #include "testBondConstraint.hpp" -#include // for string - #include "constants/conversionFactors.hpp" #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult #include "timingsSettings.hpp" @@ -131,4 +129,4 @@ TEST_F(TestBondConstraint, applyRattle) ); EXPECT_TRUE(_bondConstraint->applyRattle(1000.0)); -} \ No newline at end of file +} diff --git a/tests/src/constraints/testConstraints.cpp b/tests/src/constraints/testConstraints.cpp index f51325fb2..ee9cb1b81 100644 --- a/tests/src/constraints/testConstraints.cpp +++ b/tests/src/constraints/testConstraints.cpp @@ -22,8 +22,6 @@ #include "testConstraints.hpp" -#include // for basic_string - #include "exceptions.hpp" // for ShakeException #include "gmock/gmock.h" // for DoubleNear, ElementsAre, MakePredica... #include "gtest/gtest.h" // for Message, TestPartResult, InitGoogleTest @@ -228,4 +226,4 @@ TEST_F(TestConstraints, isActivated) _constraints->activateDistanceConstraints(); EXPECT_TRUE(_constraints->isActive()); EXPECT_TRUE(_constraints->isDistanceConstraintsActive()); -} \ No newline at end of file +} diff --git a/tests/src/forceField/testAngleType.cpp b/tests/src/forceField/testAngleType.cpp index 73e7be698..85721f164 100644 --- a/tests/src/forceField/testAngleType.cpp +++ b/tests/src/forceField/testAngleType.cpp @@ -22,8 +22,6 @@ #include // for Test, EXPECT_FALSE, InitGoogleTest, RUN_ALL... -#include // for allocator, string - #include "angleType.hpp" // for AngleType #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult @@ -43,4 +41,4 @@ TEST(TestAngleType, operatorEqual) EXPECT_FALSE(angleType1 == angleType3); EXPECT_FALSE(angleType1 == angleType4); EXPECT_FALSE(angleType1 == angleType5); -} \ No newline at end of file +} diff --git a/tests/src/forceField/testBondType.cpp b/tests/src/forceField/testBondType.cpp index 10773a875..1a9ed45eb 100644 --- a/tests/src/forceField/testBondType.cpp +++ b/tests/src/forceField/testBondType.cpp @@ -22,8 +22,6 @@ #include // for Test, EXPECT_FALSE, InitGoogleTest, RUN_ALL... -#include // for allocator, string - #include "bondType.hpp" // for BondType #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult @@ -43,4 +41,4 @@ TEST(TestBondType, operatorEqual) EXPECT_FALSE(bondType1 == bondType3); EXPECT_FALSE(bondType1 == bondType4); EXPECT_FALSE(bondType1 == bondType5); -} \ No newline at end of file +} diff --git a/tests/src/forceField/testDihedralType.cpp b/tests/src/forceField/testDihedralType.cpp index 065369010..db61280b7 100644 --- a/tests/src/forceField/testDihedralType.cpp +++ b/tests/src/forceField/testDihedralType.cpp @@ -22,8 +22,6 @@ #include // for Test, EXPECT_FALSE, InitGoogleTest, RUN_... -#include // for allocator, string - #include "dihedralType.hpp" // for DihedralType #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult @@ -45,4 +43,4 @@ TEST(TestDihedralType, operatorEqual) EXPECT_FALSE(dihedralType1 == dihedralType4); EXPECT_FALSE(dihedralType1 == dihedralType5); EXPECT_FALSE(dihedralType1 == dihedralType6); -} \ No newline at end of file +} diff --git a/tests/src/input/CMakeLists.txt b/tests/src/input/CMakeLists.txt index 1132c4694..9a1c60e14 100644 --- a/tests/src/input/CMakeLists.txt +++ b/tests/src/input/CMakeLists.txt @@ -14,6 +14,7 @@ foreach(source_file ${source_files}) add_executable(${test_name} ${source_file}) target_include_directories(${test_name} PRIVATE + ${PROJECT_SOURCE_DIR}/include/input/ ${PROJECT_SOURCE_DIR}/tests/include/input ${PROJECT_SOURCE_DIR}/tests/include/macros ) @@ -26,6 +27,7 @@ foreach(source_file ${source_files}) gtest gmock pq_test_main + testUtils ) add_test( NAME ${test_name} diff --git a/tests/src/input/inputFileParsing/CMakeLists.txt b/tests/src/input/inputFileParsing/CMakeLists.txt index cdb9c8268..c40961192 100644 --- a/tests/src/input/inputFileParsing/CMakeLists.txt +++ b/tests/src/input/inputFileParsing/CMakeLists.txt @@ -38,6 +38,7 @@ foreach(source_file ${source_files}) gtest gmock pq_test_main + testUtils ) add_test( NAME ${test_name} diff --git a/tests/src/input/inputFileParsing/testConvergenceParser.cpp b/tests/src/input/inputFileParsing/testConvergenceParser.cpp index 7cf4c036e..d34fae655 100644 --- a/tests/src/input/inputFileParsing/testConvergenceParser.cpp +++ b/tests/src/input/inputFileParsing/testConvergenceParser.cpp @@ -22,8 +22,6 @@ #include // for TEST_F, EXPECT_EQ, RUN_ALL_TESTS -#include // for string, allocator - #include "convergenceInputParser.hpp" // for InputFileParserOptimizer #include "convergenceSettings.hpp" // for ConvSettings #include "exceptions.hpp" // for InputFileException, customException @@ -285,4 +283,4 @@ TEST_F(TestInputFileReader, parserRMSForceConvergence) "RMS force convergence must be greater than 0.0 in input file at " "line 0." ) -} \ No newline at end of file +} diff --git a/tests/src/input/inputFileParsing/testCoulombLongRangeParser.cpp b/tests/src/input/inputFileParsing/testCoulombLongRangeParser.cpp index 14ffc3f61..19e6dd4bb 100644 --- a/tests/src/input/inputFileParsing/testCoulombLongRangeParser.cpp +++ b/tests/src/input/inputFileParsing/testCoulombLongRangeParser.cpp @@ -22,8 +22,6 @@ #include // for TestInfo (ptr only) -#include // for string, allocator - #include "coulombLongRangeInputParser.hpp" #include "exceptions.hpp" // for InputFileException #include "gtest/gtest.h" // for Message, TestPartResult @@ -120,4 +118,4 @@ TEST_F(TestInputFileReader, testParseReactionFieldEpsilon) "Static relative permittivity \"rf_epsilon\" cannot be lower than " "1.0" ); -} \ No newline at end of file +} diff --git a/tests/src/input/inputFileParsing/testGeneralParser.cpp b/tests/src/input/inputFileParsing/testGeneralParser.cpp index ff41185a4..7e8f53696 100644 --- a/tests/src/input/inputFileParsing/testGeneralParser.cpp +++ b/tests/src/input/inputFileParsing/testGeneralParser.cpp @@ -37,7 +37,8 @@ #include "ringPolymerqmmdEngine.hpp" // for RingPolymerQMMDEngine #include "settings.hpp" // for Settings #include "testInputFileReader.hpp" // for TestInputFileReader -#include "throwWithMessage.hpp" // for EXPECT_THROW_MSG +#include "testUtils.hpp" +#include "throwWithMessage.hpp" // for EXPECT_THROW_MSG using namespace input; using namespace settings; @@ -57,33 +58,33 @@ TEST_F(TestInputFileReader, JobType) parser.parseJobTypeForEngine(lineElements, 0, engine); EXPECT_EQ(Settings::getJobtype(), JobType::MM_MD); EXPECT_EQ(Settings::isMMActivated(), true); - EXPECT_EQ(typeid(*engine), typeid(engine::MMMDEngine)); + test::checkType(engine, typeid(engine::MMMDEngine)); lineElements = {"jobtype", "=", "qm-md"}; parser.parseJobTypeForEngine(lineElements, 0, engine); EXPECT_EQ(Settings::getJobtype(), JobType::QM_MD); EXPECT_EQ(Settings::isQMActivated(), true); - EXPECT_EQ(typeid(*engine), typeid(engine::QMMDEngine)); + test::checkType(engine, typeid(engine::QMMDEngine)); lineElements = {"jobtype", "=", "qm-rpmd"}; parser.parseJobTypeForEngine(lineElements, 0, engine); EXPECT_EQ(Settings::getJobtype(), JobType::RING_POLYMER_QM_MD); EXPECT_EQ(Settings::isQMActivated(), true); EXPECT_EQ(Settings::isRingPolymerMDActivated(), true); - EXPECT_EQ(typeid(*engine), typeid(engine::RingPolymerQMMDEngine)); + test::checkType(engine, typeid(engine::RingPolymerQMMDEngine)); lineElements = {"jobtype", "=", "mm-opt"}; parser.parseJobTypeForEngine(lineElements, 0, engine); EXPECT_EQ(Settings::getJobtype(), JobType::MM_OPT); EXPECT_EQ(Settings::isOptJobType(), true); EXPECT_EQ(Settings::isMMActivated(), true); - EXPECT_EQ(typeid(*engine), typeid(engine::OptEngine)); + test::checkType(engine, typeid(engine::OptEngine)); lineElements = {"jobtype", "=", "mm-hessian"}; parser.parseJobTypeForEngine(lineElements, 0, engine); EXPECT_EQ(Settings::getJobtype(), JobType::MM_HESSIAN); EXPECT_EQ(Settings::isMMActivated(), true); - EXPECT_EQ(typeid(*engine), typeid(engine::HessianEngine)); + test::checkType(engine, typeid(engine::HessianEngine)); lineElements = {"jobtype", "=", "notValid"}; EXPECT_THROW_MSG( diff --git a/tests/src/input/inputFileParsing/testInputFileParser.cpp b/tests/src/input/inputFileParsing/testInputFileParser.cpp index cb283803f..27b85640d 100644 --- a/tests/src/input/inputFileParsing/testInputFileParser.cpp +++ b/tests/src/input/inputFileParsing/testInputFileParser.cpp @@ -22,15 +22,15 @@ #include // for TestInfo (ptr only), EXPECT_EQ -#include // for _Bind_front_t, bind_front -#include // for map -#include // for string, allocator, basic_string -#include // for vector - -#include "exceptions.hpp" // for InputFileException -#include "generalInputParser.hpp" // for InputFileParserGeneral -#include "gtest/gtest.h" // for Message, TestPartResult -#include "inputFileParser.hpp" // for ParseFunc, checkCommand +#include // for map +#include // for string, allocator, basic_string +#include // for vector + +#include "exceptions.hpp" // for InputFileException +#include "generalInputParser.hpp" // for InputFileParserGeneral +#include "gtest/gtest.h" // for Message, TestPartResult +#include "inputFileParser.hpp" // for ParseFunc, checkCommand +#include "parserUtils.hpp" #include "testInputFileReader.hpp" // for TestInputFileReader #include "throwWithMessage.hpp" // for ASSERT_THROW_MSG @@ -114,7 +114,7 @@ TEST_F(TestInputFileReader, addKeyword) parser.addKeyword( "test", - bind_front(&GeneralInputParser::parseJobType, parser), + input::bindMember(&GeneralInputParser::parseJobType, &parser), true ); @@ -126,4 +126,4 @@ TEST_F(TestInputFileReader, addKeyword) EXPECT_EQ(parser.getKeywordRequiredMap().size(), 1 + initialSizeOfMaps); EXPECT_EQ(parser.getKeywordRequiredMap().at("test"), true); -} \ No newline at end of file +} diff --git a/tests/src/input/inputFileParsing/testOptParser.cpp b/tests/src/input/inputFileParsing/testOptParser.cpp index 88cee5a9a..e2e6bc0db 100644 --- a/tests/src/input/inputFileParsing/testOptParser.cpp +++ b/tests/src/input/inputFileParsing/testOptParser.cpp @@ -22,8 +22,6 @@ #include // for TEST_F, EXPECT_EQ, RUN_ALL_TESTS -#include // for string, allocator - #include "exceptions.hpp" // for InputFileException, customException #include "gtest/gtest.h" // for Message, TestPartResult #include "optInputParser.hpp" // for InputFileParserOptimizer @@ -258,4 +256,4 @@ TEST_F(TestInputFileReader, parserMinLearningRate) "Minimum learning rate must be greater than 0.0 in input file at line " "0." ) -} \ No newline at end of file +} diff --git a/tests/src/input/parameterFileReader/testNonCoulombicTypesSection.cpp b/tests/src/input/parameterFileReader/testNonCoulombicTypesSection.cpp index 08a83c042..ba61a61bd 100644 --- a/tests/src/input/parameterFileReader/testNonCoulombicTypesSection.cpp +++ b/tests/src/input/parameterFileReader/testNonCoulombicTypesSection.cpp @@ -22,8 +22,6 @@ #include // for EXPECT_EQ, TestInfo (ptr only) -#include // for string, basic_string - #include "buckinghamPair.hpp" // for BuckinghamPair #include "engine.hpp" // for Engine #include "exceptions.hpp" // for ParameterFileException @@ -203,27 +201,33 @@ TEST_F(TestParameterFileSection, processSectionNonCoulombics) PotentialSettings::setNonCoulombType(NonCoulombType::LJ); nonCoulombicsSection.processSection(lineElements, *_engine); EXPECT_EQ(potential.getNonCoulombPairsVector().size(), 1); - EXPECT_NO_THROW(dynamic_cast( - potential.getNonCoulombPairsVector()[0].get() - )); + EXPECT_NO_THROW( + [[maybe_unused]] auto ret = dynamic_cast( + potential.getNonCoulombPairsVector()[0].get() + ) + ); lineElements = {"0", "1", "1.22", "234.3", "324.3"}; PotentialSettings::setNonCoulombType(NonCoulombType::BUCKINGHAM); EXPECT_NO_THROW(nonCoulombicsSection.processSection(lineElements, *_engine) ); EXPECT_EQ(potential.getNonCoulombPairsVector().size(), 2); - EXPECT_NO_THROW(dynamic_cast( - potential.getNonCoulombPairsVector()[0].get() - )); + EXPECT_NO_THROW( + [[maybe_unused]] auto ret = dynamic_cast( + potential.getNonCoulombPairsVector()[0].get() + ) + ); lineElements = {"0", "1", "1.22", "234.3", "324.3"}; PotentialSettings::setNonCoulombType(NonCoulombType::MORSE); EXPECT_NO_THROW(nonCoulombicsSection.processSection(lineElements, *_engine) ); EXPECT_EQ(potential.getNonCoulombPairsVector().size(), 3); - EXPECT_NO_THROW(dynamic_cast( - potential.getNonCoulombPairsVector()[0].get() - )); + EXPECT_NO_THROW( + [[maybe_unused]] auto ret = dynamic_cast( + potential.getNonCoulombPairsVector()[0].get() + ) + ); lineElements = {"0", "1", "1.22", "234.3", "324.3"}; PotentialSettings::setNonCoulombType(NonCoulombType::LJ_9_12); @@ -243,4 +247,4 @@ TEST_F(TestParameterFileSection, endedNormallyNonCoulombic) ParameterFileException, "Parameter file noncoulombics section ended abnormally!" ); -} \ No newline at end of file +} diff --git a/tests/src/input/restartFileSection/CMakeLists.txt b/tests/src/input/restartFileSection/CMakeLists.txt index 55b1efe7d..745f77d26 100644 --- a/tests/src/input/restartFileSection/CMakeLists.txt +++ b/tests/src/input/restartFileSection/CMakeLists.txt @@ -10,6 +10,7 @@ foreach(source_file ${source_files}) add_executable(${test_name} ${source_file}) target_include_directories(${test_name} PRIVATE + ${PROJECT_SOURCE_DIR}/include/input/ ${PROJECT_SOURCE_DIR}/tests/include/input ${PROJECT_SOURCE_DIR}/tests/include/macros ) @@ -39,4 +40,4 @@ if(${BUILD_WITH_GCOVR}) EXECUTABLE_ARGS "-L;restartFileSection" OUTPUT_PATH "coverage" ) -endif() \ No newline at end of file +endif() diff --git a/tests/src/input/restartFileSection/testAtomSection.cpp b/tests/src/input/restartFileSection/testAtomSection.cpp index cf443df55..6855f1676 100644 --- a/tests/src/input/restartFileSection/testAtomSection.cpp +++ b/tests/src/input/restartFileSection/testAtomSection.cpp @@ -27,15 +27,15 @@ #include // for string, stod, allocator, basic_string #include // for vector -#include "atom.hpp" // for Atom -#include "atomSection.hpp" // for AtomSection -#include "engine.hpp" // for Engine -#include "exceptions.hpp" // for RstFileException, customException -#include "gmock/gmock.h" // for ElementsAre, MakePredicateFormatter -#include "gtest/gtest.h" // for Message, TestPartResult -#include "molecule.hpp" // for Molecule -#include "moleculeType.hpp" // for MoleculeType -#include "restartFileSection.hpp" // for RstFileSection, AtomSection +#include "atom.hpp" // for Atom +#include "engine.hpp" // for Engine +#include "exceptions.hpp" // for RstFileException, customException +#include "gmock/gmock.h" // for ElementsAre, MakePredicateFormatter +#include "gtest/gtest.h" // for Message, TestPartResult +#include "molecule.hpp" // for Molecule +#include "moleculeType.hpp" // for MoleculeType +#include "restartFileReader/atomSection.hpp" +#include "restartFileReader/restartFileSection.hpp" #include "testRestartFileSection.hpp" // for TestAtomSection #include "throwWithMessage.hpp" // for ASSERT_THROW_MSG @@ -261,4 +261,4 @@ TEST_F(TestAtomSection, testProcessQMAtomLine) ); ASSERT_EQ(atoms[0]->getAtomTypeName(), line[0]); -} \ No newline at end of file +} diff --git a/tests/src/input/restartFileSection/testBoxSection.cpp b/tests/src/input/restartFileSection/testBoxSection.cpp index 476e3f9b9..c98169b1e 100644 --- a/tests/src/input/restartFileSection/testBoxSection.cpp +++ b/tests/src/input/restartFileSection/testBoxSection.cpp @@ -20,20 +20,21 @@ ******************************************************************************/ -#include "engine.hpp" // for Engine -#include "exceptions.hpp" // for RstFileException, customException -#include "restartFileSection.hpp" // for RstFileSection, readInput +#include // for TestInfo (ptr only), ASSERT_THROW + +#include // for size_t, std +#include // for string, allocator, basic_string +#include // for vector + +#include "engine.hpp" // for Engine +#include "exceptions.hpp" // for RstFileException, customException +#include "gmock/gmock.h" // for ElementsAre, MakePredicateForma... +#include "gtest/gtest.h" // for Message, TestPartResult, Assert... +#include "restartFileReader/restartFileSection.hpp" #include "settings.hpp" // for Settings #include "simulationBoxSettings.hpp" // for SimulationBoxSettings #include "testRestartFileSection.hpp" // for TestBoxSection -#include "gmock/gmock.h" // for ElementsAre, MakePredicateForma... -#include "gtest/gtest.h" // for Message, TestPartResult, Assert... -#include // for size_t, std -#include // for TestInfo (ptr only), ASSERT_THROW -#include // for string, allocator, basic_string -#include // for vector - using namespace input; TEST_F(TestBoxSection, testKeyword) { EXPECT_EQ(_section->keyword(), "box"); } @@ -46,7 +47,10 @@ TEST_F(TestBoxSection, testNumberOfArguments) if (i != 4 && i != 7) { auto line = std::vector(i); - ASSERT_THROW(_section->process(line, *_engine), customException::RstFileException); + ASSERT_THROW( + _section->process(line, *_engine), + customException::RstFileException + ); } } @@ -58,22 +62,43 @@ TEST_F(TestBoxSection, testProcess) std::vector line = {"box", "1.0", "2.0", "3.0"}; _section->process(line, *_engine); - ASSERT_THAT(_engine->getSimulationBox().getBoxDimensions(), testing::ElementsAre(1.0, 2.0, 3.0)); - ASSERT_THAT(_engine->getSimulationBox().getBoxAngles(), testing::ElementsAre(90.0, 90.0, 90.0)); + ASSERT_THAT( + _engine->getSimulationBox().getBoxDimensions(), + testing::ElementsAre(1.0, 2.0, 3.0) + ); + ASSERT_THAT( + _engine->getSimulationBox().getBoxAngles(), + testing::ElementsAre(90.0, 90.0, 90.0) + ); line = {"box", "1.0", "2.0", "3.0", "90.0", "90.0", "70.0"}; _section->process(line, *_engine); - ASSERT_THAT(_engine->getSimulationBox().getBoxDimensions(), testing::ElementsAre(1.0, 2.0, 3.0)); - ASSERT_THAT(_engine->getSimulationBox().getBoxAngles(), testing::ElementsAre(90.0, 90.0, 70.0)); + ASSERT_THAT( + _engine->getSimulationBox().getBoxDimensions(), + testing::ElementsAre(1.0, 2.0, 3.0) + ); + ASSERT_THAT( + _engine->getSimulationBox().getBoxAngles(), + testing::ElementsAre(90.0, 90.0, 70.0) + ); line = {"box", "1.0", "2.0", "-3.0", "90.0", "90.0", "90.0"}; - ASSERT_THROW(_section->process(line, *_engine), customException::RstFileException); + ASSERT_THROW( + _section->process(line, *_engine), + customException::RstFileException + ); line = {"box", "1.0", "2.0", "3.0", "90.0", "90.0", "190.0"}; - ASSERT_THROW(_section->process(line, *_engine), customException::RstFileException); + ASSERT_THROW( + _section->process(line, *_engine), + customException::RstFileException + ); line = {"box", "1.0", "2.0", "3.0", "90.0", "90.0", "-90.0"}; - ASSERT_THROW(_section->process(line, *_engine), customException::RstFileException); + ASSERT_THROW( + _section->process(line, *_engine), + customException::RstFileException + ); EXPECT_EQ(settings::SimulationBoxSettings::getBoxSet(), true); -} \ No newline at end of file +} diff --git a/tests/src/input/restartFileSection/testNoseHooverSection.cpp b/tests/src/input/restartFileSection/testNoseHooverSection.cpp index 35e135aba..2acbf8ee3 100644 --- a/tests/src/input/restartFileSection/testNoseHooverSection.cpp +++ b/tests/src/input/restartFileSection/testNoseHooverSection.cpp @@ -20,19 +20,4 @@ ******************************************************************************/ -#include // for TestInfo (ptr only), TEST_F, InitG... - -// TEST_F(TestNoseHooverSection, testKeyword) { EXPECT_EQ(_section->keyword(), -// "chi"); } - -// TEST_F(TestNoseHooverSection, testIsHeader) { -// EXPECT_TRUE(_section->isHeader()); } - -// TEST_F(TestNoseHooverSection, testNumberOfArguments) { GTEST_SKIP(); } - -// TEST_F(TestNoseHooverSection, testProcess) -// { -// auto line = std::vector(0); -// ASSERT_THROW(_section->process(line, *_engine), -// customException::RstFileException); -// } \ No newline at end of file +#include diff --git a/tests/src/input/restartFileSection/testStepCountSection.cpp b/tests/src/input/restartFileSection/testStepCountSection.cpp index a1ab24831..efe692b71 100644 --- a/tests/src/input/restartFileSection/testStepCountSection.cpp +++ b/tests/src/input/restartFileSection/testStepCountSection.cpp @@ -26,9 +26,9 @@ #include // for string, allocator, basic_string #include // for vector -#include "exceptions.hpp" // for RstFileException, customException -#include "gtest/gtest.h" // for AssertionResult, Message, TestPart... -#include "restartFileSection.hpp" // for RstFileSection, readInput +#include "exceptions.hpp" // for RstFileException, customException +#include "gtest/gtest.h" // for AssertionResult, Message, TestPart... +#include "restartFileReader/restartFileSection.hpp" // for RstFileSection, readInput #include "testRestartFileSection.hpp" // for TestStepCountSection #include "timingsSettings.hpp" // for TimingsSettings @@ -73,4 +73,4 @@ TEST_F(TestStepCountSection, testProcess) line[1] = "1000"; _section->process(line, *_engine); EXPECT_EQ(settings::TimingsSettings::getStepCount(), 1000); -} \ No newline at end of file +} diff --git a/tests/src/input/testInputFileReader.cpp b/tests/src/input/testInputFileReader.cpp index 90a0b34cc..721a9e21a 100644 --- a/tests/src/input/testInputFileReader.cpp +++ b/tests/src/input/testInputFileReader.cpp @@ -35,6 +35,7 @@ #include "mmmdEngine.hpp" #include "potentialSettings.hpp" #include "settings.hpp" +#include "testUtils.hpp" #include "throwWithMessage.hpp" using namespace input; @@ -302,7 +303,7 @@ TEST_F(TestInputFileReader, testReadJobType) auto engine = std::unique_ptr(); ASSERT_NO_THROW(input::readJobType(filename, engine)); EXPECT_EQ(settings::Settings::getJobtype(), settings::JobType::MM_MD); - EXPECT_EQ(typeid(*engine), typeid(engine::MMMDEngine)); + test::checkType(engine, typeid(engine::MMMDEngine)); filename = "fileNotFound"; ASSERT_THROW_MSG( @@ -317,4 +318,4 @@ TEST_F(TestInputFileReader, testReadJobType) customException::InputFileException, "Missing keyword \"jobtype\" in input file" ); -} \ No newline at end of file +} diff --git a/tests/src/input/testMoldescriptorReader.cpp b/tests/src/input/testMoldescriptorReader.cpp index 1c4841aa4..58d5b6db3 100644 --- a/tests/src/input/testMoldescriptorReader.cpp +++ b/tests/src/input/testMoldescriptorReader.cpp @@ -20,17 +20,16 @@ ******************************************************************************/ +#include // for TestInfo (ptr only), TEST_F + #include "engine.hpp" // for Engine #include "exceptions.hpp" // for MolDescriptorException #include "fileSettings.hpp" // for FileSettings +#include "gtest/gtest.h" // for Message, TestPartResult, testing #include "moldescriptorReader.hpp" // for MoldescriptorReader #include "testMoldesctripotReader.hpp" // for TestMoldescriptorReader #include "throwWithMessage.hpp" // for ASSERT_THROW_MSG -#include "gtest/gtest.h" // for Message, TestPartResult, testing -#include // for TestInfo (ptr only), TEST_F -#include // for allocator, basic_string - using namespace std; using namespace ::testing; using namespace input::molDescriptor; @@ -42,7 +41,9 @@ using namespace customException; */ TEST_F(TestMoldescriptorReader, constructor) { - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptor.dat"); + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptor.dat" + ); ASSERT_NO_THROW(MoldescriptorReader reader(*_engine)); } @@ -52,9 +53,15 @@ TEST_F(TestMoldescriptorReader, constructor) */ TEST_F(TestMoldescriptorReader, argumentsInMoldescriptor) { - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptorWithOneWordLine.dat"); + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptorWithOneWordLine.dat" + ); MoldescriptorReader reader(*_engine); - ASSERT_THROW_MSG(reader.read(), MolDescriptorException, "Error in moldescriptor file at line 1"); + ASSERT_THROW_MSG( + reader.read(), + MolDescriptorException, + "Error in moldescriptor file at line 1" + ); } /** @@ -63,19 +70,35 @@ TEST_F(TestMoldescriptorReader, argumentsInMoldescriptor) */ TEST_F(TestMoldescriptorReader, argumentsInMoleculeSection) { - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptorWithErrorInAtomArguments.dat"); + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptorWithErrorInAtomArguments.dat" + ); MoldescriptorReader reader(*_engine); ASSERT_THROW_MSG( - reader.read(), MolDescriptorException, "Atom line in moldescriptor file at line 4 has to have 3 or 4 elements"); - - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptorWithErrorInAtomArguments2.dat"); + reader.read(), + MolDescriptorException, + "Atom line in moldescriptor file at line 4 has to have 3 or 4 elements" + ); + + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptorWithErrorInAtomArguments2.dat" + ); MoldescriptorReader reader2(*_engine); ASSERT_THROW_MSG( - reader2.read(), MolDescriptorException, "Atom line in moldescriptor file at line 5 has to have 3 or 4 elements"); - - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptorWithErrorInMolArguments.dat"); + reader2.read(), + MolDescriptorException, + "Atom line in moldescriptor file at line 5 has to have 3 or 4 elements" + ); + + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptorWithErrorInMolArguments.dat" + ); MoldescriptorReader reader3(*_engine); - ASSERT_THROW_MSG(reader3.read(), MolDescriptorException, "Not enough arguments in moldescriptor file at line 3"); + ASSERT_THROW_MSG( + reader3.read(), + MolDescriptorException, + "Not enough arguments in moldescriptor file at line 3" + ); } /** @@ -84,7 +107,9 @@ TEST_F(TestMoldescriptorReader, argumentsInMoleculeSection) */ TEST_F(TestMoldescriptorReader, moldescriptorReader) { - settings::FileSettings::setMolDescriptorFileName("examples/setup/moldescriptor.dat"); + settings::FileSettings::setMolDescriptorFileName( + "examples/setup/moldescriptor.dat" + ); MoldescriptorReader reader(*_engine); ASSERT_NO_THROW(reader.read()); } @@ -95,7 +120,9 @@ TEST_F(TestMoldescriptorReader, moldescriptorReader) */ TEST_F(TestMoldescriptorReader, specialTypes) { - settings::FileSettings::setMolDescriptorFileName("examples/setup/moldescriptor.dat"); + settings::FileSettings::setMolDescriptorFileName( + "examples/setup/moldescriptor.dat" + ); readMolDescriptor(*_engine); ASSERT_EQ(_engine->getSimulationBox().getWaterType(), 1); ASSERT_EQ(_engine->getSimulationBox().getAmmoniaType(), 2); @@ -107,26 +134,40 @@ TEST_F(TestMoldescriptorReader, specialTypes) */ TEST_F(TestMoldescriptorReader, toManyAtomsPerMoltype) { - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptorTooManyAtomsPerMoltype.dat"); + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptorTooManyAtomsPerMoltype.dat" + ); MoldescriptorReader reader2(*_engine); ASSERT_THROW_MSG( - reader2.read(), MolDescriptorException, "Error reading of moldescriptor stopped before last molecule was finished"); + reader2.read(), + MolDescriptorException, + "Error reading of moldescriptor stopped before last molecule was " + "finished" + ); } /** - * @brief tests if non coulombic force field is activated but no global can der Waals parameter given + * @brief tests if non coulombic force field is activated but no global can der + * Waals parameter given * */ TEST_F(TestMoldescriptorReader, globalVdwTypes) { _engine->getForceFieldPtr()->activateNonCoulombic(); - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptor_withGlobalVdwTypes.dat"); + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptor_withGlobalVdwTypes.dat" + ); EXPECT_NO_THROW(readMolDescriptor(*_engine)); - settings::FileSettings::setMolDescriptorFileName("data/moldescriptorReader/moldescriptor_withMissingGlobalVdwTypes.dat"); - EXPECT_THROW_MSG(readMolDescriptor(*_engine), - MolDescriptorException, - "Error in moldescriptor file at line 6 - force field noncoulombics is activated but no global van der Waals " - "parameter given"); -} \ No newline at end of file + settings::FileSettings::setMolDescriptorFileName( + "data/moldescriptorReader/moldescriptor_withMissingGlobalVdwTypes.dat" + ); + EXPECT_THROW_MSG( + readMolDescriptor(*_engine), + MolDescriptorException, + "Error in moldescriptor file at line 6 - force field noncoulombics is " + "activated but no global van der Waals " + "parameter given" + ); +} diff --git a/tests/src/integrator/testIntegrator.cpp b/tests/src/integrator/testIntegrator.cpp index 21f008981..e3a7b6001 100644 --- a/tests/src/integrator/testIntegrator.cpp +++ b/tests/src/integrator/testIntegrator.cpp @@ -22,12 +22,11 @@ #include "testIntegrator.hpp" -#include // for string #include // for vector -#include "constants/conversionFactors.hpp" // for _FS_TO_S_ -#include "constants/internalConversionFactors.hpp" // for _V_VERLET_VELOCITY_FACTOR_ -#include "gtest/gtest.h" // for CmpHelperFloatingPointEQ, Message, Test, TestPartResult, EXPECT_EQ, EXPECT_DOUBLE_EQ, EXPECT_TRUE, TestPartResultArray, InitGoogleTest, RUN_ALL_TESTS +#include "constants/conversionFactors.hpp" +#include "constants/internalConversionFactors.hpp" +#include "gtest/gtest.h" /** * @brief tests function integrate velocities of velocity verlet integrator diff --git a/tests/src/intraNonBonded/testIntraNonBonded.cpp b/tests/src/intraNonBonded/testIntraNonBonded.cpp index 2f1610e6b..9235fe3af 100644 --- a/tests/src/intraNonBonded/testIntraNonBonded.cpp +++ b/tests/src/intraNonBonded/testIntraNonBonded.cpp @@ -25,7 +25,6 @@ #include // for size_t #include // for format #include // for shared_ptr, allocator, make_shared -#include // for basic_string #include // for vector #include "atom.hpp" // for Atom @@ -222,4 +221,4 @@ TEST(TestIntraNonBonded, calculate) std::make_shared(nonCoulombPotential) ); EXPECT_NO_THROW(intraNonBonded.calculate(simulationBox, physicalData)); -} \ No newline at end of file +} diff --git a/tests/src/manostat/testManostat.cpp b/tests/src/manostat/testManostat.cpp index be8034523..8a964478e 100644 --- a/tests/src/manostat/testManostat.cpp +++ b/tests/src/manostat/testManostat.cpp @@ -24,7 +24,6 @@ #include // for pow #include // for make_shared, __shared_ptr_access -#include // for string, allocator #include "atom.hpp" // for Atom #include "berendsenManostat.hpp" // for BerendsenManostat diff --git a/tests/src/output/testRingPolymerRestartFileOutput.cpp b/tests/src/output/testRingPolymerRestartFileOutput.cpp index f95f373af..1d4dae426 100644 --- a/tests/src/output/testRingPolymerRestartFileOutput.cpp +++ b/tests/src/output/testRingPolymerRestartFileOutput.cpp @@ -39,7 +39,7 @@ TEST_F(TestRingPolymerRestartFileOutput, write) settings::RingPolymerSettings::setNumberOfBeads(_beads.size()); _rstFileOutput->setFilename("default.rpmd.rst"); - _rstFileOutput->write(_beads, 10); + _rstFileOutput->write(_beads); _rstFileOutput->close(); std::ifstream file("default.rpmd.rst"); std::string line; @@ -93,4 +93,4 @@ TEST_F(TestRingPolymerRestartFileOutput, write) "2.00000000e+00\t 2.00000000e+00\t 2.00000000\t " "2.00000000\t 2.00000000" ); -} \ No newline at end of file +} diff --git a/tests/src/potential/nonCoulomb/testBuckinghamPair.cpp b/tests/src/potential/nonCoulomb/testBuckinghamPair.cpp index b85e9ff65..f5b225a06 100644 --- a/tests/src/potential/nonCoulomb/testBuckinghamPair.cpp +++ b/tests/src/potential/nonCoulomb/testBuckinghamPair.cpp @@ -24,7 +24,6 @@ #include // for pow, exp #include // for size_t -#include // for string #include // for vector #include "buckinghamPair.hpp" // for BuckinghamPair @@ -108,4 +107,4 @@ TEST(TestBuckinghamPair, calculateEnergyAndForces) -helper * coefficients[1] + 6.0 * coefficients[2] / ::pow(distance, 7) - forceCutoff ); -} \ No newline at end of file +} diff --git a/tests/src/potential/nonCoulomb/testLennardJonesPair.cpp b/tests/src/potential/nonCoulomb/testLennardJonesPair.cpp index 34b2cedb4..f733cce35 100644 --- a/tests/src/potential/nonCoulomb/testLennardJonesPair.cpp +++ b/tests/src/potential/nonCoulomb/testLennardJonesPair.cpp @@ -24,7 +24,6 @@ #include // for pow #include // for size_t -#include // for string #include // for vector #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult @@ -102,4 +101,4 @@ TEST(TestLennardJonesPair, calculateEnergyAndForces) 6 * coefficients[0] / ::pow(distance, 7) + 12 * coefficients[1] / ::pow(distance, 13) - forceCutoff ); -} \ No newline at end of file +} diff --git a/tests/src/potential/nonCoulomb/testMorsePair.cpp b/tests/src/potential/nonCoulomb/testMorsePair.cpp index 1abbb8aee..fa317471e 100644 --- a/tests/src/potential/nonCoulomb/testMorsePair.cpp +++ b/tests/src/potential/nonCoulomb/testMorsePair.cpp @@ -24,11 +24,10 @@ #include // for exp, pow #include // for size_t -#include // for string #include // for vector -#include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult -#include "morsePair.hpp" // for MorsePair +#include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult +#include "morsePair.hpp" // for MorsePair using namespace potential; @@ -108,4 +107,4 @@ TEST(TestMorsePair, calculateEnergyAndForces) -2 * coefficients[0] * coefficients[1] * (1 - expTerm) * expTerm - forceCutoff ); -} \ No newline at end of file +} diff --git a/tests/src/setup/CMakeLists.txt b/tests/src/setup/CMakeLists.txt index e78caf8fb..5936e455a 100644 --- a/tests/src/setup/CMakeLists.txt +++ b/tests/src/setup/CMakeLists.txt @@ -33,6 +33,7 @@ foreach(source_file ${source_files}) gtest gmock pq_test_main + testUtils ) add_test( NAME ${test_name} @@ -54,4 +55,4 @@ if(${BUILD_WITH_GCOVR}) EXECUTABLE_ARGS "-L;setup" OUTPUT_PATH "coverage" ) -endif() \ No newline at end of file +endif() diff --git a/tests/src/setup/testCelllistSetup.cpp b/tests/src/setup/testCelllistSetup.cpp index ce1ce6261..425d642a1 100644 --- a/tests/src/setup/testCelllistSetup.cpp +++ b/tests/src/setup/testCelllistSetup.cpp @@ -22,8 +22,6 @@ #include // for InitGoogleTest, RUN_ALL_TESTS, EXPECT_EQ -#include // for allocator, basic_string - #include "celllistSetup.hpp" // for CellListSetup, setupCellList, setup #include "engine.hpp" // for Engine #include "gtest/gtest.h" // for Message, TestPartResult @@ -31,6 +29,7 @@ #include "potentialCellList.hpp" // for PotentialCellList #include "potentialSettings.hpp" #include "testSetup.hpp" // for TestSetup +#include "testUtils.hpp" using namespace setup; @@ -43,8 +42,8 @@ TEST_F(TestSetup, setupCellList) CellListSetup cellListSetup(*_engine); cellListSetup.setup(); - EXPECT_EQ( - typeid((_engine->getPotential())), + test::checkType( + &_engine->getPotential(), typeid(potential::PotentialBruteForce) ); @@ -54,8 +53,8 @@ TEST_F(TestSetup, setupCellList) _engine->getCellList().activate(); cellListSetup.setup(); - EXPECT_EQ( - typeid((_engine->getPotential())), + test::checkType( + &_engine->getPotential(), typeid(potential::PotentialCellList) ); diff --git a/tests/src/setup/testConstraintsSetup.cpp b/tests/src/setup/testConstraintsSetup.cpp index b4f0dd1b0..7b5b52a5a 100644 --- a/tests/src/setup/testConstraintsSetup.cpp +++ b/tests/src/setup/testConstraintsSetup.cpp @@ -22,8 +22,6 @@ #include // for TestInfo (ptr only), EXPECT_EQ, Init... -#include // for allocator, basic_string - #include "constraintSettings.hpp" // for getShakeMaxIter, getShakeTolerance, getRattleMaxIter, getRattleTolerance #include "constraintsSetup.hpp" // for ConstraintsSetup, setupConstraints #include "engine.hpp" // for Engine @@ -87,4 +85,4 @@ TEST_F(TestSetup, setupConstraints) _engine->getConstraints().getShakeTolerance(); EXPECT_NE(shakeToleranceDeactivated, shakeToleranceActivated); -} \ No newline at end of file +} diff --git a/tests/src/setup/testManostatSetup.cpp b/tests/src/setup/testManostatSetup.cpp index 9d2c3acae..67c4dd154 100644 --- a/tests/src/setup/testManostatSetup.cpp +++ b/tests/src/setup/testManostatSetup.cpp @@ -22,8 +22,6 @@ #include // for EXPECT_EQ, EXPECT_NO_THROW, InitGoog... -#include // for allocator, basic_string - #include "berendsenManostat.hpp" // for BerendsenManostat #include "gtest/gtest.h" // for Message, TestPartResult #include "manostat.hpp" // for BerendsenManostat, Manostat @@ -88,8 +86,8 @@ TEST_F(TestSetup, setupManostatNoneIsotropyDefaultsToIsotropic) ManostatSetup manostatSetup(*_mdEngine); EXPECT_NO_THROW(manostatSetup.setup()); - const auto &manostat = _mdEngine->getManostat(); - const auto berendsen = dynamic_cast(manostat); + const auto &manostat = _mdEngine->getManostat(); + const auto berendsen = dynamic_cast(manostat); EXPECT_EQ(berendsen.getIsotropy(), Isotropy::ISOTROPIC); } diff --git a/tests/src/setup/testPotentialSetup.cpp b/tests/src/setup/testPotentialSetup.cpp index b43e2b8aa..2102b85d2 100644 --- a/tests/src/setup/testPotentialSetup.cpp +++ b/tests/src/setup/testPotentialSetup.cpp @@ -24,7 +24,6 @@ #include // for size_t #include // for make_shared -#include // for allocator, basic_string #include "coulombReactionField.hpp" // for CoulombReactionField #include "coulombShiftedPotential.hpp" // for CoulombShiftedPotential @@ -39,7 +38,8 @@ #include "potentialSettings.hpp" // for PotentialSettings #include "potentialSetup.hpp" // for PotentialSetup, setupPotential #include "testSetup.hpp" // for TestSetup -#include "throwWithMessage.hpp" // for EXPECT_THROW_MSG +#include "testUtils.hpp" +#include "throwWithMessage.hpp" // for EXPECT_THROW_MSG using namespace setup; using namespace settings; @@ -55,8 +55,8 @@ TEST_F(TestSetup, setupReactionFieldPotential) PotentialSettings::setReactionFieldEpsilon(80.0); EXPECT_NO_THROW(potentialSetup.setup()); - EXPECT_EQ( - typeid(_engine->getPotential().getCoulombPotential()), + test::checkType( + &(_engine->getPotential().getCoulombPotential()), typeid(CoulombReactionField) ); @@ -72,8 +72,8 @@ TEST_F(TestSetup, setupCoulombPotential) PotentialSetup potentialSetup(*_engine); potentialSetup.setupCoulomb(); - EXPECT_EQ( - typeid(_engine->getPotential().getCoulombPotential()), + test::checkType( + &_engine->getPotential().getCoulombPotential(), typeid(CoulombShiftedPotential) ); @@ -81,8 +81,8 @@ TEST_F(TestSetup, setupCoulombPotential) PotentialSetup potentialSetup2(*_engine); potentialSetup2.setup(); - EXPECT_EQ( - typeid(_engine->getPotential().getCoulombPotential()), + test::checkType( + &_engine->getPotential().getCoulombPotential(), typeid(CoulombWolf) ); const auto &wolfCoulomb = dynamic_cast( @@ -101,8 +101,8 @@ TEST_F(TestSetup, setupNonCoulombPotential) PotentialSetup potentialSetup(*_engine); potentialSetup.setupNonCoulomb(); - EXPECT_EQ( - typeid(_engine->getPotential().getNonCoulombPotential()), + test::checkType( + &_engine->getPotential().getNonCoulombPotential(), typeid(ForceFieldNonCoulomb) ); @@ -110,8 +110,8 @@ TEST_F(TestSetup, setupNonCoulombPotential) PotentialSetup potentialSetup2(*_engine); potentialSetup2.setupNonCoulomb(); - EXPECT_EQ( - typeid(_engine->getPotential().getNonCoulombPotential()), + test::checkType( + &_engine->getPotential().getNonCoulombPotential(), typeid(GuffNonCoulomb) ); } diff --git a/tests/src/setup/testQMSetup.cpp b/tests/src/setup/testQMSetup.cpp index 6844ef999..258407021 100644 --- a/tests/src/setup/testQMSetup.cpp +++ b/tests/src/setup/testQMSetup.cpp @@ -25,15 +25,16 @@ #include // for allocator, basic_string #include // for string_view -#include "dftbplusRunner.hpp" // for DFTBPlusRunner -#include "exceptions.hpp" // for InputFileException -#include "gtest/gtest.h" // for Message, TestPartResult -#include "pyscfRunner.hpp" // for PySCFRunner -#include "qmSettings.hpp" // for QMMethod, QMSettings -#include "qmSetup.hpp" // for QMSetup, setupQM -#include "qmSetup.hpp" // for QMSetup -#include "qmmdEngine.hpp" // for QMMDEngine -#include "settings.hpp" // for Settings +#include "dftbplusRunner.hpp" // for DFTBPlusRunner +#include "exceptions.hpp" // for InputFileException +#include "gtest/gtest.h" // for Message, TestPartResult +#include "pyscfRunner.hpp" // for PySCFRunner +#include "qmSettings.hpp" // for QMMethod, QMSettings +#include "qmSetup.hpp" // for QMSetup, setupQM +#include "qmSetup.hpp" // for QMSetup +#include "qmmdEngine.hpp" // for QMMDEngine +#include "settings.hpp" // for Settings +#include "testUtils.hpp" #include "throwWithMessage.hpp" // for ASSERT_THROW_MSG #include "turbomoleRunner.hpp" // for TurbomoleRunner @@ -64,10 +65,7 @@ TEST(TestQMSetup, setupDftbplus) setBuildCompatibleQMScript(); setupQM.setup(); - EXPECT_EQ( - typeid(dynamic_cast(*engine.getQMRunner())), - typeid(QM::DFTBPlusRunner) - ); + test::checkType(engine.getQMRunner(), typeid(QM::DFTBPlusRunner)); settings::QMSettings::setQMMethod(settings::QMMethod::NONE); @@ -88,10 +86,7 @@ TEST(TestQMSetup, setupPySCF) setBuildCompatibleQMScript(); setupQM.setup(); - EXPECT_EQ( - typeid(dynamic_cast(*engine.getQMRunner())), - typeid(QM::PySCFRunner) - ); + test::checkType(engine.getQMRunner(), typeid(QM::PySCFRunner)); settings::QMSettings::setQMMethod(settings::QMMethod::NONE); @@ -112,10 +107,7 @@ TEST(TestQMSetup, setupTurbomoleRunner) setBuildCompatibleQMScript(); setupQM.setup(); - EXPECT_EQ( - typeid(dynamic_cast(*engine.getQMRunner())), - typeid(QM::TurbomoleRunner) - ); + test::checkType(engine.getQMRunner(), typeid(QM::TurbomoleRunner)); settings::QMSettings::setQMMethod(settings::QMMethod::NONE); diff --git a/tests/src/setup/testThermostatSetup.cpp b/tests/src/setup/testThermostatSetup.cpp index 16e377f0b..6fc33739b 100644 --- a/tests/src/setup/testThermostatSetup.cpp +++ b/tests/src/setup/testThermostatSetup.cpp @@ -22,19 +22,18 @@ #include // for EXPECT_EQ, EXPECT_NO_THROW, InitGo... -#include // for sqrt -#include // for allocator, basic_string +#include // for sqrt #include "berendsenThermostat.hpp" // for BerendsenThermostat #include "constants/conversionFactors.hpp" // for _FS_TO_S_, _KG_TO_GRAM_ #include "constants/natureConstants.hpp" // for _UNIVERSAL_GAS_CONSTANT_ -#include "gtest/gtest.h" // for Message, TestPartResult -#include "langevinThermostat.hpp" // for LangevinThermostat -#include "noseHooverThermostat.hpp" // for NoseHooverThermostat -#include "testSetup.hpp" // for TestSetup -#include "thermostatSettings.hpp" // for ThermostatSettings -#include "thermostatSetup.hpp" // for ThermostatSetup, setupThermostat -#include "timingsSettings.hpp" // for TimingsSettings +#include "gtest/gtest.h" // for Message, TestPartResult +#include "langevinThermostat.hpp" // for LangevinThermostat +#include "noseHooverThermostat.hpp" // for NoseHooverThermostat +#include "testSetup.hpp" // for TestSetup +#include "thermostatSettings.hpp" // for ThermostatSettings +#include "thermostatSetup.hpp" // for ThermostatSetup, setupThermostat +#include "timingsSettings.hpp" // for TimingsSettings #include "velocityRescalingThermostat.hpp" // for VelocityRescalingThermostat using namespace setup; @@ -99,7 +98,6 @@ TEST_F(TestSetup, setupThermostat_temp_ramping) thermostatSetup.getEngine().getThermostat().getRampingFrequency(), 2 ); - } TEST_F(TestSetup, setupThermostat_only_end_temp_defined) @@ -188,8 +186,7 @@ TEST_F(TestSetup, setupThermostat_langevin) EXPECT_EQ(langevinThermostat.getFriction(), 1.0e11); const auto conversionFactor = - constants::_UNIVERSAL_GAS_CONSTANT_ * - constants::_M2_TO_ANGSTROM2_ * + constants::_UNIVERSAL_GAS_CONSTANT_ * constants::_M2_TO_ANGSTROM2_ * constants::_KG_TO_GRAM_ / constants::_FS_TO_S_; const auto sigma = std::sqrt( 4.0 * langevinThermostat.getFriction() * conversionFactor * diff --git a/tests/src/simulationBox/testCelllist.cpp b/tests/src/simulationBox/testCelllist.cpp index 56e929b69..94a1e06a1 100644 --- a/tests/src/simulationBox/testCelllist.cpp +++ b/tests/src/simulationBox/testCelllist.cpp @@ -23,7 +23,6 @@ #include "testCelllist.hpp" #include // for make_shared, __shared_ptr_access -#include // for allocator, basic_string #include // for vector #include "atom.hpp" // for Atom @@ -34,7 +33,7 @@ #include "potentialSettings.hpp" // for PotentialSettings #include "simulationBox.hpp" // for SimulationBox #include "throwWithMessage.hpp" // for EXPECT_THROW_MSG -#include "vector3d.hpp" // IWYU pragma: keep - for Vec3Dul, Vec3D, Vector3D +#include "vector3d.hpp" // IWYU pragma: keep - for Vec3Dul, Vec3D, Vector3D TEST_F(TestCellList, determineCellSize) { @@ -242,10 +241,10 @@ TEST_F(TestCellList, checkCoulombCutoff) { _simulationBox->setBoxDimensions(linearAlgebra::Vec3D(50.0, 50.0, 50.0)); _cellList->determineCellSize(_simulationBox->getBoxDimensions()); - EXPECT_NO_THROW(_cellList->checkCoulombCutoff({200.0})); + EXPECT_NO_THROW(_cellList->checkCoulombCutoff(200.0)); EXPECT_THROW_MSG( - _cellList->checkCoulombCutoff({0.1}), + _cellList->checkCoulombCutoff(0.1), customException::CellListException, "Coulomb cutoff is smaller than half of the largest cell size." ); diff --git a/tests/src/testUtils/CMakeLists.txt b/tests/src/testUtils/CMakeLists.txt new file mode 100644 index 000000000..dc8dda4d9 --- /dev/null +++ b/tests/src/testUtils/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library(testUtils + testUtils.cpp +) + +target_include_directories(testUtils + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/tests/include/testUtils/ +) + +target_link_libraries(testUtils + PUBLIC + engine + potential + coulombPotential + nonCoulombPotential +) + +install(TARGETS testUtils + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/ +) diff --git a/tests/src/testUtils/testUtils.cpp b/tests/src/testUtils/testUtils.cpp new file mode 100644 index 000000000..dd91d53b1 --- /dev/null +++ b/tests/src/testUtils/testUtils.cpp @@ -0,0 +1,77 @@ +/***************************************************************************** + + + PQ + Copyright (C) 2023-now Jakob Gamper + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + +******************************************************************************/ + +#include "testUtils.hpp" + +#include + +#include "coulombPotential.hpp" // IWYU pragma: keep -- needed for explicit template instantiation +#include "engine.hpp" // IWYU pragma: keep -- needed for explicit template instantiation +#include "nonCoulombPotential.hpp" // IWYU pragma: keep -- needed for explicit template instantiation +#include "qmRunner.hpp" // IWYU pragma: keep -- needed for explicit template instantiation + +namespace test +{ + /** + * @brief check that the dynamic type of obj matches expectedType + * + * @details Works for raw pointers, smart pointers, and plain + * references alike — dereferences anything pointer-like before + * comparing typeid, so typeid always reflects the pointee's + * actual (polymorphic) type rather than the pointer/wrapper type. + * + * @tparam T + * @param obj + * @param expectedType + */ + template + void checkType(const T& obj, const std::type_info& expectedType) + { + if constexpr (requires { *obj; }) + EXPECT_EQ(typeid(*obj), expectedType); + else + EXPECT_EQ(typeid(obj), expectedType); + } + + // explicit instantiations + template void checkType>( + const std::unique_ptr& engine, + const std::type_info& expectedType + ); + template void checkType( + potential::Potential* const& potential, + const std::type_info& expectedType + ); + template void checkType( + potential::CoulombPotential* const& potential, + const std::type_info& expectedType + ); + template void checkType( + potential::NonCoulombPotential* const& potential, + const std::type_info& expectedType + ); + template void checkType( + QM::QMRunner* const& runner, + const std::type_info& expectedType + ); + +} // namespace test diff --git a/tests/src/utilities/testMathUtilities.cpp b/tests/src/utilities/testMathUtilities.cpp index 8de8cbbbf..a76cfd29d 100644 --- a/tests/src/utilities/testMathUtilities.cpp +++ b/tests/src/utilities/testMathUtilities.cpp @@ -23,7 +23,6 @@ #include // for Test, TestInfo (ptr only), EXPECT_EQ #include // for numeric_limits -#include // for allocator, string #include "gtest/gtest.h" // for AssertionResult, Message, TestPartResult #include "mathUtilities.hpp" // for compare, sign, utilities @@ -113,4 +112,4 @@ TEST(TestMathUtilities, isZero) EXPECT_FALSE(isZero(1.0)); EXPECT_FALSE(isZero(std::numeric_limits::epsilon())); EXPECT_FALSE(isZero(std::numeric_limits::min())); -} \ No newline at end of file +}