failing erf()?

Asked by Nico Schlömer

The simple expression

   Expression('erf(x[0])')

fails to compile for me. Anyone else?

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Martin Sandve Alnæs (martinal) said :
#1

Fails here too. Easy to see why, it is not recognized by the expression parser and is interpreted as a variable. Has this worked before? It exists as a UFL function, and this works:
In [4]: from dolfin import *
In [5]: plot(erf(triangle.x[0]), mesh=UnitIntervalMesh(10))

  class Expression_bec1ba169307866a49bd65b49a562e90: public Expression
  {
  public:
    double erf;
    Expression_bec1ba169307866a49bd65b49a562e90():Expression()
    {

      erf = 0;
    }

    void eval(dolfin::Array<double>& values, const dolfin::Array<double>& x) const
    {
      values[0] = erf(x[0]);
    }
  };

Revision history for this message
Nico Schlömer (nschloe) said :
#2

Aha, mhm.
Well, I'd like to have a function that does something along the lines of

    erfc(z^2) * exp(-z^2)

and my original approach was to put this into an expression. Maybe that's not the way to go?
I could of course derive a subclass MyFun(Expression) and put whatever I want in there. Would this be the recommended approach? I'd have liked the string notation for brevity.

Revision history for this message
Johan Hake (johan-hake) said :
#3

Well, it looks like it is not included in <cmath> which is what we
include for these Expressions. When making a small test program I
perfectly find erf in math.h...

I am puzzled?!

Johan

On 12/13/2012 09:31 PM, Nico Schlömer wrote:
> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Status: Answered => Open
>
> Nico Schlömer is still having a problem:
> Aha, mhm.
> Well, I'd like to have a function that does something along the lines of
>
> erfc(z^2) * exp(-z^2)
>
> and my original approach was to put this into an expression. Maybe that's not the way to go?
> I could of course derive a subclass MyFun(Expression) and put whatever I want in there. Would this be the recommended approach? I'd have liked the string notation for brevity.
>

Revision history for this message
Nico Schlömer (nschloe) said :
#4

Yep, it's a bit weird. Earlier today I posted a message on the GCC help mailing list to ask whether or not leaving out erf(c) from cmath is intentional.
Assuming this is a bug, it'll take quite a while till this has propagated through to a GCC release on your favorite distro, so it might be worthwhile to add erf(c) to dolfin, using math.h, as a stopgap measure.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#5

Erf is C++11.
Den 13. des. 2012 22:35 skrev "Nico Schlömer" <
<email address hidden>> følgende:

> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Status: Answered => Open
>
> Nico Schlömer is still having a problem:
> Yep, it's a bit weird. Earlier today I posted a message on the GCC help
> mailing list to ask whether or not leaving out erf(c) from cmath is
> intentional.
> Assuming this is a bug, it'll take quite a while till this has propagated
> through to a GCC release on your favorite distro, so it might be worthwhile
> to add erf(c) to dolfin, using math.h, as a stopgap measure.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Nico Schlömer (nschloe) said :
#6
Revision history for this message
Garth Wells (garth-wells) said :
#7

On Fri, Dec 14, 2012 at 7:50 AM, Martin Sandve Alnæs
<email address hidden> wrote:
> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Status: Open => Answered
>
> Martin Sandve Alnæs proposed the following answer:
> Erf is C++11.

We could just include the Boost math headers to make it available.

Garth

> Den 13. des. 2012 22:35 skrev "Nico Schlömer" <
> <email address hidden>> følgende:
>
>> Question #216720 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/216720
>>
>> Status: Answered => Open
>>
>> Nico Schlömer is still having a problem:
>> Yep, it's a bit weird. Earlier today I posted a message on the GCC help
>> mailing list to ask whether or not leaving out erf(c) from cmath is
>> intentional.
>> Assuming this is a bug, it'll take quite a while till this has propagated
>> through to a GCC release on your favorite distro, so it might be worthwhile
>> to add erf(c) to dolfin, using math.h, as a stopgap measure.
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#8

