DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
vectorUtilities.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#ifndef vectorUtilities_h
19#define vectorUtilities_h
20
21#include <headers.h>
22#include <operator.h>
23
24
25
26namespace dftfe
27{
28 /**
29 * @brief Contains generic utils functions related to custom partitioned flattened dealii vector
30 *
31 * @author Phani Motamarri, Sambit Das
32 */
33 namespace vectorTools
34 {
35 /** @brief Create constraint matrix using serial mesh.
36 * Temporary fix for a bug (Issue #7053) in deal.ii until it is resolved.
37 *
38 * @param[in] serial Triangulation which must be exactly same as the
39 * parallel triangulation associated with dofHandlerPar
40 * @param[in] parallel DofHandler
41 * @param[out] periodic hanging constraints.
42 * @param[out] only hanging constraints
43 */
44 void
46 const dealii::Triangulation<3, 3> &serTria,
47 const dealii::DoFHandler<3> &dofHandlerPar,
48 const MPI_Comm &mpi_comm_parent,
49 const MPI_Comm &mpi_comm_domain,
50 const std::vector<std::vector<double>> &domainBoundingVectors,
51 dealii::AffineConstraints<double> &periodicHangingConstraints,
52 dealii::AffineConstraints<double> &onlyHangingConstraints,
53 const dftfe::Int verbosity,
54 const bool periodicX,
55 const bool periodicY,
56 const bool periodicZ);
57
58
59 /** @brief Creates a custom partitioned flattened dealii vector.
60 * stores multiple components asociated with a node sequentially.
61 *
62 * @param partitioner associated with single component vector
63 * @param blockSize number of components associated with each node
64 *
65 * @return flattenedArray custom partitioned dealii vector
66 */
67 template <typename T>
68 void
70 const std::shared_ptr<const dealii::Utilities::MPI::Partitioner>
71 &partitioner,
72 const dftfe::uInt blockSize,
73 distributedCPUVec<T> &flattenedArray);
74
75
76
77 /** @brief Creates a cell local index set map for flattened array
78 *
79 * @param partitioner associated with the flattened array
80 * @param matrix_free_data object pointer associated with the matrix free data structure
81 * @param blockSize number of components associated with each node
82 *
83 * @return flattenedArrayMacroCellLocalProcIndexId macrocell's subcell local proc index map
84 * @return flattenedArrayCellLocalProcIndexId cell local proc index map
85 */
86 void
88 const std::shared_ptr<
90 &partitioner,
91 const dealii::MatrixFree<3, double> &matrix_free_data,
92 const dftfe::uInt mfDofHandlerIndex,
93 const dftfe::uInt blockSize,
94 std::vector<std::vector<dftfe::uInt>>
95 &flattenedArrayMacroCellLocalProcIndexId,
96 std::vector<std::vector<dftfe::uInt>>
97 &flattenedArrayCellLocalProcIndexId);
98
99
100 /** @brief Creates a cell local index set map for flattened array
101 *
102 * @param partitioner associated with the flattened array
103 * @param matrix_free_data object pointer associated with the matrix free data structure
104 * @param blockSize number of components associated with each node
105 *
106 * @return flattenedArrayMacroCellLocalProcIndexId macrocell's subcell local proc index map
107 * @return flattenedArrayCellLocalProcIndexId cell local proc index map
108 */
109 void
111 const std::shared_ptr<
113 &partitioner,
114 const dealii::MatrixFree<3, double> &matrix_free_data,
115 const dftfe::uInt mfDofHandlerIndex,
116 const dftfe::uInt blockSize,
117 std::vector<dftfe::uInt> &flattenedArrayMacroCellLocalProcIndexId,
118 std::vector<dftfe::uInt> &normalCellIdToMacroCellIdMap,
119 std::vector<dftfe::uInt> &macroCellIdToNormalCellIdMap,
120 std::vector<dftfe::uInt> &flattenedArrayCellLocalProcIndexId);
121
122 /** @brief Creates a cell local index set map for flattened array
123 *
124 * @param partitioner associated with the flattened array
125 * @param matrix_free_data object pointer associated with the matrix free data structure
126 * @param blockSize number of components associated with each node
127 *
128 * @return flattenedArrayMacroCellLocalProcIndexId macrocell's subcell local proc index map
129 * @return flattenedArrayCellLocalProcIndexId cell local proc index map
130 */
131 void
133 const std::shared_ptr<
135 &partitioner,
136 const dealii::MatrixFree<3, double> &matrix_free_data,
137 const dftfe::uInt mfDofHandlerIndex,
138 const dftfe::uInt blockSize,
139 std::vector<dftfe::uInt> &flattenedArrayCellLocalProcIndexId);
140
141
142#ifdef USE_COMPLEX
143 /** @brief Copies a single field component from a flattenedArray STL
144 * vector containing multiple component fields to a 2-component field (real
145 * and complex) parallel distributed vector.
146 *
147 * @param[in] flattenedArray flattened STL vector with multiple component
148 * fields
149 * @param[in] totalNumberComponents total number of component fiels in
150 * flattenedArray
151 * @param[in] componentIndexRange desired range field components
152 * [componentIndexRange.first,componentIndexRange.second)
153 * @param[in] localProcDofIndicesReal local dof indices in the current
154 * processor which correspond to component-1 of 2-component parallel
155 * distributed array
156 * @param[in] localProcDofIndicesImag local dof indices in the current
157 * processor which correspond to component-2 of 2-component parallel
158 * distributed array
159 * @param[out] componentVectors vector of two component field parallel
160 * distributed vectors with the values corresponding to fields of
161 * componentIndexRange of flattenedArray. componentVectors is expected to be
162 * of the size componentIndexRange.second-componentIndexRange.first.
163 * Further, each entry of componentVectors is assumed to be already
164 * initialized with the 2-component version of the same single component
165 * partitioner used in the creation of the flattenedArray partitioner.
166 */
167 void
169 const std::complex<double> *flattenedArray,
170 const dftfe::uInt totalNumberComponents,
171 const dftfe::uInt localVectorSize,
172 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
173 const std::vector<dealii::types::global_dof_index>
174 &localProcDofIndicesReal,
175 const std::vector<dealii::types::global_dof_index>
176 &localProcDofIndicesImag,
177 std::vector<distributedCPUVec<double>> &componentVectors);
178
179 void
181 const std::complex<double> *flattenedArray,
182 const dftfe::uInt totalNumberComponents,
183 const dftfe::uInt localVectorSize,
184 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
185
186 std::vector<distributedCPUVec<double>> &componentVectors);
187
188#else
189 /** @brief Copies a single field component from a flattenedArray STL
190 * vector containing multiple component fields to a single field parallel
191 * distributed vector.
192 *
193 * @param[in] flattenedArray flattened STL vector with multiple component
194 * fields
195 * @param[in] totalNumberComponents total number of component fiels in
196 * flattenedArray
197 * @param[in] componentIndexRange desired range field components
198 * [componentIndexRange.first,componentIndexRange.second)
199 * @param[out] componentVectors vector of parallel distributed vectors with
200 * fields corresponding to componentIndexRange. componentVectors is expected
201 * to be of the size componentIndexRange.second-componentIndexRange.first.
202 * Further, each entry of componentVectors is assumed to be already
203 * initialized with the same single component partitioner used in the
204 * creation of the flattenedArray partitioner.
205 */
206 void
208 const double *flattenedArray,
209 const dftfe::uInt totalNumberComponents,
210 const dftfe::uInt localVectorSize,
211 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
212 std::vector<distributedCPUVec<double>> &componentVectors);
213
214#endif
215
216#ifdef USE_COMPLEX
217 /** @brief Copies a single field component from a flattenedArray parallel distributed
218 * vector containing multiple component fields to a 2-component field (real
219 * and complex) parallel distributed vector.
220 *
221 * @param[in] flattenedArray flattened parallel distributed vector with
222 * multiple component fields
223 * @param[in] totalNumberComponents total number of component fiels in
224 * flattenedArray
225 * @param[in] componentIndexRange desired range field components
226 * [componentIndexRange.first,componentIndexRange.second)
227 * @param[in] localProcDofIndicesReal local dof indices in the current
228 * processor which correspond to component-1 of 2-component parallel
229 * distributed array
230 * @param[in] localProcDofIndicesImag local dof indices in the current
231 * processor which correspond to component-2 of 2-component parallel
232 * distributed array
233 * @param[out] componentVectors vector of two component field parallel
234 * distributed vectors with the values corresponding to fields of
235 * componentIndexRange of flattenedArray. componentVectors is expected to be
236 * of the size componentIndexRange.second-componentIndexRange.first.
237 * Further, each entry of componentVectors is assumed to be already
238 * initialized with the 2-component version of the same single component
239 * partitioner used in the creation of the flattenedArray partitioner.
240 * @param[in] isFlattenedDealiiGhostValuesUpdated default is false. Use
241 * true for optimization if update ghost values has already been called in
242 * the flattened dealii vec.
243 */
244 void
246 const distributedCPUVec<std::complex<double>> &flattenedArray,
247 const dftfe::uInt totalNumberComponents,
248 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
249 const std::vector<dealii::types::global_dof_index>
250 &localProcDofIndicesReal,
251 const std::vector<dealii::types::global_dof_index>
252 &localProcDofIndicesImag,
253 std::vector<distributedCPUVec<double>> &componentVectors,
254 const bool isFlattenedDealiiGhostValuesUpdated = false);
255
256#else
257 /** @brief Copies a single field component from a flattenedArray parallel distributed
258 * vector containing multiple component fields to a single field parallel
259 * distributed vector.
260 *
261 * @param[in] flattenedArray flattened parallel distributed vector with
262 * multiple component fields
263 * @param[in] totalNumberComponents total number of component fiels in
264 * flattenedArray
265 * @param[in] componentIndexRange desired range field components
266 * [componentIndexRange.first,componentIndexRange.second)
267 * @param[out] componentVectors vector of parallel distributed vectors with
268 * fields corresponding to componentIndexRange. componentVectors is expected
269 * to be of the size componentIndexRange.second-componentIndexRange.first.
270 * Further, each entry of componentVectors is assumed to be already
271 * initialized with the same single component partitioner used in the
272 * creation of the flattenedArray partitioner.
273 * @param[in] isFlattenedDealiiGhostValuesUpdated default is false. Use
274 * true for optimization if update ghost values has already been called in
275 * the flattened dealii vec.
276 */
277 void
279 const distributedCPUVec<double> &flattenedArray,
280 const dftfe::uInt totalNumberComponents,
281 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
282 std::vector<distributedCPUVec<double>> &componentVectors,
283 const bool isFlattenedDealiiGhostValuesUpdated = false);
284
285#endif
286
287#ifdef USE_COMPLEX
288 /** @brief Copies to a flattenedArray parallel distributed
289 * vector containing multiple component fields from a 2-component field
290 * (real and complex) parallel distributed vector.
291 *
292 * @param[out] flattenedArray flattened parallel distributed vector with
293 * multiple component fields
294 * @param[in] totalNumberComponents total number of component fiels in
295 * flattenedArray
296 * @param[in] componentIndexRange desired range field components
297 * [componentIndexRange.first,componentIndexRange.second)
298 * @param[in] localProcDofIndicesReal local dof indices in the current
299 * processor which correspond to component-1 of 2-component parallel
300 * distributed array
301 * @param[in] localProcDofIndicesImag local dof indices in the current
302 * processor which correspond to component-2 of 2-component parallel
303 * distributed array
304 * @param[in] componentVectors vector of two component field parallel
305 * distributed vectors with the values corresponding to fields of
306 * componentIndexRange of flattenedArray. componentVectors is expected to be
307 * of the size componentIndexRange.second-componentIndexRange.first.
308 * Further, each entry of componentVectors is assumed to be already
309 * initialized with the 2-component version of the same single component
310 * partitioner used in the creation of the flattenedArray partitioner.
311 */
312 void
314 distributedCPUVec<std::complex<double>> &flattenedArray,
315 const dftfe::uInt totalNumberComponents,
316 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
317 const std::vector<dealii::types::global_dof_index>
318 &localProcDofIndicesReal,
319 const std::vector<dealii::types::global_dof_index>
320 &localProcDofIndicesImag,
321 const std::vector<distributedCPUVec<double>> &componentVectors);
322
323#else
324 /** @brief Copies to a flattenedArray parallel distributed
325 * vector containing multiple component fields from a single field parallel
326 * distributed vector.
327 *
328 * @param[out] flattenedArray flattened parallel distributed vector with
329 * multiple component fields
330 * @param[in] totalNumberComponents total number of component fiels in
331 * flattenedArray
332 * @param[in] componentIndexRange desired range field components
333 * [componentIndexRange.first,componentIndexRange.second)
334 * @param[in] componentVectors vector of parallel distributed vectors with
335 * fields corresponding to componentIndexRange. componentVectors is expected
336 * to be of the size componentIndexRange.second-componentIndexRange.first.
337 * Further, each entry of componentVectors is assumed to be already
338 * initialized with the same single component partitioner used in the
339 * creation of the flattenedArray partitioner.
340 */
341 void
343 distributedCPUVec<double> &flattenedArray,
344 const dftfe::uInt totalNumberComponents,
345 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
346 const std::vector<distributedCPUVec<double>> &componentVectors);
347
348#endif
349
350#ifdef USE_COMPLEX
351 /** @brief Copies to a flattenedArray stl
352 * vector containing multiple component fields from a 2-component field
353 * (real and complex) parallel distributed vector.
354 *
355 * @param[out] flattenedArray flattened stl vector with multiple component
356 * fields
357 * @param[in] totalNumberComponents total number of component fiels in
358 * flattenedArray
359 * @param[in] componentIndexRange desired range field components
360 * [componentIndexRange.first,componentIndexRange.second)
361 * @param[in] localProcDofIndicesReal local dof indices in the current
362 * processor which correspond to component-1 of 2-component parallel
363 * distributed array
364 * @param[in] localProcDofIndicesImag local dof indices in the current
365 * processor which correspond to component-2 of 2-component parallel
366 * distributed array
367 * @param[in] componentVectors vector of two component field parallel
368 * distributed vectors with the values corresponding to fields of
369 * componentIndexRange of flattenedArray. componentVectors is expected to be
370 * of the size componentIndexRange.second-componentIndexRange.first.
371 * Further, each entry of componentVectors is assumed to be already
372 * initialized with the 2-component version of the same single component
373 * partitioner used in the creation of the flattenedArray partitioner.
374 */
375 void
377 std::vector<std::complex<double>> &flattenedArray,
378 const dftfe::uInt totalNumberComponents,
379 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
380 const std::vector<dealii::types::global_dof_index>
381 &localProcDofIndicesReal,
382 const std::vector<dealii::types::global_dof_index>
383 &localProcDofIndicesImag,
384 const std::vector<distributedCPUVec<double>> &componentVectors);
385
386#else
387 /** @brief Copies to a flattenedArray stl
388 * vector containing multiple component fields from a single field parallel
389 * distributed vector.
390 *
391 * @param[out] flattenedArray flattened stl vector with multiple component
392 * fields
393 * @param[in] totalNumberComponents total number of component fiels in
394 * flattenedArray
395 * @param[in] componentIndexRange desired range field components
396 * [componentIndexRange.first,componentIndexRange.second)
397 * @param[in] componentVectors vector of parallel distributed vectors with
398 * fields corresponding to componentIndexRange. componentVectors is expected
399 * to be of the size componentIndexRange.second-componentIndexRange.first.
400 * Further, each entry of componentVectors is assumed to be already
401 * initialized with the same single component partitioner used in the
402 * creation of the flattenedArray partitioner.
403 */
404 void
406 std::vector<double> &flattenedArray,
407 const dftfe::uInt totalNumberComponents,
408 const std::pair<dftfe::uInt, dftfe::uInt> componentIndexRange,
409 const std::vector<distributedCPUVec<double>> &componentVectors);
410
411#endif
412
413 std::pair<dealii::Point<3>, dealii::Point<3>>
414 createBoundingBoxTriaLocallyOwned(const dealii::DoFHandler<3> &dofHandler);
415
416
417 void
419 const dealii::MatrixFree<3, double> &matrix_free_data,
420 const dftfe::uInt mfDofHandlerIndex,
421 std::vector<dftfe::uInt> &nodesPerCellClassificationMap);
422
423
424 void
426 const dealii::MatrixFree<3, double> &matrix_free_data,
427 const dftfe::uInt mfDofHandlerIndex,
428 const dealii::AffineConstraints<double> &constraintMatrix,
429 std::vector<dftfe::uInt> &nodesPerCellClassificationMap,
430 std::vector<dftfe::uInt> &globalArrayClassificationMap);
431
432
433
434 } // namespace vectorTools
435} // namespace dftfe
436#endif
A class template to store the communication pattern (i.e., which entries/nodes to receive from which ...
Definition MPIPatternP2P.h:57
Contains generic utils functions related to custom partitioned flattened dealii vector.
Definition vectorUtilities.h:34
void classifyInteriorSurfaceNodesInCell(const dealii::MatrixFree< 3, double > &matrix_free_data, const dftfe::uInt mfDofHandlerIndex, std::vector< dftfe::uInt > &nodesPerCellClassificationMap)
void copyFlattenedSTLVecToSingleCompVec(const double *flattenedArray, const dftfe::uInt totalNumberComponents, const dftfe::uInt localVectorSize, const std::pair< dftfe::uInt, dftfe::uInt > componentIndexRange, std::vector< distributedCPUVec< double > > &componentVectors)
Copies a single field component from a flattenedArray STL vector containing multiple component fields...
void computeCellLocalIndexSetMap(const std::shared_ptr< const utils::mpi::MPIPatternP2P< dftfe::utils::MemorySpace::HOST > > &partitioner, const dealii::MatrixFree< 3, double > &matrix_free_data, const dftfe::uInt mfDofHandlerIndex, const dftfe::uInt blockSize, std::vector< std::vector< dftfe::uInt > > &flattenedArrayMacroCellLocalProcIndexId, std::vector< std::vector< dftfe::uInt > > &flattenedArrayCellLocalProcIndexId)
Creates a cell local index set map for flattened array.
void createDealiiVector(const std::shared_ptr< const dealii::Utilities::MPI::Partitioner > &partitioner, const dftfe::uInt blockSize, distributedCPUVec< T > &flattenedArray)
Creates a custom partitioned flattened dealii vector. stores multiple components asociated with a nod...
void createParallelConstraintMatrixFromSerial(const dealii::Triangulation< 3, 3 > &serTria, const dealii::DoFHandler< 3 > &dofHandlerPar, const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const std::vector< std::vector< double > > &domainBoundingVectors, dealii::AffineConstraints< double > &periodicHangingConstraints, dealii::AffineConstraints< double > &onlyHangingConstraints, const dftfe::Int verbosity, const bool periodicX, const bool periodicY, const bool periodicZ)
Create constraint matrix using serial mesh. Temporary fix for a bug (Issue #7053) in deal....
void copySingleCompVecToFlattenedDealiiVec(distributedCPUVec< double > &flattenedArray, const dftfe::uInt totalNumberComponents, const std::pair< dftfe::uInt, dftfe::uInt > componentIndexRange, const std::vector< distributedCPUVec< double > > &componentVectors)
Copies to a flattenedArray parallel distributed vector containing multiple component fields from a si...
std::pair< dealii::Point< 3 >, dealii::Point< 3 > > createBoundingBoxTriaLocallyOwned(const dealii::DoFHandler< 3 > &dofHandler)
void classifyInteriorSurfaceNodesInGlobalArray(const dealii::MatrixFree< 3, double > &matrix_free_data, const dftfe::uInt mfDofHandlerIndex, const dealii::AffineConstraints< double > &constraintMatrix, std::vector< dftfe::uInt > &nodesPerCellClassificationMap, std::vector< dftfe::uInt > &globalArrayClassificationMap)
void copySingleCompVecToFlattenedSTLVec(std::vector< double > &flattenedArray, const dftfe::uInt totalNumberComponents, const std::pair< dftfe::uInt, dftfe::uInt > componentIndexRange, const std::vector< distributedCPUVec< double > > &componentVectors)
Copies to a flattenedArray stl vector containing multiple component fields from a single field parall...
void copyFlattenedDealiiVecToSingleCompVec(const distributedCPUVec< double > &flattenedArray, const dftfe::uInt totalNumberComponents, const std::pair< dftfe::uInt, dftfe::uInt > componentIndexRange, std::vector< distributedCPUVec< double > > &componentVectors, const bool isFlattenedDealiiGhostValuesUpdated=false)
Copies a single field component from a flattenedArray parallel distributed vector containing multiple...
Definition pseudoPotentialToDftfeConverter.cc:34
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11