PlasmaPy / PlasmaPy

An open source Python package for plasma research and education
https://docs.plasmapy.org
BSD 3-Clause "New" or "Revised" License
575 stars 338 forks source link

Utility to compute various plasma parameters from given parameters #720

Open tulasinandan opened 5 years ago

tulasinandan commented 5 years ago

Feature request

A frequent task that we perform is computation and comparison of various scales of interest for the plasma under consideration. Once a plasma is loaded, we typically want to know what various length-scales (Debye length, particle gyro-radii, inertial lengths, ...), and time scales (plasma frequencies for all species, gyro-frequencies, possibly frequencies of some wave-modes of interest).

We should have a (set of) method(s) attached to plasma class that facilitates this. If I create a plasma object with given parameters, I should be able to call these methods to print/visualize and compare various scales of interest.

As an example, I attach the output of my code that does this using P3D input parameter files. This is very specific to simulations, but gives a general idea of the kind of comparisons we want to have

############ NUMERICAL PARAMETERS ###############
Lx= 149.565      Ly= 149.565     Lz= 100000.000      ppg= 3200
Nx= 4096     Ny= 4096    Nz= 1   On 16384  procs
b0= 1.000    dx= 0.037   dy= 0.037   dz= 100000.000
me/mi = 0.04000      nu= 0.00000     eta= 0.00000    kgrid= 86.036
dt= 0.005000     substeps= 3
Expected Runtime is: 
(xNsteps for time to request): 0.032768 minutes/(simulation step)

############# PLASMA PARAMETERS #################
beta_i= 0.600    betae= 0.600    me/mi= 0.04000
rhoi= 0.775      rhoe= 0.155     Debey Length= 0.037
Va= 1.000    Vthi= 0.775     Vthe= 3.873     c= 15.000
wci= 1.000   wce= 25.000 wpi= 15.000     wpe= 75.000

######### RESOLUTION ESTIMATES #################

##### TWO FLUID WAVES ==>
At 0.0 : F/W= 0.77460  A/KAW= 0.30079  S/A= 0.01119
Courant factor:  0.035 , nu*k^3/Cf= 0.00000
--
At 45.0 : F/W= 0.77577  A/KAW= 0.21238  S/A= 0.00791
Courant factor:  0.035 , nu*k^3/Cf= 0.00000
--
At 79.2 : F/W= 0.77671  A/KAW= 0.05209  S/A= 0.00194
Courant factor:  0.035 , nu*k^3/Cf= 0.00000
--

##### MISC SPEEDS ==>
Courant factor for Alfven waves is:  0.023
Courant factor for proton thermal speed is:  0.106
Courant factor for electron thermal speed is:  0.530
Courant factor for speed of light is:  0.342

##### TIMES ==>
200.000  time steps /wci
8.000  time steps /wce
13.333  time steps /wpi
2.667  time steps /wpe

##### LENGTHS ==>
At max  27.386  grid points /di
At max  21.213  grid points /rhoi
At max  1.000  grid points /lde
At max  4.243  grid points /rhoe
At max  5.477  grid points /de
rocco8773 commented 5 years ago

Are you looking to do design something that prints these parameters, returns these parameters, or both? I've done something similar to this before. It kinda looked like...

in file plasma.py

class Plasma:
    ...
    @property
    def report(self):
        from .report_plasma import ReportPlasma
        return ReportPlasma(self)

in file report_plasma.py

from .plasma import Plasma

class ReportPlasma:
    def __init__(self, plasma: Plasma):
        self._plasma = plasma
        ...

    @property
    def scales(self):
        scales['frequencies'] = self.frequencies
        ...
        return scales

    @property
    def frequencies(self):
        freq['ion-cyclotron frequency'] = self._plasma.ion_cyclotron_frequency
        freq['plasma frequency'] = self._plasma.plasma_frequency
        ...
        return freq

    def print_frequencies(self):
        # do some pretty print with self.frequencies

Then you could do...

myplasma = Plasma()

# get all requencies
freqs = myplasma.report.frequencies

# print frequencies
myplasma.report.print_frequencies()

I've also set this up before such that print_frequencies() could print to screen or a text file.

This is also setup such that all properties are calculated when called, so if you were to update myplasma then those parameter changes would be reflected in the next myplasma.report.frequencies call.