15
This is a repository copy of Structured Mesh Generation : Open-source automatic nonuniform mesh generation for FDTD simulation. White Rose Research Online URL for this paper: http://eprints.whiterose.ac.uk/100155/ Version: Accepted Version Article: Berens, Michael, Flintoft, Ian David orcid.org/0000-0003-3153-8447 and Dawson, John Frederick orcid.org/0000-0003-4537-9977 (2016) Structured Mesh Generation : Open-source automatic nonuniform mesh generation for FDTD simulation. IEEE Antennas and Propagation Magazine. pp. 45-55. ISSN 1045-9243 https://doi.org/10.1109/MAP.2016.2541606 [email protected] https://eprints.whiterose.ac.uk/ Reuse Unless indicated otherwise, fulltext items are protected by copyright with all rights reserved. The copyright exception in section 29 of the Copyright, Designs and Patents Act 1988 allows the making of a single copy solely for the purpose of non-commercial research or private study within the limits of fair dealing. The publisher or other rights-holder may allow further reproduction and re-use of this version - refer to the White Rose Research Online record for this item. Where records identify the publisher as the copyright holder, users can verify any specific terms of use on the publisher’s website. Takedown If you consider content in White Rose Research Online to be in breach of UK law, please notify us by emailing [email protected] including the URL of the record and the reason for the withdrawal request.

Structured Mesh Generation : Open-source automatic ...eprints.whiterose.ac.uk/100155/1/JournalAPM_postprint.pdf · This is a repository copy of Structured Mesh Generation : Open-source

  • Upload
    ngothu

  • View
    258

  • Download
    1

Embed Size (px)

Citation preview

This is a repository copy of Structured Mesh Generation : Open-source automatic nonuniform mesh generation for FDTD simulation.

White Rose Research Online URL for this paper:http://eprints.whiterose.ac.uk/100155/

Version: Accepted Version

Article:

Berens, Michael, Flintoft, Ian David orcid.org/0000-0003-3153-8447 and Dawson, John Frederick orcid.org/0000-0003-4537-9977 (2016) Structured Mesh Generation : Open-source automatic nonuniform mesh generation for FDTD simulation. IEEE Antennas and Propagation Magazine. pp. 45-55. ISSN 1045-9243

https://doi.org/10.1109/MAP.2016.2541606

[email protected]://eprints.whiterose.ac.uk/

Reuse

Unless indicated otherwise, fulltext items are protected by copyright with all rights reserved. The copyright exception in section 29 of the Copyright, Designs and Patents Act 1988 allows the making of a single copy solely for the purpose of non-commercial research or private study within the limits of fair dealing. The publisher or other rights-holder may allow further reproduction and re-use of this version - refer to the White Rose Research Online record for this item. Where records identify the publisher as the copyright holder, users can verify any specific terms of use on the publisher’s website.

Takedown

If you consider content in White Rose Research Online to be in breach of UK law, please notify us by emailing [email protected] including the URL of the record and the reason for the withdrawal request.

1

Open Source Automatic Non-uniform MeshGeneration for FDTD Simulation

Michael K. Berens, Ian D. Flintoft, Senior Member, IEEE, and

John F. Dawson, Member, IEEE,

Abstract—This article describes a cuboid structured mesh generator suitable for 3D numerical modelling using

techniques such as finite-difference time-domain (FDTD) and transmission-line matrix (TLM). The mesh generator takes

as its input an unstructured triangular surface mesh such as is available from many CAD systems, determines a suitable

variable mesh discretisation and generates solid and surface meshes in a format suitable for import by the numerical

solver. The mesher is implemented in the MATLAB language and is available as open source software.

Index Terms—mesh generation, ray-casting, finite-difference time-domain, transmission-line matrix

F

1 INTRODUCTION

The finite-difference time-domain (FDTD)method is a numerical technique that is widelyused to solve Maxwell’s differential equa-tions in the time domain [1]. Both space andtime are discretised. Space is discretised intorectangular-shaped elements in 2D or cuboidelements in 3D. Cuboid elements, where theelectric fields are located on the edges of thecuboid and the magnetic fields normal to thefaces, are called Yee-cells and are the funda-mental elements of most FDTD methods [2].By filling up the problem space with thesecells, we obtain a 3D mesh, where neighbouringcells share edges and faces. Each cell has threeassociated electric and magnetic field compo-nents, while the other field components be-long to adjacent cells. The properties of eachcell are adjusted to represent materials suchas dielectrics or conductors by adjusting theconstitutive parameters used in the field equa-tions in the corresponding cells, hence forming

• J. F. Dawson, and I. D. Flintoft are with the Department ofElectronics, University of York, York YO10 5DD, U.K. ([email protected], [email protected]).

• M. Berens is with the Institut fur Grundlagen der Elektrotech-nik und Meßtechnik, University of Hanover, Hanover D-30060,Germany.

the geometrical structure of the problem to besolved. For example, Figure 1 shows a sphereand a version of the sphere discretised usingcubic elements.

Algorithms for automatic structured meshgeneration have been developed since the ca-pabilities of the FDTD method and computerhardware reached the point at which relativelycomplex geometries could be simulated. A se-lection of the techniques proposed are reportedin [3], [4], [5], [6], [7], [8], [9], [10], [11]. Theprocess of generating a cuboid structured meshfrom an arbitrary model geometry consists oftwo main steps. The first is to determine anefficient placement of the structured mesh lines,constrained by the numerical requirements ofthe FDTD method, to “best fit” the model ge-ometry and the second is the identification ofwhich structured mesh cell belongs to whichobject, a process called material mapping.

