ORNL-Fusion / PARVMEC

3D Equilibrium Solver
MIT License
13 stars 2 forks source link

FIX: Restarting from old VMEC runs #62

Open lazersos opened 1 day ago

lazersos commented 1 day ago

Currently the code crashes if you attempt to run with the reset feature:

mpirun -np 2 ~/bin/xvmec2000 input.test reset=wout_old_run.nc

However if you run with only one processor the restart feature works:

mpirun -np 1 ~/bin/xvmec2000 input.test reset=wout_old_run.nc

The issues stems from the routine Sources/Initialization_Cleanup/load_xc_from_wout.f. Specifically the code references sm and sp but these arrays are only defined over the communicator (from profile1d.f):


      nsmin = MAX(2, t1lglob)
      nsmax = t1rglob
      DO i = nsmin, nsmax
         sm(i) = pshalf(1,i)/psqrts(1,i)
         IF (i .LT. ns) THEN
            sp(i) = pshalf(1,i + 1)/psqrts(1,i)
         ELSE
            sp(i)=one/psqrts(1,i)
         END IF
      END DO

The fix seems to be to just recalculate sm and sp over the whole ns array in the load_xc_from_wout.f routine, like:

!
!     CONVERT lambda TO INTERNAL FULL MESH REPRESENTATION
!
!     START ITERATION AT JS=1
!     SM AND SP ARRAYS NEED TO BE MADE LOCALY SO THEY EXIST OVER THE 
!     WHOLE DOMAIN
!
      ALLOCATE(sm_local(ns),sp_local(0:ns)) ! See allocate_ns

      DO js = 2, ns
         t1 = hs*ABS(js-1.5_rprec)
         t2 = hs*ABS(js-2.5_rprec)
         sm_local(js) = SQRT(t1)/SQRT(hs*ABS(js-1))
         sp_local(js) = SQRT(t2)/SQRT(hs*ABS(js-1))
      END DO

      sm_local(1) = zero
      sp_local(0) = zero
      sp_local(1) = sm_local(2)

      lmn(1,:,0,:) = lmn(2,:,0,:)
      lmn(1,:,1,:) = 2*lmn(2,:,1,:)/(sm_local(2) + sp_local(1))
      lmn(1,:,2:,:) = 0

      DO m = 0, mpol1, 2
         DO js = 2, ns
            lmn(js,:,m,:) = 2*lmn(js,:,m,:) - lmn(js-1,:,m,:)
         END DO
      END DO

      DO m = 1, mpol1, 2
         DO js = 2, ns
            lmn(js,:,m,:) = (2*lmn(js,:,m,:) 
     1                    - sp_local(js-1)*lmn(js-1,:,m,:))/sm_local(js)
         END DO
      END DO

      DO js = 2, ns
         lmn(js,:,:,:) = phipf(js)*lmn(js,:,:,:)
      END DO

      DEALLOCATE(sm_local,sp_local)

There may be a more elegant fix but this seems to work.

cianciosa commented 1 day ago

I have fix in

https://github.com/ORNL-Fusion/PARVMEC/pull/63

cianciosa commented 1 day ago

Fix merged with master as of pull request https://github.com/ORNL-Fusion/PARVMEC/pull/64