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) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "material.h"
20
21#include "array.h"
22
23using namespace GMAD;
24
26{
27 clear();
29}
30
32{
33 A = 0;
34 Z = 0;
35 density = 0; //g*cm-3
36 temper = 300; //kelvin
37 pressure = 0; //atm
38 state = "solid"; //allowed values: "solid", "liquid", "gas"
39
40 components.clear();
41 componentsFractions.clear();
42 componentsWeights.clear();
43}
44
46{
47 publish("name", &Material::name);
48 publish("A", &Material::A);
49 publish("Z", &Material::Z);
50 publish("density",&Material::density);
53 publish("state", &Material::state);
54 publish("components" ,&Material::components);
55 publish("componentsWeights" ,&Material::componentsWeights);
56 publish("componentsFractions",&Material::componentsFractions);
57}
58
59void Material::print()const
60{
61 std::cout << "material: " << name << " ";
62
63 if (components.empty()) {
64 std::cout << "A= " << A << "g/mole "
65 << "Z= " << Z << " ";
66 } else {
67 std::cout << "ncomponents= " << components.size() << " ";
68 }
69 std::cout << "density= " << density << "g/cm3 "
70 << "state= " << state << " "
71 << "T= " << temper << "K "
72 << "P= " << pressure << "atm "
73 << std::endl;
74}
75
76// template specialisation for Array pointers, to be merged into templated function
77void Material::set_value(const std::string& property, Array* value)
78{
79#ifdef BDSDEBUG
80 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << std::endl;
81#endif
82 if(property=="components")
83 {
84 value->set_vector(components);
85 }
86 else if(property=="componentsWeights")
87 {
88 value->set_vector(componentsWeights);
89 }
90 else if(property=="componentsFractions")
91 {
92 value->set_vector(componentsFractions);
93 }
94 else
95 {
96 std::cerr << "Error: parser> unknown material option \"" << property << "\", or doesn't expect vector type" << std::endl;
97 exit(1);
98 }
99}
Representation of arrays used in tokens.
Definition: array.h:40
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition: array.h:102
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:92
Parser namespace for GMAD language. Combination of Geant4 and MAD.
std::string state
"solid", "liquid", or "gas"
Definition: material.h:48
Material()
constructor
Definition: material.cc:25
double pressure
atm
Definition: material.h:47
std::string name
name
Definition: material.h:41
void PublishMembers()
publish members so these can be looked up from parser
Definition: material.cc:45
double density
g*cm-3
Definition: material.h:45
double temper
Kelvin.
Definition: material.h:46
void print() const
printout
Definition: material.cc:59
void clear()
reset
Definition: material.cc:31
void set_value(const std::string &property, T value)
set methods by property name and value
Definition: material.h:72
double A
g*mol^-1
Definition: material.h:43