  MCViNE (Monte-Carlo VIrtual Neutron Experiment) is a versatile Monte Carlo
(MC) neutron ray-tracing program that provides researchers with tools for
performing computer modeling and simulations that mirror real neutron
scattering experiments. By adopting modern software engineering practices such
as using composite and visitor design patterns for representing and accessing
neutron scatterers, and using recursive algorithms for multiple scattering,
MCViNE is flexible enough to handle sophisticated neutron scattering problems
including, for example, neutron detection by complex detector systems, and
single and multiple scattering events in a variety of samples and sample
environments. In addition, MCViNE can take advantage of simulation components
in linear-chain-based MC ray tracing packages widely used in instrument design
and optimization, as well as NumPy-based components that make prototypes useful
and easy to develop. These developments have enabled us to carry out detailed
simulations of neutron scattering experiments with non-trivial samples in
time-of-flight inelastic instruments at the Spallation Neutron Source. Examples
of such simulations for powder and single-crystal samples with various
scattering kernels, including kernels for phonon and magnon scattering, are
presented. With simulations that closely reproduce experimental results,
scattering mechanisms can be turned on and off to determine how they contribute
to the measured scattering intensities, improving our understanding of the
underlying physics.
