The finite element method using deal.II - 2021/2022
step-1.cc
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------
2  *
3  * Copyright (C) 1999 - 2019 by the deal.II authors
4  *
5  * This file is part of the deal.II library.
6  *
7  * The deal.II library is free software; you can use it, redistribute
8  * it, and/or modify it under the terms of the GNU Lesser General
9  * Public License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  * The full text of the license can be found in the file LICENSE.md at
12  * the top level of the deal.II distribution.
13  *
14  * ---------------------------------------------------------------------
15  *
16  * based on deal.II step-1
17  */
18 
19 
21 #include <deal.II/grid/grid_out.h>
22 #include <deal.II/grid/tria.h>
25 
26 #include <cmath>
27 #include <fstream>
28 #include <iostream>
29 
30 using namespace dealii;
31 
32 
34 void
36 {
38 
39  std::cout << "Number of original vertices: " << triangulation.n_vertices()
40  << std::endl;
41 
42  triangulation.refine_global(4);
43 
44  std::cout << "Number of vertices after 4 refinements: "
45  << triangulation.n_vertices() << std::endl;
46  {
47  std::ofstream out("grid-1.svg");
48  GridOut grid_out;
49  grid_out.write_svg(triangulation, out);
50  std::cout << "Grid written to grid-1.svg" << std::endl;
51  }
52  {
53  std::ofstream out("grid-1.vtk");
54  GridOut grid_out;
55  grid_out.write_vtk(triangulation, out);
56  std::cout << "Grid written to grid-1.vtk" << std::endl;
57  }
58 }
59 
60 
62 void
64 {
65  const Point<2> center(1, 0);
66  const double inner_radius = 0.5, outer_radius = 1.0;
68  triangulation, center, inner_radius, outer_radius, 10);
69 
70  // triangulation.reset_all_manifolds();
71 
72  for (unsigned int step = 0; step < 5; ++step)
73  {
74  std::ofstream out("grid-2-" + std::to_string(step) + ".vtk");
75  GridOut grid_out;
76  grid_out.write_vtk(triangulation, out);
77 
78  for (auto &cell : triangulation.active_cell_iterators())
79  {
80  for (const auto v : cell->vertex_indices())
81  {
82  const double distance_from_center =
83  center.distance(cell->vertex(v));
84 
85  if (std::fabs(distance_from_center - inner_radius) <=
86  1e-6 * inner_radius)
87  {
88  cell->set_refine_flag();
89  break;
90  }
91  }
92  }
93 
94  triangulation.execute_coarsening_and_refinement();
95  }
96 }
97 
99 // `third_grid.vtk`. Refine the L-shaped mesh adaptively around the re-entrant
100 // corner three times (after the global refinement you already did), but with a
101 // twist: refine all cells with the distance between the center of the cell and
102 // re-entrant corner is smaller than 1/3.
103 void
105 {
106  // Insert code here
107 }
108 
110 // cells. Test this with all of your meshes.
111 std::tuple<unsigned int, unsigned int, unsigned int>
113 {
114  // Insert code here
115  return std::make_tuple(0, 0, 0);
116 }
117 
118 int
120 {
121  {
124  }
125  {
128  }
129 }
tria_accessor.h
triangulation
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
dealii
main
int main()
Definition: step-1.cc:119
grid_generator.h
Triangulation< 2 >
e
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
tria_iterator.h
GridOut::write_vtk
void write_vtk(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
grid_out.h
third_grid
void third_grid(Triangulation< 2 > &)
Create an L-shaped domain with one global refinement, and write it on.
Definition: step-1.cc:104
GridGenerator::hyper_shell
void hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, bool colorize=false)
tria.h
to_string
static std::string to_string(const T &s, const Patterns::PatternBase &p=*Convert< T >::to_pattern())=delete
Point< 3 >::distance
numbers::NumberTraits< double >::real_type distance(const Point< dim, double > &p) const
GridOut::write_svg
void write_svg(const Triangulation< 2, 2 > &tria, std::ostream &out) const
GridGenerator::hyper_cube
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
get_info
std::tuple< unsigned int, unsigned int, unsigned int > get_info(const Triangulation< 2 > &)
Returns a tuple with number of levels, number of cells, number of active.
Definition: step-1.cc:112
step
void step(Vector< number2 > &dst, const Vector< number2 > &rhs) const
second_grid
void second_grid(Triangulation< 2 > &triangulation)
Generate a locally refined hyper_shell, and output it as an svg file.
Definition: step-1.cc:63
Point< 2 >
GridOut
center
Point< 3 > center
first_grid
void first_grid(Triangulation< 2 > &triangulation)
Generate a hypercube, and output it as an svg file.
Definition: step-1.cc:35