82 char buf[
sizeof(uint32_t) +
sizeof(uint32_t)];
85 uint32_ptr = (uint32_t *)&buf[0];
91 uint32_ptr[1] = uModes;
94 (
const void *)buf,
sizeof(buf),
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 <<
")"
105 }
else if (rc !=
sizeof(buf)) {
106 silent_cerr(
"ExtModalForce(" << uLabel <<
"): "
107 "negotiation request send() failed "
108 "(sent " << rc <<
" of " <<
sizeof(buf) <<
" bytes)"
123 *infp >> type >> bR >> uM;
130 char buf[
sizeof(uint32_t) +
sizeof(uint32_t)];
131 uint32_t *uint32_ptr;
134 (
void *)buf,
sizeof(buf),
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 <<
")"
145 }
else if (rc !=
sizeof(buf)) {
146 silent_cerr(
"ExtModalForce(" << uLabel <<
"): "
147 "negotiation response recv() failed "
148 "(got " << rc <<
" of " <<
sizeof(buf) <<
" bytes)"
153 uint32_ptr = (uint32_t *)&buf[0];
162 silent_cerr(
"ExtModalForce(" << uLabel <<
"): "
163 "negotiation response failed: expecting MBC_MODAL "
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") <<
")"
178 silent_cerr(
"ExtModalForce(" << uLabel <<
"): "
179 "negotiation response failed: mode number mismatch "
180 "(local=" << uModes <<
", remote=" << uM <<
")"
195 Vec3& f,
Vec3& m, std::vector<doublereal>& fv)
203 uFlags, uLabel, f, m, fv);
210 const std::vector<doublereal>& q,
211 const std::vector<doublereal>& qP)
215 return SendToStream(*outfp, uFlags, uLabel, x, R, v, w, q, qP);
219 uFlags, uLabel, x,
R, v, w, q, qP);
225 Vec3& f,
Vec3& m, std::vector<doublereal>& fv)
230 >> df[0] >> df[1] >> df[2]
231 >> dm[0] >> dm[1] >> dm[2];
237 for (std::vector<doublereal>::iterator i = fv.begin(); i != fv.end(); ++i) {
249 unsigned uFlags,
unsigned& uLabel,
250 Vec3& f,
Vec3& m, std::vector<doublereal>& fv)
259 rc = recv(infd, (
void *)f.
pGetVec(), size, recv_flags);
260 if (rc != (ssize_t)size) {
263 rc = recv(infd, (
void *)m.
pGetVec(), size, recv_flags);
264 if (rc != (ssize_t)size) {
271 rc = recv(infd, (
void *)&fv[0], size, recv_flags);
272 if (rc != (ssize_t)size) {
278 #else // ! USE_SOCKET
280 #endif // ! USE_SOCKET
286 const std::vector<doublereal>& q,
287 const std::vector<doublereal>& qP)
298 for (
unsigned i = 0; i < q.size(); i++) {
299 outf << q[i] <<
" " << qP[i] << std::endl;
306 unsigned uFlags,
unsigned uLabel,
308 const std::vector<doublereal>& q,
309 const std::vector<doublereal>& qP)
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);
323 #else // ! USE_SOCKET
325 #endif // ! USE_SOCKET
337 bool bOutputAccelerations,
340 bool bSendAfterPredict,
345 ExtForce(uL, pDM, pEFH, bSendAfterPredict, iCoupling, fOut),
348 bOutputAccelerations(bOutputAccelerations),
358 ASSERT((bm & ~ExtModalForceBase::EMF_ALL) == 0);
425 for (
unsigned i = 0; i <
q.size(); i++) {
434 if (
uFlags & ExtModalForceBase::EMF_RIGID) {
451 if (
uFlags & ExtModalForceBase::EMF_MODAL) {
456 outf <<
a(i) <<
" " << b(i);
458 outf <<
" " << bP(i);
473 silent_cerr(
"ModalExt(" <<
GetLabel() <<
"): "
474 "error while reading modal force data" << std::endl);
478 if (
uFlags != uOutFlags) {
479 silent_cerr(
"ModalExt(" <<
GetLabel() <<
"): "
480 "error while reading modal force data "
481 "(" << uOutFlags <<
"!=" <<
uFlags <<
")"
527 for (
integer iCnt = 1; iCnt <= 6; iCnt++) {
542 WorkVec.
PutItem(iIdx + iMode, iModalIndex + iMode,
f[iMode]);
554 std::ostream& out = OH.
Forces();
558 <<
" " <<
F <<
" " <<
M
565 for (std::vector<doublereal>::const_iterator i =
f.begin(); i !=
f.end(); ++i) {
567 <<
" " << *i << std::endl;
581 connectedNodes.resize(1);
582 connectedNodes[0] =
pNode;
584 connectedNodes.resize(0);
596 bool bSendAfterPredict;
597 ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
600 const Modal *pModal = 0;
609 bool bOutputAccelerations(
false);
611 bOutputAccelerations =
true;
619 }
else if (pModal == 0) {
631 silent_cerr(
"ModalExt(" << uLabel <<
"): unknown ModalExt type "
638 silent_cerr(
"ModalExt(" << uLabel <<
"): \"rigid\" needs rigid body motion "
644 silent_cerr(
"ModalExt(" << uLabel <<
"): \"modal\" needs modal joint "
650 if (dynamic_cast<ExtFileHandlerEDGE *>(pEFH) != 0) {
655 case ExtModalForceBase::EMF_RIGID:
660 case ExtModalForceBase::EMF_MODAL:
665 case ExtModalForceBase::EMF_ALL:
666 silent_cerr(
"ModalExt(" << uLabel <<
"): "
667 "EDGE ExtFileHandler can only be used "
668 "when ModalExt is either \"rigid\" "
669 "or \"modal\" but not when it is \"all\" "
691 silent_cerr(
"ModalExt(" << uLabel <<
"): "
692 "semicolon expected at line "
699 ModalExt(uLabel, pDM, pModal, pNode, bOutputAccelerations,
700 pEFH, pEMF, bSendAfterPredict, iCoupling, bm, fOut));
flag fReadOutput(MBDynParser &HP, const T &t) const
std::vector< doublereal > f
const ModalNode * pGetModalNode(void) const
ModalExt(unsigned int uL, DataManager *pDM, const Modal *pmodal, const StructNode *pnode, bool bOutputAccelerations, ExtFileHandlerBase *pEFH, ExtModalForceBase *pEMF, bool bSendAfterPredict, int iCoupling, ExtModalForceBase::BitMask bm, flag fOut)
virtual ~ExtModalForce(void)
virtual std::istream * GetInStream(void)
const Vec3 Zero3(0., 0., 0.)
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)
virtual bool bToBeOutput(void) const
const VecN & GetA(void) const
#define MBDYN_EXCEPT_ARGS
virtual int GetInFileDes(void)
virtual int GetOutFileDes(void)
virtual void ResizeReset(integer)
virtual const Mat3x3 & GetRCurr(void) const
Elem * ReadElem(MBDynParser &HP, Elem::Type type) const
integer uGetNModes(void) const
virtual ~ExtModalForceBase(void)
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)
Elem * ReadModalExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.)
virtual bool Prepare(ExtFileHandlerBase *pEFH, unsigned uLabel, bool bRigid, unsigned uModes)=0
bool Prepare(ExtFileHandlerBase *pEFH)
virtual void Output(OutputHandler &OH) const
virtual void GetConnectedNodes(std::vector< const Node * > &connectedNodes) const
virtual void PutItem(integer iSubRow, integer iRow, const doublereal &dCoef)
std::vector< doublereal > qP
virtual Negotiate NegotiateRequest(void) const
virtual bool Prepare(ExtFileHandlerBase *pEFH, unsigned uLabel, bool bRigid, unsigned uModes)
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
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)
const VecN & GetB(void) const
#define SAFENEW(pnt, item)
virtual bool IsKeyWord(const char *sKeyWord)
virtual int GetRecvFlags(void) const
virtual unsigned Recv(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)
virtual integer iGetFirstMomentumIndex(void) const =0
virtual const Vec3 & GetWCurr(void) const
virtual const Vec3 & GetWPCurr(void) const
#define ASSERT(expression)
virtual std::ostream * GetOutStream(void)
virtual unsigned Recv(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)=0
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual const Vec3 & GetXCurr(void) const
bool bOutputAccelerations
void Send(ExtFileHandlerBase *pEFH, ExtFileHandlerBase::SendWhen when)
Mat3x3 Transpose(void) const
const doublereal * pGetMat(void) const
integer iGetModalIndex(void) const
virtual void Put(integer iRow, const Vec3 &v)
const doublereal * pGetVec(void) const
virtual Force::Type GetForceType(void) const
virtual const Vec3 & GetVCurr(void) const
static const doublereal a
virtual int GetSendFlags(void) const
virtual const Vec3 & GetXPPCurr(void) const
static doublereal buf[BUFSIZE]
virtual HighParser::ErrOut GetLineData(void) const
const VecN & GetBP(void) const
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
unsigned int GetLabel(void) const
const std::vector< unsigned int > & GetModeList(void) const
Node * ReadNode(MBDynParser &HP, Node::Type type) const
std::vector< doublereal > q
void ReadExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, ExtFileHandlerBase *&pEFH, bool &bSendAfterPredict, int &iCoupling)
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)=0
virtual void Resize(integer iNewSize)=0
std::ostream & Forces(void) const
bool UseText(int out) const