LLNL/UEDGE

Running multiple simulations in a single Python script

Closed this issue · 6 comments

I am trying to run multiple PyUEDGE simulations in a loop using the Jupyter notebook. Here is the pseudocode:

from uedge import *
...
for i in range(n):
  #update some parameters in the bbb package
  bbb.exmain()
  #save some measurements

I am noticing some very interesting results. Once a certain threshold (on the order of 10) for n is exceeded, the majority of the later simulations do not run to the full 30 iterations, converging very quickly with iterm = 1 and very low fnrm values. This wouldn't be an issue in and of itself, but when I run a certain initial configuration in an environment where 100 simulations have already been run in the manner above, the measurements for te, ti, etc. are different than what I get when I run the same configuration in a fresh environment where no prior simulations were run. As a control, when I run the same initial configuration in two separate, fresh environments, I get identical measurements, so this indicates that something is going wrong.

To me, it seems like some backend variables are not being properly reset between the sequential executions of bbb.exmain(). I am new to UEDGE, so any help on this issue would be great.

Results from the run starting after 100 simulations:

UEDGE $Name: V7_09_02 $
Wrote file "gridue" with runid:    EFITD    09/07/90      # 66832 ,2384ms��������            

 ***** Grid generation has been completed
  Updating Jacobian, npe =                      1
 iter=    0 fnrm=     0.4884085628076241     nfe=      1
  Updating Jacobian, npe =                      2
 iter=    1 fnrm=     0.4671420091454486     nfe=     24
 iter=    2 fnrm=     0.4411713449131697     nfe=     50
 iter=    3 fnrm=     0.4206699610874590     nfe=     86
 iter=    4 fnrm=     0.4130005131324361     nfe=    123
 iter=    5 fnrm=     0.4087938996934226     nfe=    160
  Updating Jacobian, npe =                      3
 iter=    6 fnrm=     0.3852795681315921     nfe=    175
 iter=    7 fnrm=     0.3579047446683835     nfe=    193
 iter=    8 fnrm=     0.3264477480360225     nfe=    215
 iter=    9 fnrm=     0.3291915675412144     nfe=    247
 iter=   10 fnrm=     0.2985548946641430     nfe=    275
  Updating Jacobian, npe =                      4
 iter=   11 fnrm=     0.2616509852150688     nfe=    293
 iter=   12 fnrm=     0.2525471794564058     nfe=    316
 iter=   13 fnrm=     0.2506493148302380     nfe=    351
 iter=   14 fnrm=     0.2304580279914706     nfe=    385
 iter=   15 fnrm=     0.1602699754169653     nfe=    421
  Updating Jacobian, npe =                      5
 iter=   16 fnrm=     0.5322574291557221E-01 nfe=    434
 iter=   17 fnrm=     0.9899483298349073E-02 nfe=    450
 iter=   18 fnrm=     0.9593463464214905E-03 nfe=    466
 iter=   19 fnrm=     0.1721070907466653E-05 nfe=    483
 iter=   20 fnrm=     0.3825405343555981E-09 nfe=    506
  Updating Jacobian, npe =                      6
 iter=   21 fnrm=     0.9584557053340898E-11 nfe=    526


 nksol ---  iterm = 1.
            maxnorm(sf*f(u)) .le. ftol, where maxnorm() is
            the maximum norm function.  u is probably an
            approximate root of f.
 Interpolants created; mype =                   -1

Results from the run starting after 0 simulations (no other runs):

UEDGE $Name: V7_09_02 $
Wrote file "gridue" with runid:    EFITD    09/07/90      # 66832 ,2384ms��������            

 ***** Grid generation has been completed
  Updating Jacobian, npe =                      1
 iter=    0 fnrm=      2.136642210096055     nfe=      1
  Updating Jacobian, npe =                      2
 iter=    1 fnrm=      2.121503682570631     nfe=     13
 iter=    2 fnrm=      2.032286982296977     nfe=     30
 iter=    3 fnrm=      1.960579474356897     nfe=     52
 iter=    4 fnrm=      1.894459393842296     nfe=     79
 iter=    5 fnrm=      1.845530876385033     nfe=    114
  Updating Jacobian, npe =                      3
 iter=    6 fnrm=      1.764286058407941     nfe=    133
 iter=    7 fnrm=      1.725418282617423     nfe=    155
 iter=    8 fnrm=      1.729785803551428     nfe=    181
 iter=    9 fnrm=      1.736277375408835     nfe=    213
 iter=   10 fnrm=      1.754802041641710     nfe=    242
  Updating Jacobian, npe =                      4
 iter=   11 fnrm=      1.762044620546933     nfe=    261
 iter=   12 fnrm=      1.764575437147577     nfe=    282
 iter=   13 fnrm=      1.768529819650052     nfe=    307
 iter=   14 fnrm=      1.773356828914952     nfe=    337
 iter=   15 fnrm=      1.789545013500852     nfe=    374
  Updating Jacobian, npe =                      5
 iter=   16 fnrm=      1.794886548613142     nfe=    391
 iter=   17 fnrm=      1.802188626137893     nfe=    408
 iter=   18 fnrm=      1.778841141499653     nfe=    429
 iter=   19 fnrm=      1.791436323790826     nfe=    451
 iter=   20 fnrm=      1.793130768578333     nfe=    469
  Updating Jacobian, npe =                      6
 iter=   21 fnrm=      1.776943066727186     nfe=    484
 iter=   22 fnrm=      1.771746727188482     nfe=    501
 iter=   23 fnrm=      1.772183898681232     nfe=    521
 iter=   24 fnrm=      1.775974514502974     nfe=    546
 iter=   25 fnrm=      1.776224036709406     nfe=    574
  Updating Jacobian, npe =                      7
 iter=   26 fnrm=      1.780423723690242     nfe=    593
 iter=   27 fnrm=      1.780172675581789     nfe=    612
 iter=   28 fnrm=      1.784123582634681     nfe=    632
 iter=   29 fnrm=      1.783336972028313     nfe=    650
 iter=   30 fnrm=      1.786552326493947     nfe=    670


 nksol ---  iterm = 4.
            the maximum allowable number of nonlinear
            iterations has been reached.
 Interpolants created; mype =                   -1

I haven't figured out the exact value of n where the results start to diverge, but my guess is around 50 simulations. That is where the first simulations with <30 iterations and iterm = 1 start to appear.

Note: My goal is not to find solutions for a single timestep, but rather solutions run to steady state. I didn't want to catch you off guard if you saw the previous version of the comment. Sorry.

Thank you, the response helped clarify a lot for me. My goal is to find converged solutions at steady state for different input parameters, using the same method found in the pyexamples folder. Is there a way to achieve this in a single script? Currently, I am using the test case from the LLNL/UEDGE/jupyter folder, and I believe it is starting out with an initial solution stored in an HDF5 file. In this case, would it still be necessary to obtain a solution for the i=1 parameters?

The above solution works.