Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/medium.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ namespace batoid {
const Medium* getDevPtr() const override;

private:
const double _B1, _B2, _B3, _C1, _C2, _C3;
// ``_C1`` / ``_C2`` / ``_C3`` collide with macros from the
// Windows SDK (ctype.h), so use a Sellmeier-prefixed name.
const double _B1, _B2, _B3, _sellC1, _sellC2, _sellC3;
};


Expand Down
22 changes: 21 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,32 @@ def build_extension(self, ext):
"-DPYTHON_EXECUTABLE=" + sys.executable,
]

# Make pybind11 discoverable in PEP 517 isolated builds, where
# CMake's normal find_package would not see the temporary site
# packages. ``python -m pybind11 --cmakedir`` returns the
# directory shipped with the pybind11 wheel.
try:
import pybind11
cmake_args.append("-Dpybind11_DIR=" + pybind11.get_cmake_dir())
except (ImportError, AttributeError):
pass

cfg = "Debug" if self.debug else "RelWithDebInfo"
build_args = ["--config", cfg]

cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
# Hand parallelism to ``cmake --build --parallel`` instead of
# forwarding ``-j8`` to the underlying tool: MSBuild rejects
# ``-j8`` outright (it expects ``/m`` or ``-maxCpuCount``), while
# Make/Ninja are happy with the CMake-level flag. ``--parallel``
# picks up CMAKE_BUILD_PARALLEL_LEVEL when set, or defaults to a
# generator-appropriate count.
if "TF_BUILD" not in env:
build_args += ["--", "-j8"]
jobs = os.environ.get("CMAKE_BUILD_PARALLEL_LEVEL")
if jobs:
build_args += ["--parallel", str(jobs)]
else:
build_args += ["--parallel"]

if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
Expand Down
10 changes: 8 additions & 2 deletions src/batoid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "batoid.h"
#include <cstddef> // ptrdiff_t for OpenMP-safe signed loop counters on MSVC.
#include <limits>


Expand All @@ -10,8 +11,12 @@ namespace batoid {
double* x, double* y, double* z,
size_t n, int max_threads
) {
// MSVC's OpenMP requires a signed integral loop counter; reuse a
// ptrdiff_t mirror of ``n`` so the parallel-for index can be signed
// without clipping.
ptrdiff_t nloop = static_cast<ptrdiff_t>(n);
#pragma omp parallel for num_threads(max_threads)
for(size_t i=0; i<n; i++) {
for(ptrdiff_t i=0; i<nloop; i++) {
double dx = x[i]-dr[0];
double dy = y[i]-dr[1];
double dz = z[i]-dr[2];
Expand All @@ -26,8 +31,9 @@ namespace batoid {
double* x, double* y, double* z,
size_t n, int max_threads
) {
ptrdiff_t nloop = static_cast<ptrdiff_t>(n);
#pragma omp parallel for num_threads(max_threads)
for(size_t i=0; i<n; i++) {
for(ptrdiff_t i=0; i<nloop; i++) {
double xx = x[i]*drot[0] + y[i]*drot[1] + z[i]*drot[2] + dr[0];
double yy = x[i]*drot[3] + y[i]*drot[4] + z[i]*drot[5] + dr[1];
double zz = x[i]*drot[6] + y[i]*drot[7] + z[i]*drot[8] + dr[2];
Expand Down
7 changes: 4 additions & 3 deletions src/medium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ namespace batoid {
double B1, double B2, double B3,
double C1, double C2, double C3
) :
Medium(), _B1(B1), _B2(B2), _B3(B3), _C1(C1), _C2(C2), _C3(C3)
Medium(), _B1(B1), _B2(B2), _B3(B3),
_sellC1(C1), _sellC2(C2), _sellC3(C3)
{}

SellmeierMedium::~SellmeierMedium() {}

double SellmeierMedium::getN(double wavelength) const {
// Sellmeier coefficients assume wavelength is in microns, so we have to multiply (1e6)**2
double x = wavelength*wavelength*1e12;
return std::sqrt(1.0 + _B1*x/(x-_C1) + _B2*x/(x-_C2) + _B3*x/(x-_C3));
return std::sqrt(1.0 + _B1*x/(x-_sellC1) + _B2*x/(x-_sellC2) + _B3*x/(x-_sellC3));
}

#if defined(BATOID_GPU)
Expand All @@ -160,7 +161,7 @@ namespace batoid {
Medium* ptr;
#pragma omp target map(from:ptr)
{
ptr = new SellmeierMedium(_B1, _B2, _B3, _C1, _C2, _C3);
ptr = new SellmeierMedium(_B1, _B2, _B3, _sellC1, _sellC2, _sellC3);
}
_devPtr = ptr;
return ptr;
Expand Down
4 changes: 2 additions & 2 deletions src/obscuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace batoid {
if (y1 != y2) {
xinters = (y-y1)*(x2-x1)/(y2-y1)+x1;
}
if (x1 == x2 or x <= xinters) {
if (x1 == x2 || x <= xinters) {
inside = !inside;
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace batoid {
xinters.reserve(16); // 2 is probably most common, but it's cheap to allocate 16
for (int j=0; j<ny; j++) {
double y = ygrid[j];
if ((y < ymin) or (y > ymax)) {
if ((y < ymin) || (y > ymax)) {
for (int i=0; i<nx; i++) {
out[j*nx+i] = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace batoid {
double Table::eval(double x, double y) const {
int ix = int(std::floor((x-_x0)/_dx));
int iy = int(std::floor((y-_y0)/_dy));
if ((ix >= (_nx-1)) or (ix < 0) or (iy >= (_ny-1)) or (iy < 0)) {
if ((ix >= (_nx-1)) || (ix < 0) || (iy >= (_ny-1)) || (iy < 0)) {
return _use_nan ? NAN : 0.0;
}
double xgrid = _x0 + ix*_dx;
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace batoid {
) const {
int ix = int(std::floor((x-_x0)/_dx));
int iy = int(std::floor((y-_y0)/_dy));
if ((ix >= (_nx-1)) or (ix < 0) or (iy >= (_ny-1)) or (iy < 0)) {
if ((ix >= (_nx-1)) || (ix < 0) || (iy >= (_ny-1)) || (iy < 0)) {
if (_use_nan) {
dzdx = NAN;
dzdy = NAN;
Expand Down