MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-scalarfunc.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-scalarfunc/module-scalarfunc.cc,v 1.14 2017/01/12 14:57:30 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 <cmath>
35 #include <cfloat>
36 
37 #include "dataman.h"
38 #include "ScalarFunctions.h"
39 
41 private:
43 
44 public:
45  DummySF(const doublereal d) : dConst(d) { NO_OP; };
46  virtual ~DummySF(void) { NO_OP; };
47  virtual doublereal operator()(const doublereal x) const { return dConst; };
48  virtual doublereal ComputeDiff(const doublereal t, const integer order = 1) const { return 0; };
49 };
50 
51 /* prototype of the functional object: reads a drive caller */
52 struct DummySFR : public ScalarFunctionRead {
53  const BasicScalarFunction *
54  Read(DataManager* pDM, MBDynParser& HP) const {
55  doublereal d = HP.GetReal();
56  return new DummySF(d);
57  };
58 };
59 
60 extern "C" int
61 module_init(const char *module_name, void *pdm, void *php)
62 {
63  ScalarFunctionRead *rf = new DummySFR;
64 
65  if (!SetSF("dummy", rf)) {
66  delete rf;
67 
68  silent_cerr("DummyScalarFunction: "
69  "module_init(" << module_name << ") "
70  "failed" << std::endl);
71 
72  return -1;
73  }
74 
75  return 0;
76 }
77 
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
#define NO_OP
Definition: myassert.h:74
virtual ~DummySF(void)
enum @55 order
const BasicScalarFunction * Read(DataManager *pDM, MBDynParser &HP) const
DummySF(const doublereal d)
bool SetSF(const std::string &s, const ScalarFunctionRead *rf)
doublereal dConst
virtual doublereal operator()(const doublereal x) const
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056