Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial portable implementation of ORANGE: oak ridge geometry engine #291

Merged
merged 22 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build/emmet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mkdir ${BUILD_DIR} 2>/dev/null \
cd ${BUILD_DIR}

module purge
module load cuda
module load cuda/10
CELERITAS_ENV=$SPACK_ROOT/var/spack/environments/celeritas/.spack-env/view
export PATH=$CELERITAS_ENV/bin:${PATH}
export CMAKE_PREFIX_PATH=$CELERITAS_ENV:${CMAKE_PREFIX_PATH}
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ list(APPEND SOURCES
comm/ScopedMpiInit.cc
comm/detail/LoggerMessage.cc
geometry/detail/ScopedTimeAndRedirect.cc
orange/Types.cc
orange/construct/SurfaceInserter.cc
orange/surfaces/SurfaceIO.cc
io/ImportProcess.cc
io/ImportPhysicsTable.cc
io/ImportPhysicsVector.cc
Expand Down
20 changes: 20 additions & 0 deletions src/base/Algorithms.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ CELER_CONSTEXPR_FUNCTION const T& max(const T& a, const T& b) noexcept
return (b > a) ? b : a;
}

//---------------------------------------------------------------------------//
/*!
* Return an iterator to the lowest value in the range.
*/
template<class ForwardIt>
inline CELER_FUNCTION ForwardIt min_element(ForwardIt iter, ForwardIt last)
{
// Avoid incrementing past the end
if (iter == last)
return last;

ForwardIt result = iter++;
for (; iter != last; ++iter)
{
if (*iter < *result)
result = iter;
}
return result;
}

//---------------------------------------------------------------------------//
// Replace/extend <cmath>
//---------------------------------------------------------------------------//
Expand Down
6 changes: 6 additions & 0 deletions src/base/Array.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct Array
using const_iterator = const_pointer;
//!@}

//! Static size (not in std::array)
static constexpr size_type extent = N;

//// DATA ////

T data_[N]; //!< Storage
Expand Down Expand Up @@ -82,6 +85,9 @@ struct Array
//!@}
};

template<class T, size_type N>
constexpr size_type Array<T, N>::extent;

//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
Expand Down
5 changes: 3 additions & 2 deletions src/base/Collection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ namespace celeritas
* data collections are typically accessed by thread ID. \c ParamsData are
* immutable and always "mirrored" on both host and device. Sometimes it's
* sensible to partition \c ParamsData into discrete helper structs (stored by
* value), each with a group of collections: each of these should be called a
* \c DataGroup.
* value), each with a group of collections, and perhaps another struct that
* has non-templated scalars (since the default assignment operator is less
* work than manually copying scalars in a templated assignment operator.
*
* A collection group has the following requirements to be compatible with the
\c
Expand Down
8 changes: 5 additions & 3 deletions src/base/Constants.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ namespace constants
*/

//!@{
//! Mathemetical constant
constexpr real_type pi = 3.14159265358979323846; // truncated
constexpr real_type euler = 2.71828182845904523536;
//! Mathemetical constants (truncated)
constexpr real_type pi = 3.14159265358979323846;
constexpr real_type euler = 2.71828182845904523536;
constexpr real_type sqrt_two = 1.41421356237309504880;
constexpr real_type sqrt_three = 1.73205080756887729353;
//!@}

//!@{
Expand Down
9 changes: 8 additions & 1 deletion src/base/Macros.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@
*
* See https://clang.llvm.org/docs/LanguageExtensions.html#builtin-unreachable
* or https://msdn.microsoft.com/en-us/library/1b3fsfxw.aspx=
* or
* https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#__builtin_unreachable
*
* (The 'unreachable' and 'assume' compiler optimizations for CUDA are only
* available in API version 11.1 or higher, which is encoded as major*1000 +
* minor*10).
*
* \note This macro should not generally be used; instead, the macro \c
* CELER_ASSERT_UNREACHABLE() defined in base/Assert.hh should be used instead
* (to provide a more detailed error message in case the point *is* reached).
*/
#if defined(__clang__) || defined(__GNUC__)
#if (!defined(__CUDA_ARCH__) && (defined(__clang__) || defined(__GNUC__))) \
|| (defined(__CUDA_ARCH__) && CUDART_VERSION >= 11010)
# define CELER_UNREACHABLE __builtin_unreachable()
#elif defined(_MSC_VER)
# define CELER_UNREACHABLE __assume(false)
Expand Down
3 changes: 2 additions & 1 deletion src/base/Range.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ using RangeIter = detail::range_iter<T>;
*
* Here, T can be any of:
* - an integer,
* - an enum that has a "size_" member, or
* - an enum that has contiguous zero-indexed values and a "size_" enumeration
* value indicating how many, or
* - an OpaqueId.
*
* It is OK to dereference the end iterator! The result should just be the
Expand Down
3 changes: 3 additions & 0 deletions src/base/Span.hh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class Span
detail::SpanImpl<T, Extent> s_;
};