With regard to the mesh line placement aninteresting local approach was made in [12],where the non-uniform mesh of overlappingobjects is considered as a constrained opti-mization problem. By optimizing an objectivefunction, which expresses all the constraints,such as the maximum and minimum cell sizes,neighbouring cell size ratio and the influenceof neighbouring intervals, an acceptable mesh

Author postprint, Accepted, Jan 2016, for publication in IEEE Antennas and propagation magazine

© 2016 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media,

including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to

servers or lists, or reuse of any copyrighted component of this work in other works.

IEEE ANTENNA AND PROPAGATION MAGAZINE 2

solution for many problems is found. Anotherlocal approach was proposed in [13], wherethe numerical error, caused by a rapid changeof mesh size, is reduced by considering onlythe two cells on either side of a transitionpoint between two intervals. There are alsoglobal approaches with a focus on all the in-tervals of a mesh [14]. Less constrained Carte-sian mesh generation algorithms have also beendeveloped, e.g. for the Conformal FDTD al-gorithm [15], [16], [17] and for the hybridFDTD/FETD algorithm [18]. Another indepen-dent category of non-uniform mesh generationis adaptive mesh refinement (AMR) [19], [20],[21]. This method is used to refine the mesh inregions of interest after (or during) a simulationwithout creating a completely new mesh.

A number of different ray tracing methodshave been reported for the material mappingstage. A good method should be fast, memoryconserving and capable of handling differentkinds of special cases, e.g. intersections in avery narrow angle or exactly in the objectplane, edge or node. These special cases cancause “singularities” and make the ray castingmore difficult to implement. These issues areexplained in more detail in [22] and [23]. Veryefficient ray casting approachs are describedin [24] and [25].

Although there are many freely availablecomputer-aided design (CAD) or meshing pro-grams that can directly create an unstructuredpolygonal mesh there are no freely availablemeshers that create structured cuboid mesheswith sufficient generality for practical EM sim-ulations of complex structures. Therefore wehave developed a MATLAB [27] code for uni-form and non-uniform structured mesh gener-ation and published it as open source software.The code also works in GNU Octave [28]. Theoutput data format has been kept quite genericso it can be easily adapted to create structuredoutput meshes for a wide range of numericalsolvers. While the mesher is mostly based onthe known algorithms briefly reviewed above,we hope the open-source nature of the codewill make it useful to research and teachinginstitutions that write and use their own nu-merical solvers. Moreover, the code can be used

Fig. 1. Unstructured triangular mesh (top) and structured cubicmesh (bottom) of a sphere.

as a tool to aid the understanding of meshgeneration, and for experimentation with meshgeneration techniques.

The geometry of structures to be modelledusing an FDTD solver must be defined bysome means which allows the production ofa suitable cuboid mesh. Here we assume thedescription is principally in the form of anunstructured triangulated mesh describing thesurface of each object, such as that shown in thetop part of Figure 1 for a sphere, since such arepresentation can be generated by most CADsoftware packages.

2 STRUCTURED MESH GENERATION

FOR FDTD SOLVERS

In this section we consider the factors that affectthe placement of the mesh lines. Since the meshcell size determines both the time step durationand upper frequency limit, it is one of the mostimportant factors limiting the FDTD simula-tion. In addition, the cell size has to be chosen

IEEE ANTENNA AND PROPAGATION MAGAZINE 3

in such a way that the geometrical structure canbe represented appropriately and the numericalerror is acceptably small. However the smallerthe cell size the larger the memory consumedand the longer the run-time for a given prob-lem. Therefore a mesher should produce meshlines with the largest spacing that satisfies theabove constraints.

2.1 Numerical errors due to cell size andcell size variation

Numerical errors are inherent undesired ef-fects within the classical Yee-cell based FDTD-methods that originate from numerical disper-sion and anisotropy. In other words they orig-inate from the dependence of the numericalwave propagation velocity in the mesh on fre-quency and direction [29]. Because numericaldispersion causes cumulative phase errors andnon-physical refraction, it is necessary to min-imize these effects. In general the dispersionerror per wavelength can be expressed as

ψerr = 2π ·

λ− 1

), (1)

where λ/λ is the ratio of the exact (continu-ous space) wavelength to the numerical wave-length. The more cells there are per wavelength,the closer the numerical wavelength is to theexact one. Since the Yee-cell based FDTD algo-rithm is second-order accurate, the dispersionerror decreases by a factor m2 if the cell sizedecreases by a factor m. The effect of disper-sion can therefore be reduced to an acceptablelevel by setting the mesh size appropriately.The typical “rule of thumb” is that the meshsize should be at most dmax ≤ λ/10 with themesh spacing in each direction, dx, dy, dz ≤ dmax

[30]. For many problems a finer mesher withdmax ≤ λ/20 or dmax ≤ λ/30 may be necessaryto achieve the required accuracy.

The central-difference formulation used inmany FDTD codes is only accurate to first-orderlocally if the mesh in non-uniform, though it re-mains accurate to second-order globally [31]. Inthe interests of accuracy it is therefore better tokeep the mesh as uniform as possible and limitthe mesh size ratio between neighbouring cells

to a number close to unity. Nevertheless thereare advantages of non-uniform meshes, whichallow a fine mesh where geometrical detail orfield variation requires (for example materialinterfaces) and a coarse mesh elsewhere. Thisallows a trade-off between numerical error andcomputational efficiency. In addition, a variablemesh cell size allows the mesh-to-object fittingto be adjusted, which can be important, for ex-ample, to ensure accurate resonant frequenciesare obtained. Nevertheless, the ratio of adjacentmesh cell sizes needs to be constrained; in mostcases it is sufficient to chose the upper limit forthis ratio as di/di+1 < 1.5.

