BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
material.h
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#ifndef MATERIAL_H
20#define MATERIAL_H
21
22#include <iomanip>
23#include <iostream>
24#include <string>
25
26#include "published.h"
27
28namespace GMAD
29{
30 class Array;
31
39 struct Material : public Published<Material>{
41 std::string name;
42
43 double A;
44 double Z;
45 double density;
46 double temper;
47 double pressure;
48 std::string state;
49 std::list<std::string> components;
50 std::list<double> componentsFractions;
51 std::list<int> componentsWeights;
52
54 Material();
56 void clear();
58 void print()const;
60 template <typename T>
61 void set_value(const std::string& property, T value);
62 // Template overloading for Array pointers
64 void set_value(const std::string& property, Array* value);
65
66 private:
68 void PublishMembers();
69 };
70
71 template <typename T>
72 void Material::set_value(const std::string& property, T value)
73 {
74#ifdef BDSDEBUG
75 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
76#endif
77 // member method can throw runtime_error, catch and exit gracefully
78 try
79 {set(this,property,value);}
80 catch (const std::runtime_error&)
81 {
82 std::cerr << "Error: parser> unknown material option \"" << property << "\" with value \"" << value << "\"" << std::endl;
83 exit(1);
84 }
85 }
86}
87
88#endif
Representation of arrays used in tokens.
Definition: array.h:40
Class that provides introspection to its members.
Definition: published.h:47
void set(Material *instance, const std::string &name, double value)
Definition: published.h:99
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Material class.
Definition: material.h:39
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