Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equilibria analysis #3298

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"""

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

View check run for this annotation

Codecov / codecov/patch

bluemira/equilibria/analysis.py#L6

Added line #L6 was not covered by tests

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 @@ -914,7 +914,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 @@ -999,14 +1001,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