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::DensityProfile(int coord,int Values,int NType,double *DensityAv){ 00025 BfDefChain(); 00026 double VolumeInv = (double) (Values)/(Gen->Edge[0]*Gen->Edge[1]*Gen->Edge[2]); 00027 int NPartition = 10; 00028 double NPartInv = 1./(double)(NPartition*NPartition); 00029 double *Density = (double *)calloc(NPartition*NPartition*NType*Values,sizeof(double)); 00030 double Pos[4]; 00031 char cLine[STRSIZE]; 00032 int t=0; 00033 for(int b=0;b<Gen->NBlock;b++){ 00034 if(!strncmp(Block[b].Name,"PEP",3) ) continue; 00035 if(!strcmp(Block[b].Name,"WATER") ) continue; 00036 for(int p=Block[b].InitIdx,link=0;p<Block[b].EndIdx;p++){ 00037 t = Pm[p].Typ; 00038 for(int d=0;d<3;d++) 00039 Pos[d] = Pm[p].Pos[d]; 00040 int vx = (int)(NPartition*Pos[CLat1]/Gen->Edge[CLat2]); 00041 if(vx < 0 || vx >= Values) continue; 00042 int vy = (int)(NPartition*Pos[CLat2]/Gen->Edge[CLat2]); 00043 if(vy < 0 || vy >= Values) continue; 00044 int vz = (int)(Values*Pos[CNorm]/Gen->Edge[CNorm]); 00045 if(vz < 0 || vz >= Values) continue; 00046 if(CHAIN_IF_TYPE(Ch[Pm[p].CId].Type,CHAIN_ADDED)) 00047 t = 2; 00048 Density[((vz*NType+t)*NPartition+vy)*NPartition+vx] += 1.; 00049 } 00050 } 00051 for(int vx=0;vx<NPartition;vx++){ 00052 for(int vy=0;vy<NPartition;vy++){ 00053 double Media = 0.; 00054 double Weight = 0.; 00055 for(int v=0;v<Values;v++){ 00056 Weight += Density[((v*NType+0)*NPartition+vy)*NPartition+vx]; 00057 Media += v*Density[((v*NType+0)*NPartition+vy)*NPartition+vx]; 00058 } 00059 int vMedia = Weight > 0 ? (int)(Media/Weight) : Values/2; 00060 int vOffset = vMedia - Values/2; 00061 for(int t=0;t<NType;t++){ 00062 for(int v=0;v<Values;v++){ 00063 int vOther = v + vOffset; 00064 if(vOther < 0) 00065 vOther = Values - vOther; 00066 if(vOther >= Values) 00067 vOther = vOther - Values; 00068 DensityAv[v*NType+t] += Density[((vOther*NType+t)*NPartition+vy)*NPartition+vx]*VolumeInv; 00069 } 00070 } 00071 } 00072 } 00073 free(Density); 00074 return 0; 00075 } 00076 void VarData::Stalk(int Values,int NLevel,double **Plot,double Threshold){ 00077 double **Norma = (double **)calloc(NLevel,sizeof(double)); 00078 for(int l=0;l<NLevel;l++) 00079 Norma[l] = (double *)calloc(Values*Values,sizeof(double)); 00080 for(int b=0;b<Gen->NBlock;b++){ 00081 for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ 00082 for(int v=0;v<Values;v++){ 00083 // if(Pm[p].Typ == 1 && Pm[p-1].Typ == 0) 00084 { 00085 int v = (int)(Pm[p].Pos[CLat1]/Gen->Edge[CLat1]*Values); 00086 if( v < 0 || v >= Values) continue; 00087 int vv = (int)(Pm[p].Pos[CLat2]/Gen->Edge[CLat2]*Values); 00088 if( vv < 0 || vv >= Values) continue; 00089 Plot[b][v*Values + vv] += Pm[p].Pos[CNorm]; 00090 Norma[b][v*Values + vv] += 1.; 00091 } 00092 } 00093 } 00094 } 00095 for(int v=0;v<Values;v++) 00096 for(int vv=0;vv<Values;vv++) 00097 for(int l=0;l<NLevel;l++){ 00098 if(Norma[l][v*Values+vv] > Threshold) 00099 Plot[l][v*Values+vv] /= Norma[l][v*Values+vv]; 00100 else 00101 Plot[l][v*Values+vv] = 0.; 00102 } 00103 for(int l=0;l<NLevel;l++) 00104 free(Norma[l]); 00105 free(Norma); 00106 }