Skip to content

Computational Physics Project B - project B2, modelling electric fields - solving the laplacian

Notifications You must be signed in to change notification settings

akuhnregnier/projectB

Repository files navigation

############################################################################################################
Computational Physics Project B2 Code Documentation
Author: Alexander Kuhn-Regnier
e-mail: ahk114@ic.ac.uk
############################################################################################################

Need to run 'conda update numba' or equivalent, eg. 'pip install numba --upgrade' in order to run the code, 
as some of the functions used in the jit decorated functions are only available in newer versions of numba 
than the one currently installed by default on the college computers.

Might need to update scipy in a manner similar to the above, I found that on the college computers, 
it might be required to remove scipy beforehand using 'conda remove scipy'
before being able to update it via 'conda install scipy' or 'conda update scipy'

When running longer simulations using the iPython console
an error with the message "I/O operation on closed file" was encountered 
on some occasions. Running the same program in simple python console
resolved the problem.

############################################################################################################

For general guidelines on how to run each part of the code, most code files will include a 
"if __name__ == '__main__'" statement which runs when the code is executed directly (not simply imported).
The code run in this statement is instructive of how to use the code module.

############################################################################################################
############################################################################################################

Generating the Figures in the Report

############################################################################################################
Figure 1

Run:
coaxial_cable_different_Ns_required_Ns.py

Notes:
Should already be configured to produce results shown
############################################################################################################
Figure 2 and 4

Run:
square_coaxial_cable_figures_different_w_tube.py

Notes:
The functions corresponding to the individual scenarios will all be run if the code is run.
Alternatively, it can be imported and each function executed independently.

############################################################################################################
Figure 3

Run:
coaxial_cable_different_Ns_convergence_time.py
coaxial_cable_different_Ns_convergence_time_jacobi_iter.py

Notes:
For both files, the general solving parameters can be set at the top of the file, such as the 
maximum time allowed for solving, which should be sufficiently high so as not to cap the execution
of the iterations. The grid spacings (along an axis), Ns, can also be specified via the numpy
linspace function.
############################################################################################################
Figure 5

Run:
AMR_field_homogeneity.py

Notes:
This code generates (d) directly, whereas (a) - (c) will have have to be generated manually using the 
following bound methods (bound to the AMR_system instance, denoted here by self):
	self.show_setup(color=(0,0,0,0)) - set alpha to 0 to hide the grid lines
	self.show(grid_lines=False) - don't show grid lines
	self.streamplot(density=10) - increase density of lines for better recognition

The resulting plots are then zoomed in to xmin=0.22, xmax=0.28, ymin=0.01, ymax=0.07. They are then saved
as pdf files.
############################################################################################################
Figure 6

Run:
AMR_field_homogeneity.py

Notes:
Generated for two different tolerances, set on line 130. One ranges from 1e-5 to 1e-3, the other goes 
up to 3. (They are multiplied by 100 to get % values on the figures).
The different figures are then generated by setting the overview switch on line 196 to True and False 
as required.
############################################################################################################
Figure 7

Run:
AMR_field_homogeneity_no_side_plates.py
############################################################################################################
Figure 8

Run:
AMR_field_homogeneity_no_side_plates.py

Notes:
Same as for Figure 6. Selecting different tolerances, the different figures were generated.
############################################################################################################
Figure 9

Run:
AMR_field_homogeneity_no_side_plates.py

Notes:
Two systems were solved in the above code. Each of those can be accessed after the system has been solved.
Their respectively bound streamplot methods were used, again with the argument density=10, and then a
rightmost x limit of 0.3 selected in order to plot the figures.
############################################################################################################
Figure 10

Run:
generate_uniform_grid_image.py
############################################################################################################
Figure 11

Run:
AMR_mesh_resizing_accuracy.py

Notes:
The code can be used to generate arbitrary mesh configurations and then solve the system, while also 
comparing it to a fine grid that was solved for the same system.
############################################################################################################
Figure 12

Run:
coaxial_cable_different_Ns_convergence_time.py

Notes:
Using the Ns values shown (labelled as N on Figure 12a), the corresponding results can be generated.
############################################################################################################
Figure 13 and 14

Run:
AMR_presolving_test.py

Notes:
Running the precondition function with the arguments as stated in the report will generate the corresponding
plots.
############################################################################################################
############################################################################################################
############################################################################################################

General Remarks:
Many of the codes files seemingly exist twice. However, this is due to the shift from using the "system"
module to using the "AMR_system" module as a basis. The latter has support for the non-uniform mesh,
as well as a more uniform and neat implementation. The older "system" code and its non-AMR capable 
derivate code snippets are included merely for completeness sake. They were not used to generate 
any results in the report.

Many sample images are included, going beyond those presented in the report.

About

Computational Physics Project B - project B2, modelling electric fields - solving the laplacian

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages