Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ 4 : /* */ 5 : /* Copyright 2017 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #pragma once 10 : 11 : #include "Moose.h" 12 : #include "MooseEnum.h" 13 : #include "MultiMooseEnum.h" 14 : #include "libmesh/libmesh.h" 15 : #include "libmesh/elem.h" 16 : 17 : namespace MagpieUtils 18 : { 19 : 20 : /** 21 : * Returns a point inside element el distributed with uniform 22 : * probability. For higher order elements the non-linearity of the 23 : * mapping from the reference element coordinates to the physical element 24 : * could introduce a non-uniform distribution. 25 : * @param el The target element to locate the random point in 26 : * @param rnd A set of random numbers in [0:1) to use for generating the projected point 27 : */ 28 : Point randomElementPoint(const Elem & el, const Point & rnd); 29 : 30 : ///@{ ZAID (ZZAAA) conversion helper 31 : unsigned int getZFromZAID(unsigned int zaid); 32 : unsigned int getAFromZAID(unsigned int zaid); 33 : ///@} 34 : 35 : /// enum of different neutron energy groups (thermal, epithermal, fast, high) 36 : enum NeutronEnergyType 37 : { 38 : Thermal = 0, 39 : Epithermal, 40 : Fast, 41 : High, 42 : NET_MAX 43 : }; 44 : 45 : /// vector of strings for each neutron energy type 46 : const std::string & neutronEnergyName(unsigned int i); 47 : 48 : /// Determines neutron energy type given its energy 49 : NeutronEnergyType determineNeutronType(Real energy); 50 : 51 : /** 52 : * Proxy object to emulate a reference to a T object that can be stored in 53 : * a container and is copy constructible but NOT CopyAssignable. It uses a 54 : * pointer to T internally and overloads the assignement operator to make it 55 : * behave like a reference. This allows us to construct iterators that dereference 56 : * to pairs and have assignable 'second' members. 57 : */ 58 : template <typename T> 59 : class reference_wrapper 60 : { 61 : public: 62 : reference_wrapper() = delete; 63 : reference_wrapper(T & obj) : _ptr(std::addressof(obj)) {} 64 : reference_wrapper(T && obj) = delete; 65 : reference_wrapper(const reference_wrapper<T> & ref) : _ptr(ref._ptr) {} 66 : 67 : /// implicit cast to a value type for read access 68 : operator T() { return *_ptr; } 69 : 70 : /// explicit cast to a value reference 71 : T & get() { return *_ptr; } 72 : 73 : /// resets the pointer 74 : void set(T & rhs) { _ptr = &rhs; } 75 : 76 : /// write access to the wrapped value 77 : T & operator=(const T & value) 78 : { 79 1 : *_ptr = value; 80 : return *_ptr; 81 : } 82 : 83 : /// we need to delete this assignement ioperator as it will have an unexpected effect 84 : T & operator=(const reference_wrapper<T> & ref) = delete; // Error: cast to value type explicitly 85 : // before assigning a reference_wrapper 86 : // to another reference_wrapper! 87 : 88 : ///@{ compound assignment operators for modification of the value 89 2 : T & operator+=(const T & rhs) { return *_ptr += rhs; } 90 1 : T & operator-=(const T & rhs) { return *_ptr -= rhs; } 91 1 : T & operator*=(const T & rhs) { return *_ptr *= rhs; } 92 1 : T & operator/=(const T & rhs) { return *_ptr /= rhs; } 93 1 : T & operator%=(const T & rhs) { return *_ptr %= rhs; } 94 1 : T & operator<<=(const T & rhs) { return *_ptr <<= rhs; } 95 1 : T & operator>>=(const T & rhs) { return *_ptr >>= rhs; } 96 1 : T & operator^=(const T & rhs) { return *_ptr ^= rhs; } 97 1 : T & operator&=(const T & rhs) { return *_ptr &= rhs; } 98 1 : T & operator|=(const T & rhs) { return *_ptr |= rhs; } 99 : ///@} 100 : 101 : private: 102 : /// pointer top the wrapped object 103 : T * _ptr; 104 : }; 105 : 106 : } // namespace MagpieUtils