1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 12:08:52 -05:00
catima/structures.cpp

115 lines
2.6 KiB
C++
Raw Normal View History

2017-07-25 12:19:11 -04:00
#include "structures.h"
#include "catima/nucdata.h"
2017-12-14 09:29:23 -05:00
#include <algorithm>
2020-08-05 12:20:16 -04:00
#include <cmath>
2017-07-25 12:19:11 -04:00
namespace catima{
bool operator==(const Projectile &a, const Projectile&b){
if( (a.A==b.A) && (a.Z==b.Z) && (a.Q==b.Q)){
return true;
}
else
return false;
}
bool operator==(const Material &a, const Material&b){
2020-08-05 12:20:16 -04:00
if(std::fabs(a.density() - b.density())> 1e-6)return false;
2017-07-25 12:19:11 -04:00
if(a.ncomponents() != b.ncomponents())return false;
2018-01-29 07:38:54 -05:00
if(a.I() != b.I())return false;
2017-07-25 12:19:11 -04:00
for(int i=0;i<a.ncomponents();i++){
2017-12-14 09:29:23 -05:00
if(a.atoms[i].stn != b.atoms[i].stn)return false;
2017-07-25 12:19:11 -04:00
if(a.atoms[i].A != b.atoms[i].A)return false;
if(a.atoms[i].Z != b.atoms[i].Z)return false;
}
2018-01-29 07:38:54 -05:00
if(a.molar_mass != b.molar_mass)return false;
2017-07-25 12:19:11 -04:00
return true;
}
2018-01-29 07:38:54 -05:00
2018-05-01 20:18:50 -04:00
Material::Material(std::initializer_list<std::array<double,3>>list,double _density, double _ipot, double mass):rho(_density),i_potential(_ipot){
2017-07-25 12:19:11 -04:00
std::initializer_list<std::array<double,3>>::iterator it;
2017-12-14 09:29:23 -05:00
atoms.reserve(list.size());
2017-07-25 12:19:11 -04:00
for ( it=list.begin(); it!=list.end(); ++it){
2017-12-14 09:29:23 -05:00
add_element((*it)[0],(*it)[1],(*it)[2]);
2017-07-25 12:19:11 -04:00
}
2017-12-14 09:29:23 -05:00
2018-05-01 20:18:50 -04:00
if(mass!=0.0){
molar_mass=mass;
}
else{
calculate(); // calculate if needed, ie average molar mass
}
2017-07-25 12:19:11 -04:00
}
2019-05-13 14:51:09 -04:00
Material::Material(double _a, int _z, double _rho, double _th, double _ipot):rho(_rho),th(_th),i_potential(_ipot){
2017-07-25 12:19:11 -04:00
add_element(_a,_z,1.0);
}
void Material::add_element(double _a, int _z, double _stn){
double a = (_a>0)?_a:element_atomic_weight(_z);
2017-12-14 09:29:23 -05:00
atoms.push_back({a,_z,_stn});
2017-07-25 12:19:11 -04:00
molar_mass += _stn*a;
}
void Material::calculate(){
2017-12-14 09:29:23 -05:00
if(std::all_of(atoms.begin(),atoms.end(),[](const Target &t){return t.stn<1.0;})){
double sum = 0;
for(auto& e: atoms){
sum+= e.stn/e.A;
}
molar_mass = 1.0/sum;
2017-07-25 12:19:11 -04:00
}
}
2017-12-14 09:29:23 -05:00
2017-07-25 12:19:11 -04:00
void Layers::add(Material m){
materials.push_back(m);
}
2020-08-06 09:47:39 -04:00
void Layers::add(const Layers& l){
for(auto m: l.get_materials()){
add(m);
}
}
2020-08-03 19:44:00 -04:00
double Layers::thickness() const {
double sum = 0;
for(auto &m : materials){
sum += m.thickness();
}
return sum;
}
double Layers::thickness_cm() const {
double sum = 0;
for(auto &m : materials){
sum += m.thickness_cm();
}
return sum;
}
2017-07-25 12:19:11 -04:00
Layers operator+(const Layers &a, const Layers&b){
Layers res;
for(auto &e:a.materials){
res.add(e);
}
2019-10-22 13:50:34 -04:00
2017-07-25 12:19:11 -04:00
for(auto &e:b.materials){
res.add(e);
}
return res;
}
Layers operator+(const Layers &a, const Material &m){
Layers res;
for(auto &e:a.materials){
res.add(e);
}
res.add(m);
return res;
2017-07-25 12:19:11 -04:00
}
}