Mr-Hernandez / Conformal-FDTD

MATLAB implementation of Conformal FDTD inside a PEC box boundary with a PEC object centered inside
1 stars 0 forks source link

Area and Length finding algorithms only work on one side #1

Open Mr-Hernandez opened 3 years ago

Mr-Hernandez commented 3 years ago

Measuring the lengths and areas starts with measuring the bottomright corner of the grid. Because of this some assumption were made that this corner would be outside the PEC. This causes issues once we get tot he right half of the circle, past x_c.

I think it might be possible to use symmetry to solve for the second half by solving the first half first and then just mirroring the results along the mid point. This should work because NX, NY, and NZ are know, so we know the number of grid squares. This has only been considered for odd numbers of NX,NY,NZ and might not work or need modification for even values.

Mr-Hernandez commented 3 years ago

Quick Fix Idea: Rather than rewrite the detection of position on edge or inside PEC, we could take the output for epx_mask (permitivitty) and muz_mask (permeability) and simply overwrite the second half of the structures. For epx_mask we would have NX-1 x NY elements. For muz_mask we would have NX-1, NY-1 elements.

Note: muz_mask definitely needs this fix but epx_mask might not need it but could be implemented anyways so both methods remain consistent. Also, the lengths and FA and so on may be incorrect. Likely that this method will need updating if considering other orientations of the cylinder.

Mr-Hernandez commented 3 years ago

Update: Looking at the results of epx_mask at with NX,NY,NZ = 12 revealed a single erroneous output. This occurred in 'Cylinder2' because of a special case where the circle edge detection indicated conforming was neccessary but there were no crosspoints between the circle edge and lower or upper side of the grid square. Two possibilities then arise. Either the lower side of the grid square is completely inside the PEC or completely outside the PEC.

This special case had been noticed before but was solved incorrectly. Below we see the old method in comments just above the new method.

%             if(cross(1, counter) == -1 && abs(y_c - (j-1)*dy) < radius)...
%                     && abs(x_c - (i-1)*dx) < radius
%                 cross(1, counter) = 0;
%             end

                if(cross(1, counter) == -1 && sqrt((x_c - (i-1)*dx)^2 ...
                  + (y_c - (j-1)*dy)^2) < radius)
                  cross(1, counter) = 0;
               end`

The new method is just a measurement of the distance between the the lower right node of the grid square (since at this point the lower length is guaranteed to be completly inside or outside, then we can use any point on this length), and the distance to the center of the circle. If it is less then the radius, then it is completely inside the PEC (circle) and is sets the cross() value to 0 which indicates later to set that length to 0 rather than to dx, which would be the case if the lower side were completely outside the PEC.

Resolving this issue fixed the issues with the muz_mask output as well. This is using the mirroring method mentioned above and there may still be errors in the lengths and areas found in the second half of the iterations.

Some more testing will be done to see if the issue is solved at multiple NXYZ values (even values that is).