MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
modalmappingext.h File Reference
#include <vector>
#include <string>
#include "modalext.h"
#include "spmapmh.h"
#include "stlvh.h"
Include dependency graph for modalmappingext.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ModalMappingExt
 
struct  ModalMappingExt::NodeData
 

Functions

SpMapMatrixHandlerReadSparseMappingMatrix (MBDynParser &HP, integer &nRows, integer &nCols)
 
ElemReadModalMappingExtForce (DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
 

Function Documentation

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

Definition at line 584 of file modalmappingext.cc.

References ASSERT, ExtModalForceBase::EMF_ALL, ExtModalForceBase::EMF_MODAL, ExtModalForceBase::EMF_RIGID, Elem::FORCE, DataManager::fReadOutput(), HighParser::GetInt(), IncludeParser::GetLineData(), HighParser::GetYesNo(), HighParser::IsArg(), HighParser::IsKeyWord(), MBDYN_EXCEPT_ARGS, ReadExtForce(), DataManager::ReadNode(), ReadSparseMappingMatrix(), SAFEDELETE, SAFENEW, SAFENEWWITHCONSTRUCTOR, and Node::STRUCTURAL.

Referenced by ReadForce().

587 {
588  ExtFileHandlerBase *pEFH = 0;
589  int iCoupling = -1;
590  bool bSendAfterPredict = false;
591  ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
592 
593  const StructNode *pRefNode = 0;
594  if (HP.IsKeyWord("reference" "node")) {
595  pRefNode = pDM->ReadNode<const StructNode, Node::STRUCTURAL>(HP);
596  }
597 
598  bool bUseReferenceNodeForces(pRefNode != 0 ? true : false);
599  bool bRotateReferenceNodeForces(true);
600  if (pRefNode != 0 && HP.IsKeyWord("use" "rigid" "body" "forces")) {
601  if (!HP.GetYesNo(bUseReferenceNodeForces)) {
602  silent_cerr("ModalMappingExt(" << uLabel << "): "
603  "\"use rigid body forces\" must be either \"yes\" or \"no\" "
604  "at line " << HP.GetLineData() << std::endl);
606  }
607 
608  if (bUseReferenceNodeForces && HP.IsKeyWord("rotate" "rigid" "body" "forces")) {
609  if (!HP.GetYesNo(bRotateReferenceNodeForces)) {
610  silent_cerr("ModalMappingExt(" << uLabel << "): "
611  "\"rotate rigid body forces\" must be either \"yes\" or \"no\" "
612  "at line " << HP.GetLineData() << std::endl);
614  }
615  }
616  }
617 
618  bool bOutputAccelerations(false);
619  if (HP.IsKeyWord("accelerations")) {
620  bOutputAccelerations = true;
621  }
622 
623  // safe default: both rigid and modal
625  if (HP.IsKeyWord("type")) {
626  if (HP.IsKeyWord("rigid")) {
628  } else if (HP.IsKeyWord("modal")) {
630  } else if (HP.IsKeyWord("all")) {
632  } else {
633  silent_cerr("ModalMappingExt(" << uLabel << "): unknown ModalMappingExt type "
634  " at line " << HP.GetLineData() << std::endl);
636  }
637  }
638 
639  ExtModalForceBase *pEMF = 0;
640  if (dynamic_cast<ExtFileHandlerEDGE *>(pEFH) != 0) {
641  // EDGE needs two separate ModalMappingExt elements,
642  // one for the rigid part and one for the modal part
643 
644  switch (bm & ExtModalForceBase::EMF_ALL) {
647  ExtRigidForceEDGE(pDM));
648  break;
649 
652  ExtModalForceEDGE(pDM));
653  break;
654 
655  case ExtModalForceBase::EMF_ALL:
656  silent_cerr("ModalMappingExt(" << uLabel << "): "
657  "EDGE ExtFileHandler can only be used "
658  "when ModalMappingExt is either \"rigid\" "
659  "or \"modal\" but not when it is \"all\" "
660  " at line " << HP.GetLineData() << std::endl);
662 
663  default:
664  ASSERT(0);
666  }
667 
668 #ifdef USE_SOCKET
669  } else if (dynamic_cast<ExtSocketHandler *>(pEFH) != 0) {
670  SAFENEW(pEMF, ExtModalForce);
671 #endif // USE_SOCKET
672 
673  // add more types
674 
675  } else {
676  silent_cerr("ModalMappingExt(" << uLabel << "): "
677  "unknown external force type" << std::endl);
679  }
680 
681  if (!HP.IsKeyWord("nodes" "number")) {
682  silent_cerr("ModalMappingExt(" << uLabel << "): "
683  "\"nodes number\" keyword expected "
684  "at line " << HP.GetLineData() << std::endl);
686  }
687  int nNodes = HP.GetInt();
688  if (nNodes <= 0) {
689  silent_cerr("ModalMappingExt(" << uLabel << "): "
690  "invalid nodes number "
691  "at line " << HP.GetLineData() << std::endl);
693  }
694  std::vector<const StructNode *> n(nNodes);
695  for (int i = 0; i < nNodes; i++) {
696  n[i] = pDM->ReadNode<const StructNode, Node::STRUCTURAL>(HP);
697  }
698 
699  if (!HP.IsKeyWord("modes" "number")) {
700  silent_cerr("ModalMappingExt(" << uLabel << "): "
701  "\"modes number\" keyword expected "
702  "at line " << HP.GetLineData() << std::endl);
704  }
705  int nModes = -1;
706  if (!HP.IsKeyWord("from" "file")) {
707  nModes = HP.GetInt();
708  if (nModes <= 0) {
709  silent_cerr("ModalMappingExt(" << uLabel << "): "
710  "invalid modes number "
711  "at line " << HP.GetLineData() << std::endl);
713  }
714  }
715 
716  integer nCols = 6*nNodes;
717  SpMapMatrixHandler *pH = ReadSparseMappingMatrix(HP, nModes, nCols);
718  ASSERT(nCols == 6*nNodes);
719 
720  flag fOut = pDM->fReadOutput(HP, Elem::FORCE);
721 
722  if (HP.IsArg()) {
723  silent_cerr("ModalMappingExt(" << uLabel << "): "
724  "semicolon expected at line "
725  << HP.GetLineData() << std::endl);
726  SAFEDELETE(pH);
728  }
729 
730  Elem *pEl = 0;
732  ModalMappingExt(uLabel, pDM, pRefNode, n, pH,
733  bOutputAccelerations,
734  pEFH, pEMF, bSendAfterPredict, iCoupling, bm,
735  bUseReferenceNodeForces, bRotateReferenceNodeForces, fOut));
736 
737  return pEl;
738 }
flag fReadOutput(MBDynParser &HP, const T &t) const
Definition: dataman.h:1064
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define ASSERT(expression)
Definition: colamd.c:977
#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
Definition: elem.h:75
long int integer
Definition: colamd.c:51
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
SpMapMatrixHandler * ReadSparseMappingMatrix(MBDynParser &HP, integer &nRows, integer &nCols)
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710

