source: Sophya/trunk/Cosmo/SimLSS/cmvtstpk.cc@ 3115

Last change on this file since 3115 was 3115, checked in by ansari, 19 years ago

Creation initiale du groupe Cosmo avec le repertoire SimLSS de
simulation de distribution de masse 3D des galaxies par CMV+Rz
18/12/2006

File size: 6.2 KB
RevLine 
[3115]1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <iostream>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <unistd.h>
9#include "timing.h"
10#include "histos.h"
11#include "tvector.h"
12#include "ntuple.h"
13#include "perandom.h"
14
15#include "constcosmo.h"
16#include "pkspectrum.h"
17#include "geneutils.h"
18
19void usage(void);
20void usage(void) {
21 cout<<"cmvtstpk -k npt,lkmin,lkmax -s scale zval"<<endl
22 <<" -k npt,lkmin,lkmax : les valeurs sont en log10"<<endl
23 <<" -s scale : on multiplie pkz par scale"<<endl;
24}
25
26int main(int narg,char *arg[])
27{
28 double ob0 = 0.0444356;
29 // -- WMAP
30 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
31 // -- ouvert matter only
32 //double h100=0.71, om0=0.3, or0=0., ol0=0.,w0=-1.;
33 // -- plat matter only
34 //double h100=0.71, om0=1., or0=0., ol0=0.,w0=-1.;
35
36 double ns = 1., as = 1.;
37
38 int npt = 1000;
39 double lkmin = -4., lkmax=2.;
40 double scale = 1.;
41
42 char c;
43 while((c = getopt(narg,arg,"hk:s:")) != -1) {
44 switch (c) {
45 case 'k' :
46 sscanf(optarg,"%d,%lf,%lf",&npt,&lkmin,&lkmax);
47 if(npt<=0) npt=1000;
48 if(lkmax<lkmin) {lkmin=-4.; lkmax=2.;}
49 break;
50 case 's' :
51 sscanf(optarg,"%lf",&scale);
52 break;
53 case 'h' :
54 default :
55 usage(); return -1;
56 }
57 }
58 double dlk=(lkmax-lkmin)/npt;
59
60 // Fill z value into list
61 double zval = 0.;
62 if(optind<narg) zval = atof(arg[optind]);
63
64 cout<<"lkmin="<<lkmin<<" lkmax="<<lkmax<<" npt="<<npt<<" dlk="<<dlk<<endl;
65 cout<<"scale="<<scale<<endl;
66 cout<<"zval="<<zval<<endl;
67
68 //--------------------------
69 InitialSpectrum pkini(ns,as);
70
71 TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
72 cout<<"kpeak="<<tf.KPeak()<<endl;
73 TransfertEisenstein tfnosc2(tf); tfnosc2.SetNoOscEnv(2);
74 TransfertEisenstein tfnosc1(tf); tfnosc1.SetNoOscEnv(1);
75 TransfertEisenstein tfnob(h100,om0,0.,T_CMB_Par,true);
76
77 GrowthFactor d1(om0,ol0);
78 cout<<"GrowthFactor: "<<d1(zval)<<endl;
79
80 PkSpectrum0 pk0(pkini,tf);
81 PkSpectrum0 pk0nosc2(pkini,tfnosc2);
82 PkSpectrum0 pk0nosc1(pkini,tfnosc1);
83 PkSpectrum0 pk0nob(pkini,tfnob);
84
85 PkSpectrumZ pkz(pk0,d1,zval);
86 PkSpectrumZ pkznosc2(pk0nosc2,d1,zval);
87 PkSpectrumZ pkznosc1(pk0nosc1,d1,zval);
88 PkSpectrumZ pkznob(pk0nob,d1,zval);
89
90 //--------------------------
91 Histo hd1(0.,1000.,10000); hd1.ReCenterBin();
92 FuncToHisto(d1,hd1,false);
93
94 Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
95 FuncToHisto(pkz,hpkz,true);
96 TVector<r_8> vpkz(npt);
97 FuncToVec(pkz,vpkz,lkmin,lkmax,true);
98
99 FunRan talea(hpkz,true);
100 Histo halea(hpkz); halea.Zero();
101 int nalea = 1000000;
102 for(int i=0;i<nalea;i++) halea.Add(talea.Random());
103 halea *= hpkz.Sum()/halea.Sum();
104
105 //--------------------------
106 const int n = 14;
107 char *vname[n] = {
108 "k","pkini",
109 "tf","pk0","pk",
110 "tfnosc2","pk0nosc2","pknosc2",
111 "tfnosc1","pk0nosc1","pknosc1",
112 "tfnob","pk0nob","pknob"
113 };
114 NTuple nt(n,vname);
115 double xnt[n];
116
117 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
118 double k = pow(10.,lk);
119 xnt[0] = k;
120 xnt[1] = pkini(k);
121 xnt[2] = tf(k);
122 xnt[3] = pk0(k);
123 xnt[4] = pkz(k,zval);
124 xnt[5] = tfnosc2(k);
125 xnt[6] = pk0nosc2(k);
126 xnt[7] = pkznosc2(k,zval);
127 xnt[8] = tfnosc1(k);
128 xnt[9] = pk0nosc1(k);
129 xnt[10] = pkznosc1(k,zval);
130 xnt[11] = tfnob(k);
131 xnt[12] = pk0nob(k);
132 xnt[13] = pkznob(k,zval);
133 nt.Fill(xnt);
134 }
135
136 //--------------------------
137 cout<<">>>> ASCII"<<endl;
138 if(1) {
139 FILE * fdata = fopen("cmvtstpk.data","w");
140 fprintf(fdata,"# z= %g : k(Mpc^-1) pkini, tf pk0 pkz, tfnosc2 pk0nosc2 pkznosc2, ",zval);
141 fprintf(fdata,"tfnosc1 pk0nosc1 pkznosc1, tfnob pk0nob pkznob\n");
142 for(double lk=lkmin;lk<lkmax+dlk/2.;lk+=dlk) {
143 double k = pow(10.,lk);
144 fprintf(fdata,"%e %e %e %e %e %e %e %e %e %e %e %e %e %e\n",
145 k,pkini(k),
146 tf(k),pk0(k),scale*pkz(k,zval),
147 tfnosc2(k),pk0nosc2(k),scale*pkznosc2(k,zval),
148 tfnosc1(k),pk0nosc1(k),scale*pkznosc1(k,zval),
149 tfnob(k),pk0nob(k),scale*pkznob(k,zval));
150 }
151 fclose(fdata);
152 }
153
154 //--------------------------
155 cout<<">>>> Ecriture"<<endl;
156 string tag = "cmvtstpk.ppf";
157 POutPersist pos(tag);
158 tag = "nt"; pos.PutObject(nt,tag);
159 tag = "hd1"; pos.PutObject(hd1,tag);
160 tag = "hpkz"; pos.PutObject(hpkz,tag);
161 tag = "vpkz"; pos.PutObject(vpkz,tag);
162 tag = "halea"; pos.PutObject(halea,tag);
163 return 0;
164}
165
166/*
167openppf cmvtstpk.ppf
168
169#### growth-factor
170zone
171n/plot hd1.log10(val)%log10(x) val>0.&&x>0. ! "nsta connectpoints"
172
173#### Spectre initial
174zone
175n/plot nt.log10(pkini)%log10(k) pkini>0. ! "nsta crossmarker3"
176
177#### fct de transfert
178zone
179n/plot nt.tf%log10(k) ! ! "nsta connectpoints"
180n/plot nt.tfnosc2%log10(k) ! ! "nsta connectpoints same red"
181n/plot nt.tfnosc1%log10(k) ! ! "nsta connectpoints same blue"
182n/plot nt.tfnob%log10(k) ! ! "nsta connectpoints same green"
183
184n/plot nt.tf/tfnosc2%log10(k) ! ! "nsta connectpoints red"
185n/plot nt.tf/tfnosc1%log10(k) ! ! "nsta connectpoints same blue"
186n/plot nt.tf/tfnob%log10(k) ! ! "nsta connectpoints same red"
187addline -10 1 10 1
188
189#### Spectre a z=0
190zone
191n/plot nt.pk0%log10(k) ! ! "nsta connectpoints"
192n/plot nt.pk0nosc2%log10(k) ! ! "nsta connectpoints same red"
193n/plot nt.pk0nosc1%log10(k) ! ! "nsta connectpoints same blue"
194n/plot nt.pk0nob%log10(k) ! ! "nsta connectpoints same green"
195
196# Check
197zone 2 2
198n/plot nt.pk0/pkini-tf*tf%log10(k) pkini>0 ! "nsta crossmarker3"
199n/plot nt.pk0nosc2/pkini-tfnosc2*tfnosc2%log10(k) pkini>0 ! "nsta crossmarker3"
200n/plot nt.pk0nosc1/pkini-tfnosc1*tfnosc1%log10(k) pkini>0 ! "nsta crossmarker3"
201n/plot nt.pk0nob/pkini-tfnob*tfnob%log10(k) pkini>0 ! "nsta crossmarker3"
202
203#### Spectre a z
204zone
205n/plot nt.pk%log10(k) ! ! "nsta connectpoints"
206n/plot nt.pknosc2%log10(k) ! ! "nsta connectpoints same red"
207n/plot nt.pknosc1%log10(k) ! ! "nsta connectpoints same blue"
208n/plot nt.pknob%log10(k) ! ! "nsta connectpoints same green"
209
210n/plot nt.pk/pknosc2%log10(k) ! ! "nsta connectpoints red"
211n/plot nt.pk/pknosc1%log10(k) ! ! "nsta connectpoints same blue"
212n/plot nt.pk/pknob%log10(k) ! ! "nsta connectpoints same green"
213addline -10 1 10 1
214
215#### Le spectre version Delta^2
216set D2 k*k*k*pk/(2*M_PI*M_PI)
217n/plot nt.$D2%log10(k) ! ! "nsta crossmarker3 connectpoints"
218
219#### Test des transferts dans Histo et TVector
220zone 1 2
221n/plot nt.pk%log10(k) ! ! "nsta crossmarker3"
222disp hpkz "same red"
223
224disp vpkz
225c++exec cout<<hpkz(0)<<" =?= "<<vpkz(0)<<endl;
226
227zone
228disp hpkz
229disp halea "same red"
230
231*/
Note: See TracBrowser for help on using the repository browser.