-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_parse.m
111 lines (93 loc) · 4.63 KB
/
run_parse.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
function run_parse()
% Prepare the data for parallel coordinates plot.
%
% In this example, the design space diversity of a medium-frequency transformer is considered.
%
% This example is composed of two files:
% - run_parse.m - extract and parse the dataset
% - run_plot.m - make the parallel coordinate plot
%
% Filter and sort the provided dataset.
% Find the color of the lines.
% Select the lines to highlight.
% Find the variables name, scaling, ranges
%
% (c) 2019-2020, ETH Zurich, Power Electronic Systems Laboratory, T. Guillod
close('all');
addpath('utils')
%% param
% return the indices of the considered designs (kick the other ones)
% - filter: function handle returning the valid design indices
% - res: struct with the designs (struct of arrays)
% - n_sol: integer with the number of designs
% - example: select randomly 1% of the designs
ctrl.filter = @(res, n_sol) rand(1, n_sol)>0.99;
% return a permutation vector for sorting the designs
% - sort: function handle returning the permutation vector
% - res: struct with the designs (struct of arrays)
% - n_sol: integer with the number of designs
% - example: random permutation
ctrl.sort = @(res, n_sol) randperm(n_sol);
% description, extraction, and range of the variable
% - var: cell array with the variable
% - name: name of the variable
% - fct: function handle returning the variable data (vector)
% - range: range of the variable (axis limits)
% - scale: variable scaling ('lin' or 'log')
% - color: background color for this variable
ctrl.var_axis = {};
ctrl.var_axis{end+1} = struct('name', 'f [kHz]', 'fct', @(res, n_sol) 1e-3.*res.f, 'range', [0 350], 'scale', 'lin', 'color', 'g');
ctrl.var_axis{end+1} = struct('name', 'n [#]', 'fct', @(res, n_sol) res.n, 'range', [0 16], 'scale', 'lin', 'color', 'g');
ctrl.var_axis{end+1} = struct('name', 'f_cw [#]', 'fct', @(res, n_sol) res.fact_core_window, 'range', [0 8], 'scale', 'lin', 'color', 'g');
ctrl.var_axis{end+1} = struct('name', 'f_c [#]', 'fct', @(res, n_sol) res.fact_core, 'range', [0 8], 'scale', 'lin', 'color', 'g');
ctrl.var_axis{end+1} = struct('name', 'f_w [#]', 'fct', @(res, n_sol) res.fact_window, 'range', [0 11], 'scale', 'lin', 'color', 'g');
ctrl.var_axis{end+1} = struct('name', 'r_w [#]', 'fct', @(res, n_sol) res.fact_freq_winding, 'range', [0 5], 'scale', 'lin', 'color', 'y');
ctrl.var_axis{end+1} = struct('name', 'r_cw [#]', 'fct', @(res, n_sol) res.fact_core_winding, 'range', [0 3], 'scale', 'lin', 'color', 'y');
ctrl.var_axis{end+1} = struct('name', 'J [A/mm2]', 'fct', @(res, n_sol) 1e-6.*res.J_rms_winding, 'range', [0 7], 'scale', 'lin', 'color', 'y');
ctrl.var_axis{end+1} = struct('name', 'B [mT]', 'fct', @(res, n_sol) 1e3.*res.B_peak_core, 'range', [0 180], 'scale', 'lin', 'color', 'y');
ctrl.var_axis{end+1} = struct('name', 'dT [degC]', 'fct', @(res, n_sol) res.delta_T, 'range', [0 100], 'scale', 'lin', 'color', 'y');
ctrl.var_axis{end+1} = struct('name', 'eta [%]', 'fct', @(res, n_sol) 1e2.*res.eta, 'range', [99.5 100.0], 'scale', 'lin', 'color', 'r');
% describe the color scale
% - color: struct with the color scale data
% - name: name of the color axis
% - fct: function handle returning the color value (vector)
% - range: range of the color scale (axis limits and ticks)
% - scale: colormap scaling ('lin' or 'log')
ctrl.color_axis = struct('name', 'f [kHz]', 'fct', @(res, n_sol) 1e-3.*res.f, 'range', 0:50:350, 'scale', 'lin');
% describe the highlighted designs
% - var: cell array with the highlighted designs
% - name: name of the design
% - fct: function handle returning the index of the selected design
% - color: color of the curve for the design
ctrl.highlight_idx = {};
ctrl.highlight_idx{end+1} = struct('name', 'best', 'fct', @(res, n_sol) get_idx_max(res.eta), 'color', 'r');
ctrl.highlight_idx{end+1} = struct('name', 'min', 'fct', @(res, n_sol) get_idx_min(res.f), 'color', 'r');
ctrl.highlight_idx{end+1} = struct('name', 'max', 'fct', @(res, n_sol) get_idx_max(res.f), 'color', 'r');
%% run
% load the data
data_raw = load('data/data_raw.mat');
% parse the struct
data_parsed = get_parse(data_raw, ctrl);
% save the data
save('data/data_parsed.mat', '-struct', 'data_parsed');
end
function idx = get_idx_max(v)
% Get the index of the maximum element.
%
% Parameters:
% v (vector): vector to be considered
%
% Returns:
% idx (integer): index of the maximum
[v, idx] = max(v);
end
function idx = get_idx_min(v)
% Get the index of the minimum element.
%
% Parameters:
% v (vector): vector to be considered
%
% Returns:
% idx (integer): index of the minimum
[v, idx] = min(v);
end