Here is the call graph for this function:

SpMapMatrixHandler* ReadSparseMappingMatrix ( MBDynParser HP,
integer nRows,
integer nCols 
)

Definition at line 402 of file modalmappingext.cc.

References c, IncludeParser::GetFileName(), IncludeParser::GetLineData(), HighParser::GetReal(), HighParser::IsKeyWord(), MBDYN_EXCEPT_ARGS, and SAFENEWWITHCONSTRUCTOR.

Referenced by ReadModalMappingExtForce(), and ReadStructMappingExtForce().

403 {
404  bool bSparse;
405  if (HP.IsKeyWord("full" "mapping" "file")) {
406  bSparse = false;
407 
408  } else if (HP.IsKeyWord("sparse" "mapping" "file")) {
409  bSparse = true;
410 
411  } else {
412  silent_cerr("mapping file expected "
413  "at line " << HP.GetLineData() << std::endl);
415  }
416 
417  doublereal dThreshold = 0.;
418  if (HP.IsKeyWord("threshold")) {
419  dThreshold = HP.GetReal();
420  if (dThreshold < 0.) {
421  silent_cerr("invalid threshold " << dThreshold
422  << " at line " << HP.GetLineData() << std::endl);
424  }
425  }
426 
427  const char *sFileName = HP.GetFileName();
428  if (sFileName == 0) {
429  silent_cerr("unable to read mapping file name "
430  "at line " << HP.GetLineData() << std::endl);
432  }
433 
434  std::ifstream in(sFileName);
435  if (!in) {
436  silent_cerr("unable to open mapping file "
437  "\"" << sFileName << "\" "
438  "at line " << HP.GetLineData() << std::endl);
440  }
441 
442  char c = in.get();
443  while (c == '#') {
444  do {
445  c = in.get();
446  } while (c != '\n');
447  c = in.get();
448  }
449  in.putback(c);
450 
451  bool bComputeRows(nRows < 0);
452  bool bComputeCols(nCols < 0);
453 
454  if (bComputeRows || bComputeCols) {
455  std::streampos pos = in.tellg();
456  integer nVals;
457 
458  if (bSparse) {
459  for (nVals = 0; !in.eof(); nVals++) {
460  integer ir, ic;
461  doublereal d;
462  in >> ir >> ic >> d;
463 
464  if (bComputeRows) {
465  if (ir > nRows) {
466  nRows = ir;
467  }
468 
469  } else {
470  if (ir > nRows) {
471  silent_cerr("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
472  "inconsistent row=" << ir << " for coefficient #" << nVals << std::endl);
474  }
475  }
476 
477  if (bComputeCols) {
478  if (ic > nCols) {
479  nCols = ic;
480  }
481 
482  } else {
483  if (ic > nCols) {
484  silent_cerr("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
485  "inconsistent col=" << ic << " for coefficient #" << nVals << std::endl);
487  }
488  }
489  }
490  nVals--;
491 
492  } else {
493  if (bComputeRows && bComputeCols) {
494  silent_cerr("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
495  "cannot compute both row and col numbers" << std::endl);
497  }
498 
499  for (nVals = 0; !in.eof(); nVals++) {
500  doublereal d;
501 
502  in >> d;
503  }
504  nVals--;
505 
506  if (bComputeRows) {
507  if ((nVals % nCols) != 0) {
508  silent_cerr("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
509  "vals=" << nVals << " is not a multiple of cols=" << nCols << std::endl);
511  }
512 
513  nRows = nVals/nCols;
514 
515  } else if (bComputeCols) {
516  if ((nVals % nRows) != 0) {
517  silent_cerr("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
518  "vals=" << nVals << " is not a multiple of rows=" << nRows << std::endl);
520  }
521 
522  nCols = nVals/nRows;
523  }
524  }
525 
526  in.clear();
527  in.seekg(pos);
528 
529  silent_cout("ReadSparseMappingMatrix(\"" << sFileName << "\"): "
530  "rows=" << nRows
531  << " cols=" << nCols
532  << " vals=" << nVals
533  << std::endl);
534  }
535 
536  SpMapMatrixHandler *pH = 0;
538  SpMapMatrixHandler(nRows, nCols));
539 
540  if (bSparse) {
541  integer ir, ic, cnt = 0, nzcnt = 0;
542  doublereal d;
543  while (in >> ir >> ic >> d) {
544  if (ir <= 0 || ir > nRows || ic <= 0 || ic > nCols) {
545  silent_cerr("invalid row(=" << ir << ")/col(=" << ic <<") number for coefficient #" << cnt << " "
546  "from file \"" << sFileName << "\"" << std::endl);
548  }
549 
550  if (std::abs(d) > dThreshold) {
551  (*pH)(ir, ic) = d;
552  nzcnt++;
553  }
554 
555  cnt++;
556  }
557 
558  pedantic_cout("got " << cnt << " nonzeros (" << nzcnt << " actually stored) from file \"" << sFileName << "\"" << std::endl);
559 
560  } else {
561  int nzcnt = 0;
562  for (integer ir = 1; ir <= nRows; ir++) {
563  for (integer ic = 1; ic <= nCols; ic++) {
564  doublereal d;
565  in >> d;
566  if (!in) {
567  silent_cerr("unable to read coefficient(" << ir << ", " << ic << ") "
568  "from file \"" << sFileName << "\"" << std::endl);
570  }
571  if (std::abs(d) > dThreshold) {
572  (*pH)(ir, ic) = d;
573  nzcnt++;
574  }
575  }
576  }
577  pedantic_cout("got " << nzcnt << " nonzeros from file \"" << sFileName << "\"" << std::endl);
578  }
579 
580  return pH;
581 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
Definition: parsinc.cc:673
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
static std::stack< cleanup * > c
Definition: cleanup.cc:59
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056

Here is the call graph for this function: