create Function from MeshFunction / CellFunction ?
Is it possible to create a Function from a MeshFunction or CellFunction? I have a function defined by points in a text file. I can create a CellFunction following the example on page 189 of the FEniCS book. But I want to use this like a Function. Is such a thing possible? Can I go directly from the text file to a Function via something like project()? I couldn't find anything like this in the demos or the examples in the book.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Paul Constantine
- Solved:
- 2013-02-02
- Last query:
- 2013-02-02
- Last reply:
Okay, something like this works, but it seems a little clunky. Let me know if you know anything slicker.
====
from dolfin import *
from numpy import loadtxt,interp
class MySine(Expression):
def __init_
self.data = loadtxt(
def eval(self,
values[0] = interp(
if __name__ == "__main__":
f = MySine(
mesh = UnitIntervalMes
V = FunctionSpace(
fV = project(f,V)
print fV(0.33)
print f(0.33)
====
Garth Wells (garth-wells) said : | #2 |
Take a look at
demo/
for an example.
Looks great! Thanks!