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

Fix up for modern Nim, add comment about beamline #22

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

Vindaar
Copy link
Collaborator

@Vindaar Vindaar commented Jun 16, 2023

Makes it compile on modern Nim and comments on the LLNL beamline. In addition one can now hand a suffix that will be added to the axion image CSV and plot files.

Also makes it generate a CSV file for the differential flux.

Finally, the multithreading is taken out for now, because on modern Nim it seems to cause a segfault. The code is fast enough for the required statistics for the time being and I don't feel like debugging the issue.

edit:
Also updates the LLNL reflectivity generation tool to support generating the data in the ranges as required by REST.

To generate the correct file run:

./llnl_layer_reflectivity \
    --numEnergy 500 \
    --angleMax 9.0.° \
    --numAngle 901 \
    --outfile llnl_layer_reflectivities_rest.h5 \
    --outpath /path/to/foo

The HDF5 file then needs to be converted to the raw binary format. This can be done with the following snippet utilizing nio (https://github.com/c-blake/nio):

import nimhdf5, strutils, sequtils, arraymancer
import nio
const path = "/home/basti/org/resources/llnl_layer_reflectivities_rest.h5"
let h5f = H5open(path, "r")
h5f.visit_file()
let grp = h5f["/".grp_str]
for dset in grp:
  echo dset.name, " of shape ", dset.shape
  if "Reflectivity" in dset.name:
    let data = toTensor(h5f[dset.name, float]).asType(float32) # convert to float32
      .reshape(dset.shape)
      .transpose # transpose our data
    echo data.shape
    let dataS = data.toSeq2D
    echo dataS.shape
    # convert to seq[array]
    var dataA = newSeq[array[901, float32]](500)
    for i in 0 ..< dataS.len:
      copyMem(dataA[i][0].addr, dataS[i][0].addr, 901 * sizeof(float32))

    let name = dset.name
    dataA.save "/tmp/" & name
    
discard h5f.close()  

(Adjust the PATH as needed of course). I don't add this code to this repostiory, as it is a bit out of scope and this is just one possible implementation. I don't expect anyone else to actually use this approach anyway.

IMPORTANT: While implementing multilayer reflectivity coatings in xrayAttenuation I've realized that I've been using DarpanX wrong. The d_min and d_max values need to be handed to it in Ångström instead of nano meters. Also their code is a mess, so I'm going to finish the multilayer code and then we compute it ourselves.

Vindaar added 7 commits June 14, 2023 11:08
- almostEqual now leads to an ambiguous identifier error for some
reason
- the import of `parsetoml` suddenly breaks the `mutate` formulas due
to its definition of `{}`
Something broke, using weave on modern Nim causes segfaults. The code
is fast enough nowadays to not really need serious multithreading for
most applications. We'll fix it in the future.
This allows to run the code with the ranges required by our code or
for REST.

To generate the file for our code, run without arguments. For REST run
via

```sh
./llnl_layer_reflectivity \
    --numEnergy 500 \
    --angleMax 9.0.° \
    --numAngle 901 \
    --outfile llnl_layer_reflectivities_rest.h5 \
    --outpath /path/to/foo
```

This still needs to be converted to raw binary files.
Vindaar added 22 commits June 18, 2023 16:56
Sigh, the "Pt/C" refers to C on top of Pt and not the other way
around. :(
Oops, I wasn't consciously aware that this change wasn't done
before. I think I did that locally at some point and forgot to commit it?
Due to large possible variation, user might want to adjust this
DarpanX needs Ångström instead of nano meters as inputs...
The X-ray source can now also be used together with the Sun as an
emission source. The idea is to be able to use the geometric
properties as the Sun as a source, but use a fixed energy instead of
also sampling the energy.

This is the basis for computing the effective area for a realistic
emission model.

The effective area scan walks all given input energies and computes
the mean of the photon weights after tracing. For that all additional
factors (conversion probability, detector window, absorption) are
ignored of course and only the telescope reflectivity (and obv. loss
of X-rays completely) are included.
Instead of Pt/C use C/Pt (correct order!) and use Ångström instead of
nano meters for the layer thicknesses.
The numbers previously used were accidentally the numbers of how
many *layers each shell coating* has!!
This plot is informative, because it should reflect the area of each
shell (for a fully illuminated bore)
This is not needed generally when one wants to use a generic X-ray
source. Only if one wants to do some acceptance studies etc
Vindaar added 10 commits August 12, 2023 12:31
The previous distance was the distance from the coordinate system
origin, which is pretty useless.
This is how I noticed the sampling bug in the new raytracer.
Fixes the bug I uncovered when writing TrAXer.
The CSVs were also written to the output path. But it makes more sense
to write only them to outpath. For the plots we now have a `plotPath`.

The input comes from `resources` (the solar model file)
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.

1 participant