Repository navigation
add hfmm3d_ndiv and lfmm3d_ndiv for julia interface #70
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,7 @@ module FMM3D | |||||
|
|
||||||
| using FMM3D_jll | ||||||
|
|
||||||
| export FMMVals, hfmm3d, lfmm3d, h3ddir, l3ddir, lowerlevel_routs | ||||||
| export FMMVals, hfmm3d, hfmm3d_ndiv, lfmm3d, lfmm3d_ndiv, h3ddir, l3ddir, lowerlevel_routs | ||||||
| export stfmm3d, st3ddir, emfmm3d, em3ddir | ||||||
| export besseljs3d | ||||||
|
|
||||||
|
|
@@ -262,11 +262,11 @@ in the order: ``\\partial_{xx}``, ``\\partial_{yy}``, | |||||
| Non-zero values may indicate insufficient memory available. See the documentation for the FMM3D library. | ||||||
| If not set (`nothing`), then FMM3D library was never called. | ||||||
| """ | ||||||
| function hfmm3d(eps::Float64,zk::Union{Float64,ComplexF64}, | ||||||
| sources::Array{Float64}; | ||||||
| charges::TCN=nothing,dipvecs::TCN=nothing, | ||||||
| targets::TFN=nothing,pg::Integer=0,pgt::Integer=0, | ||||||
| nd::Integer=1) | ||||||
| function _hfmm3d_impl(eps::Float64,zk::Union{Float64,ComplexF64}, | ||||||
| sources::Array{Float64}; | ||||||
| charges::TCN=nothing,dipvecs::TCN=nothing, | ||||||
| targets::TFN=nothing,pg::Integer=0,pgt::Integer=0, | ||||||
| nd::Integer=1,ndiv::Union{Integer,Nothing}=nothing) | ||||||
|
|
||||||
| zk = complex(zk) | ||||||
|
|
||||||
|
|
@@ -303,6 +303,10 @@ function hfmm3d(eps::Float64,zk::Union{Float64,ComplexF64}, | |||||
| if anyfail | ||||||
| return vals | ||||||
| end | ||||||
| if ndiv !== nothing && ndiv < 1 | ||||||
| @warn "ndiv must be a positive integer, computing nothing" | ||||||
| return vals | ||||||
| end | ||||||
|
|
||||||
| if (ifcharge == 0); charges = zero end | ||||||
| if (ifdipole == 0); dipvecs = zero end | ||||||
|
|
@@ -369,12 +373,27 @@ function hfmm3d(eps::Float64,zk::Union{Float64,ComplexF64}, | |||||
| ier = Integer(0) | ||||||
| iper = Integer(0) | ||||||
|
|
||||||
| ccall((:hfmm3d_,libfmm3d),Cvoid,(Fi,Fd,Fc,Fi,Fd,Fi,Fc, | ||||||
| Fi,Fc,Fi,Fi,Fc,Fc,Fc,Fi, | ||||||
| Fd,Fi,Fc,Fc,Fc,Fi), | ||||||
| nd,eps,zk,n,sources,ifcharge,charges,ifdipole, | ||||||
| dipvecs,iper,pg,pot,grad,hess,nt,targets,pgt, | ||||||
| pottarg,gradtarg,hesstarg,ier) | ||||||
| if ndiv === nothing | ||||||
| ccall((:hfmm3d_,libfmm3d),Cvoid,(Fi,Fd,Fc,Fi,Fd,Fi,Fc, | ||||||
| Fi,Fc,Fi,Fi,Fc,Fc,Fc,Fi, | ||||||
| Fd,Fi,Fc,Fc,Fc,Fi), | ||||||
| nd,eps,zk,n,sources,ifcharge,charges,ifdipole, | ||||||
| dipvecs,iper,pg,pot,grad,hess,nt,targets,pgt, | ||||||
| pottarg,gradtarg,hesstarg,ier) | ||||||
| else | ||||||
| ndiv64 = Int64(ndiv) | ||||||
| idivflag = Int64(0) | ||||||
| ifnear = Int64(1) | ||||||
| timeinfo = zeros(Float64,6) | ||||||
| ccall((:hfmm3d_ndiv_,libfmm3d),Cvoid,(Fi,Fd,Fc,Fi,Fd,Fi,Fc, | ||||||
| Fi,Fc,Fi,Fi,Fc,Fc,Fc,Fi, | ||||||
| Fd,Fi,Fc,Fc,Fc,Fi,Fi,Fi, | ||||||
| Fd,Fi), | ||||||
| nd,eps,zk,n,sources,ifcharge,charges,ifdipole, | ||||||
| dipvecs,iper,pg,pot,grad,hess,nt,targets,pgt, | ||||||
| pottarg,gradtarg,hesstarg,ndiv64,idivflag,ifnear, | ||||||
| timeinfo,ier) | ||||||
| end | ||||||
|
|
||||||
| vals.ier = ier | ||||||
| if (ier != 0); @warn "libfmm3d had an error, see vals.ier"; end | ||||||
|
|
@@ -392,6 +411,24 @@ function hfmm3d(eps::Float64,zk::Union{Float64,ComplexF64}, | |||||
|
|
||||||
| end | ||||||
|
|
||||||
| function hfmm3d(eps::Float64,zk::Union{Float64,ComplexF64}, | ||||||
| sources::Array{Float64}; | ||||||
| charges::TCN=nothing,dipvecs::TCN=nothing, | ||||||
| targets::TFN=nothing,pg::Integer=0,pgt::Integer=0, | ||||||
| nd::Integer=1) | ||||||
| return _hfmm3d_impl(eps,zk,sources,charges=charges,dipvecs=dipvecs, | ||||||
| targets=targets,pg=pg,pgt=pgt,nd=nd) | ||||||
| end | ||||||
|
|
||||||
| function hfmm3d_ndiv(eps::Float64,zk::Union{Float64,ComplexF64}, | ||||||
| sources::Array{Float64},ndiv::Integer; | ||||||
| charges::TCN=nothing,dipvecs::TCN=nothing, | ||||||
| targets::TFN=nothing,pg::Integer=0,pgt::Integer=0, | ||||||
| nd::Integer=1) | ||||||
| return _hfmm3d_impl(eps,zk,sources,charges=charges,dipvecs=dipvecs, | ||||||
| targets=targets,pg=pg,pgt=pgt,nd=nd,ndiv=ndiv) | ||||||
| end | ||||||
|
Comment on lines
+423
to
+430
|
||||||
|
|
||||||
| """ | ||||||
| ```julia | ||||||
| vals = h3ddir(zk,sources,targets;charges=nothing, | ||||||
|
|
@@ -739,9 +776,10 @@ in the order: ``\\partial_{xx}``, ``\\partial_{yy}``, | |||||
| Non-zero values may indicate insufficient memory available. See the documentation for the FMM3D library. | ||||||
| If not set (`nothing`), then FMM3D library was never called. | ||||||
| """ | ||||||
| function lfmm3d(eps::Float64,sources::Array{Float64};charges::TFN=nothing, | ||||||
| dipvecs::TFN=nothing,targets::TFN=nothing, | ||||||
| pg::Integer=0,pgt::Integer=0,nd::Integer=1) | ||||||
| function _lfmm3d_impl(eps::Float64,sources::Array{Float64};charges::TFN=nothing, | ||||||
| dipvecs::TFN=nothing,targets::TFN=nothing, | ||||||
| pg::Integer=0,pgt::Integer=0,nd::Integer=1, | ||||||
| ndiv::Union{Integer,Nothing}=nothing) | ||||||
|
|
||||||
| # default values | ||||||
|
|
||||||
|
|
@@ -767,6 +805,10 @@ function lfmm3d(eps::Float64,sources::Array{Float64};charges::TFN=nothing, | |||||
| if anyfail | ||||||
| return vals | ||||||
| end | ||||||
| if ndiv !== nothing && ndiv < 1 | ||||||
|
||||||
| if ndiv !== nothing && ndiv < 1 | |
| if ndiv !== nothing && ndiv <= 0 |
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new lfmm3d_ndiv function is missing documentation. Based on the codebase conventions, all public functions should have docstrings that explain the purpose, parameters (especially the new ndiv parameter), and return values. Consider adding a docstring similar to the lfmm3d function but including information about the ndiv parameter and when it should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation for
ndivchecks if it is less than 1, but the condition should bendiv <= 0for clarity, since the error message states "ndiv must be a positive integer" which means ndiv must be greater than 0. While the current condition (ndiv < 1) is mathematically equivalent for integers, usingndiv <= 0makes the intent more explicit and aligns better with the error message.