ToFuProject / tofu

Project for an open-source python library for synthetic diagnostics and tomography for Fusion devices
https://tofuproject.github.io/tofu/index.html
MIT License
72 stars 11 forks source link

Solid angle for multiple apertures - arbitrary points #653

Open Didou09 opened 2 years ago

Didou09 commented 2 years ago

Framework:

Suggestions & code structure:


# input options: 
    visibility = True / False
    return_vector = True / False

# initialize solid angle array with zeros
# (optional, if return_vector) initialize unit vector array with nans

# loop 1: on npts (observation points)

    # loop 2: on n1 (detectors)

        # test 1: sides
           check if point lies on the good side of the detector
           => stop if not

        # loop 3: on na (apertures)

            # `computation 1`:
               compute intersection between detector and all apertures as seen from point
               stop as soon as null is found (no intersection)

        # `computation 2`:
            compute the solid angle subtended by the intersection (fill the array that was initialized if non-zero)

       # computation 3 (optional, necessary if visibility or return_vector):
           compute the direction of photon emission: 
           the unit vector from the observation point towards the center of mass of the intersection polygon

        #` test 2`: visibility (optional, requires computation 3)
             check ray-tracing to make sure there is no obstacle between the observation point and the projection, on the detector surface, of the direction of photon emission (unit vector)
             => if no visibility, set solid angle to 0 and unit vector to nan

Code re-use:

Possible difficulties / discussion points:

Priorities:

--------- ---------------------------------------------------- ---------- --------------------- Priority name visibility return_unit_vector
1 compute_solid_angle_apertures_unitvectors() False True
2 compute_solid_angle_apertures_light() False False
3 compute_solid_angle_apertures_visibility() True False

The last combination (visibility = True and return_unit_vector=True) can be handled by re-using the first one and combining it with already-coded visibility checks.

Illustrations:

In the example below, we define three arbitrary 3d polygons, the square represents the detector, the other 2 are its associated apertures. The red lines indicate normal vectors.

drawing

And after computing the solid angle for all points on a fine sampling of the tokamak volume, we plot the area where the solid angle is non-zero as a grey area. We used visibility = True to detect the fact that the internal wall hides a fraction of the viewing volume of the detector.

drawing

This was done in 2014 using a very ill-coded version of the code that I think you should not use (the computation took ~2 days....).

Didou09 commented 2 years ago

Hi @obrejank , now the Issue653_SoliAngleArbitrary branch is up-to-date, you can start on it when you feel like it

The code you can work on is in tofu/geom/_GG.pyx (bottom of the file, routine compute_solid_angle_apertures_unitvectors())

I have prepared basci unit tests that are running and you can use then as you make progress to debug. They can be launched in 2 ways: from the terminal or from a python console.

From the terminal (with verbose and debugger option)

$ pytest tofu/tests/tests01_geom/test_02_compute.py -v -x --pdb

From inside a python console:

In [1]: import tofu as tf

In [2]: test = tf.tests.tests01_geom.test_02_compute.Test01_SolidAngles()

In [3]: test.setup()

In [4]: test.test01_solid_angle_apertures()

Thanks for your help!