linear stretching of a function
Hi,
I am working on a problem, where I solve a function f on some one-dimensional mesh and then have to scale it to a different one-dimensional mesh, where I also want to turn the function around (so something like f(-x)). How do I achieve this?
I tried the following (which maybe makes the question more understandable):
take my function f on meshA of length LengthA
define an Expression that returns f(LengthA - LengthA/LengthB*x)
define a VariationalProblem that returns the stretched and mirrored function. Here is the code that I am using:
from dolfin import *
LengthA = 476.0
LengthB = 391.0
meshA = Interval(100, 0, LengthA)
meshB = Interval(100, 0, LengthB)
VA = FunctionSpace(
VB = FunctionSpace(
f = interpolate(
class foo(Expression):
def eval(self, values, x):
values[0] = f(LengthA - LengthA/
bar = foo()
T = TrialFunction(VB)
v = TestFunction(VB)
u = VariationalProb
But this throws an error: Unable to evaluate function at given point (not inside domain)...
The reason is a rounding error: on the rightmost point of meshB, we cannot evaluate f, because python returns
LengthA - LengthA/
which is outside the domain of f, as it is negative.
What is a good way to get around this problem? I have tried to take abs of the value inside f, but I would prefer to avoid this, because I am afraid this might reduce accuracy (in my computation I have to switch many times between the two meshes). And in similar situation I also left the domain on the other side. So abs does not seem to be a good solution.
thank you!
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Bento
- Solved:
- Last query:
- Last reply: