50 bool bUseReferenceNodeForces,
51 bool bRotateReferenceNodeForces,
52 std::vector<unsigned >&
labels,
53 std::vector<const StructNode *>&
nodes,
54 std::vector<Vec3>& offsets,
57 bool bOutputAccelerations,
60 bool bSendAfterPredict,
62 unsigned uOutputFlags,
65 ExtForce(uL, pDM, pEFH, bSendAfterPredict, iCoupling, fOut),
67 bUseReferenceNodeForces(bUseReferenceNodeForces),
68 bRotateReferenceNodeForces(bRotateReferenceNodeForces),
72 uOutputFlags(uOutputFlags),
76 bOutputAccelerations(bOutputAccelerations),
89 ASSERT(nodes.size() == offsets.size());
90 ASSERT((!bLabels) || (nodes.size() == offsets.size()));
102 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
103 "unknown rotation format " << uRot
108 for (
unsigned i = 0; i < nodes.size(); i++) {
120 ASSERT(!(!bLabels && !bSorted));
122 done.resize(nodes.size());
125 if (bOutputAccelerations) {
126 for (
unsigned i = 0; i <
m_Points.size(); i++) {
129 silent_cerr(
"StructExtForce"
131 "point #" << i <<
" StructNode(" <<
m_Points[i].pNode->GetLabel() <<
") "
141 unsigned node_kinematics_size = 0;
142 unsigned labels_size = 0;
146 node_kinematics_size = 3 + 3;
153 node_kinematics_size += 9 + 3;
158 node_kinematics_size += 3 + 3;
165 if (bOutputAccelerations) {
166 node_kinematics_size += 3;
168 node_kinematics_size += 3;
185 iobuf.resize(node_kinematics_size*
m_Points.size() + labels_size);
188 char *ptr = &
iobuf[0];
225 if (bOutputAccelerations) {
280 char buf[
sizeof(uint32_t) +
sizeof(uint32_t)];
281 uint32_t *uint32_ptr;
283 uint32_ptr = (uint32_t *)&buf[0];
300 (
const void *)buf,
sizeof(buf),
303 int save_errno = errno;
304 char *err_msg = strerror(save_errno);
305 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
306 "negotiation request send() failed "
307 "(" << save_errno <<
": " << err_msg <<
")"
311 }
else if (rc !=
sizeof(buf)) {
312 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
313 "negotiation request send() failed "
314 "(sent " << rc <<
" of " <<
sizeof(buf) <<
" bytes)"
336 char buf[
sizeof(uint32_t) +
sizeof(uint32_t)];
337 uint32_t *uint32_ptr;
340 (
void *)buf,
sizeof(buf),
343 int save_errno = errno;
344 char *err_msg = strerror(save_errno);
345 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
346 "negotiation response recv() failed "
347 "(" << save_errno <<
": " << err_msg <<
")"
351 }
else if (rc !=
sizeof(buf)) {
352 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
353 "negotiation response recv() failed "
354 "(got " << rc <<
" of " <<
sizeof(buf) <<
" bytes)"
359 uint32_ptr = (uint32_t *)&buf[0];
371 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
372 "negotiation response failed: expecting MBC_NODAL "
379 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
380 "negotiation response failed: reference node configuration mismatch "
381 "(local=" << (
pRefNode != 0 ?
"yes" :
"no") <<
", remote=" << (bRef ?
"yes" :
"no") <<
")"
387 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
388 "negotiation response failed: orientation output mismatch "
389 "(local=" <<
uRot <<
", remote=" << uR <<
")"
395 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
396 "negotiation response failed: labels output mismatch "
397 "(local=" << (
bLabels ?
"yes" :
"no") <<
", remote=" << (bL ?
"yes" :
"no") <<
")"
403 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
404 "negotiation response failed: acceleration output mismatch "
411 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
412 "negotiation response failed: node number mismatch "
413 "(local=" <<
m_Points.size() <<
", remote=" << uN <<
")"
452 outf <<
"# reference node" << std::endl;
502 outf <<
"# regular nodes" << std::endl;
504 for (std::vector<PointData>::const_iterator point =
m_Points.begin(); point !=
m_Points.end(); ++point) {
505 Vec3 f(point->pNode->GetRCurr()*point->Offset);
506 Vec3 x(point->pNode->GetXCurr() + f);
509 Vec3 v(point->pNode->GetVCurr() + point->pNode->GetWCurr().Cross(f));
511 const Vec3& w(point->pNode->GetWCurr());
517 << point->pNode->GetLabel()
545 <<
" " << RRef.
MulTV(Dv);
549 <<
" " << RRef.
MulTV(w - wRef);
553 const Vec3& xpp(point->pNode->GetXPPCurr());
554 const Vec3& wp(point->pNode->GetWPCurr());
557 <<
" " << RRef.
MulTV(xpp - xppRef - wpRef.
Cross(Dx)
562 <<
" " << RRef.
MulTV(wp - wpRef - wRef.
Cross(w));
569 outf <<
"# regular nodes" << std::endl;
571 for (std::vector<PointData>::const_iterator point =
m_Points.begin(); point !=
m_Points.end(); ++point) {
582 const Mat3x3&
R = point->pNode->GetRCurr();
583 Vec3 f = R*point->Offset;
584 Vec3 x = point->pNode->GetXCurr() + f;
585 const Vec3& w = point->pNode->GetWCurr();
587 Vec3 v = point->pNode->GetVCurr() + wCrossf;
591 << point->pNode->GetLabel()
626 const Vec3& wp = point->pNode->GetWPCurr();
659 send(outfd, (
void *)&l[0],
sizeof(l), 0);
692 for (
unsigned i = 0; i <
m_Points.size(); i++) {
755 for (
unsigned i = 0; i <
m_Points.size(); i++) {
815 #else // ! USE_SOCKET
817 #endif // ! USE_SOCKET
844 inf >> f[0] >> f[1] >> f[2];
846 inf >> m[0] >> m[1] >> m[2];
854 fill(
done.begin(),
done.end(),
false);
857 for (cnt = 0; inf; cnt++) {
863 >> f[0] >> f[1] >> f[2];
865 inf >> m[0] >> m[1] >> m[2];
872 for (i = 0; i <
m_Points.size(); i++) {
879 silent_cerr(
"StructExtForce"
881 "unknown label " << l
882 <<
" as " << cnt <<
"-th node"
888 silent_cerr(
"StructExtForce"
890 "label " << l <<
" already done"
904 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
905 "invalid number of nodes " << cnt
908 for (
unsigned i = 0; i <
m_Points.size(); i++) {
910 silent_cerr(
"StructExtForce"
913 <<
" not done" << std::endl);
922 for (
unsigned i = 0; i <
m_Points.size(); i++) {
934 silent_cerr(
"StructExtForce"
936 "invalid " << i <<
"-th label " << l
943 >> f[0] >> f[1] >> f[2];
945 inf >> m[0] >> m[1] >> m[2];
972 ulen = 2*
sizeof(uint32_t);
982 len = recv(infd, (
void *)buf, ulen, 0);
984 int save_errno = errno;
985 char *err_msg = strerror(save_errno);
986 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
987 "recv() failed (" << save_errno <<
": "
988 << err_msg <<
")" << std::endl);
991 }
else if (
unsigned(len) != ulen) {
992 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
993 "recv() failed (got " << len <<
" of "
994 << ulen <<
" bytes)" << std::endl);
999 uint32_t *uint32_ptr = (uint32_t *)buf;
1000 unsigned l = uint32_ptr[0];
1002 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
1003 "invalid reference node label "
1022 int save_errno = errno;
1023 char *err_msg = strerror(save_errno);
1024 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
1025 "recv() failed (" << save_errno <<
": "
1026 << err_msg <<
")" << std::endl);
1030 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
1031 "recv() failed " "(got " << len <<
" of "
1040 fill(
done.begin(),
done.end(),
false);
1043 for (cnt = 0; cnt <
m_Points.size(); cnt++) {
1047 std::vector<PointData>::const_iterator p;
1049 if (p->uLabel == l) {
1055 silent_cerr(
"StructExtForce"
1057 "unknown label " << l
1058 <<
" as " << cnt <<
"-th node"
1066 silent_cerr(
"StructExtForce"
1068 "label " << l <<
" already done"
1082 silent_cerr(
"StructExtForce(" <<
GetLabel() <<
"): "
1083 "invalid node number " << cnt
1086 for (
unsigned i = 0; i <
m_Points.size(); i++) {
1088 silent_cerr(
"StructExtForce"
1091 <<
" not done" << std::endl);
1100 for (
unsigned i = 0; i <
m_Points.size(); i++) {
1106 silent_cerr(
"StructExtForce"
1108 "invalid " << i <<
"-th label " << l
1120 #else // ! USE_SOCKET
1122 #endif // ! USE_SOCKET
1175 for (
unsigned i = 0; i <
m_Points.size(); i++) {
1179 for (
int r = 1; r <= iOffset; r++) {
1180 WorkVec.
PutRowIndex(i*iOffset + r, iFirstIndex + r);
1183 Vec3 f(RRef*point.
F);
1184 WorkVec.
Add(i*iOffset + 1, f);
1189 WorkVec.
Add(i*iOffset + 4, m);
1203 for (
int r = 1; r <= iOffset; r++) {
1204 WorkVec.
PutRowIndex(i*iOffset + r, iFirstIndex + r);
1210 WorkVec.
Add(i*iOffset + 1,
F1);
1212 WorkVec.
Add(i*iOffset + 4,
M1);
1219 for (
unsigned i = 0; i <
m_Points.size(); i++) {
1223 for (
int r = 1; r <= iOffset; r++) {
1224 WorkVec.
PutRowIndex(i*iOffset + r, iFirstIndex + r);
1227 WorkVec.
Add(i*iOffset + 1, point.
F);
1242 std::ostream& out = OH.
Forces();
1256 for (std::vector<PointData>::const_iterator point =
m_Points.begin(); point !=
m_Points.end(); ++point) {
1257 out <<
GetLabel() <<
"@" << point->uLabel
1273 for (std::vector<PointData>::const_iterator point =
m_Points.begin(); point !=
m_Points.end(); ++point) {
1274 Vec3 f(point->pNode->GetRCurr()*point->Offset);
1275 Vec3 x(point->pNode->GetXCurr() + f);
1278 Vec3 v(point->pNode->GetVCurr() + point->pNode->GetWCurr().Cross(f));
1280 const Vec3& w(point->pNode->GetWCurr());
1282 out <<
GetLabel() <<
"." << point->uLabel
1283 <<
" " << RRef.
MulTV(Dx);
1300 out <<
" " << RRef.
MulTV(Dv)
1301 <<
" " << RRef.
MulTV(w - wRef)
1306 for (std::vector<PointData>::const_iterator point =
m_Points.begin(); point !=
m_Points.end(); ++point) {
1307 const Mat3x3&
R = point->pNode->GetRCurr();
1308 Vec3 f = R*point->Offset;
1309 Vec3 x = point->pNode->GetXCurr() + f;
1310 const Vec3& w = point->pNode->GetWCurr();
1312 Vec3 v = point->pNode->GetVCurr() + wCrossf;
1314 out <<
GetLabel() <<
"." << point->uLabel
1345 connectedNodes.resize(
m_Points.size());
1346 for (
unsigned int i = 0; i <
m_Points.size(); i++) {
1347 connectedNodes[i] =
m_Points[i].pNode;
1354 unsigned int uLabel)
1359 bool bSendAfterPredict;
1360 ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
1368 bool bLabels(
false);
1370 bool bOutputAccelerations(
false);
1371 bool bUseReferenceNodeForces(
true);
1372 bool bRotateReferenceNodeForces(
true);
1374 bool bGotSorted(
false);
1375 bool bGotLabels(
false);
1376 bool bGotRot(
false);
1377 bool bGotAccels(
false);
1378 bool bGotUseRefForces(
false);
1380 while (HP.
IsArg()) {
1382 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1383 "use of \"unsorted\" deprecated in favor of \"sorted, { yes | no }\" at line "
1387 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1388 "\"unsorted\" already specified at line "
1398 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1399 "\"sorted\" already specified at line "
1405 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1406 "\"sorted\" must be either \"yes\" or \"no\" at line "
1412 }
else if (HP.
IsKeyWord(
"no" "labels")) {
1413 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1414 "use of \"no labels\" deprecated in favor of \"labels, { yes | no }\" at line "
1418 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1419 "\"no labels\" already specified at line "
1429 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1430 "\"labels\" already specified at line "
1436 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1437 "\"labels\" must be either \"yes\" or \"no\" at line "
1443 }
else if (HP.
IsKeyWord(
"orientation")) {
1445 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1446 "\"orientation\" already specified at line "
1454 }
else if (HP.
IsKeyWord(
"orientation" "vector")) {
1457 }
else if (HP.
IsKeyWord(
"orientation" "matrix")) {
1460 }
else if (HP.
IsKeyWord(
"euler" "123")) {
1464 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1465 "unknown \"orientation\" format at line "
1472 }
else if (HP.
IsKeyWord(
"accelerations")) {
1474 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1475 "\"accelerations\" already specified at line "
1480 if (!HP.
GetYesNo(bOutputAccelerations)) {
1481 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1482 "\"accelerations\" must be either \"yes\" or \"no\" at line "
1488 }
else if (HP.
IsKeyWord(
"use" "reference" "node" "forces")) {
1489 if (pRefNode == 0) {
1490 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1491 "\"use reference node forces\" only meaningful when reference node is used at line "
1496 if (bGotUseRefForces) {
1497 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1498 "\"use reference node forces\" already specified at line "
1503 if (!HP.
GetYesNo(bUseReferenceNodeForces)) {
1504 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1505 "\"use reference node forces\" must be either \"yes\" or \"no\" at line "
1509 bGotUseRefForces =
true;
1511 if (bUseReferenceNodeForces && HP.
IsKeyWord(
"rotate" "reference" "node" "forces")) {
1512 if (!HP.
GetYesNo(bRotateReferenceNodeForces)) {
1513 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1514 "\"rotate reference node forces\" must be either \"yes\" or \"no\" at line "
1525 if (!bLabels && !bSorted) {
1526 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1527 "\"no labels\" and \"unsorted\" incompatible" << std::endl);
1533 silent_cerr(
"StructExtForce(" << uLabel <<
"): illegal node number " << n <<
1538 std::vector<unsigned> Labels;
1539 std::vector<unsigned>::iterator curr_label;
1542 curr_label = Labels.begin();
1544 std::vector<const StructNode *> Nodes(n);
1545 std::vector<Vec3> Offsets(n);
1547 for (
int i = 0; i < n; i++ ) {
1557 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1558 "invalid label for point #" << i <<
" at line "
1565 ul = Nodes[i]->GetLabel();
1568 if (std::find(Labels.begin(), curr_label, ul) < curr_label) {
1569 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1570 "duplicate label for point #" << i <<
" at line "
1587 for (
int j = 0; j < i; j++) {
1588 if (Nodes[j] == Nodes[i]) {
1590 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1591 "warning, point #" << i <<
" is identical to point #" << j <<
" (same node, same offset)" << std::endl);
1593 silent_cerr(
"StructExtForce(" << uLabel <<
"): "
1594 "warning, point #" << i <<
" is based on same node of point #" << j <<
" (offsets differ)" << std::endl);
1604 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1605 "unable to parse echo file name "
1613 int save_errno = errno;
1614 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1615 "unable to open file \"" << s <<
"\" (" << save_errno <<
": " << strerror(save_errno) <<
")" << std::endl);
1620 std::ofstream out(s);
1622 out.setf(std::ios::scientific);
1624 for (
unsigned i = 0; i < Nodes.size(); i++) {
1628 out << Nodes[i]->GetLabel();
1631 out <<
" " << (Nodes[i]->GetXCurr() + Offsets[i]) <<
" ";
1634 out << Nodes[i]->GetRCurr();
1646 out <<
" " << Nodes[i]->GetVCurr() + Nodes[i]->GetWCurr().Cross(Offsets[i])
1647 <<
" " << Nodes[i]->GetWCurr()
1660 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1661 "unexpected arg at line " << HP.
GetLineData() << std::endl);
1668 if (dynamic_cast<ExtFileHandlerEDGE *>(pEFH)) {
1671 bUseReferenceNodeForces, bRotateReferenceNodeForces,
1672 Labels, Nodes, Offsets,
1673 bSorted, bLabels, bOutputAccelerations, uRot,
1674 pEFH, bSendAfterPredict, iCoupling, uOutputFlags, fOut));
1679 bUseReferenceNodeForces, bRotateReferenceNodeForces,
1680 Labels, Nodes, Offsets,
1681 bSorted, bLabels, bOutputAccelerations, uRot,
1682 pEFH, bSendAfterPredict, iCoupling, uOutputFlags, fOut));
1685 if (out.is_open()) {
flag fReadOutput(MBDynParser &HP, const T &t) const
virtual void SendToFileDes(int outfd, ExtFileHandlerBase::SendWhen when)
virtual std::istream * GetInStream(void)
const Vec3 Zero3(0., 0., 0.)
Vec3 Cross(const Vec3 &v) const
virtual bool bToBeOutput(void) const
#define MBDYN_EXCEPT_ARGS
virtual int GetInFileDes(void)
std::vector< char > iobuf
virtual int GetOutFileDes(void)
virtual void ResizeReset(integer)
virtual integer GetInt(integer iDefval=0)
doublereal * iobuf_euler_123
virtual const Mat3x3 & GetRCurr(void) const
virtual void GetConnectedNodes(std::vector< const Node * > &connectedNodes) const
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
StructExtForce(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)
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
void Send(ExtFileHandlerBase *pEFH, ExtFileHandlerBase::SendWhen when)
bool Prepare(ExtFileHandlerBase *pEFH)
Vec3 VecRot(const Mat3x3 &Phi)
virtual void Output(OutputHandler &OH) const
Vec3 MulTV(const Vec3 &v) const
virtual Negotiate NegotiateRequest(void) const
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
virtual ~StructExtForce(void)
Elem * ReadStructExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
bool bOutputAccelerations
Vec3 GetPosRel(const ReferenceFrame &rf)
virtual bool IsKeyWord(const char *sKeyWord)
std::vector< PointData > m_Points
virtual int GetRecvFlags(void) const
Vec3 MatR2EulerAngles123(const Mat3x3 &R)
bool bUseReferenceNodeForces
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)
Mat3x3 MulTM(const Mat3x3 &m) const
VectorExpression< VectorCrossExpr< VectorLhsExpr, VectorRhsExpr >, 3 > Cross(const VectorExpression< VectorLhsExpr, 3 > &u, const VectorExpression< VectorRhsExpr, 3 > &v)
virtual void SendToStream(std::ostream &outf, ExtFileHandlerBase::SendWhen when)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual const Vec3 & GetXCurr(void) const
virtual void Add(integer iRow, const Vec3 &v)
virtual void RecvFromStream(std::istream &inf)
const doublereal * pGetMat(void) const
virtual bool GetYesNo(bool &bRet)
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
doublereal * iobuf_omegap
const doublereal * pGetVec(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]
bool bRotateReferenceNodeForces
virtual HighParser::ErrOut GetLineData(void) const
unsigned int GetLabel(void) const
Node * ReadNode(MBDynParser &HP, Node::Type type) const
const StructNode * pRefNode
void ReadExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, ExtFileHandlerBase *&pEFH, bool &bSendAfterPredict, int &iCoupling)
virtual void Resize(integer iNewSize)=0
std::ostream & Forces(void) const
bool UseText(int out) const
virtual void RecvFromFileDes(int infd)
bool IsExactlySame(const doublereal &d1, const doublereal &d2)