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

Merge branch develop into master for 2023 release #965

Merged
merged 190 commits into from Feb 15, 2023
Merged

Merge branch develop into master for 2023 release #965

merged 190 commits into from Feb 15, 2023

Conversation

ftessier
Copy link
Member

No description provided.

mainegra and others added 30 commits June 27, 2022 14:21
Remove superfluous command in entry point source_check_emin copied from
entry point source_get_emax during implementation, which was setting the
value for emax.

Not really clear to me why this was happening but it turns out that
having emax as an argument in one entry point would force to also have
in the other entry point to avoid SEGFAULT errors. However, line has
been removed as it shouldn't have been there in the first place!
Before this change, there was a small risk of buffer overflow in the
tutor7pp fluence scoring arrays. The value r2 was checked to be less
than 400, and then the scoring bin number (from 0 to 199) is calculated
using the expression (int)(sqrt(r2)*10.). The problem with this check is
that certain double precision values less than 400 can nevertheless have
a square root equal to exactly 20.0 due to floating-point rounding.

For example, taking the square root of the double 399.99999999999994
results in 20.0 under certain conditions, not a value slightly less than
20.0 as would be expected. The default g++ rounding mode is
round-to-nearest, so even with the square root's true value being under
20.0, the resulting double can be rounded upwards to 20.0 if the true
value is closer to 20.0 than the previous representable float. Then,
scoring in bin 200 results in buffer overflow in the scoring array.

This change ensures the resulting scoring array bin integer is in bounds
(< 200), eliminating the potential for buffer overflow.
Check that the current region index (ir) is not -1 for region dose
scoring. Before this change, there was an out-of-bounds read in
d_reg_index when the region was -1 (outside the geometry).
Vacuum has a special medium number -1, while all other media get offsets
from 0 to nmedia. Before this change, there was a buffer overflow if
media dose scoring was used with a geometry that had vacuum as one of
the media. The vector massM is indexed by medium number, but for any
vacuum regions, it would read and write memory at the memory location
one before the buffer bounds: massM[-1].

Skipping the vacuum region masses shouldn't matter, as vacuum dose is
always zero. massM is only used later on with non-vacuum media, so
skipping vacuum regions is the right choice instead of an alternative
like appending the vacuum mass to massM.
Bug: results depend on the order in which the material composition is
defined.

Reported by Iymad Mansour who observed that egs_brachy simulations of an
irradiation with an isotropic 35 keV photon point source, embedded in a
steel applicator, produced 5% differences in the surface dose of a water
phantom when the order of the steel components was changed.

Reproduced with egs_kerma for a 35 keV photon point source surrounded by
a 1 mm steel encapsulation embedded in a spherical water phantom. Kerma
at the spherical water shell next to the encapsulation differs by 4%.

Cause: sampling element and atomic shell for photo-electric interaction
with MCDF-XCOM shell-wise using unsorted array zelem rather than
pe_zsorted.

Solution: using sorted array pe_zsorted fixes the issue.
Fix a mistake in the previous fix for non-alpha numeric characters in
the job name in egs-parallel jobs resulting in a crash. The previous fix
removed non-alphanum characters from the start of the original job name,
but actually we needed to remove from the start of the trimmed 14
character job name.
Change a few occurrences of endl to \n in egs++ scoring routines, to
increase performance by about 50%. The reason for this is that endl
performs a buffer flush each time, which is not necessary. The
performance hit was very noticeable for large arrays, like a 300x300x300
3ddose file.
Add a record of the git hash, branch and compile time to the c++
makefiles. This allows the c++ codes to access those parameters as
defines. Advanced applications now output those values during
initEGSnrcBackEnd().
Add the compilation time of an application to the printout of git hash
and branch, and add these messages to the mortran codes. Also add a
check for applications in the makefile to compare with the HEN_HOUSE
versions and print a warning if there are differences.

