classdef edgeBC < pde.internal.FEDisplay
% edgeBC Create an edgeBC object
%
% edgeBC is used to set a boundary condition on an edge.
%
% edgeBC properties:
%
% Constraint - Standard structural boundary constraints, specified as 
%       'fixed'.
% XDisplacement - x-component of enforced displacement, specified as a 
%       number or function handle. 
% YDisplacement - y-component of enforced displacement, specified as a 
%       number or function handle.
% ZDisplacement - z-component of enforced displacement, specified as a 
%       number or function handle. 
% Temperature - Temperature boundary condition, specified as a number or a 
%       function handle.
% Voltage - Voltage boundary condition, specified as a scalar to specify 
%       constant voltage or a function handle to specify spatially varying
%       voltage.
% ElectricField - Electric field boundary condition, specified as a vector of 
%       size equal to dimension of the geometry or a function handle to specify
%       spatially varying electric field.
% MagneticField - Magnetic field boundary condition, specified as a vector 
%       of size equal to dimension of the geometry or a function handle to 
%       specify spatially varying magnetic field.
% MagneticPotential - Magnetic potential boundary condition, specified as a 
%       a real number, a column vector of three elements for a 3-D  model,
%       or a function handle to specify spatially varying magnetic potential.       
% FarField - Far field boundary condition used in electricHarmonic and
%       magneticHarmonic analysis types, specified as a farFieldBC object.


% Copyright 2022 The MathWorks, Inc.

    properties
        Constraint (1,:) string {mustBeMember(Constraint,"fixed"),mustBeScalarOrEmpty}
        XDisplacement (1,:) {pde.internal.validators.mustBeDoubleOrFunctionHandle}
        YDisplacement (1,:) {pde.internal.validators.mustBeDoubleOrFunctionHandle}
        ZDisplacement (1,:) {pde.internal.validators.mustBeDoubleOrFunctionHandle}
        Temperature (1,:) {pde.internal.validators.mustBeDoubleOrFunctionHandle}
        Voltage (1,:) {pde.internal.validators.mustBeDoubleOrFunctionHandle}
        MagneticPotential (1,:) {pde.internal.validators.mustBeDoubleVectorOrFunctionHandle}
        ElectricField (1,:) {pde.internal.validators.mustBeDoubleVectorOrFunctionHandleOrComplex}
        MagneticField (1,:) {pde.internal.validators.mustBeDoubleVectorOrFunctionHandleOrComplex}
        FarField {pde.internal.validators.mustBeFarField}
    end

    methods
        function obj = edgeBC(options)
            arguments
                options.?edgeBC
            end

            for k=fields(options)'
                obj.(k{:}) = options.(k{:});
            end
        end
    end

    methods(Hidden)
        function obj = reparent(obj,parent)
            % Update display to reflect parent's new AnalysisType.
            % "structuralStatic" | "structuralModal" | "structuralTransient"
            % | "structuralFrequency" | "thermalTransient" | "thermalSteady"
            % | "electrostatic" | "magnetostatic" | "electricHarmonic" |
            % "magneticHarmonic" | "dcConduction"

            disps = ["XDisplacement","YDisplacement","ZDisplacement"];
            if ~isempty(obj) && parent.IsTwoD
                zNonEmpty = ~cellfun(@isempty, {obj.ZDisplacement});
                if any(zNonEmpty)
                    error(message('pde:femodel:NoZDisplacement2D'));
                end
                disps = ["XDisplacement","YDisplacement"];
            end

            c = { ...
                "structuralStatic", ["Constraint",disps]; ...
                "structuralModal",  ["Constraint",disps];...
                "structuralTransient", ["Constraint",disps]; ...
                "structuralFrequency", ["Constraint",disps];
                "thermalTransient", "Temperature"; ...
                "thermalSteady", "Temperature"; ...
                "electrostatic", "Voltage"; ...
                "magnetostatic", "MagneticPotential"; ...
                "electricHarmonic", ["ElectricField","FarField"]; ...
                "magneticHarmonic", ["MagneticField","FarField"]; ...
                "dcConduction","Voltage"; ...
                };
            d = dictionary(string(c(:,1)), c(:,2));
            props = "";
            if isKey(d,parent.AnalysisType)
                props = d(parent.AnalysisType);
                props = props{:};
            end

            for k=1:numel(obj)
                obj(k).DisplayAnalysisType = parent.AnalysisType;
                obj(k).DisplayPropertyList = props;
            end
        end
    end

end
