| 1 | #cxx . . $ `<file>/ncrystal_core/include/NCrystal/internal/NCEqRefl.hh`/ifndef NCrystal_EqRefl_hh |
| 2 | #define NCrystal_EqRefl_hhcxx . . $ `ncrystal_core/include/NCrystal/internal/NCEqRefl.hh:2:9`! |
| 3 | |
| 4 | //////////////////////////////////////////////////////////////////////////////// |
| 5 | // // |
| 6 | // This file is part of NCrystal (see https://mctools.github.io/ncrystal/) // |
| 7 | // // |
| 8 | // Copyright 2015-2022 NCrystal developers // |
| 9 | // // |
| 10 | // Licensed under the Apache License, Version 2.0 (the "License"); // |
| 11 | // you may not use this file except in compliance with the License. // |
| 12 | // You may obtain a copy of the License at // |
| 13 | // // |
| 14 | // http://www.apache.org/licenses/LICENSE-2.0 // |
| 15 | // // |
| 16 | // Unless required by applicable law or agreed to in writing, software // |
| 17 | // distributed under the License is distributed on an "AS IS" BASIS, // |
| 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // |
| 19 | // See the License for the specific language governing permissions and // |
| 20 | // limitations under the License. // |
| 21 | // // |
| 22 | //////////////////////////////////////////////////////////////////////////////// |
| 23 | |
| 24 | #include "NCrystal/NCTypes.hh"cxx . . $ `<file>/ncrystal_core/include/NCrystal/NCTypes.hh`/ |
| 25 | |
| 26 | //Class EqRefl provides symmetry-equivalent reflections for a given space group |
| 27 | //number, by providing a list of all (h,k,l) indices symmetry-equivalent to a |
| 28 | //given (h,k,l) index. Or more precisely, half of the list, since the symmetry |
| 29 | //(h,k,l)->(-h,-k,-l) is trivial and would be a waste of memory to expand |
| 30 | //explicitly. |
| 31 | // |
| 32 | //Note that while two equivalent (h,k,l) indices will always have identical |
| 33 | //values of d-spacing and structure factors (F^2), the opposite is not in |
| 34 | //general true. So (h,k,l) groupings based on (d,F^2) values might contain more |
| 35 | //than one symmetry-equivalency group in each (d,F^2) group. |
| 36 | // |
| 37 | //TODO: SCBragg currently assumes Info objects to either have |
| 38 | //demi-normals or contain equivalency groupings. This is currently true, but |
| 39 | //seems a bit fragile (e.g. the NCMAT factory produces (d,F^2) groups, not |
| 40 | //equivalency groups - but does fortunately provide demi-normals). A more robust |
| 41 | //situation would be desirable (either all factories should produce hkl lists |
| 42 | //grouped by equivalency, or SCBragg code should become more intelligent). |
| 43 | |
| 44 | namespace NCrystalcxx . . $ NCrystal/ { |
| 45 | |
| 46 | class EqReflcxx . . $ NCrystal/EqRefl# |
| 47 | { |
| 48 | public: |
| 49 | |
| 50 | //Initialise with space group number in 1..230: |
| 51 | EqReflcxx . . $ NCrystal/EqRefl#EqRefl(d4f767463ce0a6b3).( int spacegroup ); |
| 52 | |
| 53 | class EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList# { |
| 54 | //List with half the HKL points in a given family of symmetric equivalent |
| 55 | //HKL points (only half, since (h,k,l) and (-h,-k,-l) are trivially in the |
| 56 | //same group). This uses non-dynamic storage to keep malloc overhead low, |
| 57 | //and thus takes up roughly 100B of storage (it is thus mostly suitable |
| 58 | //for short-lived usage on the stack). |
| 59 | public: |
| 60 | const HKLcxx . . $ NCrystal/HKL#* begincxx . . $ NCrystal/EqRefl#EquivReflList#begin(6809e21b4e64c3ba).() const noexcept; |
| 61 | const HKLcxx . . $ NCrystal/HKL#& frontcxx . . $ NCrystal/EqRefl#EquivReflList#front(71a9142cdf2d2d3f).() const noexcept { return *begincxx . . $ NCrystal/EqRefl#EquivReflList#begin(6809e21b4e64c3ba).(); } |
| 62 | const HKLcxx . . $ NCrystal/HKL#* endcxx . . $ NCrystal/EqRefl#EquivReflList#end(6809e21b4e64c3ba).() const noexcept; |
| 63 | stdcxx . . $ std/::size_tcxx . . $ std/size_t# sizecxx . . $ NCrystal/EqRefl#EquivReflList#size(c9b1e749b64d5edc).() const noexcept; |
| 64 | bool containscxx . . $ NCrystal/EqRefl#EquivReflList#contains(a97afa4901f0ed54).( HKLcxx . . $ NCrystal/HKL# ) const noexcept;//is (h,k,l) or (-h,-k,-l) in the list? |
| 65 | |
| 66 | //Empty (for later assignment): |
| 67 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#EquivReflList(49f6e7a06ebc5aa8).(); |
| 68 | |
| 69 | //Copy only: |
| 70 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#EquivReflList(40ef462b6dc8c64e).( const EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& ); |
| 71 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& operatorcxx . . $ NCrystal/EqRefl#EquivReflList#`operator=`(94d869b4dd281017).=( const EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& ); |
| 72 | |
| 73 | private: |
| 74 | HKLcxx . . $ NCrystal/HKL# m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[24]; |
| 75 | HKLcxx . . $ NCrystal/HKL# * m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.; |
| 76 | friend class EqReflcxx . . $ NCrystal/EqRefl#; |
| 77 | void addcxx . . $ NCrystal/EqRefl#EquivReflList#add(b1146eedae1e1d0b).(int, int, int); |
| 78 | }; |
| 79 | |
| 80 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList# getEquivalentReflectionscxx . . $ NCrystal/EqRefl#getEquivalentReflections(baffda499cfa78ea).(int h, int k, int l) const; |
| 81 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList# getEquivalentReflectionscxx . . $ NCrystal/EqRefl#getEquivalentReflections(3eaaaf0c83f97594).( const HKLcxx . . $ NCrystal/HKL#& hkl ) const |
| 82 | { |
| 83 | return getEquivalentReflectionscxx . . $ NCrystal/EqRefl#getEquivalentReflections(baffda499cfa78ea).( hkl.hcxx . . $ NCrystal/HKL#h., hkl.kcxx . . $ NCrystal/HKL#k., hkl.lcxx . . $ NCrystal/HKL#l. ); |
| 84 | } |
| 85 | |
| 86 | //Same as getEquivalentReflections(..).front() but slightly faster (for when |
| 87 | //only that value is needed): |
| 88 | HKLcxx . . $ NCrystal/HKL# getEquivalentReflectionsRepresentativeValuecxx . . $ NCrystal/EqRefl#getEquivalentReflectionsRepresentativeValue(5f35448a2f042f26).( const HKLcxx . . $ NCrystal/HKL#& hkl ) const; |
| 89 | HKLcxx . . $ NCrystal/HKL# getEquivalentReflectionsRepresentativeValuecxx . . $ NCrystal/EqRefl#getEquivalentReflectionsRepresentativeValue(810ccc189fde37fd).( int h, int k, int l ) const; |
| 90 | |
| 91 | private: |
| 92 | struct Helpercxx . . $ NCrystal/EqRefl#Helper#; |
| 93 | friend struct Helpercxx . . $ NCrystal/EqRefl#Helper#; |
| 94 | EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList# (*m_calccxx . . $ NCrystal/EqRefl#m_calc.) (int,int,int) = nullptr; |
| 95 | }; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | //////////////////////////// |
| 100 | // Inline implementations // |
| 101 | //////////////////////////// |
| 102 | |
| 103 | namespace NCrystalcxx . . $ NCrystal/{ |
| 104 | |
| 105 | inline const HKLcxx . . $ NCrystal/HKL#* EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::begincxx . . $ NCrystal/EqRefl#EquivReflList#begin(6809e21b4e64c3ba).() const noexcept { return &m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0]; } |
| 106 | inline const HKLcxx . . $ NCrystal/HKL#* EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::endcxx . . $ NCrystal/EqRefl#EquivReflList#end(6809e21b4e64c3ba).() const noexcept { return m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.; } |
| 107 | inline stdcxx . . $ std/::size_tcxx . . $ std/size_t# EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::sizecxx . . $ NCrystal/EqRefl#EquivReflList#size(c9b1e749b64d5edc).() const noexcept { return stdcxx . . $ std/::distance(begincxx . . $ NCrystal/EqRefl#EquivReflList#begin(6809e21b4e64c3ba).(),endcxx . . $ NCrystal/EqRefl#EquivReflList#end(6809e21b4e64c3ba).()); } |
| 108 | inline EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#EquivReflList(49f6e7a06ebc5aa8).() { m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end. = &m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0]; } |
| 109 | |
| 110 | inline EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#EquivReflList(40ef462b6dc8c64e).( const EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& o ) |
| 111 | { |
| 112 | m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end. = &m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0]; |
| 113 | for ( auto& e : o ) |
| 114 | *m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.++ =cxx . . $ NCrystal/HKL#`operator=`(bfa454870510115a). e; |
| 115 | } |
| 116 | |
| 117 | inline EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::operatorcxx . . $ NCrystal/EqRefl#EquivReflList#`operator=`(94d869b4dd281017).=( const EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#& o ) |
| 118 | { |
| 119 | m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end. = &m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0]; |
| 120 | for ( auto& e : o ) |
| 121 | *m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.++ =cxx . . $ NCrystal/HKL#`operator=`(bfa454870510115a). e; |
| 122 | return *this; |
| 123 | } |
| 124 | |
| 125 | inline void EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::addcxx . . $ NCrystal/EqRefl#EquivReflList#add(b1146eedae1e1d0b).(int h, int k, int l) |
| 126 | { |
| 127 | //Only ever consider the form of (h,k,l) and (-h,-k,-l) which has first |
| 128 | //non-zero coordinate positive: |
| 129 | HKLcxx . . $ NCrystal/HKL# acxx . . $ NCrystal/HKL#HKL(cdc98de0e28b8e0).(h,k,l); |
| 130 | auto am = a.flippedcxx . . $ NCrystal/HKL#flipped(c4b5a659fb83616e).(); |
| 131 | *m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.++ =cxx . . $ NCrystal/HKL#`operator=`(bfa454870510115a). am <cxx . . $ NCrystal/HKL#`operator<`(dd7ed145b02d5347). a ? am : a; |
| 132 | } |
| 133 | |
| 134 | inline EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList# EqReflcxx . . $ NCrystal/EqRefl#::getEquivalentReflectionscxx . . $ NCrystal/EqRefl#getEquivalentReflections(baffda499cfa78ea).(int h, int k, int l) const |
| 135 | { |
| 136 | auto raw = m_calccxx . . $ NCrystal/EqRefl#m_calc.(h,k,l); |
| 137 | //Sort and discard duplicates: |
| 138 | stdcxx . . $ std/::sortcxx . . $ std/sort(249673c20e2b8d5).((HKLcxx . . $ NCrystal/HKL#*)&raw.m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0],raw.m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.); |
| 139 | raw.m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end. = stdcxx . . $ std/::uniquecxx . . $ std/unique(f80f7d6260b3ee3a).((HKLcxx . . $ NCrystal/HKL#*)&raw.m_datacxx . . $ NCrystal/EqRefl#EquivReflList#m_data.[0],raw.m_endcxx . . $ NCrystal/EqRefl#EquivReflList#m_end.); |
| 140 | return rawcxx . . $ NCrystal/EqRefl#EquivReflList#EquivReflList(40ef462b6dc8c64e).; |
| 141 | } |
| 142 | |
| 143 | inline HKLcxx . . $ NCrystal/HKL# EqReflcxx . . $ NCrystal/EqRefl#::getEquivalentReflectionsRepresentativeValuecxx . . $ NCrystal/EqRefl#getEquivalentReflectionsRepresentativeValue(810ccc189fde37fd).( int h, int k, int l ) const |
| 144 | { |
| 145 | auto raw = m_calccxx . . $ NCrystal/EqRefl#m_calc.(h,k,l); |
| 146 | auto itLow = raw.begincxx . . $ NCrystal/EqRefl#EquivReflList#begin(6809e21b4e64c3ba).(); |
| 147 | auto itE = raw.endcxx . . $ NCrystal/EqRefl#EquivReflList#end(6809e21b4e64c3ba).(); |
| 148 | for ( auto it = stdcxx . . $ std/::next(itLow); it!=itE; ++it ) { |
| 149 | if ( *it <cxx . . $ NCrystal/HKL#`operator<`(dd7ed145b02d5347). *itLow ) |
| 150 | itLow = it; |
| 151 | } |
| 152 | return *itLow; |
| 153 | } |
| 154 | |
| 155 | inline HKLcxx . . $ NCrystal/HKL# EqReflcxx . . $ NCrystal/EqRefl#::getEquivalentReflectionsRepresentativeValuecxx . . $ NCrystal/EqRefl#getEquivalentReflectionsRepresentativeValue(5f35448a2f042f26).( const HKLcxx . . $ NCrystal/HKL#& e ) const |
| 156 | { |
| 157 | return getEquivalentReflectionsRepresentativeValuecxx . . $ NCrystal/EqRefl#getEquivalentReflectionsRepresentativeValue(810ccc189fde37fd).( e.hcxx . . $ NCrystal/HKL#h., e.kcxx . . $ NCrystal/HKL#k., e.lcxx . . $ NCrystal/HKL#l. ); |
| 158 | } |
| 159 | |
| 160 | inline bool EqReflcxx . . $ NCrystal/EqRefl#::EquivReflListcxx . . $ NCrystal/EqRefl#EquivReflList#::containscxx . . $ NCrystal/EqRefl#EquivReflList#contains(a97afa4901f0ed54).( HKLcxx . . $ NCrystal/HKL# a ) const noexcept |
| 161 | { |
| 162 | //At worst 24 entries, often just a few handfuls => use simple linear search. |
| 163 | HKLcxx . . $ NCrystal/HKL# amcxx . . $ NCrystal/HKL#HKL(cdc98de0e28b8e0).(-a.hcxx . . $ NCrystal/HKL#h.,-a.kcxx . . $ NCrystal/HKL#k.,-a.lcxx . . $ NCrystal/HKL#l.); |
| 164 | if ( am <cxx . . $ NCrystal/HKL#`operator<`(dd7ed145b02d5347). a ) |
| 165 | a =cxx . . $ NCrystal/HKL#`operator=`(bfa454870510115a). am; |
| 166 | for ( auto& e : *this ) { |
| 167 | if ( e ==cxx . . $ NCrystal/HKL#`operator==`(dd7ed145b02d5347). a ) |
| 168 | return true; |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | #endif |