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
Hi! On 2002.05.03 17:04 Juan Jose Arribas wrote:
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") ;
You can't assign symbols to each other in GiNaC. You should either use an "ex tiempo" as the member variable, or initialize the "symbol tiempo" in the constructor like this: fext::fext(string & functionc) : tiempo("t") { [...] (The symbol class shouldn't have an assignment operator in the first place. I thought we had removed it but it probably reappeared with the introduction of the GINAC_IMPLEMENT_REGISTERED_CLASS macros. I think We should fix that.) Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
On Friday 03 May 2002 17:04, Juan Jose Arribas wrote:... Hello, It seems that GiNaC does not like reaffectation of symbols. The following code works better fext::fext (string & funcionc):funcionstr(funcionc),tiempo("t") { //funcionstr = string(funcionc) ; //tiempo = symbol("t") ; funcion = ex(funcionstr,lst(tiempo)) ; } (and it is advantageous since tiempo is initialized only one time) --- Hugo LECLERC L.M.A.R.C. Laboratoire de Mécanique Appliquée R. Chaléat UMR CNRS 6604 UFR Sciences et Techniques 24, chemin de l'Epitaphe 25000 BESANCON - FRANCE Tel : 0663303421 / 0381666721 Fax : 0381666700
participants (3)
-
Christian Bauer
-
Hugo LECLERC
-
Juan Jose Arribas