Giter Site home page Giter Site logo

johnaparker / miepy Goto Github PK

View Code? Open in Web Editor NEW
33.0 5.0 15.0 3.61 MB

Python module to solve Maxwell's equations for a cluster of particles using the generalized multiparticle Mie theory (GMMT)

License: GNU General Public License v3.0

Shell 0.12% Batchfile 0.04% CMake 0.05% C++ 2.87% Python 16.00% Fortran 80.85% Makefile 0.06%
python physics electrodynamics light scattering t-matrix

miepy's People

Contributors

johnaparker avatar tjpleasant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

miepy's Issues

Impoving OpenMP acceleration

The current OpenMP implementation is not optimal (2x performance for 8 threads). There are two parts to OpenMP acceleration: building the interaction matrix (A), and solving the linear system Ax = b.

The issue for building A is probably load-balancing: the A/B vsh translation coefficients involve recursion relations that depend on inter-particle separation. Some threads will finish before others.

The issue for solving Ax = b is less obvious. Since this is a widely famous problem, it's worth looking into existing software solutions.

There are a few things that can easily be parallelized: source decomposition, cross-section evaluation, force/torque evaluation, E/H field evaluation

Lastly, there are two algorithm optimizations not being used:

  1. Using rotation-translation-rotation algorithm to construct A matrix
  2. There might exist an optimal solver for the linear system based on the physical problem, see Xu papers.

Improving the interface (substrate) implementation

Currently, MiePy utilizes the normal incidence approximation (NIA) for dealing with a substrate. The exact solution is outlined in [1].

Implementation

  • Write the current NIA approximation in C++ (current implementation is slow)
  • With miepy.interface, add a bool parameter nia = True to toggle NIA (default True until exact solution is implemented)
  • Implement the exact solution in C++

Tests

  • Verify the NIA approximation with the exact solution for a single particle or multiple particles far from the interface
  • Compare to FDTD simulations with a substrate

Notes

  • Calculating the E and H field can be done in the NIA approximation using field expansions around the mirror particles. It is less clear how to do so in the exact solution (sec. 2.2.2 in [1] discusses this)
  • The definition of the cross-sections in the presence of the interface is unclear (sec. 2.5 in [1])

References

  1. Mackowski_2008_Exact solution for the scattering and absorption properties of sphere clusters.pdf
    Eqs.(19-33) for exact solution, Eq.(34) for NIA

Improve method of building wheels

  • Use miniconda to download Eigen3 and GSL, and use environments for each version of Python
  • For each OS, this script should be slightly modified
  • On Windows, the gsl.dll file needs to be packaged into the wheel (on *nix it's done with auditwheel)

Note
If the following bug occurs:

auditwheel: error: cannot repair "/io/.build_wheels/wheelhouse/miepy-0.5.0-cp38-cp38-linux_x86_64.whl" to "manylinux2010_x86_64" ABI because of the presence of too-recent versioned symbols. You'll need to compile the wheel on an older toolchain

it may be due to lingering .o or .mod files in the nfmds folder. Running make clean will remove all build files.

Implementing translational and rotational symmetries

Implement all of the symmetry options to miepy.cluster

Implementation

  • Test the convergence of the current 1D and 2D implementation. A metric of auto-convergence should determine when to stop computing (see [1])
  • Implement 3D translational symmetry (ref [2])
  • Implement the rotational and mirror symmetries (see miepy/docs for theory)
  • For translational symmetries in 2D, define symmetries the major type of lattice (square, rectangle, hexagonal, etc.)

Tests

  • FDTD 1d and 2d periodic boundary comparison
  • Rotational symmetry compared to exact solution for different integers of rotation symmetry
  • Translational symmetry compared to approximation solution (a long chain or large 2D lattice)

References

  1. Xu_2013_Scattering of electromagnetic waves by periodic particle arrays.pdf
    1D and 2D periodic
  2. josaa-31-2-322.pdf
    3D periodic

Better evaluation of cluster T-matrix

The cluster T-matrix can be computed from a solved miepy.cluster or miepy.sphere_cluster

Attempt at implementation

https://github.com/johnaparker/miepy/blob/issue_2/miepy/tmatrix/cluster_tmatrix.py

Notes

  • miepy.sphere_cluster_particle is currently implemented using NFMDS, but would be more general implemented in this way
  • The T-matrix can be constructed column-by-column by solving the cluster coefficients for each possible VSHW function as an incident source.

References

Xu.-.2003.-.Radiative.scattering.properties.of.an.ensemble.of.pdf
Eqs. (49-53) for the cluster T-matrix

Analytic expressions for scattered power (flux)

For a system of dipoles and nanoparticles, the expansion coefficients of the source and system can be calculated with this:

def get_p_src(cluster, origin=[0,0,0]):
    """get the p_src expansion coefficients; assumes all sources are dipoles

    Arguments:
        cluster      miepy.cluster or miepy.sphere_cluster
        origin       origin around which to obtain expansion
    """
    if isinstance(cluster.source, miepy.sources.combined_source):
        p_src = []
        positions = []
        for dipole in cluster.source.sources:
            p_src_d = np.zeros([2,3], dtype=complex)
            p_src_d[0] = (dipole.weight[-1], dipole.weight[0], dipole.weight[1])
            p_src.append(p_src_d)
            positions.append(dipole.position)
        p_src = np.asarray(p_src)
        positions = np.asarray(positions)
    else:
        dipole = cluster.source
        p_src = np.zeros([2,3], dtype=complex)
        p_src[0] = (dipole.weight[-1], dipole.weight[0], dipole.weight[1])
        positions = np.array([dipole.position])
        p_src = np.array([p_src])

    return miepy.cluster_coefficients(positions, p_src, 
            cluster.material_data.k_b, origin, lmax=cluster.lmax)

def get_p_scat(cluster, origin=[0,0,0]):
    """get the p_scat expansion coefficients of the nanoparticles

    Arguments:
        cluster      miepy.cluster or miepy.sphere_cluster
        origin       origin around which to obtain expansion
    """
    return miepy.cluster_coefficients(cluster.position, cluster.p_scat,
            cluster.material_data.k_b, origin=origin, lmax=cluster.lmax)

Then the flux of the source (P0) and system (P) is:

Z0 = miepy.constants.Z0
k = 2*np.pi/wavelength
p_src = get_p_src(cluster)
p_scat = get_p_scat(cluster)
P0 = 0.5/Z0*np.pi/k**2*np.sum(np.abs(p_src)**2) # power source
P = 0.5/Z0*np.pi/k**2*np.sum(np.abs(p_scat + p_src)**2) # power system
enhance = P/P0

These functions should be added to MiePy in some way to make this type of calculation straightforward.

Difficulties Installing Miepy on Midway2

Hi John,

I've been having trouble with installing on midway2.

Both with conda
image

and pip
image

Any suggestions?

Thank you,
Tyler

PS:
I saw you recommended this, by the way, but it fails even the first of those commands.
conda install -c conda-forge quaternion
conda install -c moble spherical_functions
pip install miepy

Fail to install miepy!!!

Dear authors,

Please help to check whether we can install miepy normally?

I tried to type

pip install miepy

but it took me so long for waiting...(more than one day) without any progess.

I used Spyder on the environment of Anaconda Navigator.

Thank you!
Student
Le

Multiple-layered core shell particle

Implement a many-layered core-shell particle. Along with the core-shell particle, these particles are Mie-like and can be used inside miepy.sphere_cluster rather than going to the T-matrix approach. Additionally, the interior field calculations would need to be specialized.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.