From e75e7f2f8916832f6eb83fb3e8aa2f91b44c40ba Mon Sep 17 00:00:00 2001 From: Francesco Carpanese <francesco.carpanese@epfl.ch> Date: Wed, 6 Feb 2019 17:35:46 +0000 Subject: [PATCH] function get information from the connection matrix and plot it git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@11404 d63d8f72-b253-0410-a779-e742ad2e26cf --- .../TCV_IMAS/extract_info_connection_matrix.m | 80 +++++++++++++++++++ crpptbx/TCV_IMAS/plot_connection_matrices.m | 60 ++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 crpptbx/TCV_IMAS/extract_info_connection_matrix.m create mode 100644 crpptbx/TCV_IMAS/plot_connection_matrices.m diff --git a/crpptbx/TCV_IMAS/extract_info_connection_matrix.m b/crpptbx/TCV_IMAS/extract_info_connection_matrix.m new file mode 100644 index 00000000..07fa101c --- /dev/null +++ b/crpptbx/TCV_IMAS/extract_info_connection_matrix.m @@ -0,0 +1,80 @@ +function info = extract_info_connection_matrix(IDS) +% Extract the following information from pf_active and connection +% matrix and add them to the IDS structure + +% ------------------------------------------- +% Which coils belong to a specific circuit added to +% pf_active.circuit{i}.coils_belonging_to_circuit + +% Which power supply belongs to a spefic circuit added to +% pf_active.circuit{i}.supplies_belonging_to_circuit + +% Which circuit does a given coil belong to added to +% pf_active.coil{i}.belonged_circuit + +% Which circuit does a given power supply belong to +% pf_active.supply{i}.belonged_circuit + +info = IDS; + +info.ntotcoils = numel(IDS.pf_active.coil); +info.ntotcircuits = numel(IDS.pf_active.circuit); +info.ntotsupplies = numel(IDS.pf_active.supply); +info.ntotelements = info.ntotcoils + info.ntotsupplies; + +for ii = 1:info.ntotcircuits + + % Supplies belonging to the circuit + supplies_of_circuit = {}; + supplies_of_circuit_ind = []; + counter = 0; + for jj=1:info.ntotsupplies + index = (2*(jj-1) + 1); + if sum(IDS.pf_active.circuit{ii}.connections(:,index)) == 1 + counter = counter +1; + supplies_of_circuit{counter} = IDS.pf_active.supply{jj}.name; + supplies_of_circuit_ind(counter) = jj; + end + end + info.pf_active.circuit{ii}.supplies_belonging_to_circuit = supplies_of_circuit; + info.pf_active.circuit{ii}.supplies_ind_belonging_to_circuit = supplies_of_circuit_ind; + + % Find to which circuit each supply belongs to + for jj=supplies_of_circuit_ind + info.pf_active.supply{jj}.belonged_circuit = IDS.pf_active.circuit{ii}.name; + info.pf_active.supply{jj}.belonged_circuit_ind = ii; + end + + + % Coils belonging to the circuit + coils_of_circuit = {}; + coils_of_circuit_ind = []; + counter = 0; + for jj=1:info.ntotcoils + index = (2*(jj-1) + 1 + 2*info.ntotsupplies); + if sum(IDS.pf_active.circuit{ii}.connections(:,index)) == 1 + counter = counter +1; + coils_of_circuit{counter} = IDS.pf_active.coil{jj}.name; + coils_of_circuit_ind(counter) = jj; + end + end + info.pf_active.circuit{ii}.coils_belonging_to_circuit = coils_of_circuit; + info.pf_active.circuit{ii}.coils_ind_belonging_to_circuit = coils_of_circuit_ind; + + % Find to which circuit each coil belongs to + for jj=coils_of_circuit_ind + info.pf_active.coil{jj}.belonged_circuit = IDS.pf_active.circuit{ii}.name; + info.pf_active.coil{jj}.belonged_circuit_ind = ii; + end + + + +end + + + + + + + + diff --git a/crpptbx/TCV_IMAS/plot_connection_matrices.m b/crpptbx/TCV_IMAS/plot_connection_matrices.m new file mode 100644 index 00000000..b15e0721 --- /dev/null +++ b/crpptbx/TCV_IMAS/plot_connection_matrices.m @@ -0,0 +1,60 @@ +function plot_connection_matrices(IDS) +info = extract_info_connection_matrix(IDS); + +for kk=1:info.ntotcircuits + figure + mat = info.pf_active.circuit{kk}.connections; + + b = zeros([size(mat)]+1); + b(1:end-1, 1:end-1) = mat; + pcolor(b) + + yti = [1:size(b,1)]+0.5; + xti = [1:size(b,2)]+0.5; + + ylab = cellstr(num2str([1:size(b,1)-1]')); + index = 0; + xlab = {}; + + % Get the labels + for ii=1:info.ntotsupplies + index = index +1; + + if any(ii==info.pf_active.circuit{kk}.supplies_ind_belonging_to_circuit) + addcolor = '\color{red}'; + else + addcolor = '\color{green}'; + end + + xlab{index} = [addcolor info.pf_active.supply{ii}.name 'in']; + index = index +1; + xlab{index} = [addcolor info.pf_active.supply{ii}.name 'out']; + end + for ii=1:info.ntotcoils + + if any(ii==info.pf_active.circuit{kk}.coils_ind_belonging_to_circuit) + addcolor = '\color{red}'; + else + addcolor = '\color{black}'; + end + + index = index +1; + xlab{index} = [addcolor info.pf_active.coil{ii}.name 'in']; + index = index +1; + xlab{index} = [addcolor info.pf_active.coil{ii}.name 'out']; + end + + shg + axis ij + ax = gca; + colormap(bone(2)) + xlabel('Element name. (red) Elemement belonging to circuit. (green) power supplies. (black) coils'); + ylabel('Node'); + title(['Circuit ' num2str(kk) ': ' info.pf_active.circuit{kk}.name]) + set(ax,'Xtick', xti, 'Ytick', yti, 'XTickLabel', xlab, 'YTickLabel', ylab') + +end + +end + + -- GitLab