CMBM-public issueshttps://gitlab.ethz.ch/groups/cmbm-public/-/issues2024-03-25T15:38:53Zhttps://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/23w06-g04-model-read-input2024-03-25T15:38:53ZDavid Kammerw06-g04-model-read-input# Model Class for Read Input
## Objective
The overall objective of this assignment is to implement parts of the `Model` class for the Direct Stiffness Method. For now, we will only implement the part of the `Model` class to read the r...# Model Class for Read Input
## Objective
The overall objective of this assignment is to implement parts of the `Model` class for the Direct Stiffness Method. For now, we will only implement the part of the `Model` class to read the relevant input.
The code from last week `tehpc/examples/read_input_function.cpp` can be recycled (by copy-paste), but will require modifications.
Most of the interface of the `Model` class is already implemented in `tehpc/src/model.hpp`, and is used in a test `tehpc/tests/model_read_input.cpp`. You have to implement the relevant methods of the `Model` class in `tehpc/src/model.cpp`.
## Implementation
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
1. If `model.cpp` is not already included at the appropriate place in `tehpc/src/CMakeLists.txt`, add it. This makes sure that it is compiled.
2. Add `tehpc_add_test(model_read_input)` in the `tehpc/tests/CMakeLists.txt` to include the `model_read_input` test in compilation.
3. Compile your code, use the following steps (this is new):
a. go into `tehpc/build/`
b. type: either `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..` or `ccmake ..` and make sure that build type is `Debug` and `Tests` are ON (you only have to do this the very first time).
c. type: `make` (do this whenever you want to recompile).
4. Correct all compilation errors. Use code from `tehpc/basics/read_input_function.cpp` to implement `tehpc/src/model.cpp`. Also, move `tehpc/basics/input_file.hpp` to `tehpc/src/` and make sure that it is considered in compilation (similar to above). **Important**: you are not allowed to change the `model_read_input.cpp` file.
5. If the code compiles without errors, run the test:
a. go into `tehpc/build/tests/`
b. type: `./model_read_input`
6. Make sure that the code runs without error and check printed message to see if it went to the end. Correct errors if needed. Again, you are not allowed to change the `model_read_input.cpp` files.
7. run valgrind to check for memory leakage: `valgrind --leak-check=full ./model_read_input`
8. correct memory leakage
9. Make sure that your code is well structured and commented.https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/22w06-g03-model-class-assembly2024-03-25T09:41:15ZDavid Kammerw06-g03-model-class-assembly# Model Class for Assembly
## Objective
The overall objective of this assignment is to implement parts of the `Model` class for the Direct Stiffness Method. For now, we will only implement the part of the `Model` class to assemble the...# Model Class for Assembly
## Objective
The overall objective of this assignment is to implement parts of the `Model` class for the Direct Stiffness Method. For now, we will only implement the part of the `Model` class to assemble the stiffness matrix.
The code from last week `tehpc/examples/matrix_assembly_function.cpp` can be recycled (by copy-paste), but will require modifications.
Most of the interface of the `Model` class is already implemented in `tehpc/src/model.hpp`, and is used in a test `tehpc/tests/model_assembly.cpp`. You have to implement the relevant methods of the `Model` class in `tehpc/src/model.cpp`.
## Implementation
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
1. If `model.cpp` is not already included at the appropriate place in `tehpc/src/CMakeLists.txt`, add it. This makes sure that it is compiled.
2. Add `tehpc_add_test(model_assembly)` in the `tehpc/tests/CMakeLists.txt` to include the `model_assembly` test in compilation.
3. Compile your code, use the following steps (this is new):
a. go into `tehpc/build/`
b. type: either `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..` or `ccmake ..` and make sure that build type is `Debug` and `Tests` are ON (you only have to do this the very first time).
c. type: `make` (do this whenever you want to recompile).
4. Correct all compilation errors. Use code from `tehpc/basics/matrix_assembly_function.cpp` to implement `tehpc/src/model.cpp`. **Important**: you are not allowed to change the `model_assembly.cpp` file.
5. If the code compiles without errors, run the test:
a. go into `tehpc/build/tests/`
b. type: `./model_assembly`
6. Make sure that the code runs without error and check printed message to see if it went to the end. Correct errors if needed. Again, you are not allowed to change the `model_assembly.cpp` files.
7. run valgrind to check for memory leakage: `valgrind --leak-check=full ./model_assembly`
8. correct memory leakage
9. Make sure that your code is well structured and commented.https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/21w06-g02-CGsolver-class2024-03-25T09:30:52ZDavid Kammerw06-g02-CGsolver-class# Conjugate Gradient Solver (CGsolver) Class
## Objective
The overall objective of this assignment is to implement the Conjugate Gradient Method in a class `CGsolver`. This solver will later be part of the class project Direct Stiffness...# Conjugate Gradient Solver (CGsolver) Class
## Objective
The overall objective of this assignment is to implement the Conjugate Gradient Method in a class `CGsolver`. This solver will later be part of the class project Direct Stiffness Method.
The code for this class needs to be split into a header file `.hpp` and its implementation in the `.cpp` file. Most of the interface of the `CGsolver` class is already implemented in `tehpc/src/conjugate_gradient_solver.hpp`, and is used in a simple test `tehpc/tests/CGsolver_test.cpp`. You have to implement the method `solve` of the `CGsolver` class in `tehpc/src/conjugate_gradient_solver.cpp`.
Please recycle the code from last week `tehpc/examples/conjugate_gradient_function.cpp` (method described in details in #2).
## Implementation
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
1. If `conjugate_gradient_solver.cpp` is not already included at the appropriate place in `tehpc/src/CMakeLists.txt`, add it. This makes sure that it is compiled.
2. Add `tehpc_add_test(CGsolver_test)` in the `tehpc/tests/CMakeLists.txt` to include the `CGsolver_test` in compilation.
3. Compile your code, use the following steps (this is new):
a. go into `tehpc/build/`
b. type: either `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..` or `ccmake ..` and make sure that build type is `Debug` and `Tests` are ON (you only have to do this the very first time).
c. type: `make` (do this whenever you want to recompile).
4. Correct all compilation errors. Use code from `tehpc/basics/conjugate_gradient_function.cpp` and the provided operator overloading (see `tehpc/src/matrix.hpp`, `tehpc/src/vector.hpp` and others) to implement `tehpc/src/conjugate_gradient_solver.cpp`. **Important**: you are not allowed to change the `CGsolver_test.cpp` file.
5. If the code compiles without errors, run the test:
a. go into `tehpc/build/tests/`
b. type: `./CGsolver_test`
6. Make sure that the code runs without error and check printed message to see if it went to the end. Correct errors if needed. Again, you are not allowed to change the `CGsolver_test.cpp` files.
7. run valgrind to check for memory leakage: `valgrind --leak-check=full ./CGsolver_test`.
8. correct memory leakage
9. Make sure that your code is well structured and commented.https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/20w06-g01-NRsolver-class2024-03-25T09:48:55ZDavid Kammerw06-g01-NRsolver-class# Newton Raphson Solver (NRsolver) Class
## Objective
The overall objective of this assignment is to implement the Newton Raphson Method in a class `NRsolver`. This solver will later be part of the class project Direct Stiffness Method....# Newton Raphson Solver (NRsolver) Class
## Objective
The overall objective of this assignment is to implement the Newton Raphson Method in a class `NRsolver`. This solver will later be part of the class project Direct Stiffness Method.
The code for this class needs to be split into a header file `.hpp` and its implementation in the `.cpp` file. Most of the interface of the `NRsolver` class is already implemented in `tehpc/src/newton_raphson_solver.hpp`, and is used in a simple test `tehpc/tests/NRsolver_test.cpp`. You have to implement the method `solve` of the `NRsolver` class in `tehpc/src/newton_raphson_solver.cpp`.
Please recycle the code from last week `tehpc/basics/newton_raphson_function.cpp`. (method described in details in #1)
## Implementation
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
1. If `newton_raphson_solver.cpp` is not already included at the appropriate place in `tehpc/src/CMakeLists.txt`, add it. This makes sure that it is compiled.
2. Add `tehpc_add_test(NRsolver_test)` in the `tehpc/tests/CMakeLists.txt` to include the `NRsolver_test` in compilation.
3. Compile your code, use the following steps (this is new):
a. go into `tehpc/build/`
b. type: either `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..` or `ccmake ..` and make sure that build type is `Debug` and `Tests` are ON (you only have to do this the very first time).
c. type: `make` (do this whenever you want to recompile).
4. Correct all compilation errors. Use code from `tehpc/basics/newton_raphson_function.cpp` and the provided operator overloading (see `tehpc/src/matrix.hpp`, `tehpc/src/vector.hpp` and others) to implement `tehpc/src/newton_raphson_solver.cpp`. **Important**: you are not allowed to change the `NRsolver_test.cpp` file.
5. If the code compiles without errors, run the test:
a. go into `tehpc/build/tests/`
b. type: `./NRsolver_test`
6. Make sure that the code runs without error and check printed message to see if it went to the end. Correct errors if needed. Again, you are not allowed to change the `NRsolver_test.cpp` files.
7. run valgrind to check for memory leakage: `valgrind --leak-check=full ./NRsolver_test`.
8. correct memory leakage
9. Make sure that your code is well structured and commented.https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/19w06-bsc-g04-class-basics2024-03-25T10:21:12ZDavid Kammerw06-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.c...# 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:
1. `g04_class_basics.cpp`
Compile the code with
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
0. consider `tehpc/basics/CMakeLists.txt` and make sure that `g04_class_basics` is included in compilation
1. go into the `tehpc/build/` folder (possibly in another terminal)
2. type: `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_BASICS:STRING=ON ..` (you only have to do this the very first time).
3. type: `make` (do this whenever you want to recompile).
4. To run the complied code, go into `tehpc/build/basics/`.
5. 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 the `double*` type that we have been using till now to define a
vector? What are the advantages of `std::vector` over `double*`? Is
`std::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 using
`std::cout`. What are the specific member functions in
`nodal_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 function `operator<<` in `nodal_array.hpp` and its
implementation in `nodal_array_inline.hpp`. What does the keyword
`inline` signifies?
- The nodal array class defined in `nodal_array_uint.hpp` uses
`operator()(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?https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/18w06-bsc-g03-class-basics2024-03-25T10:40:45ZDavid Kammerw06-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
...# 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:
1. `g03_class_basics.cpp`
Compile the code with
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
0. consider `tehpc/basics/CMakeLists.txt` and make sure that `g03_class_basics` is included in compilation
2. type: `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_BASICS:STRING=ON ..` (you only have to do this the very first time).
1. go into the `tehpc/build/` folder (possibly in another terminal)
3. type: `make` (do this whenever you want to recompile).
4. To run the complied code, go into `tehpc/build/basics/`.
Obeserve the output and the implementation in the file
`g03_class_basics.cpp` and answer the following questions as comments direclty on your MR.
5. 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 the `double*` type that we have been using till now to define a
vector? What are the advantages of `std::vector` over `double*`? Is
`std::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 using
`std::cout`. What are the specific member functions in
`nodal_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 function `operator<<` in `nodal_array.hpp` and its
implementation in `nodal_array_inline.hpp`. What does the keyword
`friend` signifies?
- The nodal array class defined in `nodal_array.hpp` uses `operator()(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 the `src` folder? What
is so peculiar about this file? Is it necessary to add this file?https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/17w06-bsc-g02-class-basics2024-03-25T10:14:42ZDavid Kammerw06-bsc-g02-class-basics# Class basics : MatrixUInt
In this example, we explore the basics of Classes in C++. For this
purpose, we have converted the `matrix` pointer implemented in the
last few examples into a class `MatrixUInt`. The class interface
`matrix_...# Class basics : MatrixUInt
In this example, we explore the basics of Classes in C++. For this
purpose, we have converted the `matrix` pointer implemented in the
last few examples into a class `MatrixUInt`. The class interface
`matrix_uint.hpp` and the implementation `matrix_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 `MatrixUInt` and its various
functions is added in the folder `tehpc/basics`.
Go into `tehpc/basics/`. Consider the following code:
1. `g02_class_basics.cpp`
Compile the code with
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
0. consider `tehpc/basics/CMakeLists.txt` and make sure that `g02_class_basics` is included in compilation
1. go into the `tehpc/build/` folder (possibly in another terminal)
2. type: `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_EXAMPLES:BASICS=ON ..` (you only have to do this the very first time).
3. type: `make` (do this whenever you want to recompile).
4. To run the complied code, go into `tehpc/build/basics/`.
5. type: `./g02_class_basics`.
Obeserve the output and the implementation in the file
`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 the `double*` type that we have been using till now to define a
vector? What are the advantages of `std::vector` over `double*`? Is
`std::vector` a class?
- In the example `g02_class_basics.cpp` we are performing various matrix
operations such as initializing a matrix to value 1, matrix-scalar
multiplication, matrix-vector multiplication, matrix-matrix
multiplication and printing matrix using `std::cout`. What are the
specific member functions in `matrix_uint.hpp` that allow us to perform
all these matrix operations? What is this practice generally
referred to as and how is it useful? Check the member function
`transpose` in `matrix_uint.cpp`. How is it different from the function
`matrixTransposed` implemented in the last exercise session, check the
file `basics/matrices_operations.h`.
- The matrix class defined in `matrix_uint.hpp` uses `operator()(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? Check
the member function `determinant` in `matrix.cpp`.
- Could you use this 'MatrixUInt' class to store floating point
numbers?https://gitlab.ethz.ch/cmbm-public/teaching/tehpc/tehpc2024/-/issues/16w06-bsc-g01-class-basics2024-03-25T13:25:41ZDavid Kammerw06-bsc-g01-class-basics# Class basics : Matrix
In this example, we explore the basics of Classes in C++. For this
purpose, we have converted the `matrix` pointer implemented in the
last few examples into a class `Matrix`. The class interface
`matrix.hpp` and...# Class basics : Matrix
In this example, we explore the basics of Classes in C++. For this
purpose, we have converted the `matrix` pointer implemented in the
last few examples into a class `Matrix`. The class interface
`matrix.hpp` and the implementation `matrix.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 `Matrix` and its various
functions is added in the folder `tehpc/basics`.
Go into `tehpc/basics/`. Consider the following code:
1. `g01_class_basics.cpp`
Compile the code with
0. load appropriate modules by performing the following command in your terminal: `source tehpc/tools/tehpc_load_modules.sh`.
0. consider `tehpc/basics/CMakeLists.txt` and make sure that `g01_class_basics` is included in compilation
1. go into the `tehpc/build/` folder (possibly in another terminal)
2. type: `cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_BASICS:STRING=ON ..` (you only have to do this the very first time).
3. type: `make` (do this whenever you want to recompile).
4. To run the complied code, go into `tehpc/build/basics/`.
5. type: `./g01_class_basics`.
Obeserve the output and the implementation in the file
`g01_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 the `double*` type that we have been using till now to define a
vector? What are the advantages of `std::vector` over `double*`? Is
`std::vector` a class?
- In the example `g01_class_basics.cpp` we are performing various matrix
operations such as initializing a matrix to value 1, matrix-scalar
multiplication, matrix-vector multiplication, matrix-matrix
multiplication and printing matrix using `std::cout`. What are the
specific member functions in `matrix.hpp` that allow us to perform
all these matrix operations? What is this practice generally
referred to as and how is it useful? Check the member function
`inverse` in `matrix.cpp`. How is it different from the function
`inverseMatrix` implemented in the last exercise session, check the
file `basics/newton_raphson_function.cpp`.
- The matrix class defined in `matrix.hpp` uses `operator()(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?