w07-g02-CGsolver-inherited
Inherited Conjugate Gradient Solver (CGsolver) Class
Objective
The overall objective of this assignment is to implement a abstract nonlinear solver class NLsolver
, and make the current conjugate gradient solver CGsolver
inheritated from the parent class NLsolver
. The newton-raphson solver class NRsolver
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 conjugate gradient class CGsolver
in tehpc/src/conjugate_gradient_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 NRsolver
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 conjugate gradient solverCGsolver
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
CGsolver
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
CGsolver
inheritating fromNLsolver
by applying it also onNRsolver
. Otherwise, you might need to comment the part regardingNRsolver
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 cg
-
Make sure that the test runs without error and returns success.
-
run valgrind to check for memory leakage:
valgrind --leak-check=full ./NLsolver_test cg
. 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.