expressions inside a user-defined class.

Juan Jose Arribas jja at mecanica.upm.es
Fri May 3 17:04:41 CEST 2002


Hi,:

I am trying to introduce symbolic functions in a numeric fem code.
To do that I want to store expressions (functions) inside a class.

I read outside the class a string with the function (example, sin(t) ),
then I create an object for store it. I use the constructor to pass the
string.
In the constructor I create the expression, and I intend to use it
later (with the valor function), but in the constructor I always get a
segmentation  fault when I call the ex constructor.
It must be something obvious but I am unable to find it.
I have tried to debug with gdb and put a try--catch group but I have not
found the explanation of the segmentation fault error.

The code I am using to test it is as follows:
=========================================================================
#include<iostream.h>
#include<ginac/ginac.h>
#include<ginac/lst.h>
using namespace std;
using namespace GiNaC;
class fext {
public:
     string funcionstr;
     ex funcion ;
     symbol tiempo ;
     lst l ;
public:
     fext (string &);  // Constructor 
     double valor(double);
};

fext::fext (string & funcionc)
    {
    funcionstr = string(funcionc) ;
    tiempo = symbol("t") ;
    funcion = ex(funcionstr,lst(tiempo)) ;
}

double fext::valor(double tt) {
    return( ex_to<numeric>(funcion.subs(tiempo==tt)).to_double() )  ;
}

int main()
{
        string st ;
        cin >> st ;
        fext fexx = fext(st) ;
        cout << "\n input t-value " ;
        double valorcillo ;
        cin >> valorcillo ;
        cout << "\n fexx value" << fexx.valor(valorcillo) ;
}
=================================================================


I am using debian-linux (woody)  with the following versions:

ginac-config --version
1.0.8

g++ -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011006 (Debian prerelease)


To compile it I use 
g++   prusimple.cc  -o prusimple  -lginac -lcln

Thanks in advance for any idea.

Juan Jose Arribas            Mechanics Department
Civil Engineers School       Politechnic University
Madrid                       Spain





More information about the GiNaC-list mailing list