3 AN ALGORITHM FOR STRUCTURED

MESH GENERATION

3.1 Input unstructured mesh

Since most CAD packages are capable of ex-porting an unstructured mesh, regardless oftheir internal representation, we chose to usean unstructured mesh, rather than a particularCAD representation as input to the mesher. Forthe internal unstructured and structured meshformats we created a format based on thosedefined in the AMELET-HDF specification [34].These formats are quite general and allow thedefinition of mesh nodes and various mesh ele-ments like line elements (two nodes) and trian-gles (three nodes). The AMELET-HDF formats,which were specifically developed for com-putational electromagnetics applications, alsoallow naming groups of elements of differenttypes like nodes, lines, surfaces in order to iden-tify these types of object in the mesh and allowthe allocation of different material properties toeach group.

Since AMELET-HDF uses HDF5, which isdifficult to parse in a portable way in bothMATLAB and Octave and is also quite com-plex, we chose the Gmsh msh-format [33] as theprimary ”on-disk” format for the unstructuredmesh. Gmsh can import and modify a range ofother common structured mesh formats fromCAD and other (unstructured) meshing tools(such as STEP and IGES), and has the capabilityto group elements, so it can act as an interface

IEEE ANTENNA AND PROPAGATION MAGAZINE 4

Fig. 2. Flow chart of a typical work-flow for generating the inputunstructured mesh.

between a CAD program and the mesh genera-tor introduced in this article. Figure 2 illustratesa typical work-flow using a CAD tool suchas FreeCAD to generate the original geometrywhich can be saved in a suitable intermediateformat for Gmsh.

3.2 Generating a uniform structured mesh

As mentioned above, a uniform mesh min-imises the magnitude of certain numerical er-rors and therefore it is the basic mesh for FDTDsimulations. It is also simpler to implement andunderstand than a mesh where the cell sizevaries, but still provides a good introduction tosome of the issues of structured mesh genera-tion.

Consider a problem scenario where objectswith different electromagnetic properties arepresent such as in Figure 3. In our mesher, themaximum mesh size, dmax, is constrained suchthat the mesh cells are less than or equal to λ/10in the material with the shortest wavelength(this is can be defined manually or determinedfrom a material database using the frequencydependent constitutive parameters of the mate-rial). A minimum mesh size, dmin, is specified

Object 0

Object 1

Object 2

Object 3

Object 4

y

x

d0max d1

max d2max d3

max d4max d5

max d6max d7

max

Fig. 3. Example of overlapping objects in one coordinate direc-tion (x).

manually. In order to fit the geometry to themesh, the mesher must choose a mesh size be-tween these limits which best fits the geometryof the objects to be meshed. The maximumuniform mesh size is bounded above by thesmallest mesh size of all the intervals,

dmax = min(dmaxi ≤ λ/10), (2)

where i indexes the intervals. When dmin = dmax

the algorithm simply uses the defined meshsize without any optimization.

We take a simple approach to a best fit bytrying to find a mesh size in each coordinatedirection that ensures that the edge of eachobject’s bounding box lies on a mesh line. Wedefine the edge of each object’s axis alignedbounding box (AABB) in each dimension as aconstraint point which divides the mesh into anumber of intervals di as shown in Figure 3. Theconstraint points (i.e. interval boundaries) aredefined by Xi (i = 1, . . . , Nx), Yi (i = 1, . . . , Ny)and Zi (i = 1, . . . , Nz), where Nx, Ny, Nz are thenumber of constraints in the respective direc-tions. These points have to be part of the meshto guarantee the mesh is adjacent to the objects.Since the restriction dmin prevents this align-ment in most cases, the lack of a perfect meshsolution changes the task to finding a meshsolution that causes minimum deviation fromthe input geometry in the FDTD simulation.

IEEE ANTENNA AND PROPAGATION MAGAZINE 5

The uniform mesh lines are defined by

xi = X1 + i · dx,opt i = 0, ..., nx − 1

yi = Y1 + j · dy,opt j = 0, ..., ny − 1,

zi = Z1 + k · dz,opt k = 0, ..., nz − 1

(3)

where di,opt is the unknown optimum mesh sizein the i-direction and nx, ny and nz are thenumber of mesh lines in the specified direction.The next step aims to satisfy the condition thatall the constraint points are closely aligned witha mesh line by independently minimizing thefunctions

fx(dx,opt) =Nx−1∑

i=1

(∆Xi

dx,opt

)

fy(dy,opt) =Ny−1∑

j=1

(∆Yjdy,opt

)

fz(dz,opt) =Nz−1∑

k=1

(∆Zk

dz,opt

)

(4)

with

∆Xi = Xi+1 −Xi i = 1, ..., Nx − 1

∆Yj = Yj+1 − Yj j = 1, ..., Ny − 1,

∆Zk = Zk+1 − Zk k = 1, ..., Nz − 1

(5)

using the golden section search with parabolicinterpolation algorithm available in MATLAB’sfminbnd function. In the case of several equalsolutions, the one with the largest value ofdopt is chosen to minimize the computationaltime. If a cubic mesh is required then the sumfx(dopt) + fy(dopt) + fz(dopt) is minimised in asingle optimisation.

After dopt is known it is still necessary todetermine the optimum offset of the mesh linesrelative to the constraint points. Therefore wecarry out another optimisation to simultane-ously minimize the functions

gx(x0) =Nx∑

i=1

| Xi − x0 − x |

gy(y0) =Ny∑

j=1

| Yi − y0 − y |,

gz(z0) =Nz∑

k=1

