Allink
v0.1
|
00001 /*********************************************************************** 00002 VarDataEl: Elaboration functions for the VarData class. This functions 00003 provides a simple manipulation of the data read by [Open]. The 00004 options are provided to elaborate different system's shapes. 00005 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it> 00006 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 ***********************************************************************/ 00022 #include "../include/VarData.h" 00023 00024 int VarData::PairCorrelation(double *dPoint,int NSample,int How,int Type){ 00025 BfDefChain(); 00026 //printf("%d %d\n",NSample,How); 00027 double dNSample = 1./(double)NSample; 00028 for(int v=0;v<NSample;v++) 00029 dPoint[v] = 0.; 00030 if(How == 0){//Monomer 00031 for(int p=0;p<Gen->NPart;p++){ 00032 if(Pm[p].Typ != Type)continue; 00033 Pm[p].Pos[3] = 0.; 00034 for(int pp=0;pp<Gen->NPart;pp++){ 00035 if(Pm[pp].Typ != Type)continue; 00036 if( p == pp)continue; 00037 double Dist2 = QUAD(Pm[p].Pos[0] - Pm[pp].Pos[0]); 00038 Dist2 += QUAD(Pm[p].Pos[1] - Pm[pp].Pos[1]); 00039 Dist2 += QUAD(Pm[p].Pos[2] - Pm[pp].Pos[2]); 00040 Dist2 = pow(Dist2,.5); 00041 int v = (int)(Dist2*pInvEdge(3)*NSample); 00042 if( v < 0 || v >= NSample) continue; 00043 dPoint[v] += 1.; 00044 } 00045 } 00046 // printf("Processing: %d/%d %.1f %% \r",p,HowMany,p/(double)HowMany/100.); 00047 for(int v=0;v<NSample;v++){ 00048 dPoint[v] /= Gen->NPart*(Gen->NPart-1); 00049 } 00050 } 00051 //printf("\n"); 00052 if(How == 1){//Chain 00053 for(int c=0;c<Gen->NChain;c++){ 00054 Ch[c].Pos[3] = 0.; 00055 if(Ch[c].Type != Type)continue; 00056 for(int cc=0;cc<Gen->NChain;cc++){ 00057 if(Ch[cc].Type != Type)continue; 00058 if( c == cc)continue; 00059 Ch[c].Pos[3] += QUAD((Ch[c].Pos[CLat1] - Ch[cc].Pos[CLat1])); 00060 Ch[c].Pos[3] += QUAD((Ch[c].Pos[CLat2] - Ch[cc].Pos[CLat2])); 00061 } 00062 Ch[c].Pos[3] = pow(Ch[c].Pos[3]/(double)Gen->NChain,.5); 00063 int v = (int)(Ch[c].Pos[3] / Gen->Edge[3]*NSample); 00064 if( v < 0 || v >= NSample) continue; 00065 dPoint[v] += 1.; 00066 } 00067 } 00068 for(int v=0;v<NSample;v++){ 00069 dPoint[v] /= DUE_PI*( QUAD((Gen->Edge[3]*(v+1)*dNSample)) - QUAD((Gen->Edge[3]*v*dNSample)) ); 00070 } 00071 return 0; 00072 } 00073 int VarData::PairCorrelationSquare(double **dPoint,int NSample,int Type){ 00074 BfDefChain(); 00075 double dNSample = 1./(double)NSample; 00076 double InvNChain=1./(double)Gen->NChain; 00077 int vRef = (int)(NSample/2.); 00078 for(int c=0;c<Gen->NChain;c++){ 00079 if(!CHAIN_IF_TYPE(Ch[c].Type,NChType)) continue; 00080 double ChX1 = (Ch[c].Pos[CLat1] - Gen->Edge[CLat1]*.5); 00081 double ChY1 = (Ch[c].Pos[CLat2] - Gen->Edge[CLat2]*.5); 00082 int vx1 = (int)(ChX1 / (Gen->Edge[CLat1])*NSample); 00083 int vy1 = (int)( (ChY1) / (Gen->Edge[CLat2])*NSample); 00084 for(int cc=0;cc<Gen->NChain;cc++){ 00085 if(!CHAIN_IF_TYPE(Ch[cc].Type,NChType)) continue; 00086 if( c == cc) continue; 00087 double ChX2 = (Ch[cc].Pos[CLat1] - Gen->Edge[CLat1]*.5); 00088 double ChY2 = (Ch[cc].Pos[CLat2] - Gen->Edge[CLat2]*.5); 00089 int vx2 = (int)(ChX2 / (Gen->Edge[CLat1])*NSample); 00090 int vy2 = (int)( (ChY2) / (Gen->Edge[CLat2])*NSample); 00091 int vx = vx1 - vx2; 00092 // if(vx < -vRef) vx += vRef; 00093 // if(vx > vRef ) vx -= vRef; 00094 if( vx + vRef < 0 || vx+vRef >= NSample) continue; 00095 int vy = vy1 - vy2; 00096 // if(vy < -vRef) vy += vRef; 00097 // if(vy > vRef) vy -= vRef; 00098 if( vy + vRef < 0 || vy+vRef >= NSample) continue; 00099 // printf("%d %d %d %lf %lf\n",c,vx,vy,ChX1,ChX2); 00100 dPoint[vx+vRef][vy+vRef] += InvNChain; 00101 } 00102 } 00103 return 0; 00104 } 00105 int VarData::PairCorrelationPep(double **dPoint,int NSample,int Type){ 00106 BfDefChain(); 00107 double dNSample = 1./(double)NSample; 00108 double InvNChain=1./(double)Gen->NChain; 00109 int vRef = (int)(NSample/2.); 00110 for(int c=0;c<Gen->NChain;c++){ 00111 if(!CHAIN_IF_TYPE(Ch[c].Type,NChType))continue; 00112 double ChX = remainder(Ch[c].Pos[CLat1] - pNanoPos(0,CLat1),Gen->Edge[CLat1]); 00113 double ChY = remainder(Ch[c].Pos[CLat2] - pNanoPos(0,CLat2),Gen->Edge[CLat2]); 00114 int vx = (int)(ChX/Gen->Edge[CLat1]*NSample); 00115 int vy = (int)(ChY/Gen->Edge[CLat2]*NSample); 00116 if( vx + vRef < 0 || vx+vRef >= NSample) continue; 00117 if( vy + vRef < 0 || vy+vRef >= NSample) continue; 00118 dPoint[vx+vRef][vy+vRef] += InvNChain; 00119 } 00120 return 0; 00121 } 00122 int VarData::PairCorrelationRound(double **dPoint,int NSample,int Type){ 00123 BfDefChain(); 00124 double dNSample = 1./(double)NSample; 00125 double InvNChain=1./(double)Gen->NChain; 00126 for(int c=0;c<Gen->NChain;c++){ 00127 double ChRad=0.; 00128 double ChAngle=0.; 00129 if(!CHAIN_IF_TYPE(Ch[c].Type,NChType))continue; 00130 for(int cc=0;cc<Gen->NChain;cc++){ 00131 if(!CHAIN_IF_TYPE(Ch[cc].Type,NChType))continue; 00132 if( c == cc)continue; 00133 double ChX = remainder(Ch[c].Pos[CLat1] - Ch[cc].Pos[CLat1],Gen->Edge[CLat1]); 00134 // if(ChX > .5*Gen->Edge[CLat1]) 00135 // ChX = Ch[c].Pos[CLat1] + Ch[cc].Pos[CLat1] - Gen->Edge[CLat1]; 00136 // else if (ChX < -.5*Gen->Edge[CLat1]) 00137 // ChX = -Ch[c].Pos[CLat1] - Ch[cc].Pos[CLat1] + Gen->Edge[CLat1]; 00138 double ChY = remainder(Ch[c].Pos[CLat2] - Ch[cc].Pos[CLat2],Gen->Edge[CLat2]); 00139 // if(ChY > .5*Gen->Edge[CLat2]) 00140 // ChY = Ch[c].Pos[CLat2] + Ch[cc].Pos[CLat2] - Gen->Edge[CLat2]; 00141 // else if (ChY < -.5*Gen->Edge[CLat2]) 00142 // ChY = -Ch[c].Pos[CLat2] - Ch[cc].Pos[CLat2] + Gen->Edge[CLat2]; 00143 ChRad = sqrt( QUAD((ChX)) + QUAD((ChY)) ); 00144 ChAngle = acos(ChX / ChRad); 00145 if(ChY < 0) 00146 ChAngle = DUE_PI - ChAngle; 00147 int v = (int)(ChRad / (Gen->Edge[3])*NSample); 00148 if( v < 0 || v >= NSample) continue; 00149 int vv = (int)( (ChAngle) / (DUE_PI)*NSample); 00150 if( vv < 0 || vv >= NSample) continue; 00151 //printf("%d %d %lf %lf %lf %lf\n",v,vv,ChRad,ChX,ChY,ChAngle); 00152 dPoint[v][vv] += InvNChain; 00153 } 00154 } 00155 return 0; 00156 } 00157 int VarData::Scattering2d(double **Plot,int NSample,int Type){ 00158 BfDefChain(); 00159 double dNSample = 1./(double)NSample; 00160 double InvNChain=1./(double)Gen->NChain; 00161 int vRef = (int)(NSample/2.); 00162 double *CosSin = (double *)calloc(2*SQR(NSample),sizeof(double)); 00163 for(int p=0;p<pNPart();p++){ 00164 //if(!CHAIN_IF_TYPE(Ch[Pm[p].CId].Type,NChType))continue; 00165 // double ChX = (Ch[c].Pos[CLat1] - Nano->PosBf[CLat1]); 00166 // double ChY = (Ch[c].Pos[CLat2] - Nano->PosBf[CLat2]); 00167 double ChX = (Pm[p].Pos[CLat1] - pNanoPos(0,CLat1)); 00168 double ChY = (Pm[p].Pos[CLat2] - pNanoPos(0,CLat2)); 00169 ChX -= floor(ChX*pInvEdge(CLat1))*pEdge(CLat1); 00170 ChY -= floor(ChY*pInvEdge(CLat2))*pEdge(CLat2); 00171 ChX *= pInvEdge(CLat1); 00172 ChY *= pInvEdge(CLat2); 00173 // printf("%lf %lf %lf %lf\n",vvx,ChX,vvx*ChX*DUE_PI,cos(vvx*ChX*DUE_PI)); 00174 for(int vx=0;vx<NSample;vx++){ 00175 for(int vy=0;vy<NSample;vy++){ 00176 double qx = vx*dNSample; 00177 double qy = vy*dNSample; 00178 CosSin[(vx*NSample+vy)*2 ] += cos( (qx*ChX+qy*ChY)*DUE_PI ); 00179 CosSin[(vx*NSample+vy)*2+1] += sin( (qx*ChX+qy*ChY)*DUE_PI ); 00180 } 00181 } 00182 } 00183 for(int vx=0;vx<NSample;vx++){ 00184 for(int vy=0;vy<NSample;vy++){ 00185 Plot[vx][vy] = (SQR(CosSin[(vx*NSample+vy)*2 ]) + SQR(CosSin[(vx*NSample+vy)*2+1]))*SQR(InvNChain); 00186 } 00187 } 00188 return 0; 00189 } 00190 int VarData::Scattering2D(double **dPoint,int NSample,int Type){ 00191 BfDefChain(); 00192 double dNSample = 1./(double)NSample; 00193 double InvNChain=1./(double)Gen->NChain; 00194 for(int c=0;c<Gen->NChain;c++){ 00195 if(!CHAIN_IF_TYPE(Ch[c].Type,NChType))continue; 00196 for(int cc=0;cc<Gen->NChain;cc++){ 00197 if(!CHAIN_IF_TYPE(Ch[cc].Type,NChType))continue; 00198 if( c == cc)continue; 00199 double ChX = (Ch[c].Pos[CLat1] - Ch[cc].Pos[CLat1]); 00200 if(ChX > .5*Gen->Edge[CLat1]) ChX = Ch[c].Pos[CLat1] + Ch[cc].Pos[CLat1] - Gen->Edge[CLat1]; 00201 else if (ChX < -.5*Gen->Edge[CLat1]) ChX = -Ch[c].Pos[CLat1] - Ch[cc].Pos[CLat1] + Gen->Edge[CLat1]; 00202 double ChY = (Ch[c].Pos[CLat2] - Ch[cc].Pos[CLat2]); 00203 if(ChY > .5*Gen->Edge[CLat2]) ChY = Ch[c].Pos[CLat2] + Ch[cc].Pos[CLat2] - Gen->Edge[CLat2]; 00204 else if (ChY < -.5*Gen->Edge[CLat2]) ChY = -Ch[c].Pos[CLat2] - Ch[cc].Pos[CLat2] + Gen->Edge[CLat2]; 00205 int v = NSample/2 + (int)( 2.*(ChX / Gen->Edge[CLat1])*(NSample/2) ); 00206 int vv = NSample/2 + (int)(2.*ChY / (Gen->Edge[CLat2])*(NSample/2)); 00207 //if(ChX > Gen->Edge[CLat1]*.5 || ChY > Gen->Edge[CLat2]*.5 ) printf("%d %d %lf %lf\n",v,vv,ChX,ChY); 00208 // printf("%d %d %lf %lf\n",v,vv,ChX,ChY); 00209 if( vv < 0 || vv >= NSample) continue; 00210 if( v < 0 || v >= NSample) continue; 00211 dPoint[vv][v] += InvNChain;//*sin(ChRec*ChRad)/ChRec; 00212 } 00213 } 00214 return 0; 00215 } 00216 void VarData::Spettro2d(double *Points,int NSample,int Type){ 00217 double *Plot = (double *)calloc(SQR(NSample),sizeof(double)); 00218 double *InPoints = (double *)calloc(NSample*NSample,sizeof(double)); 00219 SampleSurface(Plot,NSample,Type); 00220 for(int v=0;v<SQR(NSample);v++){ 00221 InPoints[v] = Plot[v]; 00222 } 00223 Mat->Spettro2d(InPoints,Points,NSample); 00224 free(Plot); 00225 free(InPoints); 00226 } 00227 void VarData::Spettro2d(double *Plot,int NSample){ 00228 double *Points = (double *)calloc(NSample*NSample,sizeof(double)); 00229 for(int v=0;v<SQR(NSample);v++){ 00230 Points[v] = Plot[v]; 00231 } 00232 Mat->Spettro2d(Points,Plot,NSample); 00233 free(Points); 00234 }