MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ExtModalForce Class Reference

#include <modalext.h>

Inheritance diagram for ExtModalForce:
Collaboration diagram for ExtModalForce:

Public Member Functions

 ExtModalForce (void)
 
virtual ~ExtModalForce (void)
 
virtual bool Prepare (ExtFileHandlerBase *pEFH, unsigned uLabel, bool bRigid, unsigned uModes)
 
virtual unsigned Recv (ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
 
virtual 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)
 
- Public Member Functions inherited from ExtModalForceBase
virtual ~ExtModalForceBase (void)
 

Protected Member Functions

virtual unsigned RecvFromStream (std::istream &inf, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
 
virtual unsigned RecvFromFileDes (int infd, int recv_flags, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
 
virtual void SendToStream (std::ostream &outf, 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)
 
virtual void SendToFileDes (int outfd, int send_flags, 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)
 

Additional Inherited Members

- Public Types inherited from ExtModalForceBase
enum  BitMask {
  EMF_NONE = 0x0U, EMF_RIGID = 0x1U, EMF_MODAL = 0x2U, EMF_ALL = (EMF_RIGID | EMF_MODAL),
  EMF_RIGID_DETECT = 0x10U, EMF_MODAL_DETECT = 0x20U, EMF_RIGID_DETECT_MASK = (EMF_RIGID_DETECT | EMF_RIGID), EMF_MODAL_DETECT_MASK = (EMF_MODAL_DETECT | EMF_MODAL),
  EMF_DETECT_MASK = (EMF_RIGID_DETECT | EMF_MODAL_DETECT), EMF_ERR = 0x10000000U
}
 

Detailed Description

Definition at line 102 of file modalext.h.

Constructor & Destructor Documentation

ExtModalForce::ExtModalForce ( void  )

Definition at line 53 of file modalext.cc.

References NO_OP.

54 {
55  NO_OP;
56 }
#define NO_OP
Definition: myassert.h:74
ExtModalForce::~ExtModalForce ( void  )
virtual

Definition at line 58 of file modalext.cc.

References NO_OP.

59 {
60  NO_OP;
61 }
#define NO_OP
Definition: myassert.h:74

Member Function Documentation

bool ExtModalForce::Prepare ( ExtFileHandlerBase pEFH,
unsigned  uLabel,
bool  bRigid,
unsigned  uModes 
)
virtual

Implements ExtModalForceBase.

Definition at line 64 of file modalext.cc.

References buf, ExtFileHandlerBase::GetInFileDes(), ExtFileHandlerBase::GetInStream(), ExtFileHandlerBase::GetOutFileDes(), ExtFileHandlerBase::GetOutStream(), ExtFileHandlerBase::GetRecvFlags(), ExtFileHandlerBase::GetSendFlags(), MBC_MODAL, MBC_MODAL_NODAL_MASK, MBC_REF_NODE, MBDYN_EXCEPT_ARGS, ExtFileHandlerBase::NEGOTIATE_CLIENT, ExtFileHandlerBase::NEGOTIATE_NO, ExtFileHandlerBase::NEGOTIATE_SERVER, and ExtFileHandlerBase::NegotiateRequest().

65 {
66  bool bResult = true;
67 
68  switch (pEFH->NegotiateRequest()) {
70  break;
71 
73  std::ostream *outfp = pEFH->GetOutStream();
74  if (outfp) {
75  *outfp << MBC_MODAL
76  << ' ' << bRigid
77  << ' ' << uModes
78  << std::endl;
79 
80 #ifdef USE_SOCKET
81  } else {
82  char buf[sizeof(uint32_t) + sizeof(uint32_t)];
83  uint32_t *uint32_ptr;
84 
85  uint32_ptr = (uint32_t *)&buf[0];
86  uint32_ptr[0] = MBC_MODAL;
87  if (bRigid) {
88  uint32_ptr[0] |= MBC_REF_NODE;
89  }
90 
91  uint32_ptr[1] = uModes;
92 
93  ssize_t rc = send(pEFH->GetOutFileDes(),
94  (const void *)buf, sizeof(buf),
95  pEFH->GetSendFlags());
96  if (rc == -1) {
97  int save_errno = errno;
98  char *err_msg = strerror(save_errno);
99  silent_cerr("ExtModalForce(" << uLabel << "): "
100  "negotiation request send() failed "
101  "(" << save_errno << ": " << err_msg << ")"
102  << std::endl);
104 
105  } else if (rc != sizeof(buf)) {
106  silent_cerr("ExtModalForce(" << uLabel << "): "
107  "negotiation request send() failed "
108  "(sent " << rc << " of " << sizeof(buf) << " bytes)"
109  << std::endl);
111  }
112 #endif // USE_SOCKET
113  }
114  } break;
115 
117  unsigned type;
118  bool bR;
119  unsigned uM;
120 
121  std::istream *infp = pEFH->GetInStream();
122  if (infp) {
123  *infp >> type >> bR >> uM;
124  if (type != MBC_MODAL) {
125  return false;
126  }
127 
128 #ifdef USE_SOCKET
129  } else {
130  char buf[sizeof(uint32_t) + sizeof(uint32_t)];
131  uint32_t *uint32_ptr;
132 
133  ssize_t rc = recv(pEFH->GetInFileDes(),
134  (void *)buf, sizeof(buf),
135  pEFH->GetRecvFlags());
136  if (rc == -1) {
137  int save_errno = errno;
138  char *err_msg = strerror(save_errno);
139  silent_cerr("ExtModalForce(" << uLabel << "): "
140  "negotiation response recv() failed "
141  "(" << save_errno << ": " << err_msg << ")"
142  << std::endl);
144 
145  } else if (rc != sizeof(buf)) {
146  silent_cerr("ExtModalForce(" << uLabel << "): "
147  "negotiation response recv() failed "
148  "(got " << rc << " of " << sizeof(buf) << " bytes)"
149  << std::endl);
151  }
152 
153  uint32_ptr = (uint32_t *)&buf[0];
154  type = (uint32_ptr[0] & MBC_MODAL_NODAL_MASK);
155  bR = (uint32_ptr[0] & MBC_REF_NODE);
156 
157  uM = uint32_ptr[1];
158 #endif // USE_SOCKET
159  }
160 
161  if (type != MBC_MODAL) {
162  silent_cerr("ExtModalForce(" << uLabel << "): "
163  "negotiation response failed: expecting MBC_MODAL "
164  "(=" << MBC_MODAL << "), got " << type
165  << std::endl);
166  bResult = false;
167  }
168 
169  if ((bRigid && !bR) || (!bRigid && bR)) {
170  silent_cerr("ExtModalForce(" << uLabel << "): "
171  "negotiation response failed: reference node configuration mismatch "
172  "(local=" << (bRigid ? "yes" : "no") << ", remote=" << (bR ? "yes" : "no") << ")"
173  << std::endl);
174  bResult = false;
175  }
176 
177  if (uM != uModes) {
178  silent_cerr("ExtModalForce(" << uLabel << "): "
179  "negotiation response failed: mode number mismatch "
180  "(local=" << uModes << ", remote=" << uM << ")"
181  << std::endl);
182  bResult = false;
183  }
184  } break;
185 
186  default:
188  }
189 
190  return bResult;
191 }
virtual std::istream * GetInStream(void)
Definition: extforce.cc:78
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual int GetInFileDes(void)
Definition: extforce.cc:99
virtual int GetOutFileDes(void)
Definition: extforce.cc:85
Definition: mbc.h:65
virtual Negotiate NegotiateRequest(void) const
Definition: extforce.cc:63
virtual int GetRecvFlags(void) const
Definition: extforce.cc:106
virtual std::ostream * GetOutStream(void)
Definition: extforce.cc:72
virtual int GetSendFlags(void) const
Definition: extforce.cc:92
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333

