Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connectivity #44

Merged
merged 7 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 173 additions & 3 deletions examples/minimal_SIP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <deal.II/lac/sparse_matrix.h>

#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/vector_tools_interpolate.h>

#include <algorithm>

Expand Down Expand Up @@ -59,6 +60,24 @@ RightHandSide<dim>::value_list(const std::vector<Point<dim>> &points,
}



template <int dim>
class MyFunction : public Function<dim>
{
public:
virtual double
value(const Point<dim> &p, const unsigned int component = 0) const override;
};

template <int dim>
double
MyFunction<dim>::value(const Point<dim> &p, const unsigned int) const
{
return p[0];
}



template <int dim>
class Poisson
{
Expand Down Expand Up @@ -120,11 +139,13 @@ Poisson<dim>::make_grid()
{
if (to_agglomerate)
{
tria.refine_global(2);
tria.refine_global(3);
std::cout << "N elements " << tria.n_active_cells() << std::endl;
}
else
{
tria.refine_global(1);
tria.refine_global(2);
std::cout << "N elements " << tria.n_active_cells() << std::endl;
}
}
else if constexpr (dim == 3)
Expand All @@ -135,7 +156,7 @@ Poisson<dim>::make_grid()
}
}
std::cout << "Number of cells: " << tria.n_active_cells() << std::endl;
std::ofstream out("sixtenn_grid.vtk");
std::ofstream out("test_grid.vtk");
GridOut grid_out;
grid_out.write_vtk(tria, out);
std::cout << "Grid written " << std::endl;
Expand Down Expand Up @@ -202,13 +223,121 @@ Poisson<dim>::setup_agglomeration()
idxs_to_be_agglomerated4,
cells_to_be_agglomerated4);

std::vector<types::global_cell_index> idxs_to_be_agglomerated5 = {
16, 17, 18, 19}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated5;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated5,
cells_to_be_agglomerated5);

std::vector<types::global_cell_index> idxs_to_be_agglomerated6 = {
20, 21, 22, 23}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated6;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated6,
cells_to_be_agglomerated6);

std::vector<types::global_cell_index> idxs_to_be_agglomerated7 = {
24, 25, 26, 27}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated7;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated7,
cells_to_be_agglomerated7);

std::vector<types::global_cell_index> idxs_to_be_agglomerated8 = {
28, 29, 30, 31}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated8;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated8,
cells_to_be_agglomerated8);

std::vector<types::global_cell_index> idxs_to_be_agglomerated9 = {
32, 33, 34, 35}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated9;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated9,
cells_to_be_agglomerated9);

std::vector<types::global_cell_index> idxs_to_be_agglomerated10 = {
36, 37, 38, 39}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated10;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated10,
cells_to_be_agglomerated10);

std::vector<types::global_cell_index> idxs_to_be_agglomerated11 = {
40, 41, 42, 43}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated11;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated11,
cells_to_be_agglomerated11);

std::vector<types::global_cell_index> idxs_to_be_agglomerated12 = {
44, 45, 46, 47}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated12;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated12,
cells_to_be_agglomerated12);

std::vector<types::global_cell_index> idxs_to_be_agglomerated13 = {
48, 49, 50, 51}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated13;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated13,
cells_to_be_agglomerated13);

std::vector<types::global_cell_index> idxs_to_be_agglomerated14 = {
52, 53, 54, 55}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated14;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated14,
cells_to_be_agglomerated14);

std::vector<types::global_cell_index> idxs_to_be_agglomerated15 = {
56, 57, 58, 59}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated15;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated15,
cells_to_be_agglomerated15);

std::vector<types::global_cell_index> idxs_to_be_agglomerated16 = {
60, 61, 62, 63}; //{36,37}
std::vector<typename Triangulation<dim>::active_cell_iterator>
cells_to_be_agglomerated16;
Tests::collect_cells_for_agglomeration(tria,
idxs_to_be_agglomerated16,
cells_to_be_agglomerated16);



// Agglomerate the cells just stored
ah->agglomerate_cells(cells_to_be_agglomerated);
ah->agglomerate_cells(cells_to_be_agglomerated2);
ah->agglomerate_cells(cells_to_be_agglomerated3);
ah->agglomerate_cells(cells_to_be_agglomerated4);
ah->agglomerate_cells(cells_to_be_agglomerated5);
ah->agglomerate_cells(cells_to_be_agglomerated6);
ah->agglomerate_cells(cells_to_be_agglomerated7);
ah->agglomerate_cells(cells_to_be_agglomerated8);
ah->agglomerate_cells(cells_to_be_agglomerated9);
ah->agglomerate_cells(cells_to_be_agglomerated10);
ah->agglomerate_cells(cells_to_be_agglomerated11);
ah->agglomerate_cells(cells_to_be_agglomerated12);
ah->agglomerate_cells(cells_to_be_agglomerated13);
ah->agglomerate_cells(cells_to_be_agglomerated14);
ah->agglomerate_cells(cells_to_be_agglomerated15);
ah->agglomerate_cells(cells_to_be_agglomerated16);
}
else if constexpr (dim == 3)
{
Expand Down Expand Up @@ -331,6 +460,7 @@ Poisson<dim>::assemble_system()
for (unsigned int j = 0; j < dofs_per_cell; ++j)
{
cell_matrix(i, j) +=
0. *
(-fe_face.shape_value(i, q_index) *
fe_face.shape_grad(j, q_index) *
normals[q_index] -
Expand Down Expand Up @@ -501,6 +631,21 @@ Poisson<dim>::solve()
{
SparseDirectUMFPACK A_direct;
{
{
std::cout << "Sanity check:" << std::endl;

// Sanity check: v(x,y)=x
Vector<double> interpx(ah->get_dof_handler().n_dofs());
MyFunction<dim> xfunction{};
VectorTools::interpolate(*(ah->euler_mapping),
ah->get_dof_handler(),
xfunction,
interpx);

double value = system_matrix.matrix_scalar_product(interpx, interpx);
std::cout << "Test = " << value << std::endl;
}

if (to_agglomerate)
{
std::ofstream output_file("agglo_SIP_matrix.txt");
Expand Down Expand Up @@ -559,6 +704,31 @@ Poisson<dim>::output_results()
data_out.build_patches(mapping);
data_out.write_vtu(output);
}
{
const std::string filename = "interpolated_solution.vtu";
std::ofstream output(filename);

DataOut<dim> data_out;
ah->setup_output_interpolation_matrix();
Vector<double> interpolated_solution(ah->output_dh.n_dofs());
ah->output_interpolation_matrix.vmult(interpolated_solution, solution);
data_out.attach_dof_handler(ah->output_dh);
data_out.add_data_vector(interpolated_solution,
"u",
DataOut<dim>::type_dof_data);
data_out.build_patches(mapping);
data_out.write_vtu(output);
}

// {
// // Sanity check: v(x,y)=x
// Vector<double> interpx(ah->agglo_dh.n_dofs());
// MyFunction<dim> xfunction{};
// VectorTools::interpolate(mapping, ah->agglo_dh, xfunction, interpx);

// double value = system_matrix.matrix_scalar_product(interpx, interpx);
// std::cout << "Test = " << value << std::endl;
// }
}

template <int dim>
Expand Down
Loading
Loading