Opened 4 years ago

Closed 3 years ago

# create sin(x)/x, 2*J1(x)/x and 3*j1(x)/x functions

Reported by: Owned by: pkienzle minor SasView 4.2.0 SasView SasModels Redesign

### Description

Certain expressions are repeated frequently in sasmodels, such as sin(x)/x, 2*J1(x)/x and 3*j1(x)/x functions. We should make functions for these so that they handle the case of q=0 and are numerically stable as q→0. This has already been done for the spherical Bessel function 3*j1(x)/x, using the name sph_j1c.

Once these functions are created, we need to use them whereever they occur in the code.

### comment:1 Changed 4 years ago by pkienzle

\$ grep J1 *.c
barbell.c: const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2);
barbell.c: lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
barbell.c: const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2);
barbell.c:
lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
barbell.c: const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
capped_cylinder.c: const double be = (arg == 0.0 ? 0.5 : J1(arg)/arg);
capped_cylinder.c: lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
capped_cylinder.c: const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
capped_cylinder.c:
lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
capped_cylinder.c: const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
core_shell_bicelle.c: be1 = J1(besarg1)/besarg1;
core_shell_bicelle.c: be2 = J1(besarg2)/besarg2;
core_shell_cylinder.c: const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
cylinder.c: const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
elliptical_cylinder.c: retval = 2.0*NR_BessJ1(arg)/arg;
elliptical_cylinder.c: Be = NR_BessJ1(qr)/qr;
flexible_cylinder.c: double crossSect = (2.0*J1(qr)/qr)*(2.0*J1(qr)/qr);
flexible_cylinder_ex.c: yyy = pow((2.0 * J1(arg) / arg),2);
hollow_cylinder.c: lam1 = 2.0*J1(arg1)/arg1;
hollow_cylinder.c: lam2 = 2.0*J1(arg2)/arg2;
stacked_disks.c: const double be1 = J1(besarg1)/besarg1;
stacked_disks.c: const double be2 = J1(besarg2)/besarg2;

\$ grep "sin([(]*) */" *.c
barbell.c: lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
barbell.c: const double si = (arg1 == 0.0 ? 1.0 :sin(arg1)/arg1);
barbell.c:
lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
barbell.c: const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
capped_cylinder.c: to avoid sin(alpha)/sin(alpha) for alpha = 0. It is also a teensy bit
capped_cylinder.c:
lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
capped_cylinder.c: const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
capped_cylinder.c: lim_{x→0} J1(x)/x = ½, lim_{x→0} sin(x)/x = 1
capped_cylinder.c: const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
core_shell_bicelle.c: si1 = sin(sinarg1)/sinarg1;
core_shell_bicelle.c: si2 = sin(sinarg2)/sinarg2;
core_shell_cylinder.c: const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
cylinder.c: const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
elliptical_cylinder.c: si = sin(arg) * sin(arg) / arg / arg;
elliptical_cylinder.c: Si = sin(qL)/qL;
hollow_cylinder.c: t2 = sin(sinarg)/sinarg;
lamellarPC_kernel.c: Pbil = (sin(qval*xi)/(qval*xi))*(sin(qval*xi)/(qval*xi));
linear_pearls.c: return sin(x)/x;
parallelepiped.c:
handle arg=0 separately, as sin(t)/t → 1 as t→0
parallelepiped.c: tmp1 = sin(argA)*sin(argA)/argA/argA;
parallelepiped.c: tmp2 = sin(argB)*sin(argB)/argB/argB;
parallelepiped.c: tmp3 = sin(argC)*sin(argC)/argC/argC;
parallelepiped.c: tmp1 = sin(arg1)*sin(arg1)/arg1/arg1;
parallelepiped.c: tmp2 = sin(arg2)*sin(arg2)/arg2/arg2;
stacked_disks.c: const double si1 = sin(sinarg1)/sinarg1;
stacked_disks.c: const double si2 = sin(sinarg2)/sinarg2;

Last edited 4 years ago by pkienzle (previous) (diff)

### comment:2 Changed 4 years ago by pkienzle

Also, remove duplicate function NR_BessJ1.c

### comment:3 Changed 3 years ago by pkienzle

• Resolution set to fixed
• Status changed from new to closed

### comment:4 Changed 2 years ago by butler

• Milestone changed from SasView Next Release +1 to SasView 4.2.0
Note: See TracTickets for help on using tickets.