You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-33Lines changed: 75 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,9 @@
7
7
8
8
ROOT, but not the [particle physics one](https://github.com/root-project/root). Project submission for MATH-458: Programming concepts in scientific computing.
9
9
10
-
## Project structure and dependencies
10
+
The project bundles a header-only C++ library (`libROOT`) implementing root-finding algorithms and a CLI application (`root_cli`) to read and parse input, run the algorithms implemented in libROOT, and write the output to a file of specific format.
11
+
12
+
## Project structure
11
13
12
14
The project uses the recommended [Canonical Project Structure](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html) for C++ projects.
13
15
@@ -37,40 +39,66 @@ The project uses the recommended [Canonical Project Structure](https://www.open-
37
39
└── tests # Tests for the ROOT library
38
40
```
39
41
40
-
### Dependencies
42
+
Apart from being divided into a library and a user-facing application/executable, the design on the project
43
+
is concretely split into four phases.
44
+
45
+
### CLI
46
+
47
+
The CLI application is written (and should be written) within the `main` function. The `main` function further calls the `Reader`, `Solver`, and `Writer` classes (in this order) on the input passed through the CLI application.
48
+
49
+
### Readers and Parsers
50
+
51
+
Reading and parsing is handled by the `ReaderBase` and `FunctionParserBase` daughter classes. Adding a new reading method should include writing a new `ReaderBase` daughter class and adding functionality to parse a new type of function should include writing a new `FunctionParserBase` daughter class. The information read is stored by the `ConfigBase` daughter classes (these are data classes to be specific, and can ideally by just structs, but they use some object-oriented features, requiring them to be classes). Adding a new stepper type should include adding a new `ConfigBase` daughter class. The `read` method of the `ReaderBase` daughter classes accept a pointer of the type `CLI::App` and return a pointer to an object of the type of one of the daughter classes of `ConfigBase`. The `Reader` classes further implement helper methods for reading and parsing different things, and functions for constructing the `ConfigBase` object itself. Similarly, the `parse` function of the `FunctionParser` classes takes in a `string` and returns a C++ function (parses a specific type of function). The classes also include helper methods for parsing functions, and a method (in `FunctionParserBase`) to infer the type of the function (from the string) and dispatch the appropriate daughter class objects (and methods) to parse the function. In the future, it would make sense to add a wrapper around `Reader` classes to abstract `Config` creation and pointer manipulation from the `main` function (just how it is done by the `Solver` and `Writer` classes).
52
+
53
+
### Solver and Steppers
54
+
55
+
Solving non-linear equation is completely handled by two classes: `Solver` and `StepperBase`. `StepperBase` has specialized child classes for each method (for now: Newton-Raphson, Bisection, Chords, Fixed Point).
56
+
The `Solver` class is constructed with the data stored in `ConfigBase` child classes, and has methods to manage the high-level API involved in solving an equation. The `solve` method of the `Solver` class comprises of multiple internal calls, mainly involving convergence check, results saving, instantiating an object of one of the specialized `StepperBase` child classes, and calling the relevant method to compute single step of the numerical method.
57
+
58
+
`Solver` has no child classes but it could be refactored to be child of a `SolverBase` class (refactoring and abstracting common steps, such as the convergence check and the solve loop). The refactored `SolverNonLinear` class would inherit all the methods from the abstract class and add arguments for the functions and the boolean to require Aitken's acceleration. The new `SolverNonLinear` could have child classes for solving single equations (our current `Solver`) or systems of equations, which would differ just in the type of the arguments saved (e.g. derivative/jacobian for Newton-Raphson). This draft idea, which could be substituted by a fully templated version of the `SolverNonLinear` class, comes from the fact that templating is already used to define the different kinds of initial guesses allowed, and it is not possible (in C++) to partially specialize different templates. Another more brute-force idea could be to define all the different arguments as matrices and then use them as 1 X 1 matrices (or vectors) for the single equation case, without creating two daughter classes. All of these ideas would have to be adapted for the `Stepper` classes too.
41
59
42
-
#### Dependencies for the project
60
+
`Solver::solve` declares a `StepperBase` pointer and later instantiates it to point to an object of one of its child class, passing down all the required arguments to use for a single step computation. The only public method executed by the `Stepper`s is `compute_step`, which computes a single step of the numerical method and returns the results. To allow more numerical methods, it is possible to simply define new child classes with different `compute_step` algorithms and potentially different arguments to store.
43
61
44
-
##### Required
62
+
### Writer and Printers
63
+
64
+
The writing part of the project is handled by two classes: `Writer` and `PrinterBase`, with `PrinterBase` having child classes for each output type. The output type and other relevant information is carried down through the `ConfigBase` classes (defined by the `Reader`s). Importantly, these classes are not only defined for our specific project, but can write anything correctly passed (potentially with slight refactoring of the code). The classes' methods are implemented just for the type required in our project, but different typed versions would be easy to add.
65
+
66
+
`Writer` stores what to write and how, the writing method, and implements a high-level `write` method to instantiate an object of one of the `PrinterBase` child classes. `PrinterBase` has child classes specialized for certain output types, all of which have an overwritten `write_values` method which prints a given input on a stored output. To allow different writing destinations, new child classes can be defined inheriting from the existing ones.
67
+
68
+
## Dependencies
69
+
70
+
### Dependencies for the project
71
+
72
+
#### Required
45
73
46
74
The required dependencies are included within the project as git submodules and are pinned to specific
47
75
versions for reproducibility.
48
76
49
77
-`CLI11` (`v2.6.1`): for constructing the CLI interface for the user-facing `root_cli` application.
50
78
-`Eigen3` (`v5.0.1`): for matric and vector usage / calculations.
51
79
52
-
#####Optional
80
+
#### Optional
53
81
54
82
These can be installed by a user and are not installed through the project's build system.
55
83
56
84
-`gnuplot`: for plotting results
57
85
58
-
####Required dependencies for the tests
86
+
### Required dependencies for the tests
59
87
60
88
`gnuplot` must be installed before building the project with `-DTEST=ON`. `GoogleTest` is installed automatically if the project is built with `-DTEST=ON`.
61
89
62
90
-`GoogleTest` (`v1.17.0`): for all tests.
63
91
-`gnuplot`: for testing `gnuplot` related code.
64
92
65
-
####Dependencies for the documentation
93
+
### Dependencies for the documentation
66
94
67
95
These can be installed by a user and are not installed through the project's build system.
68
96
69
-
#####Required
97
+
#### Required
70
98
71
99
-`doxygen`: for generating the documentation.
72
100
73
-
#####Optional
101
+
#### Optional
74
102
75
103
-`graphviz`: for generating hierarchy and flow diagrams in the documentation.
76
104
@@ -142,7 +170,8 @@ root_cli <arguments>
142
170
In order to print out more information about the arguments and the subcommands:
143
171
144
172
```
145
-
root_cli <arguments>
173
+
root_cli --help
174
+
root_cli <subcommand> --help
146
175
```
147
176
148
177
Every additional needed function must be added together with the function to find the root of.
@@ -154,60 +183,63 @@ Here's a list of examples of possible execution syntax:
154
183
root_cli --wcli cli --function "x^2-4" newton --initial 1.0 --derivative "2*x"
155
184
```
156
185
157
-
- DAT input file called input.dat with first row not being header and " " separating different values, .dat file output called output.dat, Bisection method to find the root of x^3-1, with initial interval [-2,2], verbose output (given tolerance and maximum iterations):
186
+
- DAT input file called input.dat, DAT output file called output.dat, Bisection method to find the root of x^3-1, with initial interval [-2,2], and verbose output (given tolerance and maximum iterations):
158
187
159
188
```
160
-
root_cli --verbose --wdat output dat input
189
+
root_cli --verbose --wdat output dat --file input.dat
161
190
```
162
191
163
192
where input.dat is:
164
193
165
194
```
166
195
function = x^3-1
167
196
method = bisection
168
-
initial = -1
197
+
interval_a = -2
198
+
interval_b = 2
169
199
tolerance = 1e-5
170
200
max-iterations = 100
171
201
derivative = 2*x
172
202
```
173
203
174
-
- CSV input file called input.csv with first row which is a header and "," separating different values, .csv file ouput
175
-
called output.csv, Fixed Point Method to find the root of cos(x), with
176
-
initial guess 0.5, fixed point function cos(x):
204
+
- CSV input file called input.csv with first row which is a header and "," separating different values, CSV output file called output.csv, Fixed Point Method to find the root of x^2-x, with initial guess 0.5, fixed point function x^2, and verbose output (given tolerance and maximum iterations)::
And the shared library can be used inside `cxx` files using:
230
+
- CLI input, DAT output file called output.dat, gnuplot writing method (a GNU Plot named output.png is created), Chords method to solve the equation x^3-8 starting from the two initial points 1 and 3:
Input reading is handled by a CLI implemented using `CLI11`, which passes the read options to the appropriate `ReaderBase` daughter class. The `read` method of the `ReaderBase` daughter classes construct and return a `ConfigBase` daughter class object. The `ReaderBase` daughter classes also use the `FunctionParserBase` daughter classes internally to parse the function (and derivation + g function) inputted by user (string to a C++ function). The information stored in `ConfigBase` daughter classes is then passed down to the `Solver` class to run the algorithm.
239
+
240
+
The `solve` method of `Solver` constructs a `StepperBase` child class object, handles its methods calls, and finally returns the matrix of the results of the computation performed. `compute_step` method of each `StepperBase` child class gets the previous iteration and computes and returns the new guess, which will be saved and checked by `Solver`'s methods. The final results returned by `solve` are then passed down to the `Writer` class to write them.
241
+
242
+
The `write` method of `Writer` construct a `PrinterBase` child class object, and handles its methods calls. `write_values` method of each `StepperBase` child class gets a certain value to be printed and prints it out in a defined destination.
211
243
212
244
## Tests
213
245
@@ -315,4 +347,14 @@ which will write the HTML files to `docs/html`.
315
347
316
348
### Building docs on GH Pages
317
349
318
-
The documentation is automatically built (on every PR) and deployed (on every push to `main`) to GH Pages using the `build-and-deploy-docs` workflow.
350
+
The documentation is automatically built (on every PR) and deployed (on every push to `main` here - [https://saransh-cpp.github.io/ROOT/](https://saransh-cpp.github.io/ROOT/)) to GH Pages using the `build-and-deploy-docs` workflow.
351
+
352
+
## Limitations and problems
353
+
354
+
Most of the limitations and problems can be found as independent issues in the [issue tracker on GitHub](https://github.com/Saransh-cpp/ROOT/issues), or in the previous Project Structure section.
355
+
356
+
## Authors and their contributions
357
+
358
+
-**Andrea Saporito** ([@andreasaporito](https://github.com/andreasaporito)): Stepper, Solver, Writer, Printer classes/functionalities, most of the integration tests and some unit tests, and some fixes/refactoring here and there (touching Reader and Parser classes/functionalities, and the build system).
359
+
360
+
-**Saransh Chopra** ([@Saransh-cpp](https://github.com/Saransh-cpp)): Top-level CLI executable/application, Reader and Parser classes/functionalities, Project infrastructure (build system {code, docs, tests}, project structure, CI/CD), most of the unit tests and some integration tests, and some refactoring here and there (touching Stepper, Solver, Writer, and Printer classes/functionalities).
0 commit comments