I have two simple subdomains representing two separate solid mechanical bodies and I'm trying to set different body force parameters (based on gravity and density) for each subdomain. Right now I'm looping through each cell and setting the x-, y- and z-component of the body force for each cell based on the subdomains density parameter which I've set earlier.
# Subdomain Body Forces
VFS = VectorFunctionSpace(mesh, 'DG', 0)
B = Function(VFS)
cell_count = len(subdomains.array())
for cell_no in range(cell_count):
# Fetch subdomain number
subdomain_no = subdomains.array()[cell_no]
# Set x-, y- and z-component of the cell
B.vector()[cell_no + (0 * cell_count)] = 0 * rho.vector()[cell_no]
B.vector()[cell_no + (1 * cell_count)] = 0 * rho.vector()[cell_no]
B.vector()[cell_no + (2 * cell_count)] = -9.8 * rho.vector()[cell_no]
I was told that the B.vector() would be structured as:
[x1 x2 ... xn y1 y2 ... yn z1 z2 ... zn]
But perhaps this is not the case. When I do like this, only one of my bodies receives a force, strangely pointing down and to the back as if the body forces of the subdomains turned out
B(subdomain0) = (0, 0, 0) (times the cell-specific density)
B(subdomain1) = (0, -9.8, -9.8) (times the cell-specific density)
Any suggestions on where I'm thinking incorrectly? How is B.vector() structured?