BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
material.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "material.h"
19
20#include "array.h"
21
22using namespace GMAD;
23
29
31{
32 A = 0;
33 Z = 0;
34 density = 0; //g*cm-3
35 temper = 300; //kelvin
36 pressure = 0; //atm
37 state = "solid"; //allowed values: "solid", "liquid", "gas"
38
39 components.clear();
40 componentsFractions.clear();
41 componentsWeights.clear();
42}
43
45{
46 publish("name", &Material::name);
47 publish("A", &Material::A);
48 publish("Z", &Material::Z);
49 publish("density",&Material::density);
52 publish("state", &Material::state);
53 publish("components" ,&Material::components);
54 publish("componentsWeights" ,&Material::componentsWeights);
55 publish("componentsFractions",&Material::componentsFractions);
56}
57
58void Material::print()const
59{
60 std::cout << "material: " << name << " ";
61
62 if (components.empty()) {
63 std::cout << "A= " << A << "g/mole "
64 << "Z= " << Z << " ";
65 } else {
66 std::cout << "ncomponents= " << components.size() << " ";
67 }
68 std::cout << "density= " << density << "g/cm3 "
69 << "state= " << state << " "
70 << "T= " << temper << "K "
71 << "P= " << pressure << "atm "
72 << std::endl;
73}
74
75// TODO template specialisation for Array pointers, to be merged into templated function
76void Material::set_value(const std::string& property, Array* value, bool bExit)
77{
78#ifdef BDSDEBUG
79 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << std::endl;
80#endif
81 if(property=="components")
82 {
83 value->set_vector(components);
84 }
85 else if(property=="componentsWeights")
86 {
87 value->set_vector(componentsWeights);
88 }
89 else if(property=="componentsFractions")
90 {
91 value->set_vector(componentsFractions);
92 }
93 else
94 {
95 std::cerr << "Error: parser> unknown material option \"" << property << "\", or doesn't expect vector type" << std::endl;
96 if(bExit)
97 {exit(1);}
98 else
99 {std::rethrow_exception(std::current_exception());} // to be caught by python
100 }
101}
102
103#if __cplusplus >= 201703L
104std::list<std::variant<bool, int, double, std::string>> Material::get_value_array(const std::string & property) {
105 std::list<std::variant<bool, int, double, std::string>> retval(components.size());
106
107 if(property=="components")
108 {
109 std::copy(components.begin(),components.end(), retval.begin());
110 }
111 else if(property=="componentsWeights")
112 {
113 std::copy(componentsWeights.begin(),componentsWeights.end(), retval.begin());
114 }
115 else if(property=="componentsFractions")
116 {
117 std::copy(componentsFractions.begin(),componentsFractions.end(), retval.begin());
118 }
119 else
120 {
121 std::cerr << "Error: parser> unknown material option \"" << property << "\", or doesn't expect vector type" << std::endl;
122 }
123
124 return retval;
125}
126#endif
Representation of arrays used in tokens.
Definition array.h:39
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition array.h:101
void publish(const std::string &name, T C::*mp)
Make pointer to member from class C and type T with accessible with a name.
Definition published.h:93
Parser namespace for GMAD language. Combination of Geant4 and MAD.
std::string state
"solid", "liquid", or "gas"
Definition material.h:49
Material()
constructor
Definition material.cc:24
std::list< std::variant< bool, int, double, std::string > > get_value_array(const std::string &)
Get method for lists.
Definition material.cc:104
double pressure
atm
Definition material.h:48
std::string name
name
Definition material.h:42
void set_value(const std::string &property, T value, bool bExit=true)
set methods by property name and value
Definition material.h:76
void PublishMembers()
publish members so these can be looked up from parser
Definition material.cc:44
double density
g*cm-3
Definition material.h:46
double temper
Kelvin.
Definition material.h:47
void print() const
printout
Definition material.cc:58
void clear()
reset
Definition material.cc:30
double A
g*mol^-1
Definition material.h:44