Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentUser.cc
Go to the documentation of this file.
1#include <iostream>
2
3#include "ComponentUser.hh"
4
5namespace Garfield {
6
9 m_efield(NULL),
10 m_potential(NULL),
11 m_wfield(NULL),
12 m_wpot(NULL),
13 m_bfield(NULL) {
14
15 m_className = "ComponentUser";
16}
17
18void ComponentUser::ElectricField(const double x, const double y,
19 const double z, double& ex, double& ey,
20 double& ez, Medium*& m, int& status) {
21
22 if (!m_efield) {
23 ex = ey = ez = 0.;
24 m = NULL;
25 status = -10;
26 return;
27 }
28
29 m_efield(x, y, z, ex, ey, ez);
30 m = GetMedium(x, y, z);
31 if (!m) {
32 if (m_debug) {
33 std::cerr << m_className << "::ElectricField:\n";
34 std::cerr << " (" << x << ", " << y << ", " << z << ")"
35 << " is not inside a medium.\n";
36 }
37 status = -6;
38 return;
39 }
40
41 if (m->IsDriftable()) {
42 status = 0;
43 } else {
44 status = -5;
45 }
46}
47
48void ComponentUser::ElectricField(const double x, const double y,
49 const double z, double& ex, double& ey,
50 double& ez, double& v, Medium*& m,
51 int& status) {
52
53 if (!m_efield) {
54 ex = ey = ez = v = 0.;
55 m = NULL;
56 status = -10;
57 return;
58 }
59 m_efield(x, y, z, ex, ey, ez);
60
61 if (m_potential) {
62 m_potential(x, y, z, v);
63 } else {
64 v = 0.;
65 }
66
67 m = GetMedium(x, y, z);
68 if (!m) {
69 if (m_debug) {
70 std::cerr << m_className << "::ElectricField:\n";
71 std::cerr << " (" << x << ", " << y << ", " << z << ")"
72 << " is not inside a medium.\n";
73 }
74 status = -6;
75 return;
76 }
77
78 if (m->IsDriftable()) {
79 status = 0;
80 } else {
81 status = -5;
82 }
83}
84
85bool ComponentUser::GetVoltageRange(double& vmin, double& vmax) {
86
87 vmin = vmax = 0.;
88 return false;
89}
90
91void ComponentUser::MagneticField(const double x, const double y,
92 const double z,
93 double& bx, double& by, double& bz,
94 int& status) {
95
96 if (!m_bfield) {
97 bx = by = bz = 0.;
98 status = -10;
99 return;
100 }
101 m_bfield(x, y, z, bx, by, bz);
102 status = 0;
103
104}
105
106void ComponentUser::WeightingField(const double x, const double y,
107 const double z, double& wx, double& wy,
108 double& wz, const std::string& label) {
109
110 wx = wy = wz = 0.;
111 if (!m_wfield) return;
112 m_wfield(x, y, z, wx, wy, wz, label);
113}
114
115double ComponentUser::WeightingPotential(const double x, const double y,
116 const double z,
117 const std::string& label) {
118
119 double v = 0.;
120 if (m_wpot) m_wpot(x, y, z, v, label);
121 return v;
122}
123
124void ComponentUser::SetElectricField(void (*f)(const double, const double,
125 const double, double&, double&,
126 double&)) {
127
128 if (!f) {
129 std::cerr << m_className << "::SetElectricField:\n Null pointer.\n";
130 return;
131 }
132 m_efield = f;
133 m_ready = true;
134}
135
136void ComponentUser::SetPotential(void (*f)(const double, const double,
137 const double, double&)) {
138
139 if (!f) {
140 std::cerr << m_className << "::SetPotential:\n Null pointer.\n";
141 return;
142 }
143 m_potential = f;
144}
145
146void ComponentUser::SetWeightingField(void (*f)(const double, const double,
147 const double, double&, double&,
148 double&, const std::string)) {
149
150 if (!f) {
151 std::cerr << m_className << "::SetWeightingField:\n Null pointer.\n";
152 return;
153 }
154 m_wfield = f;
155}
156
157void ComponentUser::SetWeightingPotential(void (*f)(const double, const double,
158 const double, double&,
159 const std::string)) {
160
161 if (!f) {
162 std::cerr << m_className << "::SetWeightingPotential:\n Null pointer.\n";
163 return;
164 }
165 m_wpot = f;
166}
167
168void ComponentUser::SetMagneticField(void (*f)(const double, const double,
169 const double, double&, double&,
170 double&)) {
171
172 if (!f) {
173 std::cerr << m_className << "::SetMagneticField:\n Null pointer.\n";
174 return;
175 }
176 m_bfield = f;
177}
178
179void ComponentUser::Reset() {
180
181 m_efield = NULL;
182 m_potential = NULL;
183 m_wfield = NULL;
184 m_wpot = NULL;
185 m_bfield = NULL;
186 m_ready = false;
187}
188
189void ComponentUser::UpdatePeriodicity() {
190
191 if (m_debug) {
192 std::cerr << m_className << "::UpdatePeriodicity:\n"
193 << " Periodicities are not supported.\n";
194 }
195}
196}
Abstract base class for components.
bool m_ready
Ready for use?
std::string m_className
Class name.
bool m_debug
Switch on/off debugging messages.
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
void SetWeightingField(void(*f)(const double, const double, const double, double &, double &, double &, const std::string))
Set the function to be called for calculating the weighting field.
void SetMagneticField(void(*f)(const double, const double, const double, double &, double &, double &))
Set the function to be called for calculating the magnetic field.
bool GetVoltageRange(double &vmin, double &vmax)
Calculate the voltage range [V].
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
void SetElectricField(void(*f)(const double, const double, const double, double &, double &, double &))
Set the function to be called for calculating the electric field.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
ComponentUser()
Constructor.
Definition: ComponentUser.cc:7
double WeightingPotential(const double x, const double y, const double z, const std::string &label)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)
void SetPotential(void(*f)(const double, const double, const double, double &))
Set the function to be called for calculating the potential.
void SetWeightingPotential(void(*f)(const double, const double, const double, double &, const std::string))
Set the function to be called for calculating the weighting potential.
Abstract base class for media.
Definition: Medium.hh:11
bool IsDriftable() const
Definition: Medium.hh:57