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

extra tests ideas #34

Open
shimwell opened this issue Nov 19, 2021 · 10 comments
Open

extra tests ideas #34

shimwell opened this issue Nov 19, 2021 · 10 comments

Comments

@shimwell
Copy link
Member

Test that point coordinates are generated within the ranges expected.

This is tricky for random samples as the results change

Allow for a wide tolerance to account for random distributions

Perhaps fixing the seed in openmc could help, openmc has a settings.seed value that defaults to 1

@shimwell
Copy link
Member Author

testing the plotting routines ideas

check that plots result in file such as png files

check the axis ranges are correct

@LiamPattinson
Copy link
Contributor

Hi Jonathan, for the first point, would I be right in thinking that you're interested in testing that TokamakSource is generating RZ coordinates correctly?

@shimwell
Copy link
Member Author

That would be very nice, something that checks triangulation and elongation are correctly handled. What do you think @RemDelaporteMathurin ?

@RemDelaporteMathurin
Copy link
Member

Hi @shimwell @LiamPattinson

So I think there are several things here and maybe we need seperated issues to make it clearer.

The TokamakSource class has a method called sample_sources() which creates a bunch of random (R, Z) coordinates based on the plasma geometry parameters (radii, elongation, triangularity, etc.). I think that's what @shimwell is refering to.

def sample_sources(self):
"""Samples self.sample_size neutrons and creates attributes .densities
(ion density), .temperatures (ion temperature), .strengths
(neutron source density) and .RZ (coordinates)
"""
# create a sample of (a, alpha) coordinates
a = np.random.random(self.sample_size) * self.minor_radius
alpha = np.random.random(self.sample_size) * 2 * np.pi
# compute densities, temperatures, neutron source densities and
# convert coordinates
self.densities = self.ion_density(a)
self.temperatures = self.ion_temperature(a)
self.neutron_source_density = neutron_source_density(
self.densities, self.temperatures
)
self.strengths = self.neutron_source_density / sum(self.neutron_source_density)
self.RZ = self.convert_a_alpha_to_R_Z(a, alpha)

One way to test this is to 1) test the method convert_a_alpha_to_R_Z() 2) for several sets of parameters (radii, elongation, etc.) test that the sampled coordinates are all in the shell produced by the plasma boundary equations :
R = major_radius + a * cos(alpha + triangularity * sin(alpha) ) + shafranov_shift
Z = elongation * a * sin(alpha)

def convert_a_alpha_to_R_Z(self, a, alpha):

@LiamPattinson
Copy link
Contributor

Thanks @RemDelaporteMathurin and @shimwell, that's what I assumed the issue was about. I've managed to get such a test working, though with a few caveats:

  • It currently only tests that the points generated are contained within a box with coordinates:
    • lower left (major_radius - minor_radius, -minor_radius * elongation)
    • upper right (major_radius + minor_radius, +minor_radius * elongation)
  • It only confirms that the generated points are accurate for the tokamak parameters given in test_tokamak_source.py.

The first point is difficult to solve, as the plasma boundary is quite a complex shape to work with, but I might be able to constrain the test further with a bit more work. The second point should be quite easy to incorporate into my solution, as I'll just need to add a few more examples of tokamak geometries. Once I've done this I'll make a pull request.

@RemDelaporteMathurin
Copy link
Member

Thanks for this. I guess that works but doesn't test the triangularity.

Perhaps we can focus on testing convert_a_alpha_to_R_Z. An "easy" way to do it is to create an inverse function convert_R_Z_to_a_alpha and check that convert_a_alpha_to_R_Z(convert_R_Z_to_a_alpha(R_test, Z_test)) == R_test, Z_test

So to create that inverse function, "simply" inverse the relations I gave above:

R = major_radius + a * cos(alpha + triangularity * sin(alpha) ) + shafranov_shift Z = elongation * a * sin(alpha)

Here's an idea of what it should look like:
image

@LiamPattinson
Copy link
Contributor

I've tried looking at an inverse function, but I believe it can only ever be approximate as the a-alpha to RZ relations aren't bijective (at least according to "Tokamak D-T neutron source models for different plasma physics confinement modes", Fausser et al.). I believe I have an approximate solution working, but it'll take some further testing to make sure it's robust.

@RemDelaporteMathurin
Copy link
Member

It isn't bijective as is but if you constraint a to be positive than each R, Z couple corresponds to one unique (a, alpha) point doesn't it?

@LiamPattinson
Copy link
Contributor

I believe so, but the inversion may need to be performed numerically rather than analytically.

@RemDelaporteMathurin
Copy link
Member

Ah maybe. Well even an approximate is better than what we have currently I suppose :-)
Thanks!

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

No branches or pull requests

3 participants