Skip to content

Commit 0bd44b1

Browse files
authored
ThinCurr: Include Vcoil currents in time-domain jumpers.hist file (OpenFUSIONToolkit#245)
- Fix indexing bug in Vcoil restart data
1 parent b19540a commit 0bd44b1

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

src/physics/thin_wall.F90

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ SUBROUTINE tw_setup(self,hole_ns)
202202
CALL xml_get_element(self%xml,"vcoils",coil_element,error_flag)
203203
IF(error_flag==0)THEN
204204
WRITE(*,'(2A)')oft_indent,'Loading V(t) driver coils'
205-
CALL tw_load_coils(coil_element,self%n_vcoils,self%vcoils)
205+
CALL tw_load_coils(coil_element,'VCOIL',self%n_vcoils,self%vcoils)
206206
ELSE
207207
WRITE(*,'(2A)')oft_indent,'No V(t) driver coils found'
208208
END IF
@@ -215,7 +215,7 @@ SUBROUTINE tw_setup(self,hole_ns)
215215
CALL xml_get_element(self%xml,"icoils",coil_element,error_flag)
216216
IF(error_flag==0)THEN
217217
WRITE(*,'(2A)')oft_indent,'Loading I(t) driver coils'
218-
CALL tw_load_coils(coil_element,self%n_icoils,self%icoils)
218+
CALL tw_load_coils(coil_element,'ICOIL',self%n_icoils,self%icoils)
219219
ELSE
220220
WRITE(*,'(2A)')oft_indent,'No I(t) driver coils found'
221221
END IF
@@ -2375,8 +2375,9 @@ END SUBROUTINE tw_setup_hole
23752375
!------------------------------------------------------------------------------
23762376
!> Read coil sets for "oft_in.xml" file
23772377
!------------------------------------------------------------------------------
2378-
subroutine tw_load_coils(group_node,ncoils,coils)
2378+
subroutine tw_load_coils(group_node,name_prefix,ncoils,coils)
23792379
TYPE(xml_node), POINTER, INTENT(IN) :: group_node !< XML node relative to base `<thincurr>` node
2380+
CHARACTER(LEN=5), INTENT(IN) :: name_prefix !< Prefix for coil set names (e.g. "icoil" or "vcoil")
23802381
INTEGER(4), INTENT(out) :: ncoils !< Number of coil sets found
23812382
TYPE(tw_coil_set), POINTER, INTENT(out) :: coils(:) !< List of coil sets
23822383
!---XML solver fields
@@ -2418,7 +2419,7 @@ subroutine tw_load_coils(group_node,ncoils,coils)
24182419
IF(xml_hasAttribute(coil_set,"name"))THEN
24192420
CALL xml_extractDataAttribute(coil_set,"name",coil_tmp%name,num=nread,iostat=ierr)
24202421
ELSE
2421-
WRITE(coil_tmp%name,'(A8,I5.5)')'UNKNOWN_',i
2422+
WRITE(coil_tmp%name,'(A5,A1,I5.5)')name_prefix,'_',i
24222423
END IF
24232424
!---Get coil set resistivity per unit length (can be overriden)
24242425
IF(xml_hasAttribute(coil_set,"res_per_len"))THEN
@@ -3147,7 +3148,7 @@ subroutine tw_rst_save(self,u,filename,path,append)
31473148
CALL hdf5_write(rst_info,filename,path)
31483149
IF(self%n_vcoils>0)THEN
31493150
allocate(pcoil_vals(self%n_vcoils))
3150-
pcoil_vals=outvec%v(self%np_active+self%nholes:self%nelems)
3151+
pcoil_vals=outvec%v(self%np_active+self%nholes+1:self%nelems)
31513152
CALL hdf5_write(pcoil_vals,filename,path//"_Vcoils")
31523153
deallocate(pcoil_vals)
31533154
END IF

src/physics/thin_wall_solvers.F90

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,8 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
807807
CALL floop_hist%write(data_r8=senout)
808808
END IF
809809
END IF
810-
IF(sensors%njumpers+self%nholes>0)THEN
811-
ALLOCATE(jumpout(sensors%njumpers+self%nholes+1))
810+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
811+
ALLOCATE(jumpout(sensors%njumpers+self%nholes+self%n_vcoils+1))
812812
DO j=1,sensors%njumpers
813813
tmp=0.d0
814814
val_prev=0.d0
@@ -829,7 +829,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
829829
END DO
830830
jumpout(j+1)=tmp/mu0
831831
END DO
832-
DO j=1,self%nholes
832+
DO j=1,self%nholes+self%n_vcoils
833833
jumpout(sensors%njumpers+j+1)=vals(self%np_active+j)/mu0
834834
END DO
835835
!---Setup history file
@@ -844,6 +844,9 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
844844
WRITE(hole_jumper_name,'(A,I4.4)')'HOLE_',i
845845
CALL jumper_hist%add_field(hole_jumper_name, 'r8')
846846
END DO
847+
DO i=1,self%n_vcoils
848+
CALL jumper_hist%add_field(self%vcoils(i)%name, 'r8')
849+
END DO
847850
CALL jumper_hist%write_header
848851
CALL jumper_hist%open
849852
jumpout(1)=t
@@ -960,7 +963,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
960963
senout(1)=t
961964
CALL floop_hist%write(data_r8=senout)
962965
END IF
963-
IF(sensors%njumpers+self%nholes>0)THEN
966+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
964967
DO j=1,sensors%njumpers
965968
tmp=0.d0
966969
val_prev=0.d0
@@ -981,7 +984,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
981984
END DO
982985
jumpout(j+1)=tmp/mu0
983986
END DO
984-
DO j=1,self%nholes
987+
DO j=1,self%nholes+self%n_vcoils
985988
jumpout(sensors%njumpers+j+1)=vals(self%np_active+j)/mu0
986989
END DO
987990
jumpout(1)=t
@@ -996,7 +999,7 @@ SUBROUTINE run_td_sim(self,dt,nsteps,vec,direct,lin_tols,use_cn,nstatus,nplot,se
996999
CALL floop_hist%close
9971000
DEALLOCATE(senout)
9981001
END IF
999-
IF(sensors%njumpers+self%nholes>0)THEN
1002+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
10001003
CALL jumper_hist%close
10011004
DEALLOCATE(jumpout)
10021005
END IF
@@ -1061,8 +1064,8 @@ SUBROUTINE plot_td_sim(self,nsteps,nplot,sensors,compute_B,rebuild_sensors,senso
10611064
CALL floop_hist%open
10621065
END IF
10631066
END IF
1064-
IF(sensors%njumpers+self%nholes>0)THEN
1065-
ALLOCATE(jumpout(sensors%njumpers+self%nholes+1))
1067+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
1068+
ALLOCATE(jumpout(sensors%njumpers+self%nholes+self%n_vcoils+1))
10661069
jumpout = 0.d0
10671070
!---Setup history file
10681071
IF(oft_env%head_proc)THEN
@@ -1076,6 +1079,9 @@ SUBROUTINE plot_td_sim(self,nsteps,nplot,sensors,compute_B,rebuild_sensors,senso
10761079
WRITE(hole_jumper_name,'(A,I4.4)')'HOLE_',i
10771080
CALL jumper_hist%add_field(hole_jumper_name, 'r8')
10781081
END DO
1082+
DO i=1,self%n_vcoils
1083+
CALL jumper_hist%add_field(self%vcoils(i)%name, 'r8')
1084+
END DO
10791085
CALL jumper_hist%write_header
10801086
CALL jumper_hist%open
10811087
END IF
@@ -1163,7 +1169,7 @@ SUBROUTINE plot_td_sim(self,nsteps,nplot,sensors,compute_B,rebuild_sensors,senso
11631169
senout(1)=t
11641170
CALL floop_hist%write(data_r8=senout)
11651171
END IF
1166-
IF(sensors%njumpers+self%nholes>0)THEN
1172+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
11671173
DO j=1,sensors%njumpers
11681174
tmp=0.d0
11691175
val_prev=0.d0
@@ -1184,7 +1190,7 @@ SUBROUTINE plot_td_sim(self,nsteps,nplot,sensors,compute_B,rebuild_sensors,senso
11841190
END DO
11851191
jumpout(j+1)=tmp/mu0
11861192
END DO
1187-
DO j=1,self%nholes
1193+
DO j=1,self%nholes+self%n_vcoils
11881194
jumpout(sensors%njumpers+j+1)=vals(self%np_active+j)/mu0
11891195
END DO
11901196
jumpout(1)=t
@@ -1198,7 +1204,7 @@ SUBROUTINE plot_td_sim(self,nsteps,nplot,sensors,compute_B,rebuild_sensors,senso
11981204
CALL floop_hist%close()
11991205
DEALLOCATE(senout)
12001206
END IF
1201-
IF(sensors%njumpers+self%nholes>0)THEN
1207+
IF(sensors%njumpers+self%nholes+self%n_vcoils>0)THEN
12021208
CALL jumper_hist%close()
12031209
DEALLOCATE(jumpout)
12041210
END IF

src/tests/physics/test_ThinCurr.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ def validate_td(sigs_final, jumpers_final=None, tols=(1.E-8, 1.E-3)):
511511
except BaseException as e:
512512
print(e)
513513
return False
514-
if not len(td_sigs_final) == len(jumpers_final):
514+
for (i, val) in enumerate(td_sigs_final[1:]):
515+
print(val)
516+
if len(td_sigs_final) != len(jumpers_final):
515517
print("FAILED: Number of jumpers does not match")
516518
return False
517519
retval = True
@@ -521,6 +523,8 @@ def validate_td(sigs_final, jumpers_final=None, tols=(1.E-8, 1.E-3)):
521523
print(" Actual = {0}".format(td_sigs_final[0]))
522524
retval = False
523525
for (i, val) in enumerate(jumpers_final[1:]):
526+
if val is None:
527+
continue
524528
if abs((val-td_sigs_final[i+1])/val) > tols[1]:
525529
print("FAILED: Signal {0} incorrect!".format(i+1))
526530
print(" Expected = {0}".format(val))
@@ -646,12 +650,13 @@ def test_fr_plate(direct_flag,python):
646650
@pytest.mark.parametrize("python", (True,))
647651
def test_td_plate_volt(direct_flag,python):
648652
sigs_final = (4.E-3, 4.580643E-4, 3.854292E-4)
653+
jumpers_final = (4.E-3, 1697.895)
649654
assert ThinCurr_setup("tw_test-plate.h5",1,direct_flag,
650655
vcoils=((0.5, 0.1),),
651656
floops=((0.5, -0.05), (0.5, -0.1)),
652657
volt_waveform=((0.0, 1.0), (1.0, 1.0)),
653658
python=python)
654-
assert validate_td(sigs_final)
659+
assert validate_td(sigs_final,jumpers_final)
655660

656661
#============================================================================
657662
# Test runners for cylinder
@@ -691,7 +696,7 @@ def test_fr_cyl(direct_flag,python):
691696
@pytest.mark.parametrize("python", (True,))
692697
def test_td_cyl_volt(direct_flag,python):
693698
sigs_final = (4.E-3, 1.504279E-4, 1.276624E-4)
694-
jumpers_final = (4.E-3, 1.1203960E3, 1120.396)
699+
jumpers_final = (4.E-3, 1.1203960E3, 1120.396, 655.853, 655.850)
695700
assert ThinCurr_setup("tw_test-cyl.h5",1,direct_flag,
696701
vcoils=((1.1, 0.25), (1.1, -0.25)),
697702
floops=((0.9, 0.5), (0.9, 0.0)),
@@ -748,13 +753,14 @@ def test_fr_torus(direct_flag,python):
748753
@pytest.mark.parametrize("python", (True,))
749754
def test_td_torus_volt(direct_flag,python):
750755
sigs_final = (4.E-3, 5.653338E-5, 4.035387E-6)
756+
jumpers_final = (4.E-3, None, -597.6068, 371.74769, 371.74780)
751757
assert ThinCurr_setup("tw_test-torus.h5",1,direct_flag,
752758
vcoils=((1.5, 0.5), (1.5, -0.5)),
753759
floops=((1.4, 0.0), (0.6, 0.0)),
754760
volt_waveform=((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)),
755761
lin_tol=1.E-11,
756762
python=python)
757-
assert validate_td(sigs_final)
763+
assert validate_td(sigs_final,jumpers_final)
758764

759765
@pytest.mark.coverage
760766
@pytest.mark.parametrize("direct_flag", ('F', 'T'))
@@ -831,12 +837,13 @@ def test_fr_passive(direct_flag,python):
831837
@pytest.mark.parametrize("python", (True,))
832838
def test_td_passive_volt(direct_flag,python):
833839
sigs_final = (4.E-3, 4.379235E-4, 4.389248E-4)
840+
jumpers_final = (4.E-3, -641.4736, 1673.2893)
834841
assert ThinCurr_setup(None,1,direct_flag,eta=1.E4,
835842
vcoils=((0.5, 0.0), (0.5, 0.1)),
836843
floops=((0.5, -0.05), (0.5, -0.1)),
837844
volt_waveform=((0.0, 0.0, 1.0), (1.0, 0.0, 1.0)),
838845
python=python)
839-
assert validate_td(sigs_final)
846+
assert validate_td(sigs_final, jumpers_final)
840847

841848
#============================================================================
842849
# Test runners for large cylinder (w/ ACA+)
@@ -879,7 +886,7 @@ def test_fr_aca(python):
879886
@pytest.mark.parametrize("python", (True,))
880887
def test_td_volt_aca(python):
881888
sigs_final = (4.E-3, 1.512679E-4, 1.291681E-4)
882-
jumpers_final = (4.E-3, 1.122550E3, 1122.550)
889+
jumpers_final = (4.E-3, 1.122550E3, 1122.550, 656.9544, 656.9797)
883890
assert ThinCurr_setup("tw_test-cyl_hr.h5",1,'F',use_aca=True,
884891
vcoils=((1.1, 0.25), (1.1, -0.25)),
885892
floops=((0.9, 0.5), (0.9, 0.0)),

0 commit comments

Comments
 (0)