Hello,
Suppose I create a 3D/ 2D mesh in gmsh. For Eg. Let's stick to a 3D mesh - a cuboid divided in 3 layers of different thickness like a cake. Each layer has 3 material properties - Young's Modulus, Poisson's ratio and Mass Density.
How can one define the individual material properties for each subdomain and use to solve a problem. I am looking at a non linear elastodynamic problem given here.
I understand how it can be done in python for a mesh created in FEniCS and also in Gmsh.
Can someone please post a sample code or explain how to do it in C++ using Gmsh and if possible, also a fenics inbuilt mesh. I can post a sample Gmsh .geo file if that is required.
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 square (1 x 1)
Omega_0.mark(subdomains, 0);
Omega1 Omega_1; // This subdomain is defined as (x[1] >= 0.5) for a Gmsh square (1 x 1)
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(); class VonMises : public PlasticityModel { public: VonMises(double E, double nu, double yield_stress, double hardening_parameter);
double E = 1500.0;class Young : public Expression
{
void eval(Array<double>& values, const Array<double>& x) const
{
if (x[1] >= 0.5 )
{
values[0] = 27000.0;
}
else
{
values[0] = 15000.0;
}
}
};
Young E_v;
auto V = std::make_shared<e::FunctionSpace>(mesh);
auto E = std::make_shared<Function>(V);
E->interpolate(E_v);