Skip to content

Commit 2e8858b

Browse files
update
1 parent 8e148a9 commit 2e8858b

16 files changed

+579
-52
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
function [h,b] = emdlab_extend_hbcurve_linear(h, b, h_final)
3+
4+
mu0 = 4*pi*1e-7*1.1;
5+
x_tmp = linspace(h(end),h_final,1e2)';
6+
y_tmp = b(end) + mu0 * (x_tmp - h(end));
7+
8+
h = [h;x_tmp(2:end)];
9+
b = [b;y_tmp(2:end)];
10+
11+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function [B_ext, v_ext] = emdlab_flib_smooth_extend_bvcurve_arctan(B, v, v_final)
2+
% emdlab_flib_smooth_extend_bvcurve_arctan
3+
% extend B and reluctivity v to v_final using smooth arctangent decay
4+
%
5+
% inputs:
6+
% B : original B vector (t)
7+
% v : original reluctivity vector (1/mu or v=B/H)
8+
% v_final : asymptotic v value for high B
9+
%
10+
% outputs:
11+
% B_ext : extended B vector
12+
% v_ext : extended v vector
13+
14+
% last point
15+
Bs = B(end);
16+
vs = v(end);
17+
18+
% last slope
19+
slope_last = (v(end) - v(end-1)) / (B(end) - B(end-1));
20+
21+
% characteristic B width for arctan transition
22+
Bk = (B(end)*0.5); % you can tune this fraction
23+
24+
% compute amplitude to match slope at B=end
25+
A = (slope_last - 0) * (pi/2) * Bk; % slope decays from slope_last to near 0
26+
27+
% generate extension points
28+
B_tail = linspace(B(end), 1e2*B(end), 100)';
29+
B_tail = B_tail(2:end); % skip first point
30+
31+
% arctangent decay
32+
v_tail = v_final + A * (atan((B_tail - Bs)/Bk) - atan(0));
33+
34+
% combine original + extension
35+
B_ext = [B; B_tail];
36+
v_ext = [v; v_tail];
37+
38+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [B_ext, v_ext] = emdlab_flib_smooth_extend_bvcurve_exp(B, v, B_final)
2+
% extend_exponential
3+
% extend B and reluctivity v to B_final using smooth exponential decay
4+
%
5+
% inputs:
6+
% B : original B vector (T)
7+
% v : original reluctivity vector (1/mu or v=B/H)
8+
% B_final : asymptotic B value for v
9+
%
10+
% outputs:
11+
% B_ext : extended B vector
12+
% v_ext : extended v vector
13+
14+
% compute slope from last segment
15+
slope = (v(end) - v(end-1)) / (B(end) - B(end-1));
16+
17+
% characteristic decay constant
18+
tau = (B_final - v(end)) / slope;
19+
20+
% create extension points
21+
B_tail = linspace(B(end), 1e2*B(end), 100)'; % 100 points beyond last B
22+
B_tail = B_tail(2:end); % skip first point (already included)
23+
24+
% exponential decay for v
25+
v_tail = B_final + (v(end) - B_final) * exp(-(B_tail - B(end))/tau);
26+
27+
% combine original + extension
28+
B_ext = [B; B_tail];
29+
v_ext = [v; v_tail];
30+
31+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [h_full,b_full] = emdlab_flib_smooth_extend_hbcurve_arctan(h, b, h_final)
2+
% emdlab_flub_smooth_extend_hbcurve_arctan
3+
% extend b-h curve to h_final using arctangent, smoothly decreasing
4+
% incremental permeability from last slope to mu0.
5+
6+
mu0 = 4*pi*1e-7; % vacuum permeability
7+
8+
% last point
9+
Hs = h(end);
10+
Bs = b(end);
11+
12+
% incremental permeability at last point
13+
mu_last = (b(end) - b(end-1)) / (h(end) - h(end-1));
14+
15+
% arctangent scale parameter to control slope decrease
16+
Ht = linspace(Hs, h_final, 100); % extension points
17+
Ht = Ht(2:end); % skip Hs
18+
19+
% compute amplitude so that slope decreases from mu_last -> mu0
20+
% dB/dH = mu0 + Bk*(2/pi)*(1/(1+(H/Hk)^2))*(1/Hk)
21+
% at H = Hs, slope = mu_last => Bk formula:
22+
Hk = (h_final - Hs)/2; % characteristic width, adjustable
23+
Bk = (mu_last - mu0) * (pi/2) * Hk; % ensures slope starts at mu_last
24+
25+
% arctangent extension
26+
b_ext = Bs + mu0*(Ht - Hs) + Bk*(2/pi)*(atan(Ht/Hk) - atan(Hs/Hk));
27+
28+
% combine original + extension
29+
h_full = [h; Ht(:)];
30+
b_full = [b; b_ext(:)];
31+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function [h_ext, b_ext] = emdlab_flib_smooth_extend_hbcurve_exp(h, b, h_final)
2+
% emdlab_flib_smooth_extend_hbcurve_exp
3+
% smooth maxwell-compatible extension of b-h curve
4+
%
5+
% inputs:
6+
% h : original h vector (a/m), monotonic increasing
7+
% b : original b vector (t)
8+
% h_final : final h value for extension (a/m)
9+
%
10+
% outputs:
11+
% h_ext : extended h vector
12+
% b_ext : extended b vector
13+
14+
% constants
15+
mu0 = 4*pi*1e-7;
16+
17+
% ensure column vectors
18+
h = h(:);
19+
b = b(:);
20+
21+
% last data point (saturation entry)
22+
Hsat = h(end);
23+
Bsat = b(end);
24+
25+
% incremental permeability at last segment
26+
mu_last = (b(end) - b(end-1)) / (h(end) - h(end-1));
27+
28+
% smoothing length (maxwell-like)
29+
DeltaH = 0.1 * Hsat;
30+
31+
% interpolation inside measured range
32+
pp = pchip(h, b);
33+
34+
% generate extended h grid
35+
if h_final <= Hsat
36+
h_ext = h;
37+
b_ext = b;
38+
return
39+
end
40+
41+
dh = mean(diff(h));
42+
h_tail = (Hsat+dh : dh : h_final).';
43+
h_ext = [h; h_tail];
44+
45+
% allocate b
46+
b_ext = zeros(size(h_ext));
47+
48+
% inside data range
49+
idx_in = h_ext <= Hsat;
50+
b_ext(idx_in) = ppval(pp, h_ext(idx_in));
51+
52+
% smooth asymptotic extension
53+
idx_out = h_ext > Hsat;
54+
Ht = h_ext(idx_out) - Hsat;
55+
b_ext(idx_out) = Bsat + mu0 * Ht + (mu_last - mu0) * DeltaH .* (1 - exp(-Ht / DeltaH));
56+
57+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function [h_full, b_full] = emdlab_flib_smooth_extend_hbcurve_polyc(h, b, h_final, n)
2+
% emdlab_flib_smooth_extend_hbcurve_polyc
3+
% smooth polynomial-based extension of B-H curve
4+
% decreasing incremental permeability from last slope to mu0
5+
%
6+
% inputs:
7+
% h : original h vector (a/m)
8+
% b : original b vector (t)
9+
% h_final : final h value for extension (a/m)
10+
% n : polynomial exponent for decay (default 2)
11+
%
12+
% outputs:
13+
% h_full : extended h vector
14+
% b_full : extended b vector
15+
16+
if nargin < 4
17+
n = 2; % default exponent
18+
end
19+
20+
mu0 = 4*pi*1e-7; % vacuum permeability
21+
22+
% last point
23+
Hs = h(end);
24+
Bs = b(end);
25+
26+
% incremental permeability at last segment
27+
mu_last = (b(end) - b(end-1)) / (h(end) - h(end-1));
28+
29+
% generate extended H vector
30+
Ht = linspace(Hs, h_final, 100);
31+
Ht = Ht(2:end); % skip Hs
32+
33+
% polynomial decay function (normalized)
34+
f = (1 - (Ht - Hs)/(h_final - Hs)).^n;
35+
36+
% incremental permeability along extension
37+
mu_ext = mu0 + (mu_last - mu0) .* f;
38+
39+
% integrate mu(H) to get B(H)
40+
b_ext = Bs + cumtrapz(Ht, mu_ext);
41+
42+
% combine original + extension
43+
h_full = [h; Ht(:)];
44+
b_full = [b; b_ext(:)];
45+
end

