# How to refine a linear FEM mesh in three regions?

I am trying to solve the one-dimensional wave equation with a frequency dependent source function over three intervals with varying velocity. I need to refine the mesh over the low velocity regions when the wavelength becomes shorter. The documentation for DiscretizeRegion shows how to do this for the left half of a linear region using step functions, but this MeshRefinementFunction does not work for ToElementMesh.

DiscretizeRegion[RegionUnion[Line[{{0}, {1.8}}], Line[{{1.8}, {2.2}}],
Line[{{2.2}, {4}}]], MeshRefinementFunction -> Function[{v, Len}, If[Max[v]
>= 2, Len > 0.003, Len > 0.5]]]


Can you help?

Thanks, Ken

You can use

ToElementMesh[
DiscretizeRegion[
RegionUnion[Line[{{0}, {1.8}}], Line[{{1.8}, {2.2}}],
Line[{{2.2}, {4}}]],
MeshRefinementFunction ->
Function[{v, Len}, If[Max[v] >= 2, Len > 0.003, Len > 0.5]]]]


Another approach you could take is to create a boundary mesh and then use RegionMarkers:

bmesh = ToBoundaryMesh["Coordinates" -> {{0}, {1.8}, {2.2}, {4}},
"BoundaryElements" -> {PointElement[{{1}, {2}, {3}, {4}}, {1, 1, 3,
3}]}, "PointElements" -> {PointElement[{{1}, {2}, {3}, {4}}, \
{1, 1, 3, 3}]}];

m = ToElementMesh[bmesh,
"RegionMarker" -> {{{0.9}, 1, 0.01}, {{2}, 2, 0.1}, {{3}, 3, 0.001}}]
m["Wireframe"]


Also note that there are two tutorials that might be of interest: one is on the wave equation in acoustics and one on the Helmholtz equation for the frequency domain in Acoustics. The fact that the tutorials are about Acoustics is not that important since many things are still applicable. Also, have a look for the acoustics models in product with examples.

Thanks for the help. I used the boundary mesh approach with this code:

    bmesh = ToBoundaryMesh["Coordinates" -> {{0}, {1.9}, {2.1}, {4}},
"BoundaryElements" -> {PointElement[{{1}, {2}, {3}, {4}}, {1, 1, 3, 3}]},
"PointElements" -> {PointElement[{{1}, {2}, {3}, {4}}, {1, 1, 3, 3}]}];

m2 = ToElementMesh[bmesh,"RegionMarker" -> {{{0.9}, 1, 0.2}, {{2}, 2, 0.05},
{{3}, 3, 0.1}}]


Then I used NDSolve and got a much better result for the frequency range I was using