diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d4d13ad --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +UseTab: Never +IndentWidth: 4 +TabWidth: 4 +AccessModifierOffset: -4 +IndentAccessModifiers: false +AllowShortFunctionsOnASingleLine: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + BeforeElse: true diff --git a/Doxyfile b/Doxyfile index ea0f35d..eeba27f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -68,7 +68,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = docs +OUTPUT_DIRECTORY = # If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format @@ -1070,7 +1070,7 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). -IMAGE_PATH = +IMAGE_PATH = ./images # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program @@ -1303,7 +1303,7 @@ GENERATE_HTML = YES # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_OUTPUT = html +HTML_OUTPUT = docs # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). @@ -2183,7 +2183,7 @@ GENERATE_MAN = YES # The default directory is: man. # This tag requires that the tag GENERATE_MAN is set to YES. -MAN_OUTPUT = man +MAN_OUTPUT = man_pages # The MAN_EXTENSION tag determines the extension that is added to the generated # man pages. In case the manual section does not start with a number, the number diff --git a/README.md b/README.md index 9d655f4..254c153 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Penning trap simulation + + + ## Credits The Doxygen theme used here is diff --git a/docs/100_particles.gif b/docs/100_particles.gif new file mode 100644 index 0000000..337c6e5 Binary files /dev/null and b/docs/100_particles.gif differ diff --git a/docs/Particle_8cpp.html b/docs/Particle_8cpp.html index 9f88834..b3fd0e9 100644 --- a/docs/Particle_8cpp.html +++ b/docs/Particle_8cpp.html @@ -113,8 +113,7 @@ $(document).ready(function(){initNavTree('Particle_8cpp.html',''); initResizable
Definition in file Particle.cpp.
diff --git a/docs/Particle_8cpp_source.html b/docs/Particle_8cpp_source.html index 159fd35..13c1950 100644 --- a/docs/Particle_8cpp_source.html +++ b/docs/Particle_8cpp_source.html @@ -102,16 +102,24 @@ $(document).ready(function(){initNavTree('Particle_8cpp_source.html',''); initReA class that holds the properties of a particle. More...
Go to the source code of this file.
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
| CParticle | A class that holds attributes of a particle |
| CPenningTrap | A class that simulates a Penning trap |
| CPenningTrapTest |
This is the complete list of members for Particle, including all inherited members.
| m | Particle | private |
| Particle(double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec) | Particle | |
| Particle(double q, double m, vec_3d r_vec, vec_3d v_vec) | Particle | |
| PenningTrap | Particle | friend |
| q | Particle | private |
| r_vec | Particle | private |
| v_vec | Particle | private |
| r_vec | Particle | private |
| v_vec | Particle | private |
Public Member Functions | |
| Particle (double q, double m, arma::vec::fixed< 3 > r_vec, arma::vec::fixed< 3 > v_vec) | |
| Initialize the particle. | |
| Particle (double q, double m, vec_3d r_vec, vec_3d v_vec) | |
| Initialize the particle. | |
Private Attributes | |
| double | m |
| Mass. | |
| arma::vec::fixed< 3 > | r_vec |
| position | |
| arma::vec::fixed< 3 > | v_vec |
| velocity | |
| vec_3d | r_vec |
| position | |
| vec_3d | v_vec |
| velocity | |
Friends | ||||
| - | arma::vec::fixed< 3 > | +vec_3d | r_vec, | |
| - | arma::vec::fixed< 3 > | +vec_3d | v_vec | |
| q | The charge of the particle |
| m | The mass of the particle |
| r_vec | The initial position of the particle |
| v_vec | The initial velocity of the particle |
Definition at line 17 of file Particle.cpp.
+Definition at line 15 of file Particle.cpp.
Make private attributes available for PenningTrap.
-Definition at line 38 of file Particle.hpp.
+Definition at line 43 of file Particle.hpp.
@@ -239,7 +248,7 @@ FriendsMass.
-Definition at line 22 of file Particle.hpp.
+Definition at line 24 of file Particle.hpp.
@@ -265,12 +274,12 @@ FriendsCharge.
-Definition at line 21 of file Particle.hpp.
+Definition at line 23 of file Particle.hpp.
- -| arma::vec::fixed<3> Particle::r_vec | +vec_3d Particle::r_vec |
position
-Definition at line 23 of file Particle.hpp.
+Definition at line 25 of file Particle.hpp.
| arma::vec::fixed<3> Particle::v_vec | +vec_3d Particle::v_vec |
velocity
-Definition at line 24 of file Particle.hpp.
+Definition at line 26 of file Particle.hpp.
Public Member Functions | |
| PenningTrap (double B_0=T, double V_0=25.*V/1000., double d=500.) | |
| Set B_0, V_0 and d. | |
| PenningTrap (double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.) | |
| Constructor for the PenningTrap class. | |
| PenningTrap (unsigned int i, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.) | |
| Constructor for the PenningTrap class. | |
| PenningTrap (std::vector< Particle > particles, double B_0=T, std::function< double(double)> V_0=[](double t) { return 25. *V/1000.;}, double d=500., double t=0.) | |
| Constructor for the PenningTrap class. | |
| void | add_particle (Particle particle) |
| Add a particle to the system. | |
| arma::vec | external_E_field (arma::vec r) |
| Calculate E at point r. | |
| arma::vec | external_B_field (arma::vec r) |
| Calculate B at point r. | |
| arma::vec | force_on_particle (int i, int j) |
| Calculate the force between 2 particles. | |
| arma::vec | total_force_external (int i) |
| Calculate the total external force on a particle. | |
| arma::vec | total_force_particles (int i) |
| Calculate the total force on a particle from other particles. | |
| arma::vec | total_force (int i) |
| calculate the total force on a particle. | |
| void | evolve_RK4 (double dt) |
| Go forward one timestep using the RK4 method. | |
| void | evolve_forward_euler (double dt) |
| Go forward one timestep using the forward Euler method. | |
| vec_3d | external_E_field (vec_3d r) |
| Calculate E at point r. | |
| vec_3d | external_B_field (vec_3d r) |
| Calculate B at point r. | |
| vec_3d | force_on_particle (unsigned int i, unsigned int j) |
| Calculate the force between 2 particles. | |
| vec_3d | total_force_external (unsigned int i) |
| Calculate the total external force on a particle. | |
| vec_3d | total_force_particles (unsigned int i) |
| Calculate the total force on a particle p_i from other particles. | |
| vec_3d | total_force (unsigned int i) |
| calculate the total force on a particle p_i. | |
| void | evolve_RK4 (double dt, bool particle_interaction=true) |
| Go forward one timestep using the RK4 method. | |
| void | evolve_forward_euler (double dt, bool particle_interaction=true) |
| Go forward one timestep using the forward Euler method. | |
| sim_arr | simulate (double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true) |
| Simulate the particle system inside the Penning trap over a certain amount of time. | |
| void | write_simulation_to_dir (std::string path, double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true) |
| Simulate and write the displacement of all particles to files. | |
| double | fraction_of_particles_left (double time, unsigned int steps, std::string method="rk4", bool particle_interaction=true) |
| Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation. | |
+Private Member Functions | |
| vec_3d | v_func (unsigned int i, unsigned int j, double dt) |
| Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values. | |
| vec_3d | r_func (unsigned int i, unsigned int j, double dt) |
| Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values. | |
Private Attributes | |
| double | B_0 |
| Magnetic field strength. | |
| double | V_0 |
| Applied potential. | |
| std::function< double(double)> | V_0 |
| Applied potential. | |
| double | d |
| Characteristic dimension. | |
| double | t |
| Current time. | |
| std::vector< Particle > | particles |
| The particles in the Penning trap. | |
| sim_arr | k_v |
| sim_arr | k_r |
A class that simulates a Penning trap.
This class simulates a Penning trap. It can take in a number of particles and simulate how they would behave inside a Penning trap.
-Definition at line 25 of file PenningTrap.hpp.
+Definition at line 30 of file PenningTrap.hpp.
Set B_0, V_0 and d.
+Constructor for the PenningTrap class.
+| B_0 | The magnetic field strength |
| V_0 | The time dependent applied potential |
| d | The characteristic dimension |
| t | The starting time |
Definition at line 26 of file PenningTrap.cpp.
+Definition at line 18 of file PenningTrap.cpp.
+ +| PenningTrap::PenningTrap | +( | +unsigned int | +i, | +
| + | + | double | +B_0 = T, |
+
| + | + | std::function< double(double)> | +V_0 = [](double t) { return 25. * V / 1000.; }, |
+
| + | + | double | +d = 500., |
+
| + | + | double | +t = 0. |
+
| + | ) | ++ |
Constructor for the PenningTrap class.
+| i | The number of particles to generate |
| B_0 | The magnetic field strength |
| V_0 | The time dependent applied potential |
| d | The characteristic dimension |
| t | The starting time |
Definition at line 27 of file PenningTrap.cpp.
+ +| PenningTrap::PenningTrap | +( | +std::vector< Particle > | +particles, | +
| + | + | double | +B_0 = T, |
+
| + | + | std::function< double(double)> | +V_0 = [](double t) { return 25. * V / 1000.; }, |
+
| + | + | double | +d = 500., |
+
| + | + | double | +t = 0. |
+
| + | ) | ++ |
Constructor for the PenningTrap class.
+| particles | The starting particles |
| B_0 | The magnetic field strength |
| V_0 | The time dependent applied potential |
| d | The characteristic dimension |
| t | The starting time |
Definition at line 39 of file PenningTrap.cpp.
Add a particle to the system.
+| particle | The particle to add to the Penning trap |
Definition at line 31 of file PenningTrap.cpp.
+Definition at line 82 of file PenningTrap.cpp.
true Go forward one timestep using the forward Euler method.
+| dt | The step length |
| particle_interaction | Turn particle interactions on/off |
Definition at line 71 of file PenningTrap.cpp.
+Definition at line 186 of file PenningTrap.cpp.
true Go forward one timestep using the RK4 method.
+| dt | The step length |
| particle_interaction | Turn particle interactions on/off |
Definition at line 66 of file PenningTrap.cpp.
+Definition at line 151 of file PenningTrap.cpp.
| arma::vec PenningTrap::external_B_field | +vec_3d PenningTrap::external_B_field | ( | -arma::vec | +vec_3d | r | ) | |||||||||||
| r | The position where we want to calculate the B field |
Definition at line 41 of file PenningTrap.cpp.
+Definition at line 95 of file PenningTrap.cpp.
| arma::vec PenningTrap::external_E_field | +vec_3d PenningTrap::external_E_field | ( | -arma::vec | +vec_3d | r | ) | |||||||||||
| r | The position where we want to calculate the E field |
Definition at line 36 of file PenningTrap.cpp.
+Definition at line 87 of file PenningTrap.cpp.
| arma::vec PenningTrap::force_on_particle | +vec_3d PenningTrap::force_on_particle | ( | -int | +unsigned int | i, | ||||||||||||
| - | int | +unsigned int | j | ||||||||||||||
| i | The index of particle p_i |
| j | The index of particle p_j |
Definition at line 46 of file PenningTrap.cpp.
+Definition at line 100 of file PenningTrap.cpp.
| arma::vec PenningTrap::total_force | +double PenningTrap::fraction_of_particles_left | ( | -int | +double | +time, | +
| + | + | unsigned int | +steps, | +||
| + | + | std::string | +method = "rk4", |
+ ||
| + | + | bool | +particle_interaction = true |
+ ||
| + | ) | ++ |
Simulate and calculate what fraction of particles are still left inside the Penning trap after the simulation.
+| time | The time to simulate in microseconds |
| steps | The amount of steps for the whole simulation |
| method | The method to use when moving forward a timestep |
| particle_interaction | Turn particle interactions on/off |
Definition at line 266 of file PenningTrap.cpp.
+ +
+
|
+ +private | +
Helper for evolve_RK4 when calculating \(k_{r,i,j}\) values.
+Something
+| i | Index i for \(k_{r,i,j}\) |
| j | Index j for \(k_{r,i,j}\) |
| dt | the step length (delta time) |
Definition at line 64 of file PenningTrap.cpp.
+ +| sim_arr PenningTrap::simulate | +( | +double | +time, | +
| + | + | unsigned int | +steps, | +
| + | + | std::string | +method = "rk4", |
+
| + | + | bool | +particle_interaction = true |
+
| + | ) | ++ |
Simulate the particle system inside the Penning trap over a certain amount of time.
+| time | The time to simulate in microseconds |
| steps | The amount of steps for the whole simulation |
| method | The method to use when moving forward a timestep |
| particle_interaction | Turn particle interactions on/off |
Definition at line 211 of file PenningTrap.cpp.
+ +| vec_3d PenningTrap::total_force | +( | +unsigned int | i | ) |
calculate the total force on a particle.
+calculate the total force on a particle p_i.
+| i | The index of particle p_i |
Definition at line 61 of file PenningTrap.cpp.
+Definition at line 146 of file PenningTrap.cpp.
| arma::vec PenningTrap::total_force_external | +vec_3d PenningTrap::total_force_external | ( | -int | +unsigned int | i | ) |
| i | The index of particle p_i |
Definition at line 51 of file PenningTrap.cpp.
+Definition at line 114 of file PenningTrap.cpp.
| arma::vec PenningTrap::total_force_particles | +vec_3d PenningTrap::total_force_particles | ( | -int | +unsigned int | i | ) |
Calculate the total force on a particle from other particles.
+Calculate the total force on a particle p_i from other particles.
+| i | The index of particle p_i |
Definition at line 56 of file PenningTrap.cpp.
+Definition at line 129 of file PenningTrap.cpp.
+ +
+
|
+ +private | +
Helper for evolve_RK4 when calculating \(k_{v,i,j}\) values.
+Something
+| i | Index i for \(k_{v,i,j}\) |
| j | Index j for \(k_{v,i,j}\) |
| dt | the step length (delta time) |
Definition at line 46 of file PenningTrap.cpp.
+ +| void PenningTrap::write_simulation_to_dir | +( | +std::string | +path, | +
| + | + | double | +time, | +
| + | + | unsigned int | +steps, | +
| + | + | std::string | +method = "rk4", |
+
| + | + | bool | +particle_interaction = true |
+
| + | ) | ++ |
Simulate and write the displacement of all particles to files.
+| path | The directory to save the data |
| time | The time to simulate in microseconds |
| steps | The amount of steps for the whole simulation |
| method | The method to use when moving forward a timestep |
| particle_interaction | Turn particle interactions on/off |
Definition at line 240 of file PenningTrap.cpp.
Magnetic field strength.
-Definition at line 27 of file PenningTrap.hpp.
+Definition at line 32 of file PenningTrap.hpp.
@@ -463,7 +992,57 @@ Private AttributesCharacteristic dimension.
-Definition at line 29 of file PenningTrap.hpp.
+Definition at line 34 of file PenningTrap.hpp.
+ + + + +
+
|
+ +private | +
A 2D vector containing all \(k_{i,j}\) where \(j\) is the index of a particle
+ +Definition at line 39 of file PenningTrap.hpp.
+ +
+
|
+ +private | +
A 2D vector containing all \(k_{i,j}\) where \(j\) is the index of a particle
+ +Definition at line 37 of file PenningTrap.hpp.
The particles in the Penning trap.
-Definition at line 30 of file PenningTrap.hpp.
+Definition at line 36 of file PenningTrap.hpp.
- -| double PenningTrap::V_0 | +double PenningTrap::t | +
Current time.
+ +Definition at line 35 of file PenningTrap.hpp.
+ +
+
|
@@ -515,7 +1120,7 @@ Private Attributes||||||
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
This is the complete list of members for PenningTrapTest, including all inherited members.
+| test_external_B_field() (defined in PenningTrapTest) | PenningTrapTest | inlinestatic |
| test_external_E_field() (defined in PenningTrapTest) | PenningTrapTest | inlinestatic |
| test_force_on_particle() (defined in PenningTrapTest) | PenningTrapTest | inlinestatic |
| test_total_force_external() (defined in PenningTrapTest) | PenningTrapTest | inlinestatic |
| test_total_force_particles() (defined in PenningTrapTest) | PenningTrapTest | inlinestatic |
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
+Static Public Member Functions | |
| static void | test_external_E_field () |
| static void | test_external_B_field () |
| static void | test_force_on_particle () |
| static void | test_total_force_external () |
| static void | test_total_force_particles () |
Definition at line 20 of file test_suite.cpp.
+
+
|
+ +inlinestatic | +
Definition at line 59 of file test_suite.cpp.
+ +
+
|
+ +inlinestatic | +
Definition at line 22 of file test_suite.cpp.
+ +
+
|
+ +inlinestatic | +
Definition at line 70 of file test_suite.cpp.
+ +
+
|
+ +inlinestatic | +
Definition at line 95 of file test_suite.cpp.
+ +
+
|
+ +inlinestatic | +
Definition at line 108 of file test_suite.cpp.
+ +Files | |
| file | animate_100_particles.py [code] |
| file | main.cpp [code] |
| The main program for this project. | |
| file | PenningTrap.cpp [code] |
| The implementation of the PenningTrap class. | |
| file | plot_particles_left.py [code] |
| file | test_suite.cpp [code] |
| The test suite for the project. | |
| file | PenningTrap.hpp [code] |
| A class for simulating a Penning trap. | |
| file | typedefs.hpp [code] |
| Useful typedefs for cleaner code. | |
| file | utils.hpp [code] |
| Function prototypes and macros that are useful. | |
| constants.hpp | Library of constants |
| Particle.hpp | A class that holds the properties of a particle |
| PenningTrap.hpp | A class for simulating a Penning trap |
| utils.hpp | Function prototypes and macros that are useful |
| ▼ src | |
| main.cpp | The main program for this project |
| Particle.cpp | The implementation of the Particle class |
| PenningTrap.cpp | The implementation of the PenningTrap class |
| test_suite.cpp | The test suite for the project |
| utils.cpp | Implementation of the utils |
| typedefs.hpp | Useful typedefs for cleaner code |
| utils.hpp | Function prototypes and macros that are useful |
| ▼ src | |
| animate_100_particles.py | |
| main.cpp | The main program for this project |
| Particle.cpp | The implementation of the Particle class |
| PenningTrap.cpp | The implementation of the PenningTrap class |
| plot_particles_left.py | |
| test_suite.cpp | The test suite for the project |
| utils.cpp | Implementation of the utils |
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
The main program for this project. More...
- +#include <cmath>#include <fstream>#include <omp.h>#include <string>#include <sys/stat.h>#include <vector>#include "PenningTrap.hpp"#include "utils.hpp"Go to the source code of this file.
+Macros | |
| #define | PARTICLES 100 |
| #define | N 10000 |
| #define | CHARGE 1. |
| #define | MASS 40. |
Functions | |
| void | simulate_single_particle () |
| void | simulate_two_particles () |
| void | simulate_single_particle_with_different_steps () |
| void | simulate_100_particles () |
| void | simulate_100_particles_with_time_potential () |
| int | main () |
+Variables | |
| +Particle | p1 (CHARGE, MASS, vec_3d{20., 0., 20.}, vec_3d{0., 25., 0.}) |
| +Particle | p2 (CHARGE, MASS, vec_3d{25., 25., 0.}, vec_3d{0., 40., 5.}) |
The main program for this project.
@@ -120,10 +160,75 @@ FunctionsDefinition in file main.cpp.
-| void simulate_100_particles | +( | +) | ++ |
| void simulate_100_particles_with_time_potential | +( | +) | ++ |
| void simulate_single_particle | +( | +) | ++ |
| void simulate_single_particle_with_different_steps | +( | +) | ++ |
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
The test suite for the project. More...
- +#include "PenningTrap.hpp"#include "utils.hpp"#include <iomanip>#include <sstream>#include <string>Go to the source code of this file.
+Classes | |
| class | PenningTrapTest |
Functions | |
| int | main () |
Definition at line 12 of file test_suite.cpp.
+Definition at line 135 of file test_suite.cpp.
Implement add_particle
- -Implement external_E_field
- -Implement external_B_field
- -Implement force_on_particle
- -Implement total_force_external
- -Implement total_force_particles
- -Implement total_force
- -Implement evolve_RK4
+Implement evolve_forward_euler
|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
Useful typedefs for cleaner code. +More...
+#include <vector>#include <armadillo>Go to the source code of this file.
++Typedefs | |
| typedef std::vector< arma::vec::fixed< 3 > > | sim_cols |
| Typedef for the column of the result vector from simulating particles. | |
| typedef std::vector< arma::vec::fixed< 3 > > | sim_rows |
| Typedef for the row of the result vector from simulating particles. | |
| typedef std::vector< sim_cols > | sim_arr |
| Typedef for the result of the simulate method. | |
| typedef arma::vec::fixed< 3 > | vec_3d |
| Typedef for a fixed 3d arma vector. | |
Useful typedefs for cleaner code.
+ +These typedefs make the code more readable and easy to follow along.
+Definition in file typedefs.hpp.
+Typedef for the result of the simulate method.
+ +Definition at line 32 of file typedefs.hpp.
+ +| typedef std::vector<arma::vec::fixed<3> > sim_cols | +
Typedef for the column of the result vector from simulating particles.
+ +Definition at line 24 of file typedefs.hpp.
+ +| typedef std::vector<arma::vec::fixed<3> > sim_rows | +
Typedef for the row of the result vector from simulating particles.
+ +Definition at line 28 of file typedefs.hpp.
+ +| typedef arma::vec::fixed<3> vec_3d | +
Typedef for a fixed 3d arma vector.
+ +Definition at line 36 of file typedefs.hpp.
+ +|
+ Penning Trap Simulation
+
+ Simulate particle behavior inside a Penning Trap
+ |
+
Implementation of the utils. More...
-#include "utils.hpp"Go to the source code of this file.
| std::string | scientific_format (const std::vector< double > &v, int width, int prec) |
| Turns a vector of doubles into a string written in scientific format. | |
| void | m_assert (bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg) |
| Test an expression, confirm that test is ok, or abort execution. | |
| bool | arma_vector_close_to (arma::vec &a, arma::vec &b, double tol) |
| Test if two armadillo vectors are close to each other. | |
| bool | mkpath (std::string path, int mode) |
| Make path given. | |
Implementation of the utils.
@@ -125,10 +135,167 @@ FunctionsDefinition in file utils.cpp.
| bool arma_vector_close_to | +( | +arma::vec & | +a, | +
| + | + | arma::vec & | +b, | +
| + | + | double | +tol = 1e-8 |
+
| + | ) | ++ |
| void m_assert | +( | +bool | +expr, | +
| + | + | std::string | +expr_str, | +
| + | + | std::string | +func, | +
| + | + | std::string | +file, | +
| + | + | int | +line, | +
| + | + | std::string | +msg | +
| + | ) | ++ |
Test an expression, confirm that test is ok, or abort execution.
+This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails.
+| expr | The expression to be evaluated |
| expr_str | The stringified version of the expression |
| func | The function name of the caller |
| file | The file of the caller |
| line | The line number where this function is called from |
| msg | The message to be displayed |
| bool mkpath | +( | +std::string | +path, | +
| + | + | int | +mode = 0777 |
+
| + | ) | ++ |
Turns a vector of doubles into a string written in scientific format.
+The code is stolen from https://github.com/anderkve/FYS3150.
| v | The vector to stringify |
Turns a double into a string written in scientific format.
-Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp
+The code is stolen from https://github.com/anderkve/FYS3150.
| d | The number to stringify |
Function prototypes and macros that are useful. More...
-#include <string>#include <vector>#include <armadillo>#include <iomanip>#include <sstream>#include <string>#include <vector>Go to the source code of this file.
| #define | DEBUG(msg) |
| Writes a debug message. | |
| #define | ASSERT(expr, msg) |
| A prettier assertion function. | |
| #define | __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) |
| Get the name of the current method/function. | |
Functions | |
| std::string | scientific_format (const std::vector< double > &v, int width=20, int prec=10) |
| Turns a vector of doubles into a string written in scientific format. | |
| void | m_assert (bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg) |
| Test an expression, confirm that test is ok, or abort execution. | |
| bool | arma_vector_close_to (arma::vec &a, arma::vec &b, double tol=1e-8) |
| Test if two armadillo vectors are close to each other. | |
| bool | mkpath (std::string path, int mode=0777) |
| Make path given. | |
Function prototypes and macros that are useful.
@@ -136,10 +152,65 @@ Functions Janita Ovidie Sandtrøen Willumsen (janitaws)These utility function are mainly for convenience and aren't directly related to the project.
-Definition in file utils.hpp.
| #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) | +
| #define ASSERT | +( | ++ | expr, | +
| + | + | + | msg | +
| + | ) | ++ |
A prettier assertion function.
+This macro calls the m_assert function which is a more informative assertion function than the regular assert function from cassert.
+ + + +Writes a debug message.
-This function writes a debug message that includes the filename, line number, and a custom message. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling.
+This macro writes a debug message that includes the filename, line number, and a custom message. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling.
- +| bool arma_vector_close_to | +( | +arma::vec & | +a, | +
| + | + | arma::vec & | +b, | +
| + | + | double | +tol = 1e-8 |
+
| + | ) | ++ |
| void m_assert | +( | +bool | +expr, | +
| + | + | std::string | +expr_str, | +
| + | + | std::string | +func, | +
| + | + | std::string | +file, | +
| + | + | int | +line, | +
| + | + | std::string | +msg | +
| + | ) | ++ |
Test an expression, confirm that test is ok, or abort execution.
+This function takes in an expression and prints an OK message if it's true, or it prints a fail message and aborts execution if it fails.
+| expr | The expression to be evaluated |
| expr_str | The stringified version of the expression |
| func | The function name of the caller |
| file | The file of the caller |
| line | The line number where this function is called from |
| msg | The message to be displayed |
| bool mkpath | +( | +std::string | +path, | +
| + | + | int | +mode = 0777 |
+
| + | ) | ++ |
Turns a vector of doubles into a string written in scientific format.
+The code is stolen from https://github.com/anderkve/FYS3150.
| v | The vector to stringify |
Turns a double into a string written in scientific format.
-Code stolen from https://github.com/anderkve/FYS3150 Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp
+The code is stolen from https://github.com/anderkve/FYS3150.
| d | The number to stringify |