Hi Joshua,
On 7/6/21 2:23 PM, Joshua colletta wrote:
Hi all,
I'm trying to model a magnet encased in a cube of elastomer for part of a project. I've seemingly tried everything under the sun, but ive been rather limited due to the poor interactive documentation.
I have to core problems:
Defining a region by a function: Material parameters can be defined over just a region, as such a function to define an inner regions of given bounds:
def inner_region_(coors, domain=None ,magnet=None): x, y, z = coors[:, 0], coors[:, 1], coors[:, 2]
mag_min_x, mag_max_x = str((magnet[1][0] - (magnet[0][0] / 2))), str((magnet[1][0] + (magnet[0][0] / 2))) mag_min_y, mag_max_y = str((magnet[1][1] - (magnet[0][1] / 2))), str((magnet[1][1] + (magnet[0][1] / 2))) mag_min_z, mag_max_z = str((magnet[1][2] - (magnet[0][2] / 2))), str((magnet[1][2] + (magnet[0][2] / 2))) parse_def_min = 'vertices in (' + x + ' > ' + mag_min_x + ') & (' + y + ' > ' + mag_min_y + ') & (' + z + ' > ' + mag_min_z + ')' parse_def_max = '& (' + x + ' < ' + mag_max_x + ') & (' + y + ' < ' + mag_max_y + ') & (' + z + ' < ' + mag_max_z + ')'
This kind of definition is used declarative region definitions, such as
domain.create_region('Gamma', 'vertices in (x < -0.4999)', ','facet')
#pls dont hate my ugly strings :)
parse_def = parse_def_min + parse_def_max flag = nm.where(parse_def)[0]
When defining region by a function, in that function (here) just use numpy:
flag = nm.where((x > mag_min_x) & (y > mag_min_y) & ....)[0]
There are no strings here, your x, y, z, and the bounds are regular arrays/numbers.
print(flag) return flag
I then call the function constructor in my main, again like the tutorials:
inner_region = Function('inner_region', inner_region_, extra_args=magnet)
and define the region off the domain:
magnet_region = domain.create_region('magnet0', 'vertices by inner_region','facet')
(i think i also need to make this region a child of my Omega (all node) region)
which fails miserably, due to the Function constructor seemingly not creating a Functions instance when called, but this is just from a bit of debugging (im no expert :D)
If the above does not help, send here a self-contained code (+ a small mesh) so that we can run it and see the problem.
Secondly, I can't seem to configure having two materials over differing regions in the mesh. I think this is partly due to the above but also very limited examples concerning this use case interactively. If someone could run me through this i'd be extremely grateful!
The easiest way is to define the two regions, let's say with names 'omega1', 'omega2', and than use something like:
m = Material('m', values={'rho': {'omega1': 2700, 'omega2': 6000}, 'E': {'omega1': 1e9, 'omega2': 1e10}})
BTW Im making meshes with pymesh, so cant use groups as a work around!
Once you are able to define the two regions, the above approach should work.
r.