function self = setIntegrationRule(self)
%setIntegrationRule - Setup integration rules for the boundary element facet 
% The setting up of integration rule for integrating distributed BCs is a
% one-time operation per solution call, as element facets are not allowed
% to change during solution.
%
% This undocumented function may be changed or removed in a future release.

%       Copyright 2020 The MathWorks, Inc.

if isempty(self.faceBoundaryConditions)
    return
end

numFaceNodes = [];
for i = 1:length(self.faceBoundaryConditions)
    bcsi = self.faceBoundaryConditions(i);
    if ~isempty(bcsi.elemFaces)
        numFaceNodes = size(bcsi.elemFaces,1);
        break
    end
end

if isempty(numFaceNodes)
    return
end

import pde.internal.elements.*;
          
if self.dim == 2
    if(numFaceNodes == 3)
        self.sfCalc = @shapeLine3;
        self.dsfCalc = @dShapeLine3;
        self.numIntPoints = 3;
        self.rs = [-1,0,1]; % natural coordinates at the 3 nodes
        self.numNormalsPerFacet = 3;
    elseif (numFaceNodes == 2)
        self.sfCalc = @shapeLine2;
        self.dsfCalc = @dShapeLine2;
        self.numIntPoints = 2;
        self.rs = [-1,1]; % natural coordinates at the 2 nodes
        self.numNormalsPerFacet = 2;
    else
        error(message('pde:pde2DBCImpl:illegalEdgeDefn', numEdgeNodes));
    end
    self.intRule=GaussianIntegrationRule(GaussianIntegrationRule.Curve, self.numIntPoints);
else
    if(numFaceNodes == 3)
        self.sfCalc = @shapeTri3;
        self.dsfCalc = @dShapeTri3;
        self.numIntPoints = 1;
        self.rs = [0 1 0; 0 0 1]; % natural coordinates at the 3 nodes
        self.numNormalsPerFacet = 1;
    elseif(numFaceNodes == 6)
        self.sfCalc = @shapeTri6;
        self.dsfCalc = @dShapeTri6;
        self.numIntPoints = 3;
        self.rs = [0 1 0 .5 .5 0; 0 0 1 0 .5 .5]; % natural coordinates at the 6 nodes
        self.numNormalsPerFacet = 6;
    else
        error(message('pde:pde3DBCImpl:illegalFaceDefn', numFaceNodes));
    end
    self.intRule=GaussianIntegrationRule(GaussianIntegrationRule.Triangle, self.numIntPoints);    
end
    

end

