Geometries subroutine

From FDTD++ wiki
Jump to: navigation, search

NOTE: This method of geometric modeling is depreciated in the current version of FDTD++. The recommended method of geometric modeling is computer-aided design (CAD)/mesh import.


One approach to geometric modeling in FDTD++ is to provide a file with a subroutine (the geometries subroutine) that specified integers $n$, corresponding to materials defined in the materials file, given any $(x, y, z)$ Cartesian coordinate. Below discusses the creation of this file and the definition of this subroutine.

Creating the file

The file containing the geometries subroutine can be created with any text editor, and given any name. This file must be placed in the compile path of FDTD++ though. The standard practice is to name this file geometry.cpp and placed in the directory FDTDxx/user/, where FDTDxx/ is the FDTD++ directory (as provided with FDTD++, by default).

Note that in the case of CAD/mesh import, this subroutine is ignored.

Note also that because the structure is specified in a .cpp file, FDTD++ must be recompiled after declaring a new structure. This is one reason why this method is depreciated.

Subroutine

The geometries subroutine must be declared as follows:

void geometry(double x, double y, double z, int &n)

Then, the subroutine must provide functionality such that $n$ is defined, consistent with the materials file, given any $(x, y, z)$ Cartesian coordinate. Note that if this subroutine does not assign a value of $n$ for a given $(x, y, z)$ position, the interior computational domain background will be assigned.

vacuum will be assigned.

Note also that the simplest way to use this function is to define the structure centered around (0, 0, 0), and use the simulation parameters geom shift to shift the structure to the desired position within the computational domain.

Example

As an example, consider the geometric modeling of a 10 nm radius sphere, and assumed that the materials file defines two materials, $n = 1$ corresponding to the sphere and $n = 0$ corresponding to the surrounding material. In this case, geometry.cpp would contain the following:

#include <cmath>

void geometry(double x, double y, double z, int &n)
{
    double r = 10.0e-9;

    if( std::sqrt(x*x + y*y + z*z) <= r  )
    {
        n = 1;
    }
    else
    {
        n = 0;
    }
}