Hi all, is there a way to set fixed values to a function object? My hope is to monitor if the solution drops below a certain eps, say eps = 1e-16, and if the function value is smaller than eps at any point, to return the value eps for that point.
In this way, I try to get rid of negative and/or very low values of the function that often mess up a solution. Alternatives to this “marking” would also be quite welcome.
@nate Thnak you for the suggestion. It works on its own, but I guess I am using another type of the Function object, as when I try to use the example in my code it throws the error that AttributeError: 'Function' object has no attribute 'x'
Instead, I found a workaround to do something like this:
from fenics import *
mesh = Mesh("mesh.xml.gz")
V = FunctionSpace(mesh, "Lagrange", 2)
u = interpolate(Expression('sin(pi * x[0])', degree=2, domain=mesh), V)
u.assign(interpolate(Expression('f > err ? f : err', degree=2, f=u, err=0.5), V))
Is that a valid thing to do or is there a better way to tackle this?
Also, it is a somewhat intermittent step, as I am solving a diffusion equation so this is a check that I do on every step to ensure strictly positive numbers. Without it, there are quite a few numerical issues in the solution going haywire and this workaround at least seems to mitigate it a bit, but not perfectly.
@dokken Many thanks, that works!
It seems like it works even better than my “workaround”, as it gets rid of those odd numerical issues that I mentioned.