Plasmapy: Optimize Braginskii code

Created on 7 Feb 2018  路  3Comments  路  Source: PlasmaPy/PlasmaPy

The Braginksii code in transport.py could do with a bit of optimization.

For example in _nondim_tec_braginskii we have:

beta_par = beta_0
    if field_orientation == 'parallel' or field_orientation == 'par':
        return beta_par

    beta_perp = (beta_1_prime[Z_idx] * hall ** 2 +
                 beta_0_prime[Z_idx]) / Delta
    if field_orientation == 'perpendicular' or field_orientation == 'perp':
        return beta_perp

    beta_cross = (beta_1_doubleprime[Z_idx] * hall ** 3 +
                  beta_0_doubleprime[Z_idx] * hall) / Delta
    if field_orientation == 'cross':
        return beta_cross

    if field_orientation == 'all':
        return np.array((beta_par, beta_perp, beta_cross))

Things like beta_perp and beta_cross should be moved under their respective if statements and under the general field_orientation == 'all' statement. This will reduce unnecessary computations across the different methods.
This seems to be a recurring pattern across the Braginskii code.

minimal Good first contribution Help wanted Optimization

Most helpful comment

@lemmatum I'd like to work on this issue since #191 is now merged.

All 3 comments

I would suggest doing this after #191 is done. Unless you like to do a lot of rebasing.

@lemmatum I'd like to work on this issue since #191 is now merged.

@apooravc go for it!
Just a fair warning, we are going to do a feature freeze for v0.1 after #242 is done. So this might not get merged until after that. Or it might just end up as part of the code review - not sure yet.
Either way, do the thing!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StanczakDominik picture StanczakDominik  路  5Comments

namurphy picture namurphy  路  4Comments

namurphy picture namurphy  路  3Comments

lemmatum picture lemmatum  路  6Comments

lemmatum picture lemmatum  路  6Comments