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) 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#ifndef MATERIAL_H
19#define MATERIAL_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24#if __cplusplus >= 201703L
25#include <variant>
26#endif
27#include "published.h"
28
29namespace GMAD
30{
31 class Array;
32
40 struct Material : public Published<Material>{
42 std::string name;
43
44 double A;
45 double Z;
46 double density;
47 double temper;
48 double pressure;
49 std::string state;
50 std::list<std::string> components;
51 std::list<double> componentsFractions;
52 std::list<int> componentsWeights;
53
55 Material();
57 void clear();
59 void print()const;
61 template <typename T>
62 void set_value(const std::string& property, T value, bool bExit = true);
63 // Template overloading for Array pointers
65 void set_value(const std::string& property, Array* value, bool bExit = true);
67#if __cplusplus >= 201703L
68 std::list<std::variant<bool, int, double, std::string>> get_value_array(const std::string &);
69#endif
70 private:
72 void PublishMembers();
73 };
74
75 template <typename T>
76 void Material::set_value(const std::string& property, T value, bool bExit)
77 {
78#ifdef BDSDEBUG
79 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
80#endif
81 // member method can throw runtime_error, catch and exit gracefully
82 try
83 {set(this,property,value);}
84 catch (const std::runtime_error&)
85 {
86 std::cerr << "Error: parser> unknown material option \"" << property << "\" with value \"" << value << "\"" << std::endl;
87 if (bExit)
88 {exit(1);}
89 else
90 {std::rethrow_exception(std::current_exception());} // to be caught by python
91 }
92 }
93}
94
95#endif
Representation of arrays used in tokens.
Definition array.h:39
Class that provides introspection to its members.
Definition published.h:48
void set(Material *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Material class.
Definition material.h:40
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