DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
pseudoUtils.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// @author Sambit Das
18//
19
20#ifndef pseudoUtils_H_
21#define pseudoUtils_H_
22
23#include <headers.h>
24#include <mpi.h>
25#include <boost/math/distributions/normal.hpp>
26#include <boost/math/special_functions/spherical_harmonic.hpp>
27#include <boost/random/normal_distribution.hpp>
28
29
30namespace dftfe
31{
32 namespace pseudoUtils
33 {
34 // some inline functions
35 inline void
36 exchangeLocalList(const std::vector<unsigned int> &masterNodeIdList,
37 std::vector<unsigned int> & globalMasterNodeIdList,
38 unsigned int numMeshPartitions,
39 const MPI_Comm & mpi_communicator)
40 {
41 int numberMasterNodesOnLocalProc = masterNodeIdList.size();
42
43 int *masterNodeIdListSizes = new int[numMeshPartitions];
44
45 MPI_Allgather(&numberMasterNodesOnLocalProc,
46 1,
47 MPI_INT,
48 masterNodeIdListSizes,
49 1,
50 MPI_INT,
51 mpi_communicator);
52
53 int newMasterNodeIdListSize =
54 std::accumulate(&(masterNodeIdListSizes[0]),
55 &(masterNodeIdListSizes[numMeshPartitions]),
56 0);
57
58 globalMasterNodeIdList.resize(newMasterNodeIdListSize);
59
60 int *mpiOffsets = new int[numMeshPartitions];
61
62 mpiOffsets[0] = 0;
63
64 for (int i = 1; i < numMeshPartitions; ++i)
65 mpiOffsets[i] = masterNodeIdListSizes[i - 1] + mpiOffsets[i - 1];
66
67 MPI_Allgatherv(&(masterNodeIdList[0]),
68 numberMasterNodesOnLocalProc,
69 MPI_INT,
70 &(globalMasterNodeIdList[0]),
71 &(masterNodeIdListSizes[0]),
72 &(mpiOffsets[0]),
73 MPI_INT,
74 mpi_communicator);
75
76
77 delete[] masterNodeIdListSizes;
78 delete[] mpiOffsets;
79
80 return;
81 }
82
83
84 inline void
85 exchangeNumberingMap(std::map<int, int> &localMap,
86 unsigned int numMeshPartitions,
87 const MPI_Comm & mpi_communicator)
88
89 {
90 std::map<int, int>::iterator iter;
91
92 std::vector<int> localSpreadVec;
93
94 iter = localMap.begin();
95 while (iter != localMap.end())
96 {
97 localSpreadVec.push_back(iter->first);
98 localSpreadVec.push_back(iter->second);
99
100 ++iter;
101 }
102 int localSpreadVecSize = localSpreadVec.size();
103
104 int *spreadVecSizes = new int[numMeshPartitions];
105
106 MPI_Allgather(&localSpreadVecSize,
107 1,
108 MPI_INT,
109 spreadVecSizes,
110 1,
111 MPI_INT,
112 mpi_communicator);
113
114 int globalSpreadVecSize =
115 std::accumulate(&(spreadVecSizes[0]),
116 &(spreadVecSizes[numMeshPartitions]),
117 0);
118
119 std::vector<int> globalSpreadVec(globalSpreadVecSize);
120
121 int *mpiOffsets = new int[numMeshPartitions];
122
123 mpiOffsets[0] = 0;
124
125 for (int i = 1; i < numMeshPartitions; ++i)
126 mpiOffsets[i] = spreadVecSizes[i - 1] + mpiOffsets[i - 1];
127
128 MPI_Allgatherv(&(localSpreadVec[0]),
129 localSpreadVecSize,
130 MPI_INT,
131 &(globalSpreadVec[0]),
132 &(spreadVecSizes[0]),
133 &(mpiOffsets[0]),
134 MPI_INT,
135 mpi_communicator);
136
137 for (int i = 0; i < globalSpreadVecSize; i = i + 2)
138 localMap[globalSpreadVec[i]] = globalSpreadVec[i + 1];
139
140
141 delete[] spreadVecSizes;
142 delete[] mpiOffsets;
143
144 return;
145 }
146
147 inline void
148 getRadialFunctionVal(const double radialCoordinate,
149 double & splineVal,
150 const alglib::spline1dinterpolant *spline)
151 {
152 splineVal = alglib::spline1dcalc(*spline, radialCoordinate);
153 return;
154 }
155
156 inline void
157 getSphericalHarmonicVal(const double theta,
158 const double phi,
159 const int l,
160 const int m,
161 double & sphericalHarmonicVal)
162 {
163 if (m < 0)
164 sphericalHarmonicVal =
165 std::sqrt(2.0) * boost::math::spherical_harmonic_i(l, -m, theta, phi);
166
167 else if (m == 0)
168 sphericalHarmonicVal =
169 boost::math::spherical_harmonic_r(l, m, theta, phi);
170
171 else if (m > 0)
172 sphericalHarmonicVal =
173 std::sqrt(2.0) * boost::math::spherical_harmonic_r(l, m, theta, phi);
174
175 return;
176 }
177
178 inline void
180 double &r,
181 double &theta,
182 double &phi)
183 {
184 double tolerance = 1e-12;
185 r = std::sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
186
187 if (std::fabs(r - 0.0) <= tolerance)
188 {
189 theta = 0.0;
190 phi = 0.0;
191 }
192 else
193 {
194 theta = std::acos(x[2] / r);
195 //
196 // check if theta = 0 or PI (i.e, whether the point is on the Z-axis)
197 // If yes, assign phi = 0.0.
198 // NOTE: In case theta = 0 or PI, phi is undetermined. The actual
199 // value of phi doesn't matter in computing the enriched function
200 // value or its gradient. We assign phi = 0.0 here just as a dummy
201 // value
202 //
203 if (fabs(theta - 0.0) >= tolerance && fabs(theta - M_PI) >= tolerance)
204 phi = std::atan2(x[1], x[0]);
205 else
206 phi = 0.0;
207 }
208 }
209 } // namespace pseudoUtils
210} // namespace dftfe
211#endif
wrapper to convert pseudopotential file from upf to dftfe format and returns the nonlinear core corre...
Definition pseudoPotentialToDftfeConverter.cc:36
void exchangeLocalList(const std::vector< unsigned int > &masterNodeIdList, std::vector< unsigned int > &globalMasterNodeIdList, unsigned int numMeshPartitions, const MPI_Comm &mpi_communicator)
Definition pseudoUtils.h:36
void getRadialFunctionVal(const double radialCoordinate, double &splineVal, const alglib::spline1dinterpolant *spline)
Definition pseudoUtils.h:148
void convertCartesianToSpherical(double *x, double &r, double &theta, double &phi)
Definition pseudoUtils.h:179
void exchangeNumberingMap(std::map< int, int > &localMap, unsigned int numMeshPartitions, const MPI_Comm &mpi_communicator)
Definition pseudoUtils.h:85
void getSphericalHarmonicVal(const double theta, const double phi, const int l, const int m, double &sphericalHarmonicVal)
Definition pseudoUtils.h:157
Definition pseudoPotentialToDftfeConverter.cc:34
@ e
Definition ExcSSDFunctionalBaseClass.h:52