MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-template.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-template/module-template.cc,v 1.36 2017/01/12 14:58:00 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 "loadable.h"
38 
39 /*
40  * user-defined struct
41  */
43  int i;
44 };
45 
46 /* default funcs */
47 static void *
49 {
50  DEBUGCOUTFNAME("read");
51 
52  /*
53  * allocation of user-defined struct
54  */
55  module_template* p = NULL;
57 
58  /*
59  * read data
60  */
61  if (HP.IsKeyWord("help")) {
62  silent_cout("Module template" << std::endl);
63  }
64 
65  return (void *)p;
66 }
67 
68 static unsigned int
70 {
71  DEBUGCOUTFNAME("i_get_num_dof");
72  return 0;
73 }
74 
75 static DofOrder::Order
76 set_dof(const LoadableElem*, unsigned int i)
77 {
78  DEBUGCOUTFNAME("set_dof");
79  return DofOrder::UNKNOWN;
80 }
81 
82 static void
84 {
85  DEBUGCOUTFNAME("output");
86 }
87 
88 static std::ostream&
89 restart(const LoadableElem* pEl, std::ostream& out)
90 {
91  DEBUGCOUTFNAME("restart");
92  return out << "not implemented yet;" << std::endl;
93 }
94 
95 static void
96 work_space_dim(const LoadableElem* pEl, integer* piNumRows, integer* piNumCols)
97 {
98  DEBUGCOUTFNAME("work_space_dim");
99  *piNumRows = 0;
100  *piNumCols = 0;
101 }
102 
105  LoadableElem* pEl,
106  VariableSubMatrixHandler& WorkMat,
107  doublereal dCoef,
108  const VectorHandler& XCurr,
109  const VectorHandler& XPrimeCurr
110 )
111 {
112  DEBUGCOUTFNAME("ass_jac");
113  integer iNumRows = 0;
114  integer iNumCols = 0;
115  pEl->WorkSpaceDim(&iNumRows, &iNumCols);
116 
117  FullSubMatrixHandler& WM = WorkMat.SetFull();
118  WM.ResizeReset(iNumRows, iNumCols);
119 
120 #if 0
122 #endif /* 0 */
123 
124  /*
125  * set sub-matrix indices and coefs
126  */
127 
128  return WorkMat;
129 }
130 
131 static void
133  LoadableElem* pEl,
134  VariableSubMatrixHandler& WorkMatA,
135  VariableSubMatrixHandler& WorkMatB,
136  const VectorHandler& XCurr,
137  const VectorHandler& XPrimeCurr
138 )
139 {
140  DEBUGCOUTFNAME("ass_mats");
141  integer iNumRows = 0;
142  integer iNumCols = 0;
143  pEl->WorkSpaceDim(&iNumRows, &iNumCols);
144 
145  FullSubMatrixHandler& WMA = WorkMatA.SetFull();
146  WMA.ResizeReset(iNumRows, iNumCols);
147 
148  FullSubMatrixHandler& WMB = WorkMatB.SetFull();
149  WMB.ResizeReset(iNumRows, iNumCols);
150 
151 #if 0
153 #endif /* 0 */
154 
155  /*
156  * set sub-matrix indices and coefs
157  */
158 }
159 
160 static SubVectorHandler&
162  LoadableElem* pEl,
163  SubVectorHandler& WorkVec,
164  doublereal dCoef,
165  const VectorHandler& XCurr,
166  const VectorHandler& XPrimeCurr
167 )
168 {
169  DEBUGCOUTFNAME("ass_res");
170  integer iNumRows = 0;
171  integer iNumCols = 0;
172  pEl->WorkSpaceDim(&iNumRows, &iNumCols);
173 
174  WorkVec.Resize(iNumRows);
175 
176 #if 0
177  module_template* p = (module_template *)pEl->pGetData();
178 #endif /* 0 */
179 
180  /*
181  * set sub-vector indices and coefs
182  */
183 
184  return WorkVec;
185 }
186 
187 static void
189  const LoadableElem* pEl,
190  VectorHandler& X,
191  VectorHandler& XP,
192  VectorHandler& XPrev,
193  VectorHandler& XPPrev
194 )
195 {
196  DEBUGCOUTFNAME("before_predict");
197 }
198 
199 static void
201  const LoadableElem* pEl,
202  VectorHandler& X,
203  VectorHandler& XP
204 )
205 {
206  DEBUGCOUTFNAME("after_predict");
207 }
208 
209 static void
211  LoadableElem* pEl,
212  const VectorHandler& X,
213  const VectorHandler& XP
214 )
215 {
216  DEBUGCOUTFNAME("update");
217 }
218 
219 static void
220 after_convergence(const LoadableElem* /* pEl */ ,
221  const VectorHandler& /* X */ ,
222  const VectorHandler& /* XP */ )
223 {
224  DEBUGCOUTFNAME("after_convergence");
225 }
226 
227 static unsigned int
229 {
230  DEBUGCOUTFNAME("i_get_initial_num_dof");
231  return 0;
232 }
233 
234 static void
236  const LoadableElem* pEl,
237  integer* piNumRows,
238  integer* piNumCols
239 )
240 {
241  DEBUGCOUTFNAME("initial_work_space_dim");
242  *piNumRows = 0;
243  *piNumCols = 0;
244 }
245 
248  LoadableElem* pEl,
249  VariableSubMatrixHandler& WorkMat,
250  const VectorHandler& XCurr
251 )
252 {
253  DEBUGCOUTFNAME("initial_ass_jac");
254  integer iNumRows = 0;
255  integer iNumCols = 0;
256  pEl->InitialWorkSpaceDim(&iNumRows, &iNumCols);
257 
258  FullSubMatrixHandler& WM = WorkMat.SetFull();
259  WM.ResizeReset(iNumRows, iNumCols);
260 
261 #if 0
263 #endif /* 0 */
264 
265  /*
266  * set sub-matrix indices and coefs
267  */
268 
269  return WorkMat;
270 }
271 
272 static SubVectorHandler&
274  LoadableElem* pEl,
275  SubVectorHandler& WorkVec,
276  const VectorHandler& XCurr
277 )
278 {
279  DEBUGCOUTFNAME("initial_ass_res");
280  integer iNumRows = 0;
281  integer iNumCols = 0;
282  pEl->WorkSpaceDim(&iNumRows, &iNumCols);
283 
284  WorkVec.Resize(iNumRows);
285 
286 #if 0
287  module_template* p = (module_template *)pEl->pGetData();
288 #endif /* 0 */
289 
290  /*
291  * set sub-vector indices and coefs
292  */
293 
294  return WorkVec;
295 }
296 
297 static void
301 {
302  DEBUGCOUTFNAME("set_value");
303 }
304 
305 static void
307 {
308  DEBUGCOUTFNAME("set_initial_value");
309 }
310 
311 static unsigned int
313 {
314  DEBUGCOUTFNAME("i_get_num_priv_data");
315  return 0;
316 }
317 
318 static unsigned int
319 i_get_priv_data_idx(const LoadableElem* pEl, const char *s)
320 {
321  DEBUGCOUTFNAME("i_get_priv_data_idx");
322  silent_cerr("Module-template Elem(" << pEl->GetLabel() << "): "
323  "priv data \"" << s << "\" is unknown" << std::endl);
325 
326  return 0;
327 }
328 
329 static doublereal
330 d_get_priv_data(const LoadableElem* pEl, unsigned int i)
331 {
332  DEBUGCOUTFNAME("d_get_priv_data");
333  ASSERT(pEl->iGetNumPrivData() > 0);
334  if (i > pEl->iGetNumPrivData()) {
335  silent_cerr("Module-template Elem(" << pEl->GetLabel() << "): "
336  "illegal private data index " << i << std::endl);
338  }
339 
340  /*
341  * return i-th priv data
342  */
343  return 0.;
344 }
345 
346 static void
348 {
349  DEBUGCOUTFNAME("destroy");
350 
352 
353  /*
354  * delete private data
355  */
356 
357  SAFEDELETE(p);
358 }
359 
360 static int
362 {
363  DEBUGCOUTFNAME("i_get_num_connected_nodes");
364 
365 #if 0
367 #endif /* 0 */
368 
369  return 0;
370 }
371 
372 static void
374  std::vector<const Node *>& connectedNodes)
375 {
376  DEBUGCOUTFNAME("get_connected_nodes");
377 
378 #if 0
380 #endif /* 0 */
381 
382  /*
383  * set args according to element connections
384  */
385  connectedNodes.resize(i_get_num_connected_nodes(pEl));
386 }
387 
388 static struct
390  LOADABLE_VERSION_SET(1, 5, 0),
391 
392  "template",
393  "1.1",
394  "Dipartimento di Ingegneria Aerospaziale, Politecnico di Milano",
395  "template module; use it as guideline for user-defined elements",
396 
397  read,
399  set_dof,
400  output,
401  restart,
403  ass_jac,
404  ass_mats,
405  ass_res,
408  update,
414  set_value,
421  destroy
422 };
423 
424 extern "C" {
425 void *calls = &lc;
426 }
427 
#define LOADABLE_VERSION_SET(maj, min, fix)
Definition: loadable.h:45
void * calls
static void set_value(const LoadableElem *pEl, DataManager *pDM, VectorHandler &X, VectorHandler &XP, SimulationEntity::Hints *ph)
static void output(const LoadableElem *pEl, OutputHandler &OH)
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
void * pGetData(void) const
Definition: loadable.h:310
static unsigned int i_get_priv_data_idx(const LoadableElem *pEl, const char *s)
#define DEBUGCOUTFNAME(fname)
Definition: myassert.h:256
FullSubMatrixHandler & SetFull(void)
Definition: submat.h:1168
static SubVectorHandler & initial_ass_res(LoadableElem *pEl, SubVectorHandler &WorkVec, const VectorHandler &XCurr)
static void before_predict(const LoadableElem *pEl, VectorHandler &X, VectorHandler &XP, VectorHandler &XPrev, VectorHandler &XPPrev)
static void after_predict(const LoadableElem *pEl, VectorHandler &X, VectorHandler &XP)
static void set_initial_value(const LoadableElem *pEl, VectorHandler &X)
static unsigned int i_get_num_dof(const LoadableElem *pEl)
static void update(LoadableElem *pEl, const VectorHandler &X, const VectorHandler &XP)
static void work_space_dim(const LoadableElem *pEl, integer *piNumRows, integer *piNumCols)
std::vector< Hint * > Hints
Definition: simentity.h:89
static int i_get_num_connected_nodes(const LoadableElem *pEl)
static doublereal d_get_priv_data(const LoadableElem *pEl, unsigned int i)
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: loadable.cc:607
static struct LoadableCalls lc
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
static std::ostream & restart(const LoadableElem *pEl, std::ostream &out)
static void initial_work_space_dim(const LoadableElem *pEl, integer *piNumRows, integer *piNumCols)
static SubVectorHandler & ass_res(LoadableElem *pEl, SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
static VariableSubMatrixHandler & ass_jac(LoadableElem *pEl, VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
#define ASSERT(expression)
Definition: colamd.c:977
static void after_convergence(const LoadableElem *, const VectorHandler &, const VectorHandler &)
virtual void ResizeReset(integer, integer)
Definition: submat.cc:182
static unsigned int i_get_num_priv_data(const LoadableElem *pEl)
static unsigned int i_get_initial_num_dof(const LoadableElem *pEl)
static void ass_mats(LoadableElem *pEl, VariableSubMatrixHandler &WorkMatA, VariableSubMatrixHandler &WorkMatB, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
static VariableSubMatrixHandler & initial_ass_jac(LoadableElem *pEl, VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
virtual unsigned int iGetNumPrivData(void) const
Definition: loadable.cc:646
static void get_connected_nodes(const LoadableElem *pEl, std::vector< const Node * > &connectedNodes)
static DofOrder::Order set_dof(const LoadableElem *, unsigned int i)
static void destroy(LoadableElem *pEl)
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
unsigned int GetLabel(void) const
Definition: withlab.cc:62
static void * read(LoadableElem *pEl, DataManager *pDM, MBDynParser &HP)
virtual void Resize(integer iNewSize)=0
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710
virtual void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: loadable.cc:528