Open mawc2019 opened 1 year ago
I'm assuming you're talking about code that was written before the +1 material grid fix, and you want to run the "same simulation" but now with the fix applied?
No, I am not talking about the meep code without +1
before fix. I am considering the situation in which the results from different solvers are compared (e.g., in some testbed problems), or results from one solver serve as the initial guess for another solver.
Different solvers may have different material-grid types, i.e., the vertex type and the center type. Even if these two types of material grids are defined in the same regions with the same resolution, the numbers of grid variables and their values will be different.
For example, the following material grid is vertex-type, and the size of the variable array is 5×4. However, if a center-type material grid with the same resolution superimposes the same region, the size of the variable array will be 4×3. The conversion between the two variable arrays may be needed if we want to load one of them into the other's material grid.
Maybe we can also have something more general: upsample/downsample the material grid from any size to any size?
Maybe we can also have something more general: upsample/downsample the material grid from any size to any size?
As Alec mentioned today, the vertex-to-center conversion can be done by scipy.interpolate.griddata, which seems also applicable to upsampling or downsampling if only vertex-type material grid is involved; but the center-to-vertex conversion needs extrapolation for the outermost vertices, which cannot be done by this function.
In meep, each variable of a material grid is defined on a vertex of a voxel. In contrast, in some other solvers, each variable of a material grid is defined on the center of a voxel (or represents each entire voxel). Consequently, even if the two types of material grids are defined in the same regions with the same resolution, the numbers of variables and their values will be different. The conversion between variables may be needed when we compare results from such two types of material grid. For example, to obtain the variables of a center-type grid from the variables of a vertex-type grid, one can compute each variable in the center-type grid as the average of the variables on the four (in 2d) or eight (in 3d) vertices of that voxel. Let $\rho{\rm cen}$ and $\rho{\rm ver}$ denote the variable vectors of center-type and vertex-type grids, respectively. The conversion can be expressed as $A\rho{\rm ver}=\rho{\rm cen}$, where $A$ denotes a matrix that encapsulates the average operation among neighboring vertices. Conversely, to obtain the variables of a vertex-type grid from the variables of a center-type grid, one can perform $\rho{\rm ver}=A^{+}\rho{\rm cen}$, where $A^{+}$ is the pseudo-inverse of $A$. Shall we add these functions in meep? Perhaps unfilter_design.py is a suitable place to put these functions, but if we do so, the name of this python file needs to be changed.