MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
modaledge.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/modaledge.cc,v 1.28 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 /* Forza */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include <cerrno>
37 
38 #include "extedge.h"
39 #include "modaledge.h"
40 
41 /* ExtForceEDGE - begin */
42 
44 : pAP(0)
45 {
47  if (pAP == 0) {
48  silent_cerr("ExtForceEDGE::ExtForceEDGE: "
49  "warning, unable to link to air properties (no airstream contribution to velocity)" << std::endl);
50  }
51 }
52 
54 {
55  NO_OP;
56 }
57 
58 bool
60  bool bRigid, unsigned uModes)
61 {
62  // consistency is checked later
63  return true;
64 }
65 
66 /* ExtForceEDGE - end */
67 
68 
69 /* ExtRigidForceEDGE - begin */
70 
72 : ExtForceEDGE(pDM)
73 {
74  NO_OP;
75 }
76 
77 /*
78 
79 * intestazione a scelta
80 body_forces,R,1,6,0
81 0.1 0.2 0.3 0.4 0.5 0.6
82 
83  * NOTE: force and moment orientation wrt/ the global reference frame,
84  * the pole of the moment is the node
85 */
86 
87 unsigned
89  unsigned uFlags,
90  unsigned& uLabel,
91  Vec3& f, Vec3& m,
92  std::vector<doublereal>& a)
93 {
94  std::istream& fin = *pEFH->GetInStream();
95  unsigned uOutFlags = ExtModalForceBase::EMF_NONE;
96 
97  ASSERT((uFlags & ExtModalForceBase::EMF_RIGID) != 0);
98  ASSERT((uFlags & ~ExtModalForceBase::EMF_ALL) == 0);
99 
100  // fake
101  uLabel = 0;
102 
103  // cycle
104  unsigned lineno = 0;
105  while (true) {
106  char buf[BUFSIZ], *p;
107  if (mbedge_goto_eol(fin, buf, sizeof(buf))) {
108  if (!fin) {
109  break;
110  }
111  }
112 
113  lineno++;
114 
115  if (buf[0] == '*') {
116  continue;
117  }
118 
119  if (strncasecmp(buf, "body_forces", STRLENOF("body_forces")) == 0) {
120  size_t buflen = sizeof(buf) - STRLENOF("body_forces");
121  p = &buf[0] + STRLENOF("body_forces");
122 
123  p = mbedge_eat_sep(p, buflen);
124  if (p == 0) {
125  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
126  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
128  }
129 
130  p = mbedge_eat_field(p, buflen, "R");
131  if (p == 0) {
132  silent_cerr("ExtRigidForceEDGE: unable to skip field \"R\" "
133  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
135  }
136 
137  p = mbedge_eat_sep(p, buflen);
138  if (p == 0) {
139  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
140  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
142  }
143 
144  p = mbedge_eat_field(p, buflen, "1");
145  if (p == 0) {
146  silent_cerr("ExtRigidForceEDGE: unable to skip field \"1\" "
147  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
149  }
150 
151  p = mbedge_eat_sep(p, buflen);
152  if (p == 0) {
153  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
154  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
156  }
157 
158  p = mbedge_eat_field(p, buflen, "6");
159  if (p == 0) {
160  silent_cerr("ExtRigidForceEDGE: unable to skip field \"6\" "
161  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
163  }
164 
165  p = mbedge_eat_sep(p, buflen);
166  if (p == 0) {
167  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
168  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
170  }
171 
172  p = mbedge_eat_field(p, buflen, "0");
173  if (p == 0) {
174  silent_cerr("ExtRigidForceEDGE: unable to skip field \"0\" "
175  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
177  }
178 
179  p = mbedge_eat_sep(p, buflen);
180  if (p == 0) {
181  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
182  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
184  }
185 
186  if (p[0] != '\0' && p[0] != '\n') {
187  silent_cerr("ExtRigidForceEDGE: no line terminator "
188  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
190  }
191 
193  doublereal b[6];
194  for (int i = 0; i < 6; i++) {
195  fin >> b[i];
196  }
197  f = Vec3(&b[0]);
198  m = Vec3(&b[3]);
199 
200  uOutFlags |= (uFlags & ExtModalForceBase::EMF_RIGID_DETECT_MASK);
201  }
202 
203  // skip to eol
204  if (mbedge_goto_eol(fin, buf, sizeof(buf))) {
205  silent_cerr("ExtRigidForceEDGE: unable to skip to end of line "
206  "at line=" << lineno << std::endl);
208  }
209  continue;
210  }
211 
212  silent_cerr("ExtRigidForceEDGE: unexpected line=" << lineno << ", "
213  "\"" << buf << "\"" << std::endl);
215  }
216 
217  return uOutFlags;
218 }
219 
220 /*
221 
222 * intestazione a scelta
223 body_dynamics,N,0,0,3
224 * Body linear velocity in body axes
225 VRELV,R,1,3,0
226 100.0 0.0 0.0
227 * Body angular velocity in body axes
228 VRELM,R,1,3,0
229 0.0 0.1 0.0
230 * Body reference frame cosines (listed by columns)
231 OMGMAN,R,3,3,0
232 11 21 31
233 12 22 32
234 13 23 33
235 
236  * NOTE:
237  * - node velocity wrt/ the reference frame of the node,
238  * including the wind velocity (from "air properties")
239  * - node angular velocity wrt/ the reference frame of the node
240  * - node orientation from global to node reference frame
241  * (the transpose of node's R)
242  */
243 
244 void
246  ExtFileHandlerBase *pEFH, unsigned uFlags,
247  unsigned uLabel,
248  const Vec3& x, const Mat3x3& R, const Vec3& v, const Vec3& w,
249  const std::vector<doublereal>& q,
250  const std::vector<doublereal>& qP)
251 {
252  std::ostream& fout = *pEFH->GetOutStream();
253  ASSERT((uFlags & ExtModalForceBase::EMF_RIGID) != 0);
254  ASSERT((uFlags & ~ExtModalForceBase::EMF_ALL) == 0);
255 
256  Vec3 vv = v;
257  Vec3 v_infty;
258 
259  if (pAP && pAP->GetVelocity(x, v_infty)) {
260  vv -= v_infty;
261  }
262 
263  Vec3 vB = R.MulTV(vv);
264  Vec3 wB = R.MulTV(w);
265 
266  fout << "* MBDyn to EDGE rigid body dynamics\n"
267  "body_dynamics,N,0,0,3\n"
268  "* Body linear velocity in body axes\n"
269  "VRELV,R,1,3,0\n"
270  << vB(1) << " " << vB(2) << " " << vB(3) << "\n"
271  "* Body angular velocity in body axes\n"
272  "VRELM,R,1,3,0\n"
273  << wB(1) << " " << wB(2) << " " << wB(3) << "\n"
274  "* Body reference frame cosines (listed by columns)\n"
275  "OMGMAN,R,3,3,0\n"
276  // NOTE: this is the transpose of the node's R
277  << R(1, 1) << " " << R(2, 1) << " " << R(3, 1) << "\n"
278  << R(1, 2) << " " << R(2, 2) << " " << R(3, 2) << "\n"
279  << R(1, 3) << " " << R(2, 3) << " " << R(3, 3) << "\n";
280 }
281 
282 /* ExtRigidForceEDGE - end */
283 
284 /* ExtModalForceEDGE - begin */
285 
287 : ExtForceEDGE(pDM)
288 {
289  NO_OP;
290 }
291 
292 /*
293 
294 * intestazione a scelta
295 modal_force_flow,R,5,1,0
296 0.1 0.2 0.3 0.4 0.5
297 
298  */
299 
300 unsigned
302  ExtFileHandlerBase *pEFH,
303  unsigned uFlags,
304  unsigned& uLabel,
305  Vec3& f, Vec3& m,
306  std::vector<doublereal>& a)
307 {
308  std::istream& fin = *pEFH->GetInStream();
309  unsigned uOutFlags = ExtModalForceBase::EMF_NONE;
310 
311  ASSERT((uFlags & ExtModalForceBase::EMF_MODAL) != 0);
312  ASSERT((uFlags & ~ExtModalForceBase::EMF_ALL) == 0);
313 
314  // fake
315  uLabel = 0;
316 
317  // cycle
318  unsigned lineno = 0;
319  while (true) {
320  char buf[BUFSIZ], *p;
321  if (mbedge_goto_eol(fin, buf, sizeof(buf))) {
322  if (!fin) {
323  break;
324  }
325  }
326 
327  lineno++;
328 
329  if (buf[0] == '*') {
330  continue;
331  }
332 
333  if (strncasecmp(buf, "modal_force_flow", STRLENOF("modal_force_flow")) == 0) {
334  p = buf + STRLENOF("modal_force_flow");
335 
336  size_t buflen = sizeof(buf) - STRLENOF("modal_force_flow");
337  p = &buf[0] + STRLENOF("modal_force_flow");
338 
339  p = mbedge_eat_sep(p, buflen);
340  if (p == 0) {
341  silent_cerr("ExtModalForceEDGE: unable to skip separator "
342  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
344  }
345 
346  p = mbedge_eat_field(p, buflen, "R");
347  if (p == 0) {
348  silent_cerr("ExtModalForceEDGE: unable to skip field \"R\" "
349  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
351  }
352 
353  p = mbedge_eat_sep(p, buflen);
354  if (p == 0) {
355  silent_cerr("ExtModalForceEDGE: unable to skip separator "
356  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
358  }
359 
360  char *next;
361  errno = 0;
362  long nmodes = strtol(p, &next, 10);
363  int save_errno = errno;
364  if (next == p) {
365  silent_cerr("ExtModalForceEDGE: unable to skip modes number field "
366  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
368 
369  } else if (save_errno == ERANGE) {
370  silent_cerr("ExtModalForceEDGE: modes number field overflows "
371  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
373  }
374 
375  p = mbedge_eat_sep(next, buflen);
376  if (p == 0) {
377  silent_cerr("ExtModalForceEDGE: unable to skip separator "
378  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
380  }
381 
382  p = mbedge_eat_field(p, buflen, "1");
383  if (p == 0) {
384  silent_cerr("ExtModalForceEDGE: unable to skip field \"1\" "
385  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
387  }
388 
389  p = mbedge_eat_sep(p, buflen);
390  if (p == 0) {
391  silent_cerr("ExtModalForceEDGE: unable to skip separator "
392  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
394  }
395 
396  p = mbedge_eat_field(p, buflen, "0");
397  if (p == 0) {
398  silent_cerr("ExtModalForceEDGE: unable to skip field \"0\" "
399  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
401  }
402 
403  p = mbedge_eat_sep(p, buflen);
404  if (p == 0) {
405  silent_cerr("ExtModalForceEDGE: unable to skip separator "
406  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
408  }
409 
410  if (p[0] != '\0' && p[0] != '\n') {
411  silent_cerr("ExtModalForceEDGE: no line terminator "
412  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
414  }
415 
416  if (std::vector<doublereal>::size_type(nmodes) != a.size()) {
417  silent_cerr("ExtModalForceEDGE: mode number mismatch, "
418  "expected " << a.size() << " got " << nmodes << std::endl);
420  }
421 
423  for (std::vector<doublereal>::iterator i = a.begin();
424  i != a.end(); ++i)
425  {
426  fin >> *i;
427  }
428 
429  uOutFlags |= (uFlags & ExtModalForceBase::EMF_MODAL_DETECT_MASK);
430  }
431 
432  // skip to eol
433  if (mbedge_goto_eol(fin, buf, sizeof(buf))) {
434  silent_cerr("ExtModalForceEDGE: unable to skip to end of line "
435  "at line=" << lineno << std::endl);
437  }
438  continue;
439  }
440 
441  silent_cerr("ExtModalForceEDGE: unexpected line=" << lineno << ", "
442  "\"" << buf << "\"" << std::endl);
444  }
445 
446  return uOutFlags;
447 }
448 
449 /*
450 
451 * intestazione a scelta
452 modal_state,N,0,0,2
453 modal_coordinate,R,1,5,0
454 1.0 2.0 3.0 4.0 5.0
455 modal_velocity,R,1,5,0
456 0.1 0.2 0.3 0.4 0.5
457 
458  */
459 
460 void
462  ExtFileHandlerBase *pEFH, unsigned uFlags,
463  unsigned uLabel,
464  const Vec3& x, const Mat3x3& R, const Vec3& v, const Vec3& w,
465  const std::vector<doublereal>& q,
466  const std::vector<doublereal>& qP)
467 {
468  std::ostream& fout = *pEFH->GetOutStream();
469  ASSERT((uFlags & ExtModalForceBase::EMF_MODAL) != 0);
470  ASSERT((uFlags & ~ExtModalForceBase::EMF_ALL) == 0);
471 
472  fout << "* MBDyn to EDGE modal dynamics\n"
473  "modal_state,N,0,0,2\n"
474  "modal_coordinate,R," << q.size() << ",1,0\n"
475  << q[0];
476  for (std::vector<doublereal>::const_iterator i = q.begin() + 1;
477  i < q.end(); ++i)
478  {
479  fout << " " << *i;
480  }
481  fout << "\n"
482  "modal_velocity,R," << qP.size() << ",1,0\n"
483  << qP[0];
484  for (std::vector<doublereal>::const_iterator i = qP.begin() + 1;
485  i < qP.end(); ++i)
486  {
487  fout << " " << *i;
488  }
489  fout << "\n";
490 }
491 
492 /* ExtModalForceEDGE - end */
493 
virtual std::istream * GetInStream(void)
Definition: extforce.cc:78
virtual ~ExtForceEDGE(void)
Definition: modaledge.cc:53
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual Vec3 GetVelocity(const Vec3 &) const
Definition: aerodyn.cc:208
char * mbedge_eat_sep(char *buf, size_t &buflen)
Definition: extedge.cc:74
#define NO_OP
Definition: myassert.h:74
bool Prepare(ExtFileHandlerBase *pEFH, unsigned uLabel, bool bRigid, unsigned uModes)
Definition: modaledge.cc:59
Vec3 MulTV(const Vec3 &v) const
Definition: matvec3.cc:482
Elem * pFindElem(Elem::Type Typ, unsigned int uElem, unsigned int iDeriv) const
Definition: elman.cc:650
DataManager * pDM
Definition: mbpar.h:252
unsigned Recv(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &a)
Definition: modaledge.cc:301
int mbedge_goto_eol(std::istream &fin, char *buf, size_t bufsiz)
Definition: extedge.cc:49
void Send(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned uLabel, const Vec3 &x, const Mat3x3 &R, const Vec3 &v, const Vec3 &w, const std::vector< doublereal > &q, const std::vector< doublereal > &qP)
Definition: modaledge.cc:461
unsigned Recv(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &a)
Definition: modaledge.cc:88
#define ASSERT(expression)
Definition: colamd.c:977
virtual std::ostream * GetOutStream(void)
Definition: extforce.cc:72
char * mbedge_eat_field(char *buf, size_t &buflen, const char *val)
Definition: extedge.cc:94
const AirProperties * pAP
Definition: modaledge.h:44
ExtRigidForceEDGE(DataManager *pDM)
Definition: modaledge.cc:71
#define STRLENOF(s)
Definition: mbdyn.h:166
ExtForceEDGE(DataManager *pDM)
Definition: modaledge.cc:43
static const doublereal a
Definition: hfluid_.h:289
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
double doublereal
Definition: colamd.c:52
void Send(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned uLabel, const Vec3 &x, const Mat3x3 &R, const Vec3 &v, const Vec3 &w, const std::vector< doublereal > &q, const std::vector< doublereal > &qP)
Definition: modaledge.cc:245
ExtModalForceEDGE(DataManager *pDM)
Definition: modaledge.cc:286
Mat3x3 R