⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_parmosm2.m

📁 带电粒子在电磁场中运动轨迹模拟程序
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = s_parmosM2(varargin)
% main program

%     Copyright (C) 2007 
%
%       mag. David Erzen
%       Faculty of Mechanical Engineering
%       LECAD Laboratory
%       Askerceva 6
%       1000 Ljubljana
%       SLOVENIA
%       contact email: david.erzen@lecad.uni-lj.si
%       
%       Prof. John P. Verboncoeur
%       Plasma Theory and Simulation Group
%       University of California
%       Berkeley, CA 94720-1730 USA
%       
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
    



%**************************************************************************
% MAJOR CORRECTIONS: 
% file: simulation_run.m
% correction: a calcualtion for guiding center is added into the
% calculate_guideCenter procedure
%
% file: simulation_run.m and sim1.wrl
% correction: a guiding center vector is added in sim1.wrl and calculated
% in simulation_run.m
%
% file: s_parmosM2.m
% correction: an option for manipulting with one field line length is
% added. there is a new pannel in the GUI window where user can choose
% electric, or magnetic field, a field line munber and set its length. the
% vrl window stil refreshes when "Show Fields" button is pressed
%
% file: simulation_run.m
% correction: in function calculate_guideCenter the test in if sentence was
% changed. before: if (t(1) ~= t1(1)) && (t(2) ~= t1(2)) &&(t(3) ~= t1(3))
% &&(t1(1) ~= t2(1)) &&(t1(2) ~= t2(2)) && (t1(3) ~= t2(3)) 
% after: if ((t(1) ~= t1(1)) || (t(2) ~= t1(2)) || (t(3) ~= t1(3))) &&
% ((t(1) ~= t2(1)) || (t(2) ~= t2(2)) || (t(3) ~= t2(3))) && ((t2(1) ~=
% t1(1)) || (t2(2) ~= t1(2)) || (t2(3) ~= t1(3))) 
% Before none of the three coordinates should be the same in the three
% points. Now, points should differ form one to another at least in one
% coodrinate.
%
% file: prepare_information.m, s_parmosM2.m, s_parmosM2.fig,
% initialization.m, lobal_variables.m
% correction: an option for concentric magnetic field is added. it is the
% same magnetic field like torus but with a different geometry for field
% lines.
%
% file: global_variables.m
% correction: a Bline_length variable can be changed here for faster
% handling. otherwise this line is under comment therefore just the pannel
% is used to change the field line length
%
% TIME DEPENDENT FIELDS
% fields have time factor with some predefined time functions
% factor is calculated in functions: calculate_B and calculate_E
% visualization of this factor is presented in transparency of field's
% lines, e.g. when factor is 1 lines are not transparent, when factor is 0
% lines are 100% transparent
%

%**************************************************************************


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @s_parmosM2_OpeningFcn, ...
                   'gui_OutputFcn',  @s_parmosM2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT    
end

% --- Executes just before s_parmosM2 is made visible.
function s_parmosM2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to s_parmosM2 (see VARARGIN)

% Choose default command line output for s_parmosM2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes s_parmosM2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

    % aditional initialization
    global_variables;
    status = STATUS_STOP;
    Bline_length = [550, 540, 530, 530, 530, 530, 540, 540, 540, 540, 540, 550, 540, 550, 540, 550, 540, 550 ];
    Eline_length = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500 ];
    
    
    set(handles.stextMagField, 'Visible', 'Off');
    set(handles.edtMagField, 'Visible', 'Off');
    set(handles.stextElecField, 'Visible', 'Off');
    set(handles.edtElecField, 'Visible', 'Off');
    field_Bchosen = BFIELD_NONE;
    

end

% --- Outputs from this function are returned to the command line.
function varargout = s_parmosM2_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;
end

