DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
vselfBinsManager.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16//
17
18#include <headers.h>
20#include "dftParameters.h"
21#include "FEBasisOperations.h"
22
23#ifndef vselfBinsManager_H_
24# define vselfBinsManager_H_
25
26namespace dftfe
27{
28 /**
29 * @brief Categorizes atoms into bins for efficient solution of nuclear electrostatic self-potential.
30 *
31 * @author Sambit Das, Phani Motamarri
32 */
34 {
35 public:
36 /**
37 * @brief Constructor
38 *
39 * @param mpi_comm_parent parent mpi communicator
40 * @param mpi_comm_domain domain decomposition mpi communicator
41 */
42 vselfBinsManager(const MPI_Comm &mpi_comm_parent,
43 const MPI_Comm &mpi_comm_domain,
44 const MPI_Comm &mpi_intercomm_kpts,
45 const dftParameters &dftParams);
46
47
48 /**
49 * @brief Categorize atoms into bins based on self-potential ball radius
50 * around each atom such that no two atoms in each bin has overlapping
51 * balls.
52 *
53 * @param[out] constraintsVector constraintsVector to which the vself bins
54 * solve constraint matrices will be pushed back
55 * @param[in] dofHandler DofHandler object
56 * @param[in] constraintMatrix dealii::AffineConstraints<double> which was
57 * used for the total electrostatics solve
58 * @param[in] atomLocations global atom locations and charge values data
59 * @param[in] imagePositions image atoms positions data
60 * @param[in] imageIds image atoms Ids data
61 * @param[in] imageCharges image atoms charge values data
62 * @param[in] radiusAtomBall self-potential ball radius
63 */
64 void
66 std::vector<const dealii::AffineConstraints<double> *> &constraintsVector,
67 const dealii::AffineConstraints<double> &onlyHangingNodeConstraints,
68 const dealii::DoFHandler<3> &dofHandler,
69 const dealii::AffineConstraints<double> &constraintMatrix,
70 const std::vector<std::vector<double>> &atomLocations,
71 const std::vector<std::vector<double>> &imagePositions,
72 const std::vector<dftfe::Int> &imageIds,
73 const std::vector<double> &imageCharges,
74 const double radiusAtomBall);
75
76 /**
77 * @brief Categorize atoms into bins based on self-potential ball radius
78 * around each atom such that no two atoms in each bin has overlapping
79 * balls.
80 *
81 * @param[out] constraintsVector constraintsVector to which the vself bins
82 * solve constraint matrices will be pushed back
83 * @param[in] dofHandler DofHandler object
84 * @param[in] constraintMatrix dealii::AffineConstraints<double> which was
85 * used for the total electrostatics solve
86 * @param[in] atomLocations global atom locations and charge values data
87 * @param[in] imagePositions image atoms positions data
88 * @param[in] imageIds image atoms Ids data
89 * @param[in] imageCharges image atoms charge values data
90 */
91 void
93 std::vector<const dealii::AffineConstraints<double> *> &constraintsVector,
94 const dealii::AffineConstraints<double> &onlyHangingNodeConstraints,
95 const dealii::DoFHandler<3> &dofHandler,
96 const dealii::AffineConstraints<double> &constraintMatrix,
97 const std::vector<std::vector<double>> &atomLocations,
98 const std::vector<std::vector<double>> &imagePositions,
99 const std::vector<dftfe::Int> &imageIds,
100 const std::vector<double> &imageCharges,
101 const bool vselfPerturbationUpdateForStress = false);
102
103
104 /**
105 * @brief Solve nuclear electrostatic self-potential of atoms in each bin one-by-one
106 *
107 * @param[in] matrix_free_data MatrixFree object
108 * @param[in] offset MatrixFree object starting offset for vself bins solve
109 * @param[out] phiExt sum of the self-potential fields of all atoms and
110 * image atoms
111 * @param[in] phiExtConstraintMatrix constraintMatrix corresponding to
112 * phiExt
113 * @param[in] imagePositions image atoms positions data
114 * @param[in] imageIds image atoms Ids data
115 * @param[in] imageCharges image atoms charge values data *
116 * @param[out] localVselfs peak self-potential values of atoms in the local
117 * processor
118 */
119 void
121 const std::shared_ptr<
123 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
124 &basisOperationsPtr,
125 const dftfe::uInt offset,
126 const dftfe::uInt matrixFreeQuadratureIdAX,
127 const dealii::AffineConstraints<double> &hangingPeriodicConstraintMatrix,
128 const std::vector<std::vector<double>> &imagePositions,
129 const std::vector<dftfe::Int> &imageIds,
130 const std::vector<double> &imageCharges,
131 std::vector<std::vector<double>> &localVselfs,
132 std::map<dealii::CellId, std::vector<double>> &bQuadValuesAllAtoms,
133 std::map<dealii::CellId, std::vector<dftfe::Int>> &bQuadAtomIdsAllAtoms,
134 std::map<dealii::CellId, std::vector<dftfe::Int>>
135 &bQuadAtomIdsAllAtomsImages,
136 std::map<dealii::CellId, std::vector<dftfe::uInt>>
137 &bCellNonTrivialAtomIds,
138 std::vector<std::map<dealii::CellId, std::vector<dftfe::uInt>>>
139 &bCellNonTrivialAtomIdsBins,
140 std::map<dealii::CellId, std::vector<dftfe::uInt>>
141 &bCellNonTrivialAtomImageIds,
142 std::vector<std::map<dealii::CellId, std::vector<dftfe::uInt>>>
143 &bCellNonTrivialAtomImageIdsBins,
144 const std::vector<double> &smearingWidths,
145 std::vector<double> &smearedChargeScaling,
146 const dftfe::uInt smearedChargeQuadratureId,
147 const bool useSmearedCharges = false,
148 const bool isVselfPerturbationSolve = false);
149
150# ifdef DFTFE_WITH_DEVICE
151 /**
152 * @brief Solve nuclear electrostatic self-potential of atoms in each bin one-by-one
153 *
154 * @param[in] matrix_free_data MatrixFree object
155 * @param[in] offset MatrixFree object starting offset for vself bins solve
156 * @param[out] phiExt sum of the self-potential fields of all atoms and
157 * image atoms
158 * @param[in] phiExtConstraintMatrix constraintMatrix corresponding to
159 * phiExt
160 * @param[in] imagePositions image atoms positions data
161 * @param[in] imageIds image atoms Ids data
162 * @param[in] imageCharges image atoms charge values data *
163 * @param[out] localVselfs peak self-potential values of atoms in the local
164 * processor
165 */
166 void
167 solveVselfInBinsDevice(
168 const std::shared_ptr<
170 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
171 &basisOperationsPtr,
172 const dftfe::uInt mfBaseDofHandlerIndex,
173 const dftfe::uInt matrixFreeQuadratureIdAX,
174 const dftfe::uInt offset,
175 const dftfe::utils::MemoryStorage<double,
177 &cellGradNIGradNJIntergralDevice,
178 const std::shared_ptr<
180 &BLASWrapperPtr,
181 const dealii::AffineConstraints<double> &hangingPeriodicConstraintMatrix,
182 const std::vector<std::vector<double>> &imagePositions,
183 const std::vector<dftfe::Int> &imageIds,
184 const std::vector<double> &imageCharges,
185 std::vector<std::vector<double>> &localVselfs,
186 std::map<dealii::CellId, std::vector<double>> &bQuadValuesAllAtoms,
187 std::map<dealii::CellId, std::vector<dftfe::Int>> &bQuadAtomIdsAllAtoms,
188 std::map<dealii::CellId, std::vector<dftfe::Int>>
189 &bQuadAtomIdsAllAtomsImages,
190 std::map<dealii::CellId, std::vector<dftfe::uInt>>
191 &bCellNonTrivialAtomIds,
192 std::vector<std::map<dealii::CellId, std::vector<dftfe::uInt>>>
193 &bCellNonTrivialAtomIdsBins,
194 std::map<dealii::CellId, std::vector<dftfe::uInt>>
195 &bCellNonTrivialAtomImageIds,
196 std::vector<std::map<dealii::CellId, std::vector<dftfe::uInt>>>
197 &bCellNonTrivialAtomImageIdsBins,
198 const std::vector<double> &smearingWidths,
199 std::vector<double> &smearedChargeScaling,
200 const dftfe::uInt smearedChargeQuadratureId,
201 const bool useSmearedCharges = false,
202 const bool isVselfPerturbationSolve = false);
203
204
205# endif
206
207 /**
208 * @brief Solve nuclear electrostatic self-potential of atoms in each bin in a perturbed domain (used for cell stress calculation)
209 *
210 */
211 void
213 const std::shared_ptr<
215 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
216 &basisOperationsPtr,
217 const dftfe::uInt mfBaseDofHandlerIndex,
218 const dftfe::uInt matrixFreeQuadratureIdAX,
219 const dftfe::uInt offset,
220# ifdef DFTFE_WITH_DEVICE
221 const dftfe::utils::MemoryStorage<double,
223 &cellGradNIGradNJIntergralDevice,
224 const std::shared_ptr<
226 &BLASWrapperPtr,
227# endif
228 const dealii::AffineConstraints<double> &hangingPeriodicConstraintMatrix,
229 const std::vector<std::vector<double>> &imagePositions,
230 const std::vector<dftfe::Int> &imageIds,
231 const std::vector<double> &imageCharges,
232 const std::vector<double> &smearingWidths,
233 const dftfe::uInt smearedChargeQuadratureId,
234 const bool useSmearedCharges = false);
235
236 /// get const reference map of binIds and atomIds
237 const std::map<dftfe::Int, std::set<dftfe::Int>> &
239
240 /// get const reference map of binIds and atomIds
241 const std::map<dftfe::Int, std::set<dftfe::Int>> &
243
244 /// get const reference to map of global dof index and vself solve boundary
245 /// flag in each bin
246 const std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>> &
248
249 /// get const reference to map of global dof index and vself solve boundary
250 /// flag in each bin
251 const std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>> &
253
254 /// get const reference to map of global dof index and vself field initial
255 /// value in each bin
256 const std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>> &
258
259 /// get const reference to map of global dof index and vself field initial
260 /// value in each bin
261 const std::vector<
262 std::map<dealii::types::global_dof_index, dealii::Point<3>>> &
264
265 /// get const reference to solved vself fields
266 const std::vector<distributedCPUVec<double>> &
268
269 /// get const reference to del{vself}/del{R_i} fields
270 const std::vector<distributedCPUVec<double>> &
272
273 /// perturbation of vself solution field to be used to evaluate the
274 /// Gateaux derivative of vself field with respect to affine strain
275 /// components using central finite difference
276 const std::vector<distributedCPUVec<double>> &
278
279 /// get const reference to d_atomIdBinIdMapLocalAllImages
280 const std::map<dftfe::uInt, dftfe::uInt> &
282
283 /// get stored adaptive ball radius
284 double
286
287
288 private:
289 /**
290 * @brief locate underlying fem nodes for atoms in bins.
291 *
292 */
293 void
294 locateAtomsInBins(const dealii::DoFHandler<3> &dofHandler);
295
296 /**
297 * @brief sanity check for Dirichlet boundary conditions on the vself balls in each bin
298 *
299 */
300 void
302 const dealii::DoFHandler<3> &dofHandler,
303 const dealii::AffineConstraints<double> &onlyHangingNodeConstraints);
304
305 /// storage for input atomLocations argument in createAtomBins function
306 std::vector<std::vector<double>> d_atomLocations;
307
308 /// storage for optimized constraints handling object
311
312 /// vector of constraint matrices for vself bins
313 std::vector<dealii::AffineConstraints<double>> d_vselfBinConstraintMatrices;
314
315 /// map of binIds and atomIds
316 std::map<dftfe::Int, std::set<dftfe::Int>> d_bins;
317
318 /// map of binIds and atomIds and imageIds
319 std::map<dftfe::Int, std::set<dftfe::Int>> d_binsImages;
320
321 /// map of global dof index and vself solve boundary flag (chargeId or
322 // imageId+numberGlobalCharges) in each bin
323 std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>>
325
326 /// map of global dof index and vself solve boundary flag (only chargeId)in
327 /// each bin
328 std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>>
330
331 /// map of global dof index to location of closest charge
332 std::vector<std::map<dealii::types::global_dof_index, dealii::Point<3>>>
334
335 /// map of global dof index and vself field initial value in each bin
336 std::vector<std::map<dealii::types::global_dof_index, double>>
338
339 /// map of global dof index and vself field initial value in each bin
340 std::vector<std::map<dealii::types::global_dof_index, dftfe::Int>>
342
343 /// Internal data: stores the map of atom Id (only in the local processor)
344 /// to the vself bin Id. Populated in solve vself in Bins
345 std::map<dftfe::uInt, dftfe::uInt> d_atomIdBinIdMapLocalAllImages;
346
347 /// solved vself solution field for each bin
348 std::vector<distributedCPUVec<double>> d_vselfFieldBins;
349
350 /// solved del{vself}/del{R_i} solution field for each bin
351 std::vector<distributedCPUVec<double>> d_vselfFieldDerRBins;
352
353 /// perturbation of vself solution field to be used to evaluate the
354 /// Gateaux derivative of vself field with respect to affine strain
355 /// components using central finite difference
356 std::vector<distributedCPUVec<double>> d_vselfFieldPerturbedBins;
357
358 // std::vector<double> d_inhomoIdsColoredVecFlattened;
359
360 /// Map of locally relevant global dof index and the atomic charge in each
361 /// bin
362 std::vector<std::map<dealii::types::global_dof_index, double>> d_atomsInBin;
363
364 /// Vself ball radius. This is stored after the first call to createAtomBins
365 /// and reused for subsequent calls
367
369
370 const MPI_Comm d_mpiCommParent;
371 const MPI_Comm mpi_communicator;
372 const MPI_Comm d_mpiInterCommKpts;
375 dealii::ConditionalOStream pcout;
376 };
377
378} // namespace dftfe
379#endif // vselfBinsManager_H_
Namespace which declares the input parameters and the functions to parse them from the input paramete...
Definition dftParameters.h:36
Overloads dealii's distribute and distribute_local_to_global functions associated with constraints cl...
Definition constraintMatrixInfo.h:43
Definition BLASWrapper.h:35
Definition MemoryStorage.h:33
const std::map< dftfe::Int, std::set< dftfe::Int > > & getAtomImageIdsBins() const
get const reference map of binIds and atomIds
std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > d_boundaryFlagOnlyChargeId
Definition vselfBinsManager.h:329
std::map< dftfe::uInt, dftfe::uInt > d_atomIdBinIdMapLocalAllImages
Definition vselfBinsManager.h:345
std::map< dftfe::Int, std::set< dftfe::Int > > d_binsImages
map of binIds and atomIds and imageIds
Definition vselfBinsManager.h:319
const std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > & getBoundaryFlagsBinsOnlyChargeId() const
const std::vector< distributedCPUVec< double > > & getVselfFieldDerRBins() const
get const reference to del{vself}/del{R_i} fields
double getStoredAdaptiveBallRadius() const
get stored adaptive ball radius
void locateAtomsInBins(const dealii::DoFHandler< 3 > &dofHandler)
locate underlying fem nodes for atoms in bins.
double d_storedAdaptiveBallRadius
Definition vselfBinsManager.h:366
std::vector< distributedCPUVec< double > > d_vselfFieldPerturbedBins
Definition vselfBinsManager.h:356
std::vector< std::map< dealii::types::global_dof_index, dealii::Point< 3 > > > d_dofClosestChargeLocationMap
map of global dof index to location of closest charge
Definition vselfBinsManager.h:333
void createAtomBins(std::vector< const dealii::AffineConstraints< double > * > &constraintsVector, const dealii::AffineConstraints< double > &onlyHangingNodeConstraints, const dealii::DoFHandler< 3 > &dofHandler, const dealii::AffineConstraints< double > &constraintMatrix, const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imagePositions, const std::vector< dftfe::Int > &imageIds, const std::vector< double > &imageCharges, const double radiusAtomBall)
Categorize atoms into bins based on self-potential ball radius around each atom such that no two atom...
void solveVselfInBinsPerturbedDomain(const std::shared_ptr< dftfe::basis::FEBasisOperations< double, double, dftfe::utils::MemorySpace::HOST > > &basisOperationsPtr, const dftfe::uInt mfBaseDofHandlerIndex, const dftfe::uInt matrixFreeQuadratureIdAX, const dftfe::uInt offset, const dealii::AffineConstraints< double > &hangingPeriodicConstraintMatrix, const std::vector< std::vector< double > > &imagePositions, const std::vector< dftfe::Int > &imageIds, const std::vector< double > &imageCharges, const std::vector< double > &smearingWidths, const dftfe::uInt smearedChargeQuadratureId, const bool useSmearedCharges=false)
Solve nuclear electrostatic self-potential of atoms in each bin in a perturbed domain (used for cell ...
std::vector< std::vector< double > > d_atomLocations
storage for input atomLocations argument in createAtomBins function
Definition vselfBinsManager.h:306
const std::vector< std::map< dealii::types::global_dof_index, dealii::Point< 3 > > > & getClosestAtomLocationsBins() const
const MPI_Comm d_mpiCommParent
Definition vselfBinsManager.h:370
void solveVselfInBins(const std::shared_ptr< dftfe::basis::FEBasisOperations< double, double, dftfe::utils::MemorySpace::HOST > > &basisOperationsPtr, const dftfe::uInt offset, const dftfe::uInt matrixFreeQuadratureIdAX, const dealii::AffineConstraints< double > &hangingPeriodicConstraintMatrix, const std::vector< std::vector< double > > &imagePositions, const std::vector< dftfe::Int > &imageIds, const std::vector< double > &imageCharges, std::vector< std::vector< double > > &localVselfs, std::map< dealii::CellId, std::vector< double > > &bQuadValuesAllAtoms, std::map< dealii::CellId, std::vector< dftfe::Int > > &bQuadAtomIdsAllAtoms, std::map< dealii::CellId, std::vector< dftfe::Int > > &bQuadAtomIdsAllAtomsImages, std::map< dealii::CellId, std::vector< dftfe::uInt > > &bCellNonTrivialAtomIds, std::vector< std::map< dealii::CellId, std::vector< dftfe::uInt > > > &bCellNonTrivialAtomIdsBins, std::map< dealii::CellId, std::vector< dftfe::uInt > > &bCellNonTrivialAtomImageIds, std::vector< std::map< dealii::CellId, std::vector< dftfe::uInt > > > &bCellNonTrivialAtomImageIdsBins, const std::vector< double > &smearingWidths, std::vector< double > &smearedChargeScaling, const dftfe::uInt smearedChargeQuadratureId, const bool useSmearedCharges=false, const bool isVselfPerturbationSolve=false)
Solve nuclear electrostatic self-potential of atoms in each bin one-by-one.
void createAtomBinsSanityCheck(const dealii::DoFHandler< 3 > &dofHandler, const dealii::AffineConstraints< double > &onlyHangingNodeConstraints)
sanity check for Dirichlet boundary conditions on the vself balls in each bin
const std::vector< distributedCPUVec< double > > & getPerturbedVselfFieldBins() const
const std::vector< distributedCPUVec< double > > & getVselfFieldBins() const
get const reference to solved vself fields
std::vector< dealii::AffineConstraints< double > > d_vselfBinConstraintMatrices
vector of constraint matrices for vself bins
Definition vselfBinsManager.h:313
std::vector< std::map< dealii::types::global_dof_index, double > > d_vselfBinField
map of global dof index and vself field initial value in each bin
Definition vselfBinsManager.h:337
vselfBinsManager(const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const MPI_Comm &mpi_intercomm_kpts, const dftParameters &dftParams)
Constructor.
std::vector< std::map< dealii::types::global_dof_index, double > > d_atomsInBin
Definition vselfBinsManager.h:362
dftUtils::constraintMatrixInfo< dftfe::utils::MemorySpace::HOST > d_constraintsOnlyHangingInfo
storage for optimized constraints handling object
Definition vselfBinsManager.h:310
const std::map< dftfe::uInt, dftfe::uInt > & getAtomIdBinIdMapLocalAllImages() const
get const reference to d_atomIdBinIdMapLocalAllImages
const MPI_Comm mpi_communicator
Definition vselfBinsManager.h:371
std::map< dftfe::Int, std::set< dftfe::Int > > d_bins
map of binIds and atomIds
Definition vselfBinsManager.h:316
const MPI_Comm d_mpiInterCommKpts
Definition vselfBinsManager.h:372
std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > d_boundaryFlag
map of global dof index and vself solve boundary flag (chargeId or
Definition vselfBinsManager.h:324
dealii::ConditionalOStream pcout
Definition vselfBinsManager.h:375
void updateBinsBc(std::vector< const dealii::AffineConstraints< double > * > &constraintsVector, const dealii::AffineConstraints< double > &onlyHangingNodeConstraints, const dealii::DoFHandler< 3 > &dofHandler, const dealii::AffineConstraints< double > &constraintMatrix, const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imagePositions, const std::vector< dftfe::Int > &imageIds, const std::vector< double > &imageCharges, const bool vselfPerturbationUpdateForStress=false)
Categorize atoms into bins based on self-potential ball radius around each atom such that no two atom...
const std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > & getClosestAtomIdsBins() const
const dftfe::uInt this_mpi_process
Definition vselfBinsManager.h:374
std::vector< distributedCPUVec< double > > d_vselfFieldDerRBins
solved del{vself}/del{R_i} solution field for each bin
Definition vselfBinsManager.h:351
const dftfe::uInt n_mpi_processes
Definition vselfBinsManager.h:373
std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > d_closestAtomBin
map of global dof index and vself field initial value in each bin
Definition vselfBinsManager.h:341
const std::vector< std::map< dealii::types::global_dof_index, dftfe::Int > > & getBoundaryFlagsBins() const
std::vector< distributedCPUVec< double > > d_vselfFieldBins
solved vself solution field for each bin
Definition vselfBinsManager.h:348
const dftParameters & d_dftParams
Definition vselfBinsManager.h:368
const std::map< dftfe::Int, std::set< dftfe::Int > > & getAtomIdsBins() const
get const reference map of binIds and atomIds
Definition FEBasisOperations.h:30
@ DEVICE
Definition MemorySpaceType.h:36
Definition pseudoPotentialToDftfeConverter.cc:34
std::uint32_t uInt
Definition TypeConfig.h:10