Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:55

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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 orange/orangeinp/detail/PostfixLogicBuilder.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <utility>
0011 #include <vector>
0012 
0013 #include "orange/OrangeTypes.hh"
0014 #include "orange/orangeinp/CsgTypes.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace orangeinp
0019 {
0020 class CsgTree;
0021 namespace detail
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Construct a postfix logic representation of a node.
0026  *
0027  * The optional surface mapping is an ordered vector of *existing* surface IDs.
0028  * Those surface IDs will be replaced by the index in the array. All existing
0029  * surface IDs must be present!
0030  *
0031  * The result is a pair of vectors: the sorted surface IDs comprising the faces
0032  * of this volume, and the logical representation using \em face IDs, i.e. with
0033  * the surfaces remapped to index of the surface in the face vector.
0034  *
0035  * Example: \verbatim
0036     all(1, 3, 5) -> {{1, 3, 5}, "0 1 & 2 & &"}
0037     all(1, 3, !all(2, 4)) -> {{1, 2, 3, 4}, "0 2 & 1 3 & ~ &"}
0038  * \endverbatim
0039  */
0040 class PostfixLogicBuilder
0041 {
0042   public:
0043     //!@{
0044     //! \name Type aliases
0045     using VecLogic = std::vector<logic_int>;
0046     using VecSurface = std::vector<LocalSurfaceId>;
0047     using result_type = std::pair<VecSurface, VecLogic>;
0048     //!@}
0049 
0050   public:
0051     //! Construct from a tree
0052     explicit PostfixLogicBuilder(CsgTree const& tree) : tree_{tree} {}
0053 
0054     // Construct from a tree and surface remapping
0055     inline PostfixLogicBuilder(CsgTree const& tree, VecSurface const& old_ids);
0056 
0057     // Convert a single node to postfix notation
0058     result_type operator()(NodeId n) const;
0059 
0060   private:
0061     CsgTree const& tree_;
0062     VecSurface const* mapping_{nullptr};
0063 };
0064 
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Construct from a tree and surface remapping.
0068  */
0069 PostfixLogicBuilder::PostfixLogicBuilder(CsgTree const& tree,
0070                                          VecSurface const& old_ids)
0071     : tree_{tree}, mapping_{&old_ids}
0072 {
0073 }
0074 
0075 //---------------------------------------------------------------------------//
0076 }  // namespace detail
0077 }  // namespace orangeinp
0078 }  // namespace celeritas