source: sasmodels/sasmodels/models/rpa.c @ 6351bfa

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 6351bfa was 6351bfa, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

undo attempted fix to rpa for AMD GPU

  • Property mode set to 100644
File size: 16.8 KB
Line 
1double Iq(double q, double case_num,
2    double N[], double Phi[], double v[], double L[], double b[],
3    double Kab, double Kac, double Kad,
4    double Kbc, double Kbd, double Kcd
5    );
6
7double Iq(double q, double case_num,
8    double N[],    // DEGREE OF POLYMERIZATION
9    double Phi[],  // VOL FRACTION
10    double v[],    // SPECIFIC VOLUME
11    double L[],    // SCATT. LENGTH
12    double b[],    // SEGMENT LENGTH
13    double Kab, double Kac, double Kad,  // CHI PARAM
14    double Kbc, double Kbd, double Kcd
15    )
16{
17  int icase = (int)case_num;
18
19  double Nab,Nac,Nad,Nbc,Nbd,Ncd;
20  double Phiab,Phiac,Phiad,Phibc,Phibd,Phicd;
21  double vab,vac,vad,vbc,vbd,vcd;
22  double m;
23  double Xa,Xb,Xc,Xd;
24  double Paa,S0aa,Pab,S0ab,Pac,S0ac,Pad,S0ad;
25  double S0ba,Pbb,S0bb,Pbc,S0bc,Pbd,S0bd;
26  double S0ca,S0cb,Pcc,S0cc,Pcd,S0cd;
27  double S0da,S0db,S0dc;
28  double Pdd,S0dd;
29  double Kaa,Kbb,Kcc;
30  double Kba,Kca,Kcb;
31  double Kda,Kdb,Kdc,Kdd;
32  double Zaa,Zab,Zac,Zba,Zbb,Zbc,Zca,Zcb,Zcc;
33  double DenT,T11,T12,T13,T21,T22,T23,T31,T32,T33;
34  double Y1,Y2,Y3,X11,X12,X13,X21,X22,X23,X31,X32,X33;
35  double ZZ,DenQ1,DenQ2,DenQ3,DenQ,Q11,Q12,Q13,Q21,Q22,Q23,Q31,Q32,Q33;
36  double N11,N12,N13,N21,N22,N23,N31,N32,N33;
37  double M11,M12,M13,M21,M22,M23,M31,M32,M33;
38  double S11,S12,S13,S14,S21,S22,S23,S24;
39  double S31,S32,S33,S34,S41,S42,S43,S44;
40  double Lad,Lbd,Lcd,Nav,Intg;
41
42  //icase was shifted to N-1 from the original code
43  if (icase <= 1){
44    Phi[0] = Phi[1] = 0.0000001;
45    N[0] = N[1] = 1000.0;
46    L[0] = L[1] = 1.e-12;
47    v[0] = v[1] = 100.0;
48    b[0] = b[1] = 5.0;
49    Kab = Kac = Kad = Kbc = Kbd = -0.0004;
50  }
51  else if ((icase > 1) && (icase <= 4)){
52    Phi[0] = 0.0000001;
53    N[0] = 1000.0;
54    L[0] = 1.e-12;
55    v[0] = 100.0;
56    b[0] = 5.0;
57    Kab = Kac = Kad = -0.0004;
58  }
59
60  Nab=sqrt(N[0]*N[1]);
61  Nac=sqrt(N[0]*N[2]);
62  Nad=sqrt(N[0]*N[3]);
63  Nbc=sqrt(N[1]*N[2]);
64  Nbd=sqrt(N[1]*N[3]);
65  Ncd=sqrt(N[2]*N[3]);
66
67  vab=sqrt(v[0]*v[1]);
68  vac=sqrt(v[0]*v[2]);
69  vad=sqrt(v[0]*v[3]);
70  vbc=sqrt(v[1]*v[2]);
71  vbd=sqrt(v[1]*v[3]);
72  vcd=sqrt(v[2]*v[3]);
73
74  Phiab=sqrt(Phi[0]*Phi[1]);
75  Phiac=sqrt(Phi[0]*Phi[2]);
76  Phiad=sqrt(Phi[0]*Phi[3]);
77  Phibc=sqrt(Phi[1]*Phi[2]);
78  Phibd=sqrt(Phi[1]*Phi[3]);
79  Phicd=sqrt(Phi[2]*Phi[3]);
80
81  Xa=q*q*b[0]*b[0]*N[0]/6.0;
82  Xb=q*q*b[1]*b[1]*N[1]/6.0;
83  Xc=q*q*b[2]*b[2]*N[2]/6.0;
84  Xd=q*q*b[3]*b[3]*N[3]/6.0;
85
86  Paa=2.0*(exp(-Xa)-1.0+Xa)/(Xa*Xa);
87  S0aa=N[0]*Phi[0]*v[0]*Paa;
88  Pab=((1.0-exp(-Xa))/Xa)*((1.0-exp(-Xb))/Xb);
89  S0ab=(Phiab*vab*Nab)*Pab;
90  Pac=((1.0-exp(-Xa))/Xa)*exp(-Xb)*((1.0-exp(-Xc))/Xc);
91  S0ac=(Phiac*vac*Nac)*Pac;
92  Pad=((1.0-exp(-Xa))/Xa)*exp(-Xb-Xc)*((1.0-exp(-Xd))/Xd);
93  S0ad=(Phiad*vad*Nad)*Pad;
94
95  S0ba=S0ab;
96  Pbb=2.0*(exp(-Xb)-1.0+Xb)/(Xb*Xb);
97  S0bb=N[1]*Phi[1]*v[1]*Pbb;
98  Pbc=((1.0-exp(-Xb))/Xb)*((1.0-exp(-Xc))/Xc);
99  S0bc=(Phibc*vbc*Nbc)*Pbc;
100  Pbd=((1.0-exp(-Xb))/Xb)*exp(-Xc)*((1.0-exp(-Xd))/Xd);
101  S0bd=(Phibd*vbd*Nbd)*Pbd;
102
103  S0ca=S0ac;
104  S0cb=S0bc;
105  Pcc=2.0*(exp(-Xc)-1.0+Xc)/(Xc*Xc);
106  S0cc=N[2]*Phi[2]*v[2]*Pcc;
107  Pcd=((1.0-exp(-Xc))/Xc)*((1.0-exp(-Xd))/Xd);
108  S0cd=(Phicd*vcd*Ncd)*Pcd;
109
110  S0da=S0ad;
111  S0db=S0bd;
112  S0dc=S0cd;
113  Pdd=2.0*(exp(-Xd)-1.0+Xd)/(Xd*Xd);
114  S0dd=N[3]*Phi[3]*v[3]*Pdd;
115  //icase was shifted to N-1 from the original code
116  switch(icase){
117  case 0:
118    S0aa=0.000001;
119    S0ab=0.000002;
120    S0ac=0.000003;
121    S0ad=0.000004;
122    S0bb=0.000005;
123    S0bc=0.000006;
124    S0bd=0.000007;
125    S0cd=0.000008;
126    break;
127  case 1:
128    S0aa=0.000001;
129    S0ab=0.000002;
130    S0ac=0.000003;
131    S0ad=0.000004;
132    S0bb=0.000005;
133    S0bc=0.000006;
134    S0bd=0.000007;
135    break;
136  case 2:
137    S0aa=0.000001;
138    S0ab=0.000002;
139    S0ac=0.000003;
140    S0ad=0.000004;
141    S0bc=0.000005;
142    S0bd=0.000006;
143    S0cd=0.000007;
144    break;
145  case 3:
146    S0aa=0.000001;
147    S0ab=0.000002;
148    S0ac=0.000003;
149    S0ad=0.000004;
150    S0bc=0.000005;
151    S0bd=0.000006;
152    break;
153  case 4:
154    S0aa=0.000001;
155    S0ab=0.000002;
156    S0ac=0.000003;
157    S0ad=0.000004;
158    break;
159  case 5:
160    S0ab=0.000001;
161    S0ac=0.000002;
162    S0ad=0.000003;
163    S0bc=0.000004;
164    S0bd=0.000005;
165    S0cd=0.000006;
166    break;
167  case 6:
168    S0ab=0.000001;
169    S0ac=0.000002;
170    S0ad=0.000003;
171    S0bc=0.000004;
172    S0bd=0.000005;
173    break;
174  case 7:
175    S0ab=0.000001;
176    S0ac=0.000002;
177    S0ad=0.000003;
178    break;
179  case 8:
180    S0ac=0.000001;
181    S0ad=0.000002;
182    S0bc=0.000003;
183    S0bd=0.000004;
184    break;
185  default : //case 9:
186    break;
187  }
188  S0ba=S0ab;
189  S0ca=S0ac;
190  S0cb=S0bc;
191  S0da=S0ad;
192  S0db=S0bd;
193  S0dc=S0cd;
194
195  Kaa=0.0;
196  Kbb=0.0;
197  Kcc=0.0;
198  Kdd=0.0;
199
200  Kba=Kab;
201  Kca=Kac;
202  Kcb=Kbc;
203  Kda=Kad;
204  Kdb=Kbd;
205  Kdc=Kcd;
206
207  Zaa=Kaa-Kad-Kad;
208  Zab=Kab-Kad-Kbd;
209  Zac=Kac-Kad-Kcd;
210  Zba=Kba-Kbd-Kad;
211  Zbb=Kbb-Kbd-Kbd;
212  Zbc=Kbc-Kbd-Kcd;
213  Zca=Kca-Kcd-Kad;
214  Zcb=Kcb-Kcd-Kbd;
215  Zcc=Kcc-Kcd-Kcd;
216
217  DenT=(-(S0ac*S0bb*S0ca) + S0ab*S0bc*S0ca + S0ac*S0ba*S0cb - S0aa*S0bc*S0cb - S0ab*S0ba*S0cc + S0aa*S0bb*S0cc);
218
219  T11= (-(S0bc*S0cb) + S0bb*S0cc)/DenT;
220  T12= (S0ac*S0cb - S0ab*S0cc)/DenT;
221  T13= (-(S0ac*S0bb) + S0ab*S0bc)/DenT;
222  T21= (S0bc*S0ca - S0ba*S0cc)/DenT;
223  T22= (-(S0ac*S0ca) + S0aa*S0cc)/DenT;
224  T23= (S0ac*S0ba - S0aa*S0bc)/DenT;
225  T31= (-(S0bb*S0ca) + S0ba*S0cb)/DenT;
226  T32= (S0ab*S0ca - S0aa*S0cb)/DenT;
227  T33= (-(S0ab*S0ba) + S0aa*S0bb)/DenT;
228
229  Y1=T11*S0ad+T12*S0bd+T13*S0cd+1.0;
230  Y2=T21*S0ad+T22*S0bd+T23*S0cd+1.0;
231  Y3=T31*S0ad+T32*S0bd+T33*S0cd+1.0;
232
233  X11=Y1*Y1;
234  X12=Y1*Y2;
235  X13=Y1*Y3;
236  X21=Y2*Y1;
237  X22=Y2*Y2;
238  X23=Y2*Y3;
239  X31=Y3*Y1;
240  X32=Y3*Y2;
241  X33=Y3*Y3;
242
243  ZZ=S0ad*(T11*S0ad+T12*S0bd+T13*S0cd)+S0bd*(T21*S0ad+T22*S0bd+T23*S0cd)+S0cd*(T31*S0ad+T32*S0bd+T33*S0cd);
244
245  m=1.0/(S0dd-ZZ);
246
247  N11=m*X11+Zaa;
248  N12=m*X12+Zab;
249  N13=m*X13+Zac;
250  N21=m*X21+Zba;
251  N22=m*X22+Zbb;
252  N23=m*X23+Zbc;
253  N31=m*X31+Zca;
254  N32=m*X32+Zcb;
255  N33=m*X33+Zcc;
256
257  M11= N11*S0aa + N12*S0ab + N13*S0ac;
258  M12= N11*S0ab + N12*S0bb + N13*S0bc;
259  M13= N11*S0ac + N12*S0bc + N13*S0cc;
260  M21= N21*S0aa + N22*S0ab + N23*S0ac;
261  M22= N21*S0ab + N22*S0bb + N23*S0bc;
262  M23= N21*S0ac + N22*S0bc + N23*S0cc;
263  M31= N31*S0aa + N32*S0ab + N33*S0ac;
264  M32= N31*S0ab + N32*S0bb + N33*S0bc;
265  M33= N31*S0ac + N32*S0bc + N33*S0cc;
266
267  DenQ1=1.0+M11-M12*M21+M22+M11*M22-M13*M31-M13*M22*M31;
268  DenQ2=  M12*M23*M31+M13*M21*M32-M23*M32-M11*M23*M32+M33+M11*M33;
269  DenQ3=  -M12*M21*M33+M22*M33+M11*M22*M33;
270  DenQ=DenQ1+DenQ2+DenQ3;
271
272  Q11= (1.0 + M22-M23*M32 + M33 + M22*M33)/DenQ;
273  Q12= (-M12 + M13*M32 - M12*M33)/DenQ;
274  Q13= (-M13 - M13*M22 + M12*M23)/DenQ;
275  Q21= (-M21 + M23*M31 - M21*M33)/DenQ;
276  Q22= (1.0 + M11 - M13*M31 + M33 + M11*M33)/DenQ;
277  Q23= (M13*M21 - M23 - M11*M23)/DenQ;
278  Q31= (-M31 - M22*M31 + M21*M32)/DenQ;
279  Q32= (M12*M31 - M32 - M11*M32)/DenQ;
280  Q33= (1.0 + M11 - M12*M21 + M22 + M11*M22)/DenQ;
281
282  S11= Q11*S0aa + Q21*S0ab + Q31*S0ac;
283  S12= Q12*S0aa + Q22*S0ab + Q32*S0ac;
284  S13= Q13*S0aa + Q23*S0ab + Q33*S0ac;
285  S14=-S11-S12-S13;
286  S21= Q11*S0ba + Q21*S0bb + Q31*S0bc;
287  S22= Q12*S0ba + Q22*S0bb + Q32*S0bc;
288  S23= Q13*S0ba + Q23*S0bb + Q33*S0bc;
289  S24=-S21-S22-S23;
290  S31= Q11*S0ca + Q21*S0cb + Q31*S0cc;
291  S32= Q12*S0ca + Q22*S0cb + Q32*S0cc;
292  S33= Q13*S0ca + Q23*S0cb + Q33*S0cc;
293  S34=-S31-S32-S33;
294  S41=S14;
295  S42=S24;
296  S43=S34;
297  S44=S11+S22+S33+2.0*S12+2.0*S13+2.0*S23;
298
299  Nav=6.022045e+23;
300  Lad=(L[0]/v[0]-L[3]/v[3])*sqrt(Nav);
301  Lbd=(L[1]/v[1]-L[3]/v[3])*sqrt(Nav);
302  Lcd=(L[2]/v[2]-L[3]/v[3])*sqrt(Nav);
303
304  Intg=Lad*Lad*S11+Lbd*Lbd*S22+Lcd*Lcd*S33+2.0*Lad*Lbd*S12+2.0*Lbd*Lcd*S23+2.0*Lad*Lcd*S13;
305
306  return Intg;
307
308
309/*  Attempts at a new implementation --- supressed for now
310#if 1  // Sasview defaults
311  if (icase <= 1) {
312    N[0]=N[1]=1000.0;
313    Phi[0]=Phi[1]=0.0000001;
314    Kab=Kac=Kad=Kbc=Kbd=-0.0004;
315    L[0]=L[1]=1.0e-12;
316    v[0]=v[1]=100.0;
317    b[0]=b[1]=5.0;
318  } else if (icase <= 4) {
319    Phi[0]=0.0000001;
320    Kab=Kac=Kad=-0.0004;
321    L[0]=1.0e-12;
322    v[0]=100.0;
323    b[0]=5.0;
324  }
325#else
326  if (icase <= 1) {
327    N[0]=N[1]=0.0;
328    Phi[0]=Phi[1]=0.0;
329    Kab=Kac=Kad=Kbc=Kbd=0.0;
330    L[0]=L[1]=L[3];
331    v[0]=v[1]=v[3];
332    b[0]=b[1]=0.0;
333  } else if (icase <= 4) {
334    N[0] = 0.0;
335    Phi[0]=0.0;
336    Kab=Kac=Kad=0.0;
337    L[0]=L[3];
338    v[0]=v[3];
339    b[0]=0.0;
340  }
341#endif
342
343  const double Xa = q*q*b[0]*b[0]*N[0]/6.0;
344  const double Xb = q*q*b[1]*b[1]*N[1]/6.0;
345  const double Xc = q*q*b[2]*b[2]*N[2]/6.0;
346  const double Xd = q*q*b[3]*b[3]*N[3]/6.0;
347
348  // limit as Xa goes to 0 is 1
349  const double Pa = Xa==0 ? 1.0 : -expm1(-Xa)/Xa;
350  const double Pb = Xb==0 ? 1.0 : -expm1(-Xb)/Xb;
351  const double Pc = Xc==0 ? 1.0 : -expm1(-Xc)/Xc;
352  const double Pd = Xd==0 ? 1.0 : -expm1(-Xd)/Xd;
353
354  // limit as Xa goes to 0 is 1
355  const double Paa = Xa==0 ? 1.0 : 2.0*(1.0-Pa)/Xa;
356  const double Pbb = Xb==0 ? 1.0 : 2.0*(1.0-Pb)/Xb;
357  const double Pcc = Xc==0 ? 1.0 : 2.0*(1.0-Pc)/Xc;
358  const double Pdd = Xd==0 ? 1.0 : 2.0*(1.0-Pd)/Xd;
359
360
361  // Note: S0ij only defined for copolymers; otherwise set to zero
362  // 0: C/D     binary mixture
363  // 1: C-D     diblock copolymer
364  // 2: B/C/D   ternery mixture
365  // 3: B/C-D   binary mixture,1 homopolymer, 1 diblock copolymer
366  // 4: B-C-D   triblock copolymer
367  // 5: A/B/C/D quaternary mixture
368  // 6: A/B/C-D ternery mixture, 2 homopolymer, 1 diblock copolymer
369  // 7: A/B-C-D binary mixture, 1 homopolymer, 1 triblock copolymer
370  // 8: A-B/C-D binary mixture, 2 diblock copolymer
371  // 9: A-B-C-D tetra-block copolymer
372#if 0
373  const double S0aa = icase<5
374                      ? 1.0 : N[0]*Phi[0]*v[0]*Paa;
375  const double S0bb = icase<2
376                      ? 1.0 : N[1]*Phi[1]*v[1]*Pbb;
377  const double S0cc = N[2]*Phi[2]*v[2]*Pcc;
378  const double S0dd = N[3]*Phi[3]*v[3]*Pdd;
379  const double S0ab = icase<8
380                      ? 0.0 : sqrt(N[0]*v[0]*Phi[0]*N[1]*v[1]*Phi[1])*Pa*Pb;
381  const double S0ac = icase<9
382                      ? 0.0 : sqrt(N[0]*v[0]*Phi[0]*N[2]*v[2]*Phi[2])*Pa*Pc*exp(-Xb);
383  const double S0ad = icase<9
384                      ? 0.0 : sqrt(N[0]*v[0]*Phi[0]*N[3]*v[3]*Phi[3])*Pa*Pd*exp(-Xb-Xc);
385  const double S0bc = (icase!=4 && icase!=7 && icase!= 9)
386                      ? 0.0 : sqrt(N[1]*v[1]*Phi[1]*N[2]*v[2]*Phi[2])*Pb*Pc;
387  const double S0bd = (icase!=4 && icase!=7 && icase!= 9)
388                      ? 0.0 : sqrt(N[1]*v[1]*Phi[1]*N[3]*v[3]*Phi[3])*Pb*Pd*exp(-Xc);
389  const double S0cd = (icase==0 || icase==2 || icase==5)
390                      ? 0.0 : sqrt(N[2]*v[2]*Phi[2]*N[3]*v[3]*Phi[3])*Pc*Pd;
391#else  // sasview equivalent
392//printf("Xc=%g, S0cc=%g*%g*%g*%g\n",Xc,N[2],Phi[2],v[2],Pcc);
393  double S0aa = N[0]*Phi[0]*v[0]*Paa;
394  double S0bb = N[1]*Phi[1]*v[1]*Pbb;
395  double S0cc = N[2]*Phi[2]*v[2]*Pcc;
396  double S0dd = N[3]*Phi[3]*v[3]*Pdd;
397  double S0ab = sqrt(N[0]*v[0]*Phi[0]*N[1]*v[1]*Phi[1])*Pa*Pb;
398  double S0ac = sqrt(N[0]*v[0]*Phi[0]*N[2]*v[2]*Phi[2])*Pa*Pc*exp(-Xb);
399  double S0ad = sqrt(N[0]*v[0]*Phi[0]*N[3]*v[3]*Phi[3])*Pa*Pd*exp(-Xb-Xc);
400  double S0bc = sqrt(N[1]*v[1]*Phi[1]*N[2]*v[2]*Phi[2])*Pb*Pc;
401  double S0bd = sqrt(N[1]*v[1]*Phi[1]*N[3]*v[3]*Phi[3])*Pb*Pd*exp(-Xc);
402  double S0cd = sqrt(N[2]*v[2]*Phi[2]*N[3]*v[3]*Phi[3])*Pc*Pd;
403switch(icase){
404  case 0:
405    S0aa=0.000001;
406    S0ab=0.000002;
407    S0ac=0.000003;
408    S0ad=0.000004;
409    S0bb=0.000005;
410    S0bc=0.000006;
411    S0bd=0.000007;
412    S0cd=0.000008;
413    break;
414  case 1:
415    S0aa=0.000001;
416    S0ab=0.000002;
417    S0ac=0.000003;
418    S0ad=0.000004;
419    S0bb=0.000005;
420    S0bc=0.000006;
421    S0bd=0.000007;
422    break;
423  case 2:
424    S0aa=0.000001;
425    S0ab=0.000002;
426    S0ac=0.000003;
427    S0ad=0.000004;
428    S0bc=0.000005;
429    S0bd=0.000006;
430    S0cd=0.000007;
431    break;
432  case 3:
433    S0aa=0.000001;
434    S0ab=0.000002;
435    S0ac=0.000003;
436    S0ad=0.000004;
437    S0bc=0.000005;
438    S0bd=0.000006;
439    break;
440  case 4:
441    S0aa=0.000001;
442    S0ab=0.000002;
443    S0ac=0.000003;
444    S0ad=0.000004;
445    break;
446  case 5:
447    S0ab=0.000001;
448    S0ac=0.000002;
449    S0ad=0.000003;
450    S0bc=0.000004;
451    S0bd=0.000005;
452    S0cd=0.000006;
453    break;
454  case 6:
455    S0ab=0.000001;
456    S0ac=0.000002;
457    S0ad=0.000003;
458    S0bc=0.000004;
459    S0bd=0.000005;
460    break;
461  case 7:
462    S0ab=0.000001;
463    S0ac=0.000002;
464    S0ad=0.000003;
465    break;
466  case 8:
467    S0ac=0.000001;
468    S0ad=0.000002;
469    S0bc=0.000003;
470    S0bd=0.000004;
471    break;
472  default : //case 9:
473    break;
474  }
475#endif
476
477  // eq 12a: \kappa_{ij}^F = \chi_{ij}^F - \chi_{i0}^F - \chi_{j0}^F
478  const double Kaa = 0.0;
479  const double Kbb = 0.0;
480  const double Kcc = 0.0;
481  //const double Kdd = 0.0;
482  const double Zaa = Kaa - Kad - Kad;
483  const double Zab = Kab - Kad - Kbd;
484  const double Zac = Kac - Kad - Kcd;
485  const double Zbb = Kbb - Kbd - Kbd;
486  const double Zbc = Kbc - Kbd - Kcd;
487  const double Zcc = Kcc - Kcd - Kcd;
488//printf("Za: %10.5g %10.5g %10.5g\n", Zaa, Zab, Zac);
489//printf("Zb: %10.5g %10.5g %10.5g\n", Zab, Zbb, Zbc);
490//printf("Zc: %10.5g %10.5g %10.5g\n", Zac, Zbc, Zcc);
491
492  // T = inv(S0)
493  const double DenT = (- S0ac*S0bb*S0ac + S0ab*S0bc*S0ac + S0ac*S0ab*S0bc
494                       - S0aa*S0bc*S0bc - S0ab*S0ab*S0cc + S0aa*S0bb*S0cc);
495  const double T11 = (-S0bc*S0bc + S0bb*S0cc)/DenT;
496  const double T12 = ( S0ac*S0bc - S0ab*S0cc)/DenT;
497  const double T13 = (-S0ac*S0bb + S0ab*S0bc)/DenT;
498  const double T22 = (-S0ac*S0ac + S0aa*S0cc)/DenT;
499  const double T23 = ( S0ac*S0ab - S0aa*S0bc)/DenT;
500  const double T33 = (-S0ab*S0ab + S0aa*S0bb)/DenT;
501
502//printf("T1: %10.5g %10.5g %10.5g\n", T11, T12, T13);
503//printf("T2: %10.5g %10.5g %10.5g\n", T12, T22, T23);
504//printf("T3: %10.5g %10.5g %10.5g\n", T13, T23, T33);
505
506  // eq 18e: m = 1/(S0_{dd} - s0^T inv(S0) s0)
507  const double ZZ = S0ad*(T11*S0ad + T12*S0bd + T13*S0cd)
508                  + S0bd*(T12*S0ad + T22*S0bd + T23*S0cd)
509                  + S0cd*(T13*S0ad + T23*S0bd + T33*S0cd);
510
511  const double m=1.0/(S0dd-ZZ);
512
513  // eq 18d: Y = inv(S0)s0 + e
514  const double Y1 = T11*S0ad + T12*S0bd + T13*S0cd + 1.0;
515  const double Y2 = T12*S0ad + T22*S0bd + T23*S0cd + 1.0;
516  const double Y3 = T13*S0ad + T23*S0bd + T33*S0cd + 1.0;
517
518  // N = mYY^T + \kappa^F
519  const double N11 = m*Y1*Y1 + Zaa;
520  const double N12 = m*Y1*Y2 + Zab;
521  const double N13 = m*Y1*Y3 + Zac;
522  const double N22 = m*Y2*Y2 + Zbb;
523  const double N23 = m*Y2*Y3 + Zbc;
524  const double N33 = m*Y3*Y3 + Zcc;
525
526//printf("N1: %10.5g %10.5g %10.5g\n", N11, N12, N13);
527//printf("N2: %10.5g %10.5g %10.5g\n", N12, N22, N23);
528//printf("N3: %10.5g %10.5g %10.5g\n", N13, N23, N33);
529//printf("S0a: %10.5g %10.5g %10.5g\n", S0aa, S0ab, S0ac);
530//printf("S0b: %10.5g %10.5g %10.5g\n", S0ab, S0bb, S0bc);
531//printf("S0c: %10.5g %10.5g %10.5g\n", S0ac, S0bc, S0cc);
532
533  // M = I + S0 N
534  const double Maa = N11*S0aa + N12*S0ab + N13*S0ac + 1.0;
535  const double Mab = N11*S0ab + N12*S0bb + N13*S0bc;
536  const double Mac = N11*S0ac + N12*S0bc + N13*S0cc;
537  const double Mba = N12*S0aa + N22*S0ab + N23*S0ac;
538  const double Mbb = N12*S0ab + N22*S0bb + N23*S0bc + 1.0;
539  const double Mbc = N12*S0ac + N22*S0bc + N23*S0cc;
540  const double Mca = N13*S0aa + N23*S0ab + N33*S0ac;
541  const double Mcb = N13*S0ab + N23*S0bb + N33*S0bc;
542  const double Mcc = N13*S0ac + N23*S0bc + N33*S0cc + 1.0;
543//printf("M1: %10.5g %10.5g %10.5g\n", Maa, Mab, Mac);
544//printf("M2: %10.5g %10.5g %10.5g\n", Mba, Mbb, Mbc);
545//printf("M3: %10.5g %10.5g %10.5g\n", Mca, Mcb, Mcc);
546
547  // Q = inv(M) = inv(I + S0 N)
548  const double DenQ = (+ Maa*Mbb*Mcc - Maa*Mbc*Mcb - Mab*Mba*Mcc
549                       + Mab*Mbc*Mca + Mac*Mba*Mcb - Mac*Mbb*Mca);
550
551  const double Q11 = ( Mbb*Mcc - Mbc*Mcb)/DenQ;
552  const double Q12 = (-Mab*Mcc + Mac*Mcb)/DenQ;
553  const double Q13 = ( Mab*Mbc - Mac*Mbb)/DenQ;
554  //const double Q21 = (-Mba*Mcc + Mbc*Mca)/DenQ;
555  const double Q22 = ( Maa*Mcc - Mac*Mca)/DenQ;
556  const double Q23 = (-Maa*Mbc + Mac*Mba)/DenQ;
557  //const double Q31 = ( Mba*Mcb - Mbb*Mca)/DenQ;
558  //const double Q32 = (-Maa*Mcb + Mab*Mca)/DenQ;
559  const double Q33 = ( Maa*Mbb - Mab*Mba)/DenQ;
560
561//printf("Q1: %10.5g %10.5g %10.5g\n", Q11, Q12, Q13);
562//printf("Q2: %10.5g %10.5g %10.5g\n", Q21, Q22, Q23);
563//printf("Q3: %10.5g %10.5g %10.5g\n", Q31, Q32, Q33);
564  // eq 18c: inv(S) = inv(S0) + mYY^T + \kappa^F
565  // eq A1 in the appendix
566  // To solve for S, use:
567  //      S = inv(inv(S^0) + N) inv(S^0) S^0
568  //        = inv(S^0 inv(S^0) + N) S^0
569  //        = inv(I + S^0 N) S^0
570  //        = Q S^0
571  const double S11 = Q11*S0aa + Q12*S0ab + Q13*S0ac;
572  const double S12 = Q12*S0aa + Q22*S0ab + Q23*S0ac;
573  const double S13 = Q13*S0aa + Q23*S0ab + Q33*S0ac;
574  const double S22 = Q12*S0ab + Q22*S0bb + Q23*S0bc;
575  const double S23 = Q13*S0ab + Q23*S0bb + Q33*S0bc;
576  const double S33 = Q13*S0ac + Q23*S0bc + Q33*S0cc;
577  // If the full S is needed...it isn't since Ldd = (rho_d - rho_d) = 0 below
578  //const double S14=-S11-S12-S13;
579  //const double S24=-S12-S22-S23;
580  //const double S34=-S13-S23-S33;
581  //const double S44=S11+S22+S33 + 2.0*(S12+S13+S23);
582
583  // eq 12 of Akcasu, 1990: I(q) = L^T S L
584  // Note: eliminate cases without A and B polymers by setting Lij to 0
585  // Note: 1e-13 to convert from fm to cm for scattering length
586  const double sqrt_Nav=sqrt(6.022045e+23) * 1.0e-13;
587  const double Lad = icase<5 ? 0.0 : (L[0]/v[0] - L[3]/v[3])*sqrt_Nav;
588  const double Lbd = icase<2 ? 0.0 : (L[1]/v[1] - L[3]/v[3])*sqrt_Nav;
589  const double Lcd = (L[2]/v[2] - L[3]/v[3])*sqrt_Nav;
590
591  const double result=Lad*Lad*S11 + Lbd*Lbd*S22 + Lcd*Lcd*S33
592                    + 2.0*(Lad*Lbd*S12 + Lbd*Lcd*S23 + Lad*Lcd*S13);
593
594  return result;
595*/
596}
Note: See TracBrowser for help on using the repository browser.