Skip to content

Commit 9a24e4f

Browse files
authored
Restructure Python CLI scripts to support bundling in Python packages (eg. PyPi) (OpenFUSIONToolkit#323)
- Remove legacy Python `print_function` bridges - Update documentation
1 parent 8579342 commit 9a24e4f

72 files changed

Lines changed: 761 additions & 1159 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,9 @@ if( OFT_BUILD_PYTHON )
489489
set(OFT_SHARED_LIBS ${ARGV0} ${OFT_SHARED_LIBS} CACHE INTERNAL "package_shared_libs")
490490
endfunction(oft_add_shared)
491491
# Library directories
492-
add_subdirectory( python/wrappers )
493492
add_subdirectory( python/OpenFUSIONToolkit )
493+
add_subdirectory( python/wrappers )
494+
add_subdirectory( python/scripts )
494495
endif()
495496

496497
########################

src/docs/ThinCurr/doc_thincurr_dep.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ mesh definition files that mark the nodes corresponding to a given hole. There a
2020
will then generate an ordered loop from this list.
2121

2222
Nodesets are stored in the `mesh/NODESET****` fields in native mesh files. These can be converted from nodesets defined via the
23-
Cubit meshing software, through the Exodus II mesh format, and `convert_cubit.py` or other mesh inputs with suitable interfacing
23+
Cubit meshing software, through the Exodus II mesh format, and `OFT_convert_cubit.py` or other mesh inputs with suitable interfacing
2424
scripts.
2525

2626
Closures can also be manually defined using "sidesets" in mesh definition files that mark the triangles where an element should be removed to
2727
avoid singularities in the system. Sidesets are stored in the `mesh/SIDESET****` fields in native mesh files. These can be
28-
converted from nodesets defined via the Cubit meshing software, through the Exodus II mesh format, and `convert_cubit.py` or other
28+
converted from nodesets defined via the Cubit meshing software, through the Exodus II mesh format, and `OFT_convert_cubit.py` or other
2929
mesh inputs with suitable interfacing scripts.

src/docs/ThinCurr/doc_thincurr_main.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ The following examples illustrate usage of ThinCurr to perform calculations usin
3636

3737
\section doc_tw_main_settings ThinCurr settings groups
3838

39-
\subsection doc_tw_main_settings_fortran Fortran option groups
40-
Driver-specific settings groups are defined for each of the programs above (eg. `thincurr_td`), follow links for description
41-
of available settings.
42-
43-
The following driver-wide settings are also available:
44-
45-
**Option group:** `thincurr_hodlr_options` (see \ref doc_tw_main_hodlr "HODLR")
46-
| Option | Description | Type [dim] |
47-
|-------------------------|---------------|------------|
48-
| `target_size=1500` | Target size for mesh partitioning | int |
49-
| `aca_min_its=20` | Minimum nuber of ACA+ iterations to perfom (if used) | int |
50-
| `L_svd_tol=-1.0` | SVD tolerance for HODLR compression of \f$ \textrm{L} \f$ matrix (negative to disable) | int |
51-
| `L_aca_rel_tol=-1.0` | ACA tolerance (relative to SVD) for HODLR compression of \f$ \textrm{L} \f$ matrix (negative to disable) | int |
52-
| `B_svd_tol=T` | SVD tolerance for HODLR compression of B reconstruction operator (negative to disable) | int |
53-
| `B_aca_rel_tol=F` | ACA tolerance (relative to SVD) for HODLR compression of B reconstruction operator (negative to disable) | int |
54-
5539
\subsection doc_tw_main_settings_xml XML input settings
5640
Settings for ThinCurr runs are contained in the `oft->thincurr` element, with the following elements:
5741
* `eta`: Comma separated values for surface resistivity (\f$ \eta_s = \eta / t \f$) in each region
@@ -74,6 +58,22 @@ Settings for ThinCurr runs are contained in the `oft->thincurr` element, with th
7458
</oft>
7559
```
7660

61+
\subsection doc_tw_main_settings_fortran Fortran option groups
62+
Driver-specific settings groups are defined for each of the programs above (eg. `thincurr_td`), follow links for description
63+
of available settings.
64+
65+
The following driver-wide settings are also available:
66+
67+
**Option group:** `thincurr_hodlr_options` (see \ref doc_tw_main_hodlr "HODLR")
68+
| Option | Description | Type [dim] |
69+
|-------------------------|---------------|------------|
70+
| `target_size=1500` | Target size for mesh partitioning | int |
71+
| `aca_min_its=20` | Minimum nuber of ACA+ iterations to perfom (if used) | int |
72+
| `L_svd_tol=-1.0` | SVD tolerance for HODLR compression of \f$ \textrm{L} \f$ matrix (negative to disable) | int |
73+
| `L_aca_rel_tol=-1.0` | ACA tolerance (relative to SVD) for HODLR compression of \f$ \textrm{L} \f$ matrix (negative to disable) | int |
74+
| `B_svd_tol=T` | SVD tolerance for HODLR compression of B reconstruction operator (negative to disable) | int |
75+
| `B_aca_rel_tol=F` | ACA tolerance (relative to SVD) for HODLR compression of B reconstruction operator (negative to disable) | int |
76+
7777

7878
\section doc_tw_main_num Description of numerics
7979
Currents in ThinCurr are represented in terms of a surface current (\f$ \textbf{J}_s = \int \textbf{J} dt_w = \textbf{J} * t_w \f$),
@@ -210,10 +210,15 @@ correct this two holes must be added, corresponding to loops in each of these tw
210210
This use of jumps and a single-valued potential to represent a multivalued potential is common practice in numerical methods.
211211

212212
\subsubsection doc_tw_main_holes_def Defining holes
213-
Holes can be defined using the `ThinCurr_compute_holes.py` script. This script analyzes the toplogy of a given
213+
Holes can be defined using the `OFT_ThinCurr_holes.py` script. This script analyzes the toplogy of a given
214214
mesh and automatically locates and defines needed hole elements. This is now the recommended way of defining holes in
215215
ThinCurr models, although \ref doc_tw_dep_leg_holes "manual definition" is also still supported.
216216

217+
The script should be available in one of two ways depending on the installation/build setup:
218+
- If OFT is installed via `pip` or similar, then it should be available via command line as `OFT_ThinCurr_holes` in any environment where OFT is also available (eg. virtual environment)
219+
- If OFT is installed any other way, including installation from source, the `OFT_ThinCurr_holes.py` script will be located in the `python` directory of the install or build folder
220+
221+
217222
\subsection doc_tw_main_close "Closure" elements
218223
As stated above the fact that the solution depends only on the gradient and not on the absolute value of \f$ \phi \f$ itself can
219224
introduce a gauge ambiguity, resulting in redundant degrees of freedom. In the cases considered above this is resolved by keeping
@@ -223,7 +228,7 @@ potential to zero at that point. We call these elements "closure" elements as th
223228
solveable.
224229

225230
\subsubsection doc_tw_main_close_def Defining closures
226-
As with holes, closures can also be defined using the `ThinCurr_compute_holes.py` script. This is now the recommended way of defining
231+
As with holes, closures can also be defined using the `OFT_ThinCurr_holes.py` script. This is now the recommended way of defining
227232
closures in ThinCurr models, although \ref doc_tw_dep_leg_holes "manual definition" is also still supported.
228233

229234
\subsection doc_tw_main_hodlr Hierarchical Off-Diagonal Low-Rank (HODLR) approximation

src/docs/ThinCurr/thincurr_example1.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ During the run you will see it report a bunch of general information and then it
1515

1616
# Post processing
1717

18-
Once complete you can now generate XDMF files suitable for visualization of results using the [VisIt](https://visit-dav.github.io/visit-website/index.html) code. This is a two step process. First, rerun the code as above but with `plot_run=T` in the `thincurr_eig_options` group. Once complete, you need to run the `build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
18+
Once complete you can now generate XDMF files suitable for visualization of results using the [VisIt](https://visit-dav.github.io/visit-website/index.html) code. This is a two step process. First, rerun the code as above but with `plot_run=T` in the `thincurr_eig_options` group. Once complete, you need to run the `OFT_build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
1919

20-
python /path/to/oft/bin/build_xdmf.py
20+
python /path/to/oft/bin/OFT_build_xdmf.py
2121

2222
Next use VisIt to open the `surf_static.xmf` file, which will contain a series of vector fields named as `J_XX` that correspond to the current distributions of the various eigenstates. If you are running this example remotely and using VisIt locally you will need to copy the `mesh.*.h5`, `scalar_dump.*.h5`, `vector_dump.*.h5`, and `*.xmf` files to your local computer for visualization. The first eigenmode `J_01` should look like the figure below.
2323

@@ -88,8 +88,8 @@ set large exodus file on
8888
export Genesis "thincurr_ex-plate.g" overwrite block 1
8989
```
9090

91-
The file can then be converted to OFT's native mesh format using the `convert_cubit.py` script as
91+
The file can then be converted to OFT's native mesh format using the `OFT_convert_cubit.py` script as
9292

93-
python /path/to/OFT/bin/convert_cubit.py --in_file=thincurr_ex-plate.g
93+
python /path/to/OFT/bin/OFT_convert_cubit.py --in_file=thincurr_ex-plate.g
9494

9595
which will yield the converted file `thincurr_ex-plate.h5`.

src/docs/ThinCurr/thincurr_example2.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Contents of the input files are provided below and in the examples directory und
2121

2222
# Post processing
2323

24-
Once complete you can now generate VisIt files to visualize the solution as above. First, rerun the code as above but with "plot_run=T" in the `thincurr_td_options` group. Once complete, you need to run the `build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
24+
Once complete you can now generate VisIt files to visualize the solution as above. First, rerun the code as above but with "plot_run=T" in the `thincurr_td_options` group. Once complete, you need to run the `OFT_build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
2525

26-
python /path/to/oft/bin/build_xdmf.py
26+
python /path/to/oft/bin/OFT_build_xdmf.py
2727

2828
Next use VisIt to open the `surf_out_XXXX.xmf` database, which will contain a series timepoints with the vector field `J`. If you are running this example remotely and using VisIt locally you will need to copy the `mesh.*.h5`, `scalar_dump.*.h5`, `vector_dump.*.h5`, and `*.xmf` files to your local computer for visualization. The solution `J` at the first time point should look like the figure below.
2929

@@ -114,8 +114,8 @@ set large exodus file on
114114
export Genesis "thincurr_ex-cyl.g" overwrite block 1
115115
```
116116

117-
The file can then be converted to OFT's native mesh format using the `convert_cubit.py` script as
117+
The file can then be converted to OFT's native mesh format using the `OFT_convert_cubit.py` script as
118118

119-
python /path/to/OFT/bin/convert_cubit.py --in_file=thincurr_ex-cyl.g
119+
python /path/to/OFT/bin/OFT_convert_cubit.py --in_file=thincurr_ex-cyl.g
120120

121121
which will yield the converted file `thincurr_ex-cyl.h5`.

src/docs/ThinCurr/thincurr_example3.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Contents of the input files are provided below and in the examples directory und
1515

1616
# Post processing
1717

18-
Once complete you can now generate XDMF files suitable for visualization of results using the [VisIt](https://visit-dav.github.io/visit-website/index.html) code. For frequency-response calculations we do not need to do a separate plotting run, so once complete, you just need to run the `build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
18+
Once complete you can now generate XDMF files suitable for visualization of results using the [VisIt](https://visit-dav.github.io/visit-website/index.html) code. For frequency-response calculations we do not need to do a separate plotting run, so once complete, you just need to run the `OFT_build_xdmf.py` script, which generates XDMF metadata files that tells VisIt how to read the data. This can be done using the following command
1919

20-
python /path/to/oft/bin/build_xdmf.py
20+
python /path/to/oft/bin/OFT_build_xdmf.py
2121

2222
Next use VisIt to open the `surf_static.xmf` file, which will contain two vector fields `JRe` and `JIm` that correspond to the current distributions for the real and imaginary components of the solution in the frequency-domain. If you are running this example remotely and using VisIt locally you will need to copy the `mesh.*.h5`, `scalar_dump.*.h5`, `vector_dump.*.h5`, and `*.xmf` files to your local computer for visualization. The real component `JRe` should look like the figure below.
2323

@@ -97,8 +97,8 @@ set large exodus file on
9797
export Genesis "thincurr_ex-torus.g" overwrite block 1
9898
```
9999

100-
The file can then be converted to OFT's native mesh format using the `convert_cubit.py` script as
100+
The file can then be converted to OFT's native mesh format using the `OFT_convert_cubit.py` script as
101101

102-
python /path/to/OFT/bin/convert_cubit.py --in_file=thincurr_ex-torus.g
102+
python /path/to/OFT/bin/OFT_convert_cubit.py --in_file=thincurr_ex-torus.g
103103

104104
which will yield the converted file `thincurr_ex-torus.h5`.

src/docs/doc_mesh_native.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ As OFT only provides mesh generation capability for selected cases, most files w
2828
by one of the provided conversion scripts from software-specfic formats (eg. CUBIT, gmsh, etc.).
2929

3030
\subsection doc_mesh_native_conv_cubit Converting CUBIT files
31-
To convert from CUBIT meshes saved using the Exodus/Gensis file format use the `convert_cubit.py` script
31+
To convert from CUBIT meshes saved using the Exodus/Gensis file format use the `OFT_convert_cubit.py` script
3232
(as below). The `--in_file` argument must be specified and by default a new file is created in native
3333
format with the same name, but `*.h5` extension, in the current working directory. Additional options
3434
to control inclusion of periodicity information are available (use `--help` for more information).
3535

3636
\verbatim
37-
~$ python /path/to/oft/bin/convert_cubit.py --in_file=/path/to/cubit_mesh.g
37+
~$ python /path/to/oft/bin/OFT_convert_cubit.py --in_file=/path/to/cubit_mesh.g
3838
\endverbatim
3939

4040
\subsection doc_mesh_native_conv_gmsh Converting Gmsh files
4141
To convert from Gmsh meshes saved using the [MSH file format](https://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format)
42-
use the `convert_gmsh.py` script (as below). The `--in_file` argument must be specified and by default a new file is created in native
42+
use the `OFT_convert_gmsh.py` script (as below). The `--in_file` argument must be specified and by default a new file is created in native
4343
format with the same name, but `*.h5` extension, in the current working directory.
4444

4545
\note Currently only Tet/Tri meshes are supported in both linear and quadratic variants.
4646

4747
\verbatim
48-
~$ python /path/to/oft/bin/convert_gmsh.py --in_file=/path/to/gmsh_mesh.msh
48+
~$ python /path/to/oft/bin/OFT_convert_gmsh.py --in_file=/path/to/gmsh_mesh.msh
4949
\endverbatim

src/docs/doc_psitet_io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package. During a run subroutines are used to output the plotting mesh \ref oft_
1919
add time steps \ref oft_io::hdf5_create_timestep "hdf5_create_timestep", and output solution fields ex. \ref
2020
oft_io::hdf5_spdata "hdf5_spdata". Mesh and field information created during these calls are stored in <code>*.h5</code>
2121
files in the run directory along with a text file `dump.dat` which contains metadata describing the fields. After
22-
a run has completed the script `build_xdmf.py` can be used to build XML descriptor files which can be read by VisIt
22+
a run has completed the script `OFT_build_xdmf.py` can be used to build XML descriptor files which can be read by VisIt
2323
to produce visualization.
2424

2525
\subsection doc_oft_io_plotting_representation Field Representation

src/examples/MUG/Spheromak_heating/MUG_sph_heat.F90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ END PROGRAM MUG_sph_heat
335335
!!/
336336
!!\endverbatim
337337
!!
338-
!! Once the post-processing run is complete `bin/build_xdmf.py` can be used to generate `*.xmf` files that can be loaded by
338+
!! Once the post-processing run is complete `bin/OFT_build_xdmf.py` can be used to generate `*.xmf` files that can be loaded by
339339
!! [VisIt](https://visit-dav.github.io/visit-website/index.html), [ParaView](https://www.paraview.org/), or other visualization programs.
340340
!!
341341
!! \image html MUG_heat_ex-Fields.png "Resulting temperature distribution (shading) and magnetic field (vectors) at the end of the simulation, showing thermal confinement in the core of the torus."
@@ -362,18 +362,18 @@ END PROGRAM MUG_sph_heat
362362
!!mesh volume 1
363363
!!
364364
!!set duplicate block elements off
365-
!!block 1 add volume 1
365+
!!block 1 add volume 1
366366
!!block 1 element type tetra10
367367
!!
368368
!!set large exodus file on
369369
!!export Genesis "cyl_heat.g" overwrite block 1
370370
!!\endverbatim
371371
!!
372-
!! Once complete the mesh should be converted into the native mesh format using the `convert_cubit.py` script as
372+
!! Once complete the mesh should be converted into the native mesh format using the `OFT_convert_cubit.py` script as
373373
!! below. The script is located in `bin` following installation or `src/utilities` in the base repo.
374374
!!
375375
!!\verbatim
376-
!!~$ python convert_cubit.py --in_file=cyl_heat.g
376+
!!~$ python OFT_convert_cubit.py --in_file=cyl_heat.g
377377
!!\endverbatim
378378
!!
379379
!!\subsection doc_mug_sph_ex2_gmsh Meshing with Gmsh
@@ -406,9 +406,9 @@ END PROGRAM MUG_sph_heat
406406
!!~$ gmsh -3 -format mesh -optimize -clscale .2 -order 2 -o cyl_heat.mesh cyl_heat.geo
407407
!!\endverbatim
408408
!!
409-
!! Once complete the mesh should be converted into the native mesh format using the `convert_gmsh.py` script as
409+
!! Once complete the mesh should be converted into the native mesh format using the `OFT_convert_gmsh.py` script as
410410
!! below. The script is located in `bin` following installation or `src/utilities` in the base repo.
411411
!!
412412
!!\verbatim
413-
!!~$ python convert_gmsh.py --in_file=cyl_heat.mesh
413+
!!~$ python OFT_convert_gmsh.py --in_file=cyl_heat.mesh
414414
!!\endverbatim

src/examples/MUG/Spheromak_tilt/MUG_sph_tilt.F90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ END PROGRAM MUG_sph_tilt
354354
!!/
355355
!!\endverbatim
356356
!!
357-
!! Once the post-processing run is complete `bin/build_xdmf.py` can be used to generate `*.xmf` files that can be loaded by
357+
!! Once the post-processing run is complete `bin/OFT_build_xdmf.py` can be used to generate `*.xmf` files that can be loaded by
358358
!! [VisIt](https://visit-dav.github.io/visit-website/index.html), [ParaView](https://www.paraview.org/), or other visualization programs.
359359
!!
360360
!! \image html MUG_tilt_ex-Fields.png "Magnetic field distribution of the initial (left) and final (right) states"
@@ -381,18 +381,18 @@ END PROGRAM MUG_sph_tilt
381381
!!mesh volume 1
382382
!!
383383
!!set duplicate block elements off
384-
!!block 1 add volume 1
384+
!!block 1 add volume 1
385385
!!block 1 element type tetra10
386386
!!
387387
!!set large exodus file on
388388
!!export Genesis "cyl_tilt.g" overwrite block 1
389389
!!\endverbatim
390390
!!
391-
!! Once complete the mesh should be converted into the native mesh format using the `convert_cubit.py` script as
391+
!! Once complete the mesh should be converted into the native mesh format using the `OFT_convert_cubit.py` script as
392392
!! below. The script is located in `bin` following installation or `src/utilities` in the base repo.
393393
!!
394394
!!\verbatim
395-
!!~$ python convert_cubit.py --in_file=cyl_tilt.g
395+
!!~$ python OFT_convert_cubit.py --in_file=cyl_tilt.g
396396
!!\endverbatim
397397
!!
398398
!!\subsection doc_mug_sph_ex1_gmsh Meshing with Gmsh
@@ -425,9 +425,9 @@ END PROGRAM MUG_sph_tilt
425425
!!~$ gmsh -3 -format mesh -optimize -clscale .2 -order 2 -o cyl_tilt.mesh cyl_tilt.geo
426426
!!\endverbatim
427427
!!
428-
!! Once complete the mesh should be converted into the native mesh format using the `convert_gmsh.py` script as
428+
!! Once complete the mesh should be converted into the native mesh format using the `OFT_convert_gmsh.py` script as
429429
!! below. The script is located in `bin` following installation or `src/utilities` in the base repo.
430430
!!
431431
!!\verbatim
432-
!!~$ python convert_gmsh.py --in_file=cyl_tilt.mesh
432+
!!~$ python OFT_convert_gmsh.py --in_file=cyl_tilt.mesh
433433
!!\endverbatim

0 commit comments

Comments
 (0)