Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentComsol.hh
Go to the documentation of this file.
1#pragma once
2
4
5namespace Garfield {
6
7/// Component for importing and interpolating Comsol field maps.
8
10 public:
11 /// Default constructor.
13 /// Constructor from file names.
14 ComponentComsol(const std::string &mesh, const std::string &mplist,
15 const std::string &field, const std::string &unit = "m");
16 /// Destructor.
18
19 void SetImportRange(const double xmin, const double xmax, const double ymin,
20 const double ymax, const double zmin, const double zmax) {
21 // TODO: Must happen before initialise function
22 m_range.set = true;
23 m_range.xmin = xmin;
24 m_range.ymin = ymin;
25 m_range.zmin = zmin;
26
27 m_range.xmax = xmax;
28 m_range.ymax = ymax;
29 m_range.zmax = zmax;
30 }
31
32 /** Import a field map.
33 * \param header name of the file containing the list of nodes
34 * \param mplist name of the file containing the material properties
35 * \param field name of the file containing the potentials at the nodes
36 * \param unit length unit
37 */
38 bool Initialise(const std::string &header = "mesh.mphtxt",
39 const std::string &mplist = "dielectrics.dat",
40 const std::string &field = "field.txt",
41 const std::string &unit = "m");
42
43 /// Import the weighting potential maps.
44 bool SetWeightingPotential(const std::string &file, const std::string &label);
45 bool SetWeightingField(const std::string &file, const std::string &label) {
46 return SetWeightingPotential(file, label);
47 }
48 /// Import the time-dependent weighting field maps.
49 bool SetDynamicWeightingPotential(const std::string &file,
50 const std::string &label);
51 /// Set the time interval of the time-dependent weighting field.
52 void SetTimeInterval(const double mint, const double maxt,
53 const double stept);
54
55 private:
56 double m_unit = 100.;
57 bool m_timeset = false;
58 static constexpr double MaxNodeDistance = 1.e-8;
59
60 bool GetTimeInterval(const std::string &file);
61
62 struct Range {
63 bool set = false;
64
65 double xmin = 0;
66 double xmax = 0;
67
68 double ymin = 0;
69 double ymax = 0;
70
71 double zmin = 0;
72 double zmax = 0;
73 };
74
75 Range m_range;
76
77 bool CheckInRange(const double x, const double y, const double z) const {
78 if (!m_range.set) return true;
79
80 if (x < m_range.xmin || x > m_range.xmax || y < m_range.ymin ||
81 y > m_range.ymax || z < m_range.zmin || z > m_range.zmax)
82 return false;
83
84 return true;
85 }
86
87 bool ElementInRange(const Element& element,
88 const std::vector<Node>& nodes) const {
89 if (m_range.set) {
90 for (size_t i = 0; i < 10; i++) {
91 const Node& node = nodes[element.emap[i]];
92 if (!CheckInRange(node.x, node.y, node.z)) return false;
93 }
94 }
95 if (m_materials[element.matmap].eps != 1) return false;
96 return true;
97 }
98 bool LoadPotentials(const std::string& field,
99 std::vector<double>& pot);
100
101};
102} // namespace Garfield
bool SetWeightingPotential(const std::string &file, const std::string &label)
Import the weighting potential maps.
void SetTimeInterval(const double mint, const double maxt, const double stept)
Set the time interval of the time-dependent weighting field.
bool Initialise(const std::string &header="mesh.mphtxt", const std::string &mplist="dielectrics.dat", const std::string &field="field.txt", const std::string &unit="m")
bool SetDynamicWeightingPotential(const std::string &file, const std::string &label)
Import the time-dependent weighting field maps.
bool SetWeightingField(const std::string &file, const std::string &label)
ComponentComsol()
Default constructor.
void SetImportRange(const double xmin, const double xmax, const double ymin, const double ymax, const double zmin, const double zmax)
std::vector< Material > m_materials
ComponentFieldMap()=delete
Default constructor.