← Back to team overview

dolfin team mailing list archive

passing functions

 

Hi all,

I'm a bit confused about passing a Function to a function and using it to
assemble some system. What I'm doing is passing a Function, "func", by
reference, to a function, foo, where func goes into a form and that form
is assembled etc.

Vector& Another_Class::foo(Mesh& mesh, Function& func)
	{
		AAA::BilineraForm a
		AAA::LinearForm L(func)

		FEM:assemble(...)
		lu_solver.solve(...)

		return x;
	}

This works fine, but when the context that called foo (e.g. main) resumes
something has happended to "func". The next time it is referenced the
porgram terminates with a segmentation violation. To get around this I can
copy the data to local Vector in foo:

Vector& Another_Class::foo(Mesh& mesh, Function& func)
	{
		Vector vec = func.vector();
		Function func2(vec,mesh,func.element());

		AAA::BilineraForm a
		AAA::LinearForm L(func2)

		FEM:assemble(...)
		lu_solver.solve(...)

		return x;
	}

I would dearly like to avoid this extra copy of a large vector. How should
one do this?

Regards,
Dag Lindbo



Follow ups