Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-19 08:43:28

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/TwodGridData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/data/Collection.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Definition of a structured nonuniform 2D grid with node-centered data.
0018  *
0019  * This relies on an external Collection of reals. Data is indexed as `[x][y]`,
0020  * C-style row-major.
0021  */
0022 struct TwodGridData
0023 {
0024     ItemRange<real_type> x;  //!< x grid definition
0025     ItemRange<real_type> y;  //!< y grid definition
0026     ItemRange<real_type> values;  //!< [x][y]
0027 
0028     //! True if assigned and valid
0029     explicit CELER_FUNCTION operator bool() const
0030     {
0031         return x.size() >= 2 && y.size() >= 2
0032                && values.size() == x.size() * y.size();
0033     }
0034 
0035     //! Get the data location for a specified x-y coordinate.
0036     CELER_FUNCTION ItemId<real_type> at(size_type ix, size_type iy) const
0037     {
0038         CELER_EXPECT(ix < this->x.size());
0039         CELER_EXPECT(iy < this->y.size());
0040         size_type index = ix * this->y.size() + iy;
0041 
0042         CELER_ENSURE(index < this->x.size() * this->y.size());
0043         return ItemId<real_type>{index + this->values.front().get()};
0044     }
0045 };
0046 
0047 //---------------------------------------------------------------------------//
0048 }  // namespace celeritas