Hello,
I am trying to divide my mesh in subdomains (in c++) and assign different material properties to them. The problem that I am trying to run is a demo of the FEniCS Solid Mech. app.
I attempted this code in c++, which runs in serial but fails in parallel. This is minimal, but I can post the full code if someone is interested. Can anyone please advise on how to accomplish the purpose in question, while running in parallel.
auto V0 = std::make_shared<DG0::FunctionSpace>(mesh);
MeshFunction<std::size_t> subdomains(mesh, mesh.topology().dim(), true);
Omega0 Omega_0; // This subdomain is defined as (x[1] <= 0.5) for a Gmsh unitsquare
Omega_0.mark(subdomains, 0);
Omega1 Omega_1; // This subdomain is defined as (x[1] >= 0.5) for a Gmsh unitsquare
Omega_1.mark(subdomains, 1);
// Material parameters --> mass density
Function rho(V0);
Array<double> rho_values(2);
rho_values[0] = 0.5;
rho_values[1] = 2;
std:size_t cell_no, subdomain_no;
for (CellIterator c(mesh); !c.end(); ++c)
{
cell_no = c->index(); // Cell number
subdomain_no = subdomains.values()[cell_no];
// Number subdomain identifier that owns the cell number " cell_no "
rho.vector()->setitem(cell_no, rho_values[subdomain_no]);
std::cout << "" << std::endl;
std::cout << "- sub_domain_number: " << subdomains.values()[cell_no] << std::endl;
std::cout << "- cell_number: " << cell_no << std::endl;
std::cout << "- rho_in_cell: " << rho.vector()->getitem(cell_no) << std::endl;
}
plot(mesh);
interactive();
plot(subdomains);
interactive();
plot(rho);
interactive();
I think the problem with this code in parallel may be the loop where it iterates over cells. This will not work in parallel since each process has only a subset of the cells.
Thanks for your help in advance!