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

Feature: polyhedral cross-section current sources and a general VIM formulation of 3-D magnetostatics #2703

Merged
merged 58 commits into from
Jan 24, 2024

Conversation

CoronelBuendia
Copy link
Contributor

@CoronelBuendia CoronelBuendia commented Oct 12, 2023

Linked Issues

Closes #1816 (almost)

This is useful for STEP, in that arbitrary cross-section conductors can be used, but I was interested in this stuff because I needed a general way to do volume integrals to calculate things like vector potential, and then self-inductance, etc. It's also potentially useful for stellarators, in that the conductors no longer need to be planar.

UPDATE (matti): As discussed 11/12 with the STEP team, at present we have only been successful in implementing a VIM method for arbitrary cross-sections with div J = 0 (equal end-cap angles). As it is possible to model their desired geometry using such a source term, I will update this feature branch to bring in an equal-angle VIM formulation with the necessary caveats. At a later date, and if a suitable implementation can be developed, we can replace it with a more general formulation.

Description

Adds PolyhedralPrismCurrentSource where you specify a set of x-z Coordinates rather than rectangular dimensions.

image
image

I've benchmarked results against the RectangularPrismCurrentSource, and it is a mixed bag:

  • For a simple source modelled with both approaches, I get the same results
  • For the Babic and Aykel paper verification test it fails spectacularly on both points at the moment, and I can't work out why.

More generally, the formulation does allow for arbitrary construction of conducting geometry, and we may want to provide a mesh interface for this volume integral approach

NOTE: RectangularPrismCurrentSource will stay alive for the foreseeable future. It's considerably faster. I have yet to fully JIT the polyhedral one because of reflected list issues, but I did performance benchmark a fully JIT-ed version of the polyhedral stuff for n=4 (dodging list reflection) and it is still much, much slower.

Interface Changes

Checklist

I confirm that I have completed the following checks:

  • Tests run locally and pass pytest tests --reactor
  • Code quality checks run locally and pass pre-commit run --from-ref develop --to-ref HEAD
  • Documentation built locally and checked sphinx-build -W documentation/source documentation/build

@CoronelBuendia CoronelBuendia added the magnetostatics Tasks relating to the magnetostatics module label Oct 12, 2023
@CoronelBuendia CoronelBuendia requested a review from a team as a code owner October 12, 2023 11:32
@CoronelBuendia CoronelBuendia changed the title WIP: Feature: polyhedral cross-section current sources and a general formulation of 3-D magnetostatics WIP: Feature: polyhedral cross-section current sources and a general VIM formulation of 3-D magnetostatics Oct 12, 2023
Copy link
Contributor

@je-cook je-cook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First run through, looks good gonna run the tests etc now

bluemira/magnetostatics/baseclass.py Outdated Show resolved Hide resolved
bluemira/magnetostatics/polyhedral_prism.py Outdated Show resolved Hide resolved
bluemira/magnetostatics/baseclass.py Outdated Show resolved Hide resolved
bluemira/magnetostatics/polyhedral_prism.py Show resolved Hide resolved
bluemira/magnetostatics/trapezoidal_prism.py Outdated Show resolved Hide resolved
Copy link
Contributor

@je-cook je-cook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the tests I'm happy

@sonarcloud
Copy link

sonarcloud bot commented Oct 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 33 Code Smells

No Coverage information No Coverage information
4.9% 4.9% Duplication

Copy link
Contributor

github-actions bot commented Dec 12, 2023

⚠️ Warning Report

Found 15 warnings.

All warnings (15)

On collect

  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_constraint_funcs' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.opt_tools' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_constraints' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/pkg_resources/__init__.py:2868: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('mpl_toolkits'). Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_problems' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.opt_problems' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.equilibria.opt_objectives' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.utilities.optimiser' is deprecated and will be removed in version 2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py:139: DeprecationWarning: The module 'bluemira.geometry.optimisation._optimisation_old' is deprecated and will be removed in v2.0.0. See https://bluemira.readthedocs.io/en/latest/optimisation/optimisation.html for documentation of the new optimisation module.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/pkg_resources/__init__.py:2868: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('sphinxcontrib'). Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages

On runtest

  • /home/runner/work/bluemira/bluemira/tests/builders/test_tf_coils.py:46: DeprecationWarning: RippleConstrainedLengthGOP API has changed, please specify how you want to constrain TF ripple by using one of the available RipplePointSelector classes. Defaulting to an EquispacedSelector with n_rip_points=3 for now.
  • /home/runner/work/bluemira/bluemira/eudemo/eudemo/tf_coils/tf_coils.py:338: DeprecationWarning: Argument 'separatrix' is deprecated, argument 'ripple_wire' is used instead.
  • /home/runner/work/bluemira/bluemira/bluemira/base/reactor.py:676: DeprecationWarning: Using kwarg 'dim' is no longer supported. Simply pass in the dimensions you would like to show, e.g. show_cad('xz')
  • /home/runner/miniconda3/envs/bluemira/lib/python3.8/site-packages/h5py/__init__.py:36: UserWarning: h5py is running against HDF5 1.14.3 when it was built against 1.14.2, this may cause problems

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 116 lines in your changes are missing coverage. Please review.

Comparison is base (a662f4c) 79.97% compared to head (97f6e28) 79.75%.

Files Patch % Lines
bluemira/magnetostatics/polyhedral_prism.py 51.42% 102 Missing ⚠️
bluemira/magnetostatics/baseclass.py 80.00% 10 Missing ⚠️
bluemira/magnetostatics/biot_savart.py 84.21% 3 Missing ⚠️
bluemira/magnetostatics/circuits.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2703      +/-   ##
===========================================
- Coverage    79.97%   79.75%   -0.23%     
===========================================
  Files          222      223       +1     
  Lines        24755    24986     +231     
===========================================
+ Hits         19799    19928     +129     
- Misses        4956     5058     +102     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@je-cook
Copy link
Contributor

je-cook commented Dec 13, 2023

Just fyi this warning needs to be fixed before merge:
image

@CoronelBuendia
Copy link
Contributor Author

Just fyi this warning needs to be fixed before merge: image

Yeah definitely. It's less trivial though, and I didn't want to do it until we decided to bite the bullet and accept the equal-angle limitation. Will get on it.

Copy link

sonarcloud bot commented Dec 14, 2023

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
1.0% Duplication on New Code

See analysis details on SonarCloud

@CoronelBuendia CoronelBuendia changed the title WIP: Feature: polyhedral cross-section current sources and a general VIM formulation of 3-D magnetostatics Feature: polyhedral cross-section current sources and a general VIM formulation of 3-D magnetostatics Jan 15, 2024
Copy link
Contributor

@je-cook je-cook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whole looks good. A couple of questions. I'll add the test plotting stuff as its minor

tests/magnetostatics/test_polyhedral_prism.py Outdated Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Outdated Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Outdated Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Outdated Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Outdated Show resolved Hide resolved
tests/magnetostatics/test_circuits.py Outdated Show resolved Hide resolved
bluemira/magnetostatics/polyhedral_prism.py Show resolved Hide resolved
bluemira/magnetostatics/polyhedral_prism.py Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Show resolved Hide resolved
tests/magnetostatics/test_polyhedral_prism.py Show resolved Hide resolved
@je-cook
Copy link
Contributor

je-cook commented Jan 18, 2024

also there is still an extra warning lying about: /home/runner/work/bluemira/bluemira/bluemira/magnetostatics/polyhedral_prism.py:323: NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (Array(float64, 1, 'C', False, aligned=True), Array(float64, 1, 'A', False, aligned=True)

@je-cook
Copy link
Contributor

je-cook commented Jan 18, 2024

and possibly a rebase to bring in the new ruff config

CoronelBuendia and others added 17 commits January 24, 2024 11:35
* add baseclass

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* add tests

* addplot test

* DRY

* remove unused zip

* rebase and fix circuit tests
…2751)

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* DRY

* 2d ring test with plot and point

* added multiple points around circuit for single point test

* tidy/remove commented lines

* add tests

* remove duplication from rebase and alterations to TestPolyhedral2DRing

* reduced discretisation to lower run time and tolerance for 2DRing test

* addded more points for below coil and changed method of array comparison

* marked TestPolyhedral2DRing as longrun

* reshuffle tests

* reduce runtime and numpy asserts

---------

Co-authored-by: CoronelBuendia <matti.coleman@gmail.com>
* add some text

