MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
DofPlugIn Class Reference

#include <dofpgin.h>

Inheritance diagram for DofPlugIn:
Collaboration diagram for DofPlugIn:

Public Member Functions

 DofPlugIn (MathParser &mp, DataManager *pDM)
 
 ~DofPlugIn (void)
 
const char * sName (void) const
 
int Read (int argc, char *argv[])
 
TypedValue::Type GetType (void) const
 
TypedValue GetVal (void) const
 
- Public Member Functions inherited from MathParser::PlugIn
 PlugIn (MathParser &mp)
 
virtual ~PlugIn ()
 

Protected Attributes

ScalarDof dof
 
DataManagerpDM
 
bool bPrev
 
- Protected Attributes inherited from MathParser::PlugIn
MathParsermp
 

Private Member Functions

unsigned int ReadLabel (const char *s)
 
NodeReadNode (unsigned int uLabel, const char *s)
 
unsigned int ReadIndex (Node *pNode, unsigned int iMaxIndex, const char *s)
 
int ReadDofOrder (Node *pNode, unsigned int iIndex, const char *s)
 

Detailed Description

Definition at line 38 of file dofpgin.h.

Constructor & Destructor Documentation

DofPlugIn::DofPlugIn ( MathParser mp,
DataManager pDM 
)

Definition at line 39 of file dofpgin.cc.

References ASSERT.

40 : MathParser::PlugIn(mp), pDM(pDM), bPrev(false)
41 {
42  ASSERT(pDM != NULL);
43 }
bool bPrev
Definition: dofpgin.h:42
DataManager * pDM
Definition: dofpgin.h:41
#define ASSERT(expression)
Definition: colamd.c:977
DofPlugIn::~DofPlugIn ( void  )

Definition at line 45 of file dofpgin.cc.

References NO_OP.

46 {
47  NO_OP;
48 }
#define NO_OP
Definition: myassert.h:74

Member Function Documentation

TypedValue::Type DofPlugIn::GetType ( void  ) const
virtual

Implements MathParser::PlugIn.

Definition at line 191 of file dofpgin.cc.

References TypedValue::VAR_REAL.

192 {
193  return TypedValue::VAR_REAL;
194 }
TypedValue DofPlugIn::GetVal ( void  ) const
virtual

Implements MathParser::PlugIn.

Definition at line 197 of file dofpgin.cc.

References bPrev, ScalarDof::dGetValue(), ScalarDof::dGetValuePrev(), and dof.

198 {
199  if (bPrev) {
200  return TypedValue(dof.dGetValuePrev());
201  }
202  return TypedValue(dof.dGetValue());
203 }
bool bPrev
Definition: dofpgin.h:42
const doublereal & dGetValuePrev(void) const
Definition: node.cc:736
ScalarDof dof
Definition: dofpgin.h:40
const doublereal & dGetValue(void) const
Definition: node.cc:730

Here is the call graph for this function:

int DofPlugIn::Read ( int  argc,
char *  argv[] 
)
virtual

Implements MathParser::PlugIn.

Definition at line 57 of file dofpgin.cc.

References ASSERT, bPrev, dof, WithLabel::GetLabel(), Node::GetNodeType(), SimulationEntity::iGetNumDof(), MBDYN_EXCEPT_ARGS, Node::PARAMETER, psNodeNames, ReadDofOrder(), ReadIndex(), ReadLabel(), ReadNode(), SAFEDELETEARR, SAFENEWWITHCONSTRUCTOR, SAFESTRDUP, and STRLENOF.

