mirror of
https://github.com/gwm17/Mask.git
synced 2024-11-22 10:18:50 -05:00
Finally fully applied power of polymorphic systems by reducing MaskApp to a single Run function. ReactionSystems can now be queried for a vector of their data.
This commit is contained in:
parent
1a10000556
commit
bfbe009c30
|
@ -14,6 +14,7 @@ namespace Mask {
|
|||
|
||||
bool SetNuclei(std::vector<int>& z, std::vector<int>& a) override;
|
||||
void RunSystem() override;
|
||||
const std::vector<Nucleus>& GetNuclei() override;
|
||||
|
||||
inline void SetDecay1Distribution(const std::string& filename) { decay1dist.ReadDistributionFile(filename); }
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace Mask {
|
|||
void Close();
|
||||
|
||||
void WriteHeader(RxnType rxn_type, int nsamples);
|
||||
void WriteData(std::vector<Nucleus>& data);
|
||||
void WriteData(MaskFileData& data);
|
||||
void WriteData(const std::vector<Nucleus>& data);
|
||||
void WriteData(const MaskFileData& data);
|
||||
MaskFileHeader ReadHeader();
|
||||
MaskFileData ReadData();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
inline double GetThetaCM() const { return m_theta_cm; };
|
||||
inline void SetDetected() { m_detectFlag = true; };
|
||||
inline void SetNotDetected() { m_detectFlag = false; };
|
||||
inline bool IsDetected() { return m_detectFlag; };
|
||||
inline bool IsDetected() const { return m_detectFlag; };
|
||||
|
||||
inline Nucleus& operator=(const Nucleus& rhs) {
|
||||
SetIsotope(rhs.GetZ(), rhs.GetA());
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Mask {
|
|||
|
||||
bool SetNuclei(std::vector<int>& z, std::vector<int>& a) override;
|
||||
void RunSystem() override;
|
||||
const std::vector<Nucleus>& GetNuclei() override;
|
||||
|
||||
inline void SetReactionThetaType(int type) { step1.SetEjectileThetaType(type); };
|
||||
inline const Nucleus& GetTarget() const { return step1.GetTarget(); };
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Mask {
|
|||
|
||||
virtual bool SetNuclei(std::vector<int>& z, std::vector<int>& a) = 0;
|
||||
virtual void RunSystem() = 0;
|
||||
virtual const std::vector<Nucleus>& GetNuclei() = 0;
|
||||
|
||||
void AddTargetLayer(std::vector<int>& zt, std::vector<int>& at, std::vector<int>& stoich, double thickness);
|
||||
|
||||
|
@ -66,6 +67,7 @@ namespace Mask {
|
|||
bool target_set_flag, gen_set_flag;
|
||||
int rxnLayer;
|
||||
std::string m_sys_equation;
|
||||
std::vector<Nucleus> nuclei;
|
||||
static constexpr double deg2rad = M_PI/180.0;
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Mask {
|
|||
~ThreeStepSystem();
|
||||
bool SetNuclei(std::vector<int>& z, std::vector<int>& a) override;
|
||||
void RunSystem() override;
|
||||
const std::vector<Nucleus>& GetNuclei() override;
|
||||
|
||||
inline void SetDecay1Distribution(const std::string& filename) { decay1dist.ReadDistributionFile(filename); };
|
||||
inline void SetDecay2Distribution(const std::string& filename) { decay2dist.ReadDistributionFile(filename); };
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Mask {
|
|||
~TwoStepSystem();
|
||||
bool SetNuclei(std::vector<int>& z, std::vector<int>& a) override;
|
||||
void RunSystem() override;
|
||||
const std::vector<Nucleus>& GetNuclei() override;
|
||||
|
||||
inline void SetDecay1Distribution(const std::string& filename) { decay1dist.ReadDistributionFile(filename); };
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ Z A (order is target, projectile, ejectile, break1, break3(if pure decay is targ
|
|||
1 1
|
||||
2 4
|
||||
----------Target Information----------
|
||||
NumberOfLayers: 2
|
||||
NumberOfLayers: 1
|
||||
begin_layer
|
||||
Thickness(ug/cm^2): 50
|
||||
begin_elements (Z, A, Stoich.)
|
||||
|
|
|
@ -6,11 +6,13 @@ namespace Mask {
|
|||
DecaySystem::DecaySystem() :
|
||||
ReactionSystem()
|
||||
{
|
||||
nuclei.resize(3);
|
||||
}
|
||||
|
||||
DecaySystem::DecaySystem(std::vector<int>& z, std::vector<int>& a) :
|
||||
ReactionSystem()
|
||||
{
|
||||
nuclei.resize(3);
|
||||
SetNuclei(z, a);
|
||||
}
|
||||
|
||||
|
@ -20,11 +22,20 @@ namespace Mask {
|
|||
if(z.size() != a.size() || z.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
step1.SetNuclei(z[0], a[0], 0, 0, z[1], a[1]);
|
||||
SetSystemEquation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<Nucleus>& DecaySystem::GetNuclei()
|
||||
{
|
||||
nuclei[0] = step1.GetTarget();
|
||||
nuclei[1] = step1.GetEjectile();
|
||||
nuclei[2] = step1.GetResidual();
|
||||
|
||||
return nuclei;
|
||||
}
|
||||
|
||||
void DecaySystem::LinkTarget() {
|
||||
step1.SetLayeredTarget(&target);
|
||||
|
|
204
src/MaskApp.cpp
204
src/MaskApp.cpp
|
@ -188,189 +188,37 @@ namespace Mask {
|
|||
|
||||
void MaskApp::Run() {
|
||||
std::cout<<"Running simulation..."<<std::endl;
|
||||
switch(m_rxn_type)
|
||||
if(sys == nullptr)
|
||||
{
|
||||
case RxnType::PureDecay :
|
||||
{
|
||||
RunOneStepDecay();
|
||||
break;
|
||||
}
|
||||
case RxnType::OneStepRxn :
|
||||
{
|
||||
RunOneStepRxn();
|
||||
break;
|
||||
}
|
||||
case RxnType::TwoStepRxn :
|
||||
{
|
||||
RunTwoStep();
|
||||
break;
|
||||
}
|
||||
case RxnType::ThreeStepRxn :
|
||||
{
|
||||
RunThreeStep();
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MaskFile output(m_outfile_name, MaskFile::FileType::write);
|
||||
output.WriteHeader(m_rxn_type, m_nsamples);
|
||||
|
||||
//For progress tracking
|
||||
uint32_t percent5 = 0.05*m_nsamples;
|
||||
uint32_t count = 0;
|
||||
uint32_t npercent = 0;
|
||||
|
||||
for(uint32_t i=0; i<m_nsamples; i++)
|
||||
{
|
||||
if(++count == percent5)
|
||||
{
|
||||
npercent++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent complete: "<<npercent*5<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
sys->RunSystem();
|
||||
output.WriteData(sys->GetNuclei());
|
||||
}
|
||||
|
||||
output.Close();
|
||||
|
||||
std::cout<<std::endl;
|
||||
std::cout<<"Complete."<<std::endl;
|
||||
std::cout<<"---------------------------------------------"<<std::endl;
|
||||
}
|
||||
|
||||
void MaskApp::RunOneStepRxn() {
|
||||
OneStepSystem* this_sys = dynamic_cast<OneStepSystem*>(sys);
|
||||
if(this_sys == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaskFile output(m_outfile_name, MaskFile::FileType::write);
|
||||
std::vector<Nucleus> data;
|
||||
data.resize(4);
|
||||
output.WriteHeader(m_rxn_type, m_nsamples);
|
||||
|
||||
|
||||
//For progress tracking
|
||||
uint32_t percent5 = 0.05*m_nsamples;
|
||||
uint32_t count = 0;
|
||||
uint32_t npercent = 0;
|
||||
|
||||
for(uint32_t i=0; i<m_nsamples; i++)
|
||||
{
|
||||
if(++count == percent5)
|
||||
{//Show update every 5 percent
|
||||
npercent++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent complete: "<<npercent*5<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
this_sys->RunSystem();
|
||||
data[0] = this_sys->GetTarget();
|
||||
data[1] = this_sys->GetProjectile();
|
||||
data[2] = this_sys->GetEjectile();
|
||||
data[3] = this_sys->GetResidual();
|
||||
output.WriteData(data);
|
||||
|
||||
}
|
||||
|
||||
output.Close();
|
||||
}
|
||||
|
||||
void MaskApp::RunOneStepDecay() {
|
||||
DecaySystem* this_sys = dynamic_cast<DecaySystem*>(sys);
|
||||
if(this_sys == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaskFile output(m_outfile_name, MaskFile::FileType::write);
|
||||
std::vector<Nucleus> data;
|
||||
data.resize(3);
|
||||
output.WriteHeader(m_rxn_type, m_nsamples);
|
||||
|
||||
//For progress tracking
|
||||
uint32_t percent5 = 0.05*m_nsamples;
|
||||
uint32_t count = 0;
|
||||
uint32_t npercent = 0;
|
||||
|
||||
for(uint32_t i=0; i<m_nsamples; i++)
|
||||
{
|
||||
if(++count == percent5)
|
||||
{
|
||||
npercent++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent complete: "<<npercent*5<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
this_sys->RunSystem();
|
||||
data[0] = this_sys->GetTarget();
|
||||
data[1] = this_sys->GetEjectile();
|
||||
data[2] = this_sys->GetResidual();
|
||||
output.WriteData(data);
|
||||
}
|
||||
|
||||
output.Close();
|
||||
}
|
||||
|
||||
void MaskApp::RunTwoStep() {
|
||||
|
||||
TwoStepSystem* this_sys = dynamic_cast<TwoStepSystem*>(sys);
|
||||
if(this_sys == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaskFile output(m_outfile_name, MaskFile::FileType::write);
|
||||
std::vector<Nucleus> data;
|
||||
data.resize(6);
|
||||
output.WriteHeader(m_rxn_type, m_nsamples);
|
||||
|
||||
//For progress tracking
|
||||
uint32_t percent5 = 0.05*m_nsamples;
|
||||
uint32_t count = 0;
|
||||
uint32_t npercent = 0;
|
||||
|
||||
for(uint32_t i=0; i<m_nsamples; i++)
|
||||
{
|
||||
if(++count == percent5)
|
||||
{
|
||||
npercent++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent complete: "<<npercent*5<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
this_sys->RunSystem();
|
||||
data[0] = this_sys->GetTarget();
|
||||
data[1] = this_sys->GetProjectile();
|
||||
data[2] = this_sys->GetEjectile();
|
||||
data[3] = this_sys->GetResidual();
|
||||
data[4] = this_sys->GetBreakup1();
|
||||
data[5] = this_sys->GetBreakup2();
|
||||
output.WriteData(data);
|
||||
}
|
||||
|
||||
output.Close();
|
||||
}
|
||||
|
||||
void MaskApp::RunThreeStep() {
|
||||
|
||||
ThreeStepSystem* this_sys = dynamic_cast<ThreeStepSystem*>(sys);
|
||||
if(this_sys == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaskFile output(m_outfile_name, MaskFile::FileType::write);
|
||||
std::vector<Nucleus> data;
|
||||
data.resize(8);
|
||||
output.WriteHeader(m_rxn_type, m_nsamples);
|
||||
|
||||
//For progress updating
|
||||
uint32_t percent5 = 0.05*m_nsamples;
|
||||
uint32_t count = 0;
|
||||
uint32_t npercent = 0;
|
||||
|
||||
for(uint32_t i=0; i<m_nsamples; i++)
|
||||
{
|
||||
if(++count == percent5)
|
||||
{
|
||||
npercent++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent complete: "<<npercent*5<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
this_sys->RunSystem();
|
||||
data[0] = this_sys->GetTarget();
|
||||
data[1] = this_sys->GetProjectile();
|
||||
data[2] = this_sys->GetEjectile();
|
||||
data[3] = this_sys->GetResidual();
|
||||
data[4] = this_sys->GetBreakup1();
|
||||
data[5] = this_sys->GetBreakup2();
|
||||
data[6] = this_sys->GetBreakup3();
|
||||
data[7] = this_sys->GetBreakup4();
|
||||
output.WriteData(data);
|
||||
}
|
||||
|
||||
output.Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ namespace Mask {
|
|||
return header;
|
||||
}
|
||||
|
||||
void MaskFile::WriteData(std::vector<Nucleus>& data) {
|
||||
void MaskFile::WriteData(const std::vector<Nucleus>& data) {
|
||||
|
||||
char* data_pointer;
|
||||
double datum;
|
||||
|
@ -224,7 +224,7 @@ namespace Mask {
|
|||
}
|
||||
}
|
||||
|
||||
void MaskFile::WriteData(MaskFileData& data) {
|
||||
void MaskFile::WriteData(const MaskFileData& data) {
|
||||
|
||||
char* data_pointer;
|
||||
double datum;
|
||||
|
|
|
@ -6,11 +6,13 @@ namespace Mask {
|
|||
OneStepSystem::OneStepSystem() :
|
||||
ReactionSystem()
|
||||
{
|
||||
nuclei.resize(4);
|
||||
}
|
||||
|
||||
OneStepSystem::OneStepSystem(std::vector<int>& z, std::vector<int>& a) :
|
||||
ReactionSystem()
|
||||
{
|
||||
nuclei.resize(4);
|
||||
SetNuclei(z, a);
|
||||
}
|
||||
|
||||
|
@ -25,6 +27,16 @@ namespace Mask {
|
|||
SetSystemEquation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<Nucleus>& OneStepSystem::GetNuclei()
|
||||
{
|
||||
nuclei[0] = step1.GetTarget();
|
||||
nuclei[1] = step1.GetProjectile();
|
||||
nuclei[2] = step1.GetEjectile();
|
||||
nuclei[3] = step1.GetResidual();
|
||||
|
||||
return nuclei;
|
||||
}
|
||||
|
||||
void OneStepSystem::LinkTarget() {
|
||||
step1.SetLayeredTarget(&target);
|
||||
|
|
|
@ -7,11 +7,13 @@ namespace Mask {
|
|||
ThreeStepSystem::ThreeStepSystem() :
|
||||
ReactionSystem(), m_phi2Range(0, 2.0*M_PI)
|
||||
{
|
||||
nuclei.resize(8);
|
||||
}
|
||||
|
||||
ThreeStepSystem::ThreeStepSystem(std::vector<int>& z, std::vector<int>& a) :
|
||||
ReactionSystem(), m_phi2Range(0, 2.0*M_PI)
|
||||
{
|
||||
nuclei.resize(8);
|
||||
SetNuclei(z, a);
|
||||
}
|
||||
|
||||
|
@ -34,6 +36,20 @@ namespace Mask {
|
|||
return true;
|
||||
}
|
||||
|
||||
const std::vector<Nucleus>& ThreeStepSystem::GetNuclei()
|
||||
{
|
||||
nuclei[0] = step1.GetTarget();
|
||||
nuclei[1] = step1.GetProjectile();
|
||||
nuclei[2] = step1.GetEjectile();
|
||||
nuclei[3] = step1.GetResidual();
|
||||
nuclei[4] = step2.GetEjectile();
|
||||
nuclei[5] = step2.GetResidual();
|
||||
nuclei[6] = step3.GetEjectile();
|
||||
nuclei[7] = step3.GetResidual();
|
||||
|
||||
return nuclei;
|
||||
}
|
||||
|
||||
void ThreeStepSystem::LinkTarget() {
|
||||
step1.SetLayeredTarget(&target);
|
||||
step2.SetLayeredTarget(&target);
|
||||
|
|
|
@ -7,11 +7,13 @@ namespace Mask {
|
|||
TwoStepSystem::TwoStepSystem() :
|
||||
ReactionSystem(), m_phi2Range(0, 2.0*M_PI)
|
||||
{
|
||||
nuclei.resize(6);
|
||||
}
|
||||
|
||||
TwoStepSystem::TwoStepSystem(std::vector<int>& z, std::vector<int>& a) :
|
||||
ReactionSystem(), m_phi2Range(0, 2.0*M_PI)
|
||||
{
|
||||
nuclei.resize(6);
|
||||
SetNuclei(z, a);
|
||||
}
|
||||
|
||||
|
@ -31,6 +33,18 @@ namespace Mask {
|
|||
SetSystemEquation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<Nucleus>& TwoStepSystem::GetNuclei()
|
||||
{
|
||||
nuclei[0] = step1.GetTarget();
|
||||
nuclei[1] = step1.GetProjectile();
|
||||
nuclei[2] = step1.GetEjectile();
|
||||
nuclei[3] = step1.GetResidual();
|
||||
nuclei[4] = step2.GetEjectile();
|
||||
nuclei[5] = step2.GetResidual();
|
||||
|
||||
return nuclei;
|
||||
}
|
||||
|
||||
void TwoStepSystem::LinkTarget() {
|
||||
step1.SetLayeredTarget(&target);
|
||||
|
|
Loading…
Reference in New Issue
Block a user