Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:42

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2021-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/grid/VectorUtils.hh
0007 //! \brief Grid creation helpers
0008 //---------------------------------------------------------------------------//
0009 #pragma once
0010 
0011 #include <algorithm>
0012 #include <vector>
0013 
0014 #include "corecel/Types.hh"
0015 #include "corecel/cont/Span.hh"
0016 #include "corecel/math/Algorithms.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 // Return evenly spaced numbers over a specific interval
0022 std::vector<double> linspace(double start, double stop, size_type n);
0023 
0024 //---------------------------------------------------------------------------//
0025 // Return logarithmically spaced numbers over a specific interval
0026 std::vector<double> logspace(double start, double stop, size_type n);
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * True if the grid values are monotonically nondecreasing.
0031  */
0032 template<class T>
0033 inline bool is_monotonic_nondecreasing(Span<T> grid)
0034 {
0035     return all_adjacent(grid.begin(), grid.end(), [](T& left, T& right) {
0036         return left <= right;
0037     });
0038 }
0039 
0040 //---------------------------------------------------------------------------//
0041 /*!
0042  * True if the grid values are monotonically increasing.
0043  */
0044 template<class T>
0045 inline bool is_monotonic_increasing(Span<T> grid)
0046 {
0047     return all_adjacent(grid.begin(), grid.end(), [](T& left, T& right) {
0048         return left < right;
0049     });
0050 }
0051 
0052 //---------------------------------------------------------------------------//
0053 }  // namespace celeritas