| Zi − z0 − z |

(6)

where x, y and z are the mesh lines calculatedusing (3) and (4) and x0, y0 and z0 are the

Fig. 4. Example of a uniform mesh solution for three overlappingobjects.

offsets to be determined. For this MATLAB’smulti-variable gradient-based fmincon optimi-sation function is used. Because the solutionof (6) is periodic, the offsets are limited to theranges defined by 0 ≤ x0 ≤ dx,opt, 0 ≤ y0 ≤ dy,optand 0 ≤ z0 ≤ dz,opt. Since this step shifts theorigin of the mesh, it is necessary to extend themesh in order to ensure that it still encloses theobjects to be meshed. The position of the meshlines are therefore

x = X1 − x0 + i ·Dx,opt i = 0, ..., nx

y = Y1 − y0 + j ·Dy,opt j = 0, ..., ny.

z = Z1 − z0 + k ·Dz,opt k = 0, ..., nz

(7)

A practical example of the results of thealgorithm can be seen in Figure 4, where auniform mesh has been generated to representthree overlapping objects by using the smallestmesh size defined by one of the objects. Thestructured mesh shown is the optimal meshsolution found by the above algorithm, with allobject boundaries aligned with the mesh lines.The full implementation also allows weights tobe assigned to different constraints so the usercan control the optimisation process.

3.3 Generating a non-uniform mesh

In contrast to the uniform mesh algorithm de-scribed in the previous section, an automaticnon-uniform mesh algorithm that can handle

IEEE ANTENNA AND PROPAGATION MAGAZINE 6

most mesh scenarios is a much more com-plex problem. Each object may impose differentmesh size limits, objects may overlap on anyaxis and the rate of change of mesh size is lim-ited; all these interactions must be considered toproduce a good mesh. For simplicity we presentthe treatment of only one axis in the following -the process is identical for each axis. This meansthat the aspect ratio of the cells is not currentlyconstrained directly, though the way that themaximum mesh size in each material is usedin the constraints in each direction indirectlylimits the ability of the algorithm to generatehigh aspect ratio cells.

Considering a scenario similar to the onein Figure 3, it is first necessary to create a 1Dprojection of the objects on to each axis. Foreach interval delineated by the object bound-ing boxes, the object with the smallest definedmaximum mesh size, dmax

i , must dominate allother overlapping objects when the mesh isgenerated. If we take the maximum mesh sizefor each interval, as determined from the objectwith the smallest maximum mesh size in thatinterval, and plot it against position on one axisa plot like that of Figure 5 is obtained.

In order to produce a viable mesh we musthonour the maximum mesh size in each inter-val. However in order to minimise the numberof mesh elements we must allow the mesh sizeto grow when we progress from an intervalwith a small maximum mesh size to an intervalwith a larger mesh size. The growth in meshsize being limited by the maximum cell sizeratio rmax. Figure 6 shows the possible growthin mesh size from each interval added to theinterval mesh sizes of Figure 5. We now knowfor all interval boundaries the maximum meshsize that can be created, either by the respectiveinterval itself or by growth of the mesh sizefrom neighbouring intervals.

Figure 7 shows the next step. In order toavoid exceeding rmax, the smallest mesh sizehas to be selected at each boundary. If this meshsize was determined by mesh growth from asmaller cell it is continued until it either endsin another subinterval boundary (position A)or until it exceeds the maximum mesh size,dmaxi , of the current subinterval (position B) as

xInterval 1

Interval 2 Interval 8

Interval 9

dximax

Fig. 5. The maximum allowed mesh size in each interval alongthe x-axis.

x

dximax

Interval 1

Interval 2 Interval 8

Interval 9

Fig. 6. Geometric progression of mesh sizes from each interval.

x

dximax

Interval 1

Interval 2 Interval 8

Interval 9

A B C

Fig. 7. Initial selection of smallest mesh size at interval bound-aries and extension of growth lines.

x

dximax

Interval 1

Interval 2 Interval 8

Interval 9

A B C

Fig. 8. Final selection of maximum mesh size at each point onthe axis.

IEEE ANTENNA AND PROPAGATION MAGAZINE 7

diA diBL

LMLA LBdi

x

dimax

Fig. 9. Mesh size for interval for a non-uniform mesh that growsfrom both sides reaching the interval maximum d

maxi .

diA diBL

LA LBdi

x

dimax

1/2(L - LB + LA)

Fig. 10. Mesh size for interval for a non-uniform mesh that growsfrom both sides and does not reaching the interval maximumdmaxi before clashing.

illustrated in Figure 7. Another possible meshsolution occur if two geometric progressionsintersect before overstepping dmax

i (position C).

Now we can choose the line of smallestmesh size in each interval as shown in Figure 8.Having now determined the feasible limit ofmesh size in each interval we have to place themesh lines. However it should be pointed outthat Figure 8 represents only an approximatesolution as there must be an integer number ofmesh cells in each interval if the interval bound-aries are to be maintained. Mesh lines, whichsatisfy the mesh size and ratio constraints, canbe created locally for each interval with theinformation for each interval illustrated in Fig-ure 8.

There are a number of scenarios that canoccur in each interval and each must be treatedindividually. Figure 9 shows the mesh size dxacross an interval of length L for the case wherethe mesh size grows and reaches its maximumvalue, dmax

i , within the interval. LA is the dis-tance from the left boundary over which themesh size grows, LM is the distance for whichthe mesh size remains constant at its maximumvalue, and LB is the distance over which themesh grows from the right boundary. LA andLB are initially not known. The number of mesh

cells, NiA , in LA is

NiA =

1 +log

(dmaxi

diA

)

