assemble VariationalProblem members

Asked by Dominique

Hello,

In Python, I am trying to encapsulate a problem stated in weak form: a(v,u) = L(v) for all v in V (nonlinear or not). The first option that came to my mind is to use

problem = VariationalProblem(a, L, bc)

Now I can do

A = assemble(a, mesh=mesh) ; b = assemble(L, mesh=mesh) ; bc.apply(A,b)

but I cannot do

A = assemble(problem.a, mesh=mesh) ; b = assemble(problem.L, mesh=mesh)

Somehow assemble() doesn't want to work on the members of 'problem'. It returns:

Unable to convert object to a UFL form: <dolfin.fem.form.Form; proxy of <Swig Object of type 'dolfin::Form *' at 0x99fa350> >
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (4, 0))
[...]
UFLException: Unable to convert object to a UFL form: <dolfin.fem.form.Form; proxy of <Swig Object of type 'dolfin::Form *' at 0x99fa350> >

I don't *have* to use VariationalProblem to encapsulate the data, but I need to be able to get A and b somehow. I saw in a previous post that one could subclass NonlinearProblem. That would be fine for me, but I have 2 questions:

1) Is there a recommended way to encapsulate a and L so that they can be assemble()'d?

2) Could you please show an example usage of calling problem.F and problem.J when problem is a VariationalProblem? That just might answer the question.

Thanks in advance!
Dominique

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Best Garth Wells (garth-wells) said :
#1

On 23/08/10 18:26, Dominique wrote:
> New question #122406 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/122406
>
> Hello,
>
> In Python, I am trying to encapsulate a problem stated in weak form:
> a(v,u) = L(v) for all v in V (nonlinear or not). The first option
> that came to my mind is to use
>
> problem = VariationalProblem(a, L, bc)
>
> Now I can do
>
> A = assemble(a, mesh=mesh) ; b = assemble(L, mesh=mesh) ;
> bc.apply(A,b)
>

You should just do

   A = assemble(a)
   b = assemble(L)

> but I cannot do
>
> A = assemble(problem.a, mesh=mesh) ; b = assemble(problem.L,
> mesh=mesh)
>
> Somehow assemble() doesn't want to work on the members of 'problem'.
> It returns:
>
> Unable to convert object to a UFL form:<dolfin.fem.form.Form; proxy
> of<Swig Object of type 'dolfin::Form *' at 0x99fa350> > ERROR: An
> unexpected error occurred while tokenizing input The following
> traceback may be corrupted or invalid The error message is: ('EOF in
> multi-line statement', (4, 0)) [...] UFLException: Unable to convert
> object to a UFL form:<dolfin.fem.form.Form; proxy of<Swig Object of
> type 'dolfin::Form *' at 0x99fa350> >
>
> I don't *have* to use VariationalProblem to encapsulate the data, but
> I need to be able to get A and b somehow. I saw in a previous post
> that one could subclass NonlinearProblem. That would be fine for me,
> but I have 2 questions:
>
> 1) Is there a recommended way to encapsulate a and L so that they can
> be assemble()'d?
>
> 2) Could you please show an example usage of calling problem.F and
> problem.J when problem is a VariationalProblem? That just might
> answer the question.
>

You don't want to put a and L in a VariationalProblem if you're not
going to use the member function of VariationalProblem. Just work with a
and L directly.

Garth

> Thanks in advance! Dominique
>

Revision history for this message
Dominique (dominique-orban) said :
#2

Thanks Garth Wells, that solved my question.