-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrents.m
240 lines (208 loc) · 8.79 KB
/
currents.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
%% This programm looks for the borders of your chip and identificates the current boundary condition
%
% This algorithm will just be able to find the borders of your geometry, if there is at least one
% row or column between it and the chip border parallel to the conductor.(Thatmeans: all conductor,
% which starts at the border, is for in or outcomming current)
% Currents are counted positive from left to right or from up to down, (like the coordinates)
% The resolution must be high enough, a straight borderline section must be at leat made of three gridpoints
% (otherwise corners of the borderlines won't be detected!).
function [general_currentmask,length_currentzone] = currents(geometrymask,holemask,geometry)
border = -1;
gridpointX = geometry.gridpointX;
gridpointY = geometry.gridpointY;
deltaX = geometry.deltaX;
deltaY = geometry.deltaY;
nospace = geometry.nospace;
space = geometry.space;
nohole = geometry.nohole;
nocurrent = geometry.nocurrent;
general_current_1 = geometry.general_current_1;
general_current_2 = geometry.general_current_2;
%% Initiate an array
general_currentmask = ones(gridpointY,gridpointX) * nocurrent;
%% First detect borders and note them in general_currentmask
for i = 2:1:gridpointY-1
for j = 1:1:gridpointX
%%for the row
if (geometrymask(i-1,j) == nospace) && (geometrymask(i,j) == space)
general_currentmask(i,j) = border;
end
if (geometrymask(i+1,j) == nospace) && (geometrymask(i,j) == space)
general_currentmask(i,j) = border;
end
end
end
for i = 1:1:gridpointY
for j = 2:1:gridpointX-1
%%for the column
if (geometrymask(i,j-1) == nospace) && (geometrymask(i,j) == space)
general_currentmask(i,j) = border;
end
if (geometrymask(i,j+1) == nospace) && (geometrymask(i,j) == space)
general_currentmask(i,j) = border;
end
end
end
%%sometimes 'corners' in the boundary condition are not seen by the above iteration, we fix that here ...
%%(but this algorithm won't work with curved borders! minimum length of straight sections: 3 gridpoints)
cornercount = 0;
for i = 3:1:gridpointY-2
for j = 3:1:gridpointX-2
%%there are 4 possible 'corner cases'
if general_currentmask(i+1,j)==general_currentmask(i,j+1) ...
&& general_currentmask(i,j)==nocurrent ...
&& general_currentmask(i+1,j)==border ...
&& general_currentmask(i,j+1)==border ...
&& general_currentmask(i+2,j)==border ...
&& general_currentmask(i,j+2)==border
general_currentmask(i,j) = general_currentmask(i,j+1);
cornercount = cornercount + 1;
end
if general_currentmask(i-1,j)==general_currentmask(i,j-1) ...
&& general_currentmask(i,j)==nocurrent ...
&& general_currentmask(i-1,j)==border ...
&& general_currentmask(i,j-1)==border ...
&& general_currentmask(i-2,j)==border ...
&& general_currentmask(i,j-2)==border
general_currentmask(i,j) = general_currentmask(i,j-1);
cornercount = cornercount + 1;
end
if general_currentmask(i-1,j)==general_currentmask(i,j+1) ...
&& general_currentmask(i,j)==nocurrent ...
&& general_currentmask(i-1,j)==border ...
&& general_currentmask(i,j+1)==border ...
&& general_currentmask(i-2,j)==border ...
&& general_currentmask(i,j+2)==border
general_currentmask(i,j) = general_currentmask(i,j+1);
cornercount = cornercount + 1;
end
if general_currentmask(i,j-1)==general_currentmask(i+1,j) ...
&& general_currentmask(i,j)==nocurrent ...
&& general_currentmask(i,j-1)==border ...
&& general_currentmask(i+1,j)==border ...
&& general_currentmask(i,j-2)==border ...
&& general_currentmask(i+2,j)==border
general_currentmask(i,j) = general_currentmask(i+1,j);
cornercount = cornercount + 1;
end
end
end
%% Now we note the two different borders
%For the left and right border
for index = [1 gridpointX]
for i = 2:1:gridpointY-1
if general_currentmask(i,index) == border
%%identificate class of border
if (geometrymask(i-1,index) == nospace) && (geometrymask(i,index) == space) && (general_currentmask(i,index) == border)
general_current = general_current_1;
end
if (geometrymask(i+1,index) == nospace) && (geometrymask(i,index) == space) && (general_currentmask(i,index) == border)
general_current = general_current_2;
end
%%follow the borderline and apply values
i2 = i;
if index == 1; j2 = 2; elseif index == gridpointX; j2 = gridpointX-1; end
general_currentmask(i,index) = general_current;
general_currentmask(i,j2) = general_current;
while (i2 ~= 1) && (j2 ~= 1) && (i2 ~= gridpointY) && (j2~= gridpointX)
if general_currentmask(i2-1,j2) == border
general_currentmask(i2-1,j2) = general_current;
i2 = i2-1;
end
if general_currentmask(i2+1,j2) == border
general_currentmask(i2+1,j2) = general_current;
i2 = i2+1;
end
if general_currentmask(i2,j2-1) == border
general_currentmask(i2,j2-1) = general_current;
j2 = j2-1;
end
if general_currentmask(i2,j2+1) == border
general_currentmask(i2,j2+1) = general_current;
j2 = j2+1;
end
end
end
end
end
%%For the upper and lower border
for index = [1 gridpointY]
for j = 2:1:gridpointX-1
if general_currentmask(index,j) == border
%%identificate class of border
if (geometrymask(index,j-1) == nospace) && (geometrymask(index,j) ~= nospace) && (general_currentmask(index,j) == border)
general_current = general_current_2;
end
if (geometrymask(index,j+1) == nospace) && (geometrymask(index,j) ~= nospace) && (general_currentmask(index,j) == border)
general_current = general_current_1;
end
%%follow the borderline and apply values
j2 = j;
if index == 1; i2 = 2; elseif index == gridpointY; i2 = gridpointY-1; end
general_currentmask(index,j) = general_current;
general_currentmask(i2,j) = general_current;
while (i2 ~= 1) && (j2 ~= 1) && (i2 ~= gridpointY) && (j2~= gridpointX)
if general_currentmask(i2-1,j2) == border
general_currentmask(i2-1,j2) = general_current;
i2 = i2-1;
end
if general_currentmask(i2+1,j2) == border
general_currentmask(i2+1,j2) = general_current;
i2 = i2+1;
end
if general_currentmask(i2,j2-1) == border
general_currentmask(i2,j2-1) = general_current;
j2 = j2-1;
end
if general_currentmask(i2,j2+1) == border
general_currentmask(i2,j2+1) = general_current;
j2 = j2+1;
end
end
end
end
end
%% Here we delete the borders of the holes, they are no current boundary conditions ...
index = [-1 -1; -1 0; -1 1;0 -1; 0 0; 0 1; 1 -1; 1 0; 1 1];
for i = 2:1:gridpointY-1
for j = 2:1:gridpointX-1
for k = 1:1:9
if (general_currentmask(i,j)==-1) && (holemask(i+index(k,1),j+index(k,2))~=nohole)
general_currentmask(i,j) = nocurrent;
end
end
end
end
%% And check the length of the incomming currentzone
length_currentzone = 0;
flag = 0;
for i = 1:1:gridpointY %%For the left border ...
if general_currentmask(i,1)==general_current_1
flag = 1;
begin = i;
end
if (general_currentmask(i,1)==general_current_2) && (flag==1)
flag = 0;
length_currentzone = length_currentzone + deltaY*(i-begin);
end
end
flag = 0;
for j = 1:1:gridpointX %%... and the upper border.
if general_currentmask(1,j)==general_current_2
flag = 1;
begin = j;
end
if (general_currentmask(1,j)==general_current_1) && (flag==1)
flag = 0;
length_currentzone = length_currentzone + deltaX*(j-begin);
end
end
%% Island geometries (but not holes!) have borders which are not detected from the above algorithm
%%(because they are not connected to the borders of the chip), we give 'closed'
%%borderlines (but not hole borders) the boundary condition general_current_1
general_currentmask(general_currentmask == border) = general_current_1; % hier viellciht eine hüpflösung wie oben!!!
%% Check if all -1's are gone
if any(general_currentmask==-1)
disp('Something with borderdetection went wrong!');
end
end