INP-PM / FEDM

Finite Element Discharge Modelling code
https://inp-pm.github.io/FEDM/
GNU Lesser General Public License v3.0
10 stars 4 forks source link

WIP: Style edits #6

Closed LiamPattinson closed 1 year ago

LiamPattinson commented 1 year ago

I've been going through the code and making some style changes following Issue https://github.com/AleksandarJ1984/FEDM/issues/2. I'm trying to avoid changing code behaviour wherever possible, though there are some areas where I thought it could be beneficial.

I've written tests for one function so far, but it'll take me some time to figure out how Dolfin works before I can extend this to most other functions. You can run them by calling the following from the project's top-level directory within the Docker container:

python3 -m pip install --user .[tests]
python3 -m pytest -v tests

I'll leave comments here to explain my changes in more detail. I can revert/edit any of these changes if you think I've changed things for the worse, as 'good style' is a highly subjective topic.

LiamPattinson commented 1 year ago

I've finished modifying the examples given to create integrated tests. It's now possible to change the input/output directories via a Files class, which uses properties to manage the locations of the input directory, output directory, error file, and log file. Assigning a new directory to files.output_folder_path will create a new directory if it doesn't exist, and will update files.error_file and files.model_log to files in the new directory.

I've also 'modularised' the shortened examples (glow discharge, streamer discharge, time of flight), so they can be imported to other Python modules and called using a main function. They also use argparse to handle command line inputs, so the user can more easily specify the input/output directories:

python3 fedm_streamer.py -i my_input_dir -o my_output_dir # short form
python3 fedm_streamer.py --input my_input_dir --output my_output_dir # long form
python3 fedm_streamer.py # use defaults
python3 fedm_streamer.py -h # display help text

I'd recommend updating the code in Examplessimilarly if you think it'd be useful. The tests can be run using a short bash script in the root directory. You first need to install with the test dependencies:

# install FEDM with its usual dependencies, plus pytest, vtk, h5py
python3 -m pip install --user .[tests] 
# vtk library needs OpenGL for some reason, which isn't on the Docker container by default
sudo apt install libgl1

You then need to call ./run_tests.sh (maybe with sudo) from within the docker container, and it'll run the units tests followed by the integrated tests one-by-one. This avoids the weird issue where calling python3 -m pytest tests causes the integrated tests to fail, but individual calls such as python3 -m pytest tests/integrated_tests/glow_discharge work just fine.

Let me know if you'd like anything explained in more detail or if you'd like me to update the code any further. I should receive notifications if you leave a comment on any of the code in the 'Files changed' tab.