Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.6-Feature Dev #181

Merged
merged 29 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ac4b992
Added constructors for `StableAdd` and `StableMul`.
frankwswang Jan 13, 2025
d19053b
Moved `Identity`.
frankwswang Jan 13, 2025
5146c31
Code optimization.
frankwswang Jan 14, 2025
4e6456d
Extended factorial computation range and added the corresponding cache.
frankwswang Jan 14, 2025
06dcb53
Removed flag in case for different integer-type inputs.
frankwswang Jan 14, 2025
034dd19
Reorganized and optimized core functions.
frankwswang Jan 16, 2025
8f15979
Code optimization.
frankwswang Jan 17, 2025
f857dfc
Added caching to the overlap computation of PGTO.
frankwswang Jan 17, 2025
206c39c
Fixed type constraint for `NormalizeCompOrb` with inhomogeneous core …
frankwswang Jan 18, 2025
3c779e2
Added multi-cache support for different GTO subshells.
frankwswang Jan 18, 2025
c48a9a1
Improved the caching stability.
frankwswang Jan 18, 2025
89ea758
Added `TypedPrimGTOcore`.
frankwswang Jan 19, 2025
6e28895
Optimized `NormalizeCompOrb`.
frankwswang Jan 19, 2025
871a9eb
Split cache for different dimensions.
frankwswang Jan 19, 2025
b43dd14
Formatted code and replaced anonymous functions with typed functors.
frankwswang Jan 19, 2025
641718c
Added support of keyword arguments for `ReturnedTyped`.
frankwswang Jan 19, 2025
dd3933e
Added support of vector input for `ShiftByArg`.
frankwswang Jan 19, 2025
426fd26
Optimized the interface of core integral caching.
frankwswang Jan 19, 2025
fb79d10
Formatted code and temporarily disabled lazy generations of integral …
frankwswang Jan 20, 2025
c6c689a
Added `MonomialMul`.
frankwswang Jan 20, 2025
c6728ef
Implemented integral computations of multipole moments.
frankwswang Jan 20, 2025
8675758
Formatting code.
frankwswang Jan 20, 2025
5a1e60e
Implemented interfaces for integral computation cache.
frankwswang Jan 20, 2025
0cee187
Changed the field order of `PrimitiveOrb`.
frankwswang Jan 21, 2025
ca8376b
Added type parameters.
frankwswang Jan 21, 2025
e812f5c
Changed `computeCache` from a keyword argument to a positional argume…
frankwswang Jan 21, 2025
9608b81
Optimized the interface for cached computing of integrals.
frankwswang Jan 28, 2025
89be2f2
Formatting code.
frankwswang Jan 28, 2025
66b1f1d
Replaced generated functions with dict getters for generating integra…
frankwswang Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 264 additions & 80 deletions src/Integrals/Engines/GaussianOrbitals.jl

Large diffs are not rendered by default.

124 changes: 66 additions & 58 deletions src/Integrals/Engines/Numerical.jl
Original file line number Diff line number Diff line change
@@ -1,90 +1,98 @@
using HCubature

function changeFuncRange(f::F, ::Type{T}) where {F, T}
fCore = function (x)
x = Tuple(x)
f(x ./ (one(T) .- x.^2)) * mapreduce(*, x) do t
(1 + t^2) / (1 - t^2)^2
end
end
ReturnTyped(fCore, T)
struct ConfineInterval{T, F<:ReturnTyped{T}} <: FunctionModifier
f::F

ConfineInterval(f::F) where {T, F<:ReturnTyped{T}} = new{T, F}(f)
end

ConfineInterval(::Type{T}, f::Function) where {T} = ConfineInterval(ReturnTyped(f, T))

function numericalIntegration(integrand::ReturnTyped{T},
interval::NTuple{2, NonEmptyTuple{T, D}}) where {T, D}
(first∘hcubature)(integrand, first(interval), last(interval); maxevals=typemax(Int))
function (f::ConfineInterval{T})(x::AbstractVector{T}) where {T}
val = f.f(x ./ (one(T) .- x.^2))
mapreduce(*, x) do t
tSquare = t * t
(1 + tSquare) / (1 - tSquare)^2
end * val
end


function composeOneBodyKernel(op::O, ::Type{T}, termL::F1, termR::F2) where
{O<:Function, T, F1<:Function, F2<:Function}
PairCombine(StableBinary(*, T), adjoint∘termL, op(termR))
end
struct ModSquaredMap{T, F<:ReturnTyped{T}} <: FunctionModifier
f::F

function composeOneBodyKernel(op::O, ::Type{T}, term::F) where {O<:Function, T, F<:Function}
composeOneBodyKernel(op, T, term, term)
ModSquaredMap(f::F) where {T, F<:ReturnTyped{T}} = new{T, F}(f)
end

function composeOneBodyKernel(::Identity, ::Type{T}, term::F) where {T, F<:Function}
function (input::I) where {I}
val = term(input)::T
val' * val
end
end
ModSquaredMap(::Type{T}, f::Function) where {T} = ModSquaredMap(ReturnTyped(f, T))

function numericalOneBodyInt(op::F, (orb,)::Tuple{EvalFieldFunction{T, D}},
(pVal,)::Tuple{FilteredVecOfArr{T}}) where
{F<:DirectOperator, T, D}
term = Base.Fix2(orb, pVal)
integrand = changeFuncRange(composeOneBodyKernel(op, T, term), T)
bound = ntuple(_->one(T), Val(D))
numericalIntegration(integrand, (.-(bound), bound))
function (f::ModSquaredMap{T})(input::AbstractVector{T}) where {T}
val = f.f(input)
val' * val
end

