source: trunk/source/processes/hadronic/models/de_excitation/fermi_breakup/src/G4FermiIntegerPartition.cc @ 1199

Last change on this file since 1199 was 819, checked in by garnier, 16 years ago

import all except CVS

File size: 3.2 KB
Line 
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// Hadronic Process: Nuclear De-excitations
28// by V. Lara
29
30
31#include "G4FermiIntegerPartition.hh"
32
33void G4FermiIntegerPartition::Initialize(const G4int N, const G4int size)
34{
35  total = N;
36  int S(size);
37  if (!enableNull)
38    {
39      S = std::min(size,N);
40    }
41  partition.clear();
42  partition.reserve(S);
43  G4int ini(1);
44  if (enableNull)
45    {
46      ini = 0;
47      partition.push_back(total);
48    }
49  else
50    {
51      partition.push_back(total-S+1);
52    }
53  for (G4int i = 1; i < S; i++) partition.push_back(ini);
54
55#ifdef G4FermiIntegerPartition_debug
56  this->TestPartition();
57#endif
58
59  return;
60}
61
62
63G4bool G4FermiIntegerPartition::Next()
64{
65  std::vector<G4int>::iterator first = partition.begin();
66  std::vector<G4int>::iterator i = first+1;
67
68  while ( i != partition.end() && (*first) <= (*i)+1 ) i++; 
69
70  if ( i == partition.end() )
71    {
72      return false;
73    }
74  else
75    {
76      (*i)++;
77      G4int d = -1;
78      for (std::vector<G4int>::iterator j = i-1; j != first; j--)
79        {
80          d += (*j) - (*i);
81          (*j) = (*i);
82        }
83      (*first) += d;
84    }
85
86#ifdef G4FermiIntegerPartition_debug
87  this->TestPartition();
88#endif
89
90  return true;
91}
92
93#ifdef G4FermiIntegerPartition_debug
94
95void G4FermiIntegerPartition::TestPartition()
96{
97  G4int tmp = this->GetSum();
98  if (total != tmp)
99    {
100      std::cerr << "G4FermiIntegerPartition Error: " 
101                  << "Partition of " << total << " into " << partition.size()
102                  << " is [";
103      for (std::vector<G4int>::iterator it = partition.begin();
104           it != partition.end(); ++it)
105        {
106          std::cerr << *it << ',';
107        }
108      std::cerr << "\b\b] = " << tmp << '\n';
109    }
110  return;
111}
112
113#endif
Note: See TracBrowser for help on using the repository browser.