TkN 2.7
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 "sqlite3.h"
16#include "tklog.h"
17#include "tkstring.h"
18#include "tkmanager.h"
19
20namespace tkn {
29}
30
31using namespace tkn;
32
33vector<int> tknucleus::fmagic_number_list{2, 8, 20, 28, 50, 82, 126};
34
40tknucleus::tknucleus(int _Z, int _A) : tkproperty_list("nucleus")
41{
42 tkstring symbol = gmanager->get_element_symbol(_Z);
43 if (symbol.empty()) {
44 glog << warning << "Unknown nucleus. No properties loaded " << tkstring::form("(%d,%d)", _Z, _A) << do_endl;
45 fZ = _Z;
46 fN = _A - _Z;
47 fA = _A;
48 return;
49 }
50 symbol.prepend(tkstring::form("%d", _A));
51 if (!gmanager->known_nucleus(symbol)) {
52 glog << warning << "Unknown nucleus. No properties loaded (" << symbol << ")" << do_endl;
53 return;
54 }
55 const tknucleus &nuc = *gmanager->get_nucleus(symbol).get(); // vérifier que ca fasse une copie et pas une reference
56 (*this) = nuc;
57}
58
65{
66 if (!gmanager->known_element(_Z))
67 glog << warning << "Unknown element. No properties loaded" << do_endl;
68 else {
69 shared_ptr<tknucleus> bestnuc;
70 for (const auto &nuc : gmanager->get_nuclei_for_z(_Z)) {
71 if (bestnuc == nullptr)
72 bestnuc = nuc;
73 else if (isnan(bestnuc->get_lifetime()) || (nuc->get_lifetime() > bestnuc->get_lifetime()))
74 bestnuc = nuc;
75 else if (nuc->get_lifetime() == bestnuc->get_lifetime() && nuc->get_abundance() > bestnuc->get_abundance())
76 bestnuc = nuc;
77 }
78 const tknucleus &nuc = *bestnuc.get();
79 (*this) = nuc;
80 }
81}
82
88tknucleus::tknucleus(const char *_symbol) : tkproperty_list("nucleus")
89{
90 if (!gmanager->known_nucleus(tkstring(_symbol))) {
91 int z;
92 if (gmanager->known_element(tkstring(_symbol), z)) {
93 if (!tkstring(_symbol).is_alpha()) {
94 glog << warning << "Unknown nucleus. TkN will choose one for you ;)" << do_endl;
95 }
96 const tknucleus nuc(z);
97 (*this) = nuc;
98 return;
99 }
100 glog << warning << "Unknown nucleus. No properties loaded (" << _symbol << ")" << do_endl;
101 return;
102 }
103 const tknucleus &nuc = *gmanager->get_nucleus(_symbol);
104 (*this) = nuc;
105}
106
107void tknucleus::set_name(const char *_name)
108{
109 fSymbol = _name;
110 felement_symbol = fSymbol.extract_alpha();
111 fA = fSymbol.atoi();
112}
113
115{
116 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fZ) != fmagic_number_list.end()) return true;
117 return false;
118}
119
121{
122 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fN) != fmagic_number_list.end()) return true;
123 return false;
124}
125
126shared_ptr<tklevel_scheme> tknucleus::get_level_scheme()
127{
128 return gmanager->get_level_scheme(get_symbol(), get_z(), get_a());
129}
130
139{
140 if (!has_property("radius")) return -1.;
141 return get("radius")->get_value();
142}
143
152{
153 if (!has_property("magnetic_dipole")) return -1.;
154 return get("magnetic_dipole")->get_value();
155}
156
165{
166 if (!has_property("electric_quadrupole")) return -1.;
167 return get("electric_quadrupole")->get_value();
168}
169
178{
179 if (!has_property("abundance")) return -1.;
180 return get("abundance")->get_value();
181}
182
191{
192 if (!has_property("mass_excess")) return std::nan("1");
193 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
194 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
195 return std::nan("1");
196 }
197 return get("mass_excess")->get_value(_unit);
198}
199
208{
209 if (!has_property("binding_energy_overA")) return std::nan("1");
210 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
211 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
212 return std::nan("1");
213 }
214 return get("binding_energy_overA")->get_value(_unit);
215}
216
225{
226 if (!has_property("lifetime")) return std::nan("1");
227 if (gunits->get_type(_unit) != tkunit_manager::units_type::kTime && gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
228 glog << error << gunits->get_name(_unit) << " is not of 'time' or 'energy' type (returns nan(1))" << do_endl;
229 return std::nan("1");
230 }
231 return get("lifetime")->get_value(_unit);
232}
233
247double tknucleus::get_fission_yield(tkstring _parent, bool _cumulative)
248{
249 if (!_parent.begins_with("FY")) _parent.prepend("FY");
250 if (_cumulative) _parent.prepend("c");
251 if (!has_property(_parent)) return 0.;
252 return get(_parent)->get_value();
253}
254
260{
261 if (!has_property("lifetime")) return "";
262 tkstring lifetime_str;
263
264 if (is_stable())
265 lifetime_str = "STABLE";
266 else {
267 vector<tkunit_manager::units_keys> units{tkunit_manager::y, tkunit_manager::d, tkunit_manager::h, tkunit_manager::min,
271
272 for (auto &unit : units) {
273 double lifetime = get_lifetime(unit);
274 if (lifetime > 1.) {
275 lifetime_str = tkstring::Form("%.3g %s", lifetime, std::get<0>(tkunit_manager::funits_properties.at(unit)).data());
276 break;
277 }
278 }
279 }
280
281 return lifetime_str;
282}
283
290shared_ptr<tklevel> tknucleus::get_ground_state()
291{
292 if (!get_level_scheme()->get_levels().empty())
293 return get_level_scheme()->get_levels().front();
294 return nullptr;
295}
296
303{
304 if (!has_property("binding_energy_overA")) return false;
305 return get("binding_energy_overA")->get_value() > 0;
306}
307
313vector<pair<tkstring, double>> tknucleus::get_decay_modes()
314{
315 vector<pair<tkstring, double>> decay_list;
316 auto decays = get_decay_mode_str();
317 auto tokkens = decays.replace_all("[", "]").tokenize("]");
318 for (auto &dec : tokkens) {
319 auto tokk = dec.tokenize(";");
320 decay_list.push_back({tokk.front(), tokk.back().atof()});
321 }
322 return decay_list;
323}
324
341{
342 glog << info << fSymbol << " (Z=" << fZ << ", N=" << fN << ") properties:" << do_endl;
343 glog << info << "Ground state configuration: ";
344 if (get_jpi().is_empty())
345 glog << "Unknown" << do_endl;
346 else
347 glog << get_jpi() << do_endl;
348 if (is_stable())
349 glog << info << "Stable nucleus, abundance: " << tkstring::form("%3.2f", get_abundance()) << " %" << do_endl;
350 else {
351 glog << info << "Radioactive nucleus:" << do_endl;
353 glog << info << "Decay: " << get_property("decay_modes") << do_endl;
354 }
355}
356
357#ifdef HAS_ROOT
359ClassImp(tknucleus);
360#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:173
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)
returns the lifetime in second
bool is_stable() const
test if the nucleus is stable
Definition tknucleus.h:166
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()
returns the lifetime in string (using the best adapted unit)
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
returns the lifetime tkmeasure object
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_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:155
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
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