Thank you Nate for your quick answer.
I am aware that it is not possible to divide only one cell in a conforming mesh.
So it’s not a problem for me if refine cuts more than one cell.
But I do not understand why refine cuts cells close to the top left of the unit square while I mark (or try to mark) a cell close to the bottom left.
As it seems I did not copy properly my script in my previous mail (indentations disapear), I copy it a second time in this mail.
Xavier
from fenics import *
from matplotlib import pyplot
cpp_code = """
#include<pybind11/pybind11.h>
#include<dolfin/adaptivity/adapt.h>
#include<dolfin/mesh/Mesh.h>
#include<dolfin/mesh/MeshFunction.h>
#include<dolfin/fem/DirichletBC.h>
#include<dolfin/function/FunctionSpace.h>
#include<dolfin/fem/Form.h>
namespace py = pybind11;
PYBIND11_MODULE(SIGNATURE, m) {
m.def("adapt", (std::shared_ptr<dolfin::MeshFunction<std::size_t>> (*)(const dolfin::MeshFunction<std::size_t>&,
std::shared_ptr<const dolfin::Mesh>)) &dolfin::adapt,
py::arg("mesh_function"), py::arg("adapted_mesh"));
m.def("adapt", (std::shared_ptr<dolfin::DirichletBC> (*)(const dolfin::DirichletBC&,
std::shared_ptr<const dolfin::Mesh>, const dolfin::FunctionSpace&)) &dolfin::adapt,
py::arg("bc"), py::arg("adapted_mesh"), py::arg("S"));
m.def("adapt", (std::shared_ptr<dolfin::FunctionSpace> (*)(const dolfin::FunctionSpace&,
std::shared_ptr<const dolfin::Mesh>)) &dolfin::adapt,
py::arg("space"), py::arg("adapted_mesh"));
m.def("adapt", (std::shared_ptr<dolfin::Form> (*)(const dolfin::Form&,
std::shared_ptr<const dolfin::Mesh>, bool)) &dolfin::adapt,
py::arg("form"), py::arg("adapted_mesh"), py::arg("adapt_coefficients")=true);
}
"""
adapt = compile_cpp_code(cpp_code).adapt
#
n_elem = 1
n_ref = 5
mesh = UnitSquareMesh(n_elem,n_elem,"crossed")
#
Praf = Point(0.20981,0.10987652,0.0)
for i_ref in range(n_ref):
print("-------------------------------------")
print("Refinement "+str(i_ref))
print("-------------------------------------")
print(" ")
markers = MeshFunction("bool", mesh, False)
for cell in cells(mesh):
markers[cell] = cell.contains(Praf)
if markers[cell]:
print(cell.get_vertex_coordinates())
print("")
#
plot(mesh)
pyplot.show()
mesh = refine(mesh,markers)
# mesh = adapt(mesh,markers)
plot(mesh)
pyplot.show()