Skip to content

Commit cc87f93

Browse files
authored
Fix bug in VMECIO.write_vmec_input (#1667)
- Adds missing `&END` to the input file created from `desc.vmec.VMECIO.write_vmec_input`, and adds automatically generated header file showing date the input file was created. Resolves #1653
2 parents de4f853 + 78f256d commit cc87f93

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ Changelog
22
=========
33

44
New Features
5-
65
- Adds a new utility function ``desc.compat.contract_equilibrium`` which takes in an ``Equilibrium`` object and an argument ``inner_rho``, and returns a new ``Equilibrium`` with original ``Equilibrium``'s ``inner_rho`` flux surface as its boundary.
76
Optionally can also contract the profiles of the original ``Equilibrium`` so that the new ``Equilibrium``'s profiles match the original's in real space.
87
- Adds second-order NAE constraints, accessible by passing ``order=2`` to ``desc.objectives.get_NAE_constraints``.
8+
- Adds automatically generated header file showing date the input file was created with `desc.vmec.VMECIO.write_vmec_input`
99

1010

1111
v0.14.1
@@ -15,6 +15,7 @@ Bug Fixes
1515
- Fixes bug in ``desc.vmec.VMECIO.write_vmec_input`` for current-constrained equilibria, where DESC was incorrectly writing the ``s**0`` mode, where VMEC actually assumes it is zero and starts at the ``s**1`` (which is different than the usual convention VMEC uses for its current profile when it uses the current derivative, where it starts with the ``s**0`` mode).
1616
- Fixes error that occurs when using the default grid for ``SplineXYZCoil`` in an optimization.
1717
- Fixes bug in ``desc.coils.CoilSet.save_in_makegrid_format`` for ``CoilSet`` objects with ``sym=True`` or ``NFP>1``
18+
- Adds missing `&END` to the input file created from `desc.vmec.VMECIO.write_vmec_input`
1819

1920
v0.14.0
2021
-------

desc/vmec.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import io
44
import os
55
import warnings
6+
from datetime import datetime
67

78
import matplotlib.pyplot as plt
89
import numpy as np
910
from netCDF4 import Dataset, stringtochar
1011
from scipy import integrate, interpolate, optimize
1112
from scipy.constants import mu_0
1213

14+
import desc
1315
from desc.basis import DoubleFourierSeries
1416
from desc.compat import ensure_positive_jacobian
1517
from desc.equilibrium import Equilibrium
@@ -1432,7 +1434,7 @@ def read_vmec_output(cls, fname):
14321434
return vmec_data
14331435

14341436
@classmethod
1435-
def write_vmec_input(cls, eq, fname, header="", **kwargs): # noqa: C901
1437+
def write_vmec_input(cls, eq, fname, header=None, **kwargs): # noqa: C901
14361438
"""Write a VMEC input file for an equivalent DESC equilibrium.
14371439
14381440
Parameters
@@ -1455,7 +1457,17 @@ def write_vmec_input(cls, eq, fname, header="", **kwargs): # noqa: C901
14551457
else:
14561458
f = fname
14571459
f.seek(0)
1458-
1460+
if header is None:
1461+
now = datetime.now()
1462+
date = now.strftime("%m/%d/%Y")
1463+
time = now.strftime("%H:%M:%S")
1464+
# auto header
1465+
header = (
1466+
" This VMEC input file was auto generated in DESC"
1467+
+ f" version {desc.__version__} from a\n"
1468+
+ "! DESC Equilibrium using the method VMECIO.write_vmec_input\n"
1469+
+ "! on {} at {}.\n".format(date, time)
1470+
)
14591471
f.write("! " + header + "\n")
14601472
f.write("&INDATA\n")
14611473

@@ -1635,7 +1647,8 @@ def write_vmec_input(cls, eq, fname, header="", **kwargs): # noqa: C901
16351647
+ f" ZBS({n:3.0f},{m:3.0f}) = {zbs:+14.8E}\n"
16361648
)
16371649

1638-
f.write("/")
1650+
f.write("/\n")
1651+
f.write("&END")
16391652
f.close()
16401653
return None
16411654

0 commit comments

Comments
 (0)