Skip to content

Commit

Permalink
Modified atomSphericalData and atomSphericalDataContainer, optimized …
Browse files Browse the repository at this point in the history
…atomSevereFunction
  • Loading branch information
Avirup Sircar committed Sep 8, 2024
1 parent 15188ee commit 67201d1
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,19 @@ double rho1sOrbital(const dftefe::utils::Point &point, const std::vector<dftefe:
std::vector<double>
operator()(const std::vector<utils::Point> &points) const
{
double ylm00 = atoms::Clm(0, 0) * atoms::Dm(0) * atoms::Plm(0, 0, 1) * atoms::Qm(0, 0);
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "density");
for(auto &enrichmentObjId : vec)
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = ret[i] + std::abs(enrichmentObjId->getValue(points[i], origin) * (1/ylm00));
}
}
return ret;
}
};
Expand Down Expand Up @@ -194,10 +201,19 @@ double rho1sOrbital(const dftefe::utils::Point &point, const std::vector<dftefe:
{
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "vnuclear");
for (unsigned int i = 0 ; i < points.size() ; i++)
{
for(auto &enrichmentObjId : vec)
{
ret[i] = ret[i] + std::abs(enrichmentObjId->getValue(points[i], origin) *
((*d_b)(points[i])));
}
}
}
return ret;
}
};
Expand Down Expand Up @@ -247,10 +263,19 @@ double rho1sOrbital(const dftefe::utils::Point &point, const std::vector<dftefe:
{
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "orbital");
for (unsigned int i = 0 ; i < points.size() ; i++)
{
for(auto &enrichmentObjId : vec)
{
double val = enrichmentObjId->getValue(points[i], origin);
ret[i] = ret[i] + std::abs(val * val * (*d_vext)(points[i]));
}
}
}
return ret;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ add_subdirectory(${MAIN_PROJECT_DIR}/src/ksdft ${MAIN_PROJECT_DIR}/test/ksdft/li

if(ENABLE_MPI)
add_compile_definitions(DFTEFE_WITH_MPI)
add_executable(TestKohnShamDft_case1 ${MAIN_PROJECT_DIR}/analysis/classicalEnrichmentComparison/KSDFTOrthoEFE/TestKohnShamDft.cpp)
target_link_libraries(TestKohnShamDft_case1 PUBLIC dft-efe-basis dft-efe-electrostatics dft-efe-ksdft dft-efe-utils dft-efe-quadrature dft-efe-linalg dft-efe-atoms)
add_executable(TestKohnShamDft_case5 ${MAIN_PROJECT_DIR}/analysis/classicalEnrichmentComparison/KSDFTOrthoEFE/TestKohnShamDft.cpp)
target_link_libraries(TestKohnShamDft_case5 PUBLIC dft-efe-basis dft-efe-electrostatics dft-efe-ksdft dft-efe-utils dft-efe-quadrature dft-efe-linalg dft-efe-atoms)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,19 @@ T readParameter(std::string ParamFile, std::string param, utils::ConditionalOStr
std::vector<double>
operator()(const std::vector<utils::Point> &points) const
{
double ylm00 = atoms::Clm(0, 0) * atoms::Dm(0) * atoms::Plm(0, 0, 1) * atoms::Qm(0, 0);
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "density");
for(auto &enrichmentObjId : vec)
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = ret[i] + std::abs(enrichmentObjId->getValue(points[i], origin) * (1/ylm00));
}
}
return ret;
}
};
Expand Down Expand Up @@ -181,10 +188,19 @@ T readParameter(std::string ParamFile, std::string param, utils::ConditionalOStr
{
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "vtotal");
for (unsigned int i = 0 ; i < points.size() ; i++)
{
for(auto &enrichmentObjId : vec)
{
ret[i] = ret[i] + std::abs(enrichmentObjId->getValue(points[i], origin) *
((*d_b)(points[i]) + (*d_rho)(points[i])));
}
}
}
return ret;
}
};
Expand Down Expand Up @@ -235,10 +251,19 @@ T readParameter(std::string ParamFile, std::string param, utils::ConditionalOStr
{
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "vnuclear");
for (unsigned int i = 0 ; i < points.size() ; i++)
{
for(auto &enrichmentObjId : vec)
{
ret[i] = ret[i] + std::abs(enrichmentObjId->getValue(points[i], origin) *
((*d_b)(points[i])));
}
}
}
return ret;
}
};
Expand Down Expand Up @@ -288,10 +313,19 @@ T readParameter(std::string ParamFile, std::string param, utils::ConditionalOStr
{
std::vector<double> ret(0);
ret.resize(points.size());
for (unsigned int i = 0 ; i < points.size() ; i++)
{
ret[i] = (*this)(points[i]);
}
for (size_type atomId = 0 ; atomId < d_atomCoordinatesVec.size() ; atomId++)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
auto vec = d_atomSphericalDataContainer->getSphericalData(d_atomSymbolVec[atomId], "orbital");
for (unsigned int i = 0 ; i < points.size() ; i++)
{
for(auto &enrichmentObjId : vec)
{
double val = enrichmentObjId->getValue(points[i], origin);
ret[i] = ret[i] + std::abs(val * val * (*d_vext)(points[i]));
}
}
}
return ret;
}
};
Expand Down Expand Up @@ -1114,8 +1148,8 @@ int main(int argc, char** argv)
*externalPotentialFunction,
linAlgOpContext,
*MContextForInv,
*MContext,
/**MContextForInv,*/
/**MContext,*/
*MContextForInv,
*MInvContext);

