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

Implement a dispersion relation solver #11

Closed
namurphy opened this issue Jan 8, 2016 · 39 comments
Closed

Implement a dispersion relation solver #11

namurphy opened this issue Jan 8, 2016 · 39 comments
Labels
effort: very high Requiring ≳2 weeks. Can this be split up into multiple smaller/focused issues? needs subject matter expert Requires expertise from a plasma science domain expert plasmapy.dispersion Related to the plasmapy.dispersion subpackage plasmapy.formulary Related to the plasmapy.formulary subpackage
Milestone

Comments

@namurphy
Copy link
Member

namurphy commented Jan 8, 2016

When dealing with plasma waves, it would be helpful to have a dispersion relation solver.

This was recommended by John Raymond. I believe Carl Sovinec wrote a code that this several years ago, though not in python.

@tulasinandan
Copy link

tulasinandan commented Feb 27, 2017

I have a very simple two fluid dispersion (e.g. Stringer JNE 1963 or Rogers PRL 2002) solver. I could include that in. In the long run we could include a full kinetic solver in here too.

@namurphy namurphy added effort: high Requiring perhaps ∼1–2 weeks. Can this be split up into multiple smaller/focused issues? enhancement labels Apr 17, 2017
@namurphy
Copy link
Member Author

I also talked with Kristopher Klein about a general dispersion solver written in Fortran at a conference in late 2016, though I wasn't able to find it online. We would need to port that to Python or maybe Cython, however.

@tulasinandan
Copy link

I also have Peter Gary's dispersion solver. I am currently working on a python wrapper that simply calls the executable. We could bundle 64 bit static binary along with the python wrapper until we have something that is more in line with our goals. IRFU people do similar thing with WHAMP and matlab. I would have to take Peter's permission for it though.

Kris and Daniel (Verscharen) are working on an arbitrary linear dispersion solver that they call ALPS. We could coordinate with them so that their dispersion solver could be directly compiled and imported into python.

@namurphy
Copy link
Member Author

namurphy commented May 1, 2017

Thinking about this more...all the dispersion relation solvers I've heard of are numerical. I am wondering if we could implement something with SymPy to analytically find dispersion relationships as well, at least for situations where an analytic solution is possible. I think it would be possible, at the very least. Just a thought!

@StanczakDominik
Copy link
Member

I've been practicing SymPy recently and I could try to implement something in that. I could use a pointer to some reference materials for the dispersion relations themselves, though.

@namurphy namurphy modified the milestones: Future, v0.1 May 24, 2017
@StanczakDominik StanczakDominik added the plasmapy.formulary Related to the plasmapy.formulary subpackage label Aug 24, 2017
@namurphy namurphy added effort: very high Requiring ≳2 weeks. Can this be split up into multiple smaller/focused issues? and removed effort: high Requiring perhaps ∼1–2 weeks. Can this be split up into multiple smaller/focused issues? labels Sep 19, 2017
@namurphy namurphy modified the milestones: v0.1, v0.3, Future Dec 12, 2017
@namurphy namurphy added the needs subject matter expert Requires expertise from a plasma science domain expert label Dec 13, 2017
@antoinetavant
Copy link
Contributor

Hi there, My Lab is launching a project to develop a kinetic relation dispertion solver for magnetised plasma.
As it will be under free licence, it could be implemented in some way into plasmaPy !
It should be finished around mid-july !

However, we could implement natively into plasmaPy some simpler dispersion relation solver...

@lemmatum
Copy link
Contributor

What is a dispersion solver and how is it different from simple dispersion relations based on the Faddeeva function?

@tulasinandan
Copy link

@antoinelpp Great! As I said earlier as well, two fluid version is almost trivial and I have a small function for that. Kinetic one is hard, especially given the computational expense in some hard parameter regimes.

@namurphy Kris Klien and Daniel Verscharen have a very general linear dispersion solver in Fortran that they plan to make open source. We should ask them to make it an affiliate package with wrappers.

@lemmatum I did not know the term Faddeeva function before your post! I believe it is the same as plasma dispersion function, right? It is different from the "dispersion relations" for different wave modes. The first one appears in the permittivity, the second one describes a relationship between wavenumber and frequency for a given wave.

