MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
socketstreammotionelem.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/socketstreammotionelem.cc,v 1.25 2017/07/26 10:10:00 zanoni 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  * 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 "socketstreammotionelem.h"
36 #include "geomdata.h"
37 
38 /* StreamContentMotion - begin */
39 
41  std::vector<const StructNode *>& n,
43 : StreamContent(0, pMod), uFlags(uFlags), nodes(n)
44 {
45  /* FIXME: size depends on the type of the output signals */
46  ASSERT(uFlags != 0);
47  unsigned int size = 0;
48  if (uFlags & GeometryData::X) {
49  size += sizeof(doublereal)*3;
50  }
51  if (uFlags & GeometryData::R) {
52  size += sizeof(doublereal)*9;
53  }
54  if (uFlags & GeometryData::V) {
55  size += sizeof(doublereal)*3;
56  }
57  if (uFlags & GeometryData::W) {
58  size += sizeof(doublereal)*3;
59  }
60  size *= nodes.size();
61 
62  buf.resize(size);
63  memset(&buf[0], 0, size);
64  m_pMod->Set(size, &buf[0]);
65 }
66 
68 {
69  NO_OP;
70 }
71 
72 void
74 {
75  char *curbuf = &buf[0];
76  for (unsigned int i = 0; i < nodes.size(); i++) {
77  /* assign value somewhere into mailbox buffer */
78  if (uFlags & GeometryData::X) {
79  const Vec3& X = nodes[i]->GetXCurr();
80 
81  doublereal *dbuf = (doublereal *)curbuf;
82  dbuf[0] = X(1);
83  dbuf[1] = X(2);
84  dbuf[2] = X(3);
85 
86  curbuf += 3*sizeof(doublereal);
87  }
88 
89  if (uFlags & GeometryData::R) {
90  const Mat3x3& R = nodes[i]->GetRCurr();
91 
92  doublereal *dbuf = (doublereal *)curbuf;
93  dbuf[0] = R(1, 1);
94  dbuf[1] = R(1, 2);
95  dbuf[2] = R(1, 3);
96  dbuf[3] = R(2, 1);
97  dbuf[4] = R(2, 2);
98  dbuf[5] = R(2, 3);
99  dbuf[6] = R(3, 1);
100  dbuf[7] = R(3, 2);
101  dbuf[8] = R(3, 3);
102 
103  curbuf += 9*sizeof(doublereal);
104  }
105 
106  if (uFlags & GeometryData::RT) {
107  const Mat3x3& R = nodes[i]->GetRCurr();
108 
109  doublereal *dbuf = (doublereal *)curbuf;
110  dbuf[0] = R(1, 1);
111  dbuf[1] = R(2, 1);
112  dbuf[2] = R(3, 1);
113  dbuf[3] = R(1, 2);
114  dbuf[4] = R(2, 2);
115  dbuf[5] = R(3, 2);
116  dbuf[6] = R(1, 3);
117  dbuf[7] = R(2, 3);
118  dbuf[8] = R(3, 3);
119 
120  curbuf += 9*sizeof(doublereal);
121  }
122 
123  if (uFlags & GeometryData::V) {
124  const Vec3& V = nodes[i]->GetVCurr();
125 
126  doublereal *dbuf = (doublereal *)curbuf;
127  dbuf[0] = V(1);
128  dbuf[1] = V(2);
129  dbuf[2] = V(3);
130 
131  curbuf += 3*sizeof(doublereal);
132  }
133 
134  if (uFlags & GeometryData::W) {
135  const Vec3& W = nodes[i]->GetWCurr();
136 
137  doublereal *dbuf = (doublereal *)curbuf;
138  dbuf[0] = W(1);
139  dbuf[1] = W(2);
140  dbuf[2] = W(3);
141 
142  curbuf += 3*sizeof(doublereal);
143  }
144  }
145 
146  m_pMod->Modify();
147 
148  ASSERT(curbuf == &buf[buf.size()]);
149 }
150 
151 unsigned
153 {
154  return buf.size()/sizeof(doublereal);
155 }
156 
157 std::vector<const StructNode *>::const_iterator
159 {
160  return nodes.begin();
161 }
162 
163 std::vector<const StructNode *>::const_iterator
165 {
166  return nodes.end();
167 }
168 
169 const unsigned
171 {
172  return uFlags;
173 }
174 /* StreamContentMotion - end */
175 
virtual void Modify(void)=0
const unsigned uGetFlags(void) const
Definition: matvec3.h:98
std::vector< const StructNode * > nodes
StreamContentMotion(unsigned uFlags, std::vector< const StructNode * > &n, StreamContent::Modifier *pMod)
#define NO_OP
Definition: myassert.h:74
virtual ~StreamContentMotion(void)
std::vector< const StructNode * >::const_iterator nodes_begin(void) const
virtual void Set(size_t size, const char *buf)=0
std::vector< char > buf
unsigned GetNumChannels(void) const
#define ASSERT(expression)
Definition: colamd.c:977
std::vector< const StructNode * >::const_iterator nodes_end(void) const
static int nodes
Modifier * m_pMod
double doublereal
Definition: colamd.c:52
Mat3x3 R