Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4INCLINuclearPotential.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 // INCL++ intra-nuclear cascade model
27 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28 // Davide Mancusi, CEA
29 // Alain Boudard, CEA
30 // Sylvie Leray, CEA
31 // Joseph Cugnon, University of Liege
32 //
33 #define INCLXX_IN_GEANT4_MODE 1
34 
35 #include "globals.hh"
36 
37 /** \file G4INCLINuclearPotential.cc
38  * \brief Abstract interface to the nuclear potential.
39  *
40  * NuclearPotential-like classes should provide access to the value of the
41  * potential of a particle in a particular context. For example, an instance of
42  * a NuclearPotential class should be associated to every nucleus.
43  *
44  * \date 31 March 2011
45  * \author Davide Mancusi
46  */
47 
53 
54 namespace G4INCL {
55 
56  namespace NuclearPotential {
57 
58  const G4double INuclearPotential::vPionDefault = 30.6; // MeV
59 
60  namespace {
61 
62  G4ThreadLocal std::map<long,INuclearPotential const *> *nuclearPotentialCache = NULL;
63 
64  }
65 
66  INuclearPotential const *createPotential(const PotentialType type, const G4int theA, const G4int theZ, const G4bool pionPotential) {
67  if(!nuclearPotentialCache)
68  nuclearPotentialCache = new std::map<long,INuclearPotential const *>;
69 
70  const long nuclideID = (pionPotential ? 1 : -1) * (1000*theZ + theA + 1000000*type); // MCNP-style nuclide IDs
71  const std::map<long,INuclearPotential const *>::const_iterator mapEntry = nuclearPotentialCache->find(nuclideID);
72  if(mapEntry == nuclearPotentialCache->end()) {
73  INuclearPotential const *thePotential = NULL;
74  switch(type) {
76  thePotential = new NuclearPotentialEnergyIsospinSmooth(theA, theZ, pionPotential);
77  break;
79  thePotential = new NuclearPotentialEnergyIsospin(theA, theZ, pionPotential);
80  break;
81  case IsospinPotential:
82  thePotential = new NuclearPotentialIsospin(theA, theZ, pionPotential);
83  break;
84  case ConstantPotential:
85  thePotential = new NuclearPotentialConstant(theA, theZ, pionPotential);
86  break;
87  default:
88  INCL_FATAL("Unrecognized potential type at Nucleus creation." << std::endl);
89  break;
90  }
91  (*nuclearPotentialCache)[nuclideID] = thePotential;
92  return thePotential;
93  } else {
94  return mapEntry->second;
95  }
96  }
97 
98  void clearCache() {
99  if(nuclearPotentialCache) {
100  for(std::map<long,INuclearPotential const *>::const_iterator i = nuclearPotentialCache->begin(), e=nuclearPotentialCache->end(); i!=e; ++i)
101  delete i->second;
102  nuclearPotentialCache->clear();
103  delete nuclearPotentialCache;
104  nuclearPotentialCache = NULL;
105  }
106  }
107 
108  } // namespace NuclearPotential
109 
110 } // namespace G4INCL
111 
#define INCL_FATAL(x)
Isospin- and energy-dependent nuclear potential.
Abstract interface to the nuclear potential.
#define G4ThreadLocal
Definition: tls.hh:52
Isospin- and energy-dependent nuclear potential.
int G4int
Definition: G4Types.hh:78
void clearCache()
Clear the INuclearPotential cache.
bool G4bool
Definition: G4Types.hh:79
Isospin-dependent nuclear potential.
Isospin- and energy-independent nuclear potential.
double G4double
Definition: G4Types.hh:76
INuclearPotential const * createPotential(const PotentialType type, const G4int theA, const G4int theZ, const G4bool pionPotential)
Create an INuclearPotential object.