Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4FermiIntegerPartition.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// G4FermiBreakUpAN alternative de-excitation model
28// by A. Novikov (January 2025)
29//
30
32
33G4integerPartition::G4integerPartition(std::uint32_t number, std::uint32_t termsCount,
34 std::uint32_t base)
35 : number_(number), termsCount_(termsCount), base_(base)
36{}
37
39{
40 return {number_, termsCount_, base_};
41}
42
47
48/////////////////////////////////// ITERATOR //////////////////////////////
49
54
59
61{
62 NextPartition();
63 return *this;
64}
65
67{
68 auto copy = *this;
69 NextPartition();
70 return copy;
71}
72
74{
75 return partition_ == other.partition_;
76}
77
79{
80 return partition_ != other.partition_;
81}
82
83G4integerPartition::Iterator::Iterator(std::uint32_t number, std::uint32_t termsCount,
84 std::uint32_t base)
85 : partition_(termsCount, 0)
86{
87 // No possible partitions
88 if (number < base * termsCount || termsCount == 0 || number == 0) {
89 return;
90 }
91
92 std::fill(partition_.begin(), partition_.end(), base);
93 partition_[0] = number - base * (termsCount - 1);
94}
95
96void G4integerPartition::Iterator::NextPartition()
97{
98 std::uint32_t accumulated = 0;
99 for (auto partitionLast = std::next(partition_.begin()); partitionLast != partition_.end();
100 ++partitionLast)
101 {
102 if (partition_.front() >= *partitionLast + 2) {
103 --partition_.front();
104 ++(*partitionLast);
105
106 auto newValue = *partitionLast;
107 std::fill(std::next(partition_.begin()), partitionLast, newValue);
108 partition_.front() +=
109 accumulated - newValue * (std::distance(partition_.begin(), partitionLast) - 1);
110 return;
111 }
112 accumulated += *partitionLast;
113 }
114
115 // last partition
116 partition_.clear();
117}
bool G4bool
Definition G4Types.hh:86
Iterator(const Iterator &)=default
G4bool operator==(const Iterator &other) const
G4bool operator!=(const Iterator &other) const
G4integerPartition(std::uint32_t number, std::uint32_t termsCount, std::uint32_t base=1)