TkN 2.7.1
Toolkit for Nuclei
Loading...
Searching...
No Matches
tknucleus.cpp
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tknucleus.h"
15#include "tkstate_time.h"
16#include "tkn_sqlite3.h"
17#include "tklog.h"
18#include "tkstring.h"
19#include "tkmanager.h"
20
21namespace tkn {
30}
31
32using namespace tkn;
33
34vector<int> tknucleus::fmagic_number_list{2, 8, 20, 28, 50, 82, 126};
35
41tknucleus::tknucleus(int _Z, int _A) : tkproperty_list("nucleus")
42{
43 fZ = _Z;
44 fN = _A - _Z;
45 fA = _A;
46 tkstring symbol = gmanager->get_element_symbol(_Z);
47 if (symbol.empty()) {
48 glog << warning << "Unknown nucleus. No properties loaded " << tkstring::form("(%d,%d)", _Z, _A) << do_endl;
49 return;
50 }
51 symbol.prepend(tkstring::form("%d", _A));
52 if (!gmanager->known_nucleus(symbol)) {
53 glog << warning << "Unknown nucleus. No properties loaded (" << symbol << ")" << do_endl;
54 return;
55 }
56 const tknucleus &nuc = *gmanager->get_nucleus(symbol).get(); // vérifier que ca fasse une copie et pas une reference
57 (*this) = nuc;
58}
59
66{
67 if (!gmanager->known_element(_Z))
68 glog << warning << "Unknown element. No properties loaded" << do_endl;
69 else {
70 shared_ptr<tknucleus> bestnuc;
71 for (const auto &nuc : gmanager->get_nuclei_for_z(_Z)) {
72 if (bestnuc == nullptr)
73 bestnuc = nuc;
74 else if (isnan(bestnuc->get_lifetime()) || (nuc->get_lifetime() > bestnuc->get_lifetime()))
75 bestnuc = nuc;
76 else if (nuc->get_lifetime() == bestnuc->get_lifetime() && nuc->get_abundance() > bestnuc->get_abundance())
77 bestnuc = nuc;
78 }
79 const tknucleus &nuc = *bestnuc.get();
80 (*this) = nuc;
81 }
82}
83
89tknucleus::tknucleus(const char *_symbol) : tkproperty_list("nucleus")
90{
91 if (!gmanager->known_nucleus(tkstring(_symbol))) {
92 int z;
93 if (gmanager->known_element(tkstring(_symbol), z)) {
94 if (!tkstring(_symbol).is_alpha()) {
95 glog << warning << "Unknown nucleus. TkN will choose one for you ;)" << do_endl;
96 }
97 const tknucleus nuc(z);
98 (*this) = nuc;
99 return;
100 }
101 glog << warning << "Unknown nucleus. No properties loaded (" << _symbol << ")" << do_endl;
102 return;
103 }
104 const tknucleus &nuc = *gmanager->get_nucleus(_symbol);
105 (*this) = nuc;
106}
107
108void tknucleus::set_name(const char *_name)
109{
110 fSymbol = _name;
111 felement_symbol = fSymbol.extract_alpha();
112 fA = fSymbol.atoi();
113}
114
116{
117 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fZ) != fmagic_number_list.end()) return true;
118 return false;
119}
120
122{
123 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fN) != fmagic_number_list.end()) return true;
124 return false;
125}
126
127shared_ptr<tklevel_scheme> tknucleus::get_level_scheme()
128{
129 return gmanager->get_level_scheme(get_symbol(), get_z(), get_a());
130}
131
140{
141 if (!has_property("radius")) return -1.;
142 return get("radius")->get_value();
143}
144
153{
154 if (!has_property("magnetic_dipole")) return std::nan("1");
155 return get("magnetic_dipole")->get_value();
156}
157
166{
167 if (!has_property("electric_quadrupole")) return std::nan("1");
168 return get("electric_quadrupole")->get_value();
169}
170
179{
180 if (!has_property("abundance")) return -1.;
181 return get("abundance")->get_value();
182}
183
192{
193 if (!has_property("mass_excess")) return std::nan("1");
194 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
195 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
196 return std::nan("1");
197 }
198 return get("mass_excess")->get_value(_unit);
199}
200
209{
210 if (!has_property("binding_energy_overA")) return std::nan("1");
211 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
212 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
213 return std::nan("1");
214 }
215 return get("binding_energy_overA")->get_value(_unit);
216}
217
223{
224 return detail::state_time_value(get("lifetime"), is_stable(), unit, false);
225}
226
228{
229 return get_half_life(unit) / std::log(2.);
230}
231
233{
234 return detail::state_time_value(get("lifetime"), is_stable(), unit, true);
235}
236
238{
239 if (!has_property("lifetime")) return std::nan("1");
240 if (gunits->get_type(_unit) != tkunit_manager::units_type::kTime && gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
241 glog << error << gunits->get_name(_unit) << " is not of 'time' or 'energy' type (returns nan(1))" << do_endl;
242 return std::nan("1");
243 }
244 return get("lifetime")->get_value(_unit);
245}
246
260double tknucleus::get_fission_yield(tkstring _parent, bool _cumulative)
261{
262 if (!_parent.begins_with("FY")) _parent.prepend("FY");
263 if (_cumulative) _parent.prepend("c");
264 if (!has_property(_parent)) return 0.;
265 return get(_parent)->get_value();
266}
267
273{
274 if (!has_property("lifetime")) return "";
275 tkstring lifetime_str;
276
277 if (is_stable())
278 lifetime_str = "STABLE";
279 else {
280 vector<tkunit_manager::units_keys> units{tkunit_manager::y, tkunit_manager::d, tkunit_manager::h, tkunit_manager::min,
284
285 for (auto &unit : units) {
286 double lifetime = get_lifetime(unit);
287 if (lifetime > 1.) {
288 lifetime_str = tkstring::Form("%.3g %s", lifetime, std::get<0>(tkunit_manager::funits_properties.at(unit)).data());
289 break;
290 }
291 }
292 }
293
294 return lifetime_str;
295}
296
304shared_ptr<tklevel> tknucleus::get_ground_state()
305{
306 return get_level_scheme()->get_ground_state();
307}
308
316{
317 if (!has_property("binding_energy_overA")) return false;
318 return get("binding_energy_overA")->get_value() > 0;
319}
320
326vector<pair<tkstring, double>> tknucleus::get_decay_modes()
327{
328 vector<pair<tkstring, double>> decay_list;
329 auto decays = get_decay_mode_str();
330 auto tokkens = decays.replace_all("[", "]").tokenize("]");
331 for (auto &dec : tokkens) {
332 auto tokk = dec.tokenize(";");
333 decay_list.push_back({tokk.front(), tokk.back().atof()});
334 }
335 return decay_list;
336}
337
354{
355 glog << info << fSymbol << " (Z=" << fZ << ", N=" << fN << ") properties:" << do_endl;
356 glog << info << "Ground state configuration: ";
357 if (get_jpi().is_empty())
358 glog << "Unknown" << do_endl;
359 else
360 glog << get_jpi() << do_endl;
361 if (is_stable())
362 glog << info << "Stable nucleus, abundance: " << tkstring::form("%3.2f", get_abundance()) << " %" << do_endl;
363 else {
364 glog << info << "Radioactive nucleus:" << do_endl;
366 glog << info << "Decay: " << get_property("decay_modes") << do_endl;
367 }
368}
369
370#ifdef HAS_ROOT
372ClassImp(tknucleus);
373#endif
Represents a nucleus and provides access to its properties.
Definition tknucleus.h:50
double get_mass_excess(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::keV)
return the mass excess in keV by default
const tkstring & get_jpi() const
return the ground state spin and parity as a string
Definition tknucleus.h:180
int get_a()
return the mass number
Definition tknucleus.h:96
vector< pair< tkstring, double > > get_decay_modes()
return the decay modes as a vector of decay
double get_radius() const
returns the radius in fm
bool is_n_magic()
return true in case of n is a magic number
double get_lifetime(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::s)
double get_mean_lifetime(tkunit_manager::units_keys _unit=tkunit_manager::s)
Ground-state mean lifetime tau = T1/2 / ln(2); time units only.
bool is_stable() const
test if the nucleus is stable
Definition tknucleus.h:173
double get_abundance() const
returns the natural abundance in percent
tknucleus()
default constructor
Definition tknucleus.h:72
double get_fission_yield(tkstring _parent, bool _cumulative=false)
returns the fission yield of the current nucleus
tkstring get_lifetime_str()
Legacy formatting of T1/2 or Gamma (not mean lifetime).
double get_decay_width(tkunit_manager::units_keys _unit=tkunit_manager::keV)
Ground-state width Gamma = hbar/tau; energy units only. Stable: 0; absent: NaN.
shared_ptr< tklevel > get_ground_state()
return the ground state level (nullptr if no GS known)
bool is_z_magic()
return true in case of z is a magic number
int get_z()
return the proton number
Definition tknucleus.h:92
shared_ptr< tklevel_scheme > get_level_scheme()
return a tklevel_scheme shared pointer to the nucleus level scheme
double get_electric_quadrupole()
return the electric quadrupole moment in barn by default
shared_ptr< tkmeasure > get_lifetime_measure() const
Legacy stored measure: half-life in time units, width in energy units.
Definition tknucleus.h:142
void print() const
print the main nucleus properties
const tkstring & get_symbol()
return the nucleus symbol
Definition tknucleus.h:99
double get_half_life(tkunit_manager::units_keys _unit=tkunit_manager::s)
Ground-state half-life T1/2; time units only. Stable: +inf; absent/invalid: NaN.
double get_magnetic_dipole()
return the magnetic dipole moment in mun by default
tkstring get_decay_mode_str()
return the decay modes as a string
Definition tknucleus.h:162
double get_binding_energy_over_a(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::MeV)
returns the binding energy per mass unit in MeV
bool is_bound() const
test if the nucleus is bound (positive binding energy)
bool has_property(const tkstring &_property) const
to check if the property is available
shared_ptr< tkmeasure > get(const tkstring &_property) const
get the property as tkmeasure
tkproperty_list(tkstring _name)
tkstring get_property(const tkstring &_property) const
get the property value as a string
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
tkstring extract_alpha()
Returns a tkstring composed only of the alphabetic letters of the original tkstring.
Definition tkstring.cpp:394
static const char * form(const char *_format,...)
Definition tkstring.cpp:438
static tkstring Form(const char *_format,...)
Definition tkstring.cpp:368
int atoi() const
Converts a string to integer value.
Definition tkstring.cpp:210
tkstring & prepend(const tkstring &_st)
Definition tkstring.h:217
bool begins_with(const char *_s, ECaseCompare _cmp=kExact) const
Definition tkstring.h:166
units_keys
units identifiers
Definition tkunit.h:48
static const std::vector< std::tuple< tkstring, units_type, double > > funits_properties
Definition tkunit.h:54
double state_time_value(const shared_ptr< tkmeasure > &measure, bool stable, tkunit_manager::units_keys unit, bool width)
Definition tklog.cpp:16
tklog & info(tklog &log)
Definition tklog.h:313
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331