MDStressLab++
Loading...
Searching...
No Matches
spatialHash.cpp
Go to the documentation of this file.
1#include "typedef.h"
2#include "SpatialHash.h"
3#include <iostream>
4#include <fstream>
5#include <iomanip>
6
7int main()
8{
9 int numberOfPoints;
10
11 std::ifstream fileA;
12 fileA.open("NN_full_grid_eps.dat",std::ios::in);
13
14 if ( fileA.is_open() ) { // always check whether the file is open
15 fileA >> numberOfPoints; // pipe file's content into stream
16 std::cout << "Tgrid Number is " << numberOfPoints <<std::endl;
17 }else{
18 std::cout <<"Problem in reading the grid file. Exit the present program"<<std::endl;
19 exit(1);
20 }
21
22 MatrixXd configuration(numberOfPoints,DIM);
23// configuration= MatrixXd::Random(numberOfPoints,DIM);
24
25 for(int i=0; i<numberOfPoints; i++){
26 fileA >> configuration(i,0);
27 fileA >> configuration(i,1);
28 fileA >> configuration(i,2);
29 }
30/*
31 for(int i=0; i<numberOfPoints; i++){
32 std::cout << configuration(i,0) <<" " << configuration(i,1 ) << " " <<
33 configuration(i,2) << std::endl;
34 }
35*/
36 fileA.close();
37
38
39 /*
40 std::string originalgridFileName="original.dat";
41 std::fstream foutTest;
42 foutTest.open(originalgridFileName,std::ios::out);
43 foutTest << numberOfPoints << std::endl;
44 for (int i=0; i<numberOfPoints ; i++)
45 {
46 foutTest << configuration(i,0) << " " ;
47 foutTest << configuration(i,1) << " " ;
48 foutTest << configuration(i,2) << std::endl;
49 }
50 foutTest.close();
51 exit(1);
52 */
53
54 Vector3d origin,step;
55 origin.setConstant(0);
56
57 //step.setConstant(20);
58 step << 100, 100, 55 ;
59
60 ConstSpatialHash hash(origin,step,configuration);
61
62 //to count the number of each grid in the part grid
63 //Segmentation Fault will happen if maxBinNumber is too small.
64 int maxBinNumber =10000;
65 int numOfpointInPgrid[maxBinNumber];
66
67 for(int i=0; i<maxBinNumber; i++){
68 numOfpointInPgrid[i]=0;
69 }
70
71 int binNumber= 0;
72
73 for(auto pair : hash.hashTable)
74 {
75 for (auto i_particle : pair.second) // loop of all atoms inside the box
76 {// pair.first is triplet
77 // pair.second is a vector of integer
78 numOfpointInPgrid[binNumber]+=1;
79 // file << std::setw(10) << binNumber << std::setw(15) << i_particle << std::setw(10) << pair.first << std::setw(15) << configuration.row(i_particle) << std::endl;
80 }
81 //std::cout << numOfpointInPgrid[binNumber] << std::endl;
82 binNumber++;
83 }
84
85
86 binNumber=0;
87 for(auto pair : hash.hashTable) //
88 {
89 std::string subgridFileName="subGridEPS_";
90 subgridFileName= subgridFileName + std::to_string(binNumber);
91
92 /*
93 char file_number[3];
94 snprintf(file_number,3,"%03d",binNumber);
95 subgridFileName+=file_number;
96 subgridFileName+=".dat";
97 std::cout << subgridFileName << std::endl;
98 */
99
100 std::fstream fout;
101 fout.open(subgridFileName,std::ios::out);
102
103 fout << numOfpointInPgrid[binNumber] << std::endl;
104 for (auto i_particle : pair.second) // loop of all atoms in side the box
105 {
106 fout << configuration(i_particle,0) << std::endl;
107 fout << configuration(i_particle,1) << std::endl;
108 fout << configuration(i_particle,2) << std::endl;
109 }
110 binNumber++;
111
112 }
113}
std::map< Triplet, std::vector< int > > hashTable
#define DIM
int main()
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXd
Definition typedef.h:54
Eigen::Matrix< double, 1, DIM, Eigen::RowMajor > Vector3d
Definition typedef.h:60