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 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 unsigned int 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 unsigned int mfDofHandlerIndex,
93 const unsigned int blockSize,
94 std::vector<std::vector<dealii::types::global_dof_index>>
95 &flattenedArrayMacroCellLocalProcIndexId,
96 std::vector<std::vector<dealii::types::global_dof_index>>
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 unsigned int mfDofHandlerIndex,
116 const unsigned int blockSize,
117 std::vector<dealii::types::global_dof_index>
118 & flattenedArrayMacroCellLocalProcIndexId,
119 std::vector<unsigned int> &normalCellIdToMacroCellIdMap,
120 std::vector<unsigned int> &macroCellIdToNormalCellIdMap,
121 std::vector<dealii::types::global_dof_index>
122 &flattenedArrayCellLocalProcIndexId);
123
124 /** @brief Creates a cell local index set map for flattened array
125 *
126 * @param partitioner associated with the flattened array
127 * @param matrix_free_data object pointer associated with the matrix free data structure
128 * @param blockSize number of components associated with each node
129 *
130 * @return flattenedArrayMacroCellLocalProcIndexId macrocell's subcell local proc index map
131 * @return flattenedArrayCellLocalProcIndexId cell local proc index map
132 */
133 void
135 const std::shared_ptr<
137 & partitioner,
138 const dealii::MatrixFree<3, double> &matrix_free_data,
139 const unsigned int mfDofHandlerIndex,
140 const unsigned int blockSize,
141 std::vector<dealii::types::global_dof_index>
142 &flattenedArrayCellLocalProcIndexId);
143
144
145#ifdef USE_COMPLEX
146 /** @brief Copies a single field component from a flattenedArray STL
147 * vector containing multiple component fields to a 2-component field (real
148 * and complex) parallel distributed vector.
149 *
150 * @param[in] flattenedArray flattened STL vector with multiple component
151 * fields
152 * @param[in] totalNumberComponents total number of component fiels in
153 * flattenedArray
154 * @param[in] componentIndexRange desired range field components
155 * [componentIndexRange.first,componentIndexRange.second)
156 * @param[in] localProcDofIndicesReal local dof indices in the current
157 * processor which correspond to component-1 of 2-component parallel
158 * distributed array
159 * @param[in] localProcDofIndicesImag local dof indices in the current
160 * processor which correspond to component-2 of 2-component parallel
161 * distributed array
162 * @param[out] componentVectors vector of two component field parallel
163 * distributed vectors with the values corresponding to fields of
164 * componentIndexRange of flattenedArray. componentVectors is expected to be
165 * of the size componentIndexRange.second-componentIndexRange.first.
166 * Further, each entry of componentVectors is assumed to be already
167 * initialized with the 2-component version of the same single component
168 * partitioner used in the creation of the flattenedArray partitioner.
169 */
170 void
172 const std::complex<double> * flattenedArray,
173 const unsigned int totalNumberComponents,
174 const unsigned int localVectorSize,
175 const std::pair<unsigned int, unsigned int> componentIndexRange,
176 const std::vector<dealii::types::global_dof_index>
177 &localProcDofIndicesReal,
178 const std::vector<dealii::types::global_dof_index>
179 & localProcDofIndicesImag,
180 std::vector<distributedCPUVec<double>> &componentVectors);
181
182 void
184 const std::complex<double> * flattenedArray,
185 const unsigned int totalNumberComponents,
186 const unsigned int localVectorSize,
187 const std::pair<unsigned int, unsigned int> componentIndexRange,
188
189 std::vector<distributedCPUVec<double>> &componentVectors);
190
191#else
192 /** @brief Copies a single field component from a flattenedArray STL
193 * vector containing multiple component fields to a single field parallel
194 * distributed vector.
195 *
196 * @param[in] flattenedArray flattened STL vector with multiple component
197 * fields
198 * @param[in] totalNumberComponents total number of component fiels in
199 * flattenedArray
200 * @param[in] componentIndexRange desired range field components
201 * [componentIndexRange.first,componentIndexRange.second)
202 * @param[out] componentVectors vector of parallel distributed vectors with
203 * fields corresponding to componentIndexRange. componentVectors is expected
204 * to be of the size componentIndexRange.second-componentIndexRange.first.
205 * Further, each entry of componentVectors is assumed to be already
206 * initialized with the same single component partitioner used in the
207 * creation of the flattenedArray partitioner.
208 */
209 void
211 const double * flattenedArray,
212 const unsigned int totalNumberComponents,
213 const unsigned int localVectorSize,
214 const std::pair<unsigned int, unsigned int> componentIndexRange,
215 std::vector<distributedCPUVec<double>> & componentVectors);
216
217#endif
218
219#ifdef USE_COMPLEX
220 /** @brief Copies a single field component from a flattenedArray parallel distributed
221 * vector containing multiple component fields to a 2-component field (real
222 * and complex) parallel distributed vector.
223 *
224 * @param[in] flattenedArray flattened parallel distributed vector with
225 * multiple component fields
226 * @param[in] totalNumberComponents total number of component fiels in
227 * flattenedArray
228 * @param[in] componentIndexRange desired range field components
229 * [componentIndexRange.first,componentIndexRange.second)
230 * @param[in] localProcDofIndicesReal local dof indices in the current
231 * processor which correspond to component-1 of 2-component parallel
232 * distributed array
233 * @param[in] localProcDofIndicesImag local dof indices in the current
234 * processor which correspond to component-2 of 2-component parallel
235 * distributed array
236 * @param[out] componentVectors vector of two component field parallel
237 * distributed vectors with the values corresponding to fields of
238 * componentIndexRange of flattenedArray. componentVectors is expected to be
239 * of the size componentIndexRange.second-componentIndexRange.first.
240 * Further, each entry of componentVectors is assumed to be already
241 * initialized with the 2-component version of the same single component
242 * partitioner used in the creation of the flattenedArray partitioner.
243 * @param[in] isFlattenedDealiiGhostValuesUpdated default is false. Use
244 * true for optimization if update ghost values has already been called in
245 * the flattened dealii vec.
246 */
247 void
249 const distributedCPUVec<std::complex<double>> &flattenedArray,
250 const unsigned int totalNumberComponents,
251 const std::pair<unsigned int, unsigned int> componentIndexRange,
252 const std::vector<dealii::types::global_dof_index>
253 &localProcDofIndicesReal,
254 const std::vector<dealii::types::global_dof_index>
255 & localProcDofIndicesImag,
256 std::vector<distributedCPUVec<double>> &componentVectors,
257 const bool isFlattenedDealiiGhostValuesUpdated = false);
258
259#else
260 /** @brief Copies a single field component from a flattenedArray parallel distributed
261 * vector containing multiple component fields to a single field parallel
262 * distributed vector.
263 *
264 * @param[in] flattenedArray flattened parallel distributed vector with
265 * multiple component fields
266 * @param[in] totalNumberComponents total number of component fiels in
267 * flattenedArray
268 * @param[in] componentIndexRange desired range field components
269 * [componentIndexRange.first,componentIndexRange.second)
270 * @param[out] componentVectors vector of parallel distributed vectors with
271 * fields corresponding to componentIndexRange. componentVectors is expected
272 * to be of the size componentIndexRange.second-componentIndexRange.first.
273 * Further, each entry of componentVectors is assumed to be already
274 * initialized with the same single component partitioner used in the
275 * creation of the flattenedArray partitioner.
276 * @param[in] isFlattenedDealiiGhostValuesUpdated default is false. Use
277 * true for optimization if update ghost values has already been called in
278 * the flattened dealii vec.
279 */
280 void
282 const distributedCPUVec<double> & flattenedArray,
283 const unsigned int totalNumberComponents,
284 const std::pair<unsigned int, unsigned int> componentIndexRange,
285 std::vector<distributedCPUVec<double>> & componentVectors,
286 const bool isFlattenedDealiiGhostValuesUpdated = false);
287
288#endif
289
290#ifdef USE_COMPLEX
291 /** @brief Copies to a flattenedArray parallel distributed
292 * vector containing multiple component fields from a 2-component field
293 * (real and complex) parallel distributed vector.
294 *
295 * @param[out] flattenedArray flattened parallel distributed vector with
296 * multiple component fields
297 * @param[in] totalNumberComponents total number of component fiels in
298 * flattenedArray
299 * @param[in] componentIndexRange desired range field components
300 * [componentIndexRange.first,componentIndexRange.second)
301 * @param[in] localProcDofIndicesReal local dof indices in the current
302 * processor which correspond to component-1 of 2-component parallel
303 * distributed array
304 * @param[in] localProcDofIndicesImag local dof indices in the current
305 * processor which correspond to component-2 of 2-component parallel
306 * distributed array
307 * @param[in] componentVectors vector of two component field parallel
308 * distributed vectors with the values corresponding to fields of
309 * componentIndexRange of flattenedArray. componentVectors is expected to be
310 * of the size componentIndexRange.second-componentIndexRange.first.
311 * Further, each entry of componentVectors is assumed to be already
312 * initialized with the 2-component version of the same single component
313 * partitioner used in the creation of the flattenedArray partitioner.
314 */
315 void
317 distributedCPUVec<std::complex<double>> & flattenedArray,
318 const unsigned int totalNumberComponents,
319 const std::pair<unsigned int, unsigned int> componentIndexRange,
320 const std::vector<dealii::types::global_dof_index>
321 &localProcDofIndicesReal,
322 const std::vector<dealii::types::global_dof_index>
323 & localProcDofIndicesImag,
324 const std::vector<distributedCPUVec<double>> &componentVectors);
325
326#else
327 /** @brief Copies to a flattenedArray parallel distributed
328 * vector containing multiple component fields from a single field parallel
329 * distributed vector.
330 *
331 * @param[out] flattenedArray flattened parallel distributed vector with
332 * multiple component fields
333 * @param[in] totalNumberComponents total number of component fiels in
334 * flattenedArray
335 * @param[in] componentIndexRange desired range field components
336 * [componentIndexRange.first,componentIndexRange.second)
337 * @param[in] componentVectors vector of parallel distributed vectors with
338 * fields corresponding to componentIndexRange. componentVectors is expected
339 * to be of the size componentIndexRange.second-componentIndexRange.first.
340 * Further, each entry of componentVectors is assumed to be already
341 * initialized with the same single component partitioner used in the
342 * creation of the flattenedArray partitioner.
343 */
344 void
346 distributedCPUVec<double> & flattenedArray,
347 const unsigned int totalNumberComponents,
348 const std::pair<unsigned int, unsigned int> componentIndexRange,
349 const std::vector<distributedCPUVec<double>> &componentVectors);
350
351#endif
352
353#ifdef USE_COMPLEX
354 /** @brief Copies to a flattenedArray stl
355 * vector containing multiple component fields from a 2-component field
356 * (real and complex) parallel distributed vector.
357 *
358 * @param[out] flattenedArray flattened stl vector with multiple component
359 * fields
360 * @param[in] totalNumberComponents total number of component fiels in
361 * flattenedArray
362 * @param[in] componentIndexRange desired range field components
363 * [componentIndexRange.first,componentIndexRange.second)
364 * @param[in] localProcDofIndicesReal local dof indices in the current
365 * processor which correspond to component-1 of 2-component parallel
366 * distributed array
367 * @param[in] localProcDofIndicesImag local dof indices in the current
368 * processor which correspond to component-2 of 2-component parallel
369 * distributed array
370 * @param[in] componentVectors vector of two component field parallel
371 * distributed vectors with the values corresponding to fields of
372 * componentIndexRange of flattenedArray. componentVectors is expected to be
373 * of the size componentIndexRange.second-componentIndexRange.first.
374 * Further, each entry of componentVectors is assumed to be already
375 * initialized with the 2-component version of the same single component
376 * partitioner used in the creation of the flattenedArray partitioner.
377 */
378 void
380 std::vector<std::complex<double>> & flattenedArray,
381 const unsigned int totalNumberComponents,
382 const std::pair<unsigned int, unsigned int> componentIndexRange,
383 const std::vector<dealii::types::global_dof_index>
384 &localProcDofIndicesReal,
385 const std::vector<dealii::types::global_dof_index>
386 & localProcDofIndicesImag,
387 const std::vector<distributedCPUVec<double>> &componentVectors);
388
389#else
390 /** @brief Copies to a flattenedArray stl
391 * vector containing multiple component fields from a single field parallel
392 * distributed vector.
393 *
394 * @param[out] flattenedArray flattened stl vector with multiple component
395 * fields
396 * @param[in] totalNumberComponents total number of component fiels in
397 * flattenedArray
398 * @param[in] componentIndexRange desired range field components
399 * [componentIndexRange.first,componentIndexRange.second)
400 * @param[in] componentVectors vector of parallel distributed vectors with
401 * fields corresponding to componentIndexRange. componentVectors is expected
402 * to be of the size componentIndexRange.second-componentIndexRange.first.
403 * Further, each entry of componentVectors is assumed to be already
404 * initialized with the same single component partitioner used in the
405 * creation of the flattenedArray partitioner.
406 */
407 void
409 std::vector<double> & flattenedArray,
410 const unsigned int totalNumberComponents,
411 const std::pair<unsigned int, unsigned int> componentIndexRange,
412 const std::vector<distributedCPUVec<double>> &componentVectors);
413
414#endif
415
416 std::pair<dealii::Point<3>, dealii::Point<3>>
417 createBoundingBoxTriaLocallyOwned(const dealii::DoFHandler<3> &dofHandler);
418
419
420 void
422 const dealii::MatrixFree<3, double> &matrix_free_data,
423 const unsigned int mfDofHandlerIndex,
424 std::vector<unsigned int> & nodesPerCellClassificationMap);
425
426
427 void
429 const dealii::MatrixFree<3, double> & matrix_free_data,
430 const unsigned int mfDofHandlerIndex,
431 const dealii::AffineConstraints<double> &constraintMatrix,
432 std::vector<unsigned int> & nodesPerCellClassificationMap,
433 std::vector<unsigned int> & globalArrayClassificationMap);
434
435
436
437 } // namespace vectorTools
438} // namespace dftfe
439#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 copySingleCompVecToFlattenedDealiiVec(distributedCPUVec< double > &flattenedArray, const unsigned int totalNumberComponents, const std::pair< unsigned int, unsigned int > componentIndexRange, const std::vector< distributedCPUVec< double > > &componentVectors)
Copies to a flattenedArray parallel distributed vector containing multiple component fields from a si...
void createDealiiVector(const std::shared_ptr< const dealii::Utilities::MPI::Partitioner > &partitioner, const unsigned int blockSize, distributedCPUVec< T > &flattenedArray)
Creates a custom partitioned flattened dealii vector. stores multiple components asociated with a nod...
void computeCellLocalIndexSetMap(const std::shared_ptr< const utils::mpi::MPIPatternP2P< dftfe::utils::MemorySpace::HOST > > &partitioner, const dealii::MatrixFree< 3, double > &matrix_free_data, const unsigned int mfDofHandlerIndex, const unsigned int blockSize, std::vector< std::vector< dealii::types::global_dof_index > > &flattenedArrayMacroCellLocalProcIndexId, std::vector< std::vector< dealii::types::global_dof_index > > &flattenedArrayCellLocalProcIndexId)
Creates a cell local index set map for flattened array.
std::pair< dealii::Point< 3 >, dealii::Point< 3 > > createBoundingBoxTriaLocallyOwned(const dealii::DoFHandler< 3 > &dofHandler)
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 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 copySingleCompVecToFlattenedSTLVec(std::vector< double > &flattenedArray, const unsigned int totalNumberComponents, const std::pair< unsigned int, unsigned int > componentIndexRange, const std::vector< distributedCPUVec< double > > &componentVectors)
Copies to a flattenedArray stl vector containing multiple component fields from a single field parall...
void classifyInteriorSurfaceNodesInGlobalArray(const dealii::MatrixFree< 3, double > &matrix_free_data, const unsigned int mfDofHandlerIndex, const dealii::AffineConstraints< double > &constraintMatrix, std::vector< unsigned int > &nodesPerCellClassificationMap, std::vector< unsigned int > &globalArrayClassificationMap)
void copyFlattenedDealiiVecToSingleCompVec(const distributedCPUVec< double > &flattenedArray, const unsigned int totalNumberComponents, const std::pair< unsigned int, unsigned int > componentIndexRange, std::vector< distributedCPUVec< double > > &componentVectors, const bool isFlattenedDealiiGhostValuesUpdated=false)
Copies a single field component from a flattenedArray parallel distributed vector containing multiple...
void copyFlattenedSTLVecToSingleCompVec(const double *flattenedArray, const unsigned int totalNumberComponents, const unsigned int localVectorSize, const std::pair< unsigned int, unsigned int > componentIndexRange, std::vector< distributedCPUVec< double > > &componentVectors)
Copies a single field component from a flattenedArray STL vector containing multiple component fields...
void classifyInteriorSurfaceNodesInCell(const dealii::MatrixFree< 3, double > &matrix_free_data, const unsigned int mfDofHandlerIndex, std::vector< unsigned int > &nodesPerCellClassificationMap)
Definition pseudoPotentialToDftfeConverter.cc:34
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92