← Back to team overview

dolfin team mailing list archive

Re: [Question #97399]: cannot convert 'dolfin::real' to 'double' for argument '1' to 'double cos(double)

 

Garth Wells wrote:
Question #97399 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/97399

    Status: Open => Answered

Garth Wells proposed the following answer:

Murtazo Nazarov wrote:
New question #97399 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/97399


In example in /demo/ode/stiff/cpp/Timedependent1.h I tried to change function f(u,t) into


  void f(const real* u, real t, real* y)
  {
    y[0] = -1000.0 * u[0] + cos(t);
  }

But I get a compilation error:

In file included from main.cpp:12:
TestProblem1.h: In member function 'virtual void TestProblem1::f(const dolfin::real*, dolfin::real, dolfin::real*)':
TestProblem1.h:27: error: cannot convert 'dolfin::real' to 'double' for argument '1' to 'double cos(double)'
scons: *** [main.o] Error 1

It seems dolfin::real is not double by default for the latest dolfin. Is it bug or I can fix it easily in my code?
Any suggestion?

Use 'double'.

Garth

I tried with 'double'.

 void u0(double* u)
 {
   u[0] = 1.0;
 }

 void f(const double* u, double t, double* y)
 {
   y[0] = -1000.0 * u[0] + cos(t);
 }

Then I got similar error

main.cpp:64: error: cannot declare variable 'test_problem' to be of abstract type 'TestProblem1' TestProblem1.h:12: note: because the following virtual functions are pure within 'TestProblem1': /afs/nada.kth.se/home/x/u18gh7kx/data/Work/fenics/build/include/dolfin/ode/ODE.h:83: note: virtual void dolfin::ODE::u0(dolfin::real*)

The I tried like this:

 void u0(real* u)
 {
   u[0] = 1.0;
 }

 void f(const real* u, double t, double* y)
 {
   y[0] = -1000.0 * u[0] + cos(t);
 }

Still error:

In file included from main.cpp:12:
TestProblem1.h: In member function 'void TestProblem1::f(const dolfin::real*, double, double*)': TestProblem1.h:27: error: cannot convert '__gmp_expr<__mpf_struct [1], __gmp_binary_expr<__gmp_expr<__mpf_struct [1], __gmp_binary_expr<double, __gmp_expr<__mpf_struct [1], __mpf_struct [1]>, __gmp_binary_multiplies> >, double, __gmp_binary_plus> >' to 'double' in assignment
scons: *** [main.o] Error 1


Thanks,
Murtazo







Follow ups

References