Allink  v0.1
ElPolyProfile.cpp
00001 #include "ElPoly.h"
00002 
00003 int ElPoly::Temperature(int NBin,int Coord){
00004   double *dDensity;
00005   dDensity = (double *)malloc(NBin*sizeof(double));
00006   for(int v=0;v<NBin;v++){
00007     dDensity[v] = 0.;
00008   }
00009   FILE *FileToWrite = fopen("Temperature.dat","w");
00010   for(int f=NFile[0];f<NFile[1];f++){
00011     Processing(f);
00012     if(OpenRisk(cFile[f],BF_NANO)==0)return 0;
00013     //TemperatureProfile(NBin,Coord);
00014     for(int v=0;v<NBin;v++){
00015       //dDensity[v] += dPoint[v];
00016     }
00017   }
00018   printf("\n"); 
00019   for(int v=0;v<NBin;v++){
00020     fprintf(FileToWrite,"%lf \n",dDensity[v]/(double)(NFile[1] - NFile[0]));
00021   }
00022   //FileToWrite = fopen(OutFile,"w");
00023   return 0;
00024 }
00025 int ElPoly::NanoParticle(int NBin){
00026   //SetEdge(.5*sqrt(SQR(pEdge(CLat1))+SQR(pEdge(CLat2))),3);
00027   SetEdge(.5*MIN(pEdge(CLat1),pEdge(CLat2)),3);
00028   int NType = 2;
00029   double *dDensity = (double *)calloc(NType*NBin,sizeof(double));
00030   double *dRad = (double *)calloc(NType*NBin,sizeof(double));
00031   double *ThickProf = (double *)calloc(NType*NBin,sizeof(*ThickProf));
00032   double *CountCh = (double *)calloc(NType*NBin,sizeof(double));
00033   double *CountPart = (double *)calloc(NBin,sizeof(double));
00034   double *AngleProf = (double *)calloc(2*NBin,sizeof(double));
00035   double *VolEl = (double *)calloc(NBin,sizeof(double));
00036   double *VelDistr = (double *)calloc(NBin*2,sizeof(double));
00037   double *DisplRad = (double *)calloc(NBin*2,sizeof(double));
00038   double *DisplTheta = (double *)calloc(NBin*2,sizeof(double));
00039   double *E2E = (double *)calloc(NBin*2,sizeof(double));
00040   double *HFluct = (double *)calloc(NBin*2,sizeof(double));
00041   CHAIN *Ch2 = (CHAIN *)calloc(pNChain(),sizeof(CHAIN));
00042   Vettore Directive(3);
00043   Vettore Axis(3);
00044   Vettore ZedDir(3);
00045   for(int d=0;d<3;d++) ZedDir.Set(0.,d);
00046   ZedDir.Set(1.,CNorm);
00047   VolumeCircSlab(VolEl,NBin);
00048   for(int f=NFile[0];f<NFile[1];f++){
00049     Processing(f);
00050     if(OpenRisk(cFile[f],BF_CHAIN)) return 0;
00051     //ChainDiffusion(DIFF_LATERAL,ChDiff);
00052     //Sum radial profile------------------------------------
00053     for(int b=0;b<pNBlock();b++){
00054       int IfAdded = 0;
00055       if(!strncmp(Block[b].Name,"PEP",3) ) continue;
00056       for(int p=Block[b].InitIdx,link=0;p<Block[b].EndIdx;p++){
00057    if(pPos(p,CNorm) > pNanoPos(0,CNorm) + Nano->Rad*.5) continue;
00058    if(pPos(p,CNorm) < pNanoPos(0,CNorm) - Nano->Rad*.5) continue;
00059    double RadDist = sqrt( SQR(pPos(p,CLat1)-pNanoPos(0,CLat1)) + SQR(pPos(p,CLat2)-pNanoPos(0,CLat2)) );
00060    double Zed = pPos(p,CNorm);
00061    int vr = (int)(RadDist/pEdge(3)*NBin);
00062    if(vr < 0 || vr >= NBin) continue;
00063    int t = 0;
00064    if(CHAIN_IF_TYPE(Ch[pType(p)].Type,CHAIN_ADDED) ) t = 1;
00065    dRad[vr*NType+t] += 1.;
00066    CountPart[vr] += 1.;
00067       }
00068     }
00069     // DensityProfile(3,NBin,NType,dDensity);
00070     // for(int v=0;v<NBin;v++){
00071     //   for(int t=0;t<NType;t++){
00072     //   dRad[v*NType+t] += dDensity[v*NType+t];
00073     //   dDensity[v*NType+t] = 0.;
00074     //   }
00075     // }
00076     //Sum thickness profile--------------------------------
00077     for(int b=0,cOff=0;b<pNBlock();cOff+=pNChain(b++)){
00078       if(!strncmp(Block[b].Name,"PEP",3)){
00079    continue;
00080       }
00081       for(int c=cOff;c<cOff+pNChain(b);c++){
00082    double RelPos[3];
00083    for(int d=0;d<3;d++){
00084      RelPos[d] = Ch[c].Pos[d] - pNanoPos(0,d);
00085      RelPos[d] -= floor(RelPos[d]*pInvEdge(d) + .5)*pEdge(d);
00086      Directive.Set(RelPos[d],d);
00087      Axis.Set(Ch[c].Dir[d],d);
00088    }
00089    double RadDist = sqrt( SQR(RelPos[CLat1]) + SQR(RelPos[CLat2]) );
00090    double Zed = (Ch[c].Pos[CNorm] - pCm(CNorm));
00091    int vr = (int)(RadDist*pInvEdge(3)*NBin);
00092    if(vr < 0 || vr >= NBin) continue;
00093    int t = 0;
00094    if(VAR_IF_TYPE(Ch[c].Type,CHAIN_DOWN)) t = 1;
00095    CountCh[(vr)*2+t] += 1;
00096    ThickProf[(vr)*2+t] += Zed;
00097    HFluct[vr*2  ] += Zed;
00098    HFluct[vr*2+1] += SQR(Zed);
00099    double Angle = ZedDir.Angle(&Axis,&Directive);
00100    Angle = Angle < .5*M_PI ? Angle : Angle - .5*M_PI;
00101    if(!isnan(Angle)){
00102      AngleProf[vr*2  ] += Angle;
00103      AngleProf[vr*2+1] += SQR(Angle);
00104    }
00105    double VelRad = sqrt( SQR(Ch[c].Vel[CLat1]) + SQR(Ch[c].Vel[CLat2]) );
00106    double VelTheta = fabs(atan2(Ch[c].Vel[CLat2],Ch[c].Vel[CLat1]));
00107    double DRad = sqrt(SQR(Ch[c].Pos[CLat1]-Ch2[c].Pos[CLat1]) + SQR(Ch[c].Pos[CLat2]-Ch2[c].Pos[CLat2]));
00108    double DTheta = atan2(Ch[c].Pos[CLat1]-Ch2[c].Pos[CLat1],Ch[c].Pos[CLat2]-Ch2[c].Pos[CLat2]);
00109    VelDistr[vr*2  ] += VelRad;
00110    VelDistr[vr*2+1] += VelTheta < 100. ? VelTheta : 0.;
00111    DisplRad[vr*2  ] += DRad;
00112    DisplRad[vr*2+1] += SQR(DRad);
00113    DisplTheta[vr*2  ] += DTheta;
00114    DisplTheta[vr*2+1] += SQR(DTheta);
00115    double DistE2E = 0.;
00116    int pE1 = c*pNPCh();
00117    int pE2 = (c+1)*pNPCh()-1;
00118    for(int d=0;d<3;d++){
00119      Ch2[c].Pos[d] = Ch[c].Pos[d];
00120      DistE2E += SQR(pPos(pE1,d)-pPos(pE2,d));
00121    }
00122    E2E[vr*2  ] += sqrt(DistE2E);
00123    E2E[vr*2+1] += DistE2E;
00124       }
00125     }
00126   }
00127 #ifdef OMPI_MPI_H
00128   MPI_Allreduce(MPI_IN_PLACE,dDensity,NType*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00129   MPI_Allreduce(MPI_IN_PLACE,ThickProf,NType*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00130   MPI_Allreduce(MPI_IN_PLACE,CountCh,NType*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00131   MPI_Allreduce(MPI_IN_PLACE,CountPart,NType*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00132   MPI_Allreduce(MPI_IN_PLACE,VelDistr,2*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00133   MPI_Allreduce(MPI_IN_PLACE,DisplRad,2*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00134   MPI_Allreduce(MPI_IN_PLACE,DisplTheta,2*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00135   MPI_Allreduce(MPI_IN_PLACE,E2E,2*NBin, MPI_DOUBLE, MPI_SUM, Proc->CommGrid);
00136   int Rank=0;
00137   MPI_Comm_rank(Proc->CommGrid, &Rank);
00138   if(Rank==0){
00139 #endif
00140     printf("\n");
00141     //Normalize-----------------------------------
00142     double InvNFile = 1./(double)(NFile[1]-NFile[0]);
00143     double VolumeZed = pEdge(0)*pEdge(1)*pEdge(2)/(double)SQR(NBin);
00144     double VolumeRad = pEdge(3)*pEdge(3)*Nano->Rad/(double)SQR(NBin);
00145     for(int v=0;v<NBin;v++){
00146       double r = v*pEdge(3)/(double)NBin;
00147       double NormType = 0.;
00148       double NormVol = (VolumeRad*VolEl[v])/InvNFile;
00149       NormVol = NormVol > 0. ? 1./NormVol : 1.;
00150       for(int t=0;t<NType;t++){
00151    dRad[v*NType+t] *= NormVol;
00152    double Norm = CountCh[v*NType+t] > 0. ? 1./CountCh[v*NType+t] : 1.;
00153    ThickProf[v*NType+t] *= Norm;
00154    NormType += CountCh[v*NType+t];
00155       }
00156       NormType = NormType > 0. ? 1./NormType : 1.;
00157       if(r < Nano->Rad) NormType = 0.;
00158       if(r < Nano->Rad) NormVol = 0.;
00159       VelDistr[v*2  ]   *= NormType;
00160       VelDistr[v*2+1]   *= NormType;
00161       DisplRad[v*2  ]   *= NormType;
00162       DisplRad[v*2+1]    = sqrt(DisplRad[v*2+1]*NormType - SQR(DisplRad[v*2  ]));
00163       DisplTheta[v*2  ] *= NormType;
00164       DisplTheta[v*2+1]  = sqrt(DisplTheta[v*2+1]*NormType - SQR(DisplTheta[v*2  ]));
00165       HFluct[v*2  ]     *= NormType;
00166       HFluct[v*2+1]      = sqrt(HFluct[v*2+1]*NormType - SQR(HFluct[v*2  ]));
00167       AngleProf[v*2  ]  *= NormType;
00168       AngleProf[v*2+1]   = sqrt(AngleProf[v*2+1]*NormType - SQR(AngleProf[v*2  ]));
00169       E2E[v*2  ]        *= NormType;
00170       E2E[v*2+1]         = sqrt( (E2E[v*2+1]*NormType - SQR(E2E[v*2  ])) );
00171       //E2E[v*2+1]        *= NormVol;
00172     }
00173     //--------------radial density-------------------------------
00174     char FileName[256];
00175     sprintf(FileName,"NanoDensR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00176     FILE *FileToWrite = fopen(FileName,"w");
00177     char cSystem[STRSIZE];
00178     SysDef(cSystem);
00179     fprintf(FileToWrite,"# %s",cSystem);
00180     fprintf(FileToWrite,"#r DensPhob DensPhil\n");
00181     for(int v=0;v<NBin;v++){
00182       double r = v*pEdge(3)/(double)NBin;
00183       fprintf(FileToWrite,"%lf %lf %lf\n",r,dRad[v*NType],dRad[v*NType+1]);
00184     }
00185     fclose(FileToWrite);
00186     // //---------------thickness profile-----------------------------
00187     // sprintf(FileName,"NanoThickR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00188     // FileToWrite = fopen(FileName,"w");
00189     // fprintf(FileToWrite,"#r ThickUp ThickDown\n");
00190     // for(int vr=0;vr<NBin;vr++){
00191     //   double r = vr*pEdge(3)/(double)NBin;
00192     //   if(r < Nano->Rad) continue;
00193     //   if(ThickProf[vr*NType+0]*ThickProf[vr*NType+1] > 0.)
00194     //     fprintf(FileToWrite,"%lf %lf %lf\n",r,ThickProf[vr*NType+0],ThickProf[vr*NType+1]);
00195     // }
00196     // fclose(FileToWrite);
00197     //----------------velocity profile-----------------------------
00198     sprintf(FileName,"NanoRadVelR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00199     FileToWrite = fopen(FileName,"w");
00200     fprintf(FileToWrite,"#r VelRad VelTheta\n");
00201     for(int v=0;v<NBin;v++){
00202       double r = v*pEdge(3)/(double)NBin;
00203       fprintf(FileToWrite,"%lf %lf %lf\n",r,VelDistr[v*2+0],VelDistr[v*2+1]);
00204     }
00205     fclose(FileToWrite);
00206     //----------------z fluctuation profile-----------------------------
00207     sprintf(FileName,"NanoZedFluctR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00208     FileToWrite = fopen(FileName,"w");
00209     fprintf(FileToWrite,"#r <z> <(z - <z>)^2> \n");
00210     for(int v=0;v<NBin;v++){
00211       double r = v*pEdge(3)/(double)NBin;
00212       fprintf(FileToWrite,"%lf %.5g %.5g\n",r,HFluct[v*2+0],HFluct[v*2+1]);
00213     }
00214     fclose(FileToWrite);
00215     //----------------angle profile-----------------------------
00216     sprintf(FileName,"NanoAngleR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00217     FileToWrite = fopen(FileName,"w");
00218     fprintf(FileToWrite,"#r <a> <(a - <a>)^2> \n");
00219     for(int v=0;v<NBin;v++){
00220       double r = v*pEdge(3)/(double)NBin;
00221       fprintf(FileToWrite,"%lf %.5g %.5g\n",r,AngleProf[v*2+0],AngleProf[v*2+1]);
00222     }
00223     fclose(FileToWrite);
00224     //----------------end to end-----------------------------
00225     sprintf(FileName,"NanoE2ER%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00226     FileToWrite = fopen(FileName,"w");
00227     fprintf(FileToWrite,"#r <e2e> <(e2e - <e2e>)^2> \n");
00228     for(int v=0;v<NBin;v++){
00229       double r = v*pEdge(3)/(double)NBin;
00230       fprintf(FileToWrite,"%lf %.5g %.5g\n",r,E2E[v*2+0],E2E[v*2+1]);
00231     }
00232     fclose(FileToWrite);
00233     //----------------radial displacement-----------------------------
00234     sprintf(FileName,"NanoRadDisplR%.1fS%.1fH%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00235     FileToWrite = fopen(FileName,"w");
00236     fprintf(FileToWrite,"#r JumpRad JumpTheta \n");
00237     for(int v=0;v<NBin;v++){
00238       double r = v*pEdge(3)/(double)NBin;
00239       fprintf(FileToWrite,"%lf %lf %lf %lf %lf\n",r,DisplRad[v*2  ],DisplRad[v*2+1],DisplTheta[v*2  ],DisplTheta[v*2+1]);
00240     }
00241     fclose(FileToWrite);
00242 #ifdef OMPI_MPI_H
00243   }
00244 #endif
00245   //freeing-------------------------------------------------
00246   free(CountCh);
00247   free(CountPart);
00248   free(DisplRad);
00249   free(DisplTheta);
00250   free(dDensity);
00251   free(dRad);
00252   free(ThickProf);
00253   free(VelDistr);
00254   free(AngleProf);
00255   return 0;
00256 }
00257 int ElPoly::WormF(int Partition,int NBin){
00258   double *dDensity = (double *)calloc(2*NBin,sizeof(double));
00259   double Norma;
00260   double Border[2] = {-10.,10.};
00261   for(int f=NFile[0];f<NFile[1];f++){
00262     Processing(f);
00263     if(OpenRisk(cFile[f],BF_PART))return 0;
00264     Worm(Partition,NBin,Border,dDensity);
00265   }
00266   printf("\n");
00267   FILE *FileToWrite = fopen("WormDensity.dat","w");
00268   for(int v=0;v<NBin;v++){
00269     fprintf(FileToWrite,"%lf %lf %lf\n",(double)v/(double)NBin*(Border[1]-Border[0])+Border[0],dDensity[v*2]/(NFile[1]-NFile[0]),dDensity[v*2+1]/(NFile[1]-NFile[0]));
00270   }
00271   fclose(FileToWrite);
00272   free(dDensity);
00273   return 1;
00274 }
00275 //The skin is not closing, better use the marching cubes
00276 void ElPoly::StalkF(int NSample){
00277   double Threshold = 0.;
00278   int NLevel = 4;
00279   double **Plot = (double **) calloc(NLevel,sizeof(double));
00280   for(int l=0;l<NLevel;l++){
00281     Plot[l] = (double *)calloc(NSample*NSample,sizeof(double));
00282   }
00283   double **PlotA = (double **) calloc(NLevel,sizeof(double));
00284   for(int l=0;l<NLevel;l++){
00285     PlotA[l] = (double *)calloc(NSample*NSample,sizeof(double));
00286   }
00287   for(int f=NFile[0];f<NFile[1];f++){
00288     Processing(f);
00289     if(OpenRisk(cFile[f],BF_PART))return ;
00290     Stalk(NSample,NLevel,Plot,Threshold);
00291     for(int s=0;s<NSample;s++)
00292       for(int ss=0;ss<NSample;ss++)
00293    for(int l=0;l<NLevel;l++)
00294      PlotA[l][s*NSample+ss] += Plot[l][s*NSample+ss];
00295   }
00296   printf("\n");
00297   Vettore v00(3);
00298   Vettore v01(3);
00299   Vettore v11(3);
00300   Vettore v10(3);
00301   Vettore vN(3);
00302   char FileName[256];
00303   sprintf(FileName,"Stalk.xvl");
00304   FILE *FileToWrite = fopen(FileName,"w");
00305   fprintf(FileToWrite,"#l(%lf %lf %lf) v[%d] d[%s]\n",pEdge(CLat1),pEdge(CLat2),pEdge(CNorm),NSample,ChooseDraw(EL_SKIN));
00306   double FactC1 = pEdge(CLat1)/(double)NSample;
00307   double FactC2 = pEdge(CLat2)/(double)NSample;
00308   double FactCN = 1./(double)(NFile[1]-NFile[0]);
00309   for(int l=0,p=0,c=0;l<NLevel;l++){
00310     for(int ss=0;ss<NSample-1;ss++){
00311       for(int s=0;s<NSample-1;s++){
00312    v00.x[CLat1]=(s+.5)*FactC1;
00313    v00.x[CLat2]=(ss+.5)*FactC2;
00314    v00.x[CNorm]=PlotA[l][s*NSample+ss]*FactCN;
00315    v01.x[CLat1]=(s+1.5)*FactC1;
00316    v01.x[CLat2]=(ss+.5)*FactC2;
00317    v01.x[CNorm]=PlotA[l][(s+1)*NSample+ss]*FactCN;
00318    v11.x[CLat1]=(s+1.5)*FactC1;
00319    v11.x[CLat2]=(ss+1.5)*FactC2;
00320    v11.x[CNorm]=PlotA[l][(s+1)*NSample+ss+1]*FactCN;
00321    v10.x[CLat1]=(s+.5)*FactC1;
00322    v10.x[CLat2]=(ss+1.5)*FactC2;
00323    v10.x[CNorm]=PlotA[l][s*NSample+ss+1]*FactCN;
00324    //------------defines-the-squares---------------------
00325    if(PlotA[l][(s)*NSample+ss] <= Threshold){
00326      if(l==0)
00327        v00.x[CNorm]=PlotA[3][(s)*NSample+ss+1]*FactCN;
00328      if(l==1)
00329        v00.x[CNorm]=PlotA[2][(s)*NSample+ss+1]*FactCN;
00330      if(l==2) 
00331        v00.x[CNorm]=PlotA[1][(s)*NSample+ss+1]*FactCN;
00332      if(l==3) 
00333        v00.x[CNorm]=PlotA[0][(s)*NSample+ss+1]*FactCN;
00334      if(v00.x[CNorm] <= 0.) continue;
00335    }
00336    if(PlotA[l][(s+1)*NSample+ss] <= Threshold){
00337      if(l==0)
00338        v01.x[CNorm]=PlotA[3][(s)*NSample+ss]*FactCN;
00339      if(l==1)
00340        v01.x[CNorm]=PlotA[2][(s)*NSample+ss]*FactCN;
00341      if(l==2) 
00342        v01.x[CNorm]=PlotA[1][(s)*NSample+ss]*FactCN;
00343      if(l==3) 
00344        v01.x[CNorm]=PlotA[0][(s)*NSample+ss]*FactCN;
00345      if(v01.x[CNorm] <= 0.) continue;
00346    }
00347    if(PlotA[l][s*NSample+ss+1] <= Threshold){
00348      if(l==0)
00349        v10.x[CNorm]=PlotA[3][(s)*NSample+ss]*FactCN;
00350      if(l==1)
00351        v10.x[CNorm]=PlotA[2][(s)*NSample+ss]*FactCN;
00352      if(l==2) 
00353        v10.x[CNorm]=PlotA[1][(s)*NSample+ss]*FactCN;
00354      if(l==3) 
00355        v10.x[CNorm]=PlotA[0][(s)*NSample+ss]*FactCN;
00356      if(v10.x[CNorm] <= 0.) continue;
00357    }
00358    if(PlotA[l][(s+1)*NSample+(ss+1)] <= Threshold){
00359      if(l==0)
00360        v11.x[CNorm]=PlotA[3][(s)*NSample+ss+1]*FactCN;
00361      if(l==1)
00362        v11.x[CNorm]=PlotA[2][(s)*NSample+ss+1]*FactCN;
00363      if(l==2) 
00364        v11.x[CNorm]=PlotA[1][(s)*NSample+ss+1]*FactCN;
00365      if(l==3) 
00366        v11.x[CNorm]=PlotA[0][(s)*NSample+ss+1]*FactCN;
00367      if(v11.x[CNorm] <= 0.) continue;
00368    }
00369    fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf) l[%d] l[%d] l[%d] }\n",p+0,c,l,v00.x[CLat1],v00.x[CLat2],v00.x[CNorm],(double)l*.25,.5,.8,p+1,p+2,p+3);
00370    fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf) l[%d] l[%d] l[%d] }\n",p+1,c,l,v01.x[CLat1],v01.x[CLat2],v01.x[CNorm],(double)l*.25,.5,.8,p+2,p+3,p+0);
00371    fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf) l[%d] l[%d] l[%d] }\n",p+2,c,l,v11.x[CLat1],v11.x[CLat2],v11.x[CNorm],(double)l*.25,.5,.8,p+3,p+0,p+1);
00372    fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf) l[%d] l[%d] l[%d] }\n",p+3,c,l,v10.x[CLat1],v10.x[CLat2],v10.x[CNorm],(double)l*.25,.5,.8,p+0,p+1,p+2);
00373    p += 4;
00374    c++;
00375       }
00376     }
00377   }
00378   for(int l=0;l<NLevel;l++){
00379     free(Plot[l]);
00380     free(PlotA[l]);
00381   }
00382   free(Plot);
00383   free(PlotA);
00384 }
00388 void ElPoly::StalkLineProfF(int NBin){
00389 #ifdef USE_FFTW
00390   double *Line = (double *)calloc(NBin,sizeof(double));
00391   double *Spe = (double *)calloc(NBin,sizeof(double));
00392   char FName[120];
00393   int NHalf = (int)(NBin/2);
00394   // Excluding the two ends that are at most di
00395   double InvNBin = 1./(double)(NBin-2);
00396   double InvNFile = 1./(double)(NFile[1]-NFile[0]);
00397   fftw_complex *out = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex));
00398   fftw_complex *in = (fftw_complex *)fftw_malloc(NBin*sizeof(fftw_complex));
00399   fftw_plan plan = fftw_plan_dft_1d(NBin-2,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
00400   fftw_plan plan2 = fftw_plan_dft_1d(NBin-2,out,in,FFTW_BACKWARD,FFTW_ESTIMATE);
00401   for(int f=NFile[0];f<NFile[1];f++){
00402     Processing(f);
00403     if(Open(cFile[f],BF_CHAIN)) return;
00404     StalkLineProf(Line,NBin);
00405     for(int vx=0;vx<NBin-2;vx++) in[vx][0] = Line[vx+1];
00406     fftw_execute(plan);
00407     for(int vx=0;vx<NBin-2;vx++){
00408       //int vvx = vx < NHalf ? vx + NHalf : vx - NHalf;
00409       Spe[vx] += (SQR(out[vx][0]) + SQR(out[vx][1]))*SQR(InvNBin);
00410     }
00411     //-------------------------write-temp-files
00412     if(1==1){
00413       sprintf(FName,"StalkLine%05d.dat",f);
00414       FILE *FWrite = fopen(FName,"w");
00415       for(int vx=0;vx<NBin;vx++){
00416    fprintf(FWrite,"%lf %lf \n",vx*pEdge(CLat2)/(double)NBin,Line[vx]);
00417       }
00418       fclose(FWrite);
00419     }
00420   }
00421   printf("\n");
00422   double dx = pEdge(CLat1)*InvNBin;
00423   FILE *FWrite = fopen("StalkLineSpectrum.dat","w");
00424   for(int vx=0;vx<NBin/2-2;vx++){
00425     double qx  = 2.*M_PI*vx*pInvEdge(CLat1);
00426     double qq = SQR(qx/dx - .5/dx);
00427     //fprintf(FWrite,"%lf %lf \n",qx,Spe[vx]*InvNFile*pEdge(CLat2)*pEdge(CLat2));
00428     fprintf(FWrite,"%lf %lf \n",qx,Spe[vx]*InvNFile);
00429   }
00430   fclose(FWrite);
00431   free(Line);
00432   free(Spe);
00433   fftw_free(out);
00434   fftw_free(in);
00435 #else
00436   printf("fftw not implemented\n");
00437 #endif // USE_FFTW
00438 }
00439 void ElPoly::Prova(){
00440   char FName[60];
00441   for(int f=NFile[0];f<NFile[1];f++){
00442     Processing(f);
00443     if(Open(cFile[f],BF_NO))return;
00444     Nano[0].Pos[0] = 12.0;
00445     Nano[0].Pos[1] = 12.0;
00446     Nano[0].Pos[2] = 9.0;
00447     sprintf(FName,"new%07d00.dat",f*2);
00448     Write(cFile[f]);
00449   }
00450   printf("\n");
00451 }
00452 void ElPoly::RadNormPos(int NBin,int NGrid){
00453   //SigErr((NFile[1]-NFile[0]) != SQR(NGrid),"RadNormPos: the number of files is not compatible with the parameter span");
00454   char FName[120];
00455   int NWeight = 5;
00456   double *RadProf = (double *)calloc(NBin,sizeof(double));
00457   double *RadProfS = (double *)calloc(NBin,sizeof(double));
00458   double *Count = (double *)calloc(NBin,sizeof(double));
00459   double *PlotMin = (double *)calloc(NGrid*NGrid,sizeof(double));
00460   double *PlotThin = (double *)calloc(NGrid*NGrid,sizeof(double));
00461   double *PlotTmp = (double *)calloc(NGrid*NGrid,sizeof(double));
00462   double *AngList = (double *)calloc((NFile[1]-NFile[0]),sizeof(double));
00463   double *HeiList = (double *)calloc((NFile[1]-NFile[0]),sizeof(double));
00464   double *Weight = (double *)calloc(NWeight,sizeof(double));
00465   int *WIndex = (int *)calloc(NWeight,sizeof(int));
00466   double InvNBin = 1./(NBin);
00467   Mat->FillWeightGauss(Weight,WIndex,NWeight,0.0,2.0);
00468   SetEdge(.5*MIN(pEdge(CLat1),pEdge(CLat2)),3);
00469   for(int f=NFile[0];f<NFile[1];f++){
00470     Processing(f);
00471     if(Open(cFile[f],BF_PART)) return;
00472     double Angle = Nano->Hamaker;
00473     double Hei = Nano->Height;
00474     for(int r=0;r<NBin;r++){
00475       RadProf[r] = 0.;
00476       Count[r] = 0.;
00477     }
00478     for(int p=0;p<pNPart();p++){
00479       double Rad = sqrt(SQR(Pm[p].Pos[CLat1]-Nano->Pos[CLat1])+SQR(Pm[p].Pos[CLat2]-Nano->Pos[CLat2]));
00480       //if(Rad < 1.5*Nano->Rad) continue;
00481       int r = (int)(Rad*pInvEdge(3)*NBin);
00482       if(r < 0 || r >= NBin) continue;
00483       RadProf[r] += Pm[p].Pos[CNorm];
00484       Count[r] += 1.;
00485     }
00486     for(int r=0;r<NBin;r++){
00487       if(Count[r] <= 0.) continue;
00488       RadProf[r] /= Count[r];
00489     }
00490     //smooth
00491     Matrice Mask1(5);
00492     Mask1.FillGaussian(.5,3.);
00493     int NDim = 1;
00494     int IfMinImConv = 0;
00495     Mask1.ConvoluteMatrix(RadProf,NBin,NDim,IfMinImConv);
00496     // for(int v=0;v<NBin;v++) RadProfS[v] = RadProf[v];
00497     // InterBSpline1D(RadProfS,RadProf,NBin,NBin);
00498     // for(int v=0;v<NBin;v++) RadProfS[v] = RadProf[v];
00499     // InterBSpline1D(RadProfS,RadProf,NBin,NBin);
00500     // for(int v=0;v<NBin;v++) RadProfS[v] = RadProf[v];
00501     // InterBSpline1D(RadProfS,RadProf,NBin,NBin);
00502     // Mat->ConvWeight(RadProf,NBin,Weight,WIndex,NWeight);
00503     double Thinning = 100000.;
00504     double MinDist = 0.;
00505     int rLower = 0;
00506     for(int r=3;r<NBin;r++){
00507       if(Count[r] <= 0.) continue;
00508       if(Thinning > RadProf[r]){
00509    Thinning = RadProf[r];
00510    MinDist = r*pEdge(3)/(double)NBin;
00511    rLower = r;
00512       }
00513     }
00514     //printf("%lf %lf %lf %lf\n",Angle,Hei,MinDist,Thinning);
00515     AngList[f] = Angle;
00516     HeiList[f] = Hei;
00517     PlotMin[f] = MinDist;
00518     PlotThin[f] = Thinning;
00519     sprintf(FName,"ThinProfHei%.1fAng%02d.dat",Hei,(int)Angle);
00520     FILE *FProf = fopen(FName,"w");
00521     for(int r=0;r<NBin;r++){
00522       if(Count[r] <= 0.) continue;  
00523       double Rad = r*pEdge(3)*InvNBin;
00524       fprintf(FProf,"%lf %lf\n",Rad,RadProf[r]);
00525     }
00526     fclose(FProf);
00527   }
00528   //smooth and write dens
00529   Matrice Mask(5,5);
00530   Mask.FillGaussian(.5,3.);
00531   Mask.Print();
00532   int NDim = 2;
00533   int IfMinImConv = 1;
00534   for(int t=0;t<0;t++){
00535     Mask.ConvoluteMatrix(PlotMin,NGrid,NDim,IfMinImConv);
00536     Mask.ConvoluteMatrix(PlotThin,NGrid,NDim,IfMinImConv);
00537   }
00538   for(int s=0;s<NGrid*NGrid;s++) PlotTmp[s] = PlotMin[s];
00539   InterBSpline2D(PlotTmp,PlotMin,NGrid,NGrid);
00540   for(int s=0;s<NGrid*NGrid;s++) PlotTmp[s] = PlotThin[s];
00541   InterBSpline2D(PlotTmp,PlotThin,NGrid,NGrid);
00542   FILE *FMinDist = fopen("HeiAngMinDist.dat","w");
00543   FILE *FThin = fopen("HeiAngThin.dat","w");
00544   for(int f=NFile[0];f<NFile[1];f++){
00545     double Angle = AngList[f];
00546     double Hei = HeiList[f];
00547     fprintf(FMinDist,"%lf %lf %lf\n",Hei,Angle,PlotMin[f]);
00548     fprintf(FThin,"%lf %lf %lf\n",Hei,Angle,PlotThin[f]);
00549   }
00550   free(Count);
00551   free(RadProf);
00552   free(RadProfS);
00553   free(PlotMin);
00554   free(PlotThin);
00555   fclose(FThin);
00556   fclose(FMinDist);
00557   printf("\n");
00558 }
00559 #ifdef USE_CGAL
00560 void ElPoly::AreaDistrF(int NBin){
00561   SetEdge(.5*MIN(pEdge(CLat1),pEdge(CLat2)),3);
00562   double *Distr = (double *)calloc(NBin,sizeof(double));
00563   double *DistrRadAv = (double *)calloc(NBin,sizeof(double));
00564   double *DistrRad = (double *)calloc(NBin,sizeof(double));
00565   double *VolContr = (double *)calloc(NBin,sizeof(double));
00566   VolumeCircSlab(VolContr,NBin);
00567   double FNormaInv = 1./(double)(NFile[1]-NFile[0]);
00568   double BoxRadInv = .5*sqrt( SQR(pEdge(CLat1)) + SQR(pEdge(CLat2)) )/(double)NBin;
00569   double AreaMean = 3.*.5*pNChain()/(pEdge(CLat1)*pEdge(CLat2));
00570   for(int f=NFile[0];f<NFile[1];f++){
00571     Processing(f);
00572     if(OpenRisk(cFile[f],BF_CHAIN))return ;
00573     BfDefChain();
00574     AreaDistr(Distr,DistrRad,NBin);
00575     for(int v=0;v<NBin;v++)
00576       DistrRadAv[v] += DistrRad[v];
00577   }
00578   printf("\n");
00579   //---------normalize------------------
00580   double NormF = NFile[1] - NFile[0];
00581   for(int v=0;v<NBin;v++){
00582     DistrRadAv[v] /= VolContr[v]*NormF;
00583     Distr[v] /= VolContr[v]*NormF;
00584   }
00585   //---------write----------------------
00586   char FileName[120];
00587   sprintf(FileName,"NanoAreaRadDistrR%.1fH%.1fh%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00588   FILE *File2Write = fopen(FileName,"w");
00589   for(int v=0;v<NBin;v++){
00590     fprintf(File2Write,"%lf %lf\n",v*BoxRadInv,DistrRadAv[v]*FNormaInv);
00591   }
00592   fclose(File2Write);
00593   sprintf(FileName,"NanoAreaDistrR%.1fH%.1fh%.1f.dat",Nano->Rad,Nano->Hamaker,Nano->Height);
00594   File2Write = fopen(FileName,"w");
00595   for(int v=0;v<NBin;v++){
00596     fprintf(File2Write,"%lf %lf\n",v*AreaMean/(double)NBin,Distr[v]*FNormaInv);
00597   }
00598   fclose(File2Write);
00599   free(Distr);
00600   free(DistrRadAv);
00601   free(DistrRad);
00602 }
00603 #else
00604 void ElPoly::AreaDistrF(int NBin){
00605   printf("CGAL libraries not implemented\n");
00606 }
00607 #endif