Skip to content

Commit 0a031ee

Browse files
authored
Merge pull request #5 from moetomg/main
minor modification on sydney's model
2 parents 52a53cd + 8ede57f commit 0a031ee

File tree

2 files changed

+80
-74
lines changed

2 files changed

+80
-74
lines changed
-563 Bytes
Binary file not shown.

src_py/magnethub/sydney.py

+80-74
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
File contains the model according to the Paderborn University approach for the magnet challenge.
2+
File contains the model according to the Sydney University approach for the magnet challenge.
33
44
Source: https://github.com/moetomg/magnet-engine
55
"""
@@ -24,83 +24,82 @@
2424
"N87": "N87.pt",
2525
"ML95S": "ML95S.pt",
2626
}
27-
2827
# Material normalization data (1.B 2.H 3.F 4.T 5.dB/dt)
2928
normsDict ={"77": [[-2.63253458e-19, 7.47821754e-02],
3029
[-7.60950004e-18, 1.10664739e+01],
31-
[5.24678898e+00, 2.89351404e-01],
32-
[5.87473793e+01, 2.40667381e+01],
33-
[6.16727829e+00, 3.83645439e+01]],
34-
"78": [[5.67033925e-19, 7.22424510e-02],
30+
[ 5.24678898e+00, 2.89351404e-01],
31+
[ 5.87473793e+01, 2.40667381e+01],
32+
[ 6.16727829e+00, 3.83645439e+01]],
33+
"78": [[ 5.67033925e-19, 7.22424510e-02],
3534
[-1.54283684e-16, 1.15338828e+01],
36-
[5.23810768e+00, 2.89979160e-01],
37-
[5.87434082e+01, 2.40685291e+01],
38-
[6.09561586e+00, 3.81356049e+01]],
39-
"79": [[1.70344847e-13, 9.41321492e-02],
35+
[ 5.23810768e+00, 2.89979160e-01],
36+
[ 5.87434082e+01, 2.40685291e+01],
37+
[ 6.09561586e+00, 3.81356049e+01]],
38+
"79": [[ 1.70344847e-13, 9.41321492e-02],
4039
[-4.54025068e-02, 3.20463941e+01],
41-
[5.21954346e+00, 2.66715437e-01],
42-
[5.52068787e+01, 2.37196522e+01],
43-
[6.77422905e+00, 3.90895233e+01]],
44-
"N27": [[7.52738469e-19, 7.48951129e-02],
40+
[ 5.21954346e+00, 2.66715437e-01],
41+
[ 5.52068787e+01, 2.37196522e+01],
42+
[ 6.77422905e+00, 3.90895233e+01]],
43+
"N27": [[ 7.52738469e-19, 7.48951129e-02],
4544
[-8.97477366e-17, 1.47606605e+01],
46-
[5.24649334e+00, 2.89964765e-01],
47-
[5.87355194e+01, 2.40766029e+01],
48-
[6.17841434e+00, 3.84738274e+01]],
49-
"N30": [[1.43320465e-19, 6.56044649e-02],
45+
[ 5.24649334e+00, 2.89964765e-01],
46+
[ 5.87355194e+01, 2.40766029e+01],
47+
[ 6.17841434e+00, 3.84738274e+01]],
48+
"N30": [[ 1.43320465e-19, 6.56044649e-02],
5049
[-1.57874135e-16, 1.09083332e+01],
51-
[5.31786680e+00, 2.78960317e-01],
52-
[5.86466904e+01, 2.40616817e+01],
53-
[7.01255989e+00, 4.09709969e+01]],
50+
[ 5.31786680e+00, 2.78960317e-01],
51+
[ 5.86466904e+01, 2.40616817e+01],
52+
[ 7.01255989e+00, 4.09709969e+01]],
5453
"N49": [[-8.99073580e-19, 8.94479227e-02],
55-
[4.15423721e-16, 3.70622618e+01],
56-
[5.25545311e+00, 3.00384015e-01],
57-
[5.94716339e+01, 2.44349327e+01],
58-
[6.75209475e+00, 3.91901703e+01]],
59-
"N87": [[1.72051200e-13, 6.26231476e-02],
60-
[4.02299992e-02, 7.61060358e+00],
61-
[5.26309967e+00, 2.87137657e-01],
62-
[5.83059006e+01, 2.40639057e+01],
63-
[6.53078842e+00, 3.93127785e+01]],
64-
"3E6": [[1.01579639e-18, 7.04261607e-02],
65-
[2.34374135e-16, 7.21573964e+00],
66-
[5.34307003e+00, 2.66708523e-01],
67-
[5.86578026e+01, 2.40552864e+01],
68-
[7.23155785e+00, 4.15975838e+01]],
54+
[ 4.15423721e-16, 3.70622618e+01],
55+
[ 5.25545311e+00, 3.00384015e-01],
56+
[ 5.94716339e+01, 2.44349327e+01],
57+
[ 6.75209475e+00, 3.91901703e+01]],
58+
"N87": [[ 1.72051200e-13, 6.26231476e-02],
59+
[ 4.02299992e-02, 7.61060358e+00],
60+
[ 5.26309967e+00, 2.87137657e-01],
61+
[ 5.83059006e+01, 2.40639057e+01],
62+
[ 6.53078842e+00, 3.93127785e+01]],
63+
"3E6": [[ 1.01579639e-18, 7.04261607e-02],
64+
[ 2.34374135e-16, 7.21573964e+00],
65+
[ 5.34307003e+00, 2.66708523e-01],
66+
[ 5.86578026e+01, 2.40552864e+01],
67+
[ 7.23155785e+00, 4.15975838e+01]],
6968
"3F4": [[-1.75200068e-19, 5.98892952e-02],
7069
[-9.48865199e-18, 4.74414811e+01],
71-
[5.14398336e+00, 3.04210454e-01],
72-
[5.76523476e+01, 2.43824081e+01],
73-
[6.23030663e+00, 3.64991379e+01]],
74-
"T37": [[1.72051200e-13, 6.26231476e-02],
75-
[4.02299992e-02, 7.61060358e+00],
76-
[5.26309967e+00, 2.87137657e-01],
77-
[5.83059006e+01, 2.40639057e+01],
78-
[6.53078842e+00, 3.93127785e+01]],
70+
[ 5.14398336e+00, 3.04210454e-01],
71+
[ 5.76523476e+01, 2.43824081e+01],
72+
[ 6.23030663e+00, 3.64991379e+01]],
73+
"T37": [[ 1.72051200e-13, 6.26231476e-02],
74+
[ 4.02299992e-02, 7.61060358e+00],
75+
[ 5.26309967e+00, 2.87137657e-01],
76+
[ 5.83059006e+01, 2.40639057e+01],
77+
[ 6.53078842e+00, 3.93127785e+01]],
7978
"3C90":[[-3.27923689e-19, 6.56109348e-02],
80-
[6.99196716e-17, 1.26583787e+01],
81-
[5.19875193e+00, 2.68499136e-01],
82-
[5.86049919e+01, 2.40574703e+01],
83-
[6.29652929e+00, 3.84585190e+01]],
79+
[ 6.99196716e-17, 1.26583787e+01],
80+
[ 5.19875193e+00, 2.68499136e-01],
81+
[ 5.86049919e+01, 2.40574703e+01],
82+
[ 6.29652929e+00, 3.84585190e+01]],
8483
"3C92":[[-2.35520104e-13, 6.53518693e-02],
85-
[1.18689366e-01, 1.23585692e+01],
86-
[5.16579533e+00, 2.73998171e-01],
87-
[5.84305267e+01, 2.40970516e+01],
88-
[5.88209248e+00, 3.69935722e+01]],
89-
"3C94":[[1.21232679e-19, 7.44383659e-02],
84+
[ 1.18689366e-01, 1.23585692e+01],
85+
[ 5.16579533e+00, 2.73998171e-01],
86+
[ 5.84305267e+01, 2.40970516e+01],
87+
[ 5.88209248e+00, 3.69935722e+01]],
88+
"3C94":[[ 1.21232679e-19, 7.44383659e-02],
9089
[-2.19613879e-17, 1.18042579e+01],
91-
[5.22766781e+00, 2.68348873e-01],
92-
[5.87128143e+01, 2.40769634e+01],
93-
[6.53718996e+00, 3.91955910e+01]],
94-
"3C95":[[5.64116728e-14, 7.90115297e-02],
95-
[1.11898437e-01, 1.29696641e+01],
96-
[5.18842697e+00, 2.69014776e-01],
97-
[5.86223640e+01, 2.40957470e+01],
98-
[6.25767517e+00, 3.84026108e+01]],
90+
[ 5.22766781e+00, 2.68348873e-01],
91+
[ 5.87128143e+01, 2.40769634e+01],
92+
[ 6.53718996e+00, 3.91955910e+01]],
93+
"3C95":[[ 5.64116728e-14, 7.90115297e-02],
94+
[ 1.11898437e-01, 1.29696641e+01],
95+
[ 5.18842697e+00, 2.69014776e-01],
96+
[ 5.86223640e+01, 2.40957470e+01],
97+
[ 6.25767517e+00, 3.84026108e+01]],
9998
"ML95S":[[-1.53185180e-13, 1.15827541e-01],
100-
[3.84426934e-01, 4.45061606e+01],
101-
[5.21606445e+00, 2.65364528e-01],
102-
[5.70770302e+01, 2.44398289e+01],
103-
[7.30377579e+00, 4.04136391e+01]],
99+
[ 3.84426934e-01, 4.45061606e+01],
100+
[ 5.21606445e+00, 2.65364528e-01],
101+
[ 5.70770302e+01, 2.44398289e+01],
102+
[ 7.30377579e+00, 4.04136391e+01]],
104103
}
105104

106105
# %% Initialize model
@@ -122,9 +121,10 @@ def __init__(self, mdl_path, material):
122121
def __call__(self, data_B, data_F, data_T):
123122
"""Call method."""
124123
# ----------------------------------------------------------- batch execution
125-
# if isinstance(data_F, np.ndarray):
126-
127124
# 1.Get dataloader
125+
if data_B.ndim == 1:
126+
data_B = np.array(data_B).reshape(1, -1)
127+
128128
loader = get_dataloader(data_B,data_F,data_T,self.mdl.norm)
129129

130130
# 2.Validate the models
@@ -138,12 +138,17 @@ def __call__(self, data_B, data_F, data_T):
138138

139139
data_P = torch.cat((data_P,Pv.to(self.device)),dim=0)
140140
data_P, h_series = data_P.cpu().numpy(), h_series.cpu().numpy()
141+
142+
# 3.Return results
141143
if data_P.size == 1:
142144
data_P = data_P.item()
143145
if h_series.ndim == 1:
144146
h_series = h_series.reshape(1, -1)
147+
145148
return data_P, h_series
146149

150+
151+
147152
class MMINet(torch.nn.Module):
148153
"""
149154
Magnetization mechanism-determined neural network.
@@ -235,7 +240,7 @@ def forward(self, x, var):
235240
H = torch.from_numpy(H).view(batch_size,-1,1)
236241
real_H = torch.cat((H[:, -self.n_init:, :],H[:, :-self.n_init, :]), dim=1)
237242
return torch.flatten(Pv).cpu(), real_H[:, :, 0].cpu()
238-
243+
239244
class StopOperatorCell():
240245
"""
241246
MMINN Sub-layer: Static hysteresis prediction using stop operators.
@@ -257,8 +262,7 @@ def __call__(self, dB, state):
257262
r = self.operator_thre.to(dB.device)
258263
output = self.sslu((dB + state)/r)*r
259264
return output.float()
260-
261-
265+
262266
class EddyCell(torch.nn.Module):
263267
"""
264268
MMINN subsubnetwork: Dynamic hysteresis prediction.
@@ -312,12 +316,14 @@ def get_dataloader(data_B, data_F, data_T, norm, n_init=32):
312316
n_init : int
313317
Additional points for computing the history magnetization
314318
"""
319+
315320
# Data pre-process
316321
# 1. Down-sample to 128 points
317322
seq_length = 128
318-
cols = np.array(range(0,1023,8))
319-
data_B = data_B[:, cols]
320323

324+
cols = np.array(range(0,data_B.shape[1],round(data_B.shape[1]/seq_length)))
325+
data_B = data_B[:, cols]
326+
321327
# 2. Add extra points for initial magnetization calculation
322328
data_length = seq_length + n_init
323329
data_B = np.hstack((data_B,data_B[:,1:1+n_init]))
@@ -335,7 +341,7 @@ def get_dataloader(data_B, data_F, data_T, norm, n_init=32):
335341
in_B = (B-norm[0][0])/norm[0][1]
336342
in_F = (F-norm[2][0])/norm[2][1]
337343
in_T = (T-norm[3][0])/norm[3][1]
338-
344+
339345
# 5. Extra features
340346
in_dB = torch.diff(in_B,dim=1) # Flux density change
341347
in_dB = torch.cat((in_dB[:, 0:1, :], in_dB), dim=1)
@@ -371,9 +377,9 @@ def get_operator_init(B0, dB, Bmax, Bmin, operator_size=30, max_out_H=1):
371377
Bmin: torch_like (batch)
372378
Min flux density of each cycle
373379
operator_size: int
374-
TBD
380+
The number of operators
375381
max_out_H:
376-
TBD
382+
The maximum output of field strength
377383
"""
378384
# 1. Parameter setting
379385
batch = dB.shape[0]

0 commit comments

Comments
 (0)