With the git information now printed to machine.mortran, it is not
necessary to pass it as c++ compile flags. However, I will leave these
flags for future use.
Also replace an old reference to nmake with mingw32-make.
Change the git branch and commit reporting to be passed as defines at
compile time, instead of being generated during the configuration of
EGSnrc. This fixes the issue where users could switch branches but not
run the configuration script, resulting in the wrong git branch and
commit being output.
As discussed in issue #745 ensure that one EGS_TrackScoring object is
define to prevent bugs at write time when multiple objects try to write
to the same file.
Fix memory leaks in EGS_AdvancedApplication: interpolation arrays are
never freed, and transportp is allocated by EGS_Input::getInputItem but
never freed. Also Fix memory leak in EGS_ObjectFactory::createObjects:
EGS_Input* input is allocated by EGS_Input::takeInputItem but never
freed.

Memory leaks reported by AddressSanitizer.
After compiling egs_view with asan support, there was a buffer overflow
error traced back to the memcpy call in ImageWindow::paintEvent.

ERROR: AddressSanitizer: dynamic-stack-buffer-overflow ...
READ of size 400 at 0x7ffe71889e40 thread T0
    #0 0x7f543595ecdf  (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x99cdf)
    #1 0x55dc3acdbb15 in memcpy
    #2 0x55dc3acdbb15 in ImageWindow::paintEvent(QPaintEvent*)
    #3 0x7f5434f86047 in QWidget::event(QEvent*)

The issue is that memcpy will always copy sizeof(lastRegions) bytes into
the array regions. But before this change, regions could be shorter than
lastRegions, leading to a buffer overflow. After this change, maxreg is
always set to N_REG_MAX, the length of lastRegions.
In the solution to one of the questions in the getting-started manual,
the total dose was calculated as the sum of dose to regions, instead of
appropriately weighted by the relative volume of each region. This was
corrected, as well as another typo in the instructions.

Reported by @mjukdisk in discussion #780.
Fix a GUI error that occurred in DYNJAWS jaw definitions when clicking
the button to calculate the jaw settings from the field size and SSD.
The button triggered a function that was duplicated with the same name
in SYNCJAWS, leading to the error. As the fix, the syncjaws version of
the function has been renamed. This bug has existed since SYNCJAWS was
added to the GUI.
Set the minimum distance between component modules in BEAMnrc to 1e-5 cm
(macro $MIN_GAP). Previously this minimum gap was set to 0.01 cm. Given
that the code is normally used in double-precision nowadays, there is no
point in leaving such a large value as the default.

This change follows for looking into issue #773.
Add the source-axis distance to the z position of the particle before it
is written to the phase space file. This change only affects IAEA phsp
sources, and only when scoring particles in BEAMnrc coordinates.
Fix a minor bug in FLURZnrc where it expected the wrong number of inputs
when reading in the SLOTE parameter from the egsinp file. This did not
result in any actual issues, but an error message was printed to the
screen about the user providing the wrong number of inputs.
Implement a graceful exit from the addphsp application if the total
number of particles is greater than 2^32-1, the maximum count that can
be stored in the header. Only enforce this for a phase space in EGSnrc
format.
ftessier and others added 24 commits January 10, 2023 14:25
Fix the egs_chamber examples so that they now run without needing to
compile any BEAMnrc accelerators or make changes to the input file. Also
fix a typo in the example2 water box size.
- EGS_Interpolator: increase array size when creating an interpolator
  based on an array of value pairs to have an extra bin to prevent
  round-off errors. This is also done by PEGS4 when determining fit
  parameters for each interval. The extra bin uses the same parameters
  as the previous one, i.e., it extrapolates.

- Add auxiliary methods to application classes to get electron step size,
  energy deposited and app source type.

- Fluence scoring: at a plane, in regions for all particles.
Get proper stopping power interpolator depending on charge.
- Add "clean" target for dose and fluence scoring objects (instead of
  manually deleting files when building the ausgab object). Need to add
  to the rest of the ausgab objects!

- One can now define DEBUG=-DDEBUG to turn on some debugging messages that
  I found useful.

