def computeHprimary(rs, js, robs, prec): #this function computes H-fields via FMM3D library #convention is 3 by number of points #prec determines the accuracy of the multipole expansion #Note: for magnetic dipoles electromagnetic duality implies that #if we pass magnetic dipoles weights as js we get negative E-primary. # As such, this function is used to compute E-primary due to magnetic currents also. outex = fmm.Output() Hprimary = np.zeros([3, robs.shape[1]]) muover4pi = -1e-7 js1 = js[0, :] out = fmm.lfmm3d(eps=prec, sources=rs, targets=robs, charges=js1, pgt=2) logger.debug("Run 1") Hprimary[1, :] = -out.gradtarg[2, :] Hprimary[2, :] = out.gradtarg[1, :] js1 = js[1, :] out = fmm.lfmm3d(eps=prec, sources=rs, targets=robs, charges=js1, pgt=2) logger.debug("Run 2") Hprimary[0, :] = out.gradtarg[2, :] Hprimary[2, :] = Hprimary[2, :] - out.gradtarg[0, :] js1 = js[2, :] out = fmm.lfmm3d(eps=prec, sources=rs, targets=robs, charges=js1, pgt=2) logger.debug("Run 3") Hprimary[0, :] = Hprimary[0, :] - out.gradtarg[1, :] Hprimary[1, :] = Hprimary[1, :] + out.gradtarg[0, :] Hprimary *= muover4pi return Hprimary
def _calculate_dadt_ccd_FMM(msh, ccd_file, coil_matrix, didt, geo_fn, eps=1e-3): """ auxiliary function to calculate the dA/dt field from a ccd file using FMM """ import fmm3dpy d_position, d_moment = _rotate_coil(ccd_file, coil_matrix) # bring everything to SI d_position *= 1e-3 pos = msh.nodes[:] * 1e-3 A = np.zeros((len(pos), 3), dtype=float) out = [ fmm3dpy.lfmm3d(eps=eps, sources=d_position.T, charges=d_m, targets=pos.T, pgt=2) for d_m in d_moment.T ] A[:, 0] = (out[1].gradtarg[2] - out[2].gradtarg[1]) A[:, 1] = (out[2].gradtarg[0] - out[0].gradtarg[2]) A[:, 2] = (out[0].gradtarg[1] - out[1].gradtarg[0]) A *= -1e-7 * didt if geo_fn is not None: mesh_io.write_geo_spheres(d_position * 1e3, geo_fn, np.linalg.norm(d_moment, axis=1), 'coil_dipoles') return mesh_io.NodeData(A)
import fmm3dpy as fmm import numpy as np # # This is a sample code to demonstrate how to use # the fmm libraries # # sample with one density, sources to sources, # charge interactions, and potential only # n = 200000 nd = 1 sources = np.random.uniform(0, 1, (3, n)) eps = 10**(-5) charges = np.random.uniform(0, 1, n) out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=1) # sample with a vector of densities, sources to # sources and targets, dipole interactions, # potential and gradietns nd = 3 nt = 1870 targ = np.random.uniform(0, 1, (3, nt)) dipvecs = np.random.uniform(0, 1, (nd, 3, n)) out = fmm.lfmm3d(eps=eps,sources=sources,dipvec=dipvecs,\ targets=targ,nd=nd,pg=2,pgt=2)
def test_lfmm(): ntests = 54 testres = np.zeros(ntests) # # This is a testing code for making sure all the # fmm routines are accessible through fmm3d.py # n = 2000 ntest = 10 zk = 1.1 + 1j * 0 sources = np.random.uniform(0, 1, (3, n)) stmp = sources[:, 0:ntest] nt = 1880 targ = np.random.uniform(0, 1, (3, nt)) ttmp = targ[:, 0:ntest] eps = 10**(-5) zk = 1.1 + 1j * 0 charges = np.random.uniform(0, 1, n) dipvec = np.random.uniform(0, 1, (3, n)) outex = fmm.Output() itest = 0 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=1) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, pgt=1) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=1) out2 = fmm.l3ddir(sources=sources, targets=stmp, dipvec=dipvec, pgt=1) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=1) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=1) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges and dipoles, pot") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=2) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=2) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot and grad") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=2) out2 = fmm.l3ddir(sources=sources,targets=stmp,dipvec=dipvec, \ pgt=2) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot and grad") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=2) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, dipvec=dipvec, pgt=2) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges and dipoles, pot and grad") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=3) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=3) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot, grad, and hess") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=3) out2 = fmm.l3ddir(sources=sources,targets=stmp,dipvec=dipvec, \ pgt=3) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot, grad, and hess") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=3) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, dipvec=dipvec, pgt=3) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges and dipoles, pot and grad") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=1) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=1) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges, pot") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=1) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=1) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ, \ charges=charges, \ dipvec=dipvec,pgt=1) out2=fmm.l3ddir(sources=sources,targets=ttmp, \ charges=charges, \ dipvec=dipvec,pgt=1) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges and dipoles, pot") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=2) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=2) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges, pot and grad") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=2) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=2) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot and grad") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=2) out2 =fmm.l3ddir(sources=sources,targets=ttmp,charges=charges,\ dipvec=dipvec,pgt=2) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges and dipoles, pot and grad") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=3) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=3) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges, pot, grad, and hess") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=3) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=3) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot, grad, and hess") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=3) out2 =fmm.l3ddir(sources=sources,targets=ttmp,charges=charges,\ dipvec=dipvec,pgt=3) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3) if (err < eps): testres[itest] = 1 else: print( "Failed sources to targets, charges and dipoles, pot, grad, and hess" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=1, pg=1) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, pgt=1) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=1) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources and targets, charges, pot") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=1,pg=1) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=1) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp, \ dipvec=dipvec,pgt=1) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources and targets, dipoles, pot") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ, \ charges=charges, \ dipvec=dipvec,pgt=1,pg=1) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=1) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=1) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=2, pg=2) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=2) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ pgt=2) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources and targets, charges, pot and grad") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=2,pg=2) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=2) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,dipvec=dipvec, \ pgt=2) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources and targets, dipoles, pot and grad") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=2,pg=2) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=2) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=2) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot and grad" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=3, pg=3) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=3) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ pgt=3) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges, pot, grad, hess") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=3,pg=3) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=3) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,dipvec=dipvec, \ pgt=3) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, dipoles, pot, grad, hess") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=3,pg=3) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=3) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=3) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot and grad" ) nd = 2 charges = np.random.uniform(0, 1, (nd, n)) dipvec = np.random.uniform(0, 1, (nd, 3, n)) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=1, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, pgt=1, nd=nd) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot, vectorized") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=1, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=stmp, dipvec=dipvec, pgt=1, nd=nd) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=1,nd=nd) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=1,nd=nd) out2.pot = out2.pottarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=1, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources, charges and dipoles, pot, vectorized") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=2, nd=nd) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=2,nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot and grad, vectorized") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=2, nd=nd) out2 = fmm.l3ddir(sources=sources,targets=stmp,dipvec=dipvec, \ pgt=2,nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot and grad, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=2,nd=nd) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, dipvec=dipvec, pgt=2, nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=2, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources, charges and dipoles, pot and grad, vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, charges=charges, pg=3, nd=nd) out2 = fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=3,nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, charges, pot, grad, hess vectorized") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, dipvec=dipvec, pg=3, nd=nd) out2 = fmm.l3ddir(sources=sources,targets=stmp,dipvec=dipvec, \ pgt=3,nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to sources, dipoles, pot, grad, hess vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,charges=charges, \ dipvec=dipvec,pg=3,nd=nd) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, dipvec=dipvec, pgt=3, nd=nd) out2.pot = out2.pottarg out2.grad = out2.gradtarg out2.hess = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=out2, pg=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources, charges and dipoles, pot, grad, hess vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=1, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=1, nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges, pot, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=1,nd=nd) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=1,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ, \ charges=charges, \ dipvec=dipvec,pgt=1,nd=nd) out2=fmm.l3ddir(sources=sources,targets=ttmp, \ charges=charges, \ dipvec=dipvec,pgt=1,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to targets, charges and dipoles, pot, vectorized") itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=2, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=2, nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, charges, pot and grad, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=2,nd=nd) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=2,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot and grad, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=2,nd=nd) out2 =fmm.l3ddir(sources=sources,targets=ttmp,charges=charges,\ dipvec=dipvec,pgt=2,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to targets, charges and dipoles, pot and grad, vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=3, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=3, nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to targets, charges, pot, grad, hess, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=3,nd=nd) out2=fmm.l3ddir(sources=sources,targets=ttmp,\ dipvec=dipvec,pgt=3,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print("Failed sources to targets, dipoles, pot, grad, hess vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=3,nd=nd) out2 =fmm.l3ddir(sources=sources,targets=ttmp,charges=charges,\ dipvec=dipvec,pgt=3,nd=nd) err = fmm.comperr(ntest=ntest, out=out, outex=out2, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to targets, charges and dipoles, pot, grad, hess vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=1, pg=1, nd=nd) out2 = fmm.l3ddir(sources=sources, targets=stmp, charges=charges, pgt=1, nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2 = fmm.l3ddir(sources=sources, targets=ttmp, charges=charges, pgt=1, nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges, pot, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=1,pg=1,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=1,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp, \ dipvec=dipvec,pgt=1,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, dipoles, pot, vectorized") itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ, \ charges=charges, \ dipvec=dipvec,pgt=1,pg=1,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=1,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=1,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=1, pgt=1, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot, vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=2, pg=2, nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=2,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ pgt=2,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges, pot and grad, vectorized" ) itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=2,pg=2,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=2,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,dipvec=dipvec, \ pgt=2,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, dipoles, pot and grad, vectorized" ) itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=2,pg=2,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=2,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=2,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=2, pgt=2, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot and grad, vectorized" ) itest = itest + 1 out = fmm.lfmm3d(eps=eps, sources=sources, targets=targ, charges=charges, pgt=3, pg=3, nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ pgt=3,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ pgt=3,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges, pot and grad, vectorized" ) itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,\ dipvec=dipvec,pgt=3,pg=3,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp, \ dipvec=dipvec,pgt=3,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,dipvec=dipvec, \ pgt=3,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, dipoles, pot and grad, vectorized" ) itest = itest + 1 out=fmm.lfmm3d(eps=eps,sources=sources,targets=targ,charges=charges,\ dipvec=dipvec,pgt=3,pg=3,nd=nd) out2=fmm.l3ddir(sources=sources,targets=stmp,charges=charges, \ dipvec=dipvec,pgt=3,nd=nd) outex.pot = out2.pottarg outex.grad = out2.gradtarg outex.hess = out2.hesstarg out2=fmm.l3ddir(sources=sources,targets=ttmp,charges=charges, \ dipvec=dipvec,pgt=3,nd=nd) outex.pottarg = out2.pottarg outex.gradtarg = out2.gradtarg outex.hesstarg = out2.hesstarg err = fmm.comperr(ntest=ntest, out=out, outex=outex, pg=3, pgt=3, nd=nd) if (err < eps): testres[itest] = 1 else: print( "Failed sources to sources and targets, charges and dipoles, pot and grad, vectorized" ) if (sum(testres) == ntests): print("all lfmm tests succeeded")