/* * This file is part of libpsht. * * libpsht is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * libpsht is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with libpsht; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * libpsht is being developed at the Max-Planck-Institut fuer Astrophysik * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt * (DLR). */ /*! \file psht_test.c Accuracy test for libpsht's map analysis. This program first generates a_lm coefficients up to a user-specified lmax (with mmax=lmax); where applicable, the real and imaginary parts of the coefficients are uniform random numbers of the interval [-1;1[. Afterwards, the random a_lm are converted to a map. This map is analyzed (optionally using an iterative scheme with a user-supplied number of steps). After every iteration, the code then outputs the RMS of the residual a_lm (i.e. the difference between the current and original a_lm), divided by the RMS of the original a_lm, as well as the maximum absolute change of any real or imaginary part between the current and original a_lm. This operation can be performed for several different pixelisations: - a Gaussian with the minimal number of rings for exact analysis and a user-defined ring resolution - an ECP grid with the minimal number of rings for exact analysis and a user-defined ring resolution - a Healpix grid with a user-defined Nside parameter. The user can specify the spin of the desired transform. Copyright (C) 2006-2010 Max-Planck-Society \author Martin Reinecke */ #include #include #include "psht.h" #include "psht_geomhelpers.h" #include "psht_almhelpers.h" #include "c_utils.h" #include "walltime_c.h" static double drand (double min, double max) { return min + (max-min)*rand()/(RAND_MAX+1.0); } static void random_alm (pshtd_cmplx *alm, psht_alm_info *helper, int spin) { int l,m; for (m=0;m<=helper->mmax; ++m) for (l=m;l<=helper->lmax; ++l) { if ((lmaxdiff) maxdiff=fabs(x); if (fabs(y)>maxdiff) maxdiff=fabs(y); } sum=sqrt(sum/nalms); sum2=sqrt(sum2/nalms); printf("component %i: rms %e, maxerr %e\n",i, sum/sum2, maxdiff); } } static void map2alm_iter (psht_geom_info *tinfo, double **map, pshtd_cmplx **alm_orig, pshtd_cmplx **alm, int lmax, int mmax, ptrdiff_t npix, ptrdiff_t nalms, int spin, int niter) { psht_alm_info *alms; pshtd_joblist *joblist; int ncomp = (spin==0) ? 1 : 2; int iter,i; ptrdiff_t m; double timer; psht_make_triangular_alm_info(lmax,mmax,1,&alms); pshtd_make_joblist (&joblist); if (spin==0) pshtd_add_job_map2alm(joblist,map[0],alm[0],0); else pshtd_add_job_map2alm_spin(joblist,map[0],map[1],alm[0],alm[1],spin,0); timer=wallTime(); pshtd_execute_jobs (joblist, tinfo, alms); printf("wall time for map2alm: %fs\n",wallTime()-timer); pshtd_clear_joblist (joblist); measure_errors(alm_orig,alm,nalms,ncomp); for (iter=0; iter0) random_alm(alm[1],alms,spin); ALLOC2D(alm2,pshtd_cmplx,ncomp,nalms); printf ("\niteration 0:\n"); if (spin==0) pshtd_add_job_alm2map(joblist,alm[0],map[0],0); else pshtd_add_job_alm2map_spin(joblist,alm[0],alm[1],map[0],map[1],spin,0); timer=wallTime(); pshtd_execute_jobs (joblist, tinfo, alms); printf("wall time for alm2map: %fs\n",wallTime()-timer); pshtd_clear_joblist (joblist); map2alm_iter(tinfo, map, alm, alm2, lmax, mmax, npix, nalms, spin, niter); DEALLOC2D(map); DEALLOC2D(alm); DEALLOC2D(alm2); psht_destroy_alm_info(alms); pshtd_destroy_joblist(joblist); } int main(int argc, char **argv) { int lmax; int spin; int niter; psht_geom_info *tinfo; UTIL_ASSERT (argc==6, "usage: psht_test "); lmax=atoi(argv[2]); niter=atoi(argv[4]); spin=atoi(argv[5]); printf("Testing map analysis accuracy.\n"); printf("lmax=%d, %d iterations, spin=%d\n", lmax, niter, spin); if (strcmp(argv[1],"gauss")==0) { int nrings=lmax+1; int ppring=atoi(argv[3]); ptrdiff_t npix=(ptrdiff_t)nrings*ppring; printf("\nTesting Gaussian grid (%d rings, %d pixels/ring, %ld pixels)\n", nrings,ppring,(long)npix); psht_make_gauss_geom_info (nrings, ppring, 1, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,niter); psht_destroy_geom_info(tinfo); } else if (strcmp(argv[1],"ecp")==0) { int nrings=2*lmax+2; int ppring=atoi(argv[3]); ptrdiff_t npix=(ptrdiff_t)nrings*ppring; printf("\nTesting ECP grid (%d rings, %d pixels/ring, %ld pixels)\n", nrings,ppring,(long)npix); psht_make_ecp_geom_info (nrings, ppring, 0., 1, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,niter); psht_destroy_geom_info(tinfo); } else if (strcmp(argv[1],"healpix")==0) { int nside=atoi(argv[3]); ptrdiff_t npix; if (nside<1) nside=1; npix=12*(ptrdiff_t)nside*nside; printf("\nTesting Healpix grid (nside=%d, %ld pixels)\n", nside,(long)npix); psht_make_healpix_geom_info (nside, 1, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,niter); psht_destroy_geom_info(tinfo); } else UTIL_FAIL("unknown grid geometry"); return 0; }