MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-mds.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-mds/module-mds.cc,v 1.10 2017/01/12 14:54:57 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  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
32 
33 #include <iostream>
34 #include <cfloat>
35 
36 #include "dataman.h"
37 #include "userelem.h"
38 
39 class ModuleMDS
40 : virtual public Elem, public UserDefinedElem {
41 private:
42  // add private data
46 
47 public:
48  ModuleMDS(unsigned uLabel, const DofOwner *pDO,
49  DataManager* pDM, MBDynParser& HP);
50  virtual ~ModuleMDS(void);
51 
52  virtual void Output(OutputHandler& OH) const;
53  virtual void WorkSpaceDim(integer* piNumRows, integer* piNumCols) const;
56  doublereal dCoef,
57  const VectorHandler& XCurr,
58  const VectorHandler& XPrimeCurr);
60  AssRes(SubVectorHandler& WorkVec,
61  doublereal dCoef,
62  const VectorHandler& XCurr,
63  const VectorHandler& XPrimeCurr);
64  unsigned int iGetNumPrivData(void) const;
65  int iGetNumConnectedNodes(void) const;
66  void GetConnectedNodes(std::vector<const Node *>& connectedNodes) const;
69  virtual unsigned int iGetNumDof(void) const;
70  virtual DofOrder::Order GetDofType(unsigned int i) const;
71  virtual DofOrder::Order GetEqType(unsigned int i) const;
72  std::ostream& Restart(std::ostream& out) const;
73  virtual unsigned int iGetInitialNumDof(void) const;
74  virtual void
75  InitialWorkSpaceDim(integer* piNumRows, integer* piNumCols) const;
78  const VectorHandler& XCurr);
80  InitialAssRes(SubVectorHandler& WorkVec, const VectorHandler& XCurr);
81 };
82 
84  unsigned uLabel, const DofOwner *pDO,
85  DataManager* pDM, MBDynParser& HP)
86 : Elem(uLabel, flag(0)),
87 UserDefinedElem(uLabel, pDO)
88 {
89  // help
90  if (HP.IsKeyWord("help")) {
91  silent_cout(
92 " \n"
93 "Module: msd \n"
94 "Author: Pierangelo Masarati <masarati@aero.polimi.it> \n"
95 "Organization: Dipartimento di Ingegneria Aerospaziale \n"
96 " Politecnico di Milano \n"
97 " http://www.aero.polimi.it/ \n"
98 " \n"
99 " All rights reserved \n"
100  << std::endl);
101 
102  if (!HP.IsArg()) {
103  /*
104  * Exit quietly if nothing else is provided
105  */
106  throw NoErr(MBDYN_EXCEPT_ARGS);
107  }
108  }
109 
110  dM = HP.GetReal();
111  dD = HP.GetReal();
112  dK = HP.GetReal();
113 
114  F.Set(HP.GetDriveCaller());
115 
117 }
118 
120 {
121  // destroy private data
122  NO_OP;
123 }
124 
125 void
127 {
128  if (bToBeOutput()) {
129  std::ostream& out = OH.Loadable();
130 
131  out << std::setw(8) << GetLabel() // 1: label
132  << " " << dX //
133  << " " << dV //
134  << " " << dVP //
135  << std::endl;
136  }
137 }
138 
139 void
140 ModuleMDS::WorkSpaceDim(integer* piNumRows, integer* piNumCols) const
141 {
142  *piNumRows = 2;
143  *piNumCols = 2;
144 }
145 
148  doublereal dCoef,
149  const VectorHandler& XCurr,
150  const VectorHandler& XPrimeCurr)
151 {
152  // should do something useful
153  FullSubMatrixHandler& WM = WorkMat.SetFull();
154 
155  WM.Resize(2, 2);
156 
157  integer iFirstIndex = iGetFirstIndex();
158 
159  WM.PutRowIndex(1, iFirstIndex + 1);
160  WM.PutColIndex(1, iFirstIndex + 1);
161  WM.PutRowIndex(2, iFirstIndex + 2);
162  WM.PutColIndex(2, iFirstIndex + 2);
163 
164  /*
165  * [ -m 0 ]
166  * r_/y' = [ ]
167  * [ 0 -1 ]
168  *
169  * [ -d -k ]
170  * r_/y = [ ]
171  * [ 1 0 ]
172  *
173  * [ (m + dCoef*d) dCoef*k ]
174  * J = -(r_/y' + dCoef*r_/y) = [ ]
175  * [ -dCoef 1. ]
176  */
177 
178 #if 1
179  // old style
180  WM.PutCoef(1, 1, dM + dCoef*dD);
181  WM.PutCoef(1, 2, dCoef*dK);
182  WM.PutCoef(2, 1, -dCoef);
183  WM.PutCoef(2, 2, 1.);
184 #endif
185 
186 #if 0
187  // cleaner (less efficient?)
188  WM(1, 1) = dM + dCoef*dD;
189  WM(1, 2) = dCoef*dK;
190  WM(2, 1) = -dCoef;
191  WM(2, 2) = 1.;
192 #endif
193 
194  return WorkMat;
195 }
196 
199  doublereal dCoef,
200  const VectorHandler& XCurr,
201  const VectorHandler& XPrimeCurr)
202 {
203  // should do something useful
204  WorkVec.ResizeReset(2);
205 
206  integer iFirstIndex = iGetFirstIndex();
207 
208  WorkVec.PutRowIndex(1, iFirstIndex + 1);
209  WorkVec.PutRowIndex(2, iFirstIndex + 2);
210 
211  dVP = XPrimeCurr(iFirstIndex + 1);
212  doublereal dXP = XPrimeCurr(iFirstIndex + 2);
213  dV = XCurr(iFirstIndex + 1);
214  dX = XCurr(iFirstIndex + 2);
215 
216  /*
217  * { f(t) - m*v' - d*v - d*k }
218  * r = { }
219  * { v - x' }
220  */
221 
222 #if 0
223  WorkVec.PutCoef(1, F.dGet() - dM*dVP - dD*dV - dK*dX);
224  WorkVec.PutCoef(2, dV - dXP);
225 #endif
226 
227  WorkVec(1) = F.dGet() - dM*dVP - dD*dV - dK*dX;
228  WorkVec(2) = dV - dXP;
229 
230  return WorkVec;
231 }
232 
233 unsigned int
235 {
236  return 0;
237 }
238 
239 int
241 {
242  return 0;
243 }
244 
245 void
246 ModuleMDS::GetConnectedNodes(std::vector<const Node *>& connectedNodes) const
247 {
248  connectedNodes.resize(0);
249 }
250 
251 void
255 {
256  NO_OP;
257 }
258 
259 unsigned int
261 {
262  return 2;
263 }
264 
266 ModuleMDS::GetDofType(unsigned int i) const
267 {
268  return DofOrder::DIFFERENTIAL;
269 }
270 
272 ModuleMDS::GetEqType(unsigned int i) const
273 {
274  return DofOrder::DIFFERENTIAL;
275 }
276 
277 std::ostream&
278 ModuleMDS::Restart(std::ostream& out) const
279 {
280  return out << "# ModuleMDS: not implemented" << std::endl;
281 }
282 
283 unsigned int
285 {
286  return 0;
287 }
288 
289 void
291  integer* piNumRows,
292  integer* piNumCols) const
293 {
294  *piNumRows = 0;
295  *piNumCols = 0;
296 }
297 
300  VariableSubMatrixHandler& WorkMat,
301  const VectorHandler& XCurr)
302 {
303  // should not be called, since initial workspace is empty
304  ASSERT(0);
305 
306  WorkMat.SetNullMatrix();
307 
308  return WorkMat;
309 }
310 
313  SubVectorHandler& WorkVec,
314  const VectorHandler& XCurr)
315 {
316  // should not be called, since initial workspace is empty
317  ASSERT(0);
318 
319  WorkVec.ResizeReset(0);
320 
321  return WorkVec;
322 }
323 
324 extern "C" int
325 module_init(const char *module_name, void *pdm, void *php)
326 {
328 
329  if (!SetUDE("mds", rf)) {
330  delete rf;
331 
332  silent_cerr("module-mds: "
333  "module_init(" << module_name << ") "
334  "failed" << std::endl);
335 
336  return -1;
337  }
338 
339  return 0;
340 }
341 
flag fReadOutput(MBDynParser &HP, const T &t) const
Definition: dataman.h:1064
void PutColIndex(integer iSubCol, integer iCol)
Definition: submat.h:325
doublereal dK
Definition: module-mds.cc:43
virtual void Output(OutputHandler &OH) const
Definition: module-mds.cc:126
long int flag
Definition: mbdyn.h:43
virtual bool bToBeOutput(void) const
Definition: output.cc:890
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
doublereal dVP
Definition: module-mds.cc:44
virtual void ResizeReset(integer)
Definition: vh.cc:55
FullSubMatrixHandler & SetFull(void)
Definition: submat.h:1168
virtual ~ModuleMDS(void)
Definition: module-mds.cc:119
doublereal dD
Definition: module-mds.cc:43
void Resize(integer iNewRow, integer iNewCol)
Definition: submat.cc:138
void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: submat.h:672
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
Definition: module-mds.cc:325
#define NO_OP
Definition: myassert.h:74
doublereal dM
Definition: module-mds.cc:43
std::vector< Hint * > Hints
Definition: simentity.h:89
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: module-mds.cc:198
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
void GetConnectedNodes(std::vector< const Node * > &connectedNodes) const
Definition: module-mds.cc:246
void SetValue(DataManager *pDM, VectorHandler &X, VectorHandler &XP, SimulationEntity::Hints *ph)
Definition: module-mds.cc:252
void SetNullMatrix(void)
Definition: submat.h:1159
virtual DofOrder::Order GetEqType(unsigned int i) const
Definition: module-mds.cc:272
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
std::ostream & Loadable(void) const
Definition: output.h:506
std::ostream & Restart(std::ostream &out) const
Definition: module-mds.cc:278
int iGetNumConnectedNodes(void) const
Definition: module-mds.cc:240
unsigned int uLabel
Definition: withlab.h:44
#define ASSERT(expression)
Definition: colamd.c:977
VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: module-mds.cc:147
virtual void PutCoef(integer iRow, const doublereal &dCoef)=0
ModuleMDS(unsigned uLabel, const DofOwner *pDO, DataManager *pDM, MBDynParser &HP)
Definition: module-mds.cc:83
Definition: except.h:79
doublereal dV
Definition: module-mds.cc:44
virtual DofOrder::Order GetDofType(unsigned int i) const
Definition: module-mds.cc:266
virtual bool IsArg(void)
Definition: parser.cc:807
Definition: elem.h:75
SubVectorHandler & InitialAssRes(SubVectorHandler &WorkVec, const VectorHandler &XCurr)
Definition: module-mds.cc:312
VariableSubMatrixHandler & InitialAssJac(VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
Definition: module-mds.cc:299
void PutRowIndex(integer iSubRow, integer iRow)
Definition: submat.h:311
bool SetUDE(const std::string &s, UserDefinedElemRead *rude)
Definition: userelem.cc:97
void Set(const DriveCaller *pDC)
Definition: drive.cc:647
doublereal dGet(const doublereal &dVar) const
Definition: drive.cc:664
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: module-mds.cc:290
DriveCaller * GetDriveCaller(bool bDeferred=false)
Definition: mbpar.cc:2033
unsigned int iGetNumPrivData(void) const
Definition: module-mds.cc:234
virtual void SetOutputFlag(flag f=flag(1))
Definition: output.cc:896
virtual integer iGetFirstIndex(void) const
Definition: dofown.h:127
double doublereal
Definition: colamd.c:52
DriveOwner F
Definition: module-mds.cc:45
virtual unsigned int iGetNumDof(void) const
Definition: module-mds.cc:260
long int integer
Definition: colamd.c:51
unsigned int GetLabel(void) const
Definition: withlab.cc:62
virtual unsigned int iGetInitialNumDof(void) const
Definition: module-mds.cc:284
virtual void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: module-mds.cc:140
doublereal dX
Definition: module-mds.cc:44
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056