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

Status of triangle functions #19

Open
leon-vv opened this issue Aug 21, 2023 · 7 comments
Open

Status of triangle functions #19

leon-vv opened this issue Aug 21, 2023 · 7 comments

Comments

@leon-vv
Copy link
Contributor

leon-vv commented Aug 21, 2023

Hi there!

First of all thanks for making this very useful piece of software.

I was looking into the FMM method to speed up my electron optics simulation package Traceon. For this purpose I'm very interested in using the triangle methods provided by FMMLIB3D.

After some tweaking I was able to get it to work. First I had to uncomment the "tria" line in the .mako file. Furthermore I had to change dipvec to dipvec.T on line 226 of the __init__.py file. I have attached an example script below for you to test out.

My question is why the triangle methods are not supported out of the box? It seems like all the infrastructure is in place to enable them. If this is purely a manpower issue, would you accept my pull requests to enable them?

Thanks again!

import pyfmmlib
import numpy as np
from scipy.integrate import dblquad

N = 5

triangles = np.random.rand(N, 3, 3)
centroids = np.mean(triangles, axis=1)

normals = np.cross(triangles[:, 2]-triangles[:, 0], triangles[:, 1]-triangles[:, 0])
normals /= np.linalg.norm(normals, axis=0)

charges = np.random.rand(N)

class Mesh:
    def __init__(self, triangles, normals, centroids):
        self.triangles = triangles
        self.normals = normals
        self.centroids = centroids

    def __len__(self):
        return len(self.triangles)

# Return the exact value for triangle at index i
def exact(i):
     
    target = centroids[i]
     
    def to_integrate(a, b, j):
        v1, v2, v3 = triangles[j]
        
        location = v1 + (v3-v1)*a + (v2-v1)*b
        area = np.linalg.norm(np.cross(v3-v1, v2-v1))

        return area/np.linalg.norm(location-target)
     
    potential = 0.
     
    for j in range(N):
        potential += charges[j]*dblquad(to_integrate, 0, 1, 0, lambda y: 1-y, args=(j,))[0]

    return potential

 
m = Mesh(triangles, normals, centroids)
pot1 = pyfmmlib.fmm_tria("p", 0, pyfmmlib.LaplaceKernel(), m, slp_density=charges).real

e = exact(0)/(4*np.pi)
print(f'Accuracy: {e/pot1[0] - 1:.1e}')
@inducer
Copy link
Owner

inducer commented Aug 22, 2023

I would be willing to review a PR (with tests!) that enables the triangle functions.

@leon-vv
Copy link
Contributor Author

leon-vv commented Sep 20, 2023

Hi Inducer, thanks for reviewing my PR and merging it into the project. To start using the updated package I need the update to land into PyPI. Is there anything I can do to help you release a new version on PyPI?

@inducer
Copy link
Owner

inducer commented Sep 20, 2023

@leon-vv
Copy link
Contributor Author

leon-vv commented Sep 21, 2023

Thanks! At the risk of being annoying, would it be difficult to add wheels for the Windows platform? Currently the package is only installable if a Fortran compiler is available, which is not the case out of the box on Windows.

@inducer
Copy link
Owner

inducer commented Sep 21, 2023

You're welcome to give it a try. #12 has the beginnings of a cibuildwheel configuration. If you can get it to work, I'd be happy to merge it. Alternatively, the conda-forge package for pyfmmlib already supports Windows.

@leon-vv
Copy link
Contributor Author

leon-vv commented Sep 21, 2023

I'm trying to build the package using the Windows Intel Fortran compiler with limited success. I don't really get the conda-forge repository, does it automatically build Windows wheels? If so, why can we not upload those wheels to PyPI ?

@inducer
Copy link
Owner

inducer commented Sep 21, 2023

Conda-forge has its own package format, different from wheels, and its own package manager, conda.

To use it, download and install miniforge, and then conda install pyfmmlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants