MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
strext.cc File Reference
#include "mbconfig.h"
#include "dataman.h"
#include "extedge.h"
#include "strext.h"
#include "stredge.h"
#include "Rot.hh"
#include <fstream>
#include <cerrno>
#include <algorithm>
Include dependency graph for strext.cc:

Go to the source code of this file.

Functions

ElemReadStructExtForce (DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
 

Function Documentation

Elem* ReadStructExtForce ( DataManager pDM,
MBDynParser HP,
unsigned int  uLabel 
)

Definition at line 1352 of file strext.cc.

References dRaDegr, Elem::FORCE, DataManager::fReadOutput(), IncludeParser::GetFileName(), HighParser::GetInt(), IncludeParser::GetLineData(), MBDynParser::GetPosRel(), HighParser::GetYesNo(), HighParser::IsArg(), IsExactlySame(), HighParser::IsKeyWord(), MatR2EulerAngles123(), MBC_ROT_EULER_123, MBC_ROT_MAT, MBC_ROT_NONE, MBC_ROT_THETA, MBDYN_EXCEPT_ARGS, ExtFileHandlerBase::OUTPUT_KIN, ExtFileHandlerBase::OUTPUT_REF_DYN, ReadExtForce(), DataManager::ReadNode(), SAFENEWWITHCONSTRUCTOR, ExtFileHandlerBase::SEND_FIRST_TIME, StructExtForce::SendToStream(), Node::STRUCTURAL, RotManip::VecRot(), and Zero3.

Referenced by ReadForce().

1355 {
1356  ExtFileHandlerBase *pEFH = 0;
1357  int iCoupling;
1358 
1359  bool bSendAfterPredict;
1360  ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
1361 
1362  const StructNode *pRefNode(0);
1363  if (HP.IsKeyWord("reference" "node")) {
1364  pRefNode = pDM->ReadNode<const StructNode, Node::STRUCTURAL>(HP);
1365  }
1366 
1367  bool bSorted(true);
1368  bool bLabels(false);
1369  unsigned uRot = MBC_ROT_MAT;
1370  bool bOutputAccelerations(false);
1371  bool bUseReferenceNodeForces(true);
1372  bool bRotateReferenceNodeForces(true);
1373 
1374  bool bGotSorted(false);
1375  bool bGotLabels(false);
1376  bool bGotRot(false);
1377  bool bGotAccels(false);
1378  bool bGotUseRefForces(false);
1379 
1380  while (HP.IsArg()) {
1381  if (HP.IsKeyWord("unsorted")) {
1382  silent_cerr("StructExtForce(" << uLabel << "): "
1383  "use of \"unsorted\" deprecated in favor of \"sorted, { yes | no }\" at line "
1384  << HP.GetLineData() << std::endl);
1385 
1386  if (bGotSorted) {
1387  silent_cerr("StructExtForce(" << uLabel << "): "
1388  "\"unsorted\" already specified at line "
1389  << HP.GetLineData() << std::endl);
1391  }
1392 
1393  bSorted = false;
1394  bGotSorted = true;
1395 
1396  } else if (HP.IsKeyWord("sorted")) {
1397  if (bGotSorted) {
1398  silent_cerr("StructExtForce(" << uLabel << "): "
1399  "\"sorted\" already specified at line "
1400  << HP.GetLineData() << std::endl);
1402  }
1403 
1404  if (!HP.GetYesNo(bSorted)) {
1405  silent_cerr("StructExtForce(" << uLabel << "): "
1406  "\"sorted\" must be either \"yes\" or \"no\" at line "
1407  << HP.GetLineData() << std::endl);
1409  }
1410  bGotSorted = true;
1411 
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 "
1415  << HP.GetLineData() << std::endl);
1416 
1417  if (bGotLabels) {
1418  silent_cerr("StructExtForce(" << uLabel << "): "
1419  "\"no labels\" already specified at line "
1420  << HP.GetLineData() << std::endl);
1422  }
1423 
1424  bLabels = false;
1425  bGotLabels = true;
1426 
1427  } else if (HP.IsKeyWord("labels")) {
1428  if (bGotLabels) {
1429  silent_cerr("StructExtForce(" << uLabel << "): "
1430  "\"labels\" already specified at line "
1431  << HP.GetLineData() << std::endl);
1433  }
1434 
1435  if (!HP.GetYesNo(bLabels)) {
1436  silent_cerr("StructExtForce(" << uLabel << "): "
1437  "\"labels\" must be either \"yes\" or \"no\" at line "
1438  << HP.GetLineData() << std::endl);
1440  }
1441  bGotLabels = true;
1442 
1443  } else if (HP.IsKeyWord("orientation")) {
1444  if (bGotRot) {
1445  silent_cerr("StructExtForce(" << uLabel << "): "
1446  "\"orientation\" already specified at line "
1447  << HP.GetLineData() << std::endl);
1449  }
1450 
1451  if (HP.IsKeyWord("none")) {
1452  uRot = MBC_ROT_NONE;
1453 
1454  } else if (HP.IsKeyWord("orientation" "vector")) {
1455  uRot = MBC_ROT_THETA;
1456 
1457  } else if (HP.IsKeyWord("orientation" "matrix")) {
1458  uRot = MBC_ROT_MAT;
1459 
1460  } else if (HP.IsKeyWord("euler" "123")) {
1461  uRot = MBC_ROT_EULER_123;
1462 
1463  } else {
1464  silent_cerr("StructExtForce(" << uLabel << "): "
1465  "unknown \"orientation\" format at line "
1466  << HP.GetLineData() << std::endl);
1468  }
1469 
1470  bGotRot = true;
1471 
1472  } else if (HP.IsKeyWord("accelerations")) {
1473  if (bGotAccels) {
1474  silent_cerr("StructExtForce(" << uLabel << "): "
1475  "\"accelerations\" already specified at line "
1476  << HP.GetLineData() << std::endl);
1478  }
1479 
1480  if (!HP.GetYesNo(bOutputAccelerations)) {
1481  silent_cerr("StructExtForce(" << uLabel << "): "
1482  "\"accelerations\" must be either \"yes\" or \"no\" at line "
1483  << HP.GetLineData() << std::endl);
1485  }
1486  bGotAccels = true;
1487 
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 "
1492  << HP.GetLineData() << std::endl);
1494  }
1495 
1496  if (bGotUseRefForces) {
1497  silent_cerr("StructExtForce(" << uLabel << "): "
1498  "\"use reference node forces\" already specified at line "
1499  << HP.GetLineData() << std::endl);
1501  }
1502 
1503  if (!HP.GetYesNo(bUseReferenceNodeForces)) {
1504  silent_cerr("StructExtForce(" << uLabel << "): "
1505  "\"use reference node forces\" must be either \"yes\" or \"no\" at line "
1506  << HP.GetLineData() << std::endl);
1508  }
1509  bGotUseRefForces = true;
1510 
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 "
1515  << HP.GetLineData() << std::endl);
1517  }
1518  }
1519 
1520  } else {
1521  break;
1522  }
1523  }
1524 
1525  if (!bLabels && !bSorted) {
1526  silent_cerr("StructExtForce(" << uLabel << "): "
1527  "\"no labels\" and \"unsorted\" incompatible" << std::endl);
1529  }
1530 
1531  int n = HP.GetInt();
1532  if (n <= 0) {
1533  silent_cerr("StructExtForce(" << uLabel << "): illegal node number " << n <<
1534  " at line " << HP.GetLineData() << std::endl);
1536  }
1537 
1538  std::vector<unsigned> Labels;
1539  std::vector<unsigned>::iterator curr_label;
1540  if (bLabels) {
1541  Labels.resize(n);
1542  curr_label = Labels.begin();
1543  }
1544  std::vector<const StructNode *> Nodes(n);
1545  std::vector<Vec3> Offsets(n);
1546 
1547  for (int i = 0; i < n; i++ ) {
1548  Nodes[i] = pDM->ReadNode<const StructNode, Node::STRUCTURAL>(HP);
1549 
1550  ReferenceFrame RF(Nodes[i]);
1551 
1552  if (bLabels) {
1553  unsigned ul;
1554  if (HP.IsKeyWord("label")) {
1555  int l = HP.GetInt();
1556  if (l < 0) {
1557  silent_cerr("StructExtForce(" << uLabel << "): "
1558  "invalid label for point #" << i << " at line "
1559  << HP.GetLineData() << std::endl);
1561  }
1562  ul = unsigned(l);
1563 
1564  } else {
1565  ul = Nodes[i]->GetLabel();
1566  }
1567 
1568  if (std::find(Labels.begin(), curr_label, ul) < curr_label) {
1569  silent_cerr("StructExtForce(" << uLabel << "): "
1570  "duplicate label for point #" << i << " at line "
1571  << HP.GetLineData() << std::endl);
1573  }
1574 
1575  *curr_label = ul;
1576  ++curr_label;
1577 
1578  }
1579 
1580  if (HP.IsKeyWord("offset")) {
1581  Offsets[i] = HP.GetPosRel(RF);
1582 
1583  } else {
1584  Offsets[i] = Vec3(Zero3);
1585  }
1586 
1587  for (int j = 0; j < i; j++) {
1588  if (Nodes[j] == Nodes[i]) {
1589  if (Offsets[j].IsExactlySame(Offsets[i])) {
1590  silent_cerr("StructExtForce(" << uLabel << "): "
1591  "warning, point #" << i << " is identical to point #" << j << " (same node, same offset)" << std::endl);
1592  } else {
1593  silent_cerr("StructExtForce(" << uLabel << "): "
1594  "warning, point #" << i << " is based on same node of point #" << j << " (offsets differ)" << std::endl);
1595  }
1596  }
1597  }
1598  }
1599 
1600  std::ofstream out;
1601  if (HP.IsKeyWord("echo")) {
1602  const char *s = HP.GetFileName();
1603  if (s == NULL) {
1604  silent_cerr("StructMappingExtForce(" << uLabel << "): "
1605  "unable to parse echo file name "
1606  "at line " << HP.GetLineData()
1607  << std::endl);
1609  }
1610 
1611  out.open(s);
1612  if (!out) {
1613  int save_errno = errno;
1614  silent_cerr("StructMappingExtForce(" << uLabel << "): "
1615  "unable to open file \"" << s << "\" (" << save_errno << ": " << strerror(save_errno) << ")" << std::endl);
1617  }
1618 #if 0
1619 
1620  std::ofstream out(s);
1621 
1622  out.setf(std::ios::scientific);
1623 
1624  for (unsigned i = 0; i < Nodes.size(); i++) {
1625  if (bLabels) {
1626  out << Labels[i];
1627  } else {
1628  out << Nodes[i]->GetLabel();
1629  }
1630 
1631  out << " " << (Nodes[i]->GetXCurr() + Offsets[i]) << " ";
1632  switch (uRot) {
1633  case MBC_ROT_MAT:
1634  out << Nodes[i]->GetRCurr();
1635  break;
1636 
1637  case MBC_ROT_THETA:
1638  out << RotManip::VecRot(Nodes[i]->GetRCurr());
1639  break;
1640 
1641  case MBC_ROT_NONE:
1642  case MBC_ROT_EULER_123:
1643  out << MatR2EulerAngles123(Nodes[i]->GetRCurr())*dRaDegr;
1644  break;
1645  }
1646  out << " " << Nodes[i]->GetVCurr() + Nodes[i]->GetWCurr().Cross(Offsets[i])
1647  << " " << Nodes[i]->GetWCurr()
1648  << std::endl;
1649  }
1650 #endif
1651  }
1652 
1653  unsigned uOutputFlags = ExtFileHandlerBase::OUTPUT_REF_DYN;
1654  flag fOut = pDM->fReadOutput(HP, Elem::FORCE);
1655  if (HP.IsArg()) {
1656  if (HP.IsKeyWord("kinematics")) {
1657  uOutputFlags |= ExtFileHandlerBase::OUTPUT_KIN;
1658  fOut = 1;
1659  } else {
1660  silent_cerr("StructMappingExtForce(" << uLabel << "): "
1661  "unexpected arg at line " << HP.GetLineData() << std::endl);
1663  }
1664  }
1665 
1666  StructExtForce *pEl = 0;
1667 
1668  if (dynamic_cast<ExtFileHandlerEDGE *>(pEFH)) {
1670  StructExtEDGEForce(uLabel, pDM, pRefNode,
1671  bUseReferenceNodeForces, bRotateReferenceNodeForces,
1672  Labels, Nodes, Offsets,
1673  bSorted, bLabels, bOutputAccelerations, uRot,
1674  pEFH, bSendAfterPredict, iCoupling, uOutputFlags, fOut));
1675 
1676  } else {
1678  StructExtForce(uLabel, pDM, pRefNode,
1679  bUseReferenceNodeForces, bRotateReferenceNodeForces,
1680  Labels, Nodes, Offsets,
1681  bSorted, bLabels, bOutputAccelerations, uRot,
1682  pEFH, bSendAfterPredict, iCoupling, uOutputFlags, fOut));
1683  }
1684 
1685  if (out.is_open()) {
1687  }
1688 
1689  return pEl;
1690 }
flag fReadOutput(MBDynParser &HP, const T &t) const
Definition: dataman.h:1064
const Vec3 Zero3(0., 0., 0.)
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
Definition: parsinc.cc:673
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
Vec3 GetPosRel(const ReferenceFrame &rf)
Definition: mbpar.cc:1331
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
Vec3 MatR2EulerAngles123(const Mat3x3 &R)
Definition: matvec3.cc:893
const doublereal dRaDegr
Definition: matvec3.cc:884
virtual void SendToStream(std::ostream &outf, ExtFileHandlerBase::SendWhen when)
Definition: strext.cc:442
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual bool GetYesNo(bool &bRet)
Definition: parser.cc:1022
virtual bool IsArg(void)
Definition: parser.cc:807
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
Node * ReadNode(MBDynParser &HP, Node::Type type) const
Definition: dataman3.cc:2309
void ReadExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, ExtFileHandlerBase *&pEFH, bool &bSendAfterPredict, int &iCoupling)
Definition: extforce.cc:1141
bool IsExactlySame(const doublereal &d1, const doublereal &d2)
Definition: matvec3.cc:1131

Here is the call graph for this function: