|
| 1 | +#include <dftfe/dealiiLinearSolverProblem.h> |
| 2 | +#include <dftfe/triangulationManager.h> |
| 3 | +#include <dftfe/FEBasisOperations.h> |
| 4 | + |
| 5 | +#ifndef ldosSolverProblem_H_ |
| 6 | +# define ldosSolverProblem_H_ |
| 7 | + |
| 8 | +namespace dftfe |
| 9 | +{ |
| 10 | + template <dftfe::uInt FEOrderElectro> |
| 11 | + class ldosSolverProblem : public dealiiLinearSolverProblem |
| 12 | + { |
| 13 | + public: |
| 14 | + /// Constructor |
| 15 | + ldosSolverProblem(const MPI_Comm &mpi_comm_parent, |
| 16 | + const MPI_Comm &mpi_comm_domain); |
| 17 | + |
| 18 | + /** |
| 19 | + * @brief initialize the matrix-free data structures |
| 20 | + * |
| 21 | + */ |
| 22 | + void |
| 23 | + init(std::shared_ptr< |
| 24 | + dftfe::basis:: |
| 25 | + FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>> |
| 26 | + &basisOperationsPtr, |
| 27 | + dealii::AffineConstraints<double> &constraintMatrix, |
| 28 | + distributedCPUVec<double> &x, |
| 29 | + const dftfe::uInt matrixFreeVectorComponent, |
| 30 | + const dftfe::uInt matrixFreeQuadratureComponent, |
| 31 | + const dftfe::uInt matrixFreeAxQuadratureComponent, |
| 32 | + const bool isComputeMeanValueConstraint); |
| 33 | + |
| 34 | + /** |
| 35 | + * @brief reinitialize data structures . |
| 36 | + * |
| 37 | + */ |
| 38 | + void |
| 39 | + reinit( |
| 40 | + distributedCPUVec<double> &x, |
| 41 | + const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST> |
| 42 | + &residualQuadValues, |
| 43 | + const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST> |
| 44 | + &ldosAxQuadValues); |
| 45 | + |
| 46 | + /** |
| 47 | + * @brief get the reference to x field |
| 48 | + * |
| 49 | + */ |
| 50 | + distributedCPUVec<double> & |
| 51 | + getX(); |
| 52 | + |
| 53 | + /** |
| 54 | + * @brief Compute A matrix multipled by x. |
| 55 | + * |
| 56 | + */ |
| 57 | + void |
| 58 | + vmult(distributedCPUVec<double> &Ax, distributedCPUVec<double> &x); |
| 59 | + |
| 60 | + /** |
| 61 | + * @brief Compute right hand side vector for the problem Ax = rhs. |
| 62 | + * |
| 63 | + */ |
| 64 | + void |
| 65 | + computeRhs(distributedCPUVec<double> &rhs); |
| 66 | + |
| 67 | + /** |
| 68 | + * @brief Jacobi preconditioning. |
| 69 | + * |
| 70 | + */ |
| 71 | + void |
| 72 | + precondition_Jacobi(distributedCPUVec<double> &dst, |
| 73 | + const distributedCPUVec<double> &src, |
| 74 | + const double omega) const; |
| 75 | + |
| 76 | + /** |
| 77 | + * @brief distribute x to the constrained nodes. |
| 78 | + * |
| 79 | + */ |
| 80 | + void |
| 81 | + distributeX(); |
| 82 | + |
| 83 | + /// function needed by dealii to mimic SparseMatrix for Jacobi |
| 84 | + /// preconditioning |
| 85 | + void |
| 86 | + subscribe(std::atomic<bool> *const validity, |
| 87 | + const std::string &identifier = "") const {}; |
| 88 | + |
| 89 | + /// function needed by dealii to mimic SparseMatrix for Jacobi |
| 90 | + /// preconditioning |
| 91 | + void |
| 92 | + unsubscribe(std::atomic<bool> *const validity, |
| 93 | + const std::string &identifier = "") const {}; |
| 94 | + |
| 95 | + /// function needed by dealii to mimic SparseMatrix |
| 96 | + bool |
| 97 | + operator!=(double val) const |
| 98 | + { |
| 99 | + return true; |
| 100 | + }; |
| 101 | + |
| 102 | + const distributedCPUVec<double> & |
| 103 | + getDlocMassVector() const; |
| 104 | + |
| 105 | + double |
| 106 | + computeDlocIntegral(const distributedCPUVec<double> &phi) const; |
| 107 | + |
| 108 | + double |
| 109 | + getTotalDOS() const; |
| 110 | + |
| 111 | + private: |
| 112 | + void |
| 113 | + computeMeanValueConstraint(); |
| 114 | + |
| 115 | + void |
| 116 | + meanValueConstraintDistribute(distributedCPUVec<double> &vec) const; |
| 117 | + |
| 118 | + void |
| 119 | + meanValueConstraintDistributeSlaveToMaster( |
| 120 | + distributedCPUVec<double> &vec) const; |
| 121 | + |
| 122 | + void |
| 123 | + meanValueConstraintSetZero(distributedCPUVec<double> &vec) const; |
| 124 | + |
| 125 | + /** |
| 126 | + * @brief required for the cell_loop operation in dealii's MatrixFree class |
| 127 | + * |
| 128 | + */ |
| 129 | + void |
| 130 | + AX(const dealii::MatrixFree<3, double> &matrixFreeData, |
| 131 | + distributedCPUVec<double> &dst, |
| 132 | + const distributedCPUVec<double> &src, |
| 133 | + const std::pair<dftfe::uInt, dftfe::uInt> &cell_range) const; |
| 134 | + |
| 135 | + /** |
| 136 | + * @brief Compute the diagonal of A. |
| 137 | + * |
| 138 | + */ |
| 139 | + void |
| 140 | + computeDiagonalA(); |
| 141 | + |
| 142 | + void |
| 143 | + computeProjectedQuadToNodalField( |
| 144 | + const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST> |
| 145 | + &quadValues, |
| 146 | + distributedCPUVec<double> &nodalField); |
| 147 | + |
| 148 | + /// storage for diagonal of the A matrix |
| 149 | + distributedCPUVec<double> d_diagonalA; |
| 150 | + distributedCPUVec<double> d_dlocMassVector; |
| 151 | + distributedCPUVec<double> d_meanValueConstraintVec; |
| 152 | + |
| 153 | + bool d_isMeanValueConstraintComputed; |
| 154 | + dealii::types::global_dof_index d_meanValueConstraintNodeId; |
| 155 | + dftfe::uInt d_meanValueConstraintProcId; |
| 156 | + |
| 157 | + /// pointer to the x vector being solved for |
| 158 | + distributedCPUVec<double> *d_xPtr; |
| 159 | + |
| 160 | + /// Integral of the discrete LDOS field used in the Helmholtz operator. |
| 161 | + double d_totalDOS; |
| 162 | + |
| 163 | + /// matrix free index required to access the DofHandler and |
| 164 | + /// dealii::AffineConstraints<double> objects corresponding to the problem |
| 165 | + dftfe::uInt d_matrixFreeVectorComponent; |
| 166 | + |
| 167 | + /// matrix free quadrature index |
| 168 | + dftfe::uInt d_matrixFreeQuadratureComponent; |
| 169 | + dftfe::uInt d_matrixFreeAxQuadratureComponent; |
| 170 | + |
| 171 | + /// pointer to electron density cell and grad residual data |
| 172 | + const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST> |
| 173 | + *d_residualQuadValuesPtr; |
| 174 | + const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST> |
| 175 | + *d_ldosAxQuadValuesPtr; |
| 176 | + const dealii::DoFHandler<3> *d_dofHandlerPRefinedPtr; |
| 177 | + const dealii::AffineConstraints<double> *d_constraintMatrixPRefinedPtr; |
| 178 | + const dealii::MatrixFree<3, double> *d_matrixFreeDataPRefinedPtr; |
| 179 | + std::shared_ptr< |
| 180 | + dftfe::basis:: |
| 181 | + FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>> |
| 182 | + d_basisOperationsPtr; |
| 183 | + |
| 184 | + const MPI_Comm d_mpiCommParent; |
| 185 | + const MPI_Comm mpi_communicator; |
| 186 | + const dftfe::uInt n_mpi_processes; |
| 187 | + const dftfe::uInt this_mpi_process; |
| 188 | + dealii::ConditionalOStream pcout; |
| 189 | + }; |
| 190 | + |
| 191 | +} // namespace dftfe |
| 192 | +#endif // ldosSolverProblem_H_ |
0 commit comments