Garfield++ 4.0
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
4
5namespace Garfield {
6
8
9Medium* ComponentUser::GetMedium(const double x, const double y,
10 const double z) {
11
12 if (!m_hasArea) return Component::GetMedium(x, y, z);
13 return InArea(x, y, z) ? m_medium : nullptr;
14}
15
16void ComponentUser::ElectricField(const double x, const double y,
17 const double z, double& ex, double& ey,
18 double& ez, Medium*& m, int& status) {
19 if (!m_efield) {
20 ex = ey = ez = 0.;
21 m = nullptr;
22 status = -10;
23 return;
24 }
25
26 m_efield(x, y, z, ex, ey, ez);
27 m = GetMedium(x, y, z);
28 if (!m) {
29 if (m_debug) {
30 std::cerr << m_className << "::ElectricField:\n (" << x << ", " << y
31 << ", " << z << ") is not inside a medium.\n";
32 }
33 status = -6;
34 return;
35 }
36
37 status = m->IsDriftable() ? 0 : -5;
38}
39
40void ComponentUser::ElectricField(const double x, const double y,
41 const double z, double& ex, double& ey,
42 double& ez, double& v, Medium*& m,
43 int& status) {
44 if (!m_efield) {
45 ex = ey = ez = v = 0.;
46 m = nullptr;
47 status = -10;
48 return;
49 }
50 m_efield(x, y, z, ex, ey, ez);
51
52 if (m_potential) {
53 m_potential(x, y, z, v);
54 } else {
55 v = 0.;
56 }
57
58 m = GetMedium(x, y, z);
59 if (!m) {
60 if (m_debug) {
61 std::cerr << m_className << "::ElectricField:\n (" << x << ", " << y
62 << ", " << z << ") is not inside a medium.\n";
63 }
64 status = -6;
65 return;
66 }
67
68 status = m->IsDriftable() ? 0 : -5;
69}
70
71bool ComponentUser::GetVoltageRange(double& vmin, double& vmax) {
72 vmin = vmax = 0.;
73 return false;
74}
75
76void ComponentUser::MagneticField(const double x, const double y,
77 const double z, double& bx, double& by,
78 double& bz, int& status) {
79 if (!m_bfield) {
80 bx = by = bz = 0.;
81 status = -10;
82 return;
83 }
84 m_bfield(x, y, z, bx, by, bz);
85 status = 0;
86}
87
88void ComponentUser::WeightingField(const double x, const double y,
89 const double z, double& wx, double& wy,
90 double& wz, const std::string& label) {
91 wx = wy = wz = 0.;
92 if (!m_wfield) return;
93 m_wfield(x, y, z, wx, wy, wz, label);
94}
95
96double ComponentUser::WeightingPotential(const double x, const double y,
97 const double z,
98 const std::string& label) {
99 double v = 0.;
100 if (m_wpot) m_wpot(x, y, z, v, label);
101 return v;
102}
103
104void ComponentUser::DelayedWeightingField(const double x, const double y,
105 const double z, const double t,
106 double& wx, double& wy, double& wz,
107 const std::string& label) {
108 wx = wy = wz = 0.;
109 if (m_dwfield) m_dwfield(x, y, z, t, wx, wy, wz, label);
110}
111
113 double& xmin, double& ymin, double& zmin,
114 double& xmax, double& ymax, double& zmax) {
115
116 if (!m_hasArea) {
117 return Component::GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax);
118 }
119 xmin = m_xmin[0];
120 ymin = m_xmin[1];
121 zmin = m_xmin[2];
122 xmax = m_xmax[0];
123 ymax = m_xmax[1];
124 zmax = m_xmax[2];
125 return true;
126}
127
129 std::function<void(const double, const double, const double,
130 double&, double&, double&)> f) {
131 if (!f) {
132 std::cerr << m_className << "::SetElectricField: Function is empty.\n";
133 return;
134 }
135 m_efield = f;
136 m_ready = true;
137}
138
140 std::function<void(const double, const double, const double,
141 double&)> f) {
142 if (!f) {
143 std::cerr << m_className << "::SetPotential: Function is empty.\n";
144 return;
145 }
146 m_potential = f;
147}
148
150 std::function<void(const double, const double, const double,
151 double&, double&, double&, const std::string&)> f) {
152 if (!f) {
153 std::cerr << m_className << "::SetWeightingField: Function is empty.\n";
154 return;
155 }
156 m_wfield = f;
157}
158
160 std::function<void(const double, const double, const double,
161 double&, const std::string&)> f) {
162 if (!f) {
163 std::cerr << m_className << "::SetWeightingPotential: Function is empty.\n";
164 return;
165 }
166 m_wpot = f;
167}
168
170 std::function<void(const double, const double, const double, const double,
171 double&, double&, double&, const std::string&)> f) {
172
173 if (!f) {
174 std::cerr << m_className << "::SetDelayedWeightingField: Function is empty.\n";
175 return;
176 }
177 m_dwfield = f;
178}
179
181 std::function<void(const double, const double, const double,
182 double&, double&, double&)> f) {
183 if (!f) {
184 std::cerr << m_className << "::SetMagneticField: Function is empty.\n";
185 return;
186 }
187 m_bfield = f;
188}
189
191 const double xmin, const double ymin, const double zmin,
192 const double xmax, const double ymax, const double zmax) {
193
194 m_xmin[0] = std::min(xmin, xmax);
195 m_xmin[1] = std::min(ymin, ymax);
196 m_xmin[2] = std::min(zmin, zmax);
197 m_xmax[0] = std::max(xmin, xmax);
198 m_xmax[1] = std::max(ymin, ymax);
199 m_xmax[2] = std::max(zmin, zmax);
200 m_hasArea = true;
201}
202
204 m_xmin.fill(0.);
205 m_xmax.fill(0.);
206 m_hasArea = false;
207}
208
209void ComponentUser::Reset() {
210 m_efield = nullptr;
211 m_potential = nullptr;
212 m_wfield = nullptr;
213 m_wpot = nullptr;
214 m_dwfield = nullptr;
215 m_bfield = nullptr;
216 m_ready = false;
217 UnsetArea();
218 m_medium = nullptr;
219}
220
221void ComponentUser::UpdatePeriodicity() {
222 if (m_debug) {
223 std::cerr << m_className << "::UpdatePeriodicity:\n"
224 << " Periodicities are not supported.\n";
225 }
226}
227}
void DelayedWeightingField(const double x, const double y, const double z, const double t, double &wx, double &wy, double &wz, const std::string &label) override
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void UnsetArea()
Remove the explicit limits of the active area.
void SetElectricField(std::function< void(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) override
void SetWeightingPotential(std::function< void(const double, const double, const double, double &, const std::string &)>)
Set the function to be called for calculating the weighting potential.
ComponentUser()
Constructor.
Definition: ComponentUser.cc:7
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
void SetPotential(std::function< void(const double, const double, const double, double &)>)
Set the function to be called for calculating the potential.
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
Definition: ComponentUser.cc:9
void SetArea(const double xmin, const double ymin, const double zmin, const double xmax, const double ymax, const double zmax)
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void SetWeightingField(std::function< void(const double, const double, const double, double &, double &, double &, const std::string &)>)
Set the function to be called for calculating the weighting field.
void SetDelayedWeightingField(std::function< void(const double, const double, const double, const double, double &, double &, double &, const std::string &)>)
Set the function to be called for calculating the delayed weighting field.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
void SetMagneticField(std::function< void(const double, const double, const double, double &, double &, double &)>)
Set the function to be called for calculating the magnetic field.
Abstract base class for components.
Definition: Component.hh:13
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
Definition: Component.cc:99
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
Definition: Component.cc:22
bool m_debug
Switch on/off debugging messages.
Definition: Component.hh:341
std::string m_className
Class name.
Definition: Component.hh:329
bool m_ready
Ready for use?
Definition: Component.hh:338
Abstract base class for media.
Definition: Medium.hh:13
bool IsDriftable() const
Is charge carrier transport enabled in this medium?
Definition: Medium.hh:74