For take coordinates of point i can use x[i] (x[0] for example). How to extract value of function in current point? I need to extract value in expression class, because i try to define Neumann boundary like u'=k*u on boundary.
p = Point() f = Function(V) try: print f(p) except TypeError: # issue 68 print f(p.x(), p.y(), p.z())
Issue68 has been already fixed but affects version $\le$ 1.2.0.
I need extract value in expression class, because i try to define Neumann boundary like u'=k*u on boundary. If i use your method i have "error: ‘u’ was not declared in this scope".
Please, provide short and complete code producing this error.
I use u in expression class, but u define in main function, and when class creating u is not declared. May be i should define u as global function?
Please, provide short and complete code producing this error.$ $
Function u(); class dUdN : public Expression { public:
dUdN() : Expression() {}
void eval(Array& values, const Array& x) const { values[0] = (x[2]<=DOLFIN_EPS)?(u(x[0],x[1],x[2])):0.0; } }; int main() {
Poisson::FunctionSpace V(mesh); Poisson::BilinearForm a(V, V); Poisson::LinearForm L(V); Function u(V);
}
In member function ‘virtual void dUdN::eval(dolfin::Array&, const dolfin::Array&) const’: /home/sheva/cpp/main.cpp:48:53: error: too many arguments to function ‘dolfin::Function u()’
and when i write class dUdN : public Expression { public:
dUdN() : Expression() {} void eval(Array& values, const Array& x) const { Point p(x[0],x[1],x[2]); values[0] = (x[2]<=DOLFIN_EPS)?(u(p)):0.0; } }; i have this error again/
Ok, syntax
u(x[0], x[1], x[2]) u(p)
works only in python. In C++ you need to use Function::eval method to evaluate function. Although your approach could work (in fixed-point iteration manner) it is in fact very poor implementation (in a view of available tools within DOLFIN). Robin condition can be implemented directly into variational form. For linear Poisson problem this way
Function::eval
v = TestFunction(element) u = TrialFunction(element) k = Constant(element) #k = Coefficient(element) # for non-constant k a = ... - k*u*v*ds
(not-tested).
thx. It's realy better write boudary condition in UFL.
Hi. How to extract value of function in current point from main function? For example, i have this code. Function u; for (CellIterator c(mesh); !c.end(); ++c) for (VertexIterator v0(c); !v0.end(); ++v0) for (VertexIterator v1(*v0); !v1.end(); ++v1) cout << *v1 << endl; How i can get value of u in v1?
Use some Function::eval method.