w07-g01-NRsolver-inherited
Inherited Newton Raphson Solver (NRsolver) Class
Objective
The overall objective of this assignment is to implement an abstract nonlinear solver class NLsolver
, and make the current newton raphson solver NRsolver
inheritated from the parent class NLsolver
. The conjugate gradient solver class CGsolver
will be another child class of NLsolver
. This abstract solver class makes it possible to extend the project with more solvers without the need of modifying other classes.
Here, you need to implement an abstract nonlinear solver class NLsolver
in tehpc/src/nonlinear_solver.hpp
. Then you need to modify the newton raphson class NRsolver
in tehpc/src/newton_raphson_solver
(both .hpp
and .cpp
) into a child class of NLsolver
. Move as much functionality as possible while keeping the NLsolver
class general enough to allow also the CGsolver
to inherit from it.
Implementation
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
If
nonlinear_solver.hpp
is not already included at the appropriate place intehpc/src/CMakeLists.txt
, add it. This makes sure that it is compiled. -
Add
tehpc_add_test(NLsolver_test)
in thetehpc/tests/CMakeLists.txt
to include theNLsolver_test
in compilation. -
Compile your code, use the following steps:
a. go into
tehpc/build/
b. type:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..
or useccmake ..
to configure (you only have to do this the very first time).c. type:
make
(do this whenever you want to recompile). -
Implement the nonlinear solver class
NLsolver
intehpc/src/nonlinear_solver.hpp
and modify the newton raphson solverNRsolver
into a child class ofNLsolver
. Correct all compilation errors.a. compare
CGsolver
andNRsolver
, move the shared part into theNLsolver
, including the #include directive, members and member functions.b. make
NRsolver
inheritated fromNLsolver
. The use ofvirtual function
could help. Pay attention to the constructor and destructor.c. read
tehpc/tests/NLsolver_test.cpp
, especially the function that has a pointer to the abstract class as one of its arguments, and compare the way of creating an object to last week.d. If you have enough time, repeat the procees of making
NRsolver
inheritating fromNLsolver
by applying it also onCGsolver
. Otherwise, you might need to comment the part regardingCGsolver
in theNLsolver_test.cpp
. -
If the code compiles without errors, run the test
NLsolver_test
:a. go into
tehpc/build/tests/
b. type:
./NLsolver_test nr
-
Make sure that the test runs without error and returns success.
-
run valgrind to check for memory leakage:
valgrind --leak-check=full ./NLsolver_test nr
. Correct memory leakage if you encounter this problem. -
Make sure that your code is well structured and commented.
-
Generate the
doxygen
software catalogue for the entire project:a. go into
tehpc/build/
b. type:
ccmake .
and switch on the option forTEHPC_DOC
, and configure withc
and generate withg
c. type:
make
d. download the generated catalogue files in
tehpc/build/docs/doxygen
to your local computer and view it.e. IMPORTANT: you can use the same approach for your project (i.e. stage II) for that, you need to copy the Doxygen part of
tehpc/CMakeLists.txt
toyour-project/CMakeLists.txt
, and copy thetehpc/docs/CMakeLists.txt
andtehpc/docs/Doxyfile.in
to the equivalent directories of your project.