Skip to content

Commit

Permalink
Equilibria analysis (#3298)
Browse files Browse the repository at this point in the history
* 🎨 Small cleanup

* 🚧 Initial structure
  • Loading branch information
je-cook committed Jun 28, 2024
1 parent 79157d1 commit fe1191a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
33 changes: 33 additions & 0 deletions bluemira/equilibria/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2021-present M. Coleman, J. Cook, F. Franza
# SPDX-FileCopyrightText: 2021-present I.A. Maione, S. McIntosh
# SPDX-FileCopyrightText: 2021-present J. Morris, D. Short
#
# SPDX-License-Identifier: LGPL-2.1-or-later
"""Equilibria and Equilibria optimisation analysis tools"""

from __future__ import annotations

Check warning on line 8 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L8

Added line #L8 was not covered by tests

from typing import TYPE_CHECKING

Check warning on line 10 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L10

Added line #L10 was not covered by tests

if TYPE_CHECKING:
from bluemira.equilibria.equilibrium import MHDState
from bluemira.equilibria.optimisation.problem.base import CoilsetOptimisationProblem


class EqAnalysis:

Check warning on line 17 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L17

Added line #L17 was not covered by tests
"""Equilibria analysis toolbox"""

def __init__(self, eq: MHDState):
self._eq = eq

Check warning on line 21 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L20-L21

Added lines #L20 - L21 were not covered by tests

def plot(self):

Check warning on line 23 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L23

Added line #L23 was not covered by tests
"""Plot equilibria"""
return self.eq.plot()

Check warning on line 25 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L25

Added line #L25 was not covered by tests


class COPAnalysis(EqAnalysis):

Check warning on line 28 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L28

Added line #L28 was not covered by tests
"""Coilset Optimisation Problem analysis toolbox"""

def __init__(self, cop: CoilsetOptimisationProblem):
super().__init__(cop.eq)
self._cop = cop

Check warning on line 33 in bluemira/equilibria/analysis.py

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L31-L33

Added lines #L31 - L33 were not covered by tests
11 changes: 7 additions & 4 deletions bluemira/equilibria/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,9 @@ def from_eqdsk(
filename=filename,
)

def to_dict(self, qpsi_calcmode: int = 0) -> dict[str, Any]:
def to_dict(
self, qpsi_calcmode: int | QpsiCalcMode = QpsiCalcMode.NO_CALC
) -> dict[str, Any]:
"""
Creates dictionary for equilibrium object, in preparation for saving
to a file format
Expand Down Expand Up @@ -1013,14 +1015,15 @@ def to_eqdsk(
header: str = "BP_equilibria",
directory: str | None = None,
filetype: str = "json",
qpsi_calcmode: int = 0,
qpsi_calcmode: int | QpsiCalcMode = QpsiCalcMode.NO_CALC,
**kwargs,
):
"""
Writes the Equilibrium Object to an eqdsk file
"""
if "eqdsk" in filetype and qpsi_calcmode == 0:
qpsi_calcmode = 2
qpsi_calcmode = QpsiCalcMode(qpsi_calcmode)
if "eqdsk" in filetype and qpsi_calcmode is QpsiCalcMode.NO_CALC:
qpsi_calcmode = QpsiCalcMode.ZEROS

super().to_eqdsk(
self.to_dict(qpsi_calcmode),
Expand Down

0 comments on commit fe1191a

Please sign in to comment.