<<

arXiv:astro-ph/0302138v2 27 Apr 2006 r e rgasta ol o eipoe.Ti is This improved. be not for could true that also programs few are the against Universe data. the CMB cos- of experimental many models enabled It compare has to that constant. mologists program well-tested cosmological very a a con- and is massless models neutrinos, matter, dark massive cosmological cold and flat spec- photons, calculate and and to baryons closed, used taining widely open, been for has availabletra It publicly [1]. been 1996 since has method, line- integration fast of-sight the implementing po- spectra, and anisotropy temperature larization (CMB) background microwave mic rmiglnug.TeC+lnug is language C++ The language. gramming ehv otdthe implementa- ported the variables have invariant we case gauge – our and models in quintessence – of tion code the of in modifications code the to to due changes locations. history separate similar expansion exam- numerous necessitate For cosmic energy modify. the dark and in oversee variations to difficult ple, quite is that eeindse yse.Sm epemyageta it that argue may not people Some hence is step. by of step (more redesigned objects . in in advantageous think very to is that soon), out this turns it and ented nstoisfrsailyfltuiess otiigdark containing universes, flat spatially the for in anisotropies lines the of most addition anything In changing can code without package. one it, the integrator, check in the to else If, trust one testable. not another independently does use is one ensures code instance, the however, for of design, part modular each that oriented object The ∗ iiain in limitations lcrncades [email protected] address: Electronic oee,fo h on fve fcd ein there design, code of view of point the from However, The nodrt drs hs hrcmnsadsimplify and shortcomings these address to order In cmbeasy h rga a o enrwitnfo cac,but scratch, from rewritten been not has program The www.cmbeasy.org MES: nOjc retdCd o h omcMcoaeB Microwave Cosmic the for Code Oriented Object an CMBEASY:: have cmbfast ntttfu hoeicePyi e Universit¨at Heidel der Physik f¨ur Theoretische Institut enrwitn obnfi rmteredesign. the from benefit to rewritten, been fue swl sfrisrcin rpia srinterfac user graphical a instruction, for as well background suppo as di quintessence use, of microwave and of substitution perturbations simple cosmic invariant for gauge empha allow the Both code, which new cosmology, for the in of tion design code the sketch We oriented www.cmbeasy.org. object an acltstetmeaueadpolarization and temperature the calculates independent cmbfast cmbfast ehv otdthe ported have We .INTRODUCTION I. optrpormfrcluaigcos- calculating for program computer cmbfast ti ahrmnlti code monolithic rather a is it : ol epeeti h e code. new the in present be could ..sm nnw rosand errors unknown some i.e. , eateto hsc srnm,H 17Wle Laborator Wilder 6127 HB Astronomy, & of Department akg oteC+pro- C++ the to package cmbfast atot olg,Hnvr H075 S and USA 03755, NH Hanover, College, Dartmouth akg oteC+pormiglnug oproduce to language programming C++ the to package object ihe Doran Michael ori- eg hlspewg1,610Hiebr,Germany Heidelberg, 69120 16, Philosophenweg berg, x neplt,ie give i.e. interpolate, h vlto qain,pes e h documentation the see please www.cmbeasy.org. on equations, evolution the fte soeojc.A neape e sdiscuss us let example, of an set As discrete a think Given object. to sensible one splines. is as it them that connected, of tightly so are data oti sn xmlsfo h code. the from examples of using design this the do to turning before gramming h aeo srdfie ye,teseicvralsare variables specific In the with numbers. types, objects. variables complex user-defined called arrays, many of floats, be case the e.g. can type, there same type, the data any with uto oprubto hoyadCBpyisusing physics CMB of and conventions theory the perturbation Computing to documen- duction the while C. II D, for II section section tation in in discussed is discussed precision is of interface design The user cosmology. in beasy use its and gramming adapted easily cosmology. is in code problems his- new modular equation-of-state to the an Furthermore, or specify tory. implemented, may models quintessence. one field or field alternatively constant scalar dark three cosmological The are a There neutrinos. be and can baryons energy matter, dark energy, httesmln sdneeog,abtayfunctions arbitrary enough, dense is sampling the that i +1 ut fe,sm aaadfntosatn nthe on acting functions and data some often, Quite ebifl nrdc h ocp fojc retdpro- oriented object of concept the introduce briefly We nC+ ls saue-enddt ye[] As [2]. type data user-defined a is class a C++, In ntenx eto IAw xli betoine pro- oriented object explain we A II section next the In n corresponding and ∗ savailable. is e eetcsooia oesadgauges. and models cosmological fferent thsbe de otecd.Frease For code. the to added been has rt speetdi eto IB hl h graphical the while B, II section in presented is cmbeasy iigtebnfiso betorienta- object of benefits the sizing h oei vial at available is code The . I H CODE THE II. .Encapsulation 1. cmbeasy sitoue nI .Fra intro- an For E. II in introduced is f .Objects A. ( x f o any for ) ( x i = ) y, swl sasmayof summary a as well as , y i n piecnsmoothly can spline a , x cmbeasy points ∈ ackground [ x 0 x , cmbeasy x , n i .Provided ]. with x We . cm- i < 2