functions/extend_exponential.m

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11

2-
function [x,y] = extend_exponential(x, y, y_final)
2+
function [B,v] = extend_exponential(B, v, B_final)
33

4-
% p = spline(x,y);
5-
% c = p.coefs(end,:);
6-
% x_tmp = x(end) - x(end-1);
7-
% slope = 3*c(4)*x_tmp^2 + 2*c(3)*x_tmp + c(2);
4+
slope = (v(end)-v(end-1))/(B(end)-B(end-1));
5+
tau = (B_final-v(end))/slope;
86

9-
slope = (y(end)-y(end-1))/(x(end)-x(end-1));
10-
tau = (y_final-y(end))/slope;
7+
x_tmp = linspace(B(end),1e2*B(end),1e2)';
8+
y_tmp = B_final + (v(end)-B_final) * exp(-(x_tmp-B(end))/tau);
119

12-
x_tmp = linspace(x(end),1e2*x(end),1e2)';
13-
y_tmp = y_final + (y(end)-y_final) * exp(-(x_tmp-x(end))/tau);
14-
15-
x = [x;x_tmp(2:end)];
16-
y = [y;y_tmp(2:end)];
10+
B = [B;x_tmp(2:end)];
11+
v = [v;y_tmp(2:end)];
1712

1813
end

0 commit comments

Comments
 (0)