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

📄 s_parmosm2.m

📁 带电粒子在电磁场中运动轨迹模拟程序
💻 M
📖 第 1 页 / 共 3 页
字号:


% --- Executes on button press in rbuttonGuidingCenterVector.
function rbuttonGuidingCenterVector_Callback(hObject, eventdata, handles)
% hObject    handle to rbuttonGuidingCenterVector (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 rbuttonGuidingCenterVector

    global_variables;
    vectorGuide_set = get( hObject, 'Value' );
end


% --------------------------------------------------------------------
function SaveData_Callback(hObject, eventdata, handles)
% hObject    handle to SaveData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    global_variables;
    
    [file,path] = uiputfile;
    file_info = strcat(path, file);
    if strcmp(file, '') == 0
        % saving particle trajectory
        save_file = fopen(file_info,'w');
        fprintf(save_file,'particle trajectory \n');
        fclose(save_file);
        save(file_info, 'trajectory', '-ascii', '-append');
        
        % saving guiding center
        save_file = fopen(file_info,'a');
        fprintf(save_file,'\n guiding center \n');
        fclose(save_file);
        save(file_info, 'guide_center', '-ascii', '-append');
        
        % saving magnetic field lines
        save_file = fopen(file_info,'a');
        fprintf(save_file,'\n magnetic field lines \n');
        fclose(save_file);
        for i = 1:18                          % TODO: change the number to a variable!!!
            save_file = fopen(file_info,'a');
            fprintf(save_file,'\n B line number %d \n', i);
            fclose(save_file);
            if i <= 9
                tmp_num = i;
            else
                tmp_num = i+1;
            end
            name_line = strcat('B', num2str(tmp_num), '_spine');
            line = vrnode(w, name_line); 
            spine_data = line.spine;
            save(file_info,'spine_data', '-ascii', '-append');            
        end;                    
        
        % saving electric field lines
        fprintf(save_file,'\n electric field lines \n');
        for i = 1:18                          % TODO: change the number to a variable!!!
            save_file = fopen(file_info,'a');
            fprintf(save_file,'\n E line number %d \n', i);
            fclose(save_file);
            if i <= 9
                tmp_num = i;
            else
                tmp_num = i+1;
            end
            name_line = strcat('E', num2str(tmp_num), '_spine');
            line = vrnode(w, name_line); 
            spine_data = line.spine;
            save(file_info,'spine_data', '-ascii', '-append');            
        end;                            
        
    end;
    
end


% --- Executes on selection change in popLinenum.
function popLinenum_Callback(hObject, eventdata, handles)
% hObject    handle to popLinenum (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 popLinenum contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popLinenum

    global_variables;
    
    switch get(handles.popFields, 'Value')
        case EFIELD_LINE
            set(handles.edtLinelenght, 'String', Eline_length(get(hObject, 'Value')));
        case BFIELD_LINE
            set(handles.edtLinelenght, 'String', Bline_length(get(hObject, 'Value')));
    end;

end

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

% Hint: listbox 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 selection change in popFields.
function popFields_Callback(hObject, eventdata, handles)
% hObject    handle to popFields (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 popFields contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popFields

    global_variables;
    
    switch get(hObject, 'Value')
        case EFIELD_LINE
            set(handles.edtLinelenght, 'String', Eline_length(get(handles.popLinenum, 'Value')));
        case BFIELD_LINE
            set(handles.edtLinelenght, 'String', Bline_length(get(handles.popLinenum, 'Value')));
    end;

end


% --- Executes during object creation, after setting all properties.
function popFields_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popFields (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 edtLinelenght_Callback(hObject, eventdata, handles)
% hObject    handle to edtLinelenght (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 edtLinelenght as text
%        str2double(get(hObject,'String')) returns contents of edtLinelenght as a double
    global_variables;
    
    switch get(handles.popFields, 'Value')
        case EFIELD_LINE
            Eline_length(get(handles.popLinenum, 'Value')) = str2num(get(hObject, 'String'));
        case BFIELD_LINE
            Bline_length(get(handles.popLinenum, 'Value')) = str2num(get(hObject, 'String'));
    end;

end

% --- Executes during object creation, after setting all properties.
function edtLinelenght_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtLinelenght (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 selection change in popTimeMagField.
function popTimeMagField_Callback(hObject, eventdata, handles)
% hObject    handle to popTimeMagField (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 popTimeMagField contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popTimeMagField

    global_variables;
    
    switch get(handles.popTimeMagField, 'Value')
        case BFIELD_TIMECONSTANT                                    % constant magnetic field
            set(handles.stextTimeMagField, 'Visible', 'Off');
            set(handles.edtTimeMagField, 'Visible', 'Off');
        case BFIELD_SINUSOIDAL                                      % sinusoidal magnetif field
            set(handles.stextTimeMagField, 'Visible', 'On');
            set(handles.stextTimeMagField, 'String', 'Define constants [ w, f ]');
            set(handles.edtTimeMagField, 'Visible', 'On');
            set(handles.edtTimeMagField, 'String', '[ 1e4; 0 ]');
        case BFIELD_TIMECUSTOM                                      % custom time factor
            set(handles.stextTimeMagField, 'Visible', 'On');
            set(handles.stextTimeMagField, 'String', 'Define factors for each direction [ f(t), g(t), h(t) ]');
            set(handles.edtTimeMagField, 'Visible', 'On');
            set(handles.edtTimeMagField, 'String', '[ sin(1e3*t), cos(3e3*t+1.2), atan(t-pi/3) ]');
    end
end

% --- Executes during object creation, after setting all properties.
function popTimeMagField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popTimeMagField (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 edtTimeMagField_Callback(hObject, eventdata, handles)
% hObject    handle to edtTimeMagField (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 edtTimeMagField as text
%        str2double(get(hObject,'String')) returns contents of edtTimeMagField as a double

end


% --- Executes during object creation, after setting all properties.
function edtTimeMagField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtTimeMagField (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


function edtTimeElecField_Callback(hObject, eventdata, handles)
% hObject    handle to edtTimeElecField (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 edtTimeElecField as text
%        str2double(get(hObject,'String')) returns contents of edtTimeElecField as a double

end


% --- Executes during object creation, after setting all properties.
function edtTimeElecField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtTimeElecField (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 selection change in popTimeElecfield.
function popTimeElecField_Callback(hObject, eventdata, handles)
% hObject    handle to popTimeElecfield (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 popTimeElecfield contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popTimeElecfield
    global_variables;
    
    switch get(handles.popTimeElecField, 'Value')
        case EFIELD_TIMECONSTANT                                    % constant electric field
            set(handles.stextTimeElecField, 'Visible', 'Off');
            set(handles.edtTimeElecField, 'Visible', 'Off');
        case EFIELD_SINUSOIDAL                                      % sinusoidal electric field
            set(handles.stextTimeElecField, 'Visible', 'On');
            set(handles.stextTimeElecField, 'String', 'Define constants [ w, f ]');
            set(handles.edtTimeElecField, 'Visible', 'On');
            set(handles.edtTimeElecField, 'String', '[ 1e4; 0 ]');
        case EFIELD_TIMECUSTOM                                      % custom time factor
            set(handles.stextTimeElecField, 'Visible', 'On');
            set(handles.stextTimeElecField, 'String', 'Define factors for each direction [ f(t), g(t), h(t) ]');
            set(handles.edtTimeElecField, 'Visible', 'On');
            set(handles.edtTimeElecField, 'String', '[ sin(1e3*t), cos(3e3*t+1.2), atan(t-pi/3) ]');
    end

end


% --- Executes during object creation, after setting all properties.
function popTimeElecField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popTimeElecfield (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



% --- Executes on button press in rbuttGravity.
function rbuttGravity_Callback(hObject, eventdata, handles)
% hObject    handle to rbuttGravity (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 rbuttGravity
            
    set(handles.edtInitPos, 'String', '[0; 0; 0]');
    set(handles.edtInitVel, 'String', '[0; 2e1; 0]');
end

⌨️ 快捷键说明

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