Nico, it's not a gcc bug, the C++11 standard is not the default and will not be for quite some time. If you compile with --std=c++11 then std::erf is available, if not, it is not there, just like the standards say it should be.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#9

Also, Nico, you never explained why ufl expressions are not suitable for your situation. Since you're not describing the context, there's no way for us to know what is the best approach. What's wrong with this code (missing z,u,v, but you get the point):

def erfc(x):
    return 1 - erf(x)

f = erfc(z**2)*exp(-z**2)

solve(u*v*dx == f*v*dx)

Revision history for this message
Nico Schlömer (nschloe) said :
#10

@Martin:
You're right: adding --std=c++11 adds the std:: name space qualifier to erf, erfc.

@Garth:
The functions are already available in libstdc++, it's just that they are in the global namespace rather than in std::.

Revision history for this message
Johan Hake (johan-hake) said :
#11

On 12/14/2012 09:20 AM, Garth Wells wrote:
> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Status: Open => Answered
>
> Garth Wells proposed the following answer:
> On Fri, Dec 14, 2012 at 7:50 AM, Martin Sandve Alnæs
> <email address hidden> wrote:
>> Question #216720 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/216720
>>
>> Status: Open => Answered
>>
>> Martin Sandve Alnæs proposed the following answer:
>> Erf is C++11.
>
> We could just include the Boost math headers to make it available.

Good point. However, but don't we then need to link with
libboost_math_tr1.so or something to access these functions?

Johan

> Garth
>
>
>> Den 13. des. 2012 22:35 skrev "Nico Schlömer" <
>> <email address hidden>> følgende:
>>
>>> Question #216720 on DOLFIN changed:
>>> https://answers.launchpad.net/dolfin/+question/216720
>>>
>>> Status: Answered => Open
>>>
>>> Nico Schlömer is still having a problem:
>>> Yep, it's a bit weird. Earlier today I posted a message on the GCC help
>>> mailing list to ask whether or not leaving out erf(c) from cmath is
>>> intentional.
>>> Assuming this is a bug, it'll take quite a while till this has propagated
>>> through to a GCC release on your favorite distro, so it might be worthwhile
>>> to add erf(c) to dolfin, using math.h, as a stopgap measure.
>>>
>>> --
>>> You received this question notification because you are a member of
>>> DOLFIN Team, which is an answer contact for DOLFIN.
>>>
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Nico Schlömer (nschloe) said :
#12

If you guys let me know what CMake flags to set to compile Dolfin with -std=c++11, I'd probably get what I want; no need for heavy boost gymnastics from my side then.

Revision history for this message
Joachim Haga (jobh) said :
#13

Word of warning: c++11 is not fully ABI compatible with earlier C++,
so it may not work to compile just dolfin with c++11.

An example if that std::list has grown in size (it now includes a size
member), so it can not be passed between '11 and earlier.

On 14 December 2012 12:21, Nico Schlömer
<email address hidden> wrote:
> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Nico Schlömer posted a new comment:
> If you guys let me know what CMake flags to set to compile Dolfin with
> -std=c++11, I'd probably get what I want; no need for heavy boost
> gymnastics from my side then.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Johan Hake (johan-hake) said :
#14

I will fix this by adding all functions in math.h which are not added
from cmath.

Johan

On 12/14/2012 12:45 PM, Joachim Haga wrote:
> Question #216720 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/216720
>
> Joachim Haga proposed the following answer:
> Word of warning: c++11 is not fully ABI compatible with earlier C++,
> so it may not work to compile just dolfin with c++11.
>
> An example if that std::list has grown in size (it now includes a size
> member), so it can not be passed between '11 and earlier.
>
> On 14 December 2012 12:21, Nico Schlömer
> <email address hidden> wrote:
>> Question #216720 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/216720
>>
>> Nico Schlömer posted a new comment:
>> If you guys let me know what CMake flags to set to compile Dolfin with
>> -std=c++11, I'd probably get what I want; no need for heavy boost
>> gymnastics from my side then.
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>

Can you help with this problem?

Provide an answer of your own, or ask Nico Schlömer for more information if necessary.

To post a message you must log in.