Changes in doc/guide/plugin.rst [0a9fcab:c654160] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/plugin.rst
r0a9fcab rc654160 292 292 **Note: The order of the parameters in the definition will be the order of the 293 293 parameters in the user interface and the order of the parameters in Iq(), 294 Iqxy() and form_volume(). And** *scale* **and** *background* **parameters are 295 implicit to all models, so they do not need to be included in the parameter table.** 294 Iqac(), Iqabc() and form_volume(). And** *scale* **and** *background* 295 **parameters are implicit to all models, so they do not need to be included 296 in the parameter table.** 296 297 297 298 - **"name"** is the name of the parameter shown on the FitPage. … … 362 363 scattered intensity. 363 364 364 - "volume" parameters are passed to Iq(), Iqxy(), and form_volume(), and 365 have polydispersity loops generated automatically. 366 367 - "orientation" parameters are only passed to Iqxy(), and have angular 368 dispersion. 365 - "volume" parameters are passed to Iq(), Iqac(), Iqabc() and form_volume(), 366 and have polydispersity loops generated automatically. 367 368 - "orientation" parameters are not passed, but instead are combined with 369 orientation dispersity to translate *qx* and *qy* to *qa*, *qb* and *qc*. 370 These parameters should appear at the end of the table with the specific 371 names *theta*, *phi* and for asymmetric shapes *psi*, in that order. 369 372 370 373 Some models will have integer parameters, such as number of pearls in the … … 419 422 That is, the individual models do not need to include polydispersity 420 423 calculations, but instead rely on numerical integration to compute the 421 appropriately smeared pattern. Angular dispersion values over polar angle 422 $\theta$ requires an additional $\cos \theta$ weighting due to decreased 423 arc length for the equatorial angle $\phi$ with increasing latitude. 424 appropriately smeared pattern. 424 425 425 426 Python Models … … 468 469 barbell). If I(q; pars) is NaN for any $q$, then those parameters will be 469 470 ignored, and not included in the calculation of the weighted polydispersity. 470 471 Similar to *Iq*, you can define *Iqxy(qx, qy, par1, par2, ...)* where the472 parameter list includes any orientation parameters. If *Iqxy* is not defined,473 then it will default to *Iqxy = Iq(sqrt(qx**2+qy**2), par1, par2, ...)*.474 471 475 472 Models should define *form_volume(par1, par2, ...)* where the parameter … … 497 494 } 498 495 499 *Iqxy* is similar to *Iq*, except it uses parameters *qx, qy* instead of *q*,500 and it includes orientation parameters.501 502 496 *form_volume* defines the volume of the shape. As in python models, it 503 497 includes only the volume parameters. 504 498 505 *Iqxy* will default to *Iq(sqrt(qx**2 + qy**2), par1, ...)* and506 *form_volume* will default to 1.0.507 508 499 **source=['fn.c', ...]** includes the listed C source files in the 509 program before *Iq* and *Iqxy* are defined. This allows you to extend the 510 library of C functions available to your model. 500 program before *Iq* and *form_volume* are defined. This allows you to 501 extend the library of C functions available to your model. 502 503 *c_code* includes arbitrary C code into your kernel, which can be 504 handy for defining helper functions for *Iq* and *form_volume*. Note that 505 you can put the full function definition for *Iq* and *form_volume* 506 (include function declaration) into *c_code* as well, or put them into an 507 external C file and add that file to the list of sources. 511 508 512 509 Models are defined using double precision declarations for the … … 532 529 533 530 #define INVALID(v) (v.bell_radius < v.radius) 531 532 The INVALID define can go into *Iq*, or *c_code*, or an external C file 533 listed in *source*. 534 535 Oriented Shapes 536 ............... 537 538 If the scattering is dependent on the orientation of the shape, then you 539 will need to include *orientation* parameters *theta*, *phi* and *psi* 540 at the end of the parameter table. Shape orientation uses *a*, *b* and *c* 541 axes, corresponding to the *x*, *y* and *z* axes in the laboratory coordinate 542 system, with *z* along the beam and *x*-*y* in the detector plane, with *x* 543 horizontal and *y* vertical. The *psi* parameter rotates the shape 544 about its *c* axis, the *theta* parameter then rotates the *c* axis toward 545 the *x* axis of the detector, then *phi* rotates the shape in the detector 546 plane. (Prior to these rotations, orientation dispersity will be applied 547 as roll-pitch-yaw, rotating *c*, then *b* then *a* in the shape coordinate 548 system.) A particular *qx*, *qy* point on the detector, then corresponds 549 to *qa*, *qb*, *qc* with respect to the shape. 550 551 The oriented C model is called as *Iqabc(qa, qb, qc, par1, par2, ...)* where 552 *par1*, etc. are the parameters to the model. If the shape is rotationally 553 symmetric about *c* then *psi* is not needed, and the model is called 554 as *Iqac(qab, qc, par1, par2, ...)*. In either case, the orientation 555 parameters are not included in the function call. 556 557 For 1D oriented shapes, an integral over all angles is usually needed for 558 the *Iq* function. Given symmetry and the substitution $u = \cos(\alpha)$, 559 $du = -\sin(\alpha)\,d\alpha$ this becomes 560 561 .. math:: 562 563 I(q) &= \frac{1}{4\pi} \int_{-\pi/2}^{pi/2} \int_{-pi}^{pi} 564 F(q_a, q_b, q_c)^2 \sin(\alpha)\,d\beta\,d\alpha \\ 565 &= \frac{8}{4\pi} \int_{0}^{pi/2} \int_{0}^{\pi/2} 566 F^2 \sin(\alpha)\,d\beta\,d\alpha \\ 567 &= \frac{8}{4\pi} \int_1^0 \int_{0}^{\pi/2} - F^2 \,d\beta\,du \\ 568 &= \frac{8}{4\pi} \int_0^1 \int_{0}^{\pi/2} F^2 \,d\beta\,du 569 570 for 571 572 .. math:: 573 574 q_a &= q \sin(\alpha)\sin(\beta) = q \sqrt{1-u^2} \sin(\beta) \\ 575 q_b &= q \sin(\alpha)\cos(\beta) = q \sqrt{1-u^2} \cos(\beta) \\ 576 q_c &= q \cos(\alpha) = q u 577 578 Using the $z, w$ values for Gauss-Legendre integration in "lib/gauss76.c", the 579 numerical integration is then:: 580 581 double outer_sum = 0.0; 582 for (int i = 0; i < GAUSS_N; i++) { 583 const double cos_alpha = 0.5*GAUSS_Z[i] + 0.5; 584 const double sin_alpha = sqrt(1.0 - cos_alpha*cos_alpha); 585 const double qc = cos_alpha * q; 586 double inner_sum = 0.0; 587 for (int j = 0; j < GAUSS_N; j++) { 588 const double beta = M_PI_4 * GAUSS_Z[j] + M_PI_4; 589 double sin_beta, cos_beta; 590 SINCOS(beta, sin_beta, cos_beta); 591 const double qa = sin_alpha * sin_beta * q; 592 const double qb = sin_alpha * cos_beta * q; 593 const double form = Fq(qa, qb, qc, ...); 594 inner_sum += GAUSS_W[j] * form * form; 595 } 596 outer_sum += GAUSS_W[i] * inner_sum; 597 } 598 outer_sum *= 0.25; // = 8/(4 pi) * outer_sum * (pi/2) / 4 599 600 The *z* values for the Gauss-Legendre integration extends from -1 to 1, so 601 the double sum of *w[i]w[j]* explains the factor of 4. Correcting for the 602 average *dz[i]dz[j]* gives $(1-0) \cdot (\pi/2-0) = \pi/2$. The $8/(4 \pi)$ 603 factor comes from the integral over the quadrant. With less symmetry (eg., 604 in the bcc and fcc paracrystal models), then an integral over the entire 605 sphere may be necessary. 606 607 For simpler models which are rotationally symmetric a single integral 608 suffices: 609 610 .. math:: 611 612 I(q) &= \frac{1}{\pi}\int_{-\pi/2}^{\pi/2} 613 F(q_{ab}, q_c)^2 \sin(\alpha)\,d\alpha/\pi \\ 614 &= \frac{2}{\pi} \int_0^1 F^2\,du 615 616 for 617 618 .. math:: 619 620 q_{ab} &= q \sin(\alpha) = q \sqrt{1 - u^2} \\ 621 q_c &= q \cos(\alpha) = q u 622 623 624 with integration loop:: 625 626 double sum = 0.0; 627 for (int i = 0; i < GAUSS_N; i++) { 628 const double cos_alpha = 0.5*GAUSS_Z[i] + 0.5; 629 const double sin_alpha = sqrt(1.0 - cos_alpha*cos_alpha); 630 const double qab = sin_alpha * q; 631 const double qc = cos_alpha * q; 632 const double form = Fq(qab, qc, ...); 633 sum += GAUSS_W[j] * form * form; 634 } 635 sum *= 0.5; // = 2/pi * sum * (pi/2) / 2 636 637 Magnetism 638 ......... 639 640 Magnetism is supported automatically for all shapes by modifying the 641 effective SLD of particle according to the Halpern-Johnson vector 642 describing the interaction between neutron spin and magnetic field. All 643 parameters marked as type *sld* in the parameter table are treated as 644 possibly magnetic particles with magnitude *M0* and direction 645 *mtheta* and *mphi*. Polarization parameters are also provided 646 automatically for magnetic models to set the spin state of the measurement. 647 648 For more complicated systems where magnetism is not uniform throughout 649 the individual particles, you will need to write your own models. 650 You should not mark the nuclear sld as type *sld*, but instead leave 651 them unmarked and provide your own magnetism and polarization parameters. 652 For 2D measurements you will need $(q_x, q_y)$ values for the measurement 653 to compute the proper magnetism and orientation, which you can implement 654 using *Iqxy(qx, qy, par1, par2, ...)*. 534 655 535 656 Special Functions … … 796 917 show a 50x improvement or more over the equivalent pure python model. 797 918 798 External C Models799 .................800 801 External C models are very much like embedded C models, except that802 *Iq*, *Iqxy* and *form_volume* are defined in an external source file803 loaded using the *source=[...]* statement. You need to supply the function804 declarations for each of these that you need instead of building them805 automatically from the parameter table.806 807 919 808 920 .. _Form_Factors: … … 1006 1118 variable name *Rg* for example because $R_g$ is the right name for the model 1007 1119 parameter then ignore the lint errors. Also, ignore *missing-docstring* 1008 for standard model functions *Iq*, *Iq xy*, etc.1120 for standard model functions *Iq*, *Iqac*, etc. 1009 1121 1010 1122 We will have delinting sessions at the SasView Code Camps, where we can
Note: See TracChangeset
for help on using the changeset viewer.