* add example python doc

* add pic

* fix doc

* added python doc, pic and text

* equal angles examples

* modify picture

* add note to documentation about limitations

* missing word

* Add cubic term that was missing in B field equation

---------

Co-authored-by: Jonathan Matthews <jonathan.matthews@ukaea.uk>
Co-authored-by: kj5248 <115085094+kj5248@users.noreply.github.com>
* make functions private

* add __all__

* add note on kernels

* first pass JITted source geometry

* implement fabbri

* reshuffle a little

* clean up and JIT utilities

* first pass JIT bottura

* docstring

* make arrays contiguous

---------

Co-authored-by: Matti <matti.coleman@ukaea.uk>
Copy link

sonarcloud bot commented Jan 24, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
1.0% Duplication on New Code

See analysis details on SonarCloud

@je-cook je-cook merged commit edc3750 into develop Jan 24, 2024
3 of 4 checks passed
@je-cook je-cook deleted the matti/polyhedral-prism-fabri branch January 24, 2024 12:01
OceanNuclear pushed a commit that referenced this pull request Feb 20, 2024
…ormulation of 3-D magnetostatics (#2703)

* baseclasses and housekeeping

* pause because PROCESS

* 6 hours

* write asserts

* vector potential

* add failing babic test

* add singularity protection

* add singularity protection

* typing

* add plotting to Babic Aykel test

* baseclass shenanigans

* DRY mixin

* working arbirtrary geometry

* clean up

* clean up

* kill some list reflection but still not fully JIT

* fix signatures

* add triangle test

* rotate midpoints too

* comments and clearer code

* add some docstring equations

* more docstring equations

* parametrise babic aykel test

* more source doucmentation

* parametrise maths test

* remove useless baseclass and make everything private

* make more stuff private

* make stuff private everywhere

* better file docstring

* biot savart private points

* fix some polyhedral tests

* add trapezoidal test

* add polyhedral test... that fails too

* add polyhedral test... that fails too

* add polyhedral test... that fails too

* add temporary sanity check

* add geometry test

* added test to check whether combined shape matching single shape (#2718)

* added test to check whether combined shape matching single shape

* fix duplication

* add teardown method for each class

* Add an alternative polyhedral VIM formulation (#2731)

* working bottura

* get rid of some minuses

* kernel start

* docstrings

* ruff

* make tests better written

* more maths

* fix API documentation

* Add `ArbitraryPlanarPolyhedralXSCircuit` (#2704)

* add baseclass

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* add tests

* addplot test

* DRY

* remove unused zip

* rebase and fix circuit tests

* fix tests and add error for angles

* better error

* add vector potential flux test

* remove sanity check

* docstring change

* copyright and remove tools

* sonarcloud bug

* Add test using ArbitraryPlanarPolyhedralXSCircuit for a 2D ring coil (#2751)

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* DRY

* 2d ring test with plot and point

* added multiple points around circuit for single point test

* tidy/remove commented lines

* add tests

* remove duplication from rebase and alterations to TestPolyhedral2DRing

* reduced discretisation to lower run time and tolerance for 2DRing test

* addded more points for below coil and changed method of array comparison

* marked TestPolyhedral2DRing as longrun

* reshuffle tests

* reduce runtime and numpy asserts

---------

Co-authored-by: CoronelBuendia <matti.coleman@gmail.com>

* `PolyhedralPrismCurrentSource` documentation (#2705)

* add some text

* add example python doc

* add pic

* fix doc

* added python doc, pic and text

* equal angles examples

* modify picture

* add note to documentation about limitations

* missing word

* Add cubic term that was missing in B field equation

---------

Co-authored-by: Jonathan Matthews <jonathan.matthews@ukaea.uk>
Co-authored-by: kj5248 <115085094+kj5248@users.noreply.github.com>

* code smells

* JIT `PolyhedralPrism` even more, and remove reflected lists (#2874)

* make functions private

* add __all__

* add note on kernels

* first pass JITted source geometry

* implement fabbri

* reshuffle a little

* clean up and JIT utilities

* first pass JIT bottura

* docstring

* make arrays contiguous

---------

Co-authored-by: Matti <matti.coleman@ukaea.uk>

* plt show/close is automatic now

* 🎨 Ruff

* make tests check symmetry of field

* resolve numba warning

* trigger ruff

* run precommit

* fix sonarcloud issue

---------

Co-authored-by: kj5248 <115085094+kj5248@users.noreply.github.com>
Co-authored-by: Jonathan Matthews <jonathan.matthews@ukaea.uk>
Co-authored-by: Matti <matti.coleman@ukaea.uk>
Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
Co-authored-by: james <james.cook1@ukaea.uk>
OceanNuclear pushed a commit that referenced this pull request Jun 17, 2024
…ormulation of 3-D magnetostatics (#2703)

* baseclasses and housekeeping

* pause because PROCESS

* 6 hours

* write asserts

* vector potential

* add failing babic test

* add singularity protection

* add singularity protection

* typing

* add plotting to Babic Aykel test

* baseclass shenanigans

* DRY mixin

* working arbirtrary geometry

* clean up

* clean up

* kill some list reflection but still not fully JIT

* fix signatures

* add triangle test

* rotate midpoints too

* comments and clearer code

* add some docstring equations

* more docstring equations

* parametrise babic aykel test

* more source doucmentation

* parametrise maths test

* remove useless baseclass and make everything private

* make more stuff private

* make stuff private everywhere

* better file docstring

* biot savart private points

* fix some polyhedral tests

* add trapezoidal test

* add polyhedral test... that fails too

* add polyhedral test... that fails too

* add polyhedral test... that fails too

* add temporary sanity check

* add geometry test

* added test to check whether combined shape matching single shape (#2718)

* added test to check whether combined shape matching single shape

* fix duplication

* add teardown method for each class

* Add an alternative polyhedral VIM formulation (#2731)

* working bottura

* get rid of some minuses

* kernel start

* docstrings

* ruff

* make tests better written

* more maths

* fix API documentation

* Add `ArbitraryPlanarPolyhedralXSCircuit` (#2704)

* add baseclass

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* add tests

* addplot test

* DRY

* remove unused zip

* rebase and fix circuit tests

* fix tests and add error for angles

* better error

* add vector potential flux test

* remove sanity check

* docstring change

* copyright and remove tools

* sonarcloud bug

* Add test using ArbitraryPlanarPolyhedralXSCircuit for a 2D ring coil (#2751)

* arbitrary planar polyhedral

* arbitrary planar polyhedral proper

* DRY

* 2d ring test with plot and point

* added multiple points around circuit for single point test

* tidy/remove commented lines

* add tests

* remove duplication from rebase and alterations to TestPolyhedral2DRing

* reduced discretisation to lower run time and tolerance for 2DRing test

* addded more points for below coil and changed method of array comparison

* marked TestPolyhedral2DRing as longrun

* reshuffle tests

* reduce runtime and numpy asserts

---------

Co-authored-by: CoronelBuendia <matti.coleman@gmail.com>

* `PolyhedralPrismCurrentSource` documentation (#2705)

* add some text

* add example python doc

* add pic

* fix doc

* added python doc, pic and text

* equal angles examples

* modify picture

* add note to documentation about limitations

* missing word

* Add cubic term that was missing in B field equation

---------

Co-authored-by: Jonathan Matthews <jonathan.matthews@ukaea.uk>
Co-authored-by: kj5248 <115085094+kj5248@users.noreply.github.com>

* code smells

* JIT `PolyhedralPrism` even more, and remove reflected lists (#2874)

* make functions private

* add __all__

* add note on kernels

* first pass JITted source geometry

* implement fabbri

* reshuffle a little

* clean up and JIT utilities

* first pass JIT bottura

* docstring

* make arrays contiguous

---------

Co-authored-by: Matti <matti.coleman@ukaea.uk>

* plt show/close is automatic now

* 🎨 Ruff

* make tests check symmetry of field

* resolve numba warning

* trigger ruff

* run precommit

* fix sonarcloud issue

---------

Co-authored-by: kj5248 <115085094+kj5248@users.noreply.github.com>
Co-authored-by: Jonathan Matthews <jonathan.matthews@ukaea.uk>
Co-authored-by: Matti <matti.coleman@ukaea.uk>
Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
Co-authored-by: james <james.cook1@ukaea.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
magnetostatics Tasks relating to the magnetostatics module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: arbitrary cross section current sources
3 participants