@lemmatum
Copy link
Contributor

@tulasinandan I see, yes, there is a difference between dispersion function and dispersion relation. I've already opened an issue for implementing dispersion functions, and I've got code to do, I just haven't gotten around to opening a PR (especially as it is for PlasmaPy v0.2).

There is this really handy wikipedia page which has a table of dispersion relations, we should use this as a reference for implementation.

@dstansby
Copy link
Contributor

https://github.com/danielver02/NHDS has recently been released, and I started working on building a python wrapper for it https://github.com/dstansby/NHDSPy

but then I realised the fortran needs to be recompiled each time there's a new set of input parameters which is kinda annoying. I might still try and finish the wrapper when I get some spare time.

@namurphy
Copy link
Member Author

Looks like we may run into some license issues. NHDS has been released under the GPLv3, which means that all derivative works must be released under the GPLv3 as well, and thus we won't be able to incorporate it directly into PlasmaPy unless it's released under something like an MIT or BSD license.

@tulasinandan
Copy link

tulasinandan commented Jun 19, 2018 via email

@antoinetavant
Copy link
Contributor

Hi there,
I'm organising a hackathon mid July for all the physicists of my lab in order to recreate WHAMP in python, improving both the user interface but also the physics modelled.
We are planing to create a standalone project, but we are kind to include it in PlasmaPy.
I'll keep you in touch with the result, but it is in pretty good shape around July the 15th.

ps: the project is here, but it is empty for now.

@tulasinandan
Copy link

tulasinandan commented Jun 30, 2018 via email

@tulasinandan
Copy link

tulasinandan commented Jun 30, 2018

EDIT: Add python tag to code block for syntax highlighting and add import numpy as np
EDIT 2: FIx reference from BALE JGR 2012 to BELLAN JGR 2012

#
#
# FUNCTION TO CALCULATE PHASE SPEEDS OF THE THREE BRANCHES OF TWO FLUID
# DISPERSION RELATION (e.g. STRINGER JPP 1963, ROGERS PRL 2001, 
# and BELLAN JGR 2012)
#
#                   Tulasi Nandan Parashar
import numpy as np
def tfps(beta=0.6, ca=1., de2=0.000545, theta=0., kk=1.):
   """
      beta: Total plasma beta,
      ca: Alfven speed based on mean field, 
      de2: me/mi, 
      theta: Angle of propagation in degrees
      kk: Wavenumber of interest in units of kdi
      
      Output is frequencies of the roots and the phase speeds w/k
      The roots are w[0]:Fast/Whistler, w[1]:Alfven/KAW, w[2]: Slow/Cyclotron
   """
   tht = theta*pi/180.
   ct = np.cos(tht)
   st = np.sin(tht)
   tt = st/ct
   cs=np.sqrt(beta/2.)*ca
   di =1.
   caksq=np.cos(tht)**2*ca**2
   cmsq=ca**2 + cs**2
   
   pcs=np.zeros(4)
   D = 1 + kk**2*de2
   # Find out the root of the quadratic dispersion relation
   pcs[0] = 1.
   pcs[1] = -(ca**2/D + cs**2 + caksq*(1+kk**2*di**2/D)/D)*kk**2
   pcs[2] = caksq*kk**4*(ca**2/D + cs**2 + cs**2*(1+kk**2*di**2/D))/D
   pcs[3] = -(cs**2*kk**6*caksq**2)/D**2
   w2 = np.roots(pcs); w = np.sqrt(w2)
   speeds= w/kk
   return w,speeds