log(rmax)

(8)

where ⌊z⌋ is the largest integer smaller than orequal to z and diA is the mesh size at the leftboundary. Now, as NiA is rounded down to aninteger we have a maximum mesh size less thandmaxi after NiA mesh cells, which is sufficient to

meet the mesh size criterion, that is

rNiAmaxdxA

≤ dmaxi . (9)

The length of the transition region, LA, can nowbe computed by summing the geometric series

LA =

NiA∑

i=1

diArNiAmax = diA

1− rNiAmax

1− rmax

. (10)

Similarly for LB

NiB =

1 +log

(dmaxi

diB

)

log(rmax)

(11)

and

LB = diB1− r

NiBmax

1− rmax

. (12)

It should be clear that after the preprocessingresulting in a solution similar to the example inFigure 8 there is no scenario with diA > dmax

i ordiB > dmax

i .If LA+LB < L, then the situation is as shown

in Figure 9, with LM = L − LA − LB. NowLM might not correspond to an exact numberof cells of size dmax

i that will respect the ratiobetween the intersection points of LA, LM andLB. If necessary we must modify the numberof cells and cell ratios in LA and LB by incre-menting NiA and NiB and reducing the step incell sizes to reduce LM to an exact number ofuniform cells (possibly zero). This is achievedby an iterative solution.

If LA + LB > L then the situation is as inFigure 10. Here we must compute the point atwhich the cell sizes intersect with 1/2 · (L −LB + LA) and modify NiA , NiB and the stepin cell sizes to ensure that the sections meetin an integer number of cells without breaking

IEEE ANTENNA AND PROPAGATION MAGAZINE 8

Fig. 11. Example of a non-uniform mesh showing a slice throughthree different regions and the generated mesh lines.

Fig. 12. Input unstructured mesh (left) and generated structuredmesh (right) of three objects.

the ratio condition. This is also achieved by aniterative solution.

A practical 2D example of the results of thealgorithm can be seen in Figure 11, where anon-uniform mesh is used to represent threeoverlapping objects. The mesh size increasesfrom the smallest to the largest ensuring thatthe electromagnetic properties of the objects arerespected as well as the object boundaries.

4 ALGORITHM FOR MATERIAL MAP-

PING

4.1 Ray casting

After the positions of the mesh lines are cal-culated, it is necessary to identify which struc-

tured mesh cells or faces belong to which meshobjects in the input unstructured mesh so thatthe correct material properties can be assigned.This process is called material mapping. In thispaper the ray casting method is considered.In essence, a set of rays are cast through thecomputational domain and the intersections ofthe rays with the objects in the unstructuredmesh are located. A fast ray-triangle intersec-tion algorithm reported [26] and implementedby [39] was used to find the intersections. Thisset of intersections is then projected onto thestructured mesh to locate the object. Whilerather simple in concept the method is difficultto implement reliably due to the occurrences of“singularities” associated with borderline cases.These are discussed in more detailed below.

The directions in which the rays are casthas a significant impact on the number ofsingularities that occur. Casting divergent raysfrom a point outside the computational do-main (along a diagonal of its bounding box) isone effective strategy to minimize the effect ofsingularities [22]. However, for the MATLABimplementation considered here this hindersthe vectorization of the algorithm. We thereforealso considered an approach where the rays arecast along a line of structured cells. This allowsone dimension of the ray-casting to be com-pletely vectorized using the ray-triangle inter-section algorithm implementation in [39]. Theresult of the mapping for a simple geometryconsisting of a two cubes and a sphere is shownin Figure 12.

The number of triangles in the unstructuredmesh can become enormous (several tens ofmillions) for electrical large or geometricallycomplex objects. Part of the approach to miti-gating this is parallelisation - and the ray cast-ing approach is extremely parallelizable, seefor example [9]. In addition, even more effi-ciency can be obtained by applying ray tracingacceleration techniques based on spatial parti-tioning, such as bounding volume hierarchies(BVHs) [40]. A simple BVH has been imple-mented in the open source mesher. The methodworks by successively dividing the volume oc-cupied by the triangles forming an object intosmaller and smaller sub-volumes forming a

IEEE ANTENNA AND PROPAGATION MAGAZINE 9

hierarchy. The AABB of all the triangles in eachsub-volume is determined as the sub-divisionproceeds and stored in a binary tree structure.Now when casting a ray through the object wefirst test if the highest level sub-volume AABB(the whole object) intersects the ray. If it does,we descend the two branches of the tree andtest for intersection of the ray with the sub-volume AABBs of the children. If there is nointersection with a child AABB then that child,and all its children, can immediately be elimi-nated from the search, potentially saving a verylarge number of intersections tests. If the childAABB also intersects then its children’s sub-volumes are are checked and so on down thetree. BVHs implemented in low-level languagesoften subdivide the object until there is onlyone triangle in the sub-volume. Because we areusing a vectorized intersection algorithm in ahigh-level language there is an optimum depthfor the BVH that was determined empiricallyto be when there are about 1000 triangles in asub-volume. The partitioning algorithm used todivide the triangles into sub-volumes also im-pacts on the performance of the algorithm; it isbest to try and balance the number of trianglesin each child at the same level of the tree. Inthe mesher reported here we implemented anumber of partitioning methods including theSurface Area Heuristic (SAH) [41].

4.2 Mesh generator for structured solid ob-jects

A solid is represented in the structured meshby the volumetric material cells of the insidevolume of a closed unstructured surface in theinput mesh. Because both solid and surfaceobjects are represented by a surface input mesh,it is necessary to distinguish amongst theseusing control parameters for each group ofinput objects. Thus, the input mesh for a solidis required to be a closed surface with a welldefined inside which can be identified by theoccurrence of an even number of intersectionsbetween ray and object. This means that it ispossible to identify where a ray enters andleaves the object as shown in Figure 13. Thedecision about whether a cell belongs to the

