Open butlerpd opened 10 months ago
There is a very simple library of complex functions in lib/cl_complex.h. This can be included using source = ["lib/cl_complex.h", ...]
in the model definition file.
In the model file real and imaginary will need to be given as separate input parameters. For example:
double
Iq(double q, double real, double imag, double radius) {
cdouble sld = cplx(real, imag);
double result = cabs(rmul(radius, sld));
return result*q;
}
Putting this together into a model file:
r"""
Example complex model: I(q) = r*|x + iy|*q^-4
"""
from numpy import inf
name = "complex"
title = "Test complex scattering length density"
# ["name", "units", default, [lower, upper], "type","description"],
parameters = [["real", "1e-6/Ang^2", 1, [-inf, inf], "",
"Scattering length density"],
["imag", "1e-6/Ang^2", 6, [-inf, inf], "",
"Imaginary scattering length density"],
["radius", "Ang", 50, [0, inf], "volume",
"Sphere radius"],
]
source = ["lib/cl_complex.h"]
c_code = """
double form_volume(double radius) { return 1.0; }
double Iq(double q, double real, double imag, double radius) {
cdouble sld = cplx(real, imag);
double result = cabs(rmul(radius, sld));
return result*pow(q,-4);
}
"""
At the roadmap discussion at Poland code camp, it was noted that sasmodels does support complex SLDs but that very few people know that. The desire was to see better more obvious documentation, perhaps in the "how to write a plugin model" section.