Skip to content
Snippets Groups Projects
Commit c3f59cb8 authored by Olivier Sauter's avatar Olivier Sauter
Browse files

fix pf_active, magnetics, wall, tf. Not sure yet for pf_passive if empty or not

parent 8f5a9da7
No related branches found
No related tags found
2 merge requests!50Fix complete ids corsica keep ids structures,!48Fix complete ids corsica keep ids structures
Pipeline #31657 passed with stage
in 1 minute and 16 seconds
......@@ -63,12 +63,23 @@ end
%% Add the data to the circuit
tmp = data_circuits();
Ncircuits = size(tmp,1);
Ncircuit_eff = size(tmp,1);
Ncircuit_in = numel(IDS_out.pf_active.circuit);
Nsupply_in = numel(IDS_out.pf_active.supply);
Ncoils = numel(IDS_out.pf_active.coil);
% time will be set in circuit.current.time so should not put it at top and set homogeneous to 0?
IDS_out.pf_active.time = [];
IDS_out.pf_active.ids_properties.homogeneous_time = 0;
for ii=1:Ncircuits
% Make sure default substructure maintained if insert new indices
pf_active_default = gdat([],'ids','source','pf_active');
pf_active_default = pf_active_default.pf_active;
if Ncircuit_eff > Ncircuit_in
IDS_out.pf_active.circuit(Ncircuit_in+1:Ncircuit_eff) = pf_active_default.circuit(1);
end
if Ncircuit_eff > Nsupply_in
IDS_out.pf_active.supply(Nsupply_in+1:Ncircuit_eff) = IDS_out.pf_active.supply(Nsupply_in);
end
for ii=1:Ncircuit_eff
IDS_out.pf_active.circuit{ii}.name = tmp{ii,1}{1};
IDS_out.pf_active.supply{ii}.name = tmp{ii,1}{1};
% Find index of the coils belonging to ii circuit
......@@ -83,10 +94,10 @@ for ii=1:Ncircuits
IDS_out.pf_active.circuit{ii}.current.data = IDS_out.pf_active.coil{index_coil(1)}.current.data/IDS_out.pf_active.coil{index_coil(1)}.element{1}.turns_with_sign;
IDS_out.pf_active.circuit{ii}.current.time = IDS_out.pf_active.coil{index_coil(1)}.current.time;
IDS_out.pf_active.circuit{ii}.connections = zeros(2*numel(index_coil) -1 , 2*Ncircuits + 2*Ncoils);
IDS_out.pf_active.circuit{ii}.connections = zeros(2*numel(index_coil) -1 , 2*Ncircuit_eff + 2*Ncoils);
for jj = 1:numel(index_coil)
IDS_out.pf_active.circuit{ii}.connections( jj , 2*Ncircuits + 2*(index_coil(jj)-1) +1) = 1;
IDS_out.pf_active.circuit{ii}.connections( jj +1 , 2*Ncircuits + 2*(index_coil(jj)-1) +2) = 1;
IDS_out.pf_active.circuit{ii}.connections( jj , 2*Ncircuit_eff + 2*(index_coil(jj)-1) +1) = 1;
IDS_out.pf_active.circuit{ii}.connections( jj +1 , 2*Ncircuit_eff + 2*(index_coil(jj)-1) +2) = 1;
end
% Add the connection to the power supply
......@@ -96,111 +107,72 @@ end
%% Limiter description
tmp = data_limiter();
IDS_out.wall.ids_properties.homogeneous_time = 0; % no times are set so just say not homogeneous
IDS_out.wall.description_2d{1}.limiter.unit{1}.outline.r = tmp.r;
IDS_out.wall.description_2d{1}.limiter.unit{1}.outline.z = tmp.z;
% problem with mex ids_put when time default or empty, make outline and ggd empty
IDS_out.wall.description_2d{1}.mobile.unit{1}.outline = {};
IDS_out.wall.description_ggd = {};
  • Author Maintainer

    @amerle the .time in these substructure exist but are either empty or "default value". However I get an error in the ids_put:

    ual_end_action: [UALBackendException = Cannot get Time information] ual_print_context: [UALLowlevelException = Cannot find context 8 in store] problems in putting data in database: Error using ids_put internal error occured with error code -1 ... in aos description_ggd/grid_ggd ... in IDS wall

    What is the rule? Or may be there is no rule ? At this stage I made the parent an empty cell then it works

  • Owner

    I don't know if it's a rule or a recommendation but yes for any array that exists you have to provide its dimensions. So for a dynamic array of structure time must be filled (or if homogeneous time is selected the base time). I think for time that is a rule. In that case it triggers an error because it is used by the backend and it can't find it (it's not an error that is linked to the mex interface particularly)

    Same as always, you have to remove all unused arrays of structures before doing ids_put.

    This is why for the mex I provide:

    • ids_gen2 which initialises every array of structures as empty
    • ids_allocate which given an ids name, a path within the ids and a size will allocate the corresponding array of structures with the correct size.

    This way is more similar to the FORTRAN interface if you see what I mean.

    Edited by Antoine Merle
  • Author Maintainer

    Actually having empty structures in the ids_gen is a problem since we are adding just a few data like xxx.yyy.name and xxx.yyy.data. If we do not copy the expected substructure in yyy, then xxx.yyy has only the "name" and "data" fields and the ids_put fails.

    So I cannot use something like ids_gen2, nor use the ids_get with your mex, but need the ids_gen, then copy the default structure with all expected fields in yyy then put the relevant data in yyy.name and yyy.data. What I do not do is to check that a field exists before modifying, which I should actually like isfield(xxx.yyy,'name');...

  • Owner

    But ... that was the purpose of my second bullet with the ids_allocate part ...

  • Author Maintainer

    OK I never tried that one hence do not know, you can do sub-allocation like:

    magnetics.bpol_probe(2:N) = ids_allocate('magnetics','bpol_probe',N-1);

    or something like that?

    OK I just checked, indeed I can do the above. But is it standard?

  • Owner

    Is it shared by the other MATLAB interface? no

    But the plan is to phase out the other MATLAB interface, and I think this approach has advantages over the previous one so I hope no one will truly oppose it.

    Since with ids_gen2, all arrays are initially empty, you would rather do something like:

    magnetics.bpol_probe = ids_allocate('magnetics','bpol_probe',N);
    Edited by Antoine Merle
  • Please register or sign in to reply
