function dm = structuralDamping(self,varargin)
%structuralDamping - Specify damping parameters to a structural model
% dm = structuralDamping(structuralmodel,'Name',Value) applies damping
% parameters to the model.
%
% The name-value pairs for various types of damping parameters are:
% -------------------------------------------------------------------------
%  Name			      	       Description
% -------------------------------------------------------------------------
% 'Alpha'         Mass proportional Rayleigh damping parameter. 
%
% 'Beta'          Stiffness proportional Rayleigh damping parameter. 
%
% 'Zeta'          Modal damping ratio. Use in modal transient or modal
%                 frequency response solution.
%
%  Example: Specify Proportional Damping for a Beam
% 
%   structuralmodel = createpde('structural','transient-solid');
%   gm = importGeometry(structuralmodel,'SquareBeam.stl');
%   structuralProperties(structuralmodel,'YoungsModulus',210E9,'PoissonsRatio',0.3,'MassDensity',7800);
%   structuralDamping(structuralmodel,'proportional','Alpha',10,'Beta',2);
% 
% See also pde.StructuralModel, pde.StructuralModel/structuralProperties
%         pde.StructuralModel/structuralBoundaryLoad,  
%         pde.StructuralModel/structuralBodyLoad,
%         pde.StructuralModel/structuralBC, pde.StructuralModel/solve

% Copyright 2017-2021 The MathWorks, Inc.


narginchk(3,6);
nargoutchk(0,1);

if isempty(self.Geometry)
    error(message('pde:StructuralModel:structuralModelHasNoGeom'));
end

if ~contains(self.AnalysisType,["frequency","transient"]) 
    error(message('pde:StructuralModel:noDampingOnNoNDynamicModel'));
end
 
dampingModel = [];
argsToParse = varargin;
if (mod(nargin,2) == 0) && self.isValidDampingModel(varargin{1})
    dampingModel = varargin{1};
    argsToParse = varargin(2:end);
end

parser = inputParser;
parser.addParameter('Alpha', [],@pde.EquationModel.isValidAttributeVal);
parser.addParameter('Beta', [],@pde.EquationModel.isValidAttributeVal);
parser.addParameter('Zeta', [],@pde.EquationModel.isValidAttributeVal);

parser.parse(argsToParse{:});

if self.IsTwoD
    argsToPass = [argsToParse, {'Face',  1:self.Geometry.NumFaces},{'DampingModel',dampingModel}];
else
    argsToPass = [argsToParse, {'Cell',  1:self.Geometry.NumCells},{'DampingModel',dampingModel}];
end

if isempty(self.DampingModels)
    dmContainer = pde.StructuralDampingAssignmentRecords(self);
    dm = pde.StructuralDampingAssignment(dmContainer,argsToPass{:});
    dmContainer.StructuralDampingAssignments = dm;
    self.DampingModels = dmContainer;
else
    dm = pde.StructuralDampingAssignment(self.DampingModels,argsToPass{:});
    self.DampingModels.StructuralDampingAssignments(end+1) = dm;
end

end
