|
|
|||
File indexing completed on 2026-10-26 09:34:34
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/inp/Grid.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <limits> 0010 #include <vector> 0011 0012 #include "corecel/Types.hh" 0013 #include "corecel/cont/EnumArray.hh" 0014 #include "corecel/grid/GridTypes.hh" 0015 0016 namespace celeritas 0017 { 0018 namespace inp 0019 { 0020 //---------------------------------------------------------------------------// 0021 /*! 0022 * Interpolation options for the physics grids. 0023 * 0024 * \c order is only used for \c poly_spline interpolation and \c bc is only 0025 * used for \c cubic_spline interpolation. 0026 * 0027 * \todo Let's just use "Geant4 spline" and linear interpolation, and maybe 0028 * it shouldn't be inside every single grid? 0029 */ 0030 struct Interpolation 0031 { 0032 using BC = SplineBoundaryCondition; 0033 0034 InterpolationType type{InterpolationType::linear}; 0035 //! Polynomial order for spline interpolation 0036 size_type order{1}; 0037 //! Boundary conditions for calculating cubic spline second derivatives 0038 BC bc{BC::geant}; 0039 }; 0040 0041 //---------------------------------------------------------------------------// 0042 /*! 0043 * A grid of increasing, sorted 1D data. 0044 * 0045 * This is used to store tabulated physics data such as cross sections or 0046 * energy loss. 0047 */ 0048 struct Grid 0049 { 0050 using VecDbl = std::vector<double>; 0051 0052 VecDbl x; 0053 VecDbl y; 0054 Interpolation interpolation{}; 0055 0056 explicit operator bool() const 0057 { 0058 return !y.empty() && x.size() == y.size(); 0059 } 0060 0061 //! Construct a grid with a constant value for all real numbers 0062 static Grid from_constant(double y) 0063 { 0064 Grid result; 0065 result.x = {0, std::numeric_limits<double>::infinity()}; 0066 result.y = {y, y}; 0067 return result; 0068 } 0069 }; 0070 0071 //---------------------------------------------------------------------------// 0072 /*! 0073 * A uniform grid of increasing, sorted 1D data. 0074 */ 0075 struct UniformGrid 0076 { 0077 using GridBound = EnumArray<Bound, double>; 0078 using VecDbl = std::vector<double>; 0079 0080 GridBound x{}; 0081 VecDbl y; 0082 Interpolation interpolation{}; 0083 0084 explicit operator bool() const 0085 { 0086 return !y.empty() && x[Bound::hi] > x[Bound::lo]; 0087 } 0088 }; 0089 0090 //---------------------------------------------------------------------------// 0091 /*! 0092 * Uniform grids for storing macroscopic cross sections. 0093 * 0094 * The upper grid values are expected to be pre-scaled by a factor of 1 / E. 0095 */ 0096 struct XsGrid 0097 { 0098 UniformGrid lower; 0099 UniformGrid upper; 0100 0101 explicit operator bool() const 0102 { 0103 return (lower || upper) 0104 && (!lower || !upper 0105 || lower.x[Bound::hi] == upper.x[Bound::lo]); 0106 } 0107 }; 0108 0109 //---------------------------------------------------------------------------// 0110 /*! 0111 * An increasing, sorted 2D grid with node-centered data. 0112 * 0113 * Data is interpolated linearly and indexed as '[x][y]'. 0114 */ 0115 struct TwodGrid 0116 { 0117 using VecDbl = std::vector<double>; 0118 0119 VecDbl x; 0120 VecDbl y; 0121 VecDbl value; 0122 0123 explicit operator bool() const 0124 { 0125 return !value.empty() && value.size() == x.size() * y.size(); 0126 } 0127 }; 0128 0129 //---------------------------------------------------------------------------// 0130 // HELPER FUNCTIONS 0131 //---------------------------------------------------------------------------// 0132 /*! 0133 * Equality operator, mainly for debugging. 0134 */ 0135 inline bool operator==(TwodGrid const& a, TwodGrid const& b) 0136 { 0137 return a.x == b.x && a.y == b.y && a.value == b.value; 0138 } 0139 0140 //---------------------------------------------------------------------------// 0141 } // namespace inp 0142 } // 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 |
|