MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ginacdrive.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/ginacdrive.cc,v 1.8 2017/01/12 14:46:09 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 #include "dataman.h"
35 #include "ginacdrive.h"
36 
37 #include <sstream>
38 
40  const std::string& var, const std::string& expression)
41 : DriveCaller(pDH)
42 {
43  GiNaC::lst l;
44 
45  gVar = new GiNaC::symbol(var);
46  l.append(*gVar);
47 
48  try {
49  gExpr = GiNaC::ex(expression, l);
50 
51  } catch (std::exception& e) {
52  silent_cerr("GiNaCDriveCaller: "
53  "expression \"" << expression << "\" parsing failed: " << e.what()
54  << std::endl);
55  throw e;
56  }
57 
58  try {
59  gExprDVar = gExpr.diff(*gVar);
60 
61  } catch (std::exception& e) {
62  silent_cerr("GiNaCDriveCaller: "
63  "expression \"" << expression << "\" differentiation wrt/ \"Var\" failed: " << e.what()
64  << std::endl);
65  throw e;
66  }
67 
68  pedantic_cout("GiNacDriveCaller: symbol=\"" << *gVar << "\" expression=\"" << gExpr << "\" derivative=\"" << gExprDVar << "\"" << std::endl);
69 }
70 
72 {
73  NO_OP;
74 }
75 
76 /* Copia */
79 {
80  DriveCaller* pDC = 0;
81 
82  std::ostringstream var, expr;
83  var << gVar;
84  expr << gExpr;
85 
88  GiNaCDriveCaller(pDrvHdl, var.str(), expr.str()));
89 
90  return pDC;
91 }
92 
93 /* Restart */
94 std::ostream&
95 GiNaCDriveCaller::Restart(std::ostream& out) const
96 {
97  out << " ginac, symbol, \"" << *gVar << "\", \"" << gExpr << "\"";
98 
99  return out;
100 }
101 
102 bool
104 {
105  return true;
106 }
107 
110 {
111  GiNaC::lst l;
112 
113  l.append(*gVar == dVar);
114 
115  GiNaC::ex f_expr = gExprDVar.subs(l);
116 
117  return GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
118 }
119 
120 DriveCaller *
121 GiNaCDCR::Read(const DataManager* pDM, MBDynParser& HP, bool bDeferred)
122 {
123  const DriveHandler* pDrvHdl = 0;
124  if (pDM != 0) {
125  pDrvHdl = pDM->pGetDrvHdl();
126  }
127 
128  std::string var;
129  if (HP.IsKeyWord("symbol")) {
130  var = HP.GetStringWithDelims();
131  if (var.empty()) {
132  silent_cerr("unable to read ginac drive caller symbol at line "
133  << HP.GetLineData() << std::endl);
135  }
136 
137  } else {
138  var = "Var";
139  }
140 
141  std::string expression = HP.GetStringWithDelims();
142  if (expression.empty()) {
143  silent_cerr("unable to read ginac drive caller expression at line "
144  << HP.GetLineData() << std::endl);
146  }
147 
148  DriveCaller *pDC = 0;
151  GiNaCDriveCaller(pDrvHdl, var, expression));
152 
153  return pDC;
154 }
155 
DriveCaller * Read(const DataManager *pDM, MBDynParser &HP, bool bDeferred)
Definition: ginacdrive.cc:121
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual ~GiNaCDriveCaller(void)
Definition: ginacdrive.cc:71
const DriveHandler * pGetDrvHdl(void) const
Definition: dataman.h:340
#define NO_OP
Definition: myassert.h:74
GiNaCDriveCaller(const DriveHandler *pDH, const std::string &var, const std::string &expression)
Definition: ginacdrive.cc:39
GiNaC::ex gExpr
Definition: ginacdrive.h:55
virtual std::ostream & Restart(std::ostream &out) const
Definition: ginacdrive.cc:95
virtual DriveCaller * pCopy(void) const
Definition: ginacdrive.cc:78
GiNaC::symbol * gVar
Definition: ginacdrive.h:52
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
GiNaC::ex gExprDVar
Definition: ginacdrive.h:58
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
Definition: parser.cc:1228
DriveHandler * pDrvHdl
Definition: drive.h:444
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual doublereal dGetP(void) const
Definition: drive.h:501
virtual bool bIsDifferentiable(void) const
Definition: ginacdrive.cc:103
double doublereal
Definition: colamd.c:52
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697