Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:10:55

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 celeritas/field/CylMapFieldInput.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <algorithm>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/math/SoftEqual.hh"
0014 #include "corecel/math/Turn.hh"
0015 #include "celeritas/Types.hh"
0016 
0017 #include "FieldDriverOptions.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Input data for a magnetic R-Phi-Z vector field stored on an R-Phi-Z grid.
0024  *
0025  * The magnetic field is discretized at nodes on an R-Phi-Z grid, and at each
0026  * point the field vector is approximated by a 3-D vector in R-Phi-Z. The input
0027  * units of this field are in *NATIVE UNITS* (cm/gauss when CGS). An optional
0028  * \c _units field in the input can specify whether the input is in SI or CGS
0029  * units, with allowable values of "si", "cgs", or "clhep". The native CLHEP
0030  * unit strength is 1000*tesla.
0031  *
0032  * The field values are all indexed with Z having stride 1, Phi having stride
0033  * (num_grid_z), and R having stride (num_grid_phi * num_grid_z): [R][Phi][Z]
0034  */
0035 struct CylMapFieldInput
0036 {
0037     std::vector<real_type> grid_r;  //!< R grid points [len]
0038     std::vector<RealTurn> grid_phi;  //!< Phi grid points [AU]
0039     std::vector<real_type> grid_z;  //!< Z grid points [len]
0040 
0041     std::vector<real_type> field;  //!< Flattened R-Phi-Z field component
0042                                    //!< [bfield]
0043 
0044     // TODO: remove from field input; should be a separate input
0045     FieldDriverOptions driver_options;
0046 
0047     //! Whether all data are assigned and valid
0048     explicit operator bool() const
0049     {
0050         // clang-format off
0051         return 
0052              (grid_r.size() >= 2)
0053             && (grid_phi.size() >= 2)
0054             && (grid_z.size() >= 2)
0055             && (grid_r.front() >= 0)
0056             && (soft_zero(grid_phi.front().value()))
0057             && (soft_equal(real_type{1}, grid_phi.back().value()))
0058             && std::is_sorted(grid_r.cbegin(), grid_r.cend())
0059             && std::is_sorted(grid_phi.cbegin(), grid_phi.cend())
0060             && std::is_sorted(grid_z.cbegin(), grid_z.cend())
0061             && (field.size() == static_cast<size_type>(CylAxis::size_) * grid_r.size() * grid_phi.size() * grid_z.size());
0062         // clang-format on
0063     }
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 }  // namespace celeritas