MeshRefinementFunction
according to the documentation is an option for DiscretizeRegion
. Is there an analogue for ToElementMesh
?
The following code
Needs["NDSolve`FEM`"];
f = Function[{vertices, area}, If[Mean[vertices] > 1, area > 0.1, area > 0.01]];
ToElementMesh[Interval[{0, 2}], MeshRefinementFunction -> f]
gives the error
ToElementMesh::mrff: The MeshRefinementFunction Function[{vertices, area}, If[Mean[vertices]>1, area > 0.1, area > 0.01]] is not valid and will be ignored. The function does not return either True or False.
so I have to use an ugly workaround
mymesh = DiscretizeRegion[Interval[{0, 2}], MeshRefinementFunction -> f];
ToElementMesh[mymesh]
f
to an actual list of vertex positionsvertices
and a numberarea
. Then you will see that theIf
statement does not evaluate becauseMean[vertices]
is a vector and not a number. $\endgroup$Mean[vertices] > 1
... Maybe you meant to writef = Function[{vertices, area}, If[Thread[Mean[vertices] > 1], area > 0.1, area > 0.01]]
?>
might thread over vectors in other languages, but it does not in Mathematica: Things like{0,0,0}>1
do not produceTrue
orFalse
, and thusIf[{0,0,0}>1, [...], [...]]
stays just unevaluated. So noTrue
norFalse
either. $\endgroup$