PLaSK library
Loading...
Searching...
No Matches
capacitance2d.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__MODULE_ELECTRICAL_CAPACITANCE2D_H
15#define PLASK__MODULE_ELECTRICAL_CAPACITANCE2D_H
16
17#include <plask/plask.hpp>
18
20
21namespace plask { namespace electrical { namespace capacitance {
22
26template <typename Geometry2DType>
27struct PLASK_SOLVER_API Capacitance2DSolver : public ComplexFemSolverWithMaskedMesh<Geometry2DType, RectangularMesh<2>> {
28 protected:
30 struct Active {
31 struct Region {
32 size_t left, right, bottom, top;
33 size_t rowl, rowr;
34 bool warn;
36 : left(0),
37 right(0),
38 bottom(std::numeric_limits<size_t>::max()),
39 top(std::numeric_limits<size_t>::max()),
40 rowl(std::numeric_limits<size_t>::max()),
41 rowr(0),
42 warn(true) {}
43 };
44 size_t left, right, bottom, top;
45 ptrdiff_t offset;
46 double height;
47 Active() : left(0), right(0), bottom(0), top(0), offset(0), height(0.) {}
48 Active(size_t tot, size_t l, size_t r, size_t b, size_t t, double h)
49 : left(l), right(r), bottom(b), top(t), offset(tot - l), height(h) {}
50 };
51
52 std::vector<Active> active;
53
57
58 double frequency = 20.;
59
61 inline void setLocalMatrix(dcomplex& k44,
62 dcomplex& k33,
63 dcomplex& k22,
64 dcomplex& k11,
65 dcomplex& k43,
66 dcomplex& k21,
67 dcomplex& k42,
68 dcomplex& k31,
69 dcomplex& k32,
70 dcomplex& k41,
71 dcomplex ky,
72 double width,
73 const Vec<2, double>& midpoint);
74
76 void onInitialize() override;
77
79 void onInvalidate() override;
80
85 size_t isActive(const Vec<2>& point) const {
86 size_t no(0);
87 auto roles = this->geometry->getRolesAt(point);
88 for (auto role : roles) {
89 size_t l = 0;
90 if (role.substr(0, 6) == "active")
91 l = 6;
92 else if (role.substr(0, 8) == "junction")
93 l = 8;
94 else
95 continue;
96 if (no != 0) throw BadInput(this->getId(), "multiple 'active'/'junction' roles specified");
97 if (role.size() == l)
98 no = 1;
99 else {
100 try {
101 no = boost::lexical_cast<size_t>(role.substr(l)) + 1;
102 } catch (boost::bad_lexical_cast&) {
103 throw BadInput(this->getId(), "bad junction number in role '{0}'", role);
104 }
105 }
106 }
107 return no;
108 }
109
111 size_t isActive(const RectangularMaskedMesh2D::Element& element) const { return isActive(element.getMidpoint()); }
112
114 void setupActiveRegions();
115
117 void setMatrix(FemMatrix<dcomplex>& A,
120
121 void loadConductivities();
122
123 Vec<2, dcomplex> getElementCurrentDensity(const RectangularMaskedMesh2D::Element& element, bool active_current = false) const;
124
125 void computeCurrentDensities();
126
127 public:
130
132
134
136
138
139 std::string getClassName() const override;
140
142 double getFrequency() const { return frequency; }
143
145 void setFrequency(double freq) {
146 frequency = freq;
147 this->invalidate();
148 }
149
155 void compute();
156
164 dcomplex integrateCurrent(size_t vindex, bool active_current = false, bool onlyactive = false) const;
165
172 dcomplex getAcCurrent(size_t nact = 0, bool active_current = false) const;
173
177 dcomplex getImpedance() const;
178
184 dcomplex getS11(dcomplex Z0 = 50.) const;
185
186 void loadConfiguration(XMLReader& source, Manager& manager) override;
187
188 void parseConfiguration(XMLReader& source, Manager& manager);
189
190 Capacitance2DSolver(const std::string& name = "");
191
193
194 protected:
195 const LazyData<dcomplex> getVoltage(shared_ptr<const MeshD<2>> dest_mesh, InterpolationMethod method) const;
196
197 const LazyData<Vec<2, dcomplex>> getCurrentDensities(shared_ptr<const MeshD<2>> dest_mesh, InterpolationMethod method);
198};
199
200}}} // namespace plask::electrical::capacitance
201
202#endif