Here is the call graph for this function:

unsigned ExtModalForce::Recv ( ExtFileHandlerBase pEFH,
unsigned  uFlags,
unsigned &  uLabel,
Vec3 f,
Vec3 m,
std::vector< doublereal > &  fv 
)
virtual

Implements ExtModalForceBase.

Definition at line 194 of file modalext.cc.

References ExtFileHandlerBase::GetInFileDes(), ExtFileHandlerBase::GetInStream(), ExtFileHandlerBase::GetRecvFlags(), RecvFromFileDes(), and RecvFromStream().

196 {
197  std::istream *infp = pEFH->GetInStream();
198  if (infp) {
199  return RecvFromStream(*infp, uFlags, uLabel, f, m, fv);
200 
201  } else {
202  return RecvFromFileDes(pEFH->GetInFileDes(), pEFH->GetRecvFlags(),
203  uFlags, uLabel, f, m, fv);
204  }
205 }
virtual std::istream * GetInStream(void)
Definition: extforce.cc:78
virtual int GetInFileDes(void)
Definition: extforce.cc:99
virtual unsigned RecvFromStream(std::istream &inf, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
Definition: modalext.cc:224
virtual unsigned RecvFromFileDes(int infd, int recv_flags, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
Definition: modalext.cc:248
virtual int GetRecvFlags(void) const
Definition: extforce.cc:106

Here is the call graph for this function:

unsigned ExtModalForce::RecvFromFileDes ( int  infd,
int  recv_flags,
unsigned  uFlags,
unsigned &  uLabel,
Vec3 f,
Vec3 m,
std::vector< doublereal > &  fv 
)
protectedvirtual

Definition at line 248 of file modalext.cc.

References ExtModalForceBase::EMF_MODAL, ExtModalForceBase::EMF_RIGID, MBDYN_EXCEPT_ARGS, and Vec3::pGetVec().

Referenced by Recv().

251 {
252 #ifdef USE_SOCKET
253  ssize_t rc;
254  size_t size;
255 
256  if ((uFlags & ExtModalForceBase::EMF_RIGID)) {
257  size = 3*sizeof(doublereal);
258 
259  rc = recv(infd, (void *)f.pGetVec(), size, recv_flags);
260  if (rc != (ssize_t)size) {
261  // error
262  }
263  rc = recv(infd, (void *)m.pGetVec(), size, recv_flags);
264  if (rc != (ssize_t)size) {
265  // error
266  }
267  }
268 
269  if ((uFlags & ExtModalForceBase::EMF_MODAL)) {
270  size = fv.size()*sizeof(doublereal);
271  rc = recv(infd, (void *)&fv[0], size, recv_flags);
272  if (rc != (ssize_t)size) {
273  // error
274  }
275  }
276 
277  return uFlags;
278 #else // ! USE_SOCKET
280 #endif // ! USE_SOCKET
281 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const doublereal * pGetVec(void) const
Definition: matvec3.h:192
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

unsigned ExtModalForce::RecvFromStream ( std::istream &  inf,
unsigned  uFlags,
unsigned &  uLabel,
Vec3 f,
Vec3 m,
std::vector< doublereal > &  fv 
)
protectedvirtual

Definition at line 224 of file modalext.cc.

References ExtModalForceBase::EMF_MODAL, and ExtModalForceBase::EMF_RIGID.

Referenced by Recv().

226 {
227  if ((uFlags & ExtModalForceBase::EMF_RIGID)) {
228  doublereal df[3], dm[3];
229  inf
230  >> df[0] >> df[1] >> df[2]
231  >> dm[0] >> dm[1] >> dm[2];
232  f = Vec3(df);
233  m = Vec3(dm);
234  }
235 
236  if ((uFlags & ExtModalForceBase::EMF_MODAL)) {
237  for (std::vector<doublereal>::iterator i = fv.begin(); i != fv.end(); ++i) {
238  doublereal d;
239  inf >> d;
240  *i = d;
241  }
242  }
243 
244  return uFlags;
245 }
Definition: matvec3.h:98
double doublereal
Definition: colamd.c:52
void ExtModalForce::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 
)
virtual

Implements ExtModalForceBase.

Definition at line 208 of file modalext.cc.

References ExtFileHandlerBase::GetOutFileDes(), ExtFileHandlerBase::GetOutStream(), ExtFileHandlerBase::GetSendFlags(), R, SendToFileDes(), and SendToStream().

212 {
213  std::ostream *outfp = pEFH->GetOutStream();
214  if (outfp) {
215  return SendToStream(*outfp, uFlags, uLabel, x, R, v, w, q, qP);
216 
217  } else {
218  return SendToFileDes(pEFH->GetOutFileDes(), pEFH->GetSendFlags(),
219  uFlags, uLabel, x, R, v, w, q, qP);
220  }
221 }
virtual int GetOutFileDes(void)
Definition: extforce.cc:85
virtual void SendToFileDes(int outfd, int send_flags, 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: modalext.cc:305
virtual void SendToStream(std::ostream &outf, 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: modalext.cc:284
virtual std::ostream * GetOutStream(void)
Definition: extforce.cc:72
virtual int GetSendFlags(void) const
Definition: extforce.cc:92
Mat3x3 R

Here is the call graph for this function:

void ExtModalForce::SendToFileDes ( int  outfd,
int  send_flags,
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 
)
protectedvirtual

Definition at line 305 of file modalext.cc.

References ExtModalForceBase::EMF_MODAL, ExtModalForceBase::EMF_RIGID, MBDYN_EXCEPT_ARGS, Mat3x3::pGetMat(), and Vec3::pGetVec().

Referenced by Send().

310 {
311 #ifdef USE_SOCKET
312  if ((uFlags & ExtModalForceBase::EMF_RIGID)) {
313  send(outfd, (const void *)x.pGetVec(), 3*sizeof(doublereal), send_flags);
314  send(outfd, (const void *)R.pGetMat(), 9*sizeof(doublereal), send_flags);
315  send(outfd, (const void *)v.pGetVec(), 3*sizeof(doublereal), send_flags);
316  send(outfd, (const void *)w.pGetVec(), 3*sizeof(doublereal), send_flags);
317  }
318 
319  if ((uFlags & ExtModalForceBase::EMF_MODAL)) {
320  send(outfd, (const void *)&q[0], q.size()*sizeof(doublereal), send_flags);
321  send(outfd, (const void *)&qP[0], qP.size()*sizeof(doublereal), send_flags);
322  }
323 #else // ! USE_SOCKET
325 #endif // ! USE_SOCKET
326 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const doublereal * pGetMat(void) const
Definition: matvec3.h:743
const doublereal * pGetVec(void) const
Definition: matvec3.h:192
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void ExtModalForce::SendToStream ( std::ostream &  outf,
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 
)
protectedvirtual

Definition at line 284 of file modalext.cc.

References ExtModalForceBase::EMF_MODAL, and ExtModalForceBase::EMF_RIGID.

Referenced by Send().

288 {
289  if ((uFlags & ExtModalForceBase::EMF_RIGID)) {
290  outf
291  << x << std::endl
292  << R << std::endl
293  << v << std::endl
294  << w << std::endl;
295  }
296 
297  if ((uFlags & ExtModalForceBase::EMF_MODAL)) {
298  for (unsigned i = 0; i < q.size(); i++) {
299  outf << q[i] << " " << qP[i] << std::endl;
300  }
301  }
302 }

The documentation for this class was generated from the following files: