-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.m
180 lines (123 loc) · 4.33 KB
/
generate.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
% The MIT License (MIT)
%
% Copyright (c) 2022 Roman Szewczyk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
%
%
% DESCRIPTION:
% Script generating .msz file connected with the paper:
% A. Ostaszewska-Lizewska, D. Kopala, R. Szewczyk
% "Improved control of mesh density in adaptive tetrahedral meshes
% for finite element modeling"
% submitted to Measurement Automation Robotics Journal
% (Pomiary Automatyka Robotyka), www.par.pl
%
clear all
clc
% ---- Definition of parameters values ----
% - Physical parameters -
mi0=4.*pi.*1e-7; % maqgnetic constant
mi = 1e3.*mi0; % relative magnetic permeability
ro = 1.6e-7; % resitivity (Ohm*m)
R=1e-3; % Radius of the wire (m)
I=1; % Total driving current in the wire (A)
f=3000; % Driving current frequency (Hz)
% - Modelling parameters -
b=3; % Number of dividing point
nlay=3; % Number of layers in each section
hmax=0.2; % Maximal height of the tetrahedral element
zmin=-5; % X - position of the beginning of the wire
zmax=5; % X - position of the ending of the wire
% - Calculated parameters -
w=2.*pi.*f;
k=sqrt(-1.*w.*mi.*i./ro);
% ---- Calculation of the eddy current distribution ---
r = 0:0.01.*R:R;
J=[];
for m=1:numel(r)
J=[J abs(k.*I./(2.*pi.*R).*J0(k.*r(m))./J1(k.*R))];
end
%
% Plot eddy current distribution
plot(r.*1e3,J./1e6,'-k','linewidth',2);
set(gca,'fontsize',24);
%set(gca(), 'xticklabel', {'0.0','0.2','0.4','0.6','0.8','1.0'});
%set(gca(), 'yticklabel', {'0.0','0.5','1.0','1.5','2.0'});
xlabel('{\it distance from cable axis r (mm)}');
ylabel('{\it current density i (MA/m^2)}');
grid;
hold on;
% Determine and plot division points
rb=0;
Jb=min(J);
for m=1:b
x=interp1(J,r,max(J).*m./b);
if ~isnan(x)
rb=[rb x];
Jb=[Jb interp1(r,J,rb(end))];
end
end
%
plot(rb.*1e3,Jb./1e6,'or','linewidth',2);
for m=1:numel(rb)
plot([rb(m).*1e3,rb(m).*1e3],[0, J(end)./1e6],'-r','linewidth',1);
end
%
if numel(rb)==2
fprintf('\n nothing to do \n\n');
return
end
%
% Create .msz file
fid=fopen('simple.temp','w');
n=0;
for m=numel(rb):-1:3
% nlay=3 fixed
L=[];
L=rb(m);
plot([rb(m).*1e3,rb(m).*1e3],[0, J(end)./1e6],':b','linewidth',2);
n_=DoCircleSet(fid, zmin, zmax, rb(m).*1e3, (rb(m)-rb(m-1))./3.*1e3)
n=n+n_;
for m2=nlay-1:-1:1
L=[L rb(m-1)+m2./nlay.*(rb(m)-rb(m-1))];
plot([(rb(m-1)+m2./nlay.*(rb(m)-rb(m-1))).*1e3, ...
(rb(m-1)+m2./nlay.*(rb(m)-rb(m-1))).*1e3], ...
[0, J(end)./1e6],':b','linewidth',2);
n_=DoCircleSet(fid, zmin, zmax, (rb(m-1)+m2./nlay.*(rb(m)-rb(m-1))).*1e3,...
(rb(m)-rb(m-1))./nlay.*1e3)
n=n+n_;
end
end
%
L=rb(2);
plot([rb(2).*1e3,rb(2).*1e3],[0, J(end)./1e6],':b','linewidth',2);
n_=DoCircleSet(fid, zmin, zmax, rb(2).*1e3, (rb(3)-rb(2))./3.*1e3)
n=n+n_;
%
hold off;
% Finalize .msz file
fclose(fid);
fid=fopen('simple.head','w');
fprintf(fid,'0\n%i\n',n);
fclose(fid);
system('copy simple.head + simple.temp simple.msz > nul');
unlink('simple.temp');
unlink('simple.head');
% - End of the script -