diff --git a/labs/lab-02/source/gtest.cc b/labs/lab-02/source/gtest.cc index 1b62400..83bf911 100644 --- a/labs/lab-02/source/gtest.cc +++ b/labs/lab-02/source/gtest.cc @@ -28,9 +28,9 @@ 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); @@ -38,7 +38,7 @@ TEST(Step1, DISABLED_Mark2) } -TEST(Step1, DISABLED_Mark3) +TEST(Step1, Mark3) { Triangulation<2> tria; third_grid(tria); @@ -47,7 +47,7 @@ TEST(Step1, DISABLED_Mark3) -TEST(Step1, DISABLED_Mark4) +TEST(Step1, Mark4) { Triangulation<2> tria; first_grid(tria); @@ -59,7 +59,7 @@ TEST(Step1, DISABLED_Mark4) -TEST(Step1, DISABLED_Mark5) +TEST(Step1, Mark5) { Triangulation<2> tria; second_grid(tria); @@ -71,7 +71,7 @@ TEST(Step1, DISABLED_Mark5) -TEST(Step1, DISABLED_Mark6) +TEST(Step1, Mark6) { Triangulation<2> tria; third_grid(tria); diff --git a/labs/lab-02/source/step-1.cc b/labs/lab-02/source/step-1.cc index d04733e..46c5607 100644 --- a/labs/lab-02/source/step-1.cc +++ b/labs/lab-02/source/step-1.cc @@ -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()) { @@ -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 @@ -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 -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 &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; }