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

Implement alternating division schemes between adjacent hexahedra and wedges #172

Merged
merged 11 commits into from
Nov 11, 2024

Conversation

connoramoreno
Copy link
Collaborator

@connoramoreno connoramoreno commented Nov 1, 2024

Modifies the source mesh workflow to alternate the scheme by which hexahedra and wedges are split into tetrahedra. The alternating schemes ensure that the faces of adjacent tetrahedra, but not belonging to the same hexahedron or wedge, match one another. This avoids gaps and overlaps between adjacent non-planar hexahedron and wedge faces. This alignment is ensured for adjacent wedge-wedge, wedge-hexahedron, and hexahedron-hexahedron pairs. Code changes are as follows:

  • Introduces alternate_scheme, toroidal_alt_scheme, and cfs_alt_scheme boolean parameters to control whether an alternate division scheme should be used for a given element
  • Introduces an alternate division scheme, in the form of MOAB canonical indices defining the tetrahedral division of a given element, for both hexahedra and wedges
  • Introduces checks to ensure the number of poloidal grid intervals and (conditionally) the number of toroidal grid intervals are even
  • Modifies naming convention of flux-coordinate indices, lists, etc. to be more intuitive
  • Modifies vertex indexing scheme to be more intuitive
  • Reduces toroidal extent of mesh in test_source_mesh unit tests

The alternate splitting schemes are illustrated below. Plots will follow to demonstrate expected behavior of total volume and total source strength as a function of mesh discretization.

(a)Screenshot 2024-11-01 at 2 59 13 PM
(b)Screenshot 2024-11-01 at 3 07 21 PM

Figure 1. Alternate schemes for adjacent hexahedra. (a) Original and (b) alternate.

(a)Screenshot 2024-11-01 at 3 24 55 PM
(b)Screenshot 2024-11-01 at 3 22 00 PM

Figure 2. Alternate schemes for adjacent wedges. (a) Original and (b) alternate.

Closes #168

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix @connoramoreno

parastell/source_mesh.py Outdated Show resolved Hide resolved
@connoramoreno
Copy link
Collaborator Author

connoramoreno commented Nov 3, 2024

Below are plots demonstrating that total source strength (in the form of fusion power, calculated for four periods even though only one period of the source mesh is modeled) and total mesh volume scale as expected with mesh discretization.

Expected behavior:

  • For increasing CFS discretization, total source strength converges to some value and total volume remains constant
  • For changing poloidal discretization, total source strength changes are small and trend similarly to those for total volume. Total volume converges to some value.
  • For changing toroidal discretization, total source strength changes are small and trend similarly to those for total volume. Total volume converges to some value.

(a) Screenshot 2024-11-03 at 9 08 51 AM
(b) Screenshot 2024-11-03 at 9 09 15 AM
Figure 1. Behavior of total source strength and volume as a function of CFS discretization. Numbers of poloidal and toroidal grid points are kept constant at 121 each. (a) Total source strength. Total relative change is 3.15%. (b) Total mesh volume. Total relative change is 0%.

(a) Screenshot 2024-11-03 at 9 09 05 AM
(b) Screenshot 2024-11-03 at 9 09 19 AM
Figure 2. Behavior of total source strength and volume as a function of poloidal discretization. Numbers of CFS and toroidal grid points are kept constant at 16 and 121, respectively. (a) Total source strength. Total relative change is 0.39%. (b) Total mesh volume. Total relative change is 0.41%.

(a) Screenshot 2024-11-03 at 9 09 10 AM
(b) Screenshot 2024-11-03 at 9 09 24 AM
Figure 3. Behavior of total source strength and volume as a function of toroidal discretization. Numbers of CFS and poloidal grid points are kept constant at 16 and 121, respectively. (a) Total source strength. Total relative change is 0.40%. (b) Total mesh volume. Total relative change is 0.23%.

@connoramoreno connoramoreno marked this pull request as ready for review November 3, 2024 15:33
Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

do we need to keep these different alternative scheme variables? For me it's hard to follow. If we require even numbers of poloidal voxels, I think there may be a cleaner way to do it.

@gonuke
Copy link
Member

gonuke commented Nov 3, 2024

Can we just determine the meshing scheme from whether s_idx + theta_idx + phi_idx is even or odd?

For the very first wedge of the first toroidal plane it's 0+0+0 =0 even. Then it alternates until we get to the last wedge which must be odd if we have an even number of poloidal voxels. Then the first hex on the next cfs layer is 1+0+0 =1 odd and alternates... and so on.

The first wedge on the next toroidal slice is 0+1+0 =1 odd - which is what we need it to be... and so on.

So within each hex generation method you can have

alternate_scheme = (s_idx + phi_idx + theta_idx) % 2

@gonuke
Copy link
Member

gonuke commented Nov 3, 2024

Could then have canonical ordering indexed in a list with index 0 and 1 and directly use the one you want indexed by the alternate scheme variable.

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Definitely simpler by making that red/black calculation be calculated in the methods that create the tets, but I have some questions on the choices of indexing.

In particular, I'm not sure (or don't remember) the motivation for theta_idx to go from [1,num_phi] instead of [0,num_phi-1]

parastell/source_mesh.py Outdated Show resolved Hide resolved
self._create_tet(vertex_ids)

def _create_tets_from_wedge(self, theta_idx, phi_idx):
"""Creates three tetrahedra from defined wedge.
(Internal function not intended to be called externally)

Arguments:
idx_list (list of int): list of wedge vertex indices.
theta_idx (int): index defining location along poloidal angle axis.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the stencil below. Maybe it's been this way for a while, but I don't see any points in this stencil at a s_idx=1 which I expect.
I'm also not sure why this goes from [1,num_phi] istead of [0,num_phi-1]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I agree that it's slightly confusing, and our indexing scheme could use some changes to make it more intuitive. The way we've defined things is that the vertex at the magnetic axis and those on the first closed flux surface all have a s_idx of 0. This is also why theta_idx begins at 1, to differentiate the first vertex on the first CFS from that on the magnetic axis.

It would make much more sense to have s_idx = 0 to always refer to the magnetic axis vertices, and s_idx = 1 refer to the first CFS. As such, we could then have theta_idx start from 0. I think I'll also change the naming convention from using to theta_idx and phi_idx to using poloidal_idx and toroidal_idx, respectively, to avoid confusion.

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

This is all definitely a lot easier to follow!!!

self._logger.error(e.args[0])
raise e

if angle == 360.0 and self._num_toroidal_pts % 2 != 1:
Copy link
Member

Choose a reason for hiding this comment

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

Later on you compare _toroidal_extent to 2 pi. It might make more sense to convert to radians before this test for consistency.

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Thanks for this important fix @connoramoreno

@gonuke gonuke merged commit 69fb5b6 into main Nov 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source mesh total source strength scaling incorrectly with mesh discretization
2 participants