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

Need more readily obvious/accessible user documentation on using complex SLDs #589

Open
butlerpd opened this issue Jan 19, 2024 · 1 comment

Comments

@butlerpd
Copy link
Member

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.

@pkienzle
Copy link
Contributor

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);
}
"""

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

No branches or pull requests

2 participants