fitfluct_yp

PURPOSE ^

SYNOPSIS ^

function [fluct_out] = fitfluct_yp(fluct_in,mode,method,ngrid,nharm)

DESCRIPTION ^

 Build vectorial plasma fluctuation profiles from its numerical counterpart
 Two operating modes :
 1) Spline-Fourier description for (psi,theta) magnetic equilibrium (HELENA for example)

    1-D: use interp1.m MatLab built-in function (Hermite polynomials (pchip), spline, bi-cubic, linear,  nearest,...)
    2-D: use Fourier series expansion for the poloidal dependence and the
    interp1.m for the Fourier series coefficients (Hermite polynomials (pchip), spline, bi-cubic, linear,
    nearest,...)

 2) Spline-Spline description for (x,y) magnetic equilibrium (EFIT for example)

    1-D: use interp1.m MatLab built-in function (Hermite polynomials (pchip), spline, bi-cubic, linear, nearest,...)
    2-D: use interp1.m for the x-direction and the interp1.m again for the coefficients of the 
    previous spline (Hermite polynomials (pchip), spline, bi-cubic, linear, nearest,...)

 By Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fluct_out] = fitfluct_yp(fluct_in,mode,method,ngrid,nharm)
0002 %
0003 % Build vectorial plasma fluctuation profiles from its numerical counterpart
0004 % Two operating modes :
0005 % 1) Spline-Fourier description for (psi,theta) magnetic equilibrium (HELENA for example)
0006 %
0007 %    1-D: use interp1.m MatLab built-in function (Hermite polynomials (pchip), spline, bi-cubic, linear,  nearest,...)
0008 %    2-D: use Fourier series expansion for the poloidal dependence and the
0009 %    interp1.m for the Fourier series coefficients (Hermite polynomials (pchip), spline, bi-cubic, linear,
0010 %    nearest,...)
0011 %
0012 % 2) Spline-Spline description for (x,y) magnetic equilibrium (EFIT for example)
0013 %
0014 %    1-D: use interp1.m MatLab built-in function (Hermite polynomials (pchip), spline, bi-cubic, linear, nearest,...)
0015 %    2-D: use interp1.m for the x-direction and the interp1.m again for the coefficients of the
0016 %    previous spline (Hermite polynomials (pchip), spline, bi-cubic, linear, nearest,...)
0017 %
0018 % By Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr)
0019 %
0020 if nargin == 1, 
0021     mode = 1;%Spline-Fourier case
0022     method = 'pchip';
0023     ngrid = 1001;
0024     nharm = [];
0025 end
0026 if nargin == 2, 
0027     method = 'pchip';
0028     ngrid = 1001;
0029     nharm = [];
0030 end
0031 if nargin == 3, 
0032     ngrid = 1001;  
0033     nharm = [];
0034 end
0035 if nargin == 4, 
0036     nharm = [];%For Spline-Fourier case only
0037 end
0038 %
0039 srho = linspace(0,1,ngrid).^2;
0040 lrho = length(fluct_in.rho);
0041 mtheta = length(fluct_in.theta);
0042 nphi = length(fluct_in.phi);
0043 %
0044 nharm = length(fluct_in.theta) - 1;
0045 %
0046 field_name = fieldnames(fluct_in);
0047 %
0048 test_field_name_ne = strfind(field_name,'ne');%test existence of density fluctuation
0049 test_field_name_B = strfind(field_name,'B');%test existence of magnetic field fluctuation
0050 flag_naequilp_fluct = 0;
0051 for i = 1:length(field_name),
0052     if ~isempty(test_field_name_ne{i}) | ~isempty(test_field_name_B{i}), flag_naequilp_fluct = flag_naequilp_fluct + 1;end
0053 end
0054 %
0055 for i = 1:length(field_name),
0056     if isfield(fluct_in,field_name(i)),
0057         if isstruct(fluct_in.(char(field_name(i)))) && isempty(strfind(char(field_name(i)),'fitparam')) && isempty(strfind(char(field_name(i)),'npar0_lh')),
0058             for istruct = 1:length(fluct_in.(char(field_name(i)))),
0059                 subfield_name = fieldnames(fluct_in.(char(field_name(i))));
0060                 %
0061                 for j = 1:length(subfield_name),
0062                     if strcmp(char(subfield_name{j}(1)),'phase') || strcmp(char(subfield_name{j}(1)),'X'), 
0063                         if mode == 1,%Mode 1 (rho,theta,phi)
0064                             if size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == nphi,%(rho,theta,phi) vectorisation
0065                                 %Not yet implemented
0066                             elseif size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),1) == lrho && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),2) == mtheta && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),3) == 1,%(rho,theta) vectorisation
0067                                 fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),srho,method),srho,fluct_in.theta,nharm);% Data are resampled on a finer mesh close to psi (or rho) = 0 before Hermite-Fourier calculations.
0068                             elseif size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),1) == lrho && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),2) == 1 && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),3) == 1,%(rho) vectorisation
0069                                 fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),srho,method),srho);% Data are resampled on a finer mesh close to psi (or rho) = 0 before Hermite-Fourier calculations.
0070                             %else
0071                                 %fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j))]) = fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j)));
0072                             end
0073                         else
0074                             error('Mode 2 (x,y,phi) not yet implemented in fitfluct_yp.m');
0075                         end
0076                     else
0077                         fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j))]) = fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j)));
0078                     end
0079                 end  
0080             end
0081         else
0082             if strcmp(char(field_name{i}(1)),'x') || strcmp(char(field_name{i}(1)),'X'), 
0083                 if flag_naequilp_fluct,%only is a fluctuation or a magnetic ripple model exists
0084                     if size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == nphi,%(rho,theta,phi) vectorisation
0085                        %Not yet implemented
0086                     elseif size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == 1,%(rho,theta) vectorisation
0087                         fluct_out.([char(field_name(i)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i))),srho,method),srho,fluct_in.theta,nharm);% Data are resampled on a finer mesh close to psi (or rho) = 0 before Hermite-Fourier calculations.
0088                     elseif size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == 1 && size(fluct_in.(char(field_name(i))),3) == 1,%(rho) vectorisation
0089                         fluct_out.([char(field_name(i)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i))),srho,method),srho);% Data are resampled on a finer mesh close to psi (or rho) = 0 before Hermite-Fourier calculations.
0090                     end
0091                 end
0092             else
0093                 if ~strcmp(char(field_name(i)),'rho') && ~strcmp(char(field_name(i)),'theta') && ~strcmp(char(field_name(i)),'phi')
0094                     if strcmp(char(field_name(i)),'npar0_lh') || strcmp(char(field_name(i)),'id'),
0095                         fluct_out.(char(field_name(i))) = fluct_in.(char(field_name(i)));
0096                     else
0097                         if flag_naequilp_fluct,
0098                             fluct_out.(char(field_name(i))) = fluct_in.(char(field_name(i)));
0099                             if strcmp(char(field_name(i)),'equil_id'),fluct_out.method = method;end
0100                         end 
0101                     end
0102                 end
0103             end
0104         end
0105     end
0106 end
0107 %
0108 
0109 
0110 
0111

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.