Support specular intensity for polarized GISANS
The choice simulation.options().setIncludeSpecular(True)
is currently incompatible with polarized GISANS (simulation with polarization analysis or sample with magnetic material). Computation will fail in file Sim/Contrib/GISASSpecularContribution.cpp, function compute::gisasSpecularContribution, after attempt to cast fluxIn
into a SpecularFlux
so that flux->getScalarR()
can be called.
This replaces #75 (closed).
Test script:
#!/usr/bin/env python3
"""
Minimum example of crash when using a magnetic material together with setIncludeSpecular(True).
Based on MagneticSpheres.py example.
"""
import bornagain as ba
from bornagain import ba_plot as bp, deg, nm, R3
def get_sample():
"""
Returns a sample with magnetic spheres in the substrate.
"""
# Define materials
magnetic_field = R3(0, 0, 1e7)
material_Layer = ba.RefractiveMaterial("Layer", 2e-05*1e-3, 4e-07*1e-3,
magnetic_field*1e-3)
material_Particle = ba.RefractiveMaterial("Particle", 2e-05, 4e-07,
magnetic_field)
material_Substrate = ba.RefractiveMaterial("Substrate", 7e-06,
1.8e-07)
material_Vacuum = ba.RefractiveMaterial("Vacuum", 0, 0)
# Define form factors
ff = ba.Sphere(5*nm)
# Define particles
particle = ba.Particle(material_Particle, ff)
particle.translate(0, 0, -10*nm)
# Define particle layouts
layout = ba.ParticleLayout(particle)
layout.setTotalParticleSurfaceDensity(0.01)
# Define layers
layer_1 = ba.Layer(material_Vacuum)
layer_2 = ba.Layer(material_Layer)
layer_2.addLayout(layout)
layer_3 = ba.Layer(material_Substrate)
# Define sample
sample = ba.MultiLayer()
sample.addLayer(layer_1)
sample.addLayer(layer_2)
sample.addLayer(layer_3)
return sample
def get_simulation(sample):
beam = ba.Beam(1e12, 0.1*nm, 0.5*deg, 0)
beam_polarization = R3(0, 1, 0)
beam.setPolarization(beam_polarization)
detector = ba.SphericalDetector(200, 6*deg, 0, 3*deg)
detector.setAnalyzer(R3(0, 1, 0), 1, 0.5)
simulation = ba.ScatteringSimulation(beam, sample, detector)
simulation.options().setIncludeSpecular(True) # simulation runs normally without this line
return simulation
if __name__ == '__main__':
bp.parse_args()
sample = get_sample()
simulation = get_simulation(sample)
result = simulation.simulate()
bp.plot_simulation_result(result)