-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gate.m
202 lines (157 loc) · 7.86 KB
/
Gate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
classdef Gate < comsolkit.Layer
% Gate extends layer with electric potential functionality.
properties(Dependent)
voltage % Voltage applied to the gate.
potential % Handle to the electric potential feature of Gate.
end
properties(Constant)
BASE_TAG_POTENTIAL = 'layer_pot'; % Base potential string.
BASE_TAG_FLOATING = 'layer_fp'; % Base floating potential string.
FLOATING_NAME_PREFIX = 'fp_'; % Prefix of floating potential label.
end
properties(Access=private)
potentialTag % Tag to the electrostatic potential of the gate.
floatingTag % Tag to the floating potential of the gate.
end
methods
function obj = Gate(hModel, varargin)
% Gate Creates a Gate object.
%
% Gate(hModel)
% Gate(hModel, varargin)
%
% Parameters:
% hModel: Required handle to parent ComsolModel type object
% Name: Common name of workpane and the extrude feature.
% Distance: Distance of layer. Can be monotonous array
% (must be non-zero, pos/neg, default: 1)
% zPosition: z-Position of the layer (default: 0)
% Voltage: Voltage of the gate (default: 0)
% %%% when creating from existing extruded workplane/pot. %%%
% FromExtrudeTag: Tag of an existing extrude feature
% FromPotentialTag: Tag of an existing electric potential
assert(isa(hModel, 'comsolkit.GateLayoutModel'), ...
'hModel has to be of class comsolkit.GateLayoutModel');
p = inputParser;
p.KeepUnmatched = true;
addParameter(p, 'FromPotentialTag', '', @ischar);
addParameter(p, 'Voltage', 0, ...
@(x) isnumeric(x) && isscalar(x));
parse(p,varargin{:});
obj = [email protected](hModel, p.Unmatched);
if ~isempty(p.Results.FromPotentialTag)
obj.potentialTag = p.Results.FromPotentialTag;
else
obj.potentialTag = obj.hModel.es.feature().uniquetag( ...
obj.BASE_TAG_POTENTIAL);
potential = obj.hModel.es.feature.create( ...
obj.potentialTag, 'ElectricPotential', 2);
potential.selection.named(obj.boundaryTag);
potential.name(obj.name);
end
obj.voltage = p.Results.Voltage;
% Used to introduce floating potentials when voltage = NaN.
obj.floatingTag = '';
end
function potential = get.potential(obj)
import com.comsol.model.*;
hasPotential = obj.hModel.es.feature().index(obj.potentialTag);
assert(hasPotential >= 0, '%s has no potential %s.', ...
obj.hModel.es.tag(), obj.potentialTag);
potential = obj.hModel.es.feature(obj.potentialTag);
potential.name(obj.name);
end
function voltage = get.voltage(obj)
import com.comsol.model.*;
voltage = str2double(obj.potential.getString('V0'));
end
function obj = set.voltage(obj, newVoltage)
import com.comsol.model.*;
assert(isnumeric(newVoltage) && isscalar(newVoltage), ...
'New voltage is not valid.');
obj.potential.set('V0', newVoltage);
if isnan(newVoltage)
obj.potential.active(false);
if isempty(obj.floatingTag)
obj.floatingTag = ...
obj.hModel.es.feature().uniquetag( ...
obj.BASE_TAG_FLOATING);
floating = obj.hModel.es.feature.create( ...
obj.floatingTag, 'FloatingPotential', 2);
floating.selection.named(obj.boundaryTag);
floating.name([obj.FLOATING_NAME_PREFIX obj.name]);
else
hasFloating = obj.hModel.es.feature().index( ...
obj.floatingTag);
assert(hasFloating >= 0, '%s has no floating %s.', ...
obj.hModel.es.tag(), obj.floatingTag);
floating = obj.hModel.es.feature(obj.floatingTag);
floating.active(true);
floating.name([obj.FLOATING_NAME_PREFIX obj.name]);
end
else
obj.potential.active(true);
if ~isempty(obj.floatingTag)
hasFloating = obj.hModel.es.feature().index( ...
obj.floatingTag);
assert(hasFloating >= 0, '%s has no floating %s.', ...
obj.hModel.es.tag(), obj.floatingTag);
floating = obj.hModel.es.feature(obj.floatingTag);
floating.active(false);
floating.name([obj.FLOATING_NAME_PREFIX obj.name]);
end
end
end
function delete(obj)
% delete Removes the workplane/extrude/potential from the model.
%
% delete(obj)
[email protected](obj);
try
obj.hModel.es.feature().remove(obj.potentialTag);
catch
warning('Could not remove Potential %s from server.', ...
obj.potentialTag);
end
end
function str = info_string(obj)
% info_string Generates information string about the object.
%
% str = info_string(obj)
str = [email protected](obj);
str = sprintf('%s voltage: %f', str, obj.voltage);
end
end
methods(Static)
function clear_es_features(hModel)
% clear_es_features Removes by tag pattern BASE_TAG*.
%
% clear_es_features(hModel)
%
% Parameters:
% hModel: ComsolModel object or a derived object.
import com.comsol.model.*;
assert(isa(hModel, 'comsolkit.GateLayoutModel'), ...
'hModel has to be of class comsolkit.GateLayoutModel');
itr = hModel.es.feature().iterator;
removeCell = {};
while itr.hasNext()
feature = itr.next();
featureTag = char(feature.tag());
isPotential = strncmp(featureTag, ...
comsolkit.Gate.BASE_TAG_POTENTIAL, ...
length(comsolkit.Gate.BASE_TAG_POTENTIAL));
isFloating = strncmp(featureTag, ...
comsolkit.Gate.BASE_TAG_FLOATING, ...
length(comsolkit.Gate.BASE_TAG_FLOATING));
if isPotential || isFloating
removeCell{end+1} = featureTag;
end
end
% Does not work from inside the iterator. Concurrency error.
for featureTag = removeCell
hModel.es.feature().remove(featureTag{1});
end
end
end
end