// add device synchronize for gpu
Expand Down Expand Up @@ -1174,8 +1208,8 @@ int main(int argc, char** argv)
*externalPotentialFunction,
linAlgOpContext,
*MContextForInv,
*MContext,
/**MContextForInv,*/
/**MContext,*/
*MContextForInv,
*MInvContext);

// add device synchronize for gpu
Expand Down
75 changes: 37 additions & 38 deletions src/atoms/AtomSevereFunction.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ namespace dftefe
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
{
auto vec = d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName);
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (auto &enrichmentObjId :
d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName))
for (auto &enrichmentObjId : vec)
{
retValue =
retValue + enrichmentObjId->getValue(point, origin) *
enrichmentObjId->getValue(point, origin);
double val = enrichmentObjId->getValue(point, origin);
retValue = retValue + val * val;
}
}
}
Expand All @@ -71,69 +70,69 @@ namespace dftefe
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
{
auto vec = d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName);
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (auto &enrichmentObjId :
d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName))
for (auto &enrichmentObjId : vec)
{
std::vector<double> val =
enrichmentObjId->getGradientValue(point, origin);
for (size_type iDim = 0; iDim < dim; iDim++)
{
retValue =
retValue +
enrichmentObjId->getGradientValue(point, origin)[iDim] *
enrichmentObjId->getGradientValue(point,
origin)[iDim];
retValue = retValue + val[iDim] * val[iDim];
}
}
}
}
return retValue;
}

