anstmichaels / emopt

A suite of tools for optimizing the shape and topology of electromagnetic structures.
BSD 3-Clause "New" or "Revised" License
100 stars 41 forks source link

Issues in StructuredMaterial2D::get_value #16

Closed dasu186 closed 4 years ago

dasu186 commented 4 years ago

First of all, great work! Saw your talk at PW2020.

After importing a few layouts and seeing strange results, I became curious about the way the averaging is done when trying to get an average epsilon value. I think I understand the function correctly, but I also don't think it's doing what it's meant to be doing.

First of all, cell.get_area_ratio() will always either return 1, or 0, because it's defined from a rectangular grid.

if(cell.get_area_ratio() == 0) { break; } shouldn't be in the loop, but really should be a condition to go in the loop. It's not going to change between primitives. Of course that's very minor.

if(contains_p1 && contains_p2 &&
           contains_p3 && contains_p4 &&
           cell.get_area_ratio() == 1.0) {
                return prim->get_material(xd,yd);
        }

doesn't work if it's from a subsequent layer. Say you define a structure on top of a cladding. The first structure will give an overlap of say < 1 and correctly increments val and keeps on lopping, but on the second pass it will be overwritten by that return from the cladding. In the end, all the polygons must be kept so that a difference can be computed between them.

if(cell.get_area_ratio() > 0) { val += cell.get_area_ratio()*1.0; } will always increment val by 1 if gets through the condition. But is it really what it should do? It should really be the overlap that is "left" that contributes to val.

My final thought is that there should be a more efficient way for get_values than going grid point by grid point if you already have all the polygons in hand.

dasu186 commented 4 years ago

Nevermind. It wasn't obvious at first that cell shrinks at each iteration and remains the difference. I hadn't looked enough at the GridCell class.