function sei = structuralSEInterface(self,varargin)
%structuralSEInterface - Specify interface boundaries for component mode synthesis
%  sei = structuralBoundaryLoad(structuralmodel,'REGIONTYPE',REGIONID)
%  specifies boundary regions as a superelement interface. The
%  degrees-of-freedom on the interface boundaries retained as is in
%  component mode synthesis. REGIONTYPE is 'Face', 'Edge', or 'Vertex' for
%  a 3-D model and 'Edge' or 'Vertex' for a 2-D model. REGIONID is an
%  integer vector specifying the IDs of faces, edges, or vertices.
%
%   Example: Reduce a beam model to superlement, retaining only end faces
%            degrees of freedom
%       
%       structuralmodel = createpde('structural','transient-solid');    
%       structuralmodel.Geometry = multicuboid(0.1,0.01,0.01);
%       structuralProperties(structuralmodel,'YoungsModulus',70E9, ...
%                                      'PoissonsRatio',0.3, ...
%                                      'MassDensity',2700);
%       structuralSEInterface(structuralmodel,'Edge',[4,6,9,10]);
%       structuralSEInterface(structuralmodel,'Edge',[2,8,11,12]);
%       generateMesh(structuralmodel);
%       R = reduce(structuralmodel,'FrequencyRange',[-Inf,500000])
%
%    See also pde.StructuralModel, pde.StructuralModel/structuralProperties

% Copyright 2019 The MathWorks, Inc.

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

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

parser = inputParser;
parser.addParameter('Face', [],@pde.EquationModel.isValidEntityID);
parser.addParameter('Edge', [],@pde.EquationModel.isValidEntityID);
parser.addParameter('Vertex', [],@pde.EquationModel.isValidEntityID);
parser.parse(varargin{:});

if self.IsTwoD && ~isempty(parser.Results.Face)
    error(message('pde:StructuralModel:invalidBCRegionTypeFor2D'))
end

if isempty(self.SuperelementInterfaces)
    SEIcont = pde.StructuralSEIAssignmentRecords(self);
    sei = pde.StructuralSEIAssignment(SEIcont,varargin{:});
    SEIcont.StructuralSEIAssignments = sei;
    self.SuperelementInterfaces = SEIcont;
else
    sei = pde.StructuralSEIAssignment(self.SuperelementInterfaces,varargin{:});
    self.SuperelementInterfaces.StructuralSEIAssignments(end+1) = sei;
end

end