19 if (numberOfGrids == 1)
MY_HEADING(
"Creating Grids");
21 std::cout <<
"Grid " << numberOfGrids <<
". Initializing a grid of size " <<
ngrid <<
" to the origin." << std::endl;
28 int ngridx,
int ngridy,
int ngridz):ngrid(ngridx*ngridy*ngridz)
30 if ( !(lowerLimit.array() < upperLimit.array()).prod() )
31 MY_ERROR(
"ERROR: The coordinates of lowerLimit are not less than the upperLimit");
35 if (numberOfGrids == 1)
MY_HEADING(
"Creating Grids");
38 std::cout <<
"Grid " << numberOfGrids <<
". Creating a uniform grid of " <<
ngrid <<
" points between (" << lowerLimit
39 <<
") and (" << upperLimit <<
")"<< std::endl;
40 std::cout << std::endl;
45 coordinate= lowerLimit;
48 coordinate(0) = lowerLimit(0) + i*(upperLimit(0)-lowerLimit(0))/ngridx;
51 coordinate(1) = lowerLimit(1) + j*(upperLimit(1)-lowerLimit(1))/ngridy;
54 coordinate(2)= lowerLimit(2) + k*(upperLimit(2)-lowerLimit(2))/ngridz;
69 int ngridz):ngrid(ngridx*ngridy*ngridz)
74 if (numberOfGrids == 1)
MY_HEADING(
"Creating Grids");
76 std::cout <<
"Grid " << numberOfGrids <<
". Creating a cell-aligned uniform grid of " <<
ngrid
77 <<
" points between (" << lowerLimit <<
") and (" << upperLimit <<
")" << std::endl;
78 std::cout << std::endl;
82 for (
int i_dim=0; i_dim<
DIM; ++i_dim)
84 cellVectorLengths(i_dim)= cell.col(i_dim).norm();
85 if (cellVectorLengths(i_dim)<
epsilon)
86 MY_ERROR(
"ERROR: Degenerate cell vector in grid construction.");
90 if ((cellDisplacement.array() < -
epsilon).any())
91 MY_ERROR(
"ERROR: upperLimit-lowerLimit has negative components in the cell-vector basis.");
96 double coordinate0= 0.0;
97 if (ngridx>1) coordinate0 += i*cellDisplacement(0)/ngridx;
100 double coordinate1= 0.0;
101 if (ngridy>1) coordinate1 += j*cellDisplacement(1)/ngridy;
104 double coordinate2= 0.0;
105 if (ngridz>1) coordinate2 += k*cellDisplacement(2)/ngridz;
107 Vector3d fractionalCoordinates(coordinate0,coordinate1,coordinate2);
115template<ConfigType T>
120 if (numberOfGrids == 1)
MY_HEADING(
"Creating Grids");
121 std::cout <<
"Grid " << numberOfGrids <<
". Reading grid from filename: " << filename << std::endl;
122 std::cout << std::endl;
124 std::ifstream file(filename);
127 coordinates.resize(ngrid);
128 for(
auto& position : coordinates)
129 for (
int i_dim=0; i_dim<
DIM; i_dim++)
130 if(!(file >> position(i_dim)))
MY_ERROR(
"ERROR: Reading grid coordinates");
135template<ConfigType T>
138 std::vector<std::set<int>> gridNeighborLists;
142 origin.setConstant(0.0);
143 step.setConstant(padding);
150 for(
const auto& gridPoint : coordinates)
152 std::set<int> gridContributingList;
158 std::vector<int>& particleList= hashParticles.
hashTable[neighborBin];
160 for(
const auto& particle : particleList)
162 double distance= (subconfig.
coordinates.at(T).row(particle)-gridPoint).squaredNorm();
163 if (distance<=pow(padding,2))
164 gridContributingList.insert(particle);
167 gridNeighborLists.push_back(gridContributingList);
171 return gridNeighborLists;
174template<ConfigType T>
177 std::ofstream file(filename+
".grid");
179 file << ngrid <<
"\n";
181 for (
const auto& coordinate : coordinates)
182 file << coordinate << std::endl;
185template<ConfigType T>
188 std::cout <<
"Reading grid from file " << filename <<
"\n" << std::endl;
190 std::ifstream file(filename);
194 if (ngrid!= ngridInFile)
195 MY_ERROR(
"Error: Number of grid points in file" <<
" = " << ngridInFile <<
196 ", does not equal to " << ngrid <<
" in grid.");
198 for(
auto& position : coordinates)
199 for (
int i_dim=0; i_dim<
DIM; i_dim++)
200 if(!(file >> position(i_dim)))
MY_ERROR(
"ERROR: Reading grid coordinates");
203template<ConfigType T>
208 else MY_ERROR(
"Unrecognized grid type");
212template<ConfigType T>
217template<ConfigType T>
226template<ConfigType T>
232 std::set<int> gridContributingList;
239 const std::vector<int>& particleList=
241 hashParticles.
hashTable.at(neighborBin) : std::vector<int>();
244 for(
const auto& particle : particleList)
246 double distance= (subconfig.coordinates.at(T).row(particle)-grid.coordinates[i_gridPoint]).squaredNorm();
247 if (distance<=pow(padding,2))
248 gridContributingList.insert(particle);
251 return gridContributingList;
std::map< ConfigType, MatrixXd > coordinates
Map from configuration type (Reference or Current) to coordinate matrices.
static int numberOfReferenceGrids
static int numberOfCurrentGrids
std::vector< Vector3d > coordinates
std::set< int > getGridPointNeighbors(const int &) const
GridSubConfiguration(const Grid< T > &, const SubConfiguration &, const double &)
std::vector< std::set< int > > getGridNeighborLists(const SubConfiguration &, const double &) const
void write(std::string) const
Triplet hashFunction(const int &i) const
std::map< Triplet, std::vector< int > > hashTable
std::vector< Triplet > neighborList()
void transpose(double const *mat, double *const trans)
#define MY_ERROR(message)
Eigen::Matrix< double, DIM, DIM, Eigen::RowMajor > Matrix3d
Eigen::Matrix< double, 1, DIM, Eigen::RowMajor > Vector3d
#define MY_HEADING(heading)