![]() |
|
|||
File indexing completed on 2025-09-17 08:54:06
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file corecel/grid/UniformGridData.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include "corecel/Assert.hh" 0010 #include "corecel/Types.hh" 0011 #include "corecel/cont/EnumArray.hh" 0012 #include "corecel/data/Collection.hh" 0013 0014 #include "GridTypes.hh" 0015 0016 namespace celeritas 0017 { 0018 //---------------------------------------------------------------------------// 0019 /*! 0020 * Data input for a uniform increasing grid. 0021 * 0022 * The four parameters are overconstrained -- we could omit back by calculating 0023 * from the front, delta, and size. In practice, though, that can introduce an 0024 * inconsistency into the "find" function. 0025 */ 0026 struct UniformGridData 0027 { 0028 using value_type = ::celeritas::real_type; 0029 0030 size_type size{}; //!< Number of grid edges/points 0031 value_type front{}; //!< Value of first grid point 0032 value_type back{}; //!< Value of last grid point 0033 value_type delta{}; //!< Grid cell width 0034 0035 //! True if assigned and valid 0036 CELER_FUNCTION operator bool() const 0037 { 0038 return size >= 2 && delta > 0 && front < back; 0039 } 0040 0041 //// HELPER FUNCTIONS //// 0042 0043 // Construct on host from front/back 0044 inline static UniformGridData 0045 from_bounds(EnumArray<Bound, double> bounds, size_type size); 0046 }; 0047 0048 //---------------------------------------------------------------------------// 0049 /*! 0050 * Parameterization of a discrete scalar field on a given 1D grid. 0051 * 0052 * \c derivative stores the second derivative of the interpolating cubic 0053 * spline. If it is non-empty, cubic spline interpolation will be used. 0054 * 0055 * \c spline_order stores the order of the piecewise polynomials used for 0056 * spline interpolation without continuous derivatives. The order must be 0057 * smaller than the grid size for effective spline interpolation. If the order 0058 * is set to 1, linear or cubic spline interpolation will be used. 0059 */ 0060 struct UniformGridRecord 0061 { 0062 UniformGridData grid; 0063 ItemRange<real_type> value; 0064 ItemRange<real_type> derivative; 0065 size_type spline_order{1}; 0066 0067 //! Whether the record is initialized and valid 0068 explicit CELER_FUNCTION operator bool() const 0069 { 0070 return grid && grid.size == value.size() 0071 && (derivative.empty() || grid.size == derivative.size()) 0072 && spline_order > 0 && spline_order < value.size() 0073 && (derivative.empty() || spline_order == 1); 0074 } 0075 }; 0076 0077 //---------------------------------------------------------------------------// 0078 /*! 0079 * Construct from min/max and number of grid points. 0080 */ 0081 UniformGridData 0082 UniformGridData::from_bounds(EnumArray<Bound, double> bounds, size_type size) 0083 { 0084 CELER_EXPECT(size >= 2); 0085 CELER_EXPECT(bounds[Bound::lo] < bounds[Bound::hi]); 0086 UniformGridData result; 0087 result.size = size; 0088 result.front = bounds[Bound::lo]; 0089 result.back = bounds[Bound::hi]; 0090 result.delta = (bounds[Bound::hi] - bounds[Bound::lo]) / (size - 1); 0091 CELER_ENSURE(result); 0092 return result; 0093 } 0094 0095 //---------------------------------------------------------------------------// 0096 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |