Set the phase in the interpolated fluctuation spectrum INPUT - fluct: plasma fluctuations structure - mode: pseudo-random number generator (0: Mersenne twister, 1: matlab) (default mode = 1) OUTPUT: - fluct_out: plasma fluctuations structure with phase modified or added if necessary By Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr)
0001 function [fluct_out] = fluctphase_yp(fluct,mode) 0002 % 0003 % Set the phase in the interpolated fluctuation spectrum 0004 % 0005 % INPUT 0006 % - fluct: plasma fluctuations structure 0007 % - mode: pseudo-random number generator (0: Mersenne twister, 1: matlab) 0008 % (default mode = 1) 0009 % 0010 % OUTPUT: 0011 % - fluct_out: plasma fluctuations structure with phase modified or added if necessary 0012 % 0013 % By Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr) 0014 % 0015 if nargin < 1, 0016 error('Not enough input arguments in fluctphase_yp.m'); 0017 end 0018 % 0019 if nargin < 2, 0020 mode = 1;%rand reset by clock 0021 end 0022 % 0023 fluct_out = fluct; 0024 % 0025 field_name = fieldnames(fluct); 0026 % 0027 for i = 1:length(field_name), 0028 if isstruct(fluct.(char(field_name(i)))) && (strcmp(char(field_name(i)),'B') || strcmp(char(field_name(i)),'ne') || strcmp(char(field_name(i)),'B_fit') || strcmp(char(field_name(i)),'ne_fit')), 0029 for ifield = 1:length(fluct.(char(field_name(i)))), 0030 % 0031 if fluct.(char(field_name(i)))(ifield).model == 0,%Magnetic ripple (fixed phase) 0032 phase = [];%no phase needed 0033 elseif fluct.(char(field_name(i)))(ifield).model >= 1,%random phase approximation (statistical description) 0034 dl = fluct.(char(field_name(i)))(ifield).lmax - fluct.(char(field_name(i)))(ifield).lmin + 1; 0035 dm = fluct.(char(field_name(i)))(ifield).mmax - fluct.(char(field_name(i)))(ifield).mmin + 1; 0036 dn = fluct.(char(field_name(i)))(ifield).nmax - fluct.(char(field_name(i)))(ifield).nmin + 1; 0037 if mode == 0, 0038 [lukeversion,matlabversion] = LUKEversion_jd; 0039 if str2num(matlabversion) < 713, 0040 RandStream.setDefaultStream(RandStream('mt19937ar','seed',5489));%reset rand with original Mersenne-Twister pseudo-random number generator 0041 else 0042 RandStream.setGlobalStream(RandStream('mt19937ar','seed',5489));%reset rand with original Mersenne-Twister pseudo-random number generator 0043 end 0044 end 0045 % 0046 if fluct.(char(field_name(i)))(ifield).model == 1 || fluct.(char(field_name(i)))(ifield).model == 2, 0047 phase = 2*pi*rand(1,dl*dm*dn) - pi;% 0048 elseif fluct.(char(field_name(i)))(ifield).model == 3 || fluct.(char(field_name(i)))(ifield).model == 6, 0049 phase = 2*pi*rand(1,dl*dm) - pi;% 0050 elseif fluct.(char(field_name(i)))(ifield).model == 4 || fluct.(char(field_name(i)))(ifield).model == 5, 0051 phase = 2*pi*rand(1,dm) - pi;% 0052 else 0053 error('Error in fluctuation phase calculation, model unrecongized !'); 0054 end 0055 % 0056 phase = phase(:)'; 0057 end 0058 % 0059 fluct_out.(char(field_name(i)))(ifield).phase = phase; 0060 % 0061 end 0062 end 0063 end 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 %function [fluct_out] = fluctphase_yp(fluct,dtn,optdisp) 0090 % 0091 % Set the phase in the interpolated fluctuation spectrum 0092 % 0093 % INPUT 0094 % - fluct: plasma fluctuations structure 0095 % - dtn: integration time step normalized to the collision time [1,1] 0096 % (default = NaN) 0097 % - optdisp: display option [1,1] 0098 % (default = 0) 0099 % 0100 % OUTPUT: 0101 % - fluct_out: plasma fluctuations structure with phase modified or added if necessary 0102 % 0103 % By Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr) 0104 % 0105 %if nargin < 1, 0106 % error('Not enough input arguments in fluctphase_yp.m'); 0107 %end 0108 % 0109 %if nargin < 2, 0110 % dtn = NaN; 0111 % optdisp = 0; 0112 %end 0113 % 0114 %if nargin < 3, 0115 % optdisp = 0; 0116 %end 0117 % 0118 %fluct_out = fluct; 0119 % 0120 %field_name = fieldnames(fluct); 0121 % 0122 %for i = 1:length(field_name), 0123 % if isstruct(fluct.(char(field_name(i)))) && isempty(strfind(char(field_name(i)),'cn')) && isempty(strfind(char(field_name(i)),'cm')) && isempty(strfind(char(field_name(i)),'cn_fit')) && isempty(strfind(char(field_name(i)),'cm_fit')) && isempty(strfind(char(field_name(i)),'fitparam')), 0124 % for ifield = 1:length(fluct.(char(field_name(i)))), 0125 % % 0126 % nkperp = length(fluct.(char(field_name(i)))(ifield).kp); 0127 % kpmin = min(fluct.(char(field_name(i)))(ifield).kp); 0128 % kpmax = max(fluct.(char(field_name(i)))(ifield).kp); 0129 % if fluct.(char(field_name(i)))(ifield).model == 1,%Gaussian kperp-spectrum (random phase) + electron drift wave 0130 % if isfield(fluct.(char(field_name(i)))(ifield),'phase') && isfield(fluct.(char(field_name(i)))(ifield),'omegakpn') && ~isnan(dtn), 0131 % phase = fluct.(char(field_name(i)))(ifield).phase - fluct.(char(field_name(i)))(ifield).omegakpn*dtn; 0132 % else 0133 % phase = 2*pi*rand(1,nkperp) - pi; 0134 % end 0135 % elseif fluct.(char(field_name(i)))(ifield).model == 0,%Magnetic ripple (fixed phase) 0136 % phase = zeros(1,nkperp); 0137 % else 0138 % error('Plasma fluctuations model unknown !') 0139 % end 0140 % % 0141 % fluct_out.(char(field_name(i)))(ifield).phase = phase; 0142 % % 0143 % if isfield(fluct.(char(field_name(i)))(ifield),'phase') && optdisp, 0144 % figure('Name',['Fluctuation phase ',regexprep(char(field_name(i)), '_fit', '')]), 0145 % close(['Fluctuation phase ',regexprep(char(field_name(i)), '_fit', '')]); 0146 % figure('Name',['Fluctuation phase ',regexprep(char(field_name(i)), '_fit', '')]), 0147 % graph1D_jd(fluct.(char(field_name(i)))(ifield).kp,fluct.(char(field_name(i)))(ifield).phase,0,0,'k*a_p','Phase [-\pi,\pi]',['Fluctuation phase ',regexprep(char(field_name(i)), '_fit', '')],NaN,[kpmin,kpmax],'','none','+','r',2);drawnow 0148 % graph1D_jd(fluct.(char(field_name(i)))(ifield).kp,fluct_out.(char(field_name(i)))(ifield).phase,0,0,'k*a_p','Phase [-\pi,\pi]',['Fluctuation phase ',regexprep(char(field_name(i)), '_fit', '')],NaN,[kpmin,kpmax],'','none','x','b',2);drawnow 0149 % legend('Old','New'); 0150 % % 0151 % end 0152 % end 0153 % end 0154 %end 0155