Saving To VMEC-Formatted Output

[1]:
import sys
import os

sys.path.insert(0, os.path.abspath("."))
sys.path.append(os.path.abspath("../../"))
[2]:
%matplotlib inline

import desc.io  # used for loading and saving data

# used to visualize the DESC results
from desc.plotting import plot_surfaces, plot_section

# used to save equilibrium objects as VMEC-formatted .nc files
from desc.vmec import VMECIO
DESC version 0.7.2+319.g66640f23.dirty,using JAX backend, jax version=0.2.25, jaxlib version=0.1.76, dtype=float64
Using device: CPU, with 22.94 GB available memory

In this notebook, we have just ran python -m desc tests/inputs/SOLOVEV in the main DESC directory, so we now have the DESC results file tests/inputs/SOLOVEV_output.h5. Now we load in the solved equilibrium. The results are stored in an EquilibriaFamily object, which is basically a list of equilibria from the first initial guess up until the final solved equilibrium. We will just extract the final solved equilibrium using the [-1] (The EquilibriaFamily object can be indexed like a list).

[3]:
# the ../.. are just because this notebook is located in DESC/docs/notebooks
eq = desc.io.load(load_from="../../desc/examples/SOLOVEV_output.h5")[-1]

We can look at the final flux surfaces using the plot_surfaces function, and the final normalized force error with the plot_section function, both from desc.plotting:

[4]:
plot_surfaces(eq);
../_images/notebooks_Saving_Equilibria_in_VMEC_Format_6_0.png
[5]:
# we want to plot the magnitude of the force error |F|, and we want it shown normalized by the pressure gradient
plot_section(eq, name="|F|", norm_F=True, log=True);
../_images/notebooks_Saving_Equilibria_in_VMEC_Format_7_0.png

To save the equilibrium in a VMEC-formatted .nc file, we use the VMECIO class we imported from desc.vmec. This class will convert the quantities defining the equilibrium from DESC coordinates to VMEC equivalents.

[6]:
VMECIO.save(eq, "./SOLOVEV_output.nc")
Saving parameters
Saving R
Saving Z
Saving lambda
Saving Jacobian
Saving |B|
Saving B^theta
Saving B^zeta
Saving B_psi
Saving B_theta
Saving B_zeta
Saving J^theta
Saving J^zeta

We now have a file SOLOVEV_output.nc which is the equivalent Equilibrium solution in the VMEC coordinates and data format. We can now treat it as any other VMEC .nc file. For example, we can use our VMEC comparison tools to compare the two files now, such as comparing the flux surfaces using VMECIO.plot_vmec_comparison (which unsurprisingly are the same):

[7]:
vmec_formatted_eq_file = "./SOLOVEV_output.nc"
VMECIO.plot_vmec_comparison(eq, vmec_formatted_eq_file);
../_images/notebooks_Saving_Equilibria_in_VMEC_Format_11_0.png