grid

cell center

ray

A

object

Fig. 13. Detection of active cells when mapping solid objects.

solid structure is the main task. By selecting allcell centres between the intersection points theinside volume of the object can be identified(see the grey cells).

Unfortunately the situation is not always asclear-cut as that shown in Figure 13. For anarbitrarily shaped object a ray may hit an edgeor a vertex of a triangle resulting in multipleintersections, e.g. both the triangles sharing anintersected edge will be identified as beinghit by a ray and this must not be interpretedas independent hits entering and leaving theobject. If a ray hits an edge/node that lies onthe perimeter of the silhouette of the object asseen from the ray-casting point (i.e. skims thesurface of the object) then it is should not beregarding a traversing the object’s surface. Suchcases are called singularities and they requirecareful treatment in order to ensure the correct,or at least a consistent, decision is made aboutwhether the ray traverses the object boundary.The wrong choice can lead to local “blister-ing” of an object or even disastrous globallyincorrect mapping, turining part of the object“inside-out”. A detailed description of the dif-ferent types of singularity and methods to dealwith them is given in [22]. Here we outline the

IEEE ANTENNA AND PROPAGATION MAGAZINE 10

grid

cell center

ray

A

object

Fig. 14. Detection of active cells when mapping surface objects.

approach for the open source mesher.Providing all the triangles in the unstruc-

tured mesh have a consistent normal directionand the input mesh satisfies certain tolerancesregarding triangle size it is possible to identifyedge/node singularities reliably since they willbe manifested as multiple intersections withtriangles at the same position (within a toler-ance) along the ray, with a mixture of inwardand outward facing normals. By default suchintersections are regarded as non-traversing, i.e.the ray does not cross the boundary of theobject. This, together with a verification that aneven number of intersections are made by allthe rays passing through the object ensures theglobal integrity of the mapping. Optionally, forimproved local fidelity, a six-point interpolationbased resolver can be invoked after all theobject has been mapped to determine whethernon-traversing singularities that occurs at a cellcenters should be inside or outside the objectbased on the cells immediately adjacent to thesingular cells [22]. A fall-back procedure thatallows rays to be cast from multiple directionsand the decision for each cell to be determinedby a “vote” between the results for each di-rection (with user defined dictator, majority orconsensus decision threshold) has also been im-plemented, though this substantially increasesthe computational effort.

The entire mapping algorithm depends onquite a number of interacting tolerances that

require careful tuning in order to prevent mesh-ing artifacts appearing. Some of the tolerancesare determined by an analysis of the scaleand variability of the triangles in the inputmesh. They can also be overidden by the useron an object-by-object basis. There is also apresumption that the input unstructured meshdoes not contain any pathological features sucha dramatic changes in scale comparable withthe defined tolerances. Such difficulties can beavoided by applying appropriate mesh clean-ing algorithms to the input unstructured meshbefore it is mapped.

4.3 Mesh generator for structured surfaceobjects

A surface in the structured mesh is representedby a set of cell faces (typically to supportperfect electric conductor (PEC) and sub-cellmaterial models and source and observationsurfaces) approximating a surface in the inputunstructured mesh. In order to map an arbitrar-ily orientated surface rays are cast from threedirections, along the Cartesian coordinate axisdirections; rays along the x, y, z-direction areused to identify which x, y, z-normal cell facesrespectively form part of the object’s surface.In general the surface may be open and thereis no concept of inside or outside as shown inFigure 14. As a consequence the set of ray in-tersections is not restricted to an even number.Every cell is associated with one face normal toeach direction, by convention taken to be thefaces on the low coordinate side of the cell (inFigure 14 the right side of each cell). In caseswhere the cell centre is exactly on the objectsurface, all six surfaces enclosing that cell centreget identified as part of the object by conven-tion (Figure 14 position A). This special casetreatment is a simple solution to avoiding holesin the structured surface and irregularities inthe later FDTD simulation. More sophisticatedapproaches to maintaining the local topology ofthe mapped surface are possible though nonehave been implemented yet.

IEEE ANTENNA AND PROPAGATION MAGAZINE 11

Fig. 15. Performance of the mesher with different numbers ofinput and output elements.

5 PRACTICAL EXAMPLES AND MESHER

PERFORMANCE

By investigating the meshing process, we seethat the number of unstructured input elementsand structured output elements both have asignificant influence on the performance. Forclarification the number of output elements in-cludes both the cells for the both the objectsthemselves and the free space in the compu-tational volume. Since the mesh line generationis not significantly influenced by the numberof input elements, only the material mappingis investigated in the following using a 64-bitLinux PC with an Intel Xeon E5-2687Wv2 CPUrunning at 3.40 GHz.

Figure 15 shows how the CPU-time in-creases with the number of output elements.Analysing models with different numbers ofinput elements from 240 to 101 158, a significantinfluence on the CPU-time can also be seen.Since the mesh line creation typically takes mil-liseconds to process, its influence on the overallruntime is negligible. The maximum analysedruntime was approximately 15 minutes for astructure with 101 158 input and 13 481 272 out-put elements.

The run-time is strongly influenced by thevectorisation of the MATLAB code and thebounding volume hierarchy. Currently the par-allelisation of the algorithm with regard to cast-ing different rays on separate computationalcores has not been fully implemented. This is

Fig. 16. A wideband hybrid antenna [36].

