void build_multi_fit_engine_cache(struct multi_fit_engine *f) { const int RI_IS_VARIABLE = 0; int nbmed = f->stack_list[0]->nb; int nblyr = nbmed - 2; size_t dmultipl = (f->system_kind == SYSTEM_REFLECTOMETER ? 1 : 2); /* We have just one cache for the fit engine. A cache for each sample is not needed because we assume that the RI are not fixed and so we don't do presampling of n values */ build_stack_cache(& f->cache, f->stack_list[0], f->spectra_list[0], RI_IS_VARIABLE); f->jac_th = gsl_vector_alloc(dmultipl * nblyr); switch(f->system_kind) { case SYSTEM_REFLECTOMETER: f->jac_n.refl = gsl_vector_alloc(2 * nbmed); break; case SYSTEM_ELLISS_AB: case SYSTEM_ELLISS_PSIDEL: f->jac_n.ell = cmpl_vector_alloc(2 * nbmed); default: /* */ ; } }
void test_elliss_deriv (enum se_type spkind, size_t _nb, const cmpl ns[], double phi0, const double ds[], double lambda, double anlz) { gsl_vector *jacob_th; cmpl_vector *jacob_n; struct aux_param p[1]; size_t j, nb = _nb; size_t nblyr = nb - 2; double *myds; cmpl *myns; ell_ab_t e; size_t noff; #define TEST_CHANNEL 1 printf ("LAMBDA: %f\n", lambda); jacob_th = gsl_vector_alloc (2 * nblyr); jacob_n = cmpl_vector_alloc (2 * nb); myds = emalloc (nblyr * sizeof(double)); myns = emalloc (nb * sizeof(cmpl)); mult_layer_se_jacob (spkind, nb, ns, phi0, ds, lambda, anlz, e, jacob_th, jacob_n); p->nb = nb; p->spkind = spkind; p->lambda = lambda; p->phi0 = phi0; p->anlz = anlz; p->ds = myds; p->ns = myns; p->thickness = 1; p->channel = TEST_CHANNEL; noff = (p->channel == 0 ? 0 : nblyr); for (j = 1; j < nb - 1; j++) { gsl_function F; double result, abserr; p->layer = j; F.function = & der_aux_f; F.params = p; memcpy (myds, ds, nblyr * sizeof(double)); memcpy (myns, ns, nb * sizeof(cmpl)); gsl_deriv_central (&F, ds[j-1], 1e-8, &result, &abserr); printf ("TH layer: %2i, numeric: %.6f, calcul.: %.6f, err: %f\n", j, result, gsl_vector_get (jacob_th, noff+j-1), abserr); } p->thickness = 0; p->channel = TEST_CHANNEL; noff = (p->channel == 0 ? 0 : nb); for (j = 0; j < nb; j++) { gsl_function F; double result, abserr; p->layer = j; F.function = & der_aux_f; F.params = p; memcpy (myds, ds, nblyr * sizeof(double)); memcpy (myns, ns, nb * sizeof(cmpl)); p->real_part = 1; gsl_deriv_central (&F, creal(ns[j]), 1e-8, &result, &abserr); printf ("Re{n} layer: %2i, numeric: %.6f, calcul.: %.6f, err: %f\n", j, result, creal(cmpl_vector_get (jacob_n, noff+j)), abserr); p->real_part = 0; gsl_deriv_central (&F, cimag(ns[j]), 1e-8, &result, &abserr); printf ("Im{n} layer: %2i, numeric: %.6f, calcul.: %.6f, err: %f\n", j, result, -cimag(cmpl_vector_get (jacob_n, noff+j)), abserr); } free (myds), free (myns); gsl_vector_free (jacob_th); cmpl_vector_free (jacob_n); }