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