classdef (Sealed) StructuralDampingAssignmentRecords < handle
%StructuralDampingAssignmentRecords - Assignments of structural damping models
% StructuralDampingAssignmentRecords holds a record of all the assignments
% of damping models for the structural model. Proportional damping
% assignment is applicable to entire domain. This object cannot be created
% directly; it can only be created by the StructuralModel class.
%
% StructuralDampingAssignmentRecords methods:
%    findStructuralDamping - Find structural damping assigned to a structural model
%
% StructuralDampingAssignmentRecords properties:
%    StructuralDampingAssignments - Vector of damping model assignments
%
% See also pde.StructuralModel, pde.StructuralModel/structuralDamping

% Copyright 2017-2019 The MathWorks, Inc.
    
    properties
        % StructuralDampingAssignments - Vector of damping model assignments
        % A vector containing the damping model assignments for the model.
        % Each entry in the vector is a pde.StructuralDampingAssignment
        % object. Structural damping model and its values are defined using
        % the structuralDamping method of the StructuralModel object.
        StructuralDampingAssignments
    end
    
    methods
        dm = findStructuralDamping(self, varargin)
    end
    
    methods(Hidden=true, Access={?pde.EquationModel, ?pde.StructuralResults})
        function self = StructuralDampingAssignmentRecords(spdem)
            self.StructuralDampingAssignments = [];
            self.ParentModel = spdem;
        end
        
        function performSolverPrechecks(self)
            ca = self.findStructuralDamping;
            ca.performSolverPrecheck();
        end
        
        function dampingStruct = packDampingModel(self,varargin)
            dampingStruct.alpha = 0;
            dampingStruct.beta = 0;
            dampingStruct.zeta =0;
            dampingStruct.dampingModel = "proportional";
            if ~isempty(self.StructuralDampingAssignments)
                dampingStruct.alpha = self.StructuralDampingAssignments(end).Alpha;
                dampingStruct.beta = self.StructuralDampingAssignments(end).Beta;
                dampingStruct.zeta = self.StructuralDampingAssignments(end).Zeta;
                dampingStruct.dampingModel = self.StructuralDampingAssignments(end).DampingModel;
            end
        end
    end
    
    
    methods(Hidden=true, Access={?pde.StructuralDampingAssignment})
        function delistStructuralDampingAssignments(self, dmtodelete)
            numhs = numel(self.StructuralDampingAssignments);
            for i = 1:numhs
                thishs = self.StructuralDampingAssignments(i);
                if thishs == dmtodelete
                    self.StructuralDampingAssignments(i) = [];
                    break
                end
            end
            numhs = numel(self.StructuralDampingAssignments);
            if numhs == 0 && isvalid(self.ParentModel)
                self.ParentModel.delistDampingAssignment();
            end
        end
        
    end
    
    
    methods( Hidden=true)
        function delete(self)
            numhs = numel(self.StructuralDampingAssignments);
            for i = 1:numhs
                if isvalid(self.StructuralDampingAssignments(i))
                    delete(self.StructuralDampingAssignments(i));
                end
            end
            
            if isvalid(self.ParentModel)
                self.ParentModel.delistDampingAssignment();
            end
        end
    end
    
    
    properties (Hidden = true, SetAccess='private')
        ParentModel;
    end
    
end