MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
modalforce.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/modalforce.cc,v 1.24 2017/01/12 14:46:43 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 2007-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 <fstream>
35 #include <algorithm>
36 
37 #include "dataman.h"
38 #include "modalforce.h"
39 
40 /* ModalForce - begin */
41 
42 /* Costruttore */
43 ModalForce::ModalForce(unsigned int uL,
44  const Modal *pmodal,
45  const std::vector<unsigned int>& modeList,
46  std::vector<DriveCaller *>& f,
47  const Mat3xN *mt,
48  const Mat3xN *mr,
49  flag fOut)
50 : Elem(uL, fOut),
51 Force(uL, fOut),
52 pModal(pmodal),
53 modeList(modeList),
54 f(f),
55 Mt(mt),
56 Mr(mr),
57 F(Zero3),
58 M(Zero3)
59 {
60  ASSERT(pModal != 0);
61 }
62 
64 {
65  if (!f.empty()) {
66  for (unsigned i = 0; i < f.size(); i++) {
67  delete f[i];
68  }
69  }
70 
71  if (Mt) {
72  delete Mt;
73  }
74 
75  if (Mr) {
76  delete Mr;
77  }
78 }
79 
82  doublereal dCoef,
83  const VectorHandler& XCurr,
84  const VectorHandler& XPrimeCurr)
85 {
86  integer iR, iC;
87  WorkSpaceDim(&iR, &iC);
88  WorkVec.ResizeReset(iR);
89 
90  integer iIdx = 1;
91  const StructNode *pNode = pModal->pGetModalNode();
92  integer iFirstIndex = 0;
93  if (pNode) {
94  iFirstIndex = pNode->iGetFirstMomentumIndex();
95 
96  for (integer iCnt = 1; iCnt <= 6; iCnt++) {
97  WorkVec.PutRowIndex(iCnt, iFirstIndex + iCnt);
98  }
99 
100  F = Zero3;
101  M = Zero3;
102 
103  iIdx += 6;
104 
105  }
106 
107  integer iModalIndex = pModal->iGetModalIndex() + pModal->uGetNModes();
108  for (unsigned iMode = 0; iMode < modeList.size(); iMode++) {
109  doublereal d = f[iMode]->dGet();
110  WorkVec.PutItem(iIdx + iMode, iModalIndex + modeList[iMode], d);
111  if (pNode) {
112  F += Mt->GetVec(iMode + 1)*d;
113  M += Mr->GetVec(iMode + 1)*d;
114  }
115  }
116 
117  if (pNode) {
118  WorkVec.Put(1, pNode->GetRCurr()*F);
119  WorkVec.Put(4, pNode->GetRCurr()*M);
120  }
121 
122  return WorkVec;
123 }
124 
125 void
127 {
128  if (bToBeOutput()) {
129  std::ostream& out = OH.Forces();
130 
131  out << GetLabel();
132 
133  if (pModal->pGetModalNode()) {
134  out << " " << F << " " << M;
135  }
136 
137  for (std::vector<DriveCaller *>::const_iterator i = f.begin(); i != f.end(); ++i) {
138  out << " " << (*i)->dGet();
139  }
140  out << std::endl;
141  }
142 }
143 
144 Elem*
146  MBDynParser& HP,
147  unsigned int uLabel)
148 {
149  const Modal *pModal = pDM->ReadElem<const Modal, const Joint, Elem::JOINT>(HP);
150 
151  std::vector<unsigned int> modeList;
152  if (HP.IsKeyWord("list")) {
153  const std::vector<unsigned int>& uModeList = pModal->GetModeList();
154  std::vector<bool> gotIt(pModal->uGetNModes());
155  for (integer i = 0; i < pModal->uGetNModes(); i++) {
156  gotIt[i] = false;
157  }
158 
159  int iNumModes = HP.GetInt();
160  if (iNumModes <= 0 || iNumModes > pModal->uGetNModes()) {
161  silent_cerr("ModalForce(" << uLabel << "): "
162  "illegal mode number " << iNumModes
163  << " at line " << HP.GetLineData() << std::endl);
165  }
166  modeList.resize(iNumModes);
167 
168  for (int i = 0; i < iNumModes; i++) {
169  int iM = HP.GetInt();
170  if (iM <= 0) {
171  silent_cerr("ModalForce(" << uLabel << "): "
172  "illegal mode " << iM
173  << " at line " << HP.GetLineData()
174  << std::endl);
176  }
177 
178  std::vector<unsigned int>::const_iterator
179  iv = std::find(uModeList.begin(), uModeList.end(), (unsigned int)iM);
180  if (iv == uModeList.end()) {
181  silent_cerr("ModalForce(" << uLabel << "): "
182  "mode " << iM << " not active "
183  "in Modal(" << pModal->GetLabel() << ")"
184  "at line " << HP.GetLineData() << std::endl);
186  }
187  int iModeIdx = iv - uModeList.begin();
188 
189  if (gotIt[iModeIdx]) {
190  silent_cerr("ModalForce(" << uLabel << "): "
191  "mode " << iModeIdx << " already set "
192  "at line " << HP.GetLineData() << std::endl);
194  }
195 
196  modeList[i] = iModeIdx + 1;
197  gotIt[iModeIdx] = true;
198  }
199 
200  } else {
201  modeList.resize(pModal->uGetNModes());
202  for (integer i = 0; i < pModal->uGetNModes(); i++) {
203  modeList[i] = i + 1;
204  }
205  }
206 
207  std::vector<DriveCaller *> f(modeList.size());
208  Mat3xN *Mt = 0;
209  Mat3xN *Mr = 0;
210  const StructNode *pNode = pModal->pGetModalNode();
211  if (pNode) {
212  Mt = new Mat3xN(modeList.size(), 0.);
213  Mr = new Mat3xN(modeList.size(), 0.);
214  }
215  for (unsigned i = 0; i < f.size(); i++) {
216  f[i] = HP.GetDriveCaller(false);
217  if (f[i] == 0) {
218  silent_cerr("ModalForce(" << uLabel << "): "
219  "unable to read DriveCaller for mode #" << i + 1
220  << " (mode number " << modeList[i] << ") "
221  "at line " << HP.GetLineData() << std::endl);
223  }
224 
225  if (pNode && HP.IsKeyWord("resultant")) {
226  for (unsigned r = 1; r <= 3; r++) {
227  (*Mt)(r, i + 1) = HP.GetReal();
228  }
229 
230  for (unsigned r = 1; r <= 3; r++) {
231  (*Mr)(r, i + 1) = HP.GetReal();
232  }
233  }
234  }
235 
236  flag fOut = pDM->fReadOutput(HP, Elem::FORCE);
237  Elem *pEl = 0;
239  ModalForce(uLabel, pModal, modeList, f, Mt, Mr, fOut));
240 
241  return pEl;
242 }
243 
flag fReadOutput(MBDynParser &HP, const T &t) const
Definition: dataman.h:1064
const ModalNode * pGetModalNode(void) const
Definition: modal.h:395
const Vec3 Zero3(0., 0., 0.)
long int flag
Definition: mbdyn.h:43
virtual bool bToBeOutput(void) const
Definition: output.cc:890
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual void ResizeReset(integer)
Definition: vh.cc:55
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
Elem * ReadElem(MBDynParser &HP, Elem::Type type) const
Definition: dataman3.cc:2334
std::vector< unsigned int > modeList
Definition: modalforce.h:47
integer uGetNModes(void) const
Definition: modal.h:363
const Modal * pModal
Definition: modalforce.h:46
Definition: force.h:46
const Mat3xN * Mt
Definition: modalforce.h:49
virtual void PutItem(integer iSubRow, integer iRow, const doublereal &dCoef)
Definition: submat.h:1445
Definition: modal.h:74
virtual void Output(OutputHandler &OH) const
Definition: modalforce.cc:126
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
Elem * ReadModalForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
Definition: modalforce.cc:145
Vec3 GetVec(integer iCol) const
Definition: matvec3n.cc:553
DataManager * pDM
Definition: mbpar.h:252
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
const doublereal & dGet(unsigned short int iRow) const
Definition: matvec3.h:285
virtual integer iGetFirstMomentumIndex(void) const =0
#define ASSERT(expression)
Definition: colamd.c:977
std::vector< DriveCaller * > f
Definition: modalforce.h:48
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
const Mat3xN * Mr
Definition: modalforce.h:50
virtual ~ModalForce(void)
Definition: modalforce.cc:63
integer iGetModalIndex(void) const
Definition: modal.h:391
virtual void Put(integer iRow, const Vec3 &v)
Definition: vh.cc:93
Definition: elem.h:75
ModalForce(unsigned int uL, const Modal *pmodal, const std::vector< unsigned int > &modeList, std::vector< DriveCaller * > &f, const Mat3xN *Mt, const Mat3xN *Mr, flag fOut)
Definition: modalforce.cc:43
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: modalforce.h:70
DriveCaller * GetDriveCaller(bool bDeferred=false)
Definition: mbpar.cc:2033
Definition: joint.h:50
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
unsigned int GetLabel(void) const
Definition: withlab.cc:62
const std::vector< unsigned int > & GetModeList(void) const
Definition: modal.h:367
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: modalforce.cc:81
std::ostream & Forces(void) const
Definition: output.h:450
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056