w06-bsc-g03-class-basics
Class basics : NodalArray
In this example, we explore the basics of Classes in C++. For this
purpose, we have creared a NodalArray
class. The class interface
nodal_array.hpp
and the implementation nodal_array.cpp
are in folder
tehpc/src
. Please go through the two files and observe its
various member variables and member functions.
An example on how to usage the class NodalArray
and its various
functions is added in the folder tehpc/basics
.
Go into tehpc/basics/
. Consider the following code:
g03_class_basics.cpp
Compile the code with
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
consider
tehpc/basics/CMakeLists.txt
and make sure thatg03_class_basics
is included in compilation -
type:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_BASICS:STRING=ON ..
(you only have to do this the very first time). -
go into the
tehpc/build/
folder (possibly in another terminal) -
type:
make
(do this whenever you want to recompile). -
To run the complied code, go into
tehpc/build/basics/
. Obeserve the output and the implementation in the fileg03_class_basics.cpp
and answer the following questions as comments direclty on your MR. -
type:
./g03_class_basics
.
-
You will see that to define a vector we have used the type
std::vector<double>
from#include <vector>
. How is it different from thedouble*
type that we have been using till now to define a vector? What are the advantages ofstd::vector
overdouble*
? Isstd::vector
a class? -
In the example
g03_class_basics.cpp
we are performing various mathematical operations such as initializing a nodal array to value 1, array-scalar multiplication and printing matrix usingstd::cout
. What are the specific member functions innodal_array.hpp
that allow us to perform all these operations? What is this practice generally referred to as and how is it useful? Check the member functionoperator<<
innodal_array.hpp
and its implementation innodal_array_inline.hpp
. What does the keywordfriend
signifies? -
The nodal array class defined in
nodal_array.hpp
usesoperator()(UInt i, UInt j)
to access and to store values at row i and column j. What is so special about the way entries are stored and is there an advantage of storing the values in that manner? -
There is a file
nodal_array.cpp
included in thesrc
folder? What is so peculiar about this file? Is it necessary to add this file?