CYCLUS
composition.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_COMPOSITION_H_
2 #define CYCLUS_SRC_COMPOSITION_H_
3 
4 #include <map>
5 #include <stdint.h>
6 #include <boost/shared_ptr.hpp>
7 
8 class SimInitTest;
9 
10 namespace cyclus {
11 
12 class Context;
13 
14 typedef int Nuc;
15 
16 /// a raw definition of nuclides and corresponding (dimensionless quantities).
17 typedef std::map<Nuc, double> CompMap;
18 
19 /// An immutable object responsible for holding a nuclide composition. It tracks
20 /// decay lineages to prevent duplicate calculations and output recording and is
21 /// able to record its composition data to output when told. Each composition
22 /// keeps a pointer to references to every other composition that is a result of
23 /// decaying this or a previously decayed-from composition.
24 ///
25 /// Compositions are immutable and thus their state must be created/defined
26 /// entirely at their creation. Compositions are created by passing in a
27 /// CompMap (a map of nuclides to quantities). In general CompMaps are
28 /// not assumed to be normalized to any particular value. A Uranium dioxide
29 /// composition can be created as follows:
30 ///
31 /// @code
32 /// CompMap v;
33 /// v[922350000] = 2.4;
34 /// v[80160000] = 4.8;
35 /// Composition c = Composition::CreateFromAtom(v);
36 /// @endcode
37 ///
38 class Composition {
39  friend class SimInit;
40  friend class ::SimInitTest;
41 
42  public:
43  typedef boost::shared_ptr<Composition> Ptr;
44 
45  /// Creates a new composition from v with its components having appropriate
46  /// atom-based ratios. v does not need to be normalized to any particular
47  /// value.
48  static Ptr CreateFromAtom(CompMap v);
49 
50  /// Creates a new composition from v with its components having appropriate
51  /// mass-based ratios. v does not need to be normalized to any particular
52  /// value.
53  static Ptr CreateFromMass(CompMap v);
54 
55  /// Returns a unique id associated with this composition. Note that multiple
56  /// material objects can share the same composition. Also Note that the id is
57  /// not the same for two compositions that were separately created from the
58  /// same CompMap.
59  int id();
60 
61  /// Returns the unnormalized atom composition.
62  const CompMap& atom();
63 
64  /// Returns the unnormalized mass composition.
65  const CompMap& mass();
66 
67  /// Returns a decayed version of this composition (decayed delta timesteps)
68  /// assuming a time step is 1/12 of one year in duration. This composition
69  /// remains unchanged.
70  Ptr Decay(int delta);
71 
72  /// Returns a decayed version of this composition (decayed
73  /// delta timesteps) using the seconds to timestep conversion specified.
74  Ptr Decay(int delta, uint64_t secs_per_timestep);
75 
76  /// Records the composition in output database Compositions table (if
77  /// not done previously).
78  void Record(Context* ctx);
79 
80  protected:
81  /// a chain containing compositions that are a result of decay from a common
82  /// ancestor composition. The key is the total amount of time a composition
83  /// has been decayed from its root parent.
84  typedef std::map<int, Composition::Ptr> Chain;
85 
86  typedef boost::shared_ptr<Chain> ChainPtr;
87 
88  Composition();
89 
90  ChainPtr decay_line_;
91 
92  private:
93  /// This constructor allows the creation of decayed versions of
94  /// compositions while avoiding extra memory allocations.
95  Composition(int prev_decay, ChainPtr decay_line);
96 
97  /// Performs a decay calculation and creates a new decayed composition.
98  Ptr NewDecay(int delta, uint64_t secs_per_timestep);
99 
100  static int next_id_;
101  int id_;
102  bool recorded_;
103  CompMap atom_;
104  CompMap mass_;
105 
106  /// the total time delta this composition has been decayed from its root ancestor.
107  int prev_decay_;
108 };
109 
110 } // namespace cyclus
111 
112 #endif // CYCLUS_SRC_COMPOSITION_H_
boost::shared_ptr< Composition > Ptr
Definition: composition.h:43
int id()
Returns a unique id associated with this composition.
Definition: composition.cc:38
ChainPtr decay_line_
Definition: composition.h:90
Ptr Decay(int delta)
Returns a decayed version of this composition (decayed delta timesteps) assuming a time step is 1/12 ...
Definition: composition.cc:80
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
Definition: composition.h:17
std::map< int, Composition::Ptr > Chain
a chain containing compositions that are a result of decay from a common ancestor composition...
Definition: composition.h:84
void Record(Context *ctx)
Records the composition in output database Compositions table (if not done previously).
Definition: composition.cc:84
An immutable object responsible for holding a nuclide composition.
Definition: composition.h:38
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:128
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
const CompMap & mass()
Returns the unnormalized mass composition.
Definition: composition.cc:53
Handles initialization of a simulation from the output database.
Definition: sim_init.h:24
static Ptr CreateFromAtom(CompMap v)
Creates a new composition from v with its components having appropriate atom-based ratios...
Definition: composition.cc:14
boost::shared_ptr< Chain > ChainPtr
Definition: composition.h:86
const CompMap & atom()
Returns the unnormalized atom composition.
Definition: composition.cc:42
static Ptr CreateFromMass(CompMap v)
Creates a new composition from v with its components having appropriate mass-based ratios...
Definition: composition.cc:26
int Nuc
Definition: composition.h:12