gram).1 The class (in our case) called Spline, can hence be viewed as yet another data type, with no more book- keeping needed than say for a floating point number. To illustrate this, let us discuss the visibility function g ≡ κ˙ exp(κ(τ) − κ(τ0)), where κ(τ) is the optical depth. Its typical shape is depicted in Figure 1, and its peak de- fines the epoch of last scattering. As soon as the Spline called visibility has been given the data, its maximum can be determined by a single line of code: tau ls = visibility.maximum();

Here, the function maximum() acts on the visibility. The important point to notice is that all functions defined in the Spline class are immediately available to everyone who uses Splines. So, whenever one needs to find the maximum, integrate a spline, calculate the convolution of two Splines etc, this can be done using very few lines of code: the functionality is fully encapsulated in the im- FIG. 1: The visibility g ≡ κ˙ exp(κ(τ) − κ(τ0)) as a function plementation of the Spline class. Any increase in perfor- of conformal time τ in Mpc. Its peak at about τ ≈ 300 Mpc mance or sophistication of the Spline class immediately defines the epoch of last scattering. Before the visibility func- translates over to all Splines used in the program. tion peaks, photons are very likely to scatter again until the Universe becomes translucent. After the peak, photons do not scatter at a substantial rate. It is thus the balance be- tween frequent scattering and sufficiently low optical depth 2. Inheritance that will give the largest contribution towards the anisotropy today. And this fact is exactly encoded in g. Tightly connected to the fact that data and methods are combined within one object, is the concept of in- heritance, which proves very powerful in cosmology. A class can inherit from another class (in this context called base class). All variables and the full functionality that may be described by a spline for all practical purposes. the base class implements are instantly available to the 2 This is widely used in cmbfast. For instance, the Cl’s inheriting class, called sub-class. The sub-class can then are calculated only every 50 l-values for l > 200. As the re-implement functions of the base class to provide a dif- spectrum is very smooth, this still gives a precise result. ferent functionality, or add new functions and variables. The important point to note is that all classes deriving Now, the function describing the photon visibility (see from the same base class necessarily need to provide all also Figure 1), calculated in the part of the code that the functions the base class provides. Hence, whenever tracks the thermal history of the Universe, can be used the code uses the base class, one can substitute an inher- to define a spline. Without object orientation, one would iting class for the base class by simply changing one line need to keep track of various variables, most notably ar- of code. rays for the x, y data and derivatives needed for spline in- As an illustration, let us look at the Perturbation terpolation. Also, in order to assure quick access within class of cmbeasy which is designed to evolve the pertur- the spline data table, one either needs to know the precise bation equations for one k-mode through conformal time layout of the data arrays (cmbfast does this), or even and calculate the anisotropy sources. The Perturbation more variables (storing for instance the last interpolation class defines functions to do these calculations which x value) would be necessary. In total, this sums up to a lot of bookkeeping for a conceptually simple entity like a spline. 1 We usually denote here (and in the code) classes with capital Alternatively, one may define a class holding all the first letter. In some cases where there is only one object of a necessary variables a spline needs, together with defi- class used in the code, we denote the object with the same name as the class, but with lower case initial letter. Hence, the line nitions of an interface with which other parts of the cosmos program can access and manipulate the spline data. Cosmos ; An object behaves as described by the corresponding creates an object ‘cosmos’ of the class ‘Cosmos’. 2 This is as if a child was born with the whole knowledge of its class. There can be an arbitrary number of objects parents. No training and learning would be necessary. It could of a certain class (just like there is one floating point instantly go and increase its capabilities starting from the level type float, but many variables of type float in a pro- of its parents. 3 other parts of the program can be sure to find imple- mented in all sub-classes. In practice, there are four classes that inherit from it, for perturbations in gauge- invariant variables and in synchronous gauge both with and without quintessence (see also Figure 2). From the point of view of the rest of the program, all of them are equally well suited.3 Hence, when given a Perturbation object, one may e.g. ask it to initialize the perturbation variables: perturbation->initialScalarPerturbations(); Spline Yet, depending on the specific sub-class the object be- longs to 4, the implementation of initialScalarPerturba- tions() and hence the code executed will be different. Technically this is called polymorphism. ttings, or e.g. the MiscMath class providing turbation equations are encapsulated in the TensorIntegrator oking Cosmos, the Perturbations and Integrators is

B. Design MathObject for technical reasons. The Cosmos class

There are roughly three main steps needed to cal- culate the CMB anisotropy spectrum within the line

of sight strategy: (1) solve the expansion and thermal ScalarIntegrator background evolution, (2) propagate the perturbation equations in Fourier space, (3) map the temperature anisotropy onto the sky today. In each step, several classes work together. To illustrate the hierarchy of the most important classes, an overview is given in Figure 2. The core part of the package is the CmbCalc class. It is the scheduler calling other objects to complete all three steps. So let us turn to step (1), the expansion history of the universe. MathObject QuintCosmos

1. The background evolution lasses, e.g. the ControlPanel, which holds commonly used se ng subclasses such as QuintCosmos for quintessence. The per asses is therefore unproblematic. The central instance inv The Cosmos class is the central instance providing package. All classes dealing with mathematics inherit from background quantities like the energy densityρ ¯(τ) of all species etc. This centralization of the background evolu- tion within the Cosmos class facilitates the modification Invariant of the code significantly. A different background cosmol- cmbeasy ogy (such as quintessence) can be implemented by just inheriting from Cosmos and re-implementing the expan- sion history part of the code.5 For most other objects in

the code, it makes no difference exactly what caused the Perturbation Cosmos CmbCalc Integrator universe to expand, as long as they can rely on Cosmos or any sub-class to provide access to the expansion his- tory. Both the expansion and the thermal history are

computed at the beginning of the calculation and stored Synchronous in splines. QuintSynchronous QuintInvariant

3 Except for the fact that if one wants quintessence, the perturba- tion class should of course support it. 4 Representing the gauge choice and quintessence support 5 FIG. 2: Hierarchy of the main classes of the calculates the background evolution and can be extended usi low-level mathematical functions. Perturbation class. Implementing different gauges as subcl All in all 800 lines of a total of 2500 lines of Cosmos. the CmbCalc class. Not shown are several (sometimes small) c 4

2. Propagation in k-space the same interval (or close to it). Secondly, many splines with exactly the same x-data are evaluated at the same All fluctuation equations are handled by x. For instance, the r.h.s of the perturbation equations Perturbation and its sub-classes. Its most promi- need background quantities all at the same τ. As all nent function is propagateScalar(τ1, τ2) which background quantities get their data at the same τi in evolves the perturbations from conformal time τ1 to τ2. Cosmos, they necessarily share the same x-data. There- fore, some parts of the interpolation formulae have to be For numerical stability, one usually treats the era of 7 tight coupling between baryons and photons differently. computed only once for each τ. In addition, finding the However, this results in a non-analytic jump in the r.h.s position of the interpolation interval is simple: it will be τ of the perturbation equations at τtc. Some integrators the same for the same . for ordinary differential equations get confused by this. To accommodate for these groups of splines and Therefore, propagateScalar() will determine if the caching, splines come in two flavors: with and without its jump occurs within [τ1, τ2] and if so, integrate up to τtc, own x-data. While a spline with its own x-data can live 6 make a tiny jump and integrate on till τ2. At the end on its own, a spline without x-data can only be created if of each propagation, the sources of cmb anisotropies are a “mother” spline providing the x-data is given upon the calculated by the scalarSources() function. creation of the “child” spline. Within these “families” of shared x-data, interpolation at the same x is particularly fast. 3. The Cl’s Not only must a spline be fast, it must also be robust. Hence, a spline will allocate more memory if needed8, The convolution of the sources with the Bessel func- check that no access to data occurs outside its bound, tions, as well as the final k-integration are performed check that all data is ordered xi < xi+1 and make sure in the ScalarIntegrator sub-class. In contrast to cmb- that the interpolation tables have been built before any fast ′ , we formulate the convolution with the jls as an or- interpolation takes place. Splines can easily be visual- dinary differential equation (ODE). In fact, the Spline ized. To write the data9 to a file, simply call class provides the convolution functionality. If higher precision in this step is wanted, one may simply in- myspline.dump("filename") crease the desired precision for Spline, which will pass The anisotropy sources, are evaluated on a {k, τ} grid. this through to the integrator of ODE’s. As far as the For the final τ and k integration, one needs to interpolate k-integration is concerned, we stick to the interpolation cmbfast at intermediate points. This is conveniently done using points of . We have written two other imple- the class SplineWeb. It is essentially an array of Splines, mentations of ScalarIntegrator, although none could cmbfast one for each k and one for each τ value. If one needs to compete with ’s speed. Furthermore, no gain in interpolate at a given k value, one can ask SplineWeb to accuracy justifying the speed tradeoff was found. As far return a Spline with x-data in the τ direction: as the k-integration is concerned, a fast and independent realization would be desirable. With the high level fea- spline at k = web.createAlongY(k); tures of C++, algorithms that seem hard to implement in other languages may be feasible. This is used to get the splines which are convoluted with the Bessel functions. It is also very convenient for mak- ing slices through the cold power spectrum 4. Little helpers (at either fixed k or τ). Given for instance the cold dark matter SplineWeb power, one can dump it to a file: The most valuable class assisting the computation may power.dumpAlongX(τ,"filename"); be Spline. As splines are used all over the code, and quite often in time-critical environments, the main design The above command would save the spectrum at arbi- goal has been speed. In order to perform a spline inter- trary conformal time τ to disk. polation at x, one needs to find the interval x ∈ [xi, xi+1]. There are some more of these “helpers”, most of them cmbfast While hard-wires the size and layout of the xi- small classes that sometimes make life much easier. The data, this has not been an option for a versatile spline last one we will introduce here is Anchor which keeps implementation. Yet, in all time critical situations within track of objects that are dynamically created (as are our calculation, two facts come to the rescue: Firstly, in- many splines). The objects it is asked to keep track of terpolations occur in order and close to the last interpo- lation. Hence, the next value of x is likely to lie within

7 With “once”, we mean until interpolation is requested for a dif- ferent τ. 6 More specific, it adds ∆τ, such that for double precision variables 8 and free unused memory τ 1 τ τ 9 tc + 2 ∆ = tc. and interpolated values, if desired 5

ily, there is the very sophisticated and publicly available ‘Qt’ library [8] with which the creation of a GUI is fa- cilitated. Its object oriented C++ design is a perfect match for the cmbeasy package. There is therefore an executable program called ‘cmbeasy’ giving interactive access to almost the full capabilities of the package, in- cluding quintessence. As is seen from Figure 3, the spec- tra are visualized in separate plots arranged in a so called Tab-Widget.10 One can for instance zoom in, select and save curves or print the plot.

D. Computing precision

Comparing the results from cmbfast to those ob- tained from cmbeasy, one generally notes accordance to better than 0.5% (see also Figure 4). In principle, the line of sight algorithm is equivalent to FIG. 3: Graphical user interface (GUI) for cmbeasy. evolving a large hierarchy of multipoles. In practice, as one truncates the hierarchy in the line of sight approach at some low l, there is a reflection of power after the higher multipoles gradually build up. However, as by are deleted by it on demand, or when the Anchor object far the largest contribution towards the anisotropy oc- itself is deleted. Therefore, it greatly simplifies memory curs around recombination (when the higher multipoles handling and prevents memory leaks. are still small), this does not spoil the result dramati- cally. Yet, to check this, one may increase the number of multipoles involved. This is true both for cmbfast and cmbeasy 5. Quintessence Implementation . Within cmbeasy, there are five instances in which the precision may be increased. In three of the five cases, The different background evolution of quintessence [3, changing one variable suffices. The first case is the back- 4, 5] scenarios is implemented using the QuintCosmos and ground evolution. Here one may want to increase (or the Quintessence class. Each subclass of Quintessence decrease) the precision requested from the ODE integra- corresponds to a certain model, such as the exponen- tor. During perturbation evolution in k-space, the preci- tial potential [3, 4, 6], inverse power law [4], leaping sion requirement given to Perturbation can be changed kinetic term [7] etc. Certainly, a more monolithic de- in a similar manner. The same is true for the convo- sign with the quintessence models implemented in the lution of the sources with the Bessel functions, taking QuintCosmos class would have been possible. However, place in ScalarIntegrator. Finally, and a bit more we believe that the details of a model are best kept to a difficult, one may change the number and position of class of its own. For instance tuning model parameters ϕ k-values contributing towards the k-integration. This in order to get the right amount of Ω0 is different for can be done by modifying Integrator, the base class each model and a monolithic design would have to call of ScalarIntegrator. Alternatively, one could devise a differently named functions for different models. Using different implementation for the k-integration11. Finally, sub-classing, QuintCosmos (and Perturbation) always one may increase the number of l’s at which the Cl’s are calls functions with the same argument and name for calculated. all models. Yet, as the object implementing the func- tion differs for each model, the code executed by call- ing the function can be totally different. Thus, a new E. Documentation quintessence model can be implemented by simply sub- classing Quintessence and implementing a minimal set of functions, such as one for the scalar field potential. Using the doxygen program, the documentation is automatically generated from the source code of the cm- beasy package. In its html version, it is interactively C. Graphical User Interface

For educational purposes and also to simplify the pa- 10 A widget is a part of a user interface that can interact. Examples rameter input and subsequent visualization of results, a are buttons, sliders, etc. graphical user interface (GUI) is of great value. Luck- 11 i.e. a new sub-class of Integrator 6

code. As cosmological theory reaches for a new level of precision to match the new generation of experiments, map [9], planck [10] and other experiments will soon put our predictions and hypotheses to the test, so future work will seek to improve the accuracy of the code. (At the present time, cmbeasy and the standard cmbfast are generally in agreement to better than 0.5%.) The modular design allows one to more easily develop and build upon cmbeasy, to implement new cosmolog- ical models and include more physics. As our theoret- ical cosmological models are a work-in-progress — as CMB data comes in — so are our tools for modeling the Universe. And so it makes sense to use a program design which makes this development easy. Hence, the functional blocks used in cmbeasy considerably reduce the time to implement new cosmological models. For most purposes, a new model can be achieved by sub- classing from existing solutions, thus eliminating the need to rewrite large parts of the code. Furthermore, new Λ FIG. 4: Temperature anisotropy spectrum for h = 0.65, Ω0 = modules can be easily introduced to carry out calcula- b 2 c − Λ − b 0.6, Ω0 h = 0.02, Ω0 = 1 Ω0 Ω0 obtained from cmbfast. tions that rely on the linear perturbation spectrum. Ex- The relative deviation ∆Cl/Cl of cmbeasy’s synchronous amples include lensing, secondary sources in the CMB, (long dashed line) and gauge invariant (solid line) solution cmbfast reionization, and cross-correlation with other tracers of with respect to the original spectrum are also given. large scale structure. The accordance of all spectra is always better than 1%. In cmbeasy the gauge invariant case, both the background and perturba- An additional benefit of the package is the tion evolution as well as the Cl integration are entirely inde- graphical front-end. As we have described, the GUI al- pendent of the cmbfast code. However, they use the same lows a user to visually dial through a range of parameters. thermal history algorithm that should in principle be inde- We expect that this functionality will be useful for devel- pendently implemented for cross checks. oping understanding and intuition for CMB physics and cosmological models. As stated at the outset, there is, perhaps, no program design that could not be improved. However, we hope navigable and includes the full source code. Due to the that cmbeasy will serve the cosmology community well. automatic generation, the documentation and the code are naturally synchronized. Instructions for setting up and running the program are available in this html doc- umentation. In addition, a postscript version of the doc- Acknowledgments umentation is generated. I would like to thank Luca Amendola and Ruth Dur- rer for their help, Uro˜sSeljak and Matias Zaldarriaga for III. CONCLUSIONS cmbfast and their permission to distribute cmbeasy under its new name. I would like to thank R. R. Cald- We have devised an object oriented code for calculating well, Martin Kunz, Christian M¨uller, Gregor Sch¨afer cosmic microwave background anisotropies. The main and C. Wetterich for useful discussions. Finally I would benefits of this code derive from its modularity. like to thank the free software community for their ex- The modular design allows one to test and refine each cellent compilers, libraries and desktop environments. part of cmbeasy individually. Different modules, for This work was supported by NSF grant PHY-0099543 different numerical methods and theoretical approaches, at Dartmouth and PHY-9907949 at the KITP and the can easily be switched. This feature should prove ex- Graduiertenkolleg des Instituts f¨ur Theoretische Physik tremely useful in the development and refinement of the der Universit¨at Heidelberg.

[1] U. Seljak and M. Zaldarriaga, Astrophys. J. 469 (1996) [4] B. Ratra and P. J. Peebles, Phys. Rev. D 37 (1988) 3406. 437 [arXiv:astro-ph/9603033]. [5] R. R. Caldwell, R. Dave and P. J. Steinhardt, Phys. Rev. [2] B. Stroustrup, The C++ Programming language, Lett. 80 (1998) 1582 [astro-ph/9708069]. Addison-Wesley, Reading, USA (1997) [6] P. J. Peebles and B. Ratra, Astrophys. J. 325 (1988) L17. [3] C. Wetterich, Nucl. Phys. B 302 (1988) 668. [7] Hebecker, A., Wetterich, C., 2001, Phys. Lett. B, 497, 7

281 [hep-ph/0008205] [10] http://astro.estec.esa.nl/SA-general/Projects/Planck/ [8] Qt-library, Trolltech, Oslo, www.trolltech.com [9] http://map.gsfc.nasa.gov/