Skip to content

Magnetic crystal updates - #3106

Draft
ebknudsen wants to merge 11 commits into
mccode-dev:mainfrom
ebknudsen:magnetic_crystal_updates
Draft

ebknudsen wants to merge 11 commits into
mccode-dev:mainfrom
ebknudsen:magnetic_crystal_updates

Conversation

@ebknudsen

@ebknudsen ebknudsen commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Free-form text area

WIP and experimental do not merge yet!

These are some updated to the magnetic single crystal component

  1. fixes some potential memory leaks
  2. fixes some cosemtics such as error messages referring to Single_crystal
  3. do in fact sort the reflection list according to q - instead of just hoping it is
  4. add info in header about expected format of the atom_list. (this is subject to change again if we move to support .cif

Declaration of use of AI-tools

  • Some edits have been created with Mistral

Development OS / boundary conditions

Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
This is tested on Ubuntu 26.04 through WSL


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 mccode-clangformat tool to apply the standard McCode component indentation scheme
    • 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

ebknudsen and others added 10 commits October 30, 2026 10:47
…e in diagnostics

Rename 7 diagnostic messages (read_hkl_data, INITIALIZE, TRACE, FINALLY) that
referred to the parent component Single_crystal, and drop a stray extra
hkl_info.sigma_i argument from the 'incoherent elastic scattering only' printf.
- Allocate the 4-channel structure-factor scratch array f_ once on the heap
  instead of per candidate hkl, and free it after the generation loop
  (its contents are copied into list[i].f, so a single reused allocation
  also scales to ~1e6 reflections).
- Table_Free(&atoms) after use of the parsed atom table.
- Free the reflection list, scratch array and atom table on all
  early-error returns (alloc failures, anisotropic-mosaic abort, tau_list OOM).
- Use a temporary pointer for the list realloc so the original block is
  not lost on failure.
read_hkl_data now returns 0 on success (including the valid no-atom-file,
incoherent-only case) and -1 on all errors (file read, allocation
failures, unimplemented anisotropic mosaic). Previously 0 meant fatal and
-1 was ambiguous, letting allocation failures silently continue with a
NULL reflection list. INITIALIZE check inverted accordingly; a normal
zero-reflection result no longer looks like an error.
- Add SM_list_compare and qsort the generated reflection list by |tau|
  before handing it to TRACE. The Ewald-sphere search breaks early on
  L[i].tau > tau_max assuming sortedness; without the sort most
  reflections were unreachable (physics fix).
- Sanity-check the unit cell after computing the lattice vectors:
  zero-length or degenerate (co-planar) vectors previously led to
  division by zero / inf / NaN in the reciprocal lattice and hkl loops.
  Aborts with a descriptive error message.
Describe all 28 columns of the atom file (fractional positions,
b[fm], gS/gL Lande factors, spin/orbital moment components along
a,b,c, and the reserved j0*/j2* form-factor columns), including the
b/10 unit convention and the >=14-column requirement for magnetic
use. The block lives in the %D description section (next to the
sample-shape notes) rather than under the atom_sites parameter in
%P, where mcdoc drops multi-line parameter documentation.
Files with 7-13 data columns take the magnetic branch, but Table_Index
clamps out-of-range indices to the last column, silently aliasing the
missing moment components. Emit an explicit warning naming the file,
column count, and expected layout.
@willend
willend marked this pull request as draft November 13, 2026 18:18
@willend

willend commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Converted to draft since you wrote "WIP and experimental do not merge yet!"

…le_magnetic_crystal

The branch's Single_magnetic_crystal gives PSD4PImon_I=1.19609e-05 at the
default mctest settings (ncount 1e6, seed 1000, L0=4), verified over several
seeds (1.20e-05..1.25e-05);

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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

⌂ Proxy