Allink  v0.1
VarDataPos.cpp
1 /***********************************************************************
2 VarDataEl: Elaboration functions for the VarData class. This functions
3 provides a simple manipulation of the data read by [Open]. The
4 options are provided to elaborate different system's shapes.
5 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
6 
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
22 #include "../include/VarData.h"
23 
24 int VarData::Arrange(int **Triangle,int Vertex){
25  BfDefChain();
26  int *nChain = (int *)calloc(Vertex,sizeof(int));
27  double *dChain= (double *)calloc(Vertex,sizeof(double));
28  double MaxLength = 1.5*sqrt(QUAD(Gen->Edge[0])+QUAD(Gen->Edge[1]));
29  for(int c=0;c<Gen->NChain;c++){
30  for(int v=0;v<Vertex;v++)
31  dChain[v] = MaxLength;
32  int NVertex = 0;
33  if(!CHAIN_IF_TYPE(Ch[c].Type,NChType))continue;
34  for(int cc=0;cc<Gen->NChain;cc++){
35  if(!CHAIN_IF_TYPE(Ch[cc].Type,NChType))continue;
36  if(c == cc) continue;
37  double Shift[3] = {0.,0.,0.};
38  double PosDiff[3] = {0.,0.,0.};
39  for(int d=0;d<3;d++){
40  PosDiff[d] = Ch[cc].Pos[d] - Ch[c].Pos[d];
41  Shift[d] = -floor((PosDiff[d])/Gen->Edge[d]+.5)*Gen->Edge[d];
42  }
43  double Dist = QUAD(PosDiff[CLat1]+Shift[CLat1]) + QUAD(PosDiff[CLat2]+Shift[CLat2]);// + QUAD(PosZ);
44  //if(Dist > MaxLength) continue;
45  //printf("%d %d %lf %lf\n",c,cc,Dist,dChain[0]);
46  for(int v=0;v<Vertex;v++){
47  if(dChain[v] > Dist){
48  //printf("%d %d/%d %lf %lf\n",c,cc,v,Dist,dChain[v]);
49  for(int vv=Vertex-1;vv>v;vv--){
50  dChain[vv] = dChain[vv-1];
51  nChain[vv] = nChain[vv-1];
52  }
53  dChain[v] = Dist;
54  nChain[v] = cc;
55  NVertex++;
56  //for(int v=0;v<Vertex;v++)printf("%d %d\n",v,nChain[v]);
57  break;
58  }
59  }
60  }
61  for(int v=0;v<Vertex;v++)
62  Triangle[v][c] = nChain[v];
63  Triangle[Vertex][c] = NVertex<Vertex ? NVertex : Vertex;
64  //Triangle[Vertex-1][c] = c;
65  //for(int v=0;v<Vertex+1;v++) printf("%d ",Triangle[v][c]); printf("\n");
66  }
67  free(nChain);
68  free(dChain);
69  return 1;
70 }
72  // for(int c=0;c<Gen->NChain;c++){
73  // Ch[c].nPos = CalcnPos(Ch[c].Pos);
74  // // printf("%d %d\n",c,Ch[c].nPos);
75  // for(int cc=c-1;cc>=0;cc--){
76  // int nProl = cc==0 ? 0 : Ch[cc-1].nPos;
77  // //printf("%d<%d<%d | %d<=%d<%d\n",cc,c,cc-1,Ch[cc].nPos,Ch[c].nPos,nProl);
78  // if(Ch[c].nPos < Ch[cc].nPos && Ch[c].nPos >= nProl){
79  // //printf("--%d/%d - %d/%d \n",c,cc+1,Ch[c].nPos,nProl);
80  // for(int ccc=c;ccc>cc;ccc--) SwapChain(ccc,ccc-1);
81  // break;
82  // }
83  // }
84  // //for(int cc=0;cc<=c;cc++)printf("%d %d\n",cc,Ch[cc].nPos);
85  // }
86  // return 1;
87 }
88 int VarData::CalcnPos(double *Pos){
89  double BlurDist[3]={Gen->Edge[0]/(double)SubDiv[0],Gen->Edge[1]/(double)SubDiv[1],Gen->Edge[2]/(double)SubDiv[2]};
90  int v[3];
91  for(int d=0;d<3;d++){
92  double InvSubDiv = 1./(double)SubDiv[d];
93  v[d] = (int)(Pos[d]/Gen->Edge[d]*SubDiv[d]);
94  if(v[d] > SubDiv[d]){printf("Chain out of range %d>%d\n",v[d],SubDiv[d]); continue;}
95  if(Pos[d] - v[d]*Gen->Edge[d]*InvSubDiv < .25*BlurDist[d])
96  v[d] = 2*v[d] + 1;
97  else if(Pos[d] - v[d]*Gen->Edge[d]*InvSubDiv > .75*BlurDist[d])
98  v[d] = 2*v[d] + 3;
99  else
100  v[d] = 2*v[d];
101  //printf("%d\n",v[d]);
102  }
103  int nPos = (v[0]*SubDiv[1] + v[1])*SubDiv[2]+v[2];
104  return nPos;
105 }
106 int VarData::PosVectInt(double *Pos){
107  int vx = (int)(Pos[CLat1]/Gen->Edge[CLat1]*NEdge);
108  int vy = (int)(Pos[CLat2]/Gen->Edge[CLat2]*NEdge);
109  int vz = (int)(Pos[CNorm]/Gen->Edge[CNorm]*NEdge);
110  return (vx*NEdge + vy)*NEdge+vz;
111 }
CHAIN * Ch
Information on all chains.
Definition: VarData.h:1050
int Arrange(int **Triangle, int Vertex)
The naerest.
Definition: VarDataPos.cpp:24
int CalcnPos(double *Pos)
return a univocal index of the chain position
Definition: VarDataPos.cpp:88
double Edge[4]
xyzr edges of the simulation box
Definition: VarData.h:309
int BfDefChain()
Definition of the chain.
int NChType
Type of chain selected.
Definition: VarData.h:1080
int CLat2
lateral coordinate
Definition: VarData.h:1078
int NChain
Number of chain.
Definition: VarData.h:347
int NEdge
Number of particles per edge.
Definition: VarData.h:1084
double Pos[4]
xyzr Postion of the chain
Definition: VarData.h:238
int OrderPos()
A cell list to be fixed.
Definition: VarDataPos.cpp:71
int PosVectInt(double *Pos)
Return the integer index with respect to the partition NSquare.
Definition: VarDataPos.cpp:106
int CLat1
lateral coordinate
Definition: VarData.h:1076
int CNorm
Normal coordinate.
Definition: VarData.h:1074