PrincetonUniversity / STELLOPT

This is the GitHub repository for STELLOPT, the state-of-the-art stellarator optimization code.
https://princetonuniversity.github.io/STELLOPT/
MIT License
68 stars 17 forks source link

KNOSIS Integration into STELLOPT #174

Open lazersos opened 1 year ago

lazersos commented 1 year ago

The group at CIEMAT has done a good job working on integration of KNOSOS into STELLOPT. This issue is to track a more official integration of the code. Currently, in the CIEMAT branch, the code is include as a code in the STELLOPT suite. This needs to be changed over so that it behaves like an exernally linked code. I'll (@lazersos) take the lead on this. The tasks as I see them are:

joseluisvelasco commented 1 year ago

Thanks! Let us know what we can do to help.

lazersos commented 1 year ago

I've started on this. I've created a branch CIEMAT_Laz which is based on the CIEMAT branch with a merge of develop. This will be the branch I work on for this project CIEMAT_Laz.

lazersos commented 1 year ago

OK I've got STELLOPT linking to KNOSOS built externally to STELLOPT. Does anyone have a simple example file I could run for STELLOPT to verify the code is working properly?

joseluisvelasco commented 1 year ago

Hi, not sure if you read Edi's mail of last week (his was a direct reply to notifications@github.com and does not appear here). Here's his message " Hello Sam. Here you have an input for a case from W7X including KNOSOS proxies that should work. It only run one step. Best, Edi " input.W7X_FB2.txt

lazersos commented 1 year ago

OK I'm running into a bug:

