Skip to content

Union surface and fix of focus system#2149

Merged
willend merged 32 commits intomainfrom
union_surface
Oct 28, 2025
Merged

Union surface and fix of focus system#2149
willend merged 32 commits intomainfrom
union_surface

Conversation

@mads-bertelsen
Copy link
Contributor

@mads-bertelsen mads-bertelsen commented Oct 27, 2025

Free-form text area

Please describe what your PR is adding in terms of features or bugfixes:

Adding surface physics to Union components, including

  • Refraction information can now be added to materials
  • When rays pass from one material to another (that both have the necessary information) they can refract / reflect (code and algorithm from Refractor.comp)
  • New class of components, surface_processes that describe effects on a surface, such as super-mirror reflectivity
  • Faces of geometries can have a list of surface processes attached

Fixed issues with focusing system

  • Now takes ray position into account, instead of focusing from geometry center
  • Processes can now request focusing while calculating cross section
  • Each material checks if they have any processes that require this
  • When master calculates cross section for a material that requires focusing then, a scattering location is chosen before
  • The total cross section for all processes and absorption is calculated
  • If a process that requires focusing while calculating cross section is chosen, that position is used
  • The weight is transformed to take the probability of scattering at the chosen spot into account

Development OS / boundary conditions

Please describe what OS you developed and tested your additions on, and if any special dependencies are required:

Developed and tested on OS X


PR Checklist for contributing to McStas/McXtrace

