The Open FUSION Toolkit 26.9
An open-source framework for fusion and plasma science and engineering
Loading...
Searching...
No Matches
TokaMaker Meshing Example: Building a mesh for MANTA

In this example we show how to generate a mesh for the MANTA device using TokaMaker's built in mesh generation.

Note
Running this example requires the h5py python packages, which is installable using pip or other standard methods.
import os
import sys
import json
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = "retina"

Load TokaMaker library

To load the TokaMaker python module we need to tell python where to the module is located. This can be done either through the PYTHONPATH environment variable or using within a script using sys.path.append() as below, where we look for the environement variable OFT_ROOTPATH to provide the path to where the OpenFUSIONToolkit is installed (/Applications/OFT on macOS).

For meshing we will use the gs_Domain class to build a 2D triangular grid suitable for Grad-Shafranov equilibria. This class uses the triangle code through a simple internal python wrapper within OFT.

tokamaker_python_path = os.getenv('OFT_ROOTPATH')
if tokamaker_python_path is not None:
sys.path.append(os.path.join(tokamaker_python_path,'python'))
from OpenFUSIONToolkit.TokaMaker.meshing import gs_Domain, save_gs_mesh
TokaMaker utilities for mesh generation and manipulation.
Definition meshing.py:1

Build mesh

Set mesh resolution for each region

First we define some target sizes to set the resolution in the grid. These variables will be used later and represent the target edge size within a given region, where units are in meters. In this case we are using a fairly coarse resolution in all regions.

Note
When setting up a new machine these values will need to scale with the overall size of the device/domain. Additionally, one should perform a convergence study, by increasing resolution (decreasing target size) by at least a factor of two in all regions to ensure the results are not sensitive to your choice of grid size.
plasma_resolution = 0.08
coil_resolution = 0.075
vv_resolution = 0.15
vac_resolution = 0.15
flibe_resolution = 0.15

Load geometry information

The geometry information (eg. bounding curves) are now loaded from a JSON file. For simple geometries, testing, or generative usage this can be created directly in the code. However, it is often helpful to separate this information into a fixed datafile as here.

with open('MANTA_geom.json','r') as fid:
MANTA_geom = json.load(fid)

Define regions and attributes

We now create and define the various logical mesh regions. In MANTA we have 7 regions:

  • air: The region outside the vacuum vessel, which is not actually air in a complex device like MANTA but we use this terminology for commonality with present research devices
  • plasma: The region inside the limiter where the plasma will exist
  • vvin: The inner vacuum vessel
  • flibe: The main blanket region
  • vvout: The outer vacuum vessel
  • WC: Tungsten-Carbide shielding
  • B4C: Boron-Carbide shielding
  • PF1,...: Each of the 12 coils in MANTA (4 CS, 6 PF, 2 VSC)

In MANTA all coils are independent except for the vertical stability coil (VSC), which is single coil set composed of two counter-wound coils. To treat this set as a single coil we use the coil_set and nTurns argument to define_region() to join the coils in a single VSC coil set with opposing polarities.

Note
nTurns can also be used to define the number of turns in a given coil region. At the moment we are not including # of turns in this model so we keep the amplitude for each coil as 1.0 and only adjust the polarity.

For each region you can provide a target size and one of four region types:

  • plasma: The region where the plasma can exist and the classic Grad-Shafranov equation with \(F*F'\) and \(P'\) are allowed. There can only be one region of this type
  • vacuum: A region where not current can flow and \(\nabla^* \psi = 0\) is solved
  • boundary: A special case of the vacuum region, which forms the outer boundary of the computational domain. A region of this type is required if more than one region is specified
  • conductor: A region where toroidal current can flow passively (no externally applied voltage). For this type of region the resistivity should be specified with the argument eta in units of \(\omega \mathrm{-m}\).
  • coil: A region where toroidal current can flow with specified amplitude through set_coil_currents() or via shape optimization set_coil_reg() and set_isoflux()
# Create a G-S domain
gs_mesh = gs_Domain()
# Define region information for mesh
gs_mesh.define_region('plasma',plasma_resolution,'plasma') # Define the plasma region and resolution
gs_mesh.define_region('vvin',vv_resolution,'conductor',eta=6.9E-7) # Define the VV itself
gs_mesh.define_region('flibe',flibe_resolution,'vacuum') # Define the FLIBE blanket
gs_mesh.define_region('vvout',vv_resolution,'conductor',eta=6.9E-7) # Define the VV itself
gs_mesh.define_region('WC',vv_resolution,'conductor',eta=6.9E-7) # Define the WC shielding
gs_mesh.define_region('B4C',vv_resolution,'conductor',eta=6.9E-7) # Define the B4C shielding
gs_mesh.define_region('air',vac_resolution,'boundary') # Define the domain boundary region
# Define each of the PF coils
for name in MANTA_geom['coils']:
if name.startswith('VSC'):
nTurns = 1.0
if name[-1] == 'U':
nTurns = -1.0
gs_mesh.define_region(name,coil_resolution,'coil',nTurns=nTurns,coil_set='VSC')
else:
gs_mesh.define_region(name,coil_resolution,'coil')

