mirror of
https://github.com/gwm17/catima.git
synced 2024-11-22 18:28:51 -05:00
Layers CC
This commit is contained in:
parent
f6a3cb3993
commit
345495af29
|
@ -62,16 +62,6 @@ void Material::calculate(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Layers& Layers::operator=(const Layers& other){
|
||||
|
||||
materials.clear();
|
||||
for(auto&e : other.get_materials()){
|
||||
materials.push_back(e);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Layers::add(Material m){
|
||||
materials.push_back(m);
|
||||
}
|
||||
|
@ -81,7 +71,7 @@ Layers operator+(const Layers &a, const Layers&b){
|
|||
for(auto &e:a.materials){
|
||||
res.add(e);
|
||||
}
|
||||
|
||||
|
||||
for(auto &e:b.materials){
|
||||
res.add(e);
|
||||
}
|
||||
|
|
35
structures.h
35
structures.h
|
@ -44,7 +44,7 @@ namespace catima{
|
|||
};
|
||||
|
||||
bool operator==(const Projectile &a, const Projectile&b);
|
||||
|
||||
|
||||
/**
|
||||
* Target class is used to store constituents of the Material class
|
||||
* its just to hold A,Z data for individual atoms.
|
||||
|
@ -58,7 +58,7 @@ namespace catima{
|
|||
/**
|
||||
* Material
|
||||
* class to store Material information
|
||||
* This class defines the material with which projectile will interact.
|
||||
* This class defines the material with which projectile will interact.
|
||||
* The class store nuclei constituents, density, thickness etc.
|
||||
*/
|
||||
class Material{
|
||||
|
@ -92,20 +92,20 @@ namespace catima{
|
|||
* \endcode
|
||||
*/
|
||||
Material(std::initializer_list<std::array<double,3>>list,double _density=0.0, double ipot = 0.0, double mass=0.0);
|
||||
|
||||
|
||||
/**
|
||||
* calculates internal variables if needed
|
||||
*/
|
||||
void calculate();
|
||||
|
||||
|
||||
/**
|
||||
* add atom with mass number _a and proton number _z to the Material
|
||||
* add atom with mass number _a and proton number _z to the Material
|
||||
* @param _a - mass number of the atom, is 0 the atomic weight of element _z is taken
|
||||
* @param _z - proton number of the atom
|
||||
* @param _stn - stoichiomatric number
|
||||
*/
|
||||
void add_element(double _a, int _z, double _stn);
|
||||
|
||||
|
||||
/**
|
||||
* returns i-th element of the Material as a std::pair of Target and corresponding stoichiometric number
|
||||
* @param i - index of element to return
|
||||
|
@ -139,7 +139,7 @@ namespace catima{
|
|||
* sets molar mass of the Material
|
||||
*/
|
||||
Material& M(double mass){molar_mass=mass; return *this;}
|
||||
|
||||
|
||||
/**
|
||||
* @return returns density in g/cm^3
|
||||
*/
|
||||
|
@ -149,7 +149,7 @@ namespace catima{
|
|||
* sets density in g/cm^3
|
||||
*/
|
||||
Material& density(double val){rho = val;return *this;};
|
||||
|
||||
|
||||
/**
|
||||
* @return returns thickness in g/cm^2
|
||||
*/
|
||||
|
@ -169,7 +169,7 @@ namespace catima{
|
|||
* set the mean ionization potential, if non elemental I should be used
|
||||
*/
|
||||
Material& I(double val){i_potential = val;return *this;};
|
||||
|
||||
|
||||
/**
|
||||
* 0 if default elemental potential is used
|
||||
* @return returns ionisation potential in ev
|
||||
|
@ -187,7 +187,7 @@ namespace catima{
|
|||
* return number density of atoms of i-th element in 10^23 units
|
||||
*/
|
||||
double number_density(int i)const{
|
||||
if(i>=atoms.size())return 0.0;
|
||||
if(i>=atoms.size())return 0.0;
|
||||
return number_density()*molar_fraction(i);
|
||||
}
|
||||
|
||||
|
@ -227,14 +227,14 @@ namespace catima{
|
|||
double sigma_E=0.0;
|
||||
double sigma_a=0.0;
|
||||
double sigma_r=0.0;
|
||||
double tof=0.0;
|
||||
double tof=0.0;
|
||||
#ifdef REACTIONS
|
||||
double sp = 1.0;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* structure to store results for calculation for multiple layers of materials, ie in catima::Layers
|
||||
* structure to store results for calculation for multiple layers of materials, ie in catima::Layers
|
||||
*/
|
||||
struct MultiResult{
|
||||
std::vector<Result> results;
|
||||
|
@ -247,12 +247,11 @@ namespace catima{
|
|||
* class to store multiple material layers
|
||||
*/
|
||||
|
||||
class Layers{
|
||||
class Layers{
|
||||
private:
|
||||
std::vector<Material> materials;
|
||||
public:
|
||||
Layers(){};
|
||||
Layers& operator=(const Layers& other);
|
||||
Layers() = default;
|
||||
|
||||
/**
|
||||
* @return reference to the std::vector of stored Materials
|
||||
|
@ -261,7 +260,7 @@ namespace catima{
|
|||
|
||||
/**
|
||||
* add Material m to the Layers
|
||||
* @param m Material
|
||||
* @param m Material
|
||||
*/
|
||||
void add(Material m);
|
||||
|
||||
|
@ -269,11 +268,11 @@ namespace catima{
|
|||
* @return number of stored Materials
|
||||
*/
|
||||
int num()const{return materials.size();};
|
||||
|
||||
|
||||
Material& operator[](int i){return materials[i];}
|
||||
|
||||
friend Layers operator+(const Layers &a, const Layers&b);
|
||||
|
||||
|
||||
friend Layers operator+(const Layers &a, const Material&b);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,31 +7,20 @@ using namespace std;
|
|||
#include "catima/catima.h"
|
||||
#include "catima/material_database.h"
|
||||
|
||||
bool rcompare(double a, double b,double eps){
|
||||
if(fabs((a-b)/fabs(b))<eps){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
std::cout<<"\033[1;31m"<<a<<" == "<<b<<"\033[0m"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("atima material basic tests"){
|
||||
catima::Material water({
|
||||
{1,1,2},
|
||||
{16,8,1}
|
||||
});
|
||||
|
||||
|
||||
catima::Material water2;
|
||||
water2.add_element(1,1,2);
|
||||
water2.add_element(16,8,1);
|
||||
|
||||
|
||||
catima::Material graphite;
|
||||
graphite.add_element(12,6,1);
|
||||
graphite.density(1.8);
|
||||
|
||||
|
||||
CHECK(graphite.ncomponents()==1);
|
||||
CHECK(water.ncomponents()==2);
|
||||
|
||||
|
@ -39,13 +28,13 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(water.ncomponents()==2);
|
||||
CHECK(water.M()==18);
|
||||
CHECK(water2.ncomponents()==2);
|
||||
CHECK(water2.M()==18);
|
||||
CHECK(graphite.I()==0.0);
|
||||
|
||||
CHECK(water2.M()==18);
|
||||
CHECK(graphite.I()==0.0);
|
||||
|
||||
graphite.add_element(18,40,1);
|
||||
CHECK(graphite.ncomponents()==2);
|
||||
CHECK_FALSE(graphite.M()==approx(12,0.1));
|
||||
|
||||
CHECK_FALSE(graphite.M()==approx(12,0.1));
|
||||
|
||||
CHECK(water==water2);
|
||||
CHECK(!(water==graphite));
|
||||
water.density(1.0);
|
||||
|
@ -84,7 +73,7 @@ bool rcompare(double a, double b,double eps){
|
|||
water2.add_element(1,1,2);
|
||||
water2.add_element(16,8,1);
|
||||
water2.density(1.0).thickness(2.0);
|
||||
|
||||
|
||||
catima::Material graphite;
|
||||
graphite.add_element(12,6,1);
|
||||
graphite.density(1.8).thickness(1.0);
|
||||
|
@ -119,7 +108,7 @@ bool rcompare(double a, double b,double eps){
|
|||
|
||||
catima::Layers focal_material = detector1 + detector2;
|
||||
CHECK(focal_material.num() == 8);
|
||||
|
||||
|
||||
}
|
||||
TEST_CASE("basic projectile tests"){
|
||||
catima::Projectile p{12,6,6,1000};
|
||||
|
@ -127,7 +116,7 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(p.Z==6);
|
||||
CHECK(p.Q==6);
|
||||
CHECK(p.T==1000);
|
||||
|
||||
|
||||
catima::Projectile p2(12,6);
|
||||
CHECK(p.A==12);
|
||||
CHECK(p2.Z==6);
|
||||
|
@ -139,7 +128,7 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(p2.T==500);
|
||||
|
||||
catima::Projectile p3(12,6,5);
|
||||
|
||||
|
||||
CHECK(p==p2);
|
||||
CHECK( !(p==p3));
|
||||
}
|
||||
|
@ -153,12 +142,12 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(c1==c2);
|
||||
CHECK( !(c1==c3));
|
||||
CHECK(c1==c4);
|
||||
|
||||
|
||||
c4.z_effective = catima::z_eff_type::global;
|
||||
CHECK(!(c1==c4));
|
||||
auto c5 = c4;
|
||||
CHECK(c4==c5);
|
||||
|
||||
|
||||
c4.z_effective = catima::z_eff_type::hubert;
|
||||
CHECK(!(c4==c5) );
|
||||
CHECK(!(c4==c1));
|
||||
|
@ -184,7 +173,7 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(mat5.get_element(0).Z==6);
|
||||
CHECK(mat5.get_element(1).A==16.0);
|
||||
CHECK(mat5.get_element(1).stn==2);
|
||||
|
||||
|
||||
catima::Material mat6;
|
||||
mat6 = mat5;
|
||||
CHECK(mat5==mat6);
|
||||
|
@ -194,8 +183,8 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(mat5.get_element(1).A==mat6.get_element(1).A);
|
||||
mat5.add_element(12,6,1);
|
||||
CHECK(mat5.ncomponents()==mat6.ncomponents()+1);
|
||||
|
||||
// constructor with custom Ipot
|
||||
|
||||
// constructor with custom Ipot
|
||||
catima::Material water1({
|
||||
{1,1,2},
|
||||
{16,8,1}
|
||||
|
@ -207,10 +196,10 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(water1.ncomponents()==2);
|
||||
CHECK(water2.ncomponents()==2);
|
||||
CHECK(water1.density()==1.0);
|
||||
CHECK(water2.density()==1.0);
|
||||
CHECK(water1.I()==0.0);
|
||||
CHECK(water2.I()==78.0);
|
||||
CHECK_FALSE(water1==water2);
|
||||
CHECK(water2.density()==1.0);
|
||||
CHECK(water1.I()==0.0);
|
||||
CHECK(water2.I()==78.0);
|
||||
CHECK_FALSE(water1==water2);
|
||||
|
||||
}
|
||||
TEST_CASE("fraction vs stn init"){
|
||||
|
@ -286,7 +275,7 @@ bool rcompare(double a, double b,double eps){
|
|||
c.thickness_cm(2.0);
|
||||
CHECK(c.number_density()==approx(1.7662,0.01));
|
||||
CHECK(c.number_density_cm2()==approx(2.0*1.7662,0.01));
|
||||
|
||||
|
||||
water.thickness_cm(1.0);
|
||||
CHECK(water.number_density()==approx(0.3336,0.001));
|
||||
CHECK(water.number_density_cm2()==approx(0.3336,0.001));
|
||||
|
@ -296,7 +285,7 @@ bool rcompare(double a, double b,double eps){
|
|||
CHECK(water.number_density_cm2(1)==approx(0.3336,0.001));
|
||||
water.thickness_cm(3.0);
|
||||
CHECK(water.number_density_cm2()==approx(3.0*0.3336,0.001));
|
||||
|
||||
|
||||
air.thickness_cm(1.0);
|
||||
CHECK(air.number_density(0)==approx(air.molar_fraction(0)*2*0.0002504,0.00001));
|
||||
CHECK(air.number_density(1)==approx(air.molar_fraction(1)*2*0.0002504,0.00001));
|
||||
|
|
Loading…
Reference in New Issue
Block a user