template<class T, std::size_t N>
constexpr std::size_t Span<T, N>::extent;

//---------------------------------------------------------------------------//
// HELPER FUNCTIONS
//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/GeoData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct GeoStateData

//// METHODS ////

//! True if assigned
//! True if sizes are consistent and states are assigned
explicit CELER_FUNCTION operator bool() const
{
return this->size() > 0 && dir.size() == this->size()
Expand Down
1 change: 1 addition & 0 deletions src/geometry/GeoParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class GeoParams
const std::string& id_to_label(VolumeId vol_id) const;

// Get the ID corresponding to a label
// TODO: rename to find ?? see MaterialParams etc.
VolumeId label_to_id(const std::string& label) const;

//! Number of volumes
Expand Down
3 changes: 1 addition & 2 deletions src/geometry/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

namespace celeritas
{
class Geometry;
//---------------------------------------------------------------------------//
//! Opaque numeric identifier for a geometry cell
//! Identifier for a geometry volume
using VolumeId = OpaqueId<struct Volume>;

//---------------------------------------------------------------------------//
Expand Down
63 changes: 63 additions & 0 deletions src/orange/Data.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2021 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file Data.hh
//---------------------------------------------------------------------------//
#pragma once

#include "base/Collection.hh"
#include "base/OpaqueId.hh"
#include "Types.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
// PARAMS
//---------------------------------------------------------------------------//
/*!
* Data for surface definitions.
*
* Surfaces each have a compile-time number of real data needed to define them.
* (These usually are the nonzero coefficients of the quadric equation.) A
* surface ID points to an offset into the `data` field. These surface IDs are
* *global* over all universes.
*/
template<Ownership W, MemSpace M>
struct SurfaceData
{
//// TYPES ////

template<class T>
using Items = Collection<T, W, M, SurfaceId>;

//// DATA ////

Items<SurfaceType> types;
Items<OpaqueId<real_type>> offsets;
Collection<real_type, W, M> reals;

//// METHODS ////

//! True if sizes are valid
explicit CELER_FUNCTION operator bool() const
{
return !types.empty() && offsets.size() == types.size()
&& reals.size() >= types.size();
}

//! Assign from another set of data
template<Ownership W2, MemSpace M2>
SurfaceData& operator=(const SurfaceData<W2, M2>& other)
{
CELER_EXPECT(other);
types = other.types;
offsets = other.offsets;
reals = other.reals;
return *this;
}
};

//---------------------------------------------------------------------------//
} // namespace celeritas
54 changes: 54 additions & 0 deletions src/orange/Types.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2021 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file Types.cc
//---------------------------------------------------------------------------//
#include "Types.hh"

#include "base/Assert.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Get a string corresponding to a surface type.
*/
const char* to_cstring(SurfaceType value)
{
CELER_EXPECT(value != SurfaceType::size_);

static const char* const strings[] = {
"px",
"py",
"pz",
"cxc",
"cyc",
"czc",
#if 0
"sc",
"cx",
"cy",
"cz",
"p",
#endif
"s",
#if 0
"kx",
"ky",
"kz",
"sq",
#endif
"gq",
};
static_assert(
static_cast<unsigned int>(SurfaceType::size_) * sizeof(const char*)
== sizeof(strings),
"Enum strings are incorrect");

return strings[static_cast<unsigned int>(value)];
}

//---------------------------------------------------------------------------//
} // namespace celeritas