Skip to content

Commit

Permalink
WIP: coarsen FE_Nothing and use hanging node constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
sebproell committed Feb 15, 2023
1 parent 0bec1f3 commit df58baf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
39 changes: 32 additions & 7 deletions tests/hp/field_transfer_05.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//
// ---------------------------------------------------------------------

// Check that we can use FieldTransfer when multiple cells are changed from
// FE_Nothing to FE_Q
// Check that we can use FieldTransfer when coarsening cells with non-uniform
// data

#include <deal.II/distributed/field_transfer.h>

Expand All @@ -30,6 +30,7 @@

#include <deal.II/hp/fe_collection.h>

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

#include "../tests.h"
Expand All @@ -41,10 +42,22 @@ class TestFunction : public Function<2>
double
value(const dealii::Point<2> &p, const unsigned int component) const override
{
return std::exp(10 * p[1]);
return std::exp(10 - 10 * p[1]);
}
};

void
output(const DoFHandler<2> & dof_handler,
const LinearAlgebra::distributed::Vector<double> &vector,
const std::string & file_name)
{
DataOut<2> data_out;
data_out.attach_dof_handler(dof_handler);
data_out.add_data_vector(vector, "solution");
data_out.build_patches();
data_out.write_vtu_in_parallel(file_name, MPI_COMM_WORLD);
}

int
main(int argc, char *argv[])
{
Expand Down Expand Up @@ -90,6 +103,9 @@ main(int argc, char *argv[])
VectorTools::interpolate(dof_handler, TestFunction(), solution);

{
if (false)
output(dof_handler, solution, "result_0.vtu");

deallog << "solution before: " << std::endl;
std::stringstream ss;
solution.print(ss);
Expand All @@ -113,7 +129,7 @@ main(int argc, char *argv[])
{
if (cell->is_locally_owned())
{
if (cell->center()[0] < 0.5)
if (cell->center()[1] < 0.25)
{
cell->set_coarsen_flag();
}
Expand All @@ -128,15 +144,24 @@ main(int argc, char *argv[])

dof_handler.distribute_dofs(fe_collection);

AffineConstraints<double> affine_constraints;
const double new_value = 11.;

locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(dof_handler);
LinearAlgebra::distributed::Vector<double> new_solution(
dof_handler.locally_owned_dofs(), locally_relevant_dofs, MPI_COMM_WORLD);

AffineConstraints<double> affine_constraints;
DoFTools::make_hanging_node_constraints(dof_handler, affine_constraints);
affine_constraints.close();

const double new_value = 11.;

field_transfer.interpolate(new_value, affine_constraints, new_solution);

affine_constraints.distribute(new_solution);

{
if (false)
output(dof_handler, solution, "result_1.vtu");

deallog << "solution after coarsening and activation: " << std::endl;
std::stringstream ss;
new_solution.print(ss);
Expand Down
8 changes: 4 additions & 4 deletions tests/hp/field_transfer_05.with_p4est=true.mpirun=2.output
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Vector data:

DEAL:0::solution after coarsening and activation:
DEAL:0::Process #0
Local range: [0, 31), global size: 55
Local range: [0, 42), global size: 68
Vector data:
1.000e+00 1.000e+00 1.218e+01 1.218e+01 1.000e+00 1.218e+01 1.484e+02 1.484e+02 1.484e+02 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01
1.000e+00 1.000e+00 1.218e+01 1.218e+01 1.000e+00 1.218e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.218e+01 4.252e+01 4.252e+01 4.252e+01 1.484e+02 1.484e+02 1.484e+02 1.218e+01 4.252e+01 4.252e+01 1.484e+02 1.484e+02 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 5.180e+02 5.180e+02 5.180e+02 1.808e+03 1.808e+03 1.808e+03 5.180e+02 5.180e+02 1.808e+03 1.808e+03


DEAL:1::solution before:
Expand All @@ -20,8 +20,8 @@ Vector data:

DEAL:1::solution after coarsening and activation:
DEAL:1::Process #1
Local range: [31, 55), global size: 55
Local range: [42, 68), global size: 68
Vector data:
1.808e+03 1.808e+03 1.808e+03 2.203e+04 2.203e+04 2.203e+04 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01
6.311e+03 6.311e+03 6.311e+03 2.203e+04 2.203e+04 2.203e+04 6.311e+03 6.311e+03 2.203e+04 2.203e+04 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01 1.100e+01


0 comments on commit df58baf

Please sign in to comment.