// check for r!=0 gradient.
template <unsigned int dim>
std::vector<double>
AtomSevereFunction<dim>::operator()(
const std::vector<utils::Point> &points) const
{
const size_type N = points.size();
std::vector<double> retValue(N, 0.0);
for (unsigned int iPoint = 0; iPoint < N; ++iPoint)
if (d_derivativeType == 0)
{
if (d_derivativeType == 0)
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
{
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
auto vec = d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName);
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (unsigned int iPoint = 0; iPoint < N; ++iPoint)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (auto &enrichmentObjId :
d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName))
for (auto &enrichmentObjId : vec)
{
retValue[iPoint] =
retValue[iPoint] +
enrichmentObjId->getValue(points[iPoint], origin) *
enrichmentObjId->getValue(points[iPoint], origin);
double val =
enrichmentObjId->getValue(points[iPoint], origin);
retValue[iPoint] = retValue[iPoint] + val * val;
}
}
}
if (d_derivativeType == 1)
}
if (d_derivativeType == 1)
{
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
{
for (size_type atomId = 0; atomId < d_atomCoordinatesVec.size();
atomId++)
auto vec = d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName);
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (unsigned int iPoint = 0; iPoint < N; ++iPoint)
{
utils::Point origin(d_atomCoordinatesVec[atomId]);
for (auto &enrichmentObjId :
d_atomSphericalDataContainer->getSphericalData(
d_atomSymbolVec[atomId], d_fieldName))
for (auto &enrichmentObjId : vec)
{
std::vector<double> val =
enrichmentObjId->getGradientValue(points[iPoint],
origin);
for (size_type iDim = 0; iDim < dim; iDim++)
{
retValue[iPoint] =
retValue[iPoint] +
enrichmentObjId->getGradientValue(points[iPoint],
origin)[iDim] *
enrichmentObjId->getGradientValue(points[iPoint],
origin)[iDim];
retValue[iPoint] + val[iDim] * val[iDim];
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/atoms/AtomSphericalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ namespace dftefe
AtomSphericalData::getSphericalData(const std::string fieldName) const
{
auto it = d_sphericalData.find(fieldName);
utils::throwException(it != d_sphericalData.end(),
"FieldName " + fieldName +
" not while parsing the XML file:" + d_fileName);
DFTEFE_AssertWithMsg(it != d_sphericalData.end(),
"FieldName " + fieldName +
" not while parsing the XML file:" + d_fileName);
return it->second;
}

Expand All @@ -635,13 +635,13 @@ namespace dftefe
const std::vector<int> &qNumbers) const
{
auto it = d_sphericalData.find(fieldName);
utils::throwException(it != d_sphericalData.end(),
"Unable to find the field " + fieldName +
" while parsing the XML file " + d_fileName);
DFTEFE_AssertWithMsg(it != d_sphericalData.end(),
"Unable to find the field " + fieldName +
" while parsing the XML file " + d_fileName);
auto iter = d_qNumbersToIdMap.find(fieldName);
utils::throwException(iter != d_qNumbersToIdMap.end(),
"Unable to find the field " + fieldName +
" while parsing the XML file " + d_fileName);
DFTEFE_AssertWithMsg(iter != d_qNumbersToIdMap.end(),
"Unable to find the field " + fieldName +
" while parsing the XML file " + d_fileName);
auto iterQNumberToId = (iter->second).find(qNumbers);
if (iterQNumberToId != (iter->second).end())
return *((it->second).begin() + iterQNumberToId->second);
Expand All @@ -651,10 +651,10 @@ namespace dftefe
for (size_type i = 0; i < qNumbers.size(); i++)
s += std::to_string(qNumbers[i]) + " ";

utils::throwException(false,
"Unable to find the qNumbers " + s + " for " +
" the field " + fieldName +
" while parsing the XML file " + d_fileName);
DFTEFE_AssertWithMsg(false,
"Unable to find the qNumbers " + s + " for " +
" the field " + fieldName +
" while parsing the XML file " + d_fileName);
return *((it->second).begin() + iterQNumberToId->second);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/atoms/AtomSphericalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ namespace dftefe
std::string d_fileName;
std::vector<std::string> d_fieldNames;
std::vector<std::string> d_metadataNames;
std::map<std::string, std::vector<std::shared_ptr<SphericalData>>>
std::unordered_map<std::string,
std::vector<std::shared_ptr<SphericalData>>>
d_sphericalData;
std::map<std::string, std::map<std::vector<int>, size_type>>
d_qNumbersToIdMap;
std::map<std::string, std::string> d_metadata;
std::unordered_map<std::string, std::map<std::vector<int>, size_type>>
d_qNumbersToIdMap;
std::unordered_map<std::string, std::string> d_metadata;
};
} // end of namespace atoms
} // end of namespace dftefe
Expand Down
Loading

0 comments on commit 67201d1

Please sign in to comment.