relatively straightforward to do and will sub-stantially improve the performance on largemodels.

As an example of the current practicalmesher performance, Figure 16 shows a wide-band hybrid antenna [36] which required acomputational runtime of less than one minute(input: 12 678 elements, output: 47 360 cells).This example also demonstrates the mesher’sability to deal with structures consisting of dif-ferent object types. The antenna model consistsof a metal surface ground plane (green) andvertical metal “blade” (yellow), a solid dielec-tric pillar (blue) and a metal feed structure(red). The mesher output is a good represen-tation of the input mesh without any irregular-ities or geometric deviations.

Larger models with a more complicated sur-

IEEE ANTENNA AND PROPAGATION MAGAZINE 12

Fig. 17. Input unstructured mesh (top) and generated structuredmesh (bottom) of an aeroplane [37].

face structure need longer computational run-times, e.g. the aeroplane shown in Figure 17took 67 minutes (input: 44 847 elements, output:503 941 914 cells). This is a complex object forthe mesher since it has uneven planes at dif-ferent angles as well as holes and cuts in thesurface. This surface structure can, if not rep-resented accurately, cause an incorrect electro-magnetic behaviour of the object. The mesheragain achieves good conformity between theunstructured and generated structured meshes.

Another complex-shaped object can be seenin Figure 18. This object took approximately100 minutes to map (input: 179 146 elements,output: 324 242 703 elements). Besides the com-plicated surface structure, different parts of thismodel overlap each other in the x, y and zdirections. If the mesher did not identify enter-ing and exiting locations of this model exactly,the structured output mesh would not conformwith the unstructured mesh.

Fig. 18. Meshing example of a complex ring structure [38],showing the input unstructured mesh (top), structured mesh(middle) and a zoomed view of the detail of the structured mesh(bottom).

IEEE ANTENNA AND PROPAGATION MAGAZINE 13

6 CONCLUSIONS

This article presents an open-source implemen-tation of an algorithm for uniform and non-uniform cuboid mesh generation for FDTDsolvers and similar codes. The mesher takesan unstructured mesh as input, thus allowinggreat flexibility in the CAD tools that can beutilised in the initial creation of the simulationgeometry.

The algorithm is based on an optimisationapproach to the placement of mesh lines andthe well-known ray-casting approach to mate-rial mapping. While the mesher currently doesnot have all the features of a commercial tool itcan mesh structures of modest size with reason-able complexity, as shown by the examples pre-sented. Further work is continuing to improvethe material mapping performance and featureset.

The code is available under a GPL Ver-sion 3 licence from https://bitbucket.org/uoyaeg/aegmesher/overview.

REFERENCES

[1] A. Taflove and S. C. Hagness, Computational Electromagnet-ics: The Finite-Difference Time-Domain Method, 3rd Edition,Artech House, 2005

[2] K. S. Kunz and R. J. Luebbers, The finite difference timedomain method for electromagnetics, Boca Raton, CRC press,1993

[3] W. Sun, C. A. Balanis, M. P. Purchine and G. C. Barber,Three-dimensional automatic FDTD mesh generation on aPC, Antennas and Propagation, IEEE International Symposiumon, Ann Arbor, MI, pp. 30-33, 28 Jun.-2 Jul., 1993.

[4] M. Yang and Y. Chen, AutoMesh: An automatically ad-justable, non-uniform, orthogonal FDTD mesh generator,IEEE Antennas and Propagation Magazine, vol. 41, no. 2, pp.13-19, April 1999.

[5] Y. Kanai and K. Sato, Automatic mesh generation for 3Delectromagnetic field analysis by FDTD method, Magnetics,IEEE Transactions on, vol. 34, no. 5, pp. 3383-3386, Septem-ber 1998.

[6] Y. Srisukh, J. Nehrbrass, F. L. Teixeira, J.-F. Lee and R.Lee, An approach for automatic grid generation in three-dimensional FDTD simulations of complex geometries,IEEE Antennas and Propagation Magazine, vol. 44, no.4, pp.75-80, August 2002.

[7] Y. Srisukh, J. Nehrbuss, F. L. Teixeira. JLF. Lee, and R. Lee,Automatic grid generation of complex geometries for 3-DFDTD simulations, Antennas and Propagation, IEEE Interna-tional Symposium on, Columbus, OH, pp. 326-329, 22-27 Jun.,2003.

[8] T. Ishida, S. Takahashi and K. Nakahashi, Efficient and ro-bust Cartesian mesh generation for building-cube method,Journal of Computational Science and Technology, vol. 2, no. 4,pp. 435-437, 2008.

[9] J. T. MacGillivray, Trillion cell CAD-based cartesian meshgenerator for the finite-difference time-domain method ona single-processor 4-GB workstation, Antennas and Propa-gation, IEEE Transactions on, vol. 56, no. 8, pp. 2187-2190,August 2008.

[10] S. Wang and J. H. Duyn, Three-dimensional automaticmesh generation for hybrid electromagnetic simulations,IEEE Antennas and Propagation Magazine, vol. 51, no. 2, pp.71-85, April 2009.

[11] H.-S. Kim, I. Ihm and K. Choi, Generation of non-uniformmeshes for finite-difference time-domain simulations, Jour-nal of Electrical Engineering and Technology, vol. 6, no. 1, pp.128-132, 2011.

[12] H. M. L. A. Fernanades, Development of Software for An-tenna Analysis and Design using FDTD, Portugal: Universityof Lisboa, 2007

[13] Y. Kanai and K. Sato, ”Automatic mesh generation for3D electromagnetic field analysis by FD-TD method”, IEEETransactions on Magnetics, no. 5, pp. 3383-3386, 1998

