import numpy as np
import exafmm.modified_helmholtz as mod_helm
mod_helm.__doc__
"exafmm's submodule for Modified Helmholtz kernel"
nsrcs = 100000
ntrgs = 100000
# generate random positions for particles
src_coords = np.random.random((nsrcs, 3))
trg_coords = np.random.random((nsrcs, 3))
# generate random charges for sources
src_charges = np.random.random(nsrcs)
# create a list of source instances
sources = mod_helm.init_sources(src_coords, src_charges)
# create a list of target instances
targets = mod_helm.init_targets(trg_coords)
fmm = mod_helm.ModifiedHelmholtzFmm(p=10, ncrit=400, wavek=7.5, filename='modhelm_example.dat')
Given sources, targets and FMM configurations, setup()
builds the tree and interaction list and pre-compute invariant matrices.
tree = mod_helm.setup(sources, targets, fmm)
evaluate()
triggers the evaluation and returns a $n_{trg} \times 4$ numpy.ndarray
.
The $i$-th row of trg_values
starts with the potential value of the $i$-th target, followed by its three gradient values.
trg_values = mod_helm.evaluate(tree, fmm)
trg_values[6]
array([ 652.74894239, -1315.64151095, -749.84947316, 340.94417624])
fmm.verify(tree.leafs)
returns L2-norm the relative error of potential and gradient in a list. It only works when skip_P2P
is set to False
.
fmm.verify(tree.leafs)
[1.500146160135269e-10, 9.677558408664847e-09]
niters = 4
for i in range(niters):
print('-'*10 + ' iteration {} '.format(i) + '-'*10) # print divider between iterations
src_charges = np.random.random(nsrcs) # generate new random charges
mod_helm.update_charges(tree, src_charges) # update charges
mod_helm.clear_values(tree) # clear values
trg_values = mod_helm.evaluate(tree, fmm) # evaluate potentials
print("Error: ", fmm.verify(tree.leafs)) # check accuracy
---------- iteration 0 ---------- Error: [1.5254311868722168e-10, 8.746810807253287e-09] ---------- iteration 1 ---------- Error: [1.484783794640184e-10, 1.0294833601137622e-08] ---------- iteration 2 ---------- Error: [1.586084602137114e-10, 1.0816053009140436e-08] ---------- iteration 3 ---------- Error: [1.534906027004696e-10, 9.33679182423933e-09]