w06-bsc-g04-class-basics
Class basics : NodalArrayUInt
In this example, we explore the basics of Classes in C++. For this
purpose, we have creared a NodalArrayUInt
class. The class interface
nodal_array_uint.hpp
and the implementation nodal_array_uint.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 NodalArrayUInt
and its various
functions is added in the folder tehpc/basics
.
Go into tehpc/basics/
. Consider the following code:
g04_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 thatg04_class_basics
is included in compilation - go into the
tehpc/build/
folder (possibly in another terminal) - type:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_BASICS:STRING=ON ..
(you only have to do this the very first time). - type:
make
(do this whenever you want to recompile). - To run the complied code, go into
tehpc/build/basics/
. - type:
./g04_class_basics
.
Obeserve the output and the implementation in the file
g04_class_basics.cpp
and answer the following questions as comments direclty on your MR.
-
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
g04_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 keywordinline
signifies? -
The nodal array class defined in
nodal_array_uint.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? -
Could you use this 'NodalArrayUInt' class to store floating point numbers?