TkN 2.5
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
64tknucleus::tknucleus(int _Z) : tkproperty_list("nucleus")
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 }
101 const tknucleus &nuc = *gmanager->get_nucleus(_symbol).get();
102 (*this) = nuc;
103}
104
105void tknucleus::set_name(const char *_name)
106{
107 fSymbol = _name;
108 felement_symbol = fSymbol.extract_alpha();
109 fA = fSymbol.atoi();
110}
111
113{
114 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fZ) != fmagic_number_list.end()) return true;
115 return false;
116}
117
119{
120 if (std::find(fmagic_number_list.begin(), fmagic_number_list.end(), fN) != fmagic_number_list.end()) return true;
121 return false;
122}
123
124shared_ptr<tklevel_scheme> tknucleus::get_level_scheme()
125{
126 return gmanager->get_level_scheme(get_symbol(), get_z(), get_a());
127}
128
136double tknucleus::get_radius() const
137{
138 if (!has_property("radius")) return -1.;
139 return get("radius")->get_value();
140}
141
150{
151 if (!has_property("magnetic_dipole")) return -1.;
152 return get("magnetic_dipole")->get_value();
153}
154
163{
164 if (!has_property("electric_quadrupole")) return -1.;
165 return get("electric_quadrupole")->get_value();
166}
167
175double tknucleus::get_abundance() const
176{
177 if (!has_property("abundance")) return -1.;
178 return get("abundance")->get_value();
179}
180
189{
190 if (!has_property("mass_excess")) return std::nan("1");
191 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
192 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
193 return std::nan("1");
194 }
195 return get("mass_excess")->get_value(_unit);
196}
197
206{
207 if (!has_property("binding_energy_overA")) return std::nan("1");
208 if (gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
209 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
210 return std::nan("1");
211 }
212 return get("binding_energy_overA")->get_value(_unit);
213}
214
223{
224 if (!has_property("lifetime")) return std::nan("1");
225 if (gunits->get_type(_unit) != tkunit_manager::units_type::kTime && gunits->get_type(_unit) != tkunit_manager::units_type::kEnergy) {
226 glog << error << gunits->get_name(_unit) << " is not of 'time' or 'energy' type (returns nan(1))" << do_endl;
227 return std::nan("1");
228 }
229 return get("lifetime")->get_value(_unit);
230}
231
245double tknucleus::get_fission_yield(tkstring _parent, bool _cumulative)
246{
247 if (!_parent.begins_with("FY")) _parent.prepend("FY");
248 if (_cumulative) _parent.prepend("c");
249 if (!has_property(_parent)) return 0.;
250 return get(_parent)->get_value();
251}
252
258{
259 if (!has_property("lifetime")) return "";
260 tkstring lifetime_str;
262 if (is_stable())
263 lifetime_str = "STABLE";
264 else {
265 vector<tkunit_manager::units_keys> units{tkunit_manager::y, tkunit_manager::d, tkunit_manager::h, tkunit_manager::min,
269
270 for (auto &unit : units) {
271 double lifetime = get_lifetime(unit);
272 if (lifetime > 1.) {
273 lifetime_str = tkstring::Form("%.3g %s", lifetime, std::get<0>(tkunit_manager::funits_properties.at(unit)).data());
274 break;
275 }
276 }
277 }
278
279 return lifetime_str;
280}
281
285 * @details The ground state is defined as the first level (lowest energy) in the default dataset.
286 * @see tklevel_scheme::get_levels()
287 */
288shared_ptr<tklevel> tknucleus::get_ground_state()
289{
290 if (!get_level_scheme()->get_levels().empty())
291 return get_level_scheme()->get_levels().front();
292 return nullptr;
293}
294
300bool tknucleus::is_bound() const
301{
302 if (!has_property("binding_energy_overA")) return false;
303 return get("binding_energy_overA")->get_value() > 0;
304}
305
309 * and the ratio as a double. A ratio value of -1 means that the value or decay is uncertain
310 */
311vector<pair<tkstring, double>> tknucleus::get_decay_modes()
312{
313 vector<pair<tkstring, double>> decay_list;
314 auto decays = get_decay_mode_str();
315 auto tokkens = decays.replace_all("[", "]").tokenize("]");
316 for (auto &dec : tokkens) {
317 auto tokk = dec.tokenize(";");
318 decay_list.push_back({tokk.front(), tokk.back().atof()});
319 }
320 return decay_list;
321}
322
325
333 * [ INFO ] 12C (Z=6, N=6) properties:
334 * [ INFO ] Ground state configuration: 0+
335 * [ INFO ] Stable nucleus, abundance: 98.93 %
336 * ```
337 */
338void tknucleus::print() const
340 glog << info << fSymbol << " (Z=" << fZ << ", N=" << fN << ") properties:" << do_endl;
341 glog << info << "Ground state configuration: ";
342 if (get_jpi().is_empty())
343 glog << "Unknown" << do_endl;
344 else
345 glog << get_jpi() << do_endl;
346 if (is_stable())
347 glog << info << "Stable nucleus, abundance: " << tkstring::form("%3.2f", get_abundance()) << " %" << do_endl;
348 else {
349 glog << info << "Radioactive nucleus:" << do_endl;
351 glog << info << "Decay: " << get_property("decay_modes") << do_endl;
352 }
353}
354
355#ifdef HAS_ROOT
357ClassImp(tknucleus);
358#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:165
int get_a()
return the mass number
Definition tknucleus.h:88
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:158
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:84
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:134
void print() const
print the main nucleus properties
const tkstring & get_symbol()
return the nucleus symbol
Definition tknucleus.h:91
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:147
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)
Contains list of properties.
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
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:32
static const char * form(const char *_format,...)
Definition tkstring.cpp:452
static tkstring Form(const char *_format,...)
Definition tkstring.cpp:366
tkstring & prepend(const tkstring &_st)
Definition tkstring.h:202
bool begins_with(const char *_s, ECaseCompare _cmp=kExact) const
Definition tkstring.h:163
units_keys
units identifiers
Definition tkunit.h:46
static std::vector< std::tuple< tkstring, units_type, double > > funits_properties
Definition tkunit.h:52
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