Errors with gradient computing on C++

Asked by Nguyen Van Dang

Hi
I would like to compute the grad of function sols1 on C++:
 ....
  stiffness_matrix::FunctionSpace V(mesh);
  Function sols1(V);
  sols1.vector() = 0.0; //For example
  gradient_computation::FunctionSpace V_1(mesh);
  gradient_computation::BilinearForm a_1(V_1,V_1);
  gradient_computation::LinearForm L_1(V_1,sols1);
  VariationalProblem projection(a_1,L_1);
  Function grad_u1(V_1);
  projection.solve(grad_u1);
  plot(grad_u1);
...
where
gradient_computation.ufl

V = FiniteElement("CG", "triangle", 1)
W = VectorElement("CG", "triangle", 1)
u = TrialFunction(W)
v = TestFunction(W)
f = Coefficient(V)
a = inner(u, v)*dx
L = inner(v,grad(f))*dx

Running errors:
terminate called after throwing an instance of 'std::runtime_error'
  what():

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** https://answers.launchpad.net/dolfin
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to create variational problem.
*** Reason: The VariationalProblem class has been removed. Use solve(a == L).
*** Where: This error was encountered inside VariationalProblem.cpp.
*** -------------------------------------------------------------------------

[ubuntu:04137] *** Process received signal ***
[ubuntu:04137] Signal: Aborted (6)
[ubuntu:04137] Signal code: (-6)
[ubuntu:04137] [ 0] [0x1f940c]
[ubuntu:04137] [ 1] /lib/i386-linux-gnu/libc.so.6(abort+0x17e) [0x55f834e]
[ubuntu:04137] [ 2] /usr/lib/i386-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x155) [0x3eb70b5]
[ubuntu:04137] [ 3] /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xabfa5) [0x3eb4fa5]
[ubuntu:04137] [ 4] /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xabfe2) [0x3eb4fe2]
[ubuntu:04137] [ 5] /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xac14e) [0x3eb514e]
[ubuntu:04137] [ 6] /usr/lib/libdolfin.so.1.0(_ZNK6dolfin6Logger12dolfin_errorESsSsSs+0x892) [0xc91692]
[ubuntu:04137] [ 7] /usr/lib/libdolfin.so.1.0(_ZN6dolfin12dolfin_errorESsSsSsz+0xd2) [0xc9bc82]
[ubuntu:04137] [ 8] /usr/lib/libdolfin.so.1.0(_ZNK6dolfin18VariationalProblem13error_messageEv+0x81) [0xb162d1]
[ubuntu:04137] [ 9] /usr/lib/libdolfin.so.1.0(_ZN6dolfin18VariationalProblemC2ERKNS_4FormES3_+0x1d) [0xb1648d]
[ubuntu:04137] [10] ./demo-mesh(main+0x1377) [0x806aa87]
[ubuntu:04137] [11] /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x55e0e37]
[ubuntu:04137] [12] ./demo-mesh() [0x8064061]
[ubuntu:04137] *** End of error message ***
Aborted

What are my errors and how to fix it? Any helps are appreciated.
Best regards,
Nguyen Van Dang

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

You need to read the error message:

*** Error: Unable to create variational problem.
*** Reason: The VariationalProblem class has been removed. Use solve(a == L).
*** Where: This error was encountered inside VariationalProblem.cpp.

Also see:

  http://fenicsproject.org/releases/1.0-beta/index.html

Johan

On Wednesday October 5 2011 13:30:52 Nguyen Van Dang wrote:
> New question #173357 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/173357
>
> Hi
> I would like to compute the grad of function sols1 on C++:
> ....
> stiffness_matrix::FunctionSpace V(mesh);
> Function sols1(V);
> sols1.vector() = 0.0; //For example
> gradient_computation::FunctionSpace V_1(mesh);
> gradient_computation::BilinearForm a_1(V_1,V_1);
> gradient_computation::LinearForm L_1(V_1,sols1);
> VariationalProblem projection(a_1,L_1);
> Function grad_u1(V_1);
> projection.solve(grad_u1);
> plot(grad_u1);
> ...
> where
> gradient_computation.ufl
>
> V = FiniteElement("CG", "triangle", 1)
> W = VectorElement("CG", "triangle", 1)
> u = TrialFunction(W)
> v = TestFunction(W)
> f = Coefficient(V)
> a = inner(u, v)*dx
> L = inner(v,grad(f))*dx
>
> Running errors:
> terminate called after throwing an instance of 'std::runtime_error'
> what():
>
> ***
> -------------------------------------------------------------------------
> *** DOLFIN encountered an error. If you are not able to resolve this issue
> *** using the information listed below, you can ask for help at
> ***
> *** https://answers.launchpad.net/dolfin
> ***
> *** Remember to include the error message listed below and, if possible,
> *** include a *minimal* running example to reproduce the error.
> ***
> ***
> -------------------------------------------------------------------------
> *** Error: Unable to create variational problem.
> *** Reason: The VariationalProblem class has been removed. Use solve(a ==
> L). *** Where: This error was encountered inside VariationalProblem.cpp.
> ***
> -------------------------------------------------------------------------
>
> [ubuntu:04137] *** Process received signal ***
> [ubuntu:04137] Signal: Aborted (6)
> [ubuntu:04137] Signal code: (-6)
> [ubuntu:04137] [ 0] [0x1f940c]
> [ubuntu:04137] [ 1] /lib/i386-linux-gnu/libc.so.6(abort+0x17e) [0x55f834e]
> [ubuntu:04137] [ 2]
> /usr/lib/i386-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_
> handlerEv+0x155) [0x3eb70b5] [ubuntu:04137] [ 3]
> /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xabfa5) [0x3eb4fa5]
> [ubuntu:04137] [ 4] /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xabfe2)
> [0x3eb4fe2] [ubuntu:04137] [ 5]
> /usr/lib/i386-linux-gnu/libstdc++.so.6(+0xac14e) [0x3eb514e]
> [ubuntu:04137] [ 6]
> /usr/lib/libdolfin.so.1.0(_ZNK6dolfin6Logger12dolfin_errorESsSsSs+0x892)
> [0xc91692] [ubuntu:04137] [ 7]
> /usr/lib/libdolfin.so.1.0(_ZN6dolfin12dolfin_errorESsSsSsz+0xd2)
> [0xc9bc82] [ubuntu:04137] [ 8]
> /usr/lib/libdolfin.so.1.0(_ZNK6dolfin18VariationalProblem13error_messageEv
> +0x81) [0xb162d1] [ubuntu:04137] [ 9]
> /usr/lib/libdolfin.so.1.0(_ZN6dolfin18VariationalProblemC2ERKNS_4FormES3_+
> 0x1d) [0xb1648d] [ubuntu:04137] [10] ./demo-mesh(main+0x1377) [0x806aa87]
> [ubuntu:04137] [11] /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xe7)
> [0x55e0e37] [ubuntu:04137] [12] ./demo-mesh() [0x8064061]
> [ubuntu:04137] *** End of error message ***
> Aborted
>
> What are my errors and how to fix it? Any helps are appreciated.
> Best regards,
> Nguyen Van Dang

Revision history for this message
Nguyen Van Dang (dang-1032170) said :
#2

Thanks Johan Hake, that solved my question.