distribute.m

来自「利用电磁场的源激发方法来计算光子晶体波导例如光子晶体光纤」· M 代码 · 共 65 行

M
65
字号
function positions = distribute(oGd)
% positions = DISTRIBUTE(oGd)
% Distributes sources and testing points as dictated by oGd.

alphaIn = 1- oGd.alphaIn;
alphaOut = 1+oGd.alphaOut;
sdArray = oGd.sdArray;
nSd = length(sdArray);
nSources = oGd.nSources;
nTest = oGd.nTestingPoints;
curveArray = oGd.curveArray;
lengths = [curveArray.length];
sumLengths = sum(lengths);

% create matching-points and source vectors
vNSources = round(nSources*lengths/sumLengths);
vNTest = round(nTest*lengths/sumLengths);
vCx = [curveArray.xc];
vCy = [curveArray.yc];

% create matching-points and normals
for iCurve = 1:nSd-1
        [vX, vY, vNx, vNy] = shape(vCx(iCurve), vCy(iCurve), 1, vNTest(iCurve), curveArray(iCurve));
        testingPos(iCurve).vX = vX;
        testingPos(iCurve).vY = vY;
        testingPos(iCurve).vNx = vNx;
        testingPos(iCurve).vNy = vNy;
        testingPos(iCurve).n = vNTest(iCurve);
        testingPos(iCurve).iCurve = iCurve;
end

% create sources
[sourcesPos(1:nSd).vX] = deal([]);
[sourcesPos(1:nSd).vY] = deal([]);
for iSd = 1:nSd
        sourcesPos(iSd).n = 0;
        sourcesPos(iSd).vGreen = 1;
        % sources outside the 'inside' curve
        curve = sdArray(iSd).insideCurve;
        if ~isempty(curve)
                iCurve = curve.iCurve;
                nSources = round(vNSources(iCurve));
                [vX, vY] = shape(vCx(iCurve), vCy(iCurve), alphaOut, nSources, curveArray(iCurve));
                sourcesPos(iSd).vX = vX;
                sourcesPos(iSd).vY = vY;
                sourcesPos(iSd).n = nSources;
                sourcesPos(iSd).iSd = iSd;
        end
        % sources inside the 'outside' curves
        for iOutsideCurve = 1:length(sdArray(iSd).outsideCurveArray)
                curve = sdArray(iSd).outsideCurveArray(iOutsideCurve);
                if ~isempty(curve)
                        iCurve = curve.iCurve;
                        nSources = round(vNSources(iCurve));
                        [vX, vY] = shape(vCx(iCurve), vCy(iCurve), alphaIn, nSources, curveArray(iCurve));
                        sourcesPos(iSd).vX = [sourcesPos(iSd).vX vX];
                        sourcesPos(iSd).vY = [sourcesPos(iSd).vY vY];
                        sourcesPos(iSd).n = sourcesPos(iSd).n + nSources;
                        sourcesPos(iSd).iSd = iSd;
                end
        end
end
positions.testing = testingPos;
positions.sources = sourcesPos;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?