STELLOPT Version  2.80
  Equilibrium calculation provided by:
  =================================================================================
  =========   Parallel Variational Moments Equilibrium Code (v 9.0)       =========
  =========                (S. Hirshman, J. Whitson)                      =========
  =========         http://vmecwiki.pppl.wikispaces.net/VMEC              =========
  =================================================================================

  KiNetic Orbit-averaging SOlver for Stellarators (KNOSOS) provided by:
  =================================================================================
  =========         KiNetic Orbit-averaging SOlver for Stellarators       =========
  =========               Drift Kinetic Equation Solver                   =========
  =========                      (J.L. Velasco et al.)                    =========
  =========                   joseluis.velasco@ciemat.es                  =========
  =================================================================================

 -----  MPI Params.   -----
    MPI Version:  3.01
    Optimizers requested:            1
    Number of Processors:            2
    Shared memory groups:            1
    Processors per group:            2
 Reset noptimizers=1 for single run.
   Workers per optimizer:            2
     Optimizers provided:            1
 -----  Optimization  -----
    =======VARS=======
     RBC( 001, 000):  Radial Boundary Specification (COS)
     ZBS( 001, 000):  Vertical Boundary Specification (SIN)
    ======TARGETS=====
     Radial derivative of B_00
     KNOSOS gamma_c, fast ion confinement
     KNOSOS gamma_alpha, fast ion confinement
     KNOSOS variance of B maxima
     KNOSOS variance of B at zeta=0
     KNOSOS variance of B minima
     KNOSOS width of B well
    ==================
    Number of Parameters:            2
    Number of Targets:              35
    !!!! EQUILIBRIUM RESTARTING NOT UTILIZED !!!!
     OPTIMIZER: SINGLE_ITERATION
     NFUNC_MAX:            1
 ---------------------------  EQUILIBRIUM CALCULATION  ------------------------

  NS =   16 NO. FOURIER MODES =  263 FTOLV =  1.000E-30 NITER =   1000
  PROCESSOR COUNT - RADIAL:    2
 INITIAL JACOBIAN CHANGED SIGN!
 TRYING TO IMPROVE INITIAL MAGNETIC AXIS GUESS
  ---- Improved AXIS Guess ----
      RAXIS_CC =    40.216490622035600        2.2852250384774488       -6.6142834206809040E-002 -0.12828850505130124        5.6778265876046237E-002   1.7863203878499795E-002  -2.9960603340402868E-002  -3.4174202976764941E-002   2.5771765042044481E-002   2.4983500594964399E-002  -1.3780774946302728E-002
      ZAXIS_CS =   -0.0000000000000000       -1.5790034933496113       0.19613566454168449        6.9774454219158566E-002  -4.8970969560191813E-002   3.5692721892876783E-002   4.6042063068502011E-002  -5.7377382512782765E-002  -4.5554076468455426E-002   2.3544963219827103E-002   3.4372885280048011E-002
  -----------------------------

  ITER    FSQR      FSQZ      FSQL    RAX(v=0)    DELT       WMHD

    1  4.66E+03  2.75E+02  1.60E+00  4.235E+01  1.00E+00  5.1007E+04
  200  1.11E-02  2.35E-03  3.19E-04  4.234E+01  1.22E-01  4.3712E+04
  400  2.62E-04  6.08E-05  1.04E-05  4.239E+01  1.22E-01  4.3665E+04
  600  2.88E-05  5.81E-06  1.77E-06  4.239E+01  1.22E-01  4.3658E+04
  800  6.57E-06  1.03E-06  5.47E-07  4.239E+01  1.22E-01  4.3656E+04
 1000  1.72E-06  2.05E-07  2.01E-07  4.239E+01  1.22E-01  4.3655E+04

  NS =   32 NO. FOURIER MODES =  263 FTOLV =  1.000E-30 NITER =   2000
  PROCESSOR COUNT - RADIAL:    2

  ITER    FSQR      FSQZ      FSQL    RAX(v=0)    DELT       WMHD

    1  3.02E-01  5.22E-02  5.52E-04  4.239E+01  1.00E+00  4.3657E+04
  200  8.84E-06  3.49E-06  7.89E-08  4.239E+01  5.16E-01  4.3654E+04
  400  1.27E-07  2.35E-08  1.94E-08  4.239E+01  5.01E-01  4.3654E+04
  600  1.85E-08  1.50E-09  2.53E-09  4.239E+01  5.01E-01  4.3654E+04
  800  5.08E-09  5.11E-10  1.24E-09  4.240E+01  5.01E-01  4.3653E+04
 1000  1.90E-09  2.10E-10  2.57E-10  4.240E+01  5.01E-01  4.3653E+04
 1200  8.70E-10  7.75E-11  1.36E-10  4.240E+01  5.01E-01  4.3653E+04
 1400  4.13E-10  3.83E-11  5.37E-11  4.240E+01  5.01E-01  4.3653E+04
 1600  1.89E-10  1.53E-11  2.11E-11  4.240E+01  5.01E-01  4.3653E+04
 1800  9.08E-11  5.46E-12  5.68E-12  4.240E+01  5.01E-01  4.3653E+04
 2000  5.05E-11  3.15E-12  2.90E-12  4.240E+01  5.01E-01  4.3653E+04

  NS =   64 NO. FOURIER MODES =  263 FTOLV =  1.000E-30 NITER =   4000
  PROCESSOR COUNT - RADIAL:    2

  ITER    FSQR      FSQZ      FSQL    RAX(v=0)    DELT       WMHD

    1  5.48E-01  1.06E-01  4.97E-05  4.240E+01  1.00E+00  4.3654E+04
  200  1.72E-06  9.65E-07  5.43E-07  4.240E+01  4.18E-01  4.3653E+04
  400  1.99E-08  1.95E-09  2.51E-09  4.240E+01  4.18E-01  4.3653E+04
  600  3.02E-09  2.62E-10  2.06E-10  4.240E+01  4.18E-01  4.3653E+04
  800  7.97E-10  6.91E-11  5.58E-11  4.240E+01  4.18E-01  4.3653E+04
 1000  3.75E-10  3.61E-11  2.75E-11  4.240E+01  4.18E-01  4.3653E+04
 1200  2.92E-10  2.41E-11  1.69E-11  4.240E+01  4.18E-01  4.3653E+04
 1400  1.74E-10  1.31E-11  8.13E-12  4.240E+01  4.18E-01  4.3653E+04
 1600  8.13E-11  5.96E-12  3.81E-12  4.240E+01  4.18E-01  4.3653E+04
 1800  4.04E-11  3.09E-12  1.70E-12  4.240E+01  4.18E-01  4.3653E+04
 2000  2.60E-11  1.62E-12  8.65E-13  4.240E+01  4.18E-01  4.3653E+04
 2200  1.78E-11  1.16E-12  6.40E-13  4.240E+01  4.18E-01  4.3653E+04
 2400  1.28E-11  8.37E-13  4.31E-13  4.240E+01  4.18E-01  4.3653E+04
 2600  9.58E-12  6.07E-13  2.74E-13  4.240E+01  4.18E-01  4.3653E+04
 2800  7.44E-12  4.72E-13  2.13E-13  4.240E+01  4.18E-01  4.3653E+04
 3000  5.85E-12  3.42E-13  1.59E-13  4.240E+01  4.18E-01  4.3653E+04
 3200  4.29E-12  2.35E-13  1.30E-13  4.240E+01  4.18E-01  4.3653E+04
 3400  3.23E-12  1.61E-13  1.04E-13  4.240E+01  4.18E-01  4.3653E+04
 3600  2.65E-12  1.23E-13  8.03E-14  4.240E+01  4.18E-01  4.3653E+04
 3800  2.14E-12  8.98E-14  5.97E-14  4.240E+01  4.18E-01  4.3653E+04
 4000  1.79E-12  6.62E-14  4.77E-14  4.240E+01  4.18E-01  4.3653E+04

  NS =  128 NO. FOURIER MODES =  263 FTOLV =  1.000E-12 NITER =  20000
  PROCESSOR COUNT - RADIAL:    2

  ITER    FSQR      FSQZ      FSQL    RAX(v=0)    DELT       WMHD

    1  5.61E-01  1.11E-01  4.43E-06  4.240E+01  1.00E+00  4.3653E+04
  200  4.86E-04  1.11E-04  2.94E-08  4.240E+01  3.24E-01  4.3653E+04
  400  2.50E-07  4.27E-08  1.59E-10  4.240E+01  3.24E-01  4.3653E+04
  600  2.27E-08  4.06E-09  5.38E-11  4.240E+01  3.24E-01  4.3653E+04
  800  6.19E-09  1.28E-09  2.11E-11  4.240E+01  3.24E-01  4.3653E+04
 1000  2.71E-09  4.99E-10  8.95E-12  4.240E+01  3.24E-01  4.3653E+04
 1200  1.60E-09  3.22E-10  4.16E-12  4.240E+01  3.24E-01  4.3653E+04
 1400  8.91E-10  1.66E-10  2.42E-12  4.240E+01  3.24E-01  4.3653E+04
 1600  5.48E-10  9.80E-11  1.64E-12  4.240E+01  3.24E-01  4.3653E+04
 1800  3.54E-10  5.78E-11  1.07E-12  4.240E+01  3.24E-01  4.3653E+04
 2000  2.27E-10  4.25E-11  7.04E-13  4.240E+01  3.24E-01  4.3653E+04
 2200  1.62E-10  2.86E-11  5.03E-13  4.240E+01  3.24E-01  4.3653E+04
 2400  1.04E-10  1.78E-11  3.87E-13  4.240E+01  3.24E-01  4.3653E+04
 2600  8.01E-11  1.43E-11  3.13E-13  4.240E+01  3.24E-01  4.3653E+04
 2800  5.80E-11  9.77E-12  2.65E-13  4.240E+01  3.24E-01  4.3653E+04
 3000  4.35E-11  6.91E-12  2.21E-13  4.240E+01  3.24E-01  4.3653E+04
 3200  3.15E-11  5.28E-12  1.82E-13  4.240E+01  3.24E-01  4.3653E+04
 3400  2.30E-11  3.89E-12  1.53E-13  4.240E+01  3.24E-01  4.3653E+04
 3600  1.85E-11  2.85E-12  1.33E-13  4.240E+01  3.24E-01  4.3653E+04
 3800  1.47E-11  2.21E-12  1.14E-13  4.240E+01  3.24E-01  4.3653E+04
 4000  1.16E-11  1.71E-12  9.91E-14  4.240E+01  3.24E-01  4.3653E+04
 4200  8.87E-12  1.26E-12  8.70E-14  4.240E+01  3.24E-01  4.3653E+04
 4400  6.56E-12  9.42E-13  7.51E-14  4.240E+01  3.24E-01  4.3653E+04
 4600  5.61E-12  6.99E-13  6.54E-14  4.240E+01  3.24E-01  4.3653E+04
 4800  4.18E-12  4.83E-13  5.78E-14  4.240E+01  3.24E-01  4.3653E+04
 5000  3.58E-12  3.82E-13  5.12E-14  4.240E+01  3.24E-01  4.3653E+04
 5200  3.08E-12  3.02E-13  4.54E-14  4.240E+01  3.24E-01  4.3653E+04
 5400  2.51E-12  2.27E-13  4.05E-14  4.240E+01  3.24E-01  4.3653E+04
 5600  2.18E-12  1.75E-13  3.68E-14  4.240E+01  3.24E-01  4.3653E+04
 5800  1.97E-12  1.41E-13  3.34E-14  4.240E+01  3.24E-01  4.3653E+04
 6000  1.75E-12  1.09E-13  3.05E-14  4.240E+01  3.24E-01  4.3653E+04
 6200  1.61E-12  9.43E-14  2.80E-14  4.240E+01  3.24E-01  4.3653E+04
 6400  1.48E-12  7.83E-14  2.57E-14  4.240E+01  3.24E-01  4.3653E+04
 6600  1.39E-12  6.74E-14  2.37E-14  4.240E+01  3.24E-01  4.3653E+04
 6800  1.31E-12  6.04E-14  2.18E-14  4.240E+01  3.24E-01  4.3653E+04
 7000  1.24E-12  5.43E-14  2.01E-14  4.240E+01  3.24E-01  4.3653E+04
 7200  1.18E-12  4.93E-14  1.86E-14  4.240E+01  3.24E-01  4.3653E+04
 7400  1.13E-12  4.52E-14  1.72E-14  4.240E+01  3.24E-01  4.3653E+04
 7600  1.08E-12  4.20E-14  1.59E-14  4.240E+01  3.24E-01  4.3653E+04
 7800  1.04E-12  3.93E-14  1.48E-14  4.240E+01  3.24E-01  4.3653E+04
 8000  1.00E-12  3.69E-14  1.38E-14  4.240E+01  3.24E-01  4.3653E+04
 8020  1.00E-12  3.64E-14  1.34E-14  4.240E+01  3.24E-01  4.3653E+04

 EXECUTION TERMINATED NORMALLY

 FILE : knosos_opt0
 NUMBER OF JACOBIAN RESETS =    9

    TOTAL COMPUTATIONAL TIME (SEC)       475.45
    TIME TO INPUT/OUTPUT                   0.83
       READ IN DATA                        0.00
       WRITE OUT DATA TO WOUT              0.83
    TIME IN FUNCT3D                      471.83
       BCOVAR FIELDS                      51.85
       FOURIER TRANSFORM                 119.00
       INVERSE FOURIER TRANSFORM         121.84
       FORCES AND SYMMETRIZE              54.42
       RESIDUE                            46.43
       EQFORCE                             0.00
 -------------------------  PARAVMEC CALCULATION DONE  -----------------------
     ASPECT RATIO:   19.085
             BETA:    0.023  (total)
                      0.343  (poloidal)
                      0.024  (toroidal)
  TORIDAL CURRENT:   -0.358654078658E-08
     TORIDAL FLUX:   64.220
           VOLUME:  *******
     MAJOR RADIUS:   39.560
     MINOR RADIUS:    2.073
       AXIS FIELD:    8.070
    STORED ENERGY:    0.120370049624E+10
 ---------------------------  BOOZER TRANSFORMATION  -------------------------
  0 <= mboz <=   77    -64 <= nboz <=   64
  nu_boz =   314 nv_boz =   258

             OUTBOARD (u=0)              JS          INBOARD (u=pi)