[14] H.-S. Kim, I. Ihm and K. Choi, ”Generation of Non-uniform Meshes for Finite-Difference Time-Domain Simu-lations”, Journal of Electrical Engineering & Technology, 2011

[15] W. Yu, R. Mittra, ”A conformal FDTD software packagemodeling antennas and microstrip circuit components”,IEEE Antennas and Propagation Magazine, vol. 42, no. 5, pp.28-39, 2000

[16] Z. Su, Y. Liu, W. Yu, R. Mittra, ”A conformal mesh-generating technique for the conformal finite-differencetime-domain (CFDTD) method”, IEEE Antennas and Prop-agation Magazine, vol. 46, no. 1, pp. 37-49, 2004

[17] G. Waldschmidt, A. Taflove, ”Three-dimensional CAD-based mesh Generator for the Dey-Mittra conformal FDTDalgorithm”, Antennas and Propagation, IEEE Transactions on,vol. 52, no. 7, pp. 1658-1664, 2004

[18] S. Wang, J.H. Duyn, ”Three-dimensional automatic meshgeneration for hybrid electromagnetic simulations”, IEEEAntennas and Propagation Magazine, vol. 51, no. 2, pp. 71-85,2009

[19] M. J. Aftosmis, M. J. Berger and J. E. Melton, AdaptiveCartesian Mesh Generation, CRC handbook of mesh gener-ation (Contributed Chapter), 1998

[20] T. Ishida, S. Takahashi and K. Nakahashi, Efficient andRobust Cartesian Mesh Generation for Building-Cube Method,Journal of Electrical Engineering & Technology, no. 4, pp.435-446, 2008

[21] Y. Liu, C.D. Sarris, ”AMR-FDTD: a dynamically adap-tive mesh refinement scheme for the finite-difference time-domain technique”, Antennas and Propagation Society Inter-national Symposium, vol. 1A, pp. 134-137, 2005

[22] J. Hill, Efficient Implementation of Mesh Generation and FDTDSimulation of Electromagnetic Fields, England: University ofWorcester, 1996

[23] Y. E. Kalay, ”Determining the spatial containment of apoint in general polyhedra”, Journal of Computer Graphicsand Image Processing, no. 4, pp. 303-334, 1982

[24] S. Thon, G. Gesquiere and R.Raffin, A Low Cost AntialiasedSpace Filled Voxelization Of Polygonal Objects, GraphiCon ’04Proceedings, pp. 71-78, 2004

[25] M. Szucki and J. Suchy, A Voxelization Based Mesh Genera-tion Algorithm for Numerical Models used in Foundry Engineer-ing, Journal of Metallurgy and Foundry Engineering, no. 1,2012

[26] T. Moller and B. Trumbore, Fast, minimum storageray/triangle intersection, ACM SIGGRAPH 2005 Courses,USA: Los Angeles, 2005

IEEE ANTENNA AND PROPAGATION MAGAZINE 14

[27] MathWorks, MATLAB R2015a, Available: http://de.mathworks.com/ , Online, 2015

[28] Octave community, GNU Octave 3.8.1, Available: www.gnu.org/software/octave, Online, 2014

[29] J. S. Juntunen and T. D. Tsiboukis, ”Reduction of nu-merical dispersion in FDTD method through artificialanisotropy”, IEEE Transactions on Microwave Theory andTechniques, vol. 48, no. 4, pp. 582-588, 2000

[30] K. L. Shlager and J. B. Schneider, ”Comparison of theDispersion Properties of Several Low-Dispersion Finite-Difference Time-Domain Algorithms”, IEEE Transactions onAntennas and Propagation, vol. 51, no. 3, pp. 642-653, 2003

[31] H. Jiang and H. Arai, ”Fast and efficient FDTD analysisusing non-uniform mesh for small antenna”, IEEE Antennasand Propagation Society International Symposium, vol. 2, pp.1242-1245, 1998

[32] S. J. Owen, A Survey of Unstructured Mesh GenerationTechnology, IMR, 1998

[33] C. Geuzaine and J.-F. Remacle, ”Gmsh: a three-dimensional finite element mesh generator with built-inpre- and post-processing facilities”, International Journal forNumerical Methods in Engineering 79(11), pp. 1309-1331, 2009

[34] C. Giraudon, Amelet-HDF Documentation, Axessim, 2011[35] M. Hazewinkel, Encyclopaedia of mathematics, Supplement

Volume II, Springer, 2000[36] A. C. Marvin, G. Esposito, J. F. Dawson, I. D. Flintoft,

L. Dawson, J. K. A. Everard, G. C. R. Melia, ”A wide-band hybrid antenna for use in reverberation chambers”,IEEE International Symposium on Electromagnetic Compatibil-ity (EMC), pp. 222-226, 2013

[37] 3dvia, Available: http://www.3dvia.com/content/2C7A92223406182A, Online, 2010

[38] 3dvia, Available: http://www.3dvia.com/content/E3B1C7D9EBFDCFE1, Online, 2007

[39] J. Tuszynski, “Fast vectorized triangle/rayintersection algorithm”, 29 Sep. 2011. http://uk.mathworks.com/matlabcentral/fileexchange/33073-triangle-ray-intersection

[40] I. Wald, S. Boulos and P. Shirley, “Ray Tracing DeformableScenes using Dynamic Bounding Volume Hierarchies”,ACM Transactions on Graphics 26, 1, 2007.

[41] I. Wald, “On fast Construction of SAH based Bound-ing Volume Hierarchies”, in Proceedings of the 2007 Eu-rographics/IEEE Symposium on Interactive Ray Tracing,2007.