For a coherent and useful contribution to McStas/McXtrace, please fill in relevant parts of the checklist:

  • My contribution includes patches to an existing component file

    • I have used the mcdoc utility and rendered a reasonable documentation page for the component (please attach as screenshot in comments!)
    • I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?)
    • I have used the mctest utility to test one or more instruments making use of the component (please attach mcviewtest report as screenshot in comments)
    • I have used the mcrun -c-lint "linter" and followed advice to remove most / all warnings that are raised
  • My contribution includes patches to an existing instrument file

    • I have used the mcdoc utility and rendered a reasonable documentation page for the instrument (please attach as screenshot in comments!)
    • I have used the mctest utility to test the instrument (please attach mcviewtest report as screenshot in comments)
    • I have used the mcrun -c-lint "linter" and followed advice to remove most / all warnings that are raised
  • My contribution includes a new component file

    • I have ensured that naming of parameters are in the style of existing components. (Please check the McStas or McXtrace NOMENCLATURE docs.)
    • I have ensured that component parameters are in the usually units of McStas or McXtrace (SI + neutron/x-ray 'usual' units)
    • I have used the mcdoc utility and rendered a reasonable documentation page for the component (please attach as screenshot in comments!)
    • I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?)
    • I have included a corresponding example instrument and will fill in the new instrument section below
    • My new component is added within the contrib component category
  • My contribution includes a new instrument file

    • I have used the mcdoc utility and rendered a reasonable documentation page for the instrument (please attach as screenshot in comments!)
    • I have ensured that basic use of the instrument is OK (e.g. it compiles?)
    • ... and provided reasonable default parameters in that instrument that produce reasonable output
    • ... and maybe even added a %Example: line to describe expected behaviour
    • I have used the mcrun -c-lint "linter" and followed advice to remove most / all warnings that are raised
    • My new instrument is added within the examples hierarchy in a folder in the style of examples/ESS/New_stuff/New_stuff.instr
    • My new instrument has a new, unique filename, not clashing with existing example instruments
    • My new instrument requires a data/input file. If the datafile is specific for my instrument I have left it in the same example folder, but if general use I have placed it in the global data folder.
  • My work touches the code-generator in mccode/src

    • I have added reasoning and documentation for the change through an ADR record in our GRAMMAR section
    • I am attaching test output in the comments
  • My work touches / adds to the runtime lib code (.c,.h etc in multiple locations

    • I am have added reasoning and documentation for the change below
    • I am attaching test output in the comments
  • My PR is meant to fix a specific, existing issue

    • I have indicated the issue number here:
    • I have added documentation for the fix and possible side effects
  • My contribution contains something else

    • Explanation is added in free form text above or below the checklist

Refraction will be a special case always present (if information given), and general surface effects to follow.

Work in progress, not yet functional.
…Union_make_material

Using fresnels equations to calculate reflection probability.

Now only the closest intersection solution with the same surface_index is ignored.
  box
  sphere
  cylinder
  cone

but not mesh. The only surface effect currently available is the template,
this is a simple copy of mirror component with both table and normal
reflectivity input.
complex examples run without loosing any rays.

Template_surface and Mirror_surface do the same thing, the template
is available for a developer to start coding a surface process without
overwriting any other code. It contains help with getting started.
volumes works perfectly, though there are still issues in complex setups
such as guides where geometries overlap.
Refraction will be a special case always present (if information given), and general surface effects to follow.

Work in progress, not yet functional.
…Union_make_material

Using fresnels equations to calculate reflection probability.

Now only the closest intersection solution with the same surface_index is ignored.
  box
  sphere
  cylinder
  cone

but not mesh. The only surface effect currently available is the template,
this is a simple copy of mirror component with both table and normal
reflectivity input.
complex examples run without loosing any rays.

Template_surface and Mirror_surface do the same thing, the template
is available for a developer to start coding a surface process without
overwriting any other code. It contains help with getting started.
volumes works perfectly, though there are still issues in complex setups
such as guides where geometries overlap.
…or box and cylinder.

Added possibility to specify scattering length density directly in Union_make_material, and simplified memory structure to primarily store SLD instead of more variables used to calculate it.

Improved debug prints in Union_master and adopted use of SLD.
…section.

Processes can now report the need to do so, and in that case a point will be chosen.
If that process is selected, that point is used, and a weight transformation corrects for the probability of that position.

Also introduced control parameters to disable / enable refraction and reflection just like the Refractor component.
as the focus data need to be copied to each copy of the original volume.
Refraction will be a special case always present (if information given), and general surface effects to follow.

Work in progress, not yet functional.
…Union_make_material

Using fresnels equations to calculate reflection probability.

Now only the closest intersection solution with the same surface_index is ignored.
  box
  sphere
  cylinder
  cone

but not mesh. The only surface effect currently available is the template,
this is a simple copy of mirror component with both table and normal
reflectivity input.
complex examples run without loosing any rays.

Template_surface and Mirror_surface do the same thing, the template
is available for a developer to start coding a surface process without
overwriting any other code. It contains help with getting started.
volumes works perfectly, though there are still issues in complex setups
such as guides where geometries overlap.
…or box and cylinder.

Added possibility to specify scattering length density directly in Union_make_material, and simplified memory structure to primarily store SLD instead of more variables used to calculate it.

Improved debug prints in Union_master and adopted use of SLD.
…section.

Processes can now report the need to do so, and in that case a point will be chosen.
If that process is selected, that point is used, and a weight transformation corrects for the probability of that position.

Also introduced control parameters to disable / enable refraction and reflection just like the Refractor component.

Improved header.
as the focus data need to be copied to each copy of the original volume.
Validation of Mirror_surface as compared to Mirror component.
Model of Bispectral extraction from butterfly source using super-mirror coated Si blades.

Lowered the threshold for when new intersections should be calculated from velocity changes
less than 1E-5 to 1E-10 [m/s] in any direction.
@mads-bertelsen mads-bertelsen changed the title Union surface and fix of focus system (Do not merge yet) Union surface and fix of focus system Oct 28, 2025
@willend
Copy link
Contributor

willend commented Oct 28, 2025

All tests checks out, merging!

@willend willend closed this Oct 28, 2025
@willend willend reopened this Oct 28, 2025
@willend willend merged commit 3e4efb0 into main Oct 28, 2025
66 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.

2 participants

Comments