forked from dftfeDevelopers/dftfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locatenodes.cc
195 lines (182 loc) · 7.6 KB
/
locatenodes.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// ---------------------------------------------------------------------
//
// Copyright (c) 2017 The Regents of the University of Michigan and DFT-FE authors.
//
// This file is part of the DFT-FE code.
//
// The DFT-FE code is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the DFT-FE distribution.
//
// ---------------------------------------------------------------------
//
// @author Shiva Rudraraju (2016), Phani Motamarri (2016)
//
//source file for locating core atom nodes
template<unsigned int FEOrder>
void dftClass<FEOrder>::locateAtomCoreNodes(){
unsigned int vertices_per_cell=GeometryInfo<3>::vertices_per_cell;
DoFHandler<3>::active_cell_iterator
cell = dofHandler.begin_active(),
endc = dofHandler.end();
//
//IndexSet locally_owned_elements=eigenVectors[0][0]->locally_owned_elements();
//locating atom nodes
unsigned int numAtoms=atomLocations.size();
std::set<unsigned int> atomsTolocate;
for (unsigned int i = 0; i < numAtoms; i++) atomsTolocate.insert(i);
//element loop
for (; cell!=endc; ++cell) {
if (cell->is_locally_owned()){
for (unsigned int i=0; i<vertices_per_cell; ++i){
unsigned int nodeID=cell->vertex_dof_index(i,0);
Point<3> feNodeGlobalCoord = cell->vertex(i);
//loop over all atoms to locate the corresponding nodes
for (std::set<unsigned int>::iterator it=atomsTolocate.begin(); it!=atomsTolocate.end(); ++it){
Point<3> atomCoord(atomLocations[*it][2],atomLocations[*it][3],atomLocations[*it][4]);
if(feNodeGlobalCoord.distance(atomCoord) < 1.0e-5){
if(isPseudopotential)
{
std::cout << "Atom core with valence charge " << atomLocations[*it][1] << " located with node id " << nodeID << " in processor " << this_mpi_process<<" nodal coor "<<feNodeGlobalCoord[0]<<" "<<feNodeGlobalCoord[1]<<" "<<feNodeGlobalCoord[2]<<std::endl;
}
else
{
std::cout << "Atom core with charge " << atomLocations[*it][0] << " located with node id " << nodeID << " in processor " << this_mpi_process<<" nodal coor "<<feNodeGlobalCoord[0]<<" "<<feNodeGlobalCoord[1]<<" "<<feNodeGlobalCoord[2]<<std::endl;
}
if (locally_owned_dofs.is_element(nodeID)){
if(isPseudopotential)
atoms.insert(std::pair<unsigned int,double>(nodeID,atomLocations[*it][1]));
else
atoms.insert(std::pair<unsigned int,double>(nodeID,atomLocations[*it][0]));
std::cout << " and added \n";
}
else{
std::cout << " but skipped \n";
}
atomsTolocate.erase(*it);
break;
}//tolerance check if loop
}//atomsTolocate loop
}//vertices_per_cell loop
}//locally owned cell if loop
}//cell loop
MPI_Barrier(mpi_communicator);
int numberBins = d_boundaryFlag.size();
d_atomsInBin.resize(numberBins);
for(int iBin = 0; iBin < numberBins; ++iBin)
{
unsigned int vertices_per_cell=GeometryInfo<3>::vertices_per_cell;
DoFHandler<3>::active_cell_iterator cell = dofHandler.begin_active(),endc = dofHandler.end();
std::set<int> & atomsInBinSet = d_bins[iBin];
std::vector<int> atomsInCurrentBin(atomsInBinSet.begin(),atomsInBinSet.end());
unsigned int numberGlobalAtomsInBin = atomsInCurrentBin.size();
std::set<unsigned int> atomsTolocate;
for (unsigned int i = 0; i < numberGlobalAtomsInBin; i++) atomsTolocate.insert(i);
for (; cell!=endc; ++cell) {
if (cell->is_locally_owned()){
for (unsigned int i=0; i<vertices_per_cell; ++i){
unsigned int nodeID=cell->vertex_dof_index(i,0);
Point<3> feNodeGlobalCoord = cell->vertex(i);
//loop over all atoms to locate the corresponding nodes
for (std::set<unsigned int>::iterator it=atomsTolocate.begin(); it!=atomsTolocate.end(); ++it)
{
int chargeId = atomsInCurrentBin[*it];
Point<3> atomCoord(atomLocations[chargeId][2],atomLocations[chargeId][3],atomLocations[chargeId][4]);
if(feNodeGlobalCoord.distance(atomCoord) < 1.0e-5){
if(isPseudopotential)
std::cout << "Atom core in bin " << iBin<<" with valence charge "<<atomLocations[chargeId][1] << " located with node id " << nodeID << " in processor " << this_mpi_process;
else
std::cout << "Atom core in bin " << iBin<<" with charge "<<atomLocations[chargeId][0] << " located with node id " << nodeID << " in processor " << this_mpi_process;
if (locally_owned_dofs.is_element(nodeID)){
if(isPseudopotential)
d_atomsInBin[iBin].insert(std::pair<unsigned int,double>(nodeID,atomLocations[chargeId][1]));
else
d_atomsInBin[iBin].insert(std::pair<unsigned int,double>(nodeID,atomLocations[chargeId][0]));
std::cout << " and added \n";
}
else{
std::cout << " but skipped \n";
}
atomsTolocate.erase(*it);
break;
}//tolerance check if loop
}//atomsTolocate loop
}//vertices_per_cell loop
}//locally owned cell if loop
}//cell loop
MPI_Barrier(mpi_communicator);
}//iBin loop
}
template<unsigned int FEOrder>
void dftClass<FEOrder>::locatePeriodicPinnedNodes(){
unsigned int vertices_per_cell=GeometryInfo<3>::vertices_per_cell;
DoFHandler<3>::active_cell_iterator
cell = dofHandler.begin_active(),
endc = dofHandler.end();
//locating pinned nodes
std::vector<std::vector<double> > pinnedLocations;
std::vector<double> temp;
//temp.push_back(3.8); temp.push_back(3.8); temp.push_back(3.8);//(center)
//temp.push_back(0.0); temp.push_back(0.0); temp.push_back(0.0);//(corner)
//temp.push_back(2.28); temp.push_back(0.0); temp.push_back(3.8);//(bcc)
if(this_mpi_process==0)
{
for(; cell!=endc; ++cell)
{
if (cell->is_locally_owned())
{
if (! cell->has_boundary_lines())
{
Point<3> pinPoint = cell->vertex(0);
temp.push_back(pinPoint[0]); temp.push_back(pinPoint[1]); temp.push_back(pinPoint[2]);
break;
}
}
}
}
pinnedLocations.push_back(temp);
cell = dofHandler.begin_active();
unsigned int numberNodes = pinnedLocations.size();
std::set<unsigned int> nodesTolocate;
for (unsigned int i = 0; i < numberNodes; i++) nodesTolocate.insert(i);
//element loop
if(temp.size() > 0)
{
for (; cell!=endc; ++cell)
{
if (cell->is_locally_owned())
{
for (unsigned int i=0; i<vertices_per_cell; ++i)
{
unsigned int nodeID=cell->vertex_dof_index(i,0);
Point<3> feNodeGlobalCoord = cell->vertex(i);
//loop over all atoms to locate the corresponding nodes
for (std::set<unsigned int>::iterator it=nodesTolocate.begin(); it!=nodesTolocate.end(); ++it)
{
Point<3> pinnedNodeCoord(pinnedLocations[*it][0],pinnedLocations[*it][1],pinnedLocations[*it][2]);
if(feNodeGlobalCoord.distance(pinnedNodeCoord) < 1.0e-5)
{
std::cout << "Pinned core with nodal coordinates (" << pinnedLocations[*it][0] << " " << pinnedLocations[*it][1] << " "<<pinnedLocations[*it][2]<< ") located with node id " << nodeID << " in processor " << this_mpi_process;
if (locally_owned_dofs.is_element(nodeID))
{
d_constraintsForTotalPotential.add_line(nodeID);
d_constraintsForTotalPotential.set_inhomogeneity(nodeID,0.0);
std::cout << " and added \n";
}
else
{
std::cout << " but skipped \n";
}
nodesTolocate.erase(*it);
break;
}//tolerance check if loop
}//atomsTolocate loop
}//vertices_per_cell loop
}//locally owned cell if loop
}//cell loop
}
MPI_Barrier(mpi_communicator);
}