Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:21

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-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 celeritas/field/RZMapFieldData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/grid/UniformGridData.hh"
0014 
0015 #include "FieldDriverOptions.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * FieldMap (2-dimensional RZ map) grid data
0022  */
0023 struct FieldMapGridData
0024 {
0025     UniformGridData data_z;
0026     UniformGridData data_r;
0027 };
0028 
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * FieldMap element
0032  */
0033 struct FieldMapElement
0034 {
0035     real_type value_z;
0036     real_type value_r;
0037 };
0038 
0039 //---------------------------------------------------------------------------//
0040 /*!
0041  * Device data for interpolating field values.
0042  */
0043 template<Ownership W, MemSpace M>
0044 struct RZMapFieldParamsData
0045 {
0046     //! Grids of FieldMap
0047     FieldMapGridData grids;
0048 
0049     //! Options for FieldDriver
0050     FieldDriverOptions options;
0051 
0052     //! Index of FieldMap Collection
0053     using ElementId = ItemId<size_type>;
0054 
0055     template<class T>
0056     using ElementItems = Collection<T, W, M, ElementId>;
0057     ElementItems<FieldMapElement> fieldmap;
0058 
0059     //! Check whether the data is assigned
0060     explicit inline CELER_FUNCTION operator bool() const
0061     {
0062         return !fieldmap.empty();
0063     }
0064 
0065     inline CELER_FUNCTION bool valid(real_type z, real_type r) const
0066     {
0067         CELER_EXPECT(grids.data_z);
0068         CELER_EXPECT(grids.data_r);
0069         return (z >= grids.data_z.front && z <= grids.data_z.back
0070                 && r >= grids.data_r.front && r <= grids.data_r.back);
0071     }
0072 
0073     inline CELER_FUNCTION ElementId id(size_type idx_z, size_type idx_r) const
0074     {
0075         CELER_EXPECT(grids.data_r);
0076         return ElementId(idx_z * grids.data_r.size + idx_r);
0077     }
0078 
0079     //! Assign from another set of data
0080     template<Ownership W2, MemSpace M2>
0081     RZMapFieldParamsData& operator=(RZMapFieldParamsData<W2, M2> const& other)
0082     {
0083         CELER_EXPECT(other);
0084         grids = other.grids;
0085         options = other.options;
0086         fieldmap = other.fieldmap;
0087         return *this;
0088     }
0089 };
0090 
0091 //---------------------------------------------------------------------------//
0092 }  // namespace celeritas