Skip to content

Commit 36e5578

Browse files
authored
TokaMaker: Add experimental support for voltage coils (OpenFUSIONToolkit#212)
- Add support for coils with specified voltage instead of current - Add example of voltage coils for HBT-EP - Add tests for voltage coils - Fix inconsistent units for source in `vac_solve()` (now [A/m^2]) - Add documentation throughout the code - Add helper functions for creating local lin_alg objects (eg. `create_local_stitch`) - Add coil vector<->dict conversion functions - Improve handling of coils with non-uniform current distributions
1 parent 19ce7ac commit 36e5578

File tree

11 files changed

+2141
-395
lines changed

11 files changed

+2141
-395
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Daniel Burgess (@d-burg)\
7878
Samuel Freiberger (@samuel-frei)\
7979
Sophia Guizzo (@sguizzo)\
8080
Chris Hansen (@hansec)\
81+
Joseph Jerkins (@DeIonizedPlasma)\
8182
Julia Kirby (@juliagoestoikea)\
8283
John Lhota (@john4255)\
8384
Francois Logak\

src/docs/doc_tokamaker_main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ new meshes, see \ref doc_gs_main_mesh_ex.
4646

4747
### Other workflows/examples
4848
- \subpage doc_tMaker_ITER_ex5
49+
- \subpage doc_tMaker_HBT_ex3
4950

5051
\section doc_gs_main_mesh Building meshes using gs_Domain
5152
TokaMaker includes built-in meshing functionality through the \ref OpenFUSIONToolkit.TokaMaker.meshing.gs_Domain "gs_Domain" class,

src/examples/TokaMaker/HBT/HBT_vac_coils.ipynb

Lines changed: 820 additions & 0 deletions
Large diffs are not rendered by default.

src/examples/TokaMaker/test_examples.sh.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ run_test CUTE CUTE_VDE_ex.ipynb
3131
# HBT cases
3232
run_test HBT HBT_mesh_ex.ipynb
3333
run_test HBT HBT_eq_ex.ipynb
34+
run_test HBT HBT_vac_coils.ipynb
3435

3536
# ITER cases
3637
run_test ITER ITER_mesh_ex.ipynb

src/lin_alg/lin_alg_utils.F90

Lines changed: 133 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ MODULE oft_la_utils
7979
!> Real implementation for \ref create_vector
8080
!---------------------------------------------------------------------------------
8181
SUBROUTINE create_vector_real(vec,stitch_info,maps,native)
82-
CLASS(oft_vector), POINTER, INTENT(inout) :: vec
83-
TYPE(seam_list), INTENT(inout) :: stitch_info(:)
84-
TYPE(map_list), INTENT(inout) :: maps(:)
85-
LOGICAL, OPTIONAL, INTENT(in) :: native
82+
CLASS(oft_vector), POINTER, INTENT(inout) :: vec !< Resulting vector
83+
TYPE(seam_list), INTENT(inout) :: stitch_info(:) !< Array of seam structures
84+
TYPE(map_list), INTENT(inout) :: maps(:) !< Mapping from sub-vectors into full vector
85+
LOGICAL, OPTIONAL, INTENT(in) :: native !< Force native representation?
8686
!---
8787
LOGICAL :: force_native
8888
INTEGER(i4) :: i,offset,soffset,nblocks
@@ -210,10 +210,10 @@ END SUBROUTINE create_vector_real
210210
!> Complex implementation for \ref create_vector
211211
!---------------------------------------------------------------------------------
212212
SUBROUTINE create_vector_comp(vec,stitch_info,maps,native)
213-
CLASS(oft_cvector), POINTER, INTENT(inout) :: vec
214-
TYPE(seam_list), INTENT(inout) :: stitch_info(:)
215-
TYPE(map_list), INTENT(inout) :: maps(:)
216-
LOGICAL, OPTIONAL, INTENT(in) :: native
213+
CLASS(oft_cvector), POINTER, INTENT(inout) :: vec !< Resulting vector
214+
TYPE(seam_list), INTENT(inout) :: stitch_info(:) !< Array of seam structures
215+
TYPE(map_list), INTENT(inout) :: maps(:) !< Mapping from sub-vectors into full vector
216+
LOGICAL, OPTIONAL, INTENT(in) :: native !< Force native representation?
217217
!---
218218
LOGICAL :: force_native
219219
INTEGER(i4) :: i,offset,soffset,nblocks
@@ -402,10 +402,10 @@ END SUBROUTINE condense_stitch
402402
!> Real implementation for \ref create_matrix
403403
!---------------------------------------------------------------------------------
404404
SUBROUTINE create_matrix_real(mat,ingraphs,row_vec,col_vec,native)
405-
CLASS(oft_matrix), POINTER, INTENT(inout) :: mat
406-
TYPE(oft_graph_ptr), INTENT(in) :: ingraphs(:,:)
407-
CLASS(oft_vector), POINTER, INTENT(in) :: row_vec
408-
CLASS(oft_vector), POINTER, INTENT(in) :: col_vec
405+
CLASS(oft_matrix), POINTER, INTENT(inout) :: mat !< Resulting matrix
406+
TYPE(oft_graph_ptr), INTENT(in) :: ingraphs(:,:) !< Array of graphs representing matix blocks
407+
CLASS(oft_vector), POINTER, INTENT(in) :: row_vec !< Vector representing matrix rows
408+
CLASS(oft_vector), POINTER, INTENT(in) :: col_vec !< Vector representing matrix columns
409409
LOGICAL, OPTIONAL, INTENT(in) :: native
410410
LOGICAL :: force_native
411411
INTEGER(i4) :: i,j,ni,nj,offset,soffset
@@ -570,10 +570,10 @@ END SUBROUTINE create_matrix_real
570570
!> Real implementation for \ref create_matrix
571571
!---------------------------------------------------------------------------------
572572
SUBROUTINE create_matrix_comp(mat,ingraphs,row_vec,col_vec,native)
573-
CLASS(oft_cmatrix), POINTER, INTENT(inout) :: mat
574-
TYPE(oft_graph_ptr), INTENT(in) :: ingraphs(:,:)
575-
CLASS(oft_cvector), POINTER, INTENT(in) :: row_vec
576-
CLASS(oft_cvector), POINTER, INTENT(in) :: col_vec
573+
CLASS(oft_cmatrix), POINTER, INTENT(inout) :: mat !< Resulting matrix
574+
TYPE(oft_graph_ptr), INTENT(in) :: ingraphs(:,:) !< Array of graphs representing matix blocks
575+
CLASS(oft_cvector), POINTER, INTENT(in) :: row_vec !< Vector representing matrix rows
576+
CLASS(oft_cvector), POINTER, INTENT(in) :: col_vec !< Vector representing matrix columns
577577
LOGICAL, OPTIONAL, INTENT(in) :: native
578578
LOGICAL :: force_native
579579
INTEGER(i4) :: i,j,ni,nj,offset,soffset
@@ -701,13 +701,13 @@ SUBROUTINE setup_native(this)
701701
END SUBROUTINE setup_native
702702
END SUBROUTINE create_matrix_comp
703703
!---------------------------------------------------------------------------------
704-
!> Needs Docs
704+
!> Remove redundant column indices from a CSR graph
705705
!---------------------------------------------------------------------------------
706706
SUBROUTINE csr_remove_redundant(nr,kr,nnz,lc)
707-
INTEGER(4), INTENT(in) :: nr
708-
INTEGER(4), INTENT(inout) :: kr(nr+1)
709-
INTEGER(4), INTENT(inout) :: nnz
710-
INTEGER(4), POINTER, INTENT(inout) :: lc(:)
707+
INTEGER(4), INTENT(in) :: nr !< Number of rows
708+
INTEGER(4), INTENT(inout) :: kr(nr+1) !< Row pointer
709+
INTEGER(4), INTENT(inout) :: nnz !< Number of non-zero entries
710+
INTEGER(4), POINTER, INTENT(inout) :: lc(:) !< Column indices
711711
INTEGER(4) :: i,j,nremove,js
712712
INTEGER(4), POINTER :: lctmp(:)
713713
nremove=0
@@ -970,9 +970,9 @@ end subroutine graph_add_full_col
970970
!> Real implementation for \ref combine_matrices
971971
!---------------------------------------------------------------------------------
972972
SUBROUTINE combine_matrices_real(mats,nr,nc,mat)
973-
TYPE(oft_matrix_ptr), INTENT(in) :: mats(:,:)
974-
INTEGER(i4), INTENT(in) :: nr
975-
INTEGER(i4), INTENT(in) :: nc
973+
TYPE(oft_matrix_ptr), INTENT(in) :: mats(:,:) !< Array of sub-matrices to combine
974+
INTEGER(i4), INTENT(in) :: nr !< Number of row sub-matrices
975+
INTEGER(i4), INTENT(in) :: nc !< Number of column sub-matrices
976976
CLASS(oft_matrix), POINTER, INTENT(inout) :: mat
977977
DEBUG_STACK_PUSH
978978
SELECT TYPE(this=>mat)
@@ -1145,9 +1145,9 @@ END SUBROUTINE combine_matrices_real
11451145
!> Real implementation for \ref combine_matrices
11461146
!---------------------------------------------------------------------------------
11471147
SUBROUTINE combine_matrices_comp(mats,nr,nc,mat)
1148-
TYPE(oft_cmatrix_ptr), INTENT(in) :: mats(:,:)
1149-
INTEGER(i4), INTENT(in) :: nr
1150-
INTEGER(i4), INTENT(in) :: nc
1148+
TYPE(oft_cmatrix_ptr), INTENT(in) :: mats(:,:) !< Array of matrices representing sub-matrices
1149+
INTEGER(i4), INTENT(in) :: nr !< Number of row sub-matrices
1150+
INTEGER(i4), INTENT(in) :: nc !< Number of column sub-matrices
11511151
CLASS(oft_cmatrix), POINTER, INTENT(inout) :: mat
11521152
DEBUG_STACK_PUSH
11531153
SELECT TYPE(this=>mat)
@@ -1203,4 +1203,110 @@ SUBROUTINE create_identity_graph(outgraph,vec)
12031203
outgraph%lc=[(i,i=1,outgraph%nr)]
12041204
DEBUG_STACK_POP
12051205
END SUBROUTINE create_identity_graph
1206+
!------------------------------------------------------------------------------
1207+
!> Create a tri-diagonal graph for a given vector
1208+
!------------------------------------------------------------------------------
1209+
SUBROUTINE create_tridiag_graph(outgraph,vec,periodic)
1210+
TYPE(oft_graph), POINTER, INTENT(inout) :: outgraph !< Resulting graph
1211+
CLASS(oft_vector), POINTER, INTENT(in) :: vec !< Vector representing matrix rows/columns
1212+
LOGICAL, INTENT(in) :: periodic !< Apply periodic BCs?
1213+
INTEGER(i4) :: i
1214+
DEBUG_STACK_PUSH
1215+
IF(vec%n<3)CALL oft_abort('Vector size must be at least 3 for tridiagonal graph', &
1216+
'create_tridiag_graph',__FILE__)
1217+
!---Setup graph
1218+
ALLOCATE(outgraph)
1219+
IF(periodic)THEN
1220+
outgraph%nnz=3*vec%n
1221+
ELSE
1222+
outgraph%nnz=3*vec%n-2
1223+
END IF
1224+
outgraph%nr=vec%n
1225+
outgraph%nrg=vec%ng
1226+
outgraph%nc=vec%n
1227+
outgraph%ncg=vec%ng
1228+
!---Create indexing
1229+
ALLOCATE(outgraph%kr(outgraph%nr+1))
1230+
ALLOCATE(outgraph%lc(outgraph%nnz))
1231+
outgraph%kr(1)=1
1232+
IF(periodic)THEN
1233+
outgraph%lc(1:3)=[1,2,vec%n]
1234+
outgraph%kr(2)=4
1235+
ELSE
1236+
outgraph%lc(1:2)=[1,2]
1237+
outgraph%kr(2)=3
1238+
END IF
1239+
DO i=2,vec%n-1
1240+
outgraph%lc(outgraph%kr(i):outgraph%kr(i)+2)=[i-1,i,i+1]
1241+
outgraph%kr(i+1)=outgraph%kr(i)+3
1242+
END DO
1243+
IF(periodic)THEN
1244+
outgraph%lc(outgraph%nnz-2:outgraph%nnz)=[1,vec%n-1,vec%n]
1245+
ELSE
1246+
outgraph%lc(outgraph%nnz-1:outgraph%nnz)=[vec%n-1,vec%n]
1247+
END IF
1248+
outgraph%kr(vec%n+1)=outgraph%nnz+1
1249+
DEBUG_STACK_POP
1250+
END SUBROUTINE create_tridiag_graph
1251+
!------------------------------------------------------------------------------
1252+
!> Create a dense graph for a given vector
1253+
!------------------------------------------------------------------------------
1254+
SUBROUTINE create_dense_graph(outgraph,rvec,cvec)
1255+
TYPE(oft_graph), POINTER, INTENT(inout) :: outgraph !< Resulting graph
1256+
CLASS(oft_vector), POINTER, INTENT(in) :: rvec !< Vector representing matrix rows
1257+
CLASS(oft_vector), POINTER, OPTIONAL, INTENT(in) :: cvec !< Vector representing matrix columns (optional)
1258+
INTEGER(i4) :: i,j
1259+
CLASS(oft_vector), POINTER :: vec2
1260+
DEBUG_STACK_PUSH
1261+
IF(PRESENT(cvec))THEN
1262+
vec2=>cvec
1263+
ELSE
1264+
vec2=>rvec
1265+
END IF
1266+
!---Setup graph
1267+
ALLOCATE(outgraph)
1268+
outgraph%nnz=rvec%n*vec2%n
1269+
outgraph%nr=rvec%n
1270+
outgraph%nrg=rvec%ng
1271+
outgraph%nc=vec2%n
1272+
outgraph%ncg=vec2%ng
1273+
!---Create indexing
1274+
ALLOCATE(outgraph%kr(outgraph%nr+1))
1275+
ALLOCATE(outgraph%lc(outgraph%nnz))
1276+
outgraph%kr(1)=1
1277+
DO i=1,rvec%n
1278+
outgraph%kr(i+1)=outgraph%kr(i)+vec2%n
1279+
outgraph%lc(outgraph%kr(i):outgraph%kr(i+1)-1)=[(j,j=1,vec2%n)]
1280+
END DO
1281+
DEBUG_STACK_POP
1282+
END SUBROUTINE create_dense_graph
1283+
!------------------------------------------------------------------------------
1284+
!> Create stitch and map structures for local vector
1285+
!------------------------------------------------------------------------------
1286+
SUBROUTINE create_local_stitch(stitch,map,n)
1287+
TYPE(oft_seam), INTENT(out) :: stitch !< Stitching object
1288+
TYPE(oft_map), INTENT(inout) :: map !< Map object
1289+
INTEGER(i4), INTENT(in) :: n !< Size of local vector
1290+
INTEGER(i4) :: i
1291+
DEBUG_STACK_PUSH
1292+
!---Setup stitching object
1293+
stitch%nproc_con=0
1294+
ALLOCATE(stitch%be(n),stitch%kle(0:stitch%nproc_con+1))
1295+
stitch%full=.TRUE.
1296+
stitch%nbe=0
1297+
stitch%be=.FALSE.
1298+
stitch%kle=0
1299+
!---Setup map
1300+
map%per=.FALSE.
1301+
map%offset=0
1302+
map%n=n
1303+
map%ng=n
1304+
map%nslice=n
1305+
ALLOCATE(map%slice(map%nslice))
1306+
map%slice=[(i,i=1,n)]
1307+
ALLOCATE(map%lge(map%n))
1308+
map%lge=[(i,i=1,n)]
1309+
map%gbe=>stitch%be
1310+
DEBUG_STACK_POP
1311+
END SUBROUTINE create_local_stitch
12061312
END MODULE oft_la_utils

0 commit comments

Comments
 (0)