% --- Executes on selection change in popMagField.
function popMagField_Callback(hObject, eventdata, handles)
% hObject    handle to popMagField (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popMagField contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popMagField

    global_variables;
    
    switch get(handles.popMagField, 'Value')
        case BFIELD_NONE                                    % no magnetic field is selected
            set(handles.stextMagField, 'Visible', 'Off');
            set(handles.edtMagField, 'Visible', 'Off');
            
        case BFIELD_CONSTANT                                % constant magnetic filed in z direction
            set(handles.stextMagField, 'Visible', 'On');
            set(handles.stextMagField, 'String', 'Define magnetic field strength [T]');
            set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '0.01');
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[0; 0; 0]');
            set(handles.edtInitVel, 'String', '[0; 3e5; 1e4]');
            set(handles.edtMass, 'String', '1.6e-27');
            set(handles.edtCharge, 'String', '1.6e-19');
            
        case BFIELD_EXPONENT                                % magnetic field in z direction, exponential fall in x direction
            set(handles.stextMagField, 'Visible', 'On');
            set(handles.stextMagField, 'String', 'Equ: Bo*(0,0,exp(-x/L)). Define constants Bo and L');
            set(handles.edtMagField, 'String', '[ 0.025, 0.7 ]');
            set(handles.edtMagField, 'Visible', 'On' );
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[0; 0; 0]');
            set(handles.edtInitVel, 'String', '[0; 3e5; 1e3]');
            set(handles.edtMass, 'String', '1.6e-27');
            set(handles.edtCharge, 'String', '1.6e-19');
            
        case BFIELD_TORUS                                   % magnetic field in a torus
            set(handles.stextMagField, 'String', 'Equ: Bo*Ro(-y, x, 0)/(x^2+y^2). Define Bo, Ro(also torus major radius) and a(torus minor radius)');
            set(handles.stextMagField, 'Visible', 'On');            
             set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '[ 0.1, 2, 1 ]'); 
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[2; 0; 0]');
            set(handles.edtInitVel, 'String', '[0; 3e5; 1e3]');
            set(handles.edtMass, 'String', '1.6e-27');
            set(handles.edtCharge, 'String', '1.6e-19');
            
        case BFIELD_TORUS_POLOIDAL                           % magnetic field in a torus with poloidal magnetic field
            set(handles.stextMagField, 'String', 'Equ: Bo*Ro(-y, x, 0)/(x^2+y^2) + ???????? Define Bt, Ro, Bp and a');
            set(handles.stextMagField, 'Visible', 'On');            
            set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '[ 0.05, 3, -0.01, 1 ]'); 
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[3.8; 0; 0]');
            set(handles.edtInitVel, 'String', '[2e5; 1e5; 2e5]');
            set(handles.edtMass, 'String', '3.67e-27');
            set(handles.edtCharge, 'String', '1.6e-19');
            
        case BFIELD_CONCENTRIC                              % magnetic field in a torus with poloidal magnetic field
            set(handles.stextMagField, 'String', 'Bo*Ro/(x^2+y^2)*[ -y, x, 0 ]  Define Bo and Ro.');
            set(handles.stextMagField, 'Visible', 'On');            
            set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '[ 0.015, 0.5 ]'); 
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[0; 0.5; 0]');
            set(handles.edtInitVel, 'String', '[5e4; 2e5; 0]');
            set(handles.edtMass, 'String', '1.6e-27');
            set(handles.edtCharge, 'String', '1.6e-19');
            
        case BFIELD_CUSTOM                                   % custom magnetic field
            set(handles.stextMagField, 'String', 'Define magnetic field [Bx, By, Bz]. Instead of the coordinates xyz use R(1)R(2)R(3). Example: [ 0, (R(1)+R(2))/Sqrt(R(1)^2+R(2)^2+R(3)^2), R(3)/Sqrt(R(1)^2+R(2)^2+R(3)^2) ]');
            set(handles.stextMagField, 'Visible', 'On');
            set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '[ 0, 0, 0 ]');     
            
       case BFIELD_MIRROR                              % magnetic field in a magnetic mirror / cusp
            set(handles.stextMagField, 'String', 'Define magnetic monopol displacement and top and bottom sign.');
            set(handles.stextMagField, 'Visible', 'On');            
            set(handles.edtMagField, 'Visible', 'On');
            set(handles.edtMagField, 'String', '[ 5, 0.03, -0.03 ]'); 
            
            % lets set also some "nice" particle parameters
            set(handles.edtInitPos, 'String', '[0; 0.1; 0]');
            set(handles.edtInitVel, 'String', '[1e5; 1e5; 1e5]');
            set(handles.edtMass, 'String', '1.6e-27');
            set(handles.edtCharge, 'String', '1.6e-19');

            
    end

end

% --- Executes during object creation, after setting all properties.
function popMagField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popMagField (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


function edtMagField_Callback(hObject, eventdata, handles)
% hObject    handle to edtMagField (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edtMagField as text
%        str2double(get(hObject,'String')) returns contents of edtMagField as a double
end

% --- Executes during object creation, after setting all properties.
function edtMagField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtMagField (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end

% --- Executes on slider movement.
function sliderForce_Callback(hObject, eventdata, handles)
% hObject    handle to sliderForce (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
    global_variables;
    value = get(hObject,'Value');
    factor_force = 10^value;
end

% --- Executes during object creation, after setting all properties.
function sliderForce_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderForce (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end;
    global_variables;
    value = 13.0;
    set(hObject,'Value', value);
    factor_force = 10^value;
end

% --- Executes on button press in rbuttTraject.
function rbuttTraject_Callback(hObject, eventdata, handles)
% hObject    handle to rbuttTraject (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of rbuttTraject
    global_variables;
    traj_set = get( hObject, 'Value' );
end

% --- Executes on slider movement.
function sliderVel_Callback(hObject, eventdata, handles)
% hObject    handle to sliderVel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
    
    global_variables;
    value = get(hObject,'Value');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -