# Meshing¶

## 1D mesher¶

DEVSIM has an internal 1D mesher and the proper sequence of commands follow in this example.

devsim.create_1d_mesh(mesh="cap")
tag1="top", tag2="mid")
tag1="mid", tag2="bot")
devsim.finalize_mesh(mesh="cap")
devsim.create_device(mesh="cap", device="device")


The devsim.create_1d_mesh() is first used to initialize the specification of a new mesh by the name specified with the command option. The devsim.add_1d_mesh_line() is used to specify the end points of the 1D structure, as well as the location of points where the spacing changes. The command is used to create reference labels used for specifying the contacts, interfaces and regions.

The devsim.add_1d_contact(), devsim.add_1d_interface() and devsim.add_1d_region() are used to specify the contacts, interfaces and regions for the device.

Once the meshing commands have been completed, the devsim.finalize_mesh() is called to create a mesh structure and then devsim.create_device() is used to create a device using the mesh.

## 2D mesher¶

Similar to the 1D mesher, the 2D mesher uses a sequence of non-terminating mesh lines are specified in both the x and y directions to specify a mesh structure. As opposed to using tags, the regions are specified using devsim.add_2d_region() as box coordinates on the mesh coordinates. The contacts and interfaces are specified using boxes, however it is best to ensure the the interfaces and contacts encompass only one line of points.

devsim.create_2d_mesh(mesh="cap")
yl=ymid1, yh=ymin)
yl=ymid2, yh=ymid1)
yl=ymid2, yh=ymax)

xl=0, xh=1, yl=ymid2, yh=ymid2, bloat=1.0e-10)
bloat=1.0e-10, material="metal")
bloat=1.0e-10, material="metal")
devsim.finalize_mesh(mesh="cap")
devsim.create_device(mesh="cap", device="device")


In the current implementation of the software, it is necessary to create a region on both sides of the contact in order to create a contact using devsim.add_2d_contact() or an interface using devsim.add_2d_interface().

Once the meshing commands have been completed, the devsim.finalize_mesh() is called to create a mesh structure and then devsim.create_device() is used to create a device using the mesh.

## Using an external mesher¶

DEVSIM supports reading meshes from Gmsh. Support for Genius Device Simulator is deprecated and will be removed from a future release. In addition, meshes may be input directly using the Python interface. These meshes may only contain points, lines, triangles, and tetrahedra. Hybrid meshes or uniform meshes containing other elements are not supported at this time.

### Genius¶

Meshes from the Genius Device Simulator software (see Genius) can be imported using the CGNS format. In this example, devsim.create_genius_mesh() returns region and boundary information which can be used to setup the device.

mesh_name = "nmos_iv"
result = create_genius_mesh(file="nmos_iv.cgns", mesh=mesh_name)

contacts = {}
for region_name, region_info in result['mesh_info']['regions'].iteritems():
region=region_name, material=region_info['material'])
for boundary, is_electrode in region_info['boundary_info'].iteritems():
if is_electrode:
if boundary in contacts:
contacts[boundary].append(region_name)
else:
contacts[boundary] = [region_name, ]

for contact, regions in contacts.iteritems():
if len(regions) == 1:
region=regions[0], material='metal')
else:
for region in regions:
name=contact+'@'+region, region=region, material='metal')

for boundary_name, regions in result['mesh_info']['boundaries'].iteritems():
if (len(regions) == 2):
name=boundary_name, region0=regions[0], region1=regions[1])

finalize_mesh(mesh=mesh_name)
create_device(mesh=mesh_name, device=mesh_name)


Example locations are available on genius.

### Gmsh¶

The Gmsh meshing software (see Gmsh) can be used to create a 1D, 2D, or 3D mesh suitable for use in DEVSIM. When creating the mesh file using the software, use physical group names to map the difference entities in the resulting mesh file to a group name. In this example, a MOS structure is read in:

devsim.create_gmsh_mesh(file="gmsh_mos2d.msh", mesh="mos2d")
material="Silicon")
material="Silicon")
material="Silicon")
name="drain", material="metal")
name="source", material="metal")
name="body", material="metal")
name="gate", material="metal")
region0="gate", region1="oxide", name="gate_oxide")
region0="bulk", region1="oxide", name="bulk_oxide")
devsim.finalize_mesh(mesh="mos2d")
devsim.create_device(mesh="mos2d", device="mos2d")


Once the meshing commands have been completed, the devsim.finalize_mesh() is called to create a mesh structure and then devsim.create_device() is used to create a device using the mesh.

It is also possible to arbitrarily load a mesh from a Python using the devsim.create_gmsh_mesh(). This is explained in the Notes section of the command.
The devsim.write_devices() is used to create an ASCII file suitable for saving data for restarting the simulation later. The devsim format encodes structural information, as well as the commands necessary for generating the models and equations used in the simulation. The devsim_data format is used for storing numerical information for use in other programs for analysis. The devsim.load_devices() is then used to reload the device data for restarting the simulation.