MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
stredge.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/stredge.cc,v 1.11 2017/01/12 14:46:44 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 "dataman.h"
35 #include "extedge.h"
36 #include "stredge.h"
37 #include "Rot.hh"
38 
39 #include <fstream>
40 #include <cerrno>
41 #include <algorithm>
42 
43 /* StructExtEDGEForce - begin */
44 
45 /* Costruttore */
47  DataManager *pDM,
48  const StructNode *pRefNode,
49  bool bUseReferenceNodeForces,
50  bool bRotateReferenceNodeForces,
51  std::vector<unsigned>& labels,
52  std::vector<const StructNode *>& nodes,
53  std::vector<Vec3>& offsets,
54  bool bSorted,
55  bool bLabels,
56  bool bOutputAccelerations,
57  unsigned uRot,
58  ExtFileHandlerBase *pEFH,
59  bool bSendAfterPredict,
60  int iCoupling,
61  unsigned uOutputFlags,
62  flag fOut)
63 : Elem(uL, fOut),
64 StructExtForce(uL, pDM, pRefNode, bUseReferenceNodeForces, bRotateReferenceNodeForces,
65  labels, nodes, offsets, bSorted, bLabels, bOutputAccelerations, uRot,
66  pEFH, bSendAfterPredict, iCoupling, uOutputFlags, fOut),
67 m_x(nodes.size()),
68 m_v(nodes.size())
69 {
70  ASSERT(dynamic_cast<ExtFileHandlerEDGE *>(pEFH) != 0);
71  ASSERT(bLabels);
72  ASSERT(!bSorted);
73 }
74 
76 {
77  NO_OP;
78 }
79 
80 void
82 {
83  /* header:
84 ext_model, N, 0, 0, 3
85 *
86 grid_idents, IF, 1, 121, 0
87 1 2 3 4 5 6
88 ...
89 115 116 117 118 119 120
90 121
91 str_coordinates, RF, 3, 121, 0
92 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
93 ...
94 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
95 0.000000
96 
97 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
98 ...
99 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
100 0.000000
101 
102 -0.000062 -0.000023 0.000000 0.000000 0.000000 0.000000
103 ...
104 0.035062 0.036876 0.037783 0.039294 0.040654 0.042014
105 0.043526
106 velocity, RF, 3, 121, 0
107 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
108 ...
109 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
110 0.000000
111 
112 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
113 ...
114 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
115 0.000000
116 
117 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
118 ...
119 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
120 0.000000
121  */
122 
123  if (pRefNode) {
124  const Vec3& xRef = pRefNode->GetXCurr();
125  const Mat3x3& RRef = pRefNode->GetRCurr();
126  const Vec3& vRef = pRefNode->GetVCurr();
127  const Vec3& wRef = pRefNode->GetWCurr();
128 
129  /*
130  p = x + f
131  R = R
132  v = xp + w cross f
133  w = w
134  a = xpp + wp cross f + w cross w cross f
135  wp = wp
136  */
137 
138  std::vector<PointData>::const_iterator point;
139  std::vector<Vec3>::iterator ix;
140  std::vector<Vec3>::iterator iv;
141  for (point = m_Points.begin(), ix = m_x.begin(), iv = m_v.begin(); point != m_Points.end(); ++point, ++ix, ++iv) {
142  Vec3 f(point->pNode->GetRCurr()*point->Offset);
143  Vec3 x(point->pNode->GetXCurr() + f);
144  Vec3 v(point->pNode->GetVCurr() + point->pNode->GetWCurr().Cross(f));
145 
146  *ix = RRef.MulTV(x - xRef);
147  *iv = RRef.MulTV(v - vRef - wRef.Cross(x - xRef));
148  }
149 
150  } else {
151  std::vector<PointData>::const_iterator point;
152  std::vector<Vec3>::iterator ix;
153  std::vector<Vec3>::iterator iv;
154  for (point = m_Points.begin(), ix = m_x.begin(), iv = m_v.begin(); point != m_Points.end(); ++point, ++ix, ++iv) {
155  Vec3 f(point->pNode->GetRCurr()*point->Offset);
156 
157  *ix = point->pNode->GetXCurr() + f;
158  *iv = point->pNode->GetVCurr() + point->pNode->GetWCurr().Cross(f);
159  }
160  }
161 
162  outf <<
163  "ext_model, N, 0, 0, 3\n"
164  "*\n";
165 
166  // labels - TODO: check
167  outf <<
168  "grid_idents, IF, 1, " << m_Points.size() << ", 0\n";
169 
170  int cnt = 0;
171  for (std::vector<PointData>::const_iterator point = m_Points.begin(); point != m_Points.end(); ++point, ++cnt) {
172  if (cnt > 0) {
173  if ((cnt%6) == 0) {
174  outf << "\n";
175  } else {
176  outf << " ";
177  }
178  }
179  outf << point->uLabel;
180  }
181  outf << "\n";
182 
183  // position
184  outf <<
185  "str_coordinates, RF, 3, " << m_Points.size() << ", 0\n";
186 
187  for (int c = 1; c <= 3; c++) {
188  int cnt = 0;
189  for (std::vector<Vec3>::const_iterator i = m_x.begin(); i != m_x.end(); ++i, ++cnt) {
190  if (cnt > 0) {
191  if ((cnt%6) == 0) {
192  outf << "\n";
193  } else {
194  outf << " ";
195  }
196  }
197 
198  outf << (*i)(c);
199  }
200  outf << "\n";
201  }
202 
203  // velocity
204  outf <<
205  "velocity, RF, 3, " << m_Points.size() << ", 0\n";
206 
207  for (int c = 1; c <= 3; c++) {
208  int cnt = 0;
209  for (std::vector<Vec3>::const_iterator i = m_v.begin(); i != m_v.end(); ++i, ++cnt) {
210  if (cnt > 0) {
211  if ((cnt%6) == 0) {
212  outf << "\n";
213  } else {
214  outf << " ";
215  }
216  }
217 
218  outf << (*i)(c);
219  }
220  outf << "\n";
221  }
222 
223  // TODO: other stuff?
224 }
225 
226 void
228 {
230 }
231 
232 void
234 {
235  ASSERT(!bSorted);
236  ASSERT(bLabels);
237 
238  /* header:
239 ext_model, N, 0, 0, 2
240 *
241 grid_idents, IF, 1, 121, 0
242 1 2 3 4 5 6
243 ...
244 115 116 117 118 119 120
245 121
246 force, RF, 3, 121, 0
247 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
248 ...
249 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
250 0.000000
251 
252 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
253 ...
254 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
255 0.000000
256 
257 -0.000062 -0.000023 0.000000 0.000000 0.000000 0.000000
258 ...
259 0.035062 0.036876 0.037783 0.039294 0.040654 0.042014
260 0.043526
261  */
262 
263  std::vector<unsigned> labels(m_Points.size());
264  typedef std::vector<std::vector<PointData>::iterator> RIndexType;
265  RIndexType points(m_Points.size());
266 
267  // cycle
268  unsigned lineno = 0;
269  while (true) {
270  char buf[BUFSIZ], *p;
271  if (mbedge_goto_eol(inf, buf, sizeof(buf))) {
272  if (!inf) {
273  break;
274  }
275  }
276 
277  lineno++;
278 
279  if (buf[0] == '*') {
280  continue;
281  }
282 
283  /*
284 ext_model, N, 0, 0, 2
285  */
286 
287  if (strncasecmp(buf, "ext_model", STRLENOF("ext_model")) == 0) {
288  p = buf + STRLENOF("ext_model");
289 
290  size_t buflen = sizeof(buf) - STRLENOF("ext_model");
291  p = &buf[0] + STRLENOF("ext_model");
292 
293  p = mbedge_eat_sep(p, buflen);
294  if (p == 0) {
295  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
296  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
298  }
299 
300  p = mbedge_eat_field(p, buflen, "N");
301  if (p == 0) {
302  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"N\" "
303  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
305  }
306 
307  p = mbedge_eat_sep(p, buflen);
308  if (p == 0) {
309  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
310  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
312  }
313 
314  p = mbedge_eat_field(p, buflen, "0");
315  if (p == 0) {
316  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"0\" "
317  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
319  }
320 
321  p = mbedge_eat_sep(p, buflen);
322  if (p == 0) {
323  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
324  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
326  }
327 
328  p = mbedge_eat_field(p, buflen, "0");
329  if (p == 0) {
330  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"0\" "
331  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
333  }
334 
335  p = mbedge_eat_sep(p, buflen);
336  if (p == 0) {
337  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
338  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
340  }
341 
342  p = mbedge_eat_field(p, buflen, "2");
343  if (p == 0) {
344  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"2\" "
345  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
347  }
348 
349  continue;
350  }
351 
352  /*
353 grid_idents, IF, 1, 121, 0
354  */
355 
356  if (strncasecmp(buf, "grid_idents", STRLENOF("grid_idents")) == 0) {
357  p = buf + STRLENOF("grid_idents");
358 
359  size_t buflen = sizeof(buf) - STRLENOF("grid_idents");
360  p = &buf[0] + STRLENOF("grid_idents");
361 
362  p = mbedge_eat_sep(p, buflen);
363  if (p == 0) {
364  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
365  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
367  }
368 
369  p = mbedge_eat_field(p, buflen, "IF");
370  if (p == 0) {
371  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"IF\" "
372  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
374  }
375 
376  p = mbedge_eat_sep(p, buflen);
377  if (p == 0) {
378  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
379  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
381  }
382 
383  p = mbedge_eat_field(p, buflen, "1");
384  if (p == 0) {
385  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"1\" "
386  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
388  }
389 
390  p = mbedge_eat_sep(p, buflen);
391  if (p == 0) {
392  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
393  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
395  }
396 
397  char *next;
398  errno = 0;
399  long nids = strtol(p, &next, 10);
400  int save_errno = errno;
401  if (next == p) {
402  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to read IDs number field "
403  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
405 
406  } else if (save_errno == ERANGE) {
407  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): IDs number field overflows "
408  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
410  }
411 
412  if (unsigned(nids) != m_Points.size()) {
413  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): IDs number " << nids << " does not match "
414  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
416  }
417 
418  p = next;
419 
420  p = mbedge_eat_sep(p, buflen);
421  if (p == 0) {
422  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
423  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
425  }
426 
427  p = mbedge_eat_field(p, buflen, "0");
428  if (p == 0) {
429  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"0\" "
430  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
432  }
433 
434  for (std::vector<unsigned>::iterator id = labels.begin(); id != labels.end(); ++id) {
435  long idx;
436 
437  inf >> idx;
438 
439  if (idx < 0) {
440  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): invalid ID #" << id - labels.begin() << std::endl);
442  }
443 
444  if (std::find(labels.begin(), id, unsigned(idx)) < id) {
445  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): "
446  "duplicate ID #" << id - labels.begin() << " \"" << idx << "\"" << std::endl);
448  }
449 
450  *id = idx;
451  }
452 
453 
454  mbedge_goto_eol(inf, buf, sizeof(buf));
455 
456  for (std::vector<PointData>::iterator point = m_Points.begin(); point != m_Points.end(); ++point) {
457  std::vector<unsigned>::iterator id = std::find(labels.begin(), labels.end(), point->uLabel);
458  if (id == labels.end()) {
459  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): "
460  "ID \"" << point->uLabel << "\" missing" << std::endl);
462  }
463 
464  points[id - labels.begin()] = point;
465  }
466 
467  continue;
468  }
469 
470  /*
471 force, RF, 3, 121, 0
472  */
473 
474  if (strncasecmp(buf, "force", STRLENOF("force")) == 0) {
475  p = buf + STRLENOF("force");
476 
477  size_t buflen = sizeof(buf) - STRLENOF("force");
478  p = &buf[0] + STRLENOF("force");
479 
480  p = mbedge_eat_sep(p, buflen);
481  if (p == 0) {
482  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
483  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
485  }
486 
487  p = mbedge_eat_field(p, buflen, "RF");
488  if (p == 0) {
489  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"RF\" "
490  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
492  }
493 
494  p = mbedge_eat_sep(p, buflen);
495  if (p == 0) {
496  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
497  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
499  }
500 
501  p = mbedge_eat_field(p, buflen, "3");
502  if (p == 0) {
503  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"3\" "
504  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
506  }
507 
508  p = mbedge_eat_sep(p, buflen);
509  if (p == 0) {
510  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
511  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
513  }
514 
515  char *next;
516  errno = 0;
517  long nids = strtol(p, &next, 10);
518  int save_errno = errno;
519  if (next == p) {
520  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to read IDs number field "
521  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
523 
524  } else if (save_errno == ERANGE) {
525  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): IDs number field overflows "
526  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
528  }
529  if (unsigned(nids) != m_Points.size()) {
530  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): IDs number " << nids << " does not match "
531  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
533  }
534 
535  p = next;
536 
537  p = mbedge_eat_sep(p, buflen);
538  if (p == 0) {
539  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip separator "
540  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
542  }
543 
544  p = mbedge_eat_field(p, buflen, "0");
545  if (p == 0) {
546  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unable to skip field \"0\" "
547  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
549  }
550 
551  for (RIndexType::iterator p = points.begin(); p != points.end(); p++) {
552  double d;
553 
554  inf >> d;
555 
556  (*p)->F(1) = d;
557  }
558 
559  mbedge_goto_eol(inf, buf, sizeof(buf));
560 
561  for (RIndexType::const_iterator p = points.begin(); p != points.end(); p++) {
562  double d;
563 
564  inf >> d;
565 
566  (*p)->F(2) = d;
567  }
568 
569  mbedge_goto_eol(inf, buf, sizeof(buf));
570 
571  for (RIndexType::const_iterator p = points.begin(); p != points.end(); p++) {
572  double d;
573 
574  inf >> d;
575 
576  (*p)->F(3) = d;
577  }
578 
579  mbedge_goto_eol(inf, buf, sizeof(buf));
580 
581  continue;
582  }
583 
584  silent_cerr("StructExtEDGEForce(" << GetLabel() << "): unexpected line=" << lineno << ", "
585  "\"" << buf << "\"" << std::endl);
587  }
588 }
589 
590 void
592 {
594 }
595 
StructExtEDGEForce(unsigned int uL, DataManager *pDM, const StructNode *pRefNode, bool bUseReferenceNodeForces, bool bRotateReferenceNodeForces, std::vector< unsigned > &Labels, std::vector< const StructNode * > &Nodes, std::vector< Vec3 > &Offsets, bool bSorted, bool bLabels, bool bOutputAccelerations, unsigned bRot, ExtFileHandlerBase *pEFH, bool bSendAfterPredict, int iCoupling, unsigned uOutputFlags, flag fOut)
Definition: stredge.cc:46
Vec3 Cross(const Vec3 &v) const
Definition: matvec3.h:218
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
char * mbedge_eat_sep(char *buf, size_t &buflen)
Definition: extedge.cc:74
virtual void RecvFromFileDes(int infd)
Definition: stredge.cc:591
bool bLabels
Definition: strext.h:69
Converged c
Definition: extforce.h:192
#define NO_OP
Definition: myassert.h:74
virtual ~StructExtEDGEForce(void)
Definition: stredge.cc:75
Vec3 MulTV(const Vec3 &v) const
Definition: matvec3.cc:482
std::vector< Vec3 > m_x
Definition: stredge.h:44
static int labels
bool bSorted
Definition: strext.h:70
std::vector< PointData > m_Points
Definition: strext.h:67
int mbedge_goto_eol(std::istream &fin, char *buf, size_t bufsiz)
Definition: extedge.cc:49
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
#define ASSERT(expression)
Definition: colamd.c:977
char * mbedge_eat_field(char *buf, size_t &buflen, const char *val)
Definition: extedge.cc:94
std::vector< Vec3 > m_v
Definition: stredge.h:45
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310
static int nodes
#define STRLENOF(s)
Definition: mbdyn.h:166
Definition: elem.h:75
virtual void SendToStream(std::ostream &outf, ExtFileHandlerBase::SendWhen when)
Definition: stredge.cc:81
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322
virtual void SendToFileDes(int outfd, ExtFileHandlerBase::SendWhen when)
Definition: stredge.cc:227
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
unsigned int GetLabel(void) const
Definition: withlab.cc:62
const StructNode * pRefNode
Definition: strext.h:49
virtual void RecvFromStream(std::istream &inf)
Definition: stredge.cc:233