15 return InArea(x, y, z) ? m_medium :
nullptr;
19 const double z,
double& ex,
double& ey,
20 double& ez,
Medium*& m,
int& status) {
39 const double z,
double& ex,
double& ey,
40 double& ez,
double& v,
Medium*& m,
47 const std::array<double, 3> d = {x - m_x0, y - m_y0, z - m_z0};
48 v = m_v0 - std::inner_product(d.begin(), d.end(), m_efield.begin(), 0.);
52 std::cerr <<
m_className <<
"::ElectricField: Potential not defined.\n";
58 std::cout <<
m_className <<
"::ElectricField: No medium at ("
59 << x <<
", " << y <<
", " << z <<
").\n";
73 if (!m_hasPotential)
return false;
75 double xmin, ymin, zmin;
76 double xmax, ymax, zmax;
79 <<
" Could not determine the bounding box.\n";
83 const double pxmin = m_v0 - (xmin - m_x0) * m_efield[0];
84 const double pxmax = m_v0 - (xmax - m_x0) * m_efield[0];
85 const double pymin = m_v0 - (ymin - m_y0) * m_efield[1];
86 const double pymax = m_v0 - (ymax - m_y0) * m_efield[1];
87 const double pzmin = m_v0 - (zmin - m_z0) * m_efield[2];
88 const double pzmax = m_v0 - (zmax - m_z0) * m_efield[2];
90 p[0] = pxmin + pymin + pzmin;
91 p[1] = pxmin + pymin + pzmax;
92 p[2] = pxmin + pymax + pzmin;
93 p[3] = pxmin + pymax + pzmax;
94 p[4] = pxmax + pymin + pzmin;
95 p[5] = pxmax + pymin + pzmax;
96 p[6] = pxmax + pymax + pzmin;
97 p[7] = pxmax + pymax + pzmax;
99 for (
int i = 7; i--;) {
100 if (p[i] > vmax) vmax = p[i];
101 if (p[i] < vmin) vmin = p[i];
108 double& xmin,
double& ymin,
double& zmin,
109 double& xmax,
double& ymax,
double& zmax) {
124 const double z,
double& wx,
double& wy,
125 double& wz,
const std::string& label) {
126 if (!m_hasWeightingField || label != m_label)
return;
132 std::cout <<
m_className <<
"::WeightingField: No medium at ("
133 << x <<
", " << y <<
", " << z <<
")\n";
144 const std::string& label) {
145 if (!m_hasWeightingPotential || label != m_label)
return 0.;
149 const std::array<double, 3> d = {x - m_wx0, y - m_wy0, z - m_wz0};
150 return m_w0 - std::inner_product(d.begin(), d.end(), m_wfield.begin(), 0.);
155 m_efield = {ex, ey, ez};
156 if (ex * ex + ey * ey + ez * ez < Small) {
157 std::cerr <<
m_className <<
"::SetElectricField: Field set to zero.\n";
163 const double z,
const double v) {
168 m_hasPotential =
true;
173 const std::string label) {
175 m_wfield = {wx, wy, wz};
176 m_hasWeightingField =
true;
180 const double z,
const double v) {
181 if (!m_hasWeightingField) {
182 std::cerr <<
m_className <<
"::SetWeightingPotential:\n"
183 <<
" Set the weighting field first!\n";
190 m_hasWeightingPotential =
true;
194 const double xmin,
const double ymin,
const double zmin,
195 const double xmax,
const double ymax,
const double zmax) {
197 m_xmin[0] = std::min(xmin, xmax);
198 m_xmin[1] = std::min(ymin, ymax);
199 m_xmin[2] = std::min(zmin, zmax);
200 m_xmax[0] = std::max(xmin, xmax);
201 m_xmax[1] = std::max(ymin, ymax);
202 m_xmax[2] = std::max(zmin, zmax);
212void ComponentConstant::Reset() {
214 m_hasPotential =
false;
216 m_hasWeightingField =
false;
217 m_hasWeightingPotential =
false;
224void ComponentConstant::UpdatePeriodicity() {
226 std::cerr <<
m_className <<
"::UpdatePeriodicity:\n"
227 <<
" Periodicities are not supported.\n";
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
void SetElectricField(const double ex, const double ey, const double ez)
Set the components of the electric field [V / cm].
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
void UnsetArea()
Remove the explicit limits of the active area.
void SetArea(const double xmin, const double ymin, const double zmin, const double xmax, const double ymax, const double zmax)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void SetPotential(const double x, const double y, const double z, const double v=0.)
Specify the potential at a given point.
void SetWeightingPotential(const double x, const double y, const double z, const double v=0.)
Specify the weighting potential at a given point.
void SetWeightingField(const double wx, const double wy, const double wz, const std::string label)
Set the components of the weighting field [1 / cm].
ComponentConstant()
Constructor.
Abstract base class for components.
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
bool m_debug
Switch on/off debugging messages.
std::string m_className
Class name.
bool m_ready
Ready for use?
Abstract base class for media.
bool IsDriftable() const
Is charge carrier transport enabled in this medium?