-----------------------------------------------------------------------------
  v     |B|vmec    |B|booz    Error             |B|vmec    |B|booz    Error

  0    8.052E+00  8.052E+00  3.596E-14    9    8.147E+00  8.147E+00  1.581E-13
 pi    3.582E+00  3.582E+00  1.319E-13         3.540E+00  3.540E+00  6.117E-12
  0    8.051E+00  8.051E+00  4.697E-13   10    8.153E+00  8.153E+00  3.377E-14
 pi    3.589E+00  3.589E+00  1.033E-13         3.544E+00  3.544E+00  6.124E-12
  0    8.051E+00  8.051E+00  1.346E-12   11    8.158E+00  8.158E+00  2.517E-13
 pi    3.595E+00  3.595E+00  9.585E-14         3.548E+00  3.548E+00  6.184E-12
  0    8.047E+00  8.047E+00  4.112E-10   29    8.232E+00  8.232E+00  3.296E-09
 pi    3.685E+00  3.685E+00  1.416E-13         3.611E+00  3.611E+00  3.185E-11
  0    8.047E+00  8.047E+00  2.547E-09   30    8.235E+00  8.235E+00  4.089E-09
 pi    3.688E+00  3.688E+00  1.992E-13         3.613E+00  3.613E+00  3.254E-11
  0    8.047E+00  8.047E+00  6.092E-09   31    8.238E+00  8.238E+00  4.253E-09
 pi    3.691E+00  3.691E+00  2.754E-13         3.615E+00  3.615E+00  3.292E-11
  0    8.050E+00  8.050E+00  2.521E-08   49    8.296E+00  8.296E+00  2.113E-08
 pi    3.736E+00  3.736E+00  1.628E-12         3.646E+00  3.646E+00  6.555E-12
  0    8.050E+00  8.050E+00  3.863E-08   50    8.299E+00  8.299E+00  1.855E-08
 pi    3.738E+00  3.738E+00  1.581E-12         3.648E+00  3.648E+00  4.856E-12
  0    8.050E+00  8.050E+00  4.954E-08   51    8.302E+00  8.302E+00  1.394E-08
 pi    3.740E+00  3.740E+00  1.543E-12         3.650E+00  3.650E+00  3.199E-12
 ---------------------------    KNOSOS CALCULATION     -------------------------
 -- Intialized
 -- B_FIELD
 -- CALC_DATABASE
At line 272 of file fast_ion_confinement.f90
Fortran runtime error: Index '10' of dimension 1 of array 'vs' above upper bound of 1

Error termination. Backtrace:

Could not print backtrace: executable file is not an executable
#0  0x13a271395
#1  0x13a271c61
#2  0x13a27215c
#3  0x10e315401
#4  0x10e31c1ba
#5  0x10e3096db
#6  0x10de371f4
#7  0x10de2e415
#8  0x10dddde0d
#9  0x10de1f04f
#10  0x10de18178
#11  0x10e6afcfe
--------------------------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:

  Process name: [[17878,1],0]
  Exit code:    2
--------------------------------------------------------------------------
joseluisvelasco commented 1 year ago

Hi, sorry for taking so long to answer. It did work for me (no seg fault, correct output), but I may have done sth differently. I'll check as soon as I'm back from vacation.

lazersos commented 1 year ago

@joseluisvelasco The issue arrises due to a dimension check so make sure when you compile you have the flag -fcheck=all,no-array-temps or the equivalent for non-GNU compilers.

lazersos commented 1 year ago

So I verified that if I compile KNOSOS without the -fcheck=all,no-array-temps flag then the code runs.