classdef RotTopfkern
    %% Konstanten
    properties (Constant = true, Hidden = true)                
        % Standard-Dicke des inneren axialen Schenkels; [b_ax_i_std] = m
        b_ax_i_std = 3e-3;
        
        % Standardwert des inneren Radius; [r_i_std] = m
        r_i_std = 1e-3;
        
        % Standard-Innenlänge des Topfkerns in axiale Richtung; [l_ax_i_std] = m
        l_ax_i_std = 5e-3;
        
        % Standard-Länge des Wicklungskörpers in radiale Richtung; [l_WK_rad_std] = m
        l_WK_rad_std = 5e-3;
        
        % Standard-Material
        Material_std = 'N96';
        
        % Topfkern-Darstellung
        TK_Fuellung_Farbe = [0.3 0.3 0.3];
        TK_Fuellung_Transp = 1.0;
        
        % Interpreter
        Interpreter = 'tex';
    end
    
    %% Lese-Attribute
    properties (GetAccess = public, SetAccess = protected)
        % Name der Instanz
        Name = '';
    end
    
    %% freie Attribute
    properties (Access = public)
        % innerer Radius des Topfkerns; [r_i] = m
        r_i;
        
        % Dicke des inneren axialen Schenkels; [b_ax_i] = m
        b_ax_i;
        
        % Innenlänge des Topfkerns in axiale Richtung; [l_ax_i] = m
        l_ax_i;
        
        % Höhe des Wicklungskörpers; [h_WK] = m
        l_WK_rad;
        
        % Material
        Material;
    end
    
    %% abhängige Attribute
    properties (Dependent = true)
        % äußerer Radius des inneren axialen Schenkels; [r_i_a] = m
        r_i_a;
        
        % innerer Radius des äußeren axialen Schenkels; [r_a_i] = m
        r_a_i;
        
        % äußerer Radius des Topfkerns; [r_a] = m
        r_a;
        
        % Dicke des äußeren axialen Schenkels; [b_ax_a] = m
        b_ax_a;
        
        % Dicke des radialen Schenkels; [b_rad] = m
        b_rad;
        
        % Länge in axialer Richtung; [l_ax] = m
        l_ax;
        
        % Kreisringfläche der axialen Schenkel; [A_ax] = m^2
        A_ax;
        
        % mittlerer Radius des Magnetflusses im inneren axialen Schenkel; [r_m_i] = m
        r_m_i;
        
        % mittlere magnetische Länge in axiale Richtung; [l_m_ax] = m
        l_m_ax;
    end    

    %% abhängige Attribute (intern)
    properties (Dependent = true, Hidden = false)
        % Topfkern-Koordinaten in axiale Richtung; [TK_KO_ax] = m
        TK_KO_ax;
        
        % Topfkern-Koordinaten in radiale Richtung; [TK_KO_rad] = m
        TK_KO_rad;       
    end
    
    %% Methoden
    methods
        %% Konstruktor
        function obj = RotTopfkern(Name)
            obj.Name = Name;
            obj.r_i = obj.r_i_std;
            obj.b_ax_i = obj.b_ax_i_std;
            obj.l_ax_i = obj.l_ax_i_std;
            obj.l_WK_rad = obj.l_WK_rad_std;
            obj.Material = Ferrit('N96');
        end
        
        %% Set-Methoden
        function obj = set.r_i(obj, r_i)
            if r_i <= 0
                obj.r_i = obj.r_i_std;
            else
                obj.r_i = r_i;
            end
        end
        function obj = set.b_ax_i(obj, b_i)
            if b_i <= 0
                obj.b_ax_i = obj.b_ax_i_std;
            else
                obj.b_ax_i = b_i;
            end
        end
        function obj = set.l_ax_i(obj, l_ax_i)
            if l_ax_i <= 0
                obj.l_ax_i = obj.l_ax_i_std;
            else
                obj.l_ax_i = l_ax_i;
            end
        end
        function obj = set.l_WK_rad(obj, l_WK_rad)
            if l_WK_rad <= 0
                obj.l_WK_rad = obj.l_WK_rad_std;
            else
                obj.l_WK_rad = l_WK_rad;
            end
        end
        
        %% Get-Methoden für Dependent-Attribute
        function r_i_a = get.r_i_a(obj)
            r_i_a = obj.r_i + obj.b_ax_i;
        end
        function r_a_i = get.r_a_i(obj)
            r_a_i = obj.r_i_a + obj.l_WK_rad;
        end
        function r_a = get.r_a(obj)
            r_a = sqrt(obj.r_i_a^2 - obj.r_i^2 + obj.r_a_i^2);
        end
        function b_ax_a = get.b_ax_a(obj)
            b_ax_a = obj.r_a - obj.r_a_i;
        end
        function A_ax = get.A_ax(obj)
            A_ax = pi * (obj.r_i_a^2 - obj.r_i^2);
        end
        function b_rad = get.b_rad(obj)
            b_rad = obj.A_ax / (2 * pi * obj.r_m_i);
        end
        function l_ax = get.l_ax(obj)
            l_ax = obj.l_ax_i + obj.b_rad;
        end
        function r_m_i = get.r_m_i(obj)
            r_m_i = sqrt(0.5 * (obj.r_i_a^2 + obj.r_i^2));
        end
        function l_m_ax = get.l_m_ax(obj)
            l_m_ax = 0.5 * (obj.l_ax_i + obj.l_ax);
        end

        %% Get-Methoden für versteckte Dependent-Attribute
        function TK_KO_ax = get.TK_KO_ax(obj)
            TK_KO_ax = [(0) (obj.l_ax) (obj.l_ax) (obj.l_ax - obj.l_ax_i) (obj.l_ax - obj.l_ax_i) (obj.l_ax) (obj.l_ax) (0)];
        end
        function TK_KO_rad = get.TK_KO_rad(obj)
            TK_KO_rad = [(obj.r_i) (obj.r_i) (obj.r_i_a) (obj.r_i_a) (obj.r_a_i) (obj.r_a_i) (obj.r_a) (obj.r_a)];
        end
        %% Darstellungs-Methoden
        function ZeichneQuerschnittPur(obj, Deltaz, gespiegelt)
            % Topfkern-Polygone definieren           
            if ~gespiegelt
                TK_Polygon_oben = polyshape(obj.TK_KO_ax - Deltaz, obj.TK_KO_rad);
                TK_Polygon_unten = polyshape(obj.TK_KO_ax - Deltaz, -1 * obj.TK_KO_rad);
            else
                TK_Polygon_oben = polyshape(-1 * obj.TK_KO_ax - Deltaz, obj.TK_KO_rad);
                TK_Polygon_unten = polyshape(-1 * obj.TK_KO_ax - Deltaz, -1 * obj.TK_KO_rad);
            end
            
            % Figure and Subplot definieren
            fig = figure(1);
            fig_sp = subplot(1, 1, 1);
            hold(fig_sp, 'on');
            fig_sp.DataAspectRatioMode = 'manual';
            fig_sp.DataAspectRatio = [1 1 1];
            
            % Topfkern zeichnen
            plot(fig_sp, TK_Polygon_oben, 'FaceColor', obj.TK_Fuellung_Farbe, 'FaceAlpha', obj.TK_Fuellung_Transp);
            plot(fig_sp, TK_Polygon_unten, 'FaceColor', obj.TK_Fuellung_Farbe, 'FaceAlpha', obj.TK_Fuellung_Transp);
        end
        function ZeichneQuerschnitt(obj, gespiegelt)
            % Topfkern-Polygone definieren            
            if ~gespiegelt
                TK_Polygon_oben = polyshape(obj.TK_KO_ax, obj.TK_KO_rad);
                TK_Polygon_unten = polyshape(obj.TK_KO_ax, -1 * obj.TK_KO_rad);
            else
                TK_Polygon_oben = polyshape(-1 * obj.TK_KO_ax, obj.TK_KO_rad);
                TK_Polygon_unten = polyshape(-1 * obj.TK_KO_ax, -1 * obj.TK_KO_rad);
            end
            
            % Figure and Subplot definieren
            fig = figure(1);
            fig.Name = 'ClassDef RotTopfkern.m: ZeichneQuerschnitt';
            fig_sp = subplot(1, 1, 1);
            hold(fig_sp, 'on');
            fig_sp.DataAspectRatioMode = 'manual';
            fig_sp.DataAspectRatio = [1 1 1];
            
            fig_sp.Title.String = 'Topfkern';
            fig_sp.Title.Interpreter = obj.Interpreter;
            %fig_sp.Title.Position = [(0.5 * obj.l_ax) (1.2 * fig_sp.YLim(1,2)) 0];
            fig_sp.Title.HorizontalAlignment = 'Center';
            fig_sp.Title.VerticalAlignment = 'Bottom';

            fig_sp.XAxisLocation = 'origin';
            fig_sp.XLabel.String = 'Rotationsachse';
            fig_sp.XLabel.Interpreter = obj.Interpreter;
            if ~gespiegelt
                fig_sp.XLabel.Position = [(1.1 * obj.l_ax) 0 0];
                fig_sp.XLabel.HorizontalAlignment = 'Left';
            else
                fig_sp.XLabel.Position = [(-1.1 * obj.l_ax) 0 0];
                fig_sp.XLabel.HorizontalAlignment = 'Right';
            end            
            fig_sp.XLabel.VerticalAlignment = 'Middle';
            
            if ~gespiegelt
                fig_sp.YAxisLocation = 'Left';
            else
                fig_sp.YAxisLocation = 'Right';
            end
            fig_sp.YLabel.String = 'Angaben in m';
            fig_sp.YLabel.Interpreter = obj.Interpreter;
            
            % Topfkern zeichnen
            plot(fig_sp, TK_Polygon_oben, 'FaceColor', obj.TK_Fuellung_Farbe, 'FaceAlpha', obj.TK_Fuellung_Transp);
            plot(fig_sp, TK_Polygon_unten, 'FaceColor', obj.TK_Fuellung_Farbe, 'FaceAlpha', obj.TK_Fuellung_Transp);            
        end
    end
end