#
# Compute the dispersion relation w(k) vs k for a single theta value.
#
def tfst(beta=0.6, ca=1., de2=0.000545, theta=0., kmin=1e-2, kmax=10., npoints=200,wrt='n'):
   """
      beta: Total plasma beta,
      ca: Alfven speed based on mean field, 
      de2: me/mi, 
      theta: Angle of propagation in degrees
      kkmin: Minimum Wavenumber of interest in units of kdi
      kkmax: Maximum wavenumber of interest in units of kdi

      Output is an array with 4 columns, k, w-fast, w-alf, w-slow
   """
   import matplotlib.pyplot as plt
   kmmn=np.log10(kmin)
   kmmx=np.log10(kmax)
   kk=np.logspace(kmmn,kmmx,npoints)
   warray=np.zeros((3,npoints))
   for i in range(0,npoints):
      f,s = tfps(beta, ca, de2, theta, kk[i])
      warray[:,i]=f
   plt.loglog(kk,warray[0,:], label='Fast/Magnetosonic')
   plt.loglog(kk,warray[1,:], label='Alfven/KAW')
   plt.loglog(kk,warray[2,:], label='Slow')
   plt.xlabel('$kd_i$')
   plt.ylabel('$\omega/\omega_{ci}$')
   plt.legend(loc='best',fancybox=True,framealpha=0.2)
   plt.title('Dispersion Relation for beta='+str(beta)+' and me/mi='+str(de2))
   plt.show()
   if wrt == 'y':
      ofile=open('disp'+str(theta)+'.dat','w')
      print>> ofile,'#  k', 'Acoustic', 'Alfven', 'Fast'
      for i in range(npoints):
         print>> ofile, kk[i],warray[2,i],warray[1,i],warray[0,i]
      ofile.close()

def tfev(beta=0.6, ca=1., de2=0.000545, theta=0., k=1.,aa=0.1):
   """
      beta: Total plasma beta,
      ca: Alfven speed based on mean field, 
      de2: me/mi, 
      theta: Angle of propagation in degrees
      k: wavenumber of interest in units of kdi

      Output: Prints the two fluid eigenvector to the screen
   """
   def amp(beta,de2,k,w,theta,aa):
      th=theta*pi/180.
      bb=1-w**2*(1+de2*k**2)/(k**2*np.cos(th)**2)
      sk='sin('+str(round(k,3))+'x)'
      ck='cos('+str(round(k,3))+'x)'
      def st(a):
         return str(round(a,3))
      return 'bx=0.'+\
            '\tby = '+st(round(2*aa,3))+ck+\
            '\tbz = '+st(-np.cos(th)*bb*2*aa/w)+sk+\
            '\nux = '+st(aa*k*bb*np.sin(2*th)/(w**2-beta*k**2))+sk+\
            '\tuy = '+st(-2*aa*k*np.cos(th)/w)+ck+\
            '\tuz = '+st(2*aa*k*bb*np.cos(th)**2/w**2)+sk+\
            '\t n = '+st((k*np.cos(th)/w)*aa*k*bb*np.sin(2*th)/(w**2-beta*k**2))+sk
   f,s=tfps(beta,ca,de2,theta,k)
#     The roots are w[0]:Fast/Whistler, w[1]:Alfven/KAW, w[2]: Slow/Cyclotron
   print 'Fast/ Whistler'
   print amp(beta,de2,k,f[0],theta,aa)
   print '##################'
   print
   print 'Alfven/ KAW'
   print amp(beta,de2,k,f[1],theta,aa)
   print '##################'
   print
   print 'Slow/ Cyclotron'
   print amp(beta,de2,k,f[2],theta,aa)
   

@StanczakDominik
Copy link
Member

@ritiek, the later part of the telecon today was kinda hectic and I didn't catch everything - did you want to work on this one, or should I?

@ritiek
Copy link
Contributor

ritiek commented Jul 3, 2018

@StanczakDominik I'll be a joke for implementing physics stuff but I could help a bit with coding style and python 3.6+ compatibility.

@StanczakDominik
Copy link
Member

Then let's just collaborate on this 😄 I'll try to start on this tomorrow.

@tulasinandan
Copy link

tulasinandan commented Jul 3, 2018 via email

@ritiek
Copy link
Contributor

ritiek commented Jul 3, 2018

@tulasinandan Yep! You can add all your code in a file named something like dispersion.py (?) and put it in the directory PlasmaPy/plasmapy/physics/, make the changes on your fork and then make a pull request to two-fluid-dispersion branch on my fork.

I'll apply fixes to your code and then further make a pull request to main PlasmaPy repo.

(We could directly copy paste and make your code python 3.6+/pep8 compliant and save you this trouble but it would be nicer for git to display that you wrote this code :)

