source: Sophya/trunk/Cosmo/SimLSS/cmvsinxsx.cc@ 3572

Last change on this file since 3572 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

File size: 5.6 KB
Line 
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
10#include "ntuple.h"
11#include "geneutils.h"
12/*
13...Check autour de zero
14> cmvsinxsx -n 4 1e-6,-0.1,0.1
15> cmvsinxsx -n 5 1e-6,-0.1,0.1
16...Check autour de Pi
17> cmvsinxsx -n 4 1e-6,3.041592659,3.241592659
18> cmvsinxsx -n 5 1e-6,3.041592659,3.241592659
19...Check autour de -Pi
20> cmvsinxsx -n 4 1e-6,-3.241592659,-3.041592659
21> cmvsinxsx -n 5 1e-6,-3.241592659,-3.041592659
22
23...Check longue echelle
24> cmvsinxsx -n 10 0.0001,-6.5,6.5
25> cmvsinxsx -n 11 0.0001,-6.5,6.5
26
27...Check sans plot
28> cmvsinxsx -n 100 0.00001,-6.5,6.5
29> cmvsinxsx -n 1000 0.00001,-6.5,6.5
30 */
31
32
33int main(int narg,char *arg[])
34{
35 double dt = 0.000001;
36 //double tmin = -0.1, tmax = 0.1;
37 double tmin = M_PI-0.1, tmax = M_PI+0.1;
38 unsigned long N = 4;
39 bool only_test = false;
40 double pr_test = 1.e99;
41 int nvec=0;
42 double veccent=0., vecmax = -2.;
43
44 //--- Read arguments
45 char c;
46 while((c = getopt(narg,arg,"htp:n:v:")) != -1) {
47 switch (c) {
48 case 'n' :
49 sscanf(optarg,"%lu",&N);
50 break;
51 case 't' :
52 only_test = true;
53 break;
54 case 'p' :
55 sscanf(optarg,"%lf",&pr_test);
56 break;
57 case 'v' :
58 sscanf(optarg,"%d,%lf",&nvec,&vecmax);
59 break;
60 case 'h' :
61 default :
62 cout<<"cmvsinxsx [-t] [-p eps_print] [-n N] [-v nv,(+-)vmax (rad)]"<<endl;
63 cout<<" [dt,tmin,tmax (rad)]"<<endl;
64 return -1;
65 }
66 }
67 if(optind<narg) sscanf(arg[optind],"%lf,%lf,%lf",&dt,&tmin,&tmax);
68
69 cout<<"N="<<N<<" dt="<<dt<<" tmin="<<tmin<<" tmax="<<tmax<<" rad"<<endl;
70 cout<<"only_test="<<only_test<<" pr_test="<<pr_test<<endl;
71 if(vecmax<0.) vecmax *= -M_PI;
72 cout<<"nv="<<nvec<<" vmax="<<vecmax<<" -> ["<<-vecmax/2<<","<<vecmax/2<<"]"<<endl;
73 if(tmax<=tmin) return -1;
74
75 //--- Create NTuple
76 const int nvar = 11;
77 const char *vname[nvar] = {"t","s","sn","sx","sx2","snx","snx2","asx","asx2","asnx","asnx2"};
78 double xnt[nvar];
79 NTuple nt(nvar,vname);
80
81 //--- Fill NTuple and do precision test
82 long n = 0;
83 double diffsx=0., diffsx2=0., diffsnx=0., diffsnx2=0.;
84 for(double t=tmin; t<tmax+dt/3.; t+=dt) {
85 xnt[0] = t;
86 xnt[1] = sin(t);
87 xnt[2] = sin(N*t);
88 xnt[3] = SinXsX(t);
89 xnt[4] = SinXsX_Sqr(t);
90 xnt[5] = SinNXsX(t,N);
91 xnt[6] = SinNXsX_Sqr(t,N);
92 xnt[7] = SinXsX(t,true);
93 xnt[8] = SinXsX_Sqr(t,true);
94 xnt[9] = SinNXsX(t,N,true);
95 xnt[10] = SinNXsX_Sqr(t,N,true);
96 if(!only_test) nt.Fill(xnt);
97
98 // les tests de difference maxi
99 double av;
100 if(xnt[0]>1e-15) {
101 double ref = xnt[1]/xnt[0];
102 av = fabs(xnt[3]-ref);
103 if(av>pr_test) printf("t=%.15e sx/x=%.15e, %.15e d=%g\n",t,xnt[3],ref,av);
104 if(av>diffsx) diffsx = av;
105 av = fabs(xnt[4]-ref*ref);
106 if(av>pr_test) printf("t=%.15e (sx/x)^2=%.15e, %.15e d=%g\n",t,xnt[4],ref*ref,av);
107 if(av>diffsx2) diffsx2 = av;
108 }
109 if(fabs(xnt[1])>1e-15) {
110 double ref = xnt[2]/xnt[1];
111 av = fabs(xnt[5]-ref);
112 if(av>pr_test) printf("t=%.15e snx/sx=%.15e, %.15e d=%g\n",t,xnt[5],ref,av);
113 if(fabs(av)>diffsnx) diffsnx = av;
114 av = fabs(xnt[6]-ref*ref);
115 if(av>pr_test) printf("t=%.15e (snx/sx)^2=%.15e, %.15e d=%g\n",t,xnt[6],ref*ref,av);
116 if(fabs(av)>diffsnx2) diffsnx2 = av;
117 }
118
119 n++;
120 }
121 cout<<"Number of entries = "<<n<<endl;
122 cout<<"Diff sx/x = "<<diffsx<<endl;
123 cout<<" (sx/x)^2 = "<<diffsx2<<endl;
124 //Attention, vers Pi c'est la precision machine sur sin(N*x)/sin(x) qui donne l'erreur
125 cout<<" sNx/x = "<<diffsnx<<" = "<<diffsnx/N<<" * "<<N<<endl;
126 cout<<" (sNx/x)^2 = "<<diffsnx2<<" = "<<diffsnx2/(N*N)<<" * "<<N<<" * "<<N<<endl;
127
128 //--- Fill vector for FFT
129 TVector<r_8> vsx,vsx2,vsnx,vsnx2;
130 if(nvec>1) {
131 vsx.ReSize(nvec); vsx2.ReSize(nvec); vsnx.ReSize(nvec); vsnx2.ReSize(nvec);
132 for(int i=0;i<nvec;i++) {
133 double t = veccent -vecmax/2. + i*vecmax/(double)nvec;
134 vsx(i) = SinXsX(t);
135 vsx2(i) = SinXsX_Sqr(t);
136 vsnx(i) = SinNXsX(t,N);
137 vsnx2(i) = SinNXsX_Sqr(t,N);
138 }
139 }
140
141 //--- Write PPF
142 POutPersist pos("cmvsinxsx.ppf");
143 if(!only_test) pos.PutObject(nt,"nt");
144 if(vsx.Size()>0) pos.PutObject(vsx,"vsx");
145 if(vsx2.Size()>0) pos.PutObject(vsx2,"vsx2");
146 if(vsnx.Size()>0) pos.PutObject(vsnx,"vsnx");
147 if(vsnx2.Size()>0) pos.PutObject(vsnx2,"vsnx2");
148
149 return 0;
150}
151
152/*
153openppf cmvsinxsx.ppf
154
155zone
156n/plot nt.s%t ! ! "connectpoints"
157n/plot nt.sn%t ! ! "connectpoints same red"
158
159#-------
160zone 1 3
161n/plot nt.sx%t ! ! "connectpoints"
162n/plot nt.asx%t ! ! "connectpoints same green"
163n/plot nt.sx-s/t%t fabs(t)>1e-15 ! "connectpoints"
164n/plot nt.sx-asx%t ! ! "connectpoints"
165
166#-------
167zone 1 3
168n/plot nt.sx2%t ! ! "connectpoints"
169n/plot nt.sx*sx%t ! ! "connectpoints same red"
170n/plot nt.asx2%t ! ! "connectpoints same green"
171n/plot nt.sx2-pow(s/t,2.)%t fabs(t)>1e-15 ! "connectpoints"
172n/plot nt.sx2-asx2%t ! ! "connectpoints"
173
174#-------
175zone 1 3
176n/plot nt.snx%t ! ! "connectpoints"
177n/plot nt.asnx%t ! ! "connectpoints same green"
178n/plot nt.snx-sn/s%t fabs(s)>1e-15 ! "connectpoints"
179n/plot nt.snx-asnx%t ! ! "connectpoints"
180
181#-------
182zone 1 3
183n/plot nt.snx2%t ! ! "connectpoints"
184n/plot nt.snx*snx%t ! ! "connectpoints same red"
185n/plot nt.asnx2%t ! ! "connectpoints same green"
186n/plot nt.snx2-pow(sn/s,2.)%t fabs(s)>1e-15 ! "connectpoints"
187n/plot nt.snx2-asnx2%t ! ! "connectpoints"
188
189#-------
190openppf cmvsinxsx.ppf
191
192zone 2 2
193n/plot vsx.val%n ! !
194n/plot vsx2.val%n ! !
195n/plot vsnx.val%n ! !
196n/plot vsnx2.val%n ! !
197
198zone
199fftforw vsx fvsx
200fftforw vsx2 fvsx2
201fftforw vsnx fvsnx
202fftforw vsnx2 fvsnx2
203
204zone
205n/plot fvsx.val%n ! ! "connectpoints"
206n/plot fvsx2.val%n ! ! "connectpoints"
207n/plot fvsnx.val%n ! ! "connectpoints"
208n/plot fvsnx2.val%n ! ! "connectpoints"
209
210*/
Note: See TracBrowser for help on using the repository browser.