mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 23:31:12 +00:00
beginning to fold in HOD code with jeremy tinker's approval
This commit is contained in:
parent
d8108d3a8e
commit
44cd0eb71f
95 changed files with 21950 additions and 0 deletions
64
c_tools/hod/mnbrak.c
Normal file
64
c_tools/hod/mnbrak.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <math.h>
|
||||
#define NRANSI
|
||||
#include "nrutil.h"
|
||||
#define GOLD 1.618034
|
||||
#define GLIMIT 100.0
|
||||
#define TINY 1.0e-20
|
||||
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d);
|
||||
|
||||
void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc,
|
||||
double (*func)(double))
|
||||
{
|
||||
double ulim,u,r,q,fu,dum;
|
||||
|
||||
*fa=(*func)(*ax);
|
||||
*fb=(*func)(*bx);
|
||||
if (*fb > *fa) {
|
||||
SHFT(dum,*ax,*bx,dum)
|
||||
SHFT(dum,*fb,*fa,dum)
|
||||
}
|
||||
*cx=(*bx)+GOLD*(*bx-*ax);
|
||||
*fc=(*func)(*cx);
|
||||
while (*fb > *fc) {
|
||||
r=(*bx-*ax)*(*fb-*fc);
|
||||
q=(*bx-*cx)*(*fb-*fa);
|
||||
u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/
|
||||
(2.0*SIGN(FMAX(fabs(q-r),TINY),q-r));
|
||||
ulim=(*bx)+GLIMIT*(*cx-*bx);
|
||||
if ((*bx-u)*(u-*cx) > 0.0) {
|
||||
fu=(*func)(u);
|
||||
if (fu < *fc) {
|
||||
*ax=(*bx);
|
||||
*bx=u;
|
||||
*fa=(*fb);
|
||||
*fb=fu;
|
||||
return;
|
||||
} else if (fu > *fb) {
|
||||
*cx=u;
|
||||
*fc=fu;
|
||||
return;
|
||||
}
|
||||
u=(*cx)+GOLD*(*cx-*bx);
|
||||
fu=(*func)(u);
|
||||
} else if ((*cx-u)*(u-ulim) > 0.0) {
|
||||
fu=(*func)(u);
|
||||
if (fu < *fc) {
|
||||
SHFT(*bx,*cx,u,*cx+GOLD*(*cx-*bx))
|
||||
SHFT(*fb,*fc,fu,(*func)(u))
|
||||
}
|
||||
} else if ((u-ulim)*(ulim-*cx) >= 0.0) {
|
||||
u=ulim;
|
||||
fu=(*func)(u);
|
||||
} else {
|
||||
u=(*cx)+GOLD*(*cx-*bx);
|
||||
fu=(*func)(u);
|
||||
}
|
||||
SHFT(*ax,*bx,*cx,u)
|
||||
SHFT(*fa,*fb,*fc,fu)
|
||||
}
|
||||
}
|
||||
#undef GOLD
|
||||
#undef GLIMIT
|
||||
#undef TINY
|
||||
#undef SHFT
|
||||
#undef NRANSI
|
Loading…
Add table
Add a link
Reference in a new issue