########################################################################## # Scriptfile: rectGridFromGeom.lsf # # Description: # Extract the rectangular grid from the geometry # # Inputs: # geometryName: The name of the geometry (rectangle) to interpolate # mindelta, maxdelta: max and min spacing (the average will be used if possible # # Outputs: # xgrid, ygrid: the 2D rectilinear grid (m) # # Copyright 2012, Lumerical Solutions, Inc. ########################################################################### mincount = 10; maxcount = 100; small = 1e-12; # m simOrientation = getnamed("CHARGE simulation region","dimension"); if (simOrientation == '2D Z-Normal') { dim1 = "x"; dim2 = "y"; } else { if (simOrientation == '2D Y-Normal') { dim1 = "x"; dim2 = "z"; } else { if (simOrientation == '2D X-Normal') { dim1 = "y"; dim2 = "z"; } } } # determine bounding corners zmin = getnamed(geometryName,dim2+" min"); zmax = getnamed(geometryName,dim2+" max"); xmin = getnamed(geometryName,dim1+" min"); xmax = getnamed(geometryName,dim1+" max"); zmin = max([getnamed("CHARGE simulation region",dim2+" min"),zmin]) + small; zmax = min([getnamed("CHARGE simulation region",dim2+" max"),zmax]) - small; xmin = max([getnamed("CHARGE simulation region",dim1+" min"),xmin]) + small; xmax = min([getnamed("CHARGE simulation region",dim1+" max"),xmax]) - small; # determine span of rectangle selectMin = [xmin, zmin]; # m units selectMax = [xmax, zmax]; spanSelect = selectMax - selectMin; # # make a rectilinear grid for the waveguide # avgdelta = sqrt(mindelta*maxdelta); nxspan = floor(spanSelect(1)/avgdelta); rectRatio = spanSelect(1)/spanSelect(2); if (rectRatio > 1) { nyspan = floor(nxspan/rectRatio) + 1; } else { nyspan = nxspan; nxspan = floor(rectRatio*nyspan) + 1; } if (nxspan < mincount) { nxspan = mincount; } else { if (nxspan > maxcount) { nxspan = maxcount; } } delta = floor(spanSelect(1)/(nxspan - 1)); if (delta > maxdelta) { message("Grid spacing exceeded limits"); break; } if (nyspan < mincount) { nyspan = mincount; } else { if (nyspan > maxcount) { nyspan = maxcount; } } delta = floor(spanSelect(2)/(nyspan - 1)); if (delta > maxdelta) { message("Grid spacing exceeded limits"); break; } # # make a rectilinear grid # xgrid = linspace(selectMin(1),selectMax(1),nxspan); ygrid = linspace(selectMin(2),selectMax(2),nyspan);