Garfield++ 3.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 m_className = "ComponentUser";
9}
10
11void ComponentUser::ElectricField(const double x, const double y,
12 const double z, double& ex, double& ey,
13 double& ez, Medium*& m, int& status) {
14 if (!m_efield) {
15 ex = ey = ez = 0.;
16 m = nullptr;
17 status = -10;
18 return;
19 }
20
21 m_efield(x, y, z, ex, ey, ez);
22 m = GetMedium(x, y, z);
23 if (!m) {
24 if (m_debug) {
25 std::cerr << m_className << "::ElectricField:\n (" << x << ", " << y
26 << ", " << z << ") is not inside a medium.\n";
27 }
28 status = -6;
29 return;
30 }
31
32 status = m->IsDriftable() ? 0 : -5;
33}
34
35void ComponentUser::ElectricField(const double x, const double y,
36 const double z, double& ex, double& ey,
37 double& ez, double& v, Medium*& m,
38 int& status) {
39 if (!m_efield) {
40 ex = ey = ez = v = 0.;
41 m = nullptr;
42 status = -10;
43 return;
44 }
45 m_efield(x, y, z, ex, ey, ez);
46
47 if (m_potential) {
48 m_potential(x, y, z, v);
49 } else {
50 v = 0.;
51 }
52
53 m = GetMedium(x, y, z);
54 if (!m) {
55 if (m_debug) {
56 std::cerr << m_className << "::ElectricField:\n (" << x << ", " << y
57 << ", " << z << ") is not inside a medium.\n";
58 }
59 status = -6;
60 return;
61 }
62
63 status = m->IsDriftable() ? 0 : -5;
64}
65
66bool ComponentUser::GetVoltageRange(double& vmin, double& vmax) {
67 vmin = vmax = 0.;
68 return false;
69}
70
71void ComponentUser::MagneticField(const double x, const double y,
72 const double z, double& bx, double& by,
73 double& bz, int& status) {
74 if (!m_bfield) {
75 bx = by = bz = 0.;
76 status = -10;
77 return;
78 }
79 m_bfield(x, y, z, bx, by, bz);
80 status = 0;
81}
82
83void ComponentUser::WeightingField(const double x, const double y,
84 const double z, double& wx, double& wy,
85 double& wz, const std::string& label) {
86 wx = wy = wz = 0.;
87 if (!m_wfield) return;
88 m_wfield(x, y, z, wx, wy, wz, label);
89}
90
91double ComponentUser::WeightingPotential(const double x, const double y,
92 const double z,
93 const std::string& label) {
94 double v = 0.;
95 if (m_wpot) m_wpot(x, y, z, v, label);
96 return v;
97}
98
99void ComponentUser::DelayedWeightingField(const double x, const double y,
100 const double z, const double t,
101 double& wx, double& wy, double& wz,
102 const std::string& label) {
103 wx = wy = wz = 0.;
104 if (m_dwfield) m_dwfield(x, y, z, t, wx, wy, wz, label);
105}
106
107void ComponentUser::SetElectricField(void (*f)(const double, const double,
108 const double, double&, double&,
109 double&)) {
110 if (!f) {
111 std::cerr << m_className << "::SetElectricField: Null pointer.\n";
112 return;
113 }
114 m_efield = f;
115 m_ready = true;
116}
117
118void ComponentUser::SetPotential(void (*f)(const double, const double,
119 const double, double&)) {
120 if (!f) {
121 std::cerr << m_className << "::SetPotential: Null pointer.\n";
122 return;
123 }
124 m_potential = f;
125}
126
127void ComponentUser::SetWeightingField(void (*f)(const double, const double,
128 const double, double&, double&,
129 double&, const std::string)) {
130 if (!f) {
131 std::cerr << m_className << "::SetWeightingField: Null pointer.\n";
132 return;
133 }
134 m_wfield = f;
135}
136
137void ComponentUser::SetWeightingPotential(void (*f)(const double, const double,
138 const double, double&,
139 const std::string)) {
140 if (!f) {
141 std::cerr << m_className << "::SetWeightingPotential: Null pointer.\n";
142 return;
143 }
144 m_wpot = f;
145}
146
148 void (*f)(const double, const double, const double, const double,
149 double&, double&, double&, const std::string)) {
150
151 if (!f) {
152 std::cerr << m_className << "::SetDelayedWeightingField: Null pointer.\n";
153 return;
154 }
155 m_dwfield = f;
156}
157
158void ComponentUser::SetMagneticField(void (*f)(const double, const double,
159 const double, double&, double&,
160 double&)) {
161 if (!f) {
162 std::cerr << m_className << "::SetMagneticField: Null pointer.\n";
163 return;
164 }
165 m_bfield = f;
166}
167
168void ComponentUser::Reset() {
169 m_efield = nullptr;
170 m_potential = nullptr;
171 m_wfield = nullptr;
172 m_wpot = nullptr;
173 m_bfield = nullptr;
174 m_ready = false;
175}
176
177void ComponentUser::UpdatePeriodicity() {
178 if (m_debug) {
179 std::cerr << m_className << "::UpdatePeriodicity:\n"
180 << " Periodicities are not supported.\n";
181 }
182}
183}
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 DelayedWeightingField(const double x, const double y, const double z, const double t, double &wx, double &wy, double &wz, const std::string &label) override
void SetMagneticField(void(*f)(const double, const double, const double, double &, double &, double &))
Set the function to be called for calculating the magnetic field.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
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 SetDelayedWeightingField(void(*f)(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 WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
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
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void SetPotential(void(*f)(const double, const double, const double, double &))
Set the function to be called for calculating the potential.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
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:13
bool IsDriftable() const
Is charge carrier transport enabled in this medium?
Definition: Medium.hh:74