%% Vessel description
% Understand what I need to do for the double layer vessel
%% -------------- Synthetic diagnostics------------ Need to be recomputed from CORSICA flux map
% since time set in subnode method{1}.ip.time, set homogeneous to 0 (magnetics.time already empty)
IDS_out.magnetics.ids_properties.homogeneous_time = 0;
IDS_out.magnetics.method{1}.ip.time = LXC.t;
IDS_out.magnetics.method{1}.ip.data = LXC.Ip;
% Correct IDS magnetics
aa = gdat([],'ids','source','magnetics');
magnetics_default = aa.magnetics;
mag_fluxloop_def_fields = fieldnames(magnetics_default.flux_loop{1});
if isfield(IDS_out.magnetics,'flux_loop') && length(IDS_out.magnetics.flux_loop) > 0
mag_fluxloop_fields = fieldnames(IDS_out.magnetics.flux_loop{1});
else
mag_fluxloop_fields = {};
end
fields_to_add = setdiff(mag_fluxloop_def_fields,mag_fluxloop_fields);
%% Ff
tmp = data_Ff();
for ii=1:numel(tmp.r)
if ~isempty(fields_to_add)
for idef=1:length(fields_to_add)
% add first defaults and fill in after
IDS_out.magnetics.flux_loop{ii}.(fields_to_add{idef}) = magnetics_default.flux_loop{1}.(fields_to_add{idef});
end
if ii==1; warning(['following fields added to magnetics.flux_loop: ' sprintf('%s ',fields_to_add{:})]); end
end
% Make sure default substructure maintained if insert new indices
magnetics_default = gdat([],'ids','source','magnetics');
magnetics_default = magnetics_default.magnetics;
Nflux_loop_in = numel(IDS_out.magnetics.flux_loop);
Nflux_loop_eff = numel(tmp.r);
if Nflux_loop_eff > Nflux_loop_in
IDS_out.magnetics.flux_loop(Nflux_loop_in+1:Nflux_loop_eff) = magnetics_default.flux_loop(1);
end
for ii=1:Nflux_loop_eff
IDS_out.magnetics.flux_loop{ii}.position{1}.r = tmp.r(ii);
IDS_out.magnetics.flux_loop{ii}.position{1}.z = tmp.z(ii);
IDS_out.magnetics.flux_loop{ii}.name = tmp.name{ii};
end
for ii=1:numel(tmp.r)
IDS_out.magnetics.flux_loop{ii}.flux.data = -LXC.Ff(ii,:)';
IDS_out.magnetics.flux_loop{ii}.flux.time = LXC.t;
for ii=1:Nflux_loop_eff
IDS_out.magnetics.flux_loop{ii}.flux.data = -LXC.Ff(ii,:)';
IDS_out.magnetics.flux_loop{ii}.flux.time = LXC.t;
end
%% Bm
% Correct IDS magnetics
mag_bpol_probe_def_fields = fieldnames(magnetics_default.bpol_probe{1});
if isfield(IDS_out.magnetics,'bpol_probe') && length(IDS_out.magnetics.bpol_probe) > 0
mag_bpol_probe_fields = fieldnames(IDS_out.magnetics.bpol_probe{1});
else
mag_bpol_probe_fields = {};
end
fields_to_add = setdiff(mag_bpol_probe_def_fields,mag_bpol_probe_fields);
mag_bpol_probe_def_fields = fieldnames(magnetics_default.bpol_probe{1}.position);
if length(IDS_out.magnetics.bpol_probe) > 0 && isfield(IDS_out.magnetics.bpol_probe{1},'position')
mag_bpol_probe_fields = fieldnames(IDS_out.magnetics.bpol_probe{1}.position);
else
mag_bpol_probe_fields = {};
end
fields_to_add_position = setdiff(mag_bpol_probe_def_fields,mag_bpol_probe_fields);
tmp = data_Bm();
for ii=1:numel(tmp.name)
if ~isempty(fields_to_add)
for idef=1:length(fields_to_add)
% add first defaults and fill in after
IDS_out.magnetics.bpol_probe{ii}.(fields_to_add{idef}) = magnetics_default.bpol_probe{1}.(fields_to_add{idef});
end
if ii==1; warning(['following fields added to magnetics.bpol_probe: ' sprintf('%s ',fields_to_add{:})]); end
end
if ~isempty(fields_to_add_position)
for idef=1:length(fields_to_add_position)
% add_position first defaults and fill in after
IDS_out.magnetics.bpol_probe{ii}.position.(fields_to_add_position{idef}) = magnetics_default.bpol_probe{1}.position.(fields_to_add_position{idef});
end
if ii==1; warning(['following fields add_positioned to magnetics.bpol_probe.position: ' sprintf('%s ',fields_to_add_position{:})]); end
end
% Make sure default substructure maintained if insert new indices
Nbpol_probe_in = numel(IDS_out.magnetics.bpol_probe);
Nbpol_probe_eff = numel(tmp.name);
if Nbpol_probe_eff > Nbpol_probe_in
IDS_out.magnetics.bpol_probe(Nbpol_probe_in+1:Nbpol_probe_eff) = magnetics_default.bpol_probe(1);
end
for ii=1:Nbpol_probe_eff
IDS_out.magnetics.bpol_probe{ii}.position.r = tmp.r(ii);
IDS_out.magnetics.bpol_probe{ii}.position.z = tmp.z(ii);
IDS_out.magnetics.bpol_probe{ii}.poloidal_angle = -tmp.am(ii); % Correct the sign to be consistent with COCOS 11
IDS_out.magnetics.bpol_probe{ii}.name = tmp.name{ii};
end
for ii=1:numel(tmp.name)
for ii=1:Nbpol_probe_eff
IDS_out.magnetics.bpol_probe{ii}.field.data = LXC.Bm(ii,:)';
IDS_out.magnetics.bpol_probe{ii}.field.time = LXC.t;
end
%% Ft
mag_method_def_fields = fieldnames(magnetics_default.method{1});
if isfield(IDS_out.magnetics,'method') && length(IDS_out.magnetics.method) > 0
mag_method_fields = fieldnames(IDS_out.magnetics.method{1});
else
mag_method_fields = {};
end
fields_to_add = setdiff(mag_method_def_fields,mag_method_fields);
if ~isempty(fields_to_add)
for idef=1:length(fields_to_add)
% add first defaults and fill in after
IDS_out.magnetics.method{1}.(fields_to_add{idef}) = magnetics_default.method{1}.(fields_to_add{idef});
end
warning(['following fields added to magnetics.method: ' sprintf('%s ',fields_to_add{:})]);
end
IDS_out.magnetics.method{1}.diamagnetic_flux.data = -LXC.Ft;
IDS_out.magnetics.method{1}.diamagnetic_flux.time = LXC.t;
%% rBt
IDS_out.tf.ids_properties.homogeneous_time = 1;
IDS_out.tf.time = LXC.t;
IDS_out.tf.b_field_tor_vacuum_r.time = LXC.t;
IDS_out.tf.b_field_tor_vacuum_r.data = LXC.rBt;
......
  • Author Maintainer

    I fixed most things. One question is pf_passive empty or not. Do you use something from the Corsica IDS.pf_passive?

    (cannot ids_put because homogeneous not set, but should not set if empty altogether)

  • Author Maintainer

    @carpanes I added a ids_check_empty and it seems pf_passive is empty, so I guess you do not use it?

    You can check with my shot, run=1111 in my iter database or rmfield pf_passive before running liuqe

  • Developer

    Indeed, vessel current which are the only eventual passive structure, we still don't know how to use them in ITER. Also for the case of TCV I haven't implemented yet, nor I think we are providing them to the IDS structure at the moment.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment