Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentUser.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_USER_H
2#define G_COMPONENT_USER_H
3
4#include <functional>
5#include <map>
6
7#include "Component.hh"
8
9namespace Garfield {
10
11/// Simple component with electric field given by a user function.
12
13class ComponentUser : public Component {
14 public:
15 /// Constructor
17 /// Destructor
19
20 /// Set the function to be called for calculating the electric field.
22 std::function<void(const double, const double, const double,
23 double&, double&, double&)>);
24 /// Set the expression to be used for calculating the electric field.
25 void SetElectricField(const std::string& expression);
26
27 /// Set the function to be called for calculating the electric potential.
28 void SetPotential(
29 std::function<double(const double, const double, const double)>);
30 /// Set the expression to be used for calculating the electric potential.
31 void SetPotential(const std::string& expression);
32
33 /// Set the function to be called for calculating the weighting field.
35 std::function<void(const double, const double, const double,
36 double&, double&, double&)>,
37 const std::string& label);
38 /// Set the expression to be used for calculating the weighting field.
39 void SetWeightingField(const std::string& expression,
40 const std::string& label);
41
42 /// Set the function to be called for calculating the weighting potential.
44 std::function<double(const double, const double, const double)>,
45 const std::string& label);
46 /// Set the expression to be used for calculating the weighting potential.
47 void SetWeightingPotential(const std::string& expression,
48 const std::string& label);
49
50 /// Set the function to be called for calculating the delayed weighting field.
52 std::function<void(const double, const double, const double,
53 const double,
54 double&, double&, double&)>,
55 const std::string& label);
56 /// Set the expression to be used for calculating the delayed weighting field.
57 void SetDelayedWeightingField(const std::string& expression,
58 const std::string& label);
59
60 /// Set the function to be called for calculating
61 /// the delayed weighting potential.
63 std::function<double(const double, const double, const double,
64 const double)>,
65 const std::string& label);
66 /// Set the expression to be used for calculating
67 /// the delayed weighting potential.
68 void SetDelayedWeightingPotential(const std::string& expression,
69 const std::string& label);
70
71 /// Set the function to be called for calculating the magnetic field.
73 std::function<void(const double, const double, const double,
74 double&, double&, double&)>);
75 /// Set the expression to be used for calculating the magnetic field.
76 void SetMagneticField(const std::string& expression);
77
78 /// Set the limits of the active area explicitly
79 /// (instead of using a Geometry object).
80 void SetArea(const double xmin, const double ymin, const double zmin,
81 const double xmax, const double ymax, const double zmax);
82 /// Remove the explicit limits of the active area.
83 void UnsetArea();
84 /// Set the medium in the active area.
85 void SetMedium(Medium* medium) { m_medium = medium; }
86
87 Medium* GetMedium(const double x, const double y, const double z) override {
88 return !m_hasArea ? Component::GetMedium(x, y, z) :
89 InArea(x, y, z) ? m_medium : nullptr;
90 }
91 void ElectricField(const double x, const double y, const double z, double& ex,
92 double& ey, double& ez, Medium*& m, int& status) override;
93 void ElectricField(const double x, const double y, const double z, double& ex,
94 double& ey, double& ez, double& v, Medium*& m,
95 int& status) override;
97 bool GetVoltageRange(double& vmin, double& vmax) override;
98 void MagneticField(const double x, const double y, const double z, double& bx,
99 double& by, double& bz, int& status) override;
100 void WeightingField(const double x, const double y, const double z,
101 double& wx, double& wy, double& wz,
102 const std::string& label) override;
103 double WeightingPotential(const double x, const double y, const double z,
104 const std::string& label) override;
105 void DelayedWeightingField(const double x, const double y, const double z,
106 const double t, double& wx, double& wy, double& wz,
107 const std::string& label) override;
108 double DelayedWeightingPotential(const double x, const double y,
109 const double z, const double t,
110 const std::string& label) override;
111 bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
112 double& xmax, double& ymax, double& zmax) override;
113
114 bool HasMagneticField() const override;
115
116 private:
117 /// Electric field function.
118 std::function<void(const double, const double, const double,
119 double&, double&, double&)> m_efield;
120 /// Electric potential function.
121 std::function<double(const double, const double, const double)> m_epot;
122
123 /// Weighting field functions.
124 std::map<std::string,
125 std::function<void(const double, const double, const double,
126 double&, double&, double&)> > m_wfield;
127
128 /// Weighting potential functions.
129 std::map<std::string,
130 std::function<double(const double, const double, const double)>
131 > m_wpot;
132
133 /// Delayed weighting field functions.
134 std::map<std::string,
135 std::function<void(const double, const double, const double,
136 const double,
137 double&, double&, double&)> > m_dwfield;
138
139 /// Delayed weighting potential functions.
140 std::map<std::string,
141 std::function<double(const double, const double, const double,
142 const double)> > m_dwpot;
143
144 /// Magnetic field function
145 std::function<void(const double, const double, const double,
146 double&, double&, double&)> m_bfield;
147
148 // Active area.
149 std::array<double, 3> m_xmin = {{0., 0., 0.}};
150 std::array<double, 3> m_xmax = {{0., 0., 0.}};
151 // Did we specify the active area explicitly?
152 bool m_hasArea = false;
153 // Medium in the active area.
154 Medium* m_medium = nullptr;
155
156 /// Reset the component
157 void Reset() override;
158 // Verify periodicities
159 void UpdatePeriodicity() override;
160
161 bool InArea(const double x, const double y, const double z) {
162 return (x >= m_xmin[0] && x <= m_xmax[0] &&
163 y >= m_xmin[1] && y <= m_xmax[1] &&
164 z >= m_xmin[2] && z <= m_xmax[2]);
165 }
166
167};
168}
169#endif
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 SetDelayedWeightingPotential(std::function< double(const double, const double, const double, const double)>, const std::string &label)
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 SetDelayedWeightingField(std::function< void(const double, const double, const double, const double, double &, double &, double &)>, const std::string &label)
Set the function to be called for calculating the delayed weighting field.
double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label) override
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 SetMedium(Medium *medium)
Set the medium in the active area.
ComponentUser()
Constructor.
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
void SetWeightingPotential(std::function< double(const double, const double, const double)>, const std::string &label)
Set the function to be called for calculating the weighting potential.
void SetPotential(std::function< double(const double, const double, const double)>)
Set the function to be called for calculating the electric potential.
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
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].
bool HasMagneticField() const override
Does the component have a non-zero magnetic field?
void SetWeightingField(std::function< void(const double, const double, const double, double &, double &, double &)>, const std::string &label)
Set the function to be called for calculating the 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.
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
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:24
Component()=delete
Default constructor.
Abstract base class for media.
Definition Medium.hh:16