DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
InterpolateCellWiseDataToPoints.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/*
19 * @author Vishal Subramanian, Bikash Kanungo
20 */
21
22#ifndef DFTFE_INTERPOLATECELLWISEDATATOPOINTS_H
23#define DFTFE_INTERPOLATECELLWISEDATATOPOINTS_H
24
25#include <boost/geometry.hpp>
26#include <boost/geometry/index/rtree.hpp>
27#include <boost/range/adaptors.hpp>
28#include "BLASWrapper.h"
29#include "MapPointsToCells.h"
30#include "Cell.h"
32
33
34namespace dftfe
35{
36 /**
37 * @brief This class forms the interface for interpolating data to an arbitrary set of
38 * points. This class is compatible with MPI, where the partitioning of cells
39 * and the points need not be compatible. As in the points need not lie within
40 * the cells assigned to the processor.
41 *
42 * @author Vishal Subramanian, Bikash Kanungo
43 */
44 template <typename T, dftfe::utils::MemorySpace memorySpace>
46 {
47 public:
48 /**
49 * @brief This constructor computes the mapping between the targetPts and srcCells.
50 * In case of incompatible partitioning, some targetPts can lie outside the
51 * cells assigned to the processor. In that case, the unmapped points are
52 * sent to other processors. Similarly it receives points from other
53 * processors and checks if any of them lies within its cells. Once all the
54 * points that lie within its cells are found, they are then passed to
55 * interpolateLocalObj, which provides the functionality to interpolate to
56 * those points
57 * @param[in] srcCells Cells that are assigned to the processor
58 * @param[in] interpolateLocalObj Class that can take in a Cell and provide
59 * the functionality to interpolate to points that lie within that Cell.
60 * @param[in] targetPts The set of points onto which the data needs to be
61 * interpolated
62 * @param[in] numDofsPerElem The number of basis function that is non-zero
63 * overlap with each cell. This is set to be a vector so that different
64 * cells can have different number of basis functions.
65 * @param[in] mpiComm The mpi communicator which has been used for the
66 * domain decomposition
67 *
68 * @author Vishal Subramanian, Bikash Kanungo
69 */
71 const std::vector<std::shared_ptr<const dftfe::utils::Cell<3>>> &srcCells,
72 std::vector<
74 interpolateLocalObj,
75 const std::vector<std::vector<double>> &targetPts,
76 const std::vector<unsigned int> & numDofsPerElem,
77 const unsigned int verbosity,
78 const MPI_Comm & mpiComm);
79 /**
80 * @brief This function interpolates from the data to the points passed to the constructor.
81 * The function copies the nodal data to cell wise data and then
82 * interpolates to all the points that lie within that cell. Then they are
83 * copied to the output vector. At the end a mpi call is performed to gather
84 * the value of points that do not lie within processor from othe
85 * processors.
86 * @param[in] BLASWrapperPtr BLAS Wrapper that provides the handle to the
87 * linear algebra routines
88 * @param[in] inputVec The input data. The input data should be of size
89 * locally_owned*numberOfVectors
90 * @param[in] numberOfVectors The number of vectors (blockSize) in the input
91 * data
92 * @param[in] mapVecToCells The mapping that tells the nodal data to the
93 * cell wise data
94 * @param[out] outputData The output where the nodal data is interpolated to
95 * the points. The memory layout of outputData is as follows - the memory is
96 * stored in the same order as the target points. In addition to the target
97 * points, there are ghost points which are points that lie within its cells
98 * but lie in cells assigned to a different processor.
99 * @param[in] resizeData The output data should be of size (locally owned +
100 * ghost)*numberOfVectors If the flag resizeData is set to true, outputData
101 * is resized appropriately.
102 *
103 * @author Vishal Subramanian, Bikash Kanungo
104 */
105 void
108 & BLASWrapperPtr,
110 const unsigned int numberOfVectors,
112 & mapVecToCells,
114 const unsigned int blockSizeOfInputData,
115 const unsigned int blockSizeOfOutputData,
116 const unsigned int startIndexOfInputData,
117 bool resizeData = false);
118
119 /**
120 * @brief The function is same as above but set to dealii:distributed::Vector
121 * @param[in] BLASWrapperPtr BLAS Wrapper that provides the handle to the
122 * linear algebra routines
123 * @param[in] inputVec The input data. The input data should be of size
124 * locally_owned*numberOfVectors
125 * @param[in] numberOfVectors The number of vectors (blockSize) in the input
126 * data
127 * @param[in] mapVecToCells The mapping that tells the nodal data to the
128 * cell wise data
129 * @param[out] outputData The output where the nodal data is interpolated to
130 * the points. The memory layout of outputData is as follows - the memory is
131 * stored in the same order as the target points. In addition to the target
132 * points, there are ghost points which are points that lie within its cells
133 * but lie in cells assigned to a different processor.
134 * @param[in] resizeData The output data should be of size (locally owned +
135 * ghost)*numberOfVectors If the flag resizeData is set to true, outputData
136 * is resized appropriately.
137 *
138 * @author Vishal Subramanian, Bikash Kanungo
139 */
140 void
142 const std::shared_ptr<
144 & BLASWrapperPtr,
145 const distributedCPUVec<T> &inputVec,
146 const unsigned int numberOfVectors,
149 &mapVecToCells,
151 & outputData,
152 const unsigned int blockSizeOfInputData,
153 const unsigned int blockSizeOfOutputData,
154 const unsigned int startIndexOfInputData,
155 bool resizeData = false);
156
157 private:
158 void
159 checkIfAllPointsAreFound(const std::vector<std::vector<double>> &targetPts);
160
161
163 d_mapPoints; /// TODO check if M=8 is optimal
164 // std::vector<T> d_shapeFuncValues;
166 const MPI_Comm d_mpiComm;
167
168 std::shared_ptr<
171
172 std::shared_ptr<
175
176 std::shared_ptr<dftfe::utils::mpi::MPIPatternP2P<memorySpace>>
178 std::unique_ptr<dftfe::utils::mpi::MPICommunicatorP2P<T, memorySpace>>
180
181
184
185
188
191 std::vector<unsigned int> d_numDofsPerElement;
192 std::vector<unsigned int> d_cumulativeDofs;
194
195 std::vector<size_type> d_numPointsInCell;
196
197 std::vector<std::vector<size_type>> d_mapCellLocalToProcLocal;
198
199
201
203
204 std::vector<global_size_type> d_ghostGlobalIds;
205 std::pair<global_size_type, global_size_type> d_localRange;
206
209
210 std::vector<std::shared_ptr<InterpolateFromCellToLocalPoints<memorySpace>>>
212 unsigned int d_verbosity;
213 }; // end of class InterpolateCellWiseDataToPoints
214} // end of namespace dftfe
215
216
217#endif // DFTFE_INTERPOLATECELLWISEDATATOPOINTS_H
std::vector< std::shared_ptr< InterpolateFromCellToLocalPoints< memorySpace > > > d_interpolateLocalObj
Definition InterpolateCellWiseDataToPoints.h:211
std::vector< std::vector< size_type > > d_mapCellLocalToProcLocal
Definition InterpolateCellWiseDataToPoints.h:197
void interpolateSrcDataToTargetPoints(const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > &BLASWrapperPtr, const dftfe::linearAlgebra::MultiVector< T, memorySpace > &inputVec, const unsigned int numberOfVectors, const dftfe::utils::MemoryStorage< dftfe::global_size_type, memorySpace > &mapVecToCells, dftfe::utils::MemoryStorage< T, memorySpace > &outputData, const unsigned int blockSizeOfInputData, const unsigned int blockSizeOfOutputData, const unsigned int startIndexOfInputData, bool resizeData=false)
This function interpolates from the data to the points passed to the constructor. The function copies...
dftfe::utils::MemoryStorage< dataTypes::number, memorySpace > d_tempOutputMemSpace
Definition InterpolateCellWiseDataToPoints.h:208
dftfe::utils::MapPointsToCells< 3, 8 > d_mapPoints
Definition InterpolateCellWiseDataToPoints.h:163
size_type d_numLocalPtsSze
Definition InterpolateCellWiseDataToPoints.h:200
std::vector< size_type > d_cellPointStartIndex
TODO check if M=8 is optimal.
Definition InterpolateCellWiseDataToPoints.h:165
size_type totalDofsInCells
Definition InterpolateCellWiseDataToPoints.h:193
std::vector< unsigned int > d_cumulativeDofs
Definition InterpolateCellWiseDataToPoints.h:192
dftfe::utils::MemoryStorage< global_size_type, memorySpace > d_mapPointToProcLocalMemSpace
Definition InterpolateCellWiseDataToPoints.h:183
std::pair< global_size_type, global_size_type > d_localRange
Definition InterpolateCellWiseDataToPoints.h:205
unsigned int d_verbosity
Definition InterpolateCellWiseDataToPoints.h:212
size_type d_numCells
Definition InterpolateCellWiseDataToPoints.h:190
void interpolateSrcDataToTargetPoints(const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const distributedCPUVec< T > &inputVec, const unsigned int numberOfVectors, const dftfe::utils::MemoryStorage< dftfe::global_size_type, dftfe::utils::MemorySpace::HOST > &mapVecToCells, dftfe::utils::MemoryStorage< T, dftfe::utils::MemorySpace::HOST > &outputData, const unsigned int blockSizeOfInputData, const unsigned int blockSizeOfOutputData, const unsigned int startIndexOfInputData, bool resizeData=false)
The function is same as above but set to dealii:distributed::Vector.
std::shared_ptr< dftfe::utils::mpi::MPIPatternP2P< memorySpace > > d_mpiP2PPtrMemSpace
Definition InterpolateCellWiseDataToPoints.h:177
dftfe::utils::MemoryStorage< dataTypes::number, memorySpace > d_cellLevelParentNodalMemSpace
Definition InterpolateCellWiseDataToPoints.h:187
const MPI_Comm d_mpiComm
Definition InterpolateCellWiseDataToPoints.h:166
size_type d_pointsFoundInProc
Definition InterpolateCellWiseDataToPoints.h:202
std::unique_ptr< dftfe::utils::mpi::MPICommunicatorP2P< T, memorySpace > > d_mpiCommPtrMemSpace
Definition InterpolateCellWiseDataToPoints.h:179
std::vector< size_type > d_cellShapeFuncStartIndex
Definition InterpolateCellWiseDataToPoints.h:165
std::vector< size_type > d_numPointsInCell
Definition InterpolateCellWiseDataToPoints.h:195
InterpolateCellWiseDataToPoints(const std::vector< std::shared_ptr< const dftfe::utils::Cell< 3 > > > &srcCells, std::vector< std::shared_ptr< InterpolateFromCellToLocalPoints< memorySpace > > > interpolateLocalObj, const std::vector< std::vector< double > > &targetPts, const std::vector< unsigned int > &numDofsPerElem, const unsigned int verbosity, const MPI_Comm &mpiComm)
This constructor computes the mapping between the targetPts and srcCells. In case of incompatible par...
std::vector< unsigned int > d_numDofsPerElement
Definition InterpolateCellWiseDataToPoints.h:191
std::shared_ptr< dftfe::utils::mpi::MPIPatternP2P< dftfe::utils::MemorySpace::HOST > > d_mpiPatternP2PPtr
Definition InterpolateCellWiseDataToPoints.h:170
size_type d_numPointsLocal
Definition InterpolateCellWiseDataToPoints.h:189
std::shared_ptr< dftfe::utils::mpi::MPICommunicatorP2P< T, dftfe::utils::MemorySpace::HOST > > d_mpiCommP2PPtr
Definition InterpolateCellWiseDataToPoints.h:174
void checkIfAllPointsAreFound(const std::vector< std::vector< double > > &targetPts)
std::vector< global_size_type > d_ghostGlobalIds
Definition InterpolateCellWiseDataToPoints.h:204
Definition InterpolateFromCellToLocalPoints.h:36
Definition BLASWrapper.h:35
An class template to encapsulate a MultiVector. A MultiVector is a collection of vectors belonging t...
Definition MultiVector.h:127
This class provides the interface that will be required while interpolating a nodal data to arbitrary...
Definition Cell.h:45
This class takes in a bunch of points and finds the cell (provided as input) it lies in....
Definition MapPointsToCells.h:49
Definition MemoryStorage.h:33
Definition MPICommunicatorP2P.h:63
A class template to store the communication pattern (i.e., which entries/nodes to receive from which ...
Definition MPIPatternP2P.h:57
@ HOST
Definition MemorySpaceType.h:34
Definition pseudoPotentialToDftfeConverter.cc:34
unsigned int size_type
Definition TypeConfig.h:6
unsigned long int global_size_type
Definition TypeConfig.h:7
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92