@ritiek
Copy link
Contributor

ritiek commented Jul 5, 2018

Gentle ping @tulasinandan. :D

@tulasinandan
Copy link

tulasinandan commented Jul 5, 2018 via email

@hsxie
Copy link

hsxie commented Oct 5, 2018

Hi all. I have developed several codes relevant to plasma dispersion relation, which could be advanced than some other solvers.

  1. GPDF (http://hsxie.me/codes/gpdf/): generalized plasma dispersion function, which is very fast and accurate, and can support arbitrary 1D distribution function F(v) with an one-solve-all approach, instead of the conventional only Maxwellian one.

  2. PDRF (http://hsxie.me/codes/pdrf/): A general dispersion relation solver for magnetized multi-fluid plasma, which can give all the exact solutions and corresponding polarizations at once for multi-fluid plasma model very fast. The solver does not require initial guess. For example, the cold plasma wave can be produced easily for arbitrary input parameters with arbitrary species.

  3. PDRK (http://hsxie.me/codes/pdrk/): A General Kinetic Dispersion Relation Solver for Magnetized Plasma, which can give all the exact solutions (except strong damped modes) and corresponding polarizations at once for drift bi-Maxwellian distribution kinetic plasma model very fast. It could be advanced than the conventional root finding solvers, such as WHAMP.

I think these solvers can be very helpful for many researchers, especially in space plasma. Could them be possible implemented to plasmapy? I did not use python too much.

Thanks.
-hsxie

@liangwang0734
Copy link

I implemented Huasheng's fluid and kinetic (electrostatic only for now) solvers in Python a while ago. I plan to issue a pull request in the near future.

@joglekara
Copy link

joglekara commented Apr 23, 2020

Hi all!

I'm sorry if I missed something but I wasn't able to figure out what the status is here.

I have a scipy-based electrostatic dispersion relation solver that I'm happy to contribute. Please let me know if this is of interest!

@namurphy
Copy link
Member Author

I have a scipy-based electrostatic dispersion relation solver that I'm happy to contribute. Please let me know if this is of interest!

Yes, let's definitely talk! We're currently planning for work on the dispersion subpackage to be a project for a graduate student starting sometime this summer. We've done some planning for it during our weekly community meetings which isn't on this issue, but overall we're still just getting started with this. We'd be interested to learn more about your electrostatic dispersion relation solver.

@namurphy
Copy link
Member Author

We also very recently created a chat room on Riot for discussing the dispersion relation solver.

@liangwang0734
Copy link

liangwang0734 commented Apr 23, 2020

I made one, too, based on matrix inversion instead of searching. I'm not familiar with PlasmaPy framework, but the code itself is quite straightforward and should be easy to integrate.

https://github.com/liangwang0734/xeon

The basic algorithm was originally developed by Dr. Huasheng Xie of ENN.

@tulasinandan
Copy link

tulasinandan commented Apr 23, 2020 via email

@liangwang0734
Copy link

liangwang0734 commented Apr 23, 2020 via email

@tulasinandan
Copy link

tulasinandan commented Apr 23, 2020 via email

@rocco8773 rocco8773 moved this from To-Do to Icebox in Formulary Development Jul 9, 2020
@rocco8773 rocco8773 moved this from Icebox to Backlog in Formulary Development Jul 15, 2020
@namurphy
Copy link
Member Author

There's also a dispersion relation solver from Ammar Hakim.

Formulary Development automation moved this from Backlog to Closed / Cancelled Dec 14, 2022
@namurphy namurphy added the plasmapy.dispersion Related to the plasmapy.dispersion subpackage label Jan 18, 2024
@namurphy
Copy link
Member Author

If you want to follow up on this, there's more discussion about dispersion relation solvers in #1237 and #2471.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: very high Requiring ≳2 weeks. Can this be split up into multiple smaller/focused issues? needs subject matter expert Requires expertise from a plasma science domain expert plasmapy.dispersion Related to the plasmapy.dispersion subpackage plasmapy.formulary Related to the plasmapy.formulary subpackage
Projects
Formulary Development
  
Closed / Cancelled
Potential Student Projects
Large scale issues
Development

No branches or pull requests

10 participants