Define geometry for region boundaries

Once the region types and properties are defined we now define the geometry of the mesh using shapes and references to the defined regions.

  1. We add the inner vacuum vessel as an "annulus" with curves defining the inner and outer edges respectively. We also reference plasma as the region enclosed by the annulus, vvin as the annular region itself, and flibe as the region outside the annulus.
  2. We add the outer vacuum vessel as an "annulus" with curves defining the inner and outer edges respectively. We also reference flibe as the region enclosed by the annulus, vvout as the annular region itself, and WC as the region outside the annulus.
  3. We add the \(B_4C\) shielding as an "annulus" with curves defining the inner and outer edges respectively. We also reference WC as the region enclosed by the annulus, B4C as the annular region itself, and air as the region outside the annulus.
  4. We add each of the 12 coils as "rectangles", which are defined by a center point (R,Z) along with a width (W) and height (H). We also reference air as the region outside the rectangle for the CS and PF coils and flibe for the VSC coils.
# Define geometry
gs_mesh.add_annulus(MANTA_geom['limiter'],'plasma',MANTA_geom['vvin2'][1],'vvin',parent_name='flibe') # Define the shape of the VV
gs_mesh.add_annulus(MANTA_geom['vvouter'][0],'flibe',MANTA_geom['vvouter'][1],'vvout',parent_name='WC') # Define the shape of the VV
gs_mesh.add_annulus(MANTA_geom['b4c'][0],'WC',MANTA_geom['b4c'][1],'B4C',parent_name='air') # Define the shape of the VV
# Define the shape of the PF coils
for name, coil in MANTA_geom['coils'].items():
if name.startswith('VS'):
gs_mesh.add_rectangle(coil['rc'],coil['zc'],coil['w'],coil['h'],name,parent_name='flibe',rot=coil['rotdeg'])
else:
gs_mesh.add_rectangle(coil['rc'],coil['zc'],coil['w'],coil['h'],name,parent_name='air',rot=coil['rotdeg'])

Plot topology

After defining the logical and physical topology we can now plot the curves within the definitions to double check everything is in the right place. In cases where curves appear to cross eachother (as with the VS coil and inner VV) one should zoom in to ensure no crossings exist.

fig, ax = plt.subplots(1,1)
for region in gs_mesh.regions:
region.plot_segments(fig,ax)
ax.set_aspect('equal','box')

Create mesh

Now we generate the actual mesh using the build_mesh() method. Additionally, if coil and/or conductor regions are defined the get_coils() and get_conductors() methods should also be called to get descriptive dictionaries for later use in TokaMaker. This step may take a few moments as triangle generates the mesh.

Note that, as is common with unstructured meshes, the mesh is stored a list of points mesh_pts of size [np,2], a list of cells formed from three points each mesh_lc of size [nc,3], and an array providing a region id number for each cell mesh_reg of size [nc,], which is mapped to the names above using the coil_dict and cond_dict dictionaries.

mesh_pts, mesh_lc, mesh_reg = gs_mesh.build_mesh()
coil_dict = gs_mesh.get_coils()
cond_dict = gs_mesh.get_conductors()
Assembling regions:
Warning: Small feature (dl=2.83E-02) detected at point 11 (5.67, 2.07)
Warning: Small feature (dl=3.16E-02) detected at point 13 (5.56, 1.84)
Warning: Small feature (dl=3.16E-02) detected at point 23 (5.57, -1.81)
Warning: Small feature (dl=2.83E-02) detected at point 25 (5.69, -2.05)
Warning: Small feature (dl=1.19E-02) detected at point 47 (5.234375460835327, 1.899760224651948)
Warning: Small feature (dl=5.38E-02) detected at point 51 (5.62909817703528, 1.8319289614847736)
Warning: Small feature (dl=5.38E-02) detected at point 61 (5.6460994674510845, -1.7809250902373603)
Warning: Small feature (dl=1.19E-02) detected at point 65 (5.2453146690553885, -1.8952022212269228)
  # of unique points    = 1232
  # of unique segments  = 140
Generating mesh with Triangle:
  # of points  = 8001
  # of cells   = 15766
  # of regions = 19

Plot resulting regions and grid

We now plot the mesh by region to inspect proper generation.

fig, ax = plt.subplots(2,2,figsize=(8,8),constrained_layout=True)
gs_mesh.plot_mesh(fig,ax)

Save mesh for later use

As generation of the mesh often takes comparable, or longer, time compare to runs in TokaMaker it is useful to separate generation of the mesh into a different script as demonstrated here. The method save_gs_mesh() can be used to save the resulting information for later use. This is done using and an HDF5 file through the h5py library.

save_gs_mesh(mesh_pts,mesh_lc,mesh_reg,coil_dict,cond_dict,'MANTA_mesh.h5')