Geant4  10.01.p01
G4NeutronHPChannel.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 // neutron_hp -- source file
27 // J.P. Wellisch, Nov-1996
28 // A prototype of the low energy neutron transport model.
29 //
30 // 070523 bug fix for G4FPE_DEBUG on by A. Howard ( and T. Koi)
31 // 071031 bug fix T. Koi on behalf of A. Howard
32 // 081203 bug fix in Register method by T. Koi
33 //
34 #include <stdlib.h>
35 
36 #include "G4NeutronHPChannel.hh"
37 #include "globals.hh"
38 #include "G4SystemOfUnits.hh"
39 #include "G4NeutronHPFinalState.hh"
40 #include "G4HadTmpUtil.hh"
41 
42 #include "G4NeutronHPManager.hh"
44 
46  {
47  return std::max(0., theChannelData->GetXsec(energy));
48  }
49 
51  {
52  return theIsotopeWiseData[isoNumber].GetXsec(energy);
53  }
54 
56  {
57  return theFinalStates[isoNumber]->GetXsec(energy);
58  }
59 
61  Init(G4Element * anElement, const G4String dirName, const G4String aFSType)
62  {
63  theFSType = aFSType;
64  Init(anElement, dirName);
65  }
66 
67  void G4NeutronHPChannel::Init(G4Element * anElement, const G4String dirName)
68  {
69  theDir = dirName;
70  theElement = anElement;
71  }
72 
74  {
75  registerCount++;
76  G4int Z = G4lrint(theElement->GetZ());
77 
78  Z = Z-registerCount;
79  if ( registerCount > 5 ) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material"); // for Elastic, Capture, Fission case
80  if ( Z < 1 ) return false;
81 /*
82  if(registerCount<5)
83  {
84  Z = Z-registerCount;
85  }
86 */
87  //if(Z=theElement->GetZ()-5) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material");
88  // Bug fix by TK on behalf of AH
89  if ( Z <=theElement->GetZ()-5 ) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material");
90  G4int count = 0;
91  if(registerCount==0) count = theElement->GetNumberOfIsotopes();
92  if(count == 0||registerCount!=0) count +=
94  niso = count;
95  delete [] theIsotopeWiseData;
97  delete [] active;
98  active = new G4bool[niso];
99 
100  delete [] theFinalStates;
102  delete theChannelData;
104  for(G4int i=0; i<niso; i++)
105  {
106  theFinalStates[i] = theFS->New();
107  }
108  count = 0;
109  G4int nIsos = niso;
110  if(theElement->GetNumberOfIsotopes()!=0&&registerCount==0)
111  {
112  for (G4int i1=0; i1<nIsos; i1++)
113  {
114  // G4cout <<" Init: normal case"<<G4endl;
115  G4int A = theElement->GetIsotope(i1)->GetN();
116  G4int M = theElement->GetIsotope(i1)->Getm();
118  //theFinalStates[i1]->SetA_Z(A, Z);
119  //UpdateData(A, Z, count++, frac);
120  theFinalStates[i1]->SetA_Z(A, Z, M);
121  UpdateData(A, Z, M, count++, frac);
122  }
123  } else {
124  //G4cout <<" Init: mean case: "
125  // <<theStableOnes.GetNumberOfIsotopes(Z)<<" "
126  // <<Z<<" "<<theElement
127  // << G4endl;
129  for(G4int i1=0;
131  i1++)
132  {
134  G4double frac = theStableOnes.GetAbundance(first+i1);
135  theFinalStates[i1]->SetA_Z(A, Z);
136  UpdateData(A, Z, count++, frac);
137  }
138  }
139  G4bool result = HasDataInAnyFinalState();
140 
141  //To avoid issuing hash by worker threads
142  if ( result ) theChannelData->Hash();
143 
144  return result;
145  }
146 
147  //void G4NeutronHPChannel::UpdateData(G4int A, G4int Z, G4int index, G4double abundance)
149  {
150  // Initialze the G4FissionFragment generator for this isomer if needed
152  {
154  }
155 
156  theFinalStates[index]->Init(A, Z, M, theDir, theFSType);
157  if(!theFinalStates[index]->HasAnyData()) return; // nothing there for exactly this isotope.
158 
159  // the above has put the X-sec into the FS
160  theBuffer = 0;
161  if(theFinalStates[index]->HasXsec())
162  {
163  theBuffer = theFinalStates[index]->GetXsec();
164  theBuffer->Times(abundance/100.);
166  }
167  else // get data from CrossSection directory
168  {
169  G4String tString = "/CrossSection";
170  //active[index] = theIsotopeWiseData[index].Init(A, Z, abundance, theDir, tString);
171  active[index] = theIsotopeWiseData[index].Init(A, Z, M, abundance, theDir, tString);
172  if(active[index]) theBuffer = theIsotopeWiseData[index].MakeChannelData();
173  }
175  }
176 
178  {
179  G4int s_tmp = 0, n=0, m_tmp=0;
180  G4NeutronHPVector * theMerge = new G4NeutronHPVector;
181  G4NeutronHPVector * anActive = theStore;
182  G4NeutronHPVector * aPassive = theNew;
183  G4NeutronHPVector * tmp;
184  G4int a = s_tmp, p = n, t;
185  while (a<anActive->GetVectorLength()&&p<aPassive->GetVectorLength())
186  {
187  if(anActive->GetEnergy(a) <= aPassive->GetEnergy(p))
188  {
189  G4double xa = anActive->GetEnergy(a);
190  theMerge->SetData(m_tmp, xa, anActive->GetXsec(a)+std::max(0., aPassive->GetXsec(xa)) );
191  m_tmp++;
192  a++;
193  G4double xp = aPassive->GetEnergy(p);
194  if( std::abs(std::abs(xp-xa)/xa)<0.001 )
195  {
196  p++;
197  }
198  } else {
199  tmp = anActive; t=a;
200  anActive = aPassive; a=p;
201  aPassive = tmp; p=t;
202  }
203  }
204  while (a!=anActive->GetVectorLength())
205  {
206  theMerge->SetData(m_tmp++, anActive->GetEnergy(a), anActive->GetXsec(a));
207  a++;
208  }
209  while (p!=aPassive->GetVectorLength())
210  {
211  if(std::abs(theMerge->GetEnergy(std::max(0,m_tmp-1))-aPassive->GetEnergy(p))/aPassive->GetEnergy(p)>0.001)
212  theMerge->SetData(m_tmp++, aPassive->GetEnergy(p), aPassive->GetXsec(p));
213  p++;
214  }
215  delete theStore;
216  theStore = theMerge;
217  }
218 
220 
222  ApplyYourself(const G4HadProjectile & theTrack, G4int anIsotope)
223  {
224 // G4cout << "G4NeutronHPChannel::ApplyYourself+"<<niso<<G4endl;
225  if ( anIsotope != -1 && anIsotope != -2 )
226  {
227  //Inelastic Case
228  //G4cout << "G4NeutronHPChannel Inelastic Case"
229  //<< " Z= " << this->GetZ(it) << " A = " << this->GetN(it) << G4endl;
232  return theFinalStates[anIsotope]->ApplyYourself(theTrack);
233  }
234  G4double sum=0;
235  G4int it=0;
236  G4double * xsec = new G4double[niso];
237  G4NeutronHPThermalBoost aThermalE;
238  for (G4int i=0; i<niso; i++)
239  {
240  if(theFinalStates[i]->HasAnyData())
241  {
242  xsec[i] = theIsotopeWiseData[i].GetXsec(aThermalE.GetThermalEnergy(theTrack,
243  theFinalStates[i]->GetN(),
244  theFinalStates[i]->GetZ(),
245  theTrack.GetMaterial()->GetTemperature()));
246  sum += xsec[i];
247  }
248  else
249  {
250  xsec[i]=0;
251  }
252  }
253  if(sum == 0)
254  {
255 // G4cout << "G4NeutronHPChannel::ApplyYourself theFinalState->Initialize+"<<G4endl;
256 // G4cout << "G4NeutronHPChannel::ApplyYourself theFinalState->Initialize-"<<G4endl;
257  it = static_cast<G4int>(niso*G4UniformRand());
258  }
259  else
260  {
261 // G4cout << "Are we still here? "<<sum<<G4endl;
262 // G4cout << "TESTHP 23 NISO="<<niso<<G4endl;
263  G4double random = G4UniformRand();
264  G4double running=0;
265 // G4cout << "G4NeutronHPChannel::ApplyYourself Done the sum"<<niso<<G4endl;
266 // G4cout << "TESTHP 24 NISO="<<niso<<G4endl;
267  for (G4int ix=0; ix<niso; ix++)
268  {
269  running += xsec[ix];
270  //if(random<=running/sum)
271  if( sum == 0 || random <= running/sum )
272  {
273  it = ix;
274  break;
275  }
276  }
277  if(it==niso) it--;
278  }
279  delete [] xsec;
280  G4HadFinalState * theFinalState=0;
281  const G4int A = (G4int)this->GetN(it);
282  const G4int Z = (G4int)this->GetZ(it);
283  const G4int M = (G4int)this->GetM(it);
284 
285  //-2:Marker for Fission
286  if(wendtFissionGenerator&&anIsotope==-2)
287  {
288  theFinalState = wendtFissionGenerator->ApplyYourself(theTrack, Z, A);
289  }
290 
291  // Use the standard procedure if the G4FissionFragmentGenerator model fails
292  if (!theFinalState)
293  {
294  while(theFinalState==0)
295  {
296 // G4cout << "TESTHP 24 it="<<it<<G4endl;
297  theFinalState = theFinalStates[it]->ApplyYourself(theTrack);
298  }
299  }
300 
301  //G4cout <<"THE IMPORTANT RETURN"<<G4endl;
302  //G4cout << "TK G4NeutronHPChannel Elastic, Capture and Fission Cases "
303  //<< " Z= " << this->GetZ(it) << " A = " << this->GetN(it) << G4endl;
307 
308  return theFinalState;
309  }
310 
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
G4double GetEnergy(G4int i) const
G4HadFinalState * ApplyYourself(const G4HadProjectile &projectile, G4int Z, G4int A)
void Harmonise(G4NeutronHPVector *&theStore, G4NeutronHPVector *theNew)
G4int GetVectorLength() const
virtual G4NeutronHPFinalState * New()=0
G4bool Register(G4NeutronHPFinalState *theFS)
G4double GetWeightedXsec(G4double energy, G4int isoNumber)
G4NeutronHPFinalState ** theFinalStates
G4NeutronHPVector * theChannelData
G4double GetZ(G4int i)
void Init(G4Element *theElement, const G4String dirName)
static G4NeutronHPManager * GetInstance()
G4int GetFirstIsotope(G4int Z)
G4NeutronHPReactionWhiteBoard * GetReactionWhiteBoard()
G4double GetZ() const
Definition: G4Element.hh:131
void Times(G4double factor)
G4double a
Definition: TRTMaterials.hh:39
void SetData(G4int i, G4double x, G4double y)
G4bool Init(G4int A, G4int Z, G4double abun, G4String dirName, G4String aFSType)
int G4int
Definition: G4Types.hh:78
G4NeutronHPIsoData * theIsotopeWiseData
G4NeutronHPVector * theBuffer
G4double GetN(G4int i)
G4HadFinalState * ApplyYourself(const G4HadProjectile &theTrack, G4int isoNumber=-1)
void InitializeANucleus(const G4int A, const G4int Z, const G4int M, const G4String &dataDirectory)
G4int GetN() const
Definition: G4Isotope.hh:94
#define G4UniformRand()
Definition: Randomize.hh:95
G4int Getm() const
Definition: G4Isotope.hh:100
bool G4bool
Definition: G4Types.hh:79
G4StableIsotopes theStableOnes
void UpdateData(G4int A, G4int Z, G4int index, G4double abundance)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
G4double GetXsec(G4double energy)
static const double perCent
Definition: G4SIunits.hh:296
const G4int n
static const G4double A[nN]
void SetA_Z(G4double anA, G4double aZ, G4int aM=0)
G4double GetXsec(G4double energy)
G4int GetNumberOfIsotopes(G4int Z)
G4double GetFSCrossSection(G4double energy, G4int isoNumber)
G4int GetIsotopeNucleonCount(G4int number)
void FillChannelData(G4NeutronHPVector *aBuffer)
G4double GetXsec(G4int i)
int G4lrint(double ad)
Definition: templates.hh:163
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4double GetThermalEnergy(const G4HadProjectile &aP, const G4Element *anE, G4double aT)
G4double energy(const ThreeVector &p, const G4double m)
virtual G4HadFinalState * ApplyYourself(const G4HadProjectile &)
void Init(G4double A, G4double Z, G4String &dirName, G4String &aFSType)
G4bool HasAnyData(G4int isoNumber)
G4double GetM(G4int i)
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:169
G4double GetTemperature() const
Definition: G4Material.hh:182
const G4Material * GetMaterial() const
G4double GetAbundance(G4int number)
double G4double
Definition: G4Types.hh:76
virtual G4double GetXsec(G4double)
G4NeutronHPVector * MakeChannelData()
G4WendtFissionFragmentGenerator *const wendtFissionGenerator