Hello, I’m working with the dolfinx_mpc and I’m facing some strange phenomenon about the boundary mapping.
Generally I want to creat a 1st-order CG space on a box: [0, 4pi]* [-5,5]* [-5,5], with the grid number Nx, Ny, Nz.
And I want to impose PBC on the x direction, i.e., f(0,y,z) = f(4pi,y,z). So I think the number of slaves node and master node should be equal to (Ny+1)(Nz+1). Then I define my PBC as follows:
const double pi = 3.141592653589793238462;
const double xmin = 0.0;
const double xmax = 4*pi;
const double ymin = -5.0;
const double ymax = 5.0;
const double zmin = -5.0;
const double zmax = 5.0;
const std::size_t Nx = 10;
const std::size_t Ny = 10;
const std::size_t Nz = 10;
std::array<double,3> p0{xmin,ymin,zmin};
std::array<double,3> p1{xmax,ymax,zmax};
// Create mesh and function space
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none);
auto mesh = std::make_shared<dolfinx::mesh::Mesh>(mesh::create_box(MPI_COMM_WORLD, {{p0, p1}}, {Nx, Ny, Nz}, dolfinx::mesh::CellType::hexahedron, part));
// Define some CG space
V = std::make_shared<fem::FunctionSpace>(fem::create_functionspace(functionspace_form_poisson_a, "u", mesh));
auto pbc = dolfinx_mpc::create_periodic_condition_geometrical(V, periodic_condition_x, periodic_relation_x, {}, 1, false);
auto mpc = std::make_shared<dolfinx_mpc::MultiPointConstraint<T>>(dolfinx_mpc::MultiPointConstraint<double>(V, {pbc.slaves}, {pbc.masters}, {pbc.coeffs}, {pbc.owners}, {pbc.offsets}));
std::cout<<pbc.slaves.size()<<"\n";
where
std::vector<std::int8_t> periodic_condition_x(std::experimental::mdspan<const double, std::experimental::extents<std::size_t, 3, std::experimental::dynamic_extent>> x)
{
std::vector<std::int8_t> f;
for (std::size_t p = 0; p < x.extent(1); ++p)
{
f.push_back((std::abs(x(0, p) - xmax) < 1e-8));
}
return f;
}
// PBC_x_relation
std::vector<double> periodic_relation_x(std::span<const double> x)
{
std::vector<double> y(x.size(), 0.0);
std::size_t len = x.size() / 3;
for (std::size_t i = 0; i < len; i++)
{
y[i] = (xmax + xmin) - x[i];
y[i + len] = x[i + len];
y[i + 2 * len] = x[i + 2 * len];
}
return y;
}
The problem is that, this code works only for some specifc Nx. In the code above, we know that the number of slaves node is 121, and it should not change when Nx is changed. But if I simply change Nx to 100, then I get 21 slaves dofs. I think I’m not defining the periodic relation in the correct way, does anyone know what could be the problem?
Thanks very much!