58 {
59  unsigned int uLabel;
60  Node *pNode;
61  int iOrder = 0;
62  int iParams = 2;
63 
64  if (argc < 1 || argv[0] == NULL) {
65  silent_cerr("DofPlugIn::Read(): "
66  "illegal number of parameters #" << argc
67  << std::endl);
69  }
70  uLabel = ReadLabel(argv[0]);
71 
72  if (argc < 2 || argv[1] == NULL) {
73  silent_cerr("DofPlugIn::Read(" << argv[0] << "): "
74  "illegal number of parameters " << argc
75  << std::endl);
77  }
78  pNode = ReadNode(uLabel, argv[1]);
79 
80  unsigned int iMaxIndex = pNode->iGetNumDof();
81  switch (iMaxIndex) {
82  case 0:
83  /* parameter? */
84  ASSERT(pNode->GetNodeType() == Node::PARAMETER);
85  break;
86 
87  case 1:
88  iParams++;
89 
90  if (argc < 3 || argv[2] == NULL) {
91  silent_cerr("DofPlugIn::Read(" << argv[0] << ","
92  << argv[1] << "): "
93  "illegal number of parameters " << argc
94  << std::endl);
96  }
97  iOrder = ReadDofOrder(pNode, 1, argv[2]);
98  break;
99 
100  default: {
101  iParams += 2;
102 
103  if (argc < 3 || argv[2] == NULL) {
104  silent_cerr("DofPlugIn::Read(" << argv[0] << ","
105  << argv[1] << "): "
106  "illegal number of parameters " << argc
107  << std::endl);
109  }
110  unsigned int iIndex = ReadIndex(pNode, iMaxIndex, argv[2]);
111 
112  if (argc < 4 || argv[3] == NULL) {
113  silent_cerr("DofPlugIn::Read(" << argv[0] << ","
114  << argv[1] << ","
115  << argv[2] << "): "
116  "illegal number of parameters " << argc
117  << std::endl);
119  }
120  iOrder = ReadDofOrder(pNode, iIndex, argv[3]);
121 
122  NodeDof nd(iIndex-1, pNode);
123  pNode = 0;
124  /* Chi dealloca questa memoria? ci vorrebbe l'handle */
126  pedantic_cerr(psNodeNames[pNode->GetNodeType()]
127  << "(" << pNode->GetLabel() << "): "
128  "possibly allocating a NodeDof "
129  "that nobody will delete" << std::endl);
130  break;
131  }
132  }
133  dof = ScalarDof(dynamic_cast<ScalarNode *>(pNode), iOrder, 0);
134 
135  /* legge i parametri (<param>=<value>, separati da '&') */
136  if (argc == iParams + 1) {
137  char *parm = NULL, *p, *end;
138 
139  SAFESTRDUP(parm, argv[iParams]);
140 
141  for (p = parm; p != NULL; p = end) {
142  end = std::strchr(p, '&');
143  while (end != NULL && end[-1] == '\\') {
144  end = std::strchr(end + 1, '&');
145  }
146 
147  if (end != NULL) {
148  end[0] = '\0';
149  end++;
150  }
151 
152  char *v = std::strchr(p, '=');
153  if (v == NULL) {
154  silent_cerr("dof plugin: missing \"=\" "
155  "in <param>=<value>" << std::endl);
157  }
158 
159  v[0] = '\0';
160  v++;
161 
162  /* prende il valore al passo precedente */
163  if (strncasecmp(p, "prev", STRLENOF("prev")) == 0) {
164  if (strcasecmp(v, "true") == 0) {
165  bPrev = true;
166  } else if (strcasecmp(v, "false") == 0) {
167  bPrev = false;
168  } else {
169  silent_cerr("dof plugin: "
170  "unknown mode for parameter "
171  "\"" << p << "=" << v << "\""
172  << std::endl);
174  }
175 
176  } else {
177  silent_cerr("dof plugin: unknown parameter "
178  "\"" << p << "=" << v << "\""
179  << std::endl);
181  }
182  }
183 
184  SAFEDELETEARR(parm);
185  }
186 
187  return 0;
188 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: node.h:67
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
bool bPrev
Definition: dofpgin.h:42
unsigned int ReadLabel(const char *s)
Definition: dofpgin.cc:206
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
ScalarDof dof
Definition: dofpgin.h:40
virtual unsigned int iGetNumDof(void) const =0
const char * psNodeNames[]
Definition: enums.cc:372
#define STRLENOF(s)
Definition: mbdyn.h:166
virtual Node::Type GetNodeType(void) const =0
#define SAFESTRDUP(pnt, src)
Definition: mynewmem.h:707
Node * ReadNode(unsigned int uLabel, const char *s)
Definition: dofpgin.cc:221
Definition: node.h:578
int ReadDofOrder(Node *pNode, unsigned int iIndex, const char *s)
Definition: dofpgin.cc:256
unsigned int ReadIndex(Node *pNode, unsigned int iMaxIndex, const char *s)
Definition: dofpgin.cc:243
unsigned int GetLabel(void) const
Definition: withlab.cc:62

Here is the call graph for this function:

int DofPlugIn::ReadDofOrder ( Node pNode,
unsigned int  iIndex,
const char *  s 
)
private

Definition at line 256 of file dofpgin.cc.

References DofOrder::DIFFERENTIAL, SimulationEntity::GetDofType(), WithLabel::GetLabel(), Node::GetNodeType(), MBDYN_EXCEPT_ARGS, and psNodeNames.

Referenced by Read().

257 {
258  if (strcasecmp(s, "differential") == 0) {
259  if (pNode->GetDofType(iIndex-1) != DofOrder::DIFFERENTIAL) {
260  silent_cerr("cannot take differential value of "
261  << psNodeNames[pNode->GetNodeType()]
262  << "(" << pNode->GetLabel() << ")"
263  "[" << iIndex << "]" << std::endl);
265  }
266  return 1;
267  }
268 
269  if (strcasecmp(s, "algebraic") == 0) {
270  return 0;
271  }
272 
273  silent_cerr("unknown dof order '" << s << "'" << std::endl);
275 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual DofOrder::Order GetDofType(unsigned int i) const =0
const char * psNodeNames[]
Definition: enums.cc:372
virtual Node::Type GetNodeType(void) const =0
unsigned int GetLabel(void) const
Definition: withlab.cc:62

Here is the call graph for this function:

unsigned int DofPlugIn::ReadIndex ( Node pNode,
unsigned int  iMaxIndex,
const char *  s 
)
private

Definition at line 243 of file dofpgin.cc.

References WithLabel::GetLabel(), Node::GetNodeType(), MBDYN_EXCEPT_ARGS, psNodeNames, and ReadLabel().

Referenced by Read().

244 {
245  unsigned int i = ReadLabel(s);
246  if (i == 0 || i > iMaxIndex) {
247  silent_cerr("illegal index " << i << " for "
248  << psNodeNames[pNode->GetNodeType()]
249  << "(" << pNode->GetLabel() << ")" << std::endl);
251  }
252  return i;
253 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
unsigned int ReadLabel(const char *s)
Definition: dofpgin.cc:206
const char * psNodeNames[]
Definition: enums.cc:372
virtual Node::Type GetNodeType(void) const =0
unsigned int GetLabel(void) const
Definition: withlab.cc:62

Here is the call graph for this function:

unsigned int DofPlugIn::ReadLabel ( const char *  s)
private

Definition at line 206 of file dofpgin.cc.

References MathParser::Get(), MBDYN_EXCEPT_ARGS, and MathParser::PlugIn::mp.

Referenced by Read(), and ReadIndex().

207 {
208  // must be semicolon-terminated to be read by math parser
209  std::istringstream in(std::string(s) + ";");
210  InputStream In(in);
211  int i = mp.Get(In);
212  if (i < 0) {
213  silent_cerr("DofPlugIn::ReadLabel(" << s << "): invalid negative label" << std::endl);
215  }
216 
217  return unsigned(i);
218 }
Real Get(Real d=0.)
Definition: mathp.cc:4496
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
MathParser & mp
Definition: mathp.h:224

Here is the call graph for this function:

Node * DofPlugIn::ReadNode ( unsigned int  uLabel,
const char *  s 
)
private

Definition at line 221 of file dofpgin.cc.

References Node::LASTNODETYPE, MBDYN_EXCEPT_ARGS, pDM, DataManager::pFindNode(), psNodeNames, and psReadNodesNodes.

Referenced by Read().

222 {
223  Node *pNode = NULL;
224  unsigned int i;
225  for (i = 0; i < Node::LASTNODETYPE; i++) {
226  if (strcasecmp(s, psReadNodesNodes[i]) == 0) {
227  break;
228  }
229  }
230  if (i == Node::LASTNODETYPE) {
231  silent_cerr("unknown node type '" << s << "'" << std::endl);
233  }
234  if ((pNode = pDM->pFindNode(Node::Type(i), uLabel)) == NULL) {
235  silent_cerr(psNodeNames[Node::Type(i)]
236  << "(" << uLabel << ") not defined" << std::endl);
238  }
239  return pNode;
240 }
const char * psReadNodesNodes[]
Definition: enums.cc:398
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: node.h:67
DataManager * pDM
Definition: dofpgin.h:41
Type
Definition: node.h:71
const char * psNodeNames[]
Definition: enums.cc:372
Node * pFindNode(Node::Type Typ, unsigned int uNode) const
Definition: nodeman.cc:179

Here is the call graph for this function:

const char * DofPlugIn::sName ( void  ) const
virtual

Implements MathParser::PlugIn.

Definition at line 51 of file dofpgin.cc.

52 {
53  return "dof";
54 }

Member Data Documentation

bool DofPlugIn::bPrev
protected

Definition at line 42 of file dofpgin.h.

Referenced by GetVal(), and Read().

ScalarDof DofPlugIn::dof
protected

Definition at line 40 of file dofpgin.h.

Referenced by GetVal(), and Read().

DataManager* DofPlugIn::pDM
protected

Definition at line 41 of file dofpgin.h.

Referenced by ReadNode().


The documentation for this class was generated from the following files: