Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Restarting from old VMEC runs #62

Open
lazersos opened this issue Nov 27, 2024 · 2 comments
Open

FIX: Restarting from old VMEC runs #62

lazersos opened this issue Nov 27, 2024 · 2 comments

Comments

@lazersos
Copy link

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 cianciosa mentioned this issue Nov 27, 2024
@cianciosa
Copy link
Collaborator

I have fix in

#63

@cianciosa
Copy link
Collaborator

Fix merged with master as of pull request #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants