Skip to content

Commit

Permalink
Merge pull request #992 from glotzerlab/fix/cpp17-support
Browse files Browse the repository at this point in the history
Fully Support C++17
  • Loading branch information
tommy-waltmann authored Aug 8, 2022
2 parents 74b4972 + 4e8366d commit 856408a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 15 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ on:
# twice when the pull request source branch is in the same repository.
push:
branches:
- "maint"
- "master"
- "next"
tags:
- "v*"

pull_request:
types: [opened, labeled, reopened, synchronize]

# Trigger on request.
workflow_dispatch:

Expand All @@ -20,9 +23,10 @@ jobs:
build_wheels:
name: Build wheel for ${{ matrix.os }}, Python ${{ matrix.pyver }}
runs-on: ${{ matrix.os }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'build_wheels') || github.event_name != 'pull_request' }}
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15] #, windows-2019]
os: [ubuntu-20.04, macos-12] #, windows-2019]
pyver: ["3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
Expand All @@ -45,6 +49,7 @@ jobs:
# Configure environment variables.
CIBW_ENVIRONMENT_LINUX: "CMAKE_PREFIX_PATH=/project/tbb LD_LIBRARY_PATH=/project/tbb/lib/intel64/gcc4.8:$LD_LIBRARY_PATH"
CIBW_ENVIRONMENT_MACOS: "CMAKE_PREFIX_PATH=/Users/runner/work/freud/freud/tbb LD_LIBRARY_PATH=/Users/runner/work/freud/freud/tbb/lib/intel64/gcc4.8:$LD_LIBRARY_PATH"
MACOSX_DEPLOYMENT_TARGET: "10.14"

# Set up TBB.
CIBW_BEFORE_BUILD_LINUX: "source .github/workflows/cibuildwheel-before-build.sh {package} linux"
Expand All @@ -65,6 +70,7 @@ jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'build_wheels') || github.event_name != 'pull_request' }}
steps:
- uses: actions/[email protected]
with:
Expand All @@ -90,6 +96,7 @@ jobs:
name: Publish [PyPI]
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'build_wheels') || github.event_name != 'pull_request' }}

steps:
- name: Download artifacts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
push:
branches:
- "master"
- "next"

# trigger on request
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to

### Added
* Support for 2D systems in `freud.diffraction.StaticStructureFactorDebye`.
* Compilation uses the C++17 standard.

### Fixed
* `EnvironmentMotifMatch` correctly handles `NeighborList`s with more neighbors per particle than the motif.
Expand Down
7 changes: 4 additions & 3 deletions cpp/diffraction/StaticStructureFactorDebye.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __clang__
#include <bessel-library.hpp>
#endif
#include <algorithm>
#include <cmath>
#include <limits>
#include <stdexcept>
Expand Down Expand Up @@ -86,17 +87,17 @@ void StaticStructureFactorDebye::accumulate(const freud::locality::NeighborQuery
// floating point precision errors can cause k to be
// slightly negative, and make evaluating the cylindrical
// bessel function impossible.
auto abs_k = std::abs(k);
auto nonnegative_k = std::max(float(0.0), k);

#ifdef __clang__
// clang doesn't support the special math functions in
// C++17, so we use another library instead. The cast is
// needed because the other library's implementation is
// unique only for complex numbers, otherwise it just tries
// to call std::cyl_bessel_j.
S_k += std::real(bessel::cyl_j0(std::complex<double>(abs_k * distance)));
S_k += std::real(bessel::cyl_j0(std::complex<double>(nonnegative_k * distance)));
#else
S_k += std::cyl_bessel_j(0, abs_k * distance);
S_k += std::cyl_bessel_j(0, nonnegative_k * distance);
#endif
}
else
Expand Down
1 change: 1 addition & 0 deletions doc/source/reference/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ Tommy Waltmann
* Reformat static structure factor tests.
* ``DiffractionPattern`` now raises an error when used with non-cubic boxes.
* Implement ``StaticStructureFactorDebye`` for 2D systems.
* Add support for compilation with the C++17 standard.

Maya Martirossyan

Expand Down
13 changes: 13 additions & 0 deletions doc/source/reference/freud.bib
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,16 @@ @article{Teich2019
title = {Identity crisis in alchemical space drives the entropic colloidal glass transition},
url = {https://doi.org/10.1038/s41467-018-07977-2}
}

@article{Wieder2012,
author = {Thomas Wieder},
issn = {1927-5307},
issue = {4},
journal = {Journal of Mathematical and Computational Sciences},
year = {2012},
volume = {2},
pages = {1086-1090},
publisher = {SCIK Publishing Corporation},
title = {The Debye Scattering Formula in n Dimensions},
url = {https://www.scik.org/index.php/jmcs/article/viewFile/263/120}
}
2 changes: 1 addition & 1 deletion extern/bessel-library.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Taken from https://gtihub.com/jodesarro/bessel-library.git, distributed under
* Taken from https://github.com/jodesarro/bessel-library.git, distributed under
* the MIT license.
*
* */
Expand Down
17 changes: 8 additions & 9 deletions freud/diffraction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ cdef class StaticStructureFactorDebye(_StaticStructureFactor):
.. note::
For 2D systems freud uses the bessel function :math:`J_0` instead of the
:math:`\text{sinc}` function in the equation above. See this `link
<http://www.scik.org/index.php/jmcs/article/viewFile/263/120>`__
for more information. For users wishing to calculate the structure
factor of quasi 2D systems (i.e. a 2D simulation is used to model a real
system such as particles on a 2D interface or similar) the 3D
formula should be used. In these cases users should use a 3D box with
its longest dimension being in the z-direction and particle positions of
the form :math:`(x, y, 0)`.
For 2D systems freud uses the Bessel function :math:`J_0` instead of the
:math:`\text{sinc}` function in the equation above. See
:cite:`Wieder2012` for more information. For users wishing to calculate
the structure factor of quasi 2D systems (i.e. a 2D simulation is used
to model a real system such as particles on a 2D interface or similar)
the 3D formula should be used. In these cases users should use a 3D box
with its longest dimension being in the z-direction and particle
positions of the form :math:`(x, y, 0)`.
This implementation uses an evenly spaced number of :math:`k` points between
`k_min`` and ``k_max``. If ``k_min`` is set to 0 (the default behavior), the
Expand Down

0 comments on commit 856408a

Please sign in to comment.