Edit: This is not a general problem.The problem is either in my computer or in my copy of Mathematica. I tried this on another computer and it is working correctly.
I have been playing around with simple ways of looking at vibration modes of 2d objects constrained to be zero outside a region. I defined the region as a derived combination of basic geometric regions. I then want to display the vibration mode as a 3d plot. I have not exhaustively checked many combinations of regions, but definitely have problems with the union of 2 regions. In one case, the union of a disk and a rectangle the calculation runs to completion but the kernel hangs when trying to plot the result over the region. In another case, the union of 2 disks offset from one another, the kernel hangs when plotting the region. In the case of the difference of two disks, the program processes correctly. The code that works is shown below and also attached to this post.
Clear["Global`*"]
myregion = RegionDifference[ Disk[{0, 0}, .9], Disk[{0, 0}, .3]];
dxdy = .04
RegionPlot[myregion]
numMass = IntegerPart[2/dxdy + 1]
nmodes = 10
totalRegion =
Table[Table[{xreg, yreg}, {xreg, -1, 1, dxdy}], {yreg, -1, 1, dxdy}];
myregionMat =
Map[# \[Element] myregion &, totalRegion, {2}] /. {True -> 1.,
False -> 0.};
y = IdentityMatrix[numMass];
tzz = 4 y - RotateLeft[y] - RotateRight[y];
tzp =tzm= -y;
tzpf = Flatten[tzp];
tzmf = Flatten[tzm];
tzzf = Flatten[tzz];
tzz0 = tzzf;
tzptot = Flatten[
Append[Append[tzzf, tzpf],
ConstantArray[0, numMass^2 (numMass - 2)]]];
tzmtot = Flatten[
Append[Append[tzzf, tzmf],
ConstantArray[0, numMass^2 (numMass - 2)]]];
rsltrow = Partition[Partition[tzptot, numMass], numMass];
rsltcol = Partition[Partition[tzmtot, numMass], numMass];
transitionMatrix =
Block[{ToeplitzMatrix},
ToeplitzMatrix[{x__List}, {y__List}] :=
With[{list1 = {x} /. List -> \[FormalCapitalL],
list2 = {y} /. List -> \[FormalCapitalL]},
ToeplitzMatrix[List @@ list1, List @@ list2]];
ToeplitzMatrix[rsltcol, rsltrow]] /. \[FormalCapitalL] -> List;
transitionMatrix = ArrayFlatten[transitionMatrix];
boundaryConditions = DiagonalMatrix[Flatten[myregionMat]];
nmodes = MatrixRank[N[boundaryConditions.transitionMatrix]]
evals = Eigenvalues[N[boundaryConditions.transitionMatrix]];
evalmax = Max[evals];
evecs = Eigenvectors[N[boundaryConditions.transitionMatrix], nmodes];
xplot = Table[k, {k, -1, 1, dxdy}];
yplot = xplot;
zplot = Partition[evecs[[nmodes - 3]], numMass];
xyplot = Transpose[{Flatten[ConstantArray[xplot, Length[xplot]]],
Flatten[Transpose[ConstantArray[xplot, Length[xplot]]]]}];
Table[thedata = Transpose[{xyplot, evecs[[kplot]]}];
someMode = Interpolation[thedata];
Plot3D[someMode[x, y], {x, y} \[Element] myregion,
PlotLegends -> Sqrt[evals[[kplot]]], PlotRange -> All], {kplot,
nmodes, nmodes - 7, -1}]
All I need to do is to change the region definition to
myregion=RegionUnion[ Disk[{0, 0}, .5], Rectangle[{0, -.3}, {.9, .3}]];
for a problem to arise. With this region definition the kernel hangs when trying to execute
Plot3D[someMode[x, y], {x, y} \[Element] myregion,
PlotLegends -> Sqrt[evals[[kplot]]], PlotRange -> All],
however plotting with
Plot3D[someMode[x, y1], {x, -1, 1}, {y1, -1, 1}]
works. Just trying to plot the region
RegionUnion[ Disk[{0, 0}, .5], Disk[{.5, 0}, .4]];
hangs the kernel. When the kernel hangs, I can not stop processing by aborting execution. I must quit the kernel. Has anyone else had this problem? I am using ver 10.0.2 on a W7 machine.
Attachments: