Changeset 34c2649 in sasview for sansmodels/src/sans/models/libigor/libCylinder.c
- Timestamp:
- Nov 21, 2011 4:52:25 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 1810613
- Parents:
- afea8fe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/libigor/libCylinder.c
r3a084629 r34c2649 1337 1337 1338 1338 return answer; 1339 }1340 1341 /////////functions for WRC implementation of flexible cylinders1342 static double1343 Sk_WR(double q, double L, double b)1344 {1345 //1346 double p1,p2,p1short,p2short,q0,qconnect;1347 double C,epsilon,ans,q0short,Sexvmodify,pi;1348 1349 pi = 4.0*atan(1.0);1350 1351 p1 = 4.12;1352 p2 = 4.42;1353 p1short = 5.36;1354 p2short = 5.62;1355 q0 = 3.1;1356 qconnect = q0/b;1357 //1358 q0short = fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0);1359 1360 //1361 if(L/b > 10.0) {1362 C = 3.06/pow((L/b),0.44);1363 epsilon = 0.176;1364 } else {1365 C = 1.0;1366 epsilon = 0.170;1367 }1368 //1369 1370 if( L > 4*b ) { // Longer Chains1371 if (q*b <= 3.1) { //Modified by Yun on Oct. 15,1372 Sexvmodify = Sexvnew(q, L, b);1373 ans = Sexvmodify + C * (4.0/15.0 + 7.0/(15.0*u_WR(q,L,b)) - (11.0/15.0 + 7.0/(15.0*u_WR(q,L,b)))*exp(-u_WR(q,L,b)))*(b/L);1374 } else { //q(i)*b > 3.11375 ans = a1long(q, L, b, p1, p2, q0)/(pow((q*b),p1)) + a2long(q, L, b, p1, p2, q0)/(pow((q*b),p2)) + pi/(q*L);1376 }1377 } else { //L <= 4*b Shorter Chains1378 if (q*b <= fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0) ) {1379 if (q*b<=0.01) {1380 ans = 1.0 - Rgsquareshort(q,L,b)*(q*q)/3.0;1381 } else {1382 ans = Sdebye1(q,L,b);1383 }1384 } else { //q*b > max(1.9/sqrt(Rgsquareshort(q(i),L,b)),3)1385 ans = a1short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p1short)) + a2short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p2short)) + pi/(q*L);1386 }1387 }1388 1389 return(ans);1390 //return(a2long(q, L, b, p1, p2, q0));1391 }1392 1393 //WR named this w (too generic)1394 static double1395 w_WR(double x)1396 {1397 double yy;1398 yy = 0.5*(1 + tanh((x - 1.523)/0.1477));1399 1400 return (yy);1401 }1402 1403 //1404 static double1405 u1(double q, double L, double b)1406 {1407 double yy;1408 1409 yy = Rgsquareshort(q,L,b)*q*q;1410 1411 return (yy);1412 }1413 1414 // was named u1415 static double1416 u_WR(double q, double L, double b)1417 {1418 double yy;1419 yy = Rgsquare(q,L,b)*q*q;1420 return (yy);1421 }1422 1423 1424 1425 //1426 static double1427 Rgsquarezero(double q, double L, double b)1428 {1429 double yy;1430 yy = (L*b/6.0) * (1.0 - 1.5*(b/L) + 1.5*pow((b/L),2) - 0.75*pow((b/L),3)*(1.0 - exp(-2.0*(L/b))));1431 1432 return (yy);1433 }1434 1435 //1436 static double1437 Rgsquareshort(double q, double L, double b)1438 {1439 double yy;1440 yy = AlphaSquare(L/b) * Rgsquarezero(q,L,b);1441 1442 return (yy);1443 }1444 1445 //1446 static double1447 Rgsquare(double q, double L, double b)1448 {1449 double yy;1450 yy = AlphaSquare(L/b)*L*b/6.0;1451 1452 return (yy);1453 }1454 1455 //1456 static double1457 AlphaSquare(double x)1458 {1459 double yy;1460 yy = pow( (1.0 + (x/3.12)*(x/3.12) + (x/8.67)*(x/8.67)*(x/8.67)),(0.176/3.0) );1461 1462 return (yy);1463 }1464 1465 // ?? funciton is not used - but should the log actually be log10???1466 static double1467 miu(double x)1468 {1469 double yy;1470 yy = (1.0/8.0)*(9.0*x - 2.0 + 2.0*log(1.0 + x)/x)*exp(1.0/2.565*(1.0/x + (1.0 - 1.0/(x*x))*log(1.0 + x)));1471 1472 return (yy);1473 }1474 1475 //1476 static double1477 Sdebye(double q, double L, double b)1478 {1479 double yy;1480 yy = 2.0*(exp(-u_WR(q,L,b)) + u_WR(q,L,b) -1.0)/(pow((u_WR(q,L,b)),2));1481 1482 return (yy);1483 }1484 1485 //1486 static double1487 Sdebye1(double q, double L, double b)1488 {1489 double yy;1490 yy = 2.0*(exp(-u1(q,L,b)) + u1(q,L,b) -1.0)/( pow((u1(q,L,b)),2.0) );1491 1492 return (yy);1493 }1494 1495 //1496 static double1497 Sexv(double q, double L, double b)1498 {1499 double yy,C1,C2,C3,miu,Rg2;1500 C1=1.22;1501 C2=0.4288;1502 C3=-1.651;1503 miu = 0.585;1504 1505 Rg2 = Rgsquare(q,L,b);1506 1507 yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) + C2*pow((q*sqrt(Rg2)),(-2.0/miu)) + C3*pow((q*sqrt(Rg2)),(-3.0/miu)));1508 1509 return (yy);1510 }1511 1512 // this must be WR modified version1513 static double1514 Sexvnew(double q, double L, double b)1515 {1516 double yy,C1,C2,C3,miu;1517 double del=1.05,C_star2,Rg2;1518 1519 C1=1.22;1520 C2=0.4288;1521 C3=-1.651;1522 miu = 0.585;1523 1524 //calculating the derivative to decide on the corection (cutoff) term?1525 // I have modified this from WRs original code1526 1527 if( (Sexv(q*del,L,b)-Sexv(q,L,b))/(q*del - q) >= 0.0 ) {1528 C_star2 = 0.0;1529 } else {1530 C_star2 = 1.0;1531 }1532 1533 Rg2 = Rgsquare(q,L,b);1534 1535 yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + C_star2*w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) + C2*pow((q*sqrt(Rg2)),(-2.0/miu)) + C3*pow((q*sqrt(Rg2)),(-3.0/miu)));1536 1537 return (yy);1538 }1539 1540 // these are the messy ones1541 static double1542 a2short(double q, double L, double b, double p1short, double p2short, double q0)1543 {1544 double yy,Rg2_sh;1545 double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p;1546 double pi;1547 1548 E = 2.718281828459045091;1549 pi = 4.0*atan(1.0);1550 Rg2_sh = Rgsquareshort(q,L,b);1551 Rg2_sh2 = Rg2_sh*Rg2_sh;1552 t1 = ((q0*q0*Rg2_sh)/(b*b));1553 Et1 = pow(E,t1);1554 Emt1 =pow(E,-t1);1555 q02 = q0*q0;1556 q0p = pow(q0,(-4.0 + p2short) );1557 1558 //E is the number e1559 yy = ((-(1.0/(L*((p1short - p2short))*Rg2_sh2)*((b*Emt1*q0p*((8.0*b*b*b*L - 8.0*b*b*b*Et1*L - 2.0*b*b*b*L*p1short + 2.0*b*b*b*Et1*L*p1short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 2.0*b*Et1*L*p1short*q02*Rg2_sh - Et1*pi*q02*q0*Rg2_sh2 + Et1*p1short*pi*q02*q0*Rg2_sh2)))))));1560 1561 return (yy);1562 }1563 1564 //1565 static double1566 a1short(double q, double L, double b, double p1short, double p2short, double q0)1567 {1568 double yy,Rg2_sh;1569 double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p,b3;1570 double pi;1571 1572 E = 2.718281828459045091;1573 pi = 4.0*atan(1.0);1574 Rg2_sh = Rgsquareshort(q,L,b);1575 Rg2_sh2 = Rg2_sh*Rg2_sh;1576 b3 = b*b*b;1577 t1 = ((q0*q0*Rg2_sh)/(b*b));1578 Et1 = pow(E,t1);1579 Emt1 =pow(E,-t1);1580 q02 = q0*q0;1581 q0p = pow(q0,(-4.0 + p1short) );1582 1583 yy = ((1.0/(L*((p1short - p2short))*Rg2_sh2)*((b*Emt1*q0p*((8.0*b3*L - 8.0*b3*Et1*L - 2.0*b3*L*p2short + 2.0*b3*Et1*L*p2short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 2.0*b*Et1*L*p2short*q02*Rg2_sh - Et1*pi*q02*q0*Rg2_sh2 + Et1*p2short*pi*q02*q0*Rg2_sh2))))));1584 1585 return(yy);1586 }1587 1588 // this one will be lots of trouble1589 static double1590 a2long(double q, double L, double b, double p1, double p2, double q0)1591 {1592 double yy,C1,C2,C3,C4,C5,miu,C,Rg2;1593 double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,pi;1594 double E,b2,b3,b4,q02,q03,q04,q05,Rg22;1595 1596 pi = 4.0*atan(1.0);1597 E = 2.718281828459045091;1598 if( L/b > 10.0) {1599 C = 3.06/pow((L/b),0.44);1600 } else {1601 C = 1.0;1602 }1603 1604 C1 = 1.22;1605 C2 = 0.4288;1606 C3 = -1.651;1607 C4 = 1.523;1608 C5 = 0.1477;1609 miu = 0.585;1610 1611 Rg2 = Rgsquare(q,L,b);1612 Rg22 = Rg2*Rg2;1613 b2 = b*b;1614 b3 = b*b*b;1615 b4 = b3*b;1616 q02 = q0*q0;1617 q03 = q0*q0*q0;1618 q04 = q03*q0;1619 q05 = q04*q0;1620 1621 t1 = (1.0/(b* p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2)) ));1622 1623 t2 = (b*C*(((-1.0*((14.0*b3)/(15.0*q03*Rg2))) + (14.0*b3*pow(E,(-((q02*Rg2)/b2))))/(15.0*q03*Rg2) + (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*((11.0/15.0 + (7*b2)/(15.0*q02*Rg2)))*Rg2)/b)))/L;1624 1625 t3 = (sqrt(Rg2)*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2.0))/(2.0*C5);1626 1627 t4 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2))/(C5*q04*Rg22);1628 1629 t5 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22);1630 1631 t6 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q05*Rg22);1632 1633 t7 = (((-((3.0*C3*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 3.0/miu)))/miu)) - (2.0*C2*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 2.0/miu)))/miu - (C1*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 1.0/miu)))/miu));1634 1635 t8 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));1636 1637 t9 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15*q02*Rg2))) + (7.0*b2)/(15.0*q02*Rg2))))/L;1638 1639 t10 = (2.0*b4*(((-1) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22);1640 1641 1642 yy = ((-1.0*(t1* ((-pow(q0,-p1)*(((b2*pi)/(L*q02) + t2 + t3 - t4 + t5 - t6 + 1.0/2.0*t7*t8)) - b*p1*pow(q0,((-1.0) - p1))*(((-((b*pi)/(L*q0))) + t9 + t10 + 1.0/2.0*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))))));1643 1644 return (yy);1645 }1646 1647 //need to define this on my own1648 static double1649 sech_WR(double x)1650 {1651 return(1/cosh(x));1652 }1653 1654 //1655 static double1656 a1long(double q, double L, double b, double p1, double p2, double q0)1657 {1658 double yy,C,C1,C2,C3,C4,C5,miu,Rg2;1659 double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15;1660 double E,pi;1661 double b2,b3,b4,q02,q03,q04,q05,Rg22;1662 1663 pi = 4.0*atan(1.0);1664 E = 2.718281828459045091;1665 1666 if( L/b > 10.0) {1667 C = 3.06/pow((L/b),0.44);1668 } else {1669 C = 1.0;1670 }1671 1672 C1 = 1.22;1673 C2 = 0.4288;1674 C3 = -1.651;1675 C4 = 1.523;1676 C5 = 0.1477;1677 miu = 0.585;1678 1679 Rg2 = Rgsquare(q,L,b);1680 Rg22 = Rg2*Rg2;1681 b2 = b*b;1682 b3 = b*b*b;1683 b4 = b3*b;1684 q02 = q0*q0;1685 q03 = q0*q0*q0;1686 q04 = q03*q0;1687 q05 = q04*q0;1688 1689 t1 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2))) + (7.0*b2)/(15.0*q02*Rg2))));1690 1691 t2 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));1692 1693 t3 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))));1694 1695 t4 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));1696 1697 t5 = (1.0/(b*p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2))));1698 1699 t6 = (b*C*(((-((14.0*b3)/(15.0*q03*Rg2))) + (14.0*b3*pow(E,(-((q02*Rg2)/b2))))/(15.0*q03*Rg2) + (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2)))*Rg2)/b)));1700 1701 t7 = (sqrt(Rg2)*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2));1702 1703 t8 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2));1704 1705 t9 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));1706 1707 t10 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));1708 1709 t11 = (((-((3.0*C3*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 3.0/miu)))/miu)) - (2.0*C2*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 2.0/miu)))/miu - (C1*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 1.0/miu)))/miu));1710 1711 t12 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));1712 1713 t13 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02* Rg2))) + (7.0*b2)/(15.0*q02*Rg2))));1714 1715 t14 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));1716 1717 t15 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))));1718 1719 1720 yy = (pow(q0,p1)*(((-((b*pi)/(L*q0))) +t1/L +t2/(q04*Rg22) + 1.0/2.0*t3*t4)) + (t5*((pow(q0,(p1 - p2))*(((-pow(q0,(-p1)))*(((b2*pi)/(L*q02) +t6/L +t7/(2.0*C5) -t8/(C5*q04*Rg22) +t9/(q04*Rg22) -t10/(q05*Rg22) + 1.0/2.0*t11*t12)) - b*p1*pow(q0,((-1.0) - p1))*(((-((b*pi)/(L*q0))) +t13/L +t14/(q04*Rg22) + 1.0/2.0*t15*((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))))))));1721 1722 return (yy);1723 1339 } 1724 1340 … … 2132 1748 } 2133 1749 2134 static double2135 gammaln(double xx)2136 {2137 double x,y,tmp,ser;2138 static double cof[6]={76.18009172947146,-86.50532032941677,2139 24.01409824083091,-1.231739572450155,2140 0.1208650973866179e-2,-0.5395239384953e-5};2141 int j;2142 2143 y=x=xx;2144 tmp=x+5.5;2145 tmp -= (x+0.5)*log(tmp);2146 ser=1.000000000190015;2147 for (j=0;j<=5;j++) ser += cof[j]/++y;2148 return -tmp+log(2.5066282746310005*ser/x);2149 }2150 2151 1750 2152 1751 double
Note: See TracChangeset
for help on using the changeset viewer.