-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy path__main__.py
More file actions
92 lines (76 loc) · 2.92 KB
/
Copy path__main__.py
File metadata and controls
92 lines (76 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Main command line interface to DESC for solving fixed boundary equilibria."""
import sys
from desc.input_reader import InputReader
def main(cl_args=sys.argv[1:]):
"""Run the main DESC code from the command line.
Reads and parses user input from command line, runs the code,
and prints and plots the resulting equilibrium.
"""
ir = InputReader(cl_args=cl_args)
if ir.args.version:
return
import desc
if ir.args.verbose:
print(desc.BANNER)
import matplotlib.pyplot as plt
from desc.backend import print_backend_info
from desc.equilibrium import EquilibriaFamily, Equilibrium
from desc.plotting import plot_section, plot_surfaces
if ir.args.verbose:
print_backend_info()
print("Reading input from {}".format(ir.input_path))
print("Outputs will be written to {}".format(ir.output_path))
inputs = ir.inputs
if (
len(inputs) == 1
and (inputs[-1]["pres_ratio"] is None)
and (inputs[-1]["bdry_ratio"] is None)
):
eq = Equilibrium(**inputs[-1], check_kwargs=False, ensure_nested=False)
equil_fam = EquilibriaFamily.solve_continuation_automatic(
eq,
objective=inputs[-1]["objective"],
optimizer=inputs[-1]["optimizer"],
pert_order=inputs[-1]["pert_order"],
ftol=inputs[-1]["ftol"],
xtol=inputs[-1]["xtol"],
gtol=inputs[-1]["gtol"],
maxiter=inputs[-1]["maxiter"],
verbose=ir.args.verbose,
checkpoint_path=ir.output_path,
)
else:
# initialize
equil_fam = EquilibriaFamily(inputs)
# check vmec path input
if ir.args.guess is not None:
if ir.args.verbose:
print("Initial guess from {}".format(ir.args.guess))
equil_fam[0].set_initial_guess(ir.args.guess)
# solve equilibrium
equil_fam.solve_continuation(
objective=inputs[0]["objective"],
optimizer=inputs[0]["optimizer"],
pert_order=[inp["pert_order"] for inp in inputs],
ftol=[inp["ftol"] for inp in inputs],
xtol=[inp["xtol"] for inp in inputs],
gtol=[inp["gtol"] for inp in inputs],
maxiter=[inp["maxiter"] for inp in inputs],
verbose=ir.args.verbose,
checkpoint_path=ir.output_path,
)
if ir.args.plot > 1:
for i, eq in enumerate(equil_fam[:-1]):
print("Plotting solution at step {}".format(i + 1))
_ = plot_surfaces(eq)
plt.show()
_ = plot_section(eq, "|F|_normalized", log=True)
plt.show()
if ir.args.plot > 0:
print("Plotting final solution")
_ = plot_surfaces(equil_fam[-1])
plt.show()
_ = plot_section(equil_fam[-1], "|F|_normalized", log=True)
plt.show()
if __name__ == "__main__": # pragma: no cover
main(sys.argv[1:])