- Add MYDEF for user defines: use MYDEF=-DDEBUG to activate debugging
  messages and variables.
Reworked the classes for planar and volumetric fluence scoring to
descend from a common base class which contains many commonalities, to
avoid code duplication. Should have started that way!
Add auxiliary functions to application classes, required by the fluence
scoring ausgab object.
- Add a method to get the charge of a base source, which returns -99 by
  default, matching the unknown type of the fluence scoring ausgab
  object. A base source does not know the charge of its particles unless
  it is later derived from a simple source. For instance a collection of
  sources, a beam source, or a phase space source will contain multiple
  type of particles.

- Sources derived from the class EGS_SimpleSource return the source
  particle's charge.

- Add a method to get source charge from the application.
Add an application-level method to obtain the maximum energy of the
source. This proves useful for ausgab objects that need this
information.
- Add option to define regions from where to score planar fluence to
  improve efficiency of charged particle calculations.

- Move many common tasks to the base class EGS_FluenceScoring.

- Fix group scoring region definitions.

- Improve logic for defining scoring regions in planar scoring class.

- Document classes with Doxygen comments.
- Add the ability to divide fluence in total and primary fluence.

- Add the ability to calculate integral and differential fluence.

- Improve output format.

- Investigate the effect of scoring integral charged particle fluence
  using either EDEP (within differential scoring block) or directly
  TVSTEP:

  a) Identical for FLURZ-like calculation
  b) Small, negligible differences using stprO3 and stpwrO5

  This allows extraction of the integral fluence scoring from the blocks
  for differential fluence. When one is only interested in the integral
  fluence, the calculation is up to 10% faster using a TVSTEP-based
  approach.

  Current implementation allows switching between EDEP-based and
  TVSTEP-based integral fluence calculation via the pre-processor define
  USETVSTEP. To use TVSTEP-based integral dose calculation use:

  make MYDEFS=-DUSETVSTEP

  Next iteration will only use the TVSTEP-based approach for integral
  fluence as both approaches result in negligible differences.

- Add mechanism to track the distribution of number of energy bins
  covered when spreading EDEP. This is activated via the define variable
  DEBUG: to use it, build the fluence scoring ausgab object using:

  make MYDEFS=-DDEBUG

  One can also trace the difference between the step derived from
  spreading EDEP over the energy grid and TVSTEP via DEBUG.
- Add input blocks to define the energy grid and the scoring options
  based on the scoring type.

- Improve output format.
Remove example for base class and add specific blocks for planar an
volumetric scoring inputs.
- Remove initial approach to score charged particle integral fluence
  from each contribution to the differential fluence. Now is uses TVSTEP
  and computes integral fluence in one go.

- Remove checks for pre-processor directive USETVSTEP as it not needed
  anymore.

- Polish documentation.
This new ausgab object scores fluence in user-defined regions
(volumetric) or at a circular or rectangular field (planar) located in
an arbitrary position in space. Scoring can be done for either photons,
electrons or positrons. Scoring for multiple particle types is
accomplished by defining multiple fluence scoring ausgab objects.
Add a missing include of the array c++ class library. This avoids
compiler errors that occurred on macOS.
Add ausgab calls before and after a photonuclear interaction, in order
to handle cross section enhancement (xcse) correctly. Without these
calls, there is no compensation for the enhanced cross section, hence
the photonuclear cross section is effectively increased by the xcse
factor.

Also add the photonuclear event trapping in Fano calculations, for
consistency. However, the Fano calculation fails when photonuclear
attenuation is turned on anyway, because the photon is discarded
without depositing its energy.

Also update a couple loops that print out the ausgab flags (IAUSFL)
values, to include the photonuclear attenuation option value.
@ftessier ftessier requested a review from a team as a code owner February 15, 2023 18:55
@ftessier ftessier requested review from mainegra, rtownson and blakewalters and removed request for a team February 15, 2023 18:55
@ftessier ftessier merged commit af336f6 into master Feb 15, 2023
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.

None yet

10 participants