From f9e0dd36de7e70a7a24864b7e5a7bc43251ef659 Mon Sep 17 00:00:00 2001 From: Clair Mould <86794332+clmould@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:56:01 +0000 Subject: [PATCH 1/2] add toroidal harmonics approx functions and examples --- .../toroidal_harmonics_approx_functions.py | 86 +++++++++ ...single_wire_field_toroidal_harmonics.ex.py | 165 ++++++++++++++++++ ...nics_component_function_verification.ex.py | 121 +++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 bluemira/equilibria/optimisation/harmonics/toroidal_harmonics_approx_functions.py create mode 100644 examples/equilibria/single_wire_field_toroidal_harmonics.ex.py create mode 100644 examples/equilibria/toroidal_harmonics_component_function_verification.ex.py diff --git a/bluemira/equilibria/optimisation/harmonics/toroidal_harmonics_approx_functions.py b/bluemira/equilibria/optimisation/harmonics/toroidal_harmonics_approx_functions.py new file mode 100644 index 0000000000..0538173b89 --- /dev/null +++ b/bluemira/equilibria/optimisation/harmonics/toroidal_harmonics_approx_functions.py @@ -0,0 +1,86 @@ +# 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 + +""" +A collection of functions used to approximate toroidal harmonics. +""" + +from math import factorial + +import numpy as np +from scipy.special import gamma, poch + + +def f_hypergeometric(a, b, c, z, n_max): + """Evaluates the hypergeometric power series up to n_max. + + .. math:: + F(a, b; c; z) = \\sum_0^{n_max} \\frac{(a)_{s} (b)_{s}}{Gamma(c + s) s!} z^{s} + + See https://dlmf.nist.gov/15.2#E2 and https://dlmf.nist.gov/5.2#iii for more + information. + """ + F = 0 + for s in range(n_max + 1): + F += (poch(a, s) * poch(b, s)) / (gamma(c + s) * factorial(s)) * z**s + return F + + +def my_legendre_p(lam, mu, x, n_max=20): + """Evaluates the associated Legendre function of the first kind of degree lambda and order + minus mu as a function of x. See https://dlmf.nist.gov/14.3#E18 for more information. + + TODO check domain of validity? Assumed validity is 1 Date: Mon, 28 Oct 2024 16:12:52 +0000 Subject: [PATCH 2/2] fix title --- examples/equilibria/single_wire_field_toroidal_harmonics.ex.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/equilibria/single_wire_field_toroidal_harmonics.ex.py b/examples/equilibria/single_wire_field_toroidal_harmonics.ex.py index 6acfd1fa33..0ed27d366e 100644 --- a/examples/equilibria/single_wire_field_toroidal_harmonics.ex.py +++ b/examples/equilibria/single_wire_field_toroidal_harmonics.ex.py @@ -25,8 +25,7 @@ """ # %% [markdown] -# # Example of calculating the flux solution due to a single wire as a sum of toroidal -# harmonics +# # Example of calculating the flux solution due to a single wire as a sum of toroidal harmonics # %% [markdown] # ### Imports