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