function numericalOneBodyInt(op::F, orbs::NTuple{2, EvalFieldFunction{T, D}},
pValPair::NTuple{2, FilteredVecOfArr{T}}) where
{F<:DirectOperator, T, D}
termL, termR = Base.Fix2.(orbs, pValPair)
integrand = changeFuncRange(composeOneBodyKernel(op, T, termL, termR), T)
bound = ntuple(_->one(T), Val(D))
numericalIntegration(integrand, (.-(bound), bound))

function numericalIntegrateCore(integrand::ConfineInterval{T},
interval::NTuple{2, NonEmptyTuple{T, D}}) where {T, D}
fullRes = hcubature(integrand, first(interval), last(interval), maxevals=typemax(Int))
first(fullRes)
end


struct NumOverlapOrbSelf{T, D, B<:PrimitiveOrbCore{T, D}} <: OrbitalIntegrator{T, D}
orb::Tuple{B}
function composeOneBodyKernel(op::O, ::Type{T}, (termL, termR)::Tuple{F1, F2}) where
{O<:Function, T, F1<:Function, F2<:Function}
PairCombine(StableMul(T), adjoint∘termL, op(termR))
end

function (f::NumOverlapOrbSelf{T})(pars::FilteredVecOfArr{T}) where {T}
numericalOneBodyInt(Identity(), f.orb, (pars,))
function composeOneBodyKernel(op::O, ::Type{T}, (term,)::Tuple{F}) where
{O<:Function, T, F<:Function}
composeOneBodyKernel(op, T, (term, term))
end

struct NumOverlapOrbPair{T, D, B1<:PrimitiveOrbCore{T, D},
B2<:PrimitiveOrbCore{T, D}} <: OrbitalIntegrator{T, D}
orb::Tuple{B1, B2}
function composeOneBodyKernel(::Identity, ::Type{T}, (term,)::Tuple{F}) where
{T, F<:Function}
ModSquaredMap(T, term)
end

function (f::NumOverlapOrbPair{T})(pars::Vararg{FilteredVecOfArr{T}, 2}) where {T}
numericalOneBodyInt(Identity(), f.orb, pars)

function composeIntegralKernel(::OneBodyIntegral, op::O, ::Type{T},
terms::N12Tuple{Function}) where {O<:Function, T}
composeOneBodyKernel(op, T, terms)
end

genOneBodyCoreIntegrator(::Identity, orbs::Tuple{PrimitiveOrbCore{T, D}}) where {T, D} =
NumOverlapOrbSelf(orbs)
function numericalIntegrate(::OneBodyIntegral{D}, op::F,
orbs::NonEmptyTuple{EvalFieldFunction{T, D}, N},
pVals::NonEmptyTuple{FilteredVecOfArr{T}, N}) where
{F<:DirectOperator, T, D, N}
terms = Base.Fix2.(orbs, pVals)
integralKernel = composeIntegralKernel(OneBodyIntegral{D}(), op, T, terms)
integrand = ConfineInterval(T, integralKernel)
bound = ntuple(_->one(T), Val(D))
numericalIntegrateCore(integrand, (.-(bound), bound))
end

genOneBodyCoreIntegrator(::Identity, orbs::NTuple{2, PrimitiveOrbCore{T, D}}) where {T, D} =
NumOverlapOrbPair(orbs)

function buildNormalizerCore(o::PrimitiveOrbCore{T, D}) where {T, D}
genOneBodyCoreIntegrator(Identity(), (o,))
buildCoreIntegrator(OneBodyIntegral{D}(), Identity(), (o,))
end


struct OneBodyNumIntegrate{T, D, F<:DirectOperator,
P<:N12Tuple{PrimitiveOrbCore{T, D}}} <: OrbitalIntegrator{T, D}
op::F
basis::P
end

const OneBodySelfNumInt{T, D, F<:DirectOperator, P<:PrimitiveOrbCore{T, D}} =
OneBodyNumIntegrate{T, D, F, Tuple{P}}
const OnyBodyPairNumInt{T, D, F<:DirectOperator, P1<:PrimitiveOrbCore{T, D},
P2<:PrimitiveOrbCore{T, D}} =
OneBodyNumIntegrate{T, D, F, Tuple{P1, P2}}

function (f::OneBodySelfNumInt{T, D})(pVal::FilteredVecOfArr{T}) where {T, D}
numericalIntegrate(OneBodyIntegral{D}(), f.op, f.basis, (pVal,))
end

#!! Implement a functional struct (<:OrbitalIntegrator{T, D}) for the closure
function genOneBodyCoreIntegrator(op::F,
orbs::NonEmptyTuple{PrimitiveOrbCore{T, D}, N}) where
{F<:DirectOperator, N, T, D}
function (pVal::AbtVecOfAbtArr{T}, pVals::Vararg{AbtVecOfAbtArr{T}, N}) where {T}
numericalOneBodyInt(op, orbs, (pVal, pVals...))
end
function (f::OnyBodyPairNumInt{T, D})(pVal1::FilteredVecOfArr{T},
pVal2::FilteredVecOfArr{T}) where {T, D}
numericalIntegrate(OneBodyIntegral{D}(), f.op, f.basis, (pVal1, pVal2))
end
Loading
Loading