Skip to content

Commit

Permalink
solution lab02 step1
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo committed Jun 21, 2022
1 parent e8fb5df commit 06726a7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 22 deletions.
12 changes: 6 additions & 6 deletions labs/lab-02/source/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ TEST(Step1, Mark1)
}


// Remove the DISABLED_ prefix from the following tests when you have done the
// Remove the prefix from the following tests when you have done the
// corresponding exercise
TEST(Step1, DISABLED_Mark2)
TEST(Step1, Mark2)
{
Triangulation<2> tria;
second_grid(tria);
ASSERT_TRUE(std::ifstream("grid-2.svg"));
}


TEST(Step1, DISABLED_Mark3)
TEST(Step1, Mark3)
{
Triangulation<2> tria;
third_grid(tria);
Expand All @@ -47,7 +47,7 @@ TEST(Step1, DISABLED_Mark3)



TEST(Step1, DISABLED_Mark4)
TEST(Step1, Mark4)
{
Triangulation<2> tria;
first_grid(tria);
Expand All @@ -59,7 +59,7 @@ TEST(Step1, DISABLED_Mark4)



TEST(Step1, DISABLED_Mark5)
TEST(Step1, Mark5)
{
Triangulation<2> tria;
second_grid(tria);
Expand All @@ -71,7 +71,7 @@ TEST(Step1, DISABLED_Mark5)



TEST(Step1, DISABLED_Mark6)
TEST(Step1, Mark6)
{
Triangulation<2> tria;
third_grid(tria);
Expand Down
108 changes: 92 additions & 16 deletions labs/lab-02/source/step-1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ second_grid(Triangulation<2> &triangulation)

for (unsigned int step = 0; step < 5; ++step)
{
std::ofstream out("grid-2-" + std::to_string(step) + ".vtk");
GridOut grid_out;
grid_out.write_vtk(triangulation, out);
{
std::ofstream out("grid-2-" + std::to_string(step) + ".vtk");
GridOut grid_out;
grid_out.write_vtk(triangulation, out);
}

{
std::ofstream out("grid-2-" + std::to_string(step) + ".svg");
GridOut grid_out;
grid_out.write_svg(triangulation, out);
}

for (auto &cell : triangulation.active_cell_iterators())
{
Expand All @@ -93,6 +101,21 @@ second_grid(Triangulation<2> &triangulation)

triangulation.execute_coarsening_and_refinement();
}

std::cout << "Number of vertices after 4 refinements: "
<< triangulation.n_vertices() << std::endl;
{
std::ofstream out("grid-2.svg");
GridOut grid_out;
grid_out.write_svg(triangulation, out);
std::cout << "Grid written to grid-2.svg" << std::endl;
}
{
std::ofstream out("grid-2.vtk");
GridOut grid_out;
grid_out.write_vtk(triangulation, out);
std::cout << "Grid written to grid-2.vtk" << std::endl;
}
}

//! Create an L-shaped domain with one global refinement, and write it on
Expand All @@ -101,29 +124,82 @@ second_grid(Triangulation<2> &triangulation)
// twist: refine all cells with the distance between the center of the cell and
// re-entrant corner is smaller than 1/3.
void
third_grid(Triangulation<2> &)
third_grid(Triangulation<2> &triangulation)
{
// Insert code here
GridGenerator::hyper_L(triangulation);

std::cout << "Number of original vertices: " << triangulation.n_vertices()
<< std::endl;

triangulation.refine_global(1);

const Point<2> center(0, 0);
for (unsigned int step = 0; step < 3; ++step)
{
{
std::ofstream out("grid-3-" + std::to_string(step) + ".vtk");
GridOut grid_out;
grid_out.write_vtk(triangulation, out);
}
{
std::ofstream out("grid-3-" + std::to_string(step) + ".svg");
GridOut grid_out;
grid_out.write_svg(triangulation, out);
}

for (auto &cell : triangulation.active_cell_iterators())
{
const double distance_from_center = center.distance(cell->center());
if (std::fabs(distance_from_center) < 2.0 / 3.0)
cell->set_refine_flag();
}

triangulation.execute_coarsening_and_refinement();
}
{
std::ofstream out("grid-3.svg");
GridOut grid_out;
grid_out.write_svg(triangulation, out);
}
{
std::ofstream out("grid-3.vtk");
GridOut grid_out;
grid_out.write_vtk(triangulation, out);
}
}

//! Returns a tuple with number of levels, number of cells, number of active
// cells. Test this with all of your meshes.
std::tuple<unsigned int, unsigned int, unsigned int>
get_info(const Triangulation<2> &)
get_info(const Triangulation<2> &triangulation)
{
// Insert code here
return std::make_tuple(0, 0, 0);
return std::make_tuple(triangulation.n_levels(),
triangulation.n_cells(),
triangulation.n_active_cells());
}

std::ostream &
operator<<(std::ostream &os,
const std::tuple<unsigned int, unsigned int, unsigned int> &tpl)
{
os << "levels: " << std::get<0>(tpl);
os << ", cells: " << std::get<1>(tpl);
os << ", active cells: " << std::get<2>(tpl);
return os;
}

int
main()
{
{
Triangulation<2> triangulation;
first_grid(triangulation);
}
{
Triangulation<2> triangulation;
second_grid(triangulation);
}
Triangulation<2> triangulation;
first_grid(triangulation);
std::cout << get_info(triangulation) << std::endl;

triangulation.clear();
second_grid(triangulation);
std::cout << get_info(triangulation) << std::endl;

triangulation.clear();
third_grid(triangulation);
std::cout << get_info(triangulation) << std::endl;
}

0 comments on commit 06726a7

Please sign in to comment.