-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from luca-heltai/lab-03
Added lab 03.
- Loading branch information
Showing
17 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
compile_commands.json | ||
build-container | ||
doc/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.15) | ||
|
||
PROJECT(gtest) | ||
|
||
FIND_PACKAGE(deal.II 9.3 REQUIRED | ||
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}) | ||
|
||
DEAL_II_INITIALIZE_CACHED_VARIABLES() | ||
|
||
# Executable | ||
FILE(GLOB executable_files source/*cc) | ||
ADD_EXECUTABLE(step-3 ${executable_files}) | ||
DEAL_II_SETUP_TARGET(step-3) | ||
|
||
# Library of the executable | ||
ADD_LIBRARY(step-3-lib SHARED $<TARGET_OBJECTS:step-3>) | ||
DEAL_II_SETUP_TARGET(step-3-lib) | ||
|
||
# Tester executable | ||
FIND_PACKAGE(GTest REQUIRED) | ||
FILE(GLOB test_files tests/*cc) | ||
ADD_EXECUTABLE(gtest ${test_files}) | ||
TARGET_LINK_LIBRARIES(gtest ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY} step-3-lib) | ||
DEAL_II_SETUP_TARGET(gtest) | ||
|
||
INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS} ./include/) | ||
|
||
ENABLE_TESTING() | ||
GTEST_DISCOVER_TESTS(gtest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Theory and Practice of FEM | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Lab 03 - Poisson Problem | ||
## The finite element method using deal.II | ||
|
||
**Luca Heltai** <[email protected]> | ||
|
||
* * * * * | ||
|
||
## General Instructions | ||
|
||
For each of the point below, extend the `step-3` class with functions that | ||
perform the indicated tasks, trying to minimize the amount of code you copy | ||
and paste, possibly restructuring existing code by adding arguments to existing | ||
functions, and generating wrappers similar to the `run` method (e.g., | ||
`run_exercise_3`). | ||
|
||
Once you created a function that performs the given task, add it to the | ||
`step-3-tester.cc` file, and make sure all the exercises are run through | ||
the `gtest` executable, e.g., adding a test for each exercise, as in the | ||
following snippet: | ||
|
||
```C++ | ||
TEST_F(Step3Tester, Exercise3) { | ||
run_exercise_3(); | ||
} | ||
``` | ||
By the end of this laboratory, you will have a code that solves a Poisson | ||
problem in two dimensions, on different domain types, with arbitrary right hand | ||
side, arbitrary Dirichlet boundary conditions, variable finite element degree, | ||
and different levels of refinement. | ||
The program will read parameter files for its execution. This is the minimal | ||
starting point for simple but extensible Finite Element applications, and | ||
touches already many important and fundamental characteristics of general and | ||
extensible Finite Element codes. | ||
## Lab-03 | ||
### step-3 | ||
1. See documentation of step-3 at | ||
<https://www.dealii.org/current/doxygen/deal.II/step_3.html> | ||
2. Compile and run step-3. Examine the source and header files. Move all | ||
`#include<...>` directives that you can from the header `step-3.h` to | ||
the source file `step-3.cc`. | ||
3. Open the vtk output and visualize the solution in paraview or visit. | ||
Figure out how to warp the solution by the solution variable. Save a picture | ||
of your visualization on the `figures` subdirectory, named `step-3-0.png`, | ||
and commit it to your repository. | ||
4. Follow the instructions in “Modify the type of boundary condition” | ||
in the description of the tutorial, plot your output, and save a figure in | ||
the `figures` subdirectory, named `step-3-1.png`, and commit it to your | ||
repository. Make sure the test is run through `gtest`. | ||
5. Now also do “A slight variation of the last point” but use the value | ||
-0.5 for the boundary with indicator 1. Save your output as `step-3-2.png`, | ||
and commit it to the `figures` directory in your repository. Make sure the | ||
test is run through `gtest`. | ||
6. Change the setup to have $f=0$. Save your output as `step-3-3.png`, | ||
and commit it to the `figures` directory in your repository. Make sure the | ||
test is run through `gtest`. | ||
7. Switch to an L-shaped domain and experiment with a combination of | ||
Dirichlet and Neumann boundary conditions. By experimentation, identify | ||
the faces adjacent to the re-entrant corner and apply Dirichlet conditions | ||
only there. Save your output as `step-3-4.png`, | ||
and commit it to the `figures` directory in your repository. Make sure the | ||
test is run through `gtest`. | ||
8. Bonus: Do “Convergence of the mean”. Can you see the order $h^2$? | ||
Increase the polynomial order (you need to increase all orders of | ||
the quadratures in the program!) and check the convergence of the | ||
mean now. Make sure the test is run through `gtest`. | ||
### ParameterHandler | ||
1. Follow the documentation of the class `ParameterAcceptor` | ||
(from "A typical usage of this class"). Derive your `Step3` class from | ||
`ParameterAcceptor`, and initialize the `ParameterAcceptor` class using | ||
the string `"Step3"`. Add a function that initializes the class given a | ||
parameter file name, i.e., `initialize("parameters.prm")`, by calling | ||
`ParameterAcceptor::initialize(...)` | ||
2. Add the following parameters to your `Step3` class, and make sure they | ||
are used throughout your code | ||
- Finite element degree | ||
- Number of global refinements | ||
- Output filename | ||
Notice that the `FE_Q` class will need to be built *after* the | ||
initialization of the Finite element degree variable. You can create | ||
it right before you use it, and then reference to it by | ||
`DoFHandler::get_fe()` when you need it later. | ||
3. Add two `FunctionParser<2>` members to your `Step3` class, one for the | ||
boundary conditions, and one for the forcing term. Add two `std::string` | ||
members, representing their mathematical expressions, and a | ||
`std::map<std::string, double>` representing the constants to use in your | ||
mathematical expression, and make sure they are added as parameters of your | ||
class as | ||
- Forcing term expression | ||
- Boundary condition expression | ||
- Problem constants | ||
and initialize the two `FunctionParser<2>` objects with the given | ||
expressions and the given constants. Make sure your `Step3` class uses | ||
these two functions where the boundary conditions are computed and where | ||
the right hand side is assembled | ||
4. Following the ideas in `step-70`, add two additional parameters to the | ||
`Step3` class to select at run time what grid to create, and with what | ||
arguments. Use as parameters | ||
- Grid generator function | ||
- Grid generator arguments | ||
5. Test your application with all the files in the `parameters` subdirectory, | ||
(running the test through the `gtest` application), and create a | ||
visualization for each of the given parameters, with the same | ||
name of the parameter file, i.e., the visualization of the test that runs | ||
`parameters/hyper_shell.prm` should be saved on an image named `figures/hyper_shell.png`. Commits all your generated figures. | ||
Notice that for older versions of google test, you may need to run each | ||
test individually (this is a known issue between google testsuite and the | ||
`ParameterAcceptor` class). To run an individual test, you can use the | ||
`--gtest_filter` command line option, i.e., the following command | ||
``` | ||
./gtest --gtest_filter=Step3Tester.HyperShell | ||
``` | ||
will run only the test `Step3Tester.HyperShell`. | ||
If you want to run all tests one after the other you can call the `ctest` | ||
utility, which will execute the `gtest` command passing the gtest filter for | ||
each of the tests you provided, producing, for example, an output similar | ||
to: | ||
``` | ||
dealii@66c3be678611:/workspace/sissa-mhpc-lab-03/build-container$ ctest | ||
Test project /workspace/sissa-mhpc-lab-03/build-container | ||
Start 1: Step3Tester.MakeGrid | ||
1/6 Test #1: Step3Tester.MakeGrid ............. Passed 0.68 sec | ||
Start 2: Step3Tester.HyperCube | ||
2/6 Test #2: Step3Tester.HyperCube ............ Passed 0.78 sec | ||
Start 3: Step3Tester.HyperShell | ||
3/6 Test #3: Step3Tester.HyperShell ........... Passed 1.90 sec | ||
Start 4: Step3Tester.HyperBall | ||
4/6 Test #4: Step3Tester.HyperBall ............ Passed 1.28 sec | ||
Start 5: Step3Tester.SinRhs | ||
5/6 Test #5: Step3Tester.SinRhs ............... Passed 0.79 sec | ||
Start 6: Step3Tester.SinBc | ||
6/6 Test #6: Step3Tester.SinBc ................ Passed 1.26 sec | ||
100% tests passed, 0 tests failed out of 6 | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* --------------------------------------------------------------------- | ||
* | ||
* Copyright (C) 1999 - 2020 by the deal.II authors | ||
* | ||
* This file is part of the deal.II library. | ||
* | ||
* The deal.II library is free software; you can use it, redistribute | ||
* it, and/or modify it under the terms of the GNU Lesser General | ||
* Public License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* The full text of the license can be found in the file LICENSE.md at | ||
* the top level directory of deal.II. | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* Authors: Wolfgang Bangerth, 1999, | ||
* Guido Kanschat, 2011 | ||
* Luca Heltai, 2021 | ||
*/ | ||
|
||
// Make sure we don't redefine things | ||
#ifndef step3_include_file | ||
#define step3_include_file | ||
|
||
#include <deal.II/base/function.h> | ||
#include <deal.II/base/quadrature_lib.h> | ||
|
||
#include <deal.II/dofs/dof_handler.h> | ||
#include <deal.II/dofs/dof_tools.h> | ||
|
||
#include <deal.II/fe/fe_q.h> | ||
#include <deal.II/fe/fe_values.h> | ||
|
||
#include <deal.II/grid/grid_generator.h> | ||
#include <deal.II/grid/tria.h> | ||
|
||
#include <deal.II/lac/dynamic_sparsity_pattern.h> | ||
#include <deal.II/lac/full_matrix.h> | ||
#include <deal.II/lac/precondition.h> | ||
#include <deal.II/lac/solver_cg.h> | ||
#include <deal.II/lac/sparse_matrix.h> | ||
#include <deal.II/lac/vector.h> | ||
|
||
#include <deal.II/numerics/data_out.h> | ||
#include <deal.II/numerics/matrix_tools.h> | ||
#include <deal.II/numerics/vector_tools.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
// Forward declare the tester class | ||
class Step3Tester; | ||
|
||
using namespace dealii; | ||
class Step3 | ||
{ | ||
public: | ||
Step3(); | ||
void | ||
run(); | ||
|
||
protected: | ||
void | ||
make_grid(); | ||
void | ||
setup_system(); | ||
void | ||
assemble_system(); | ||
void | ||
solve(); | ||
void | ||
output_results() const; | ||
|
||
Triangulation<2> triangulation; | ||
FE_Q<2> fe; | ||
DoFHandler<2> dof_handler; | ||
SparsityPattern sparsity_pattern; | ||
SparseMatrix<double> system_matrix; | ||
Vector<double> solution; | ||
Vector<double> system_rhs; | ||
|
||
friend class Step3Tester; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Listing of Parameters | ||
# --------------------- | ||
subsection Step3 | ||
set Boundary condition expression = 0 | ||
set Finite element degree = 1 | ||
set Forcing term expression = 1 | ||
set Grid generator arguments = 0,0: 1: false | ||
set Grid generator function = hyper_ball | ||
set Number of global refinements = 4 | ||
set Output filename = hyper_ball.vtk | ||
set Problem constants = | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Listing of Parameters | ||
# --------------------- | ||
subsection Step3 | ||
set Boundary condition expression = 0 | ||
set Finite element degree = 1 | ||
set Forcing term expression = 1 | ||
set Grid generator arguments = 0: 1: false | ||
set Grid generator function = hyper_cube | ||
set Number of global refinements = 4 | ||
set Output filename = hyper_cube.vtk | ||
set Problem constants = | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Listing of Parameters | ||
# --------------------- | ||
subsection Step3 | ||
set Boundary condition expression = 0 | ||
set Finite element degree = 1 | ||
set Forcing term expression = 1 | ||
set Grid generator arguments = 0,0: .5: 1.: 0: false | ||
set Grid generator function = hyper_shell | ||
set Number of global refinements = 4 | ||
set Output filename = hyper_shell.vtk | ||
set Problem constants = | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Listing of Parameters | ||
# --------------------- | ||
subsection Step3 | ||
set Boundary condition expression = sin(omega*pi*x)*sin(omega*pi*y) | ||
set Finite element degree = 1 | ||
set Forcing term expression = 0 | ||
set Grid generator arguments = 0,0: 1: false | ||
set Grid generator function = hyper_ball | ||
set Number of global refinements = 4 | ||
set Output filename = sin_bc.vtk | ||
set Problem constants = pi:3.141592653589793, omega:2 | ||
end | ||
|
||
|
Oops, something went wrong.