45 std::vector<const StructNode *>& n,
47 bool bOutputAccelerations,
50 bool bSendAfterPredict,
53 bool bUseReferenceNodeForces,
54 bool bRotateReferenceNodeForces,
57 ExtForce(uL, pDM, pEFH, bSendAfterPredict, iCoupling, fOut),
60 bOutputAccelerations(bOutputAccelerations),
61 bUseReferenceNodeForces(bUseReferenceNodeForces),
62 bRotateReferenceNodeForces(bRotateReferenceNodeForces),
74 ASSERT((bm & ~ExtModalForceBase::EMF_ALL) == 0);
80 fill(
f.begin(),
f.end(), 0.);
82 fill(
p.begin(),
p.end(), 0.);
85 fill(
x.begin(),
x.end(), 0.);
86 xP.resize(6*n.size());
87 fill(
xP.begin(),
xP.end(), 0.);
89 fill(
q.begin(),
q.end(), 0.);
91 fill(
qP.begin(),
qP.end(), 0.);
110 Nodes.resize(n.size());
111 for (
unsigned i = 0; i < n.size(); i++) {
112 Nodes[i].pNode = n[i];
173 for (
unsigned i = 0; i <
Nodes.size(); i++) {
174 Vec3 XRel =
Nodes[i].pNode->GetXCurr() - X;
184 for (
unsigned i = 0; i <
Nodes.size(); i++) {
206 silent_cerr(
"ModalMappingExt(" <<
GetLabel() <<
"): "
207 "error while reading modal force data" << std::endl);
211 if (
uFlags != uOutFlags) {
212 silent_cerr(
"ModalMappingExt(" <<
GetLabel() <<
"): "
213 "error while reading modal force data "
214 "(" << uOutFlags <<
"!=" <<
uFlags <<
")"
239 for (
unsigned i = 0; i <
Nodes.size(); i++) {
241 Nodes[i].M = RRef*Vec3(&
f[6*i + 3]);
255 for (
unsigned i = 0; i <
Nodes.size(); i++) {
302 for (
integer iCnt = 1; iCnt <= 6; iCnt++) {
315 for (
unsigned i = 0; i <
Nodes.size(); i++) {
316 integer iIndex =
Nodes[i].pNode->iGetFirstMomentumIndex();
317 for (
integer iCnt = 1; iCnt <= 6; iCnt++) {
336 std::ostream& out = OH.
Forces();
340 <<
" " <<
F0 <<
" " <<
M0
341 <<
" " <<
F1 <<
" " <<
M1
342 <<
" " <<
F2 <<
" " <<
M2
347 for (
unsigned i = 0; i <
p.size(); i++) {
355 for (
unsigned i = 0; i <
Nodes.size(); i++) {
356 const double *px = &
x[6*i];
357 const double *pxP = &
xP[6*i];
390 connectedNodes.resize(iOff +
Nodes.size());
396 for (
unsigned i = 0; i <
Nodes.size(); i++) {
397 connectedNodes[iOff + i] =
Nodes[i].pNode;
405 if (HP.
IsKeyWord(
"full" "mapping" "file")) {
408 }
else if (HP.
IsKeyWord(
"sparse" "mapping" "file")) {
412 silent_cerr(
"mapping file expected "
420 if (dThreshold < 0.) {
421 silent_cerr(
"invalid threshold " << dThreshold
428 if (sFileName == 0) {
429 silent_cerr(
"unable to read mapping file name "
434 std::ifstream in(sFileName);
436 silent_cerr(
"unable to open mapping file "
437 "\"" << sFileName <<
"\" "
451 bool bComputeRows(nRows < 0);
452 bool bComputeCols(nCols < 0);
454 if (bComputeRows || bComputeCols) {
455 std::streampos pos = in.tellg();
459 for (nVals = 0; !in.eof(); nVals++) {
471 silent_cerr(
"ReadSparseMappingMatrix(\"" << sFileName <<
"\"): "
472 "inconsistent row=" << ir <<
" for coefficient #" << nVals << std::endl);
484 silent_cerr(
"ReadSparseMappingMatrix(\"" << sFileName <<
"\"): "
485 "inconsistent col=" << ic <<
" for coefficient #" << nVals << std::endl);
493 if (bComputeRows && bComputeCols) {
494 silent_cerr(
"ReadSparseMappingMatrix(\"" << sFileName <<
"\"): "
495 "cannot compute both row and col numbers" << std::endl);
499 for (nVals = 0; !in.eof(); nVals++) {
507 if ((nVals % nCols) != 0) {
508 silent_cerr(
"ReadSparseMappingMatrix(\"" << sFileName <<
"\"): "
509 "vals=" << nVals <<
" is not a multiple of cols=" << nCols << std::endl);
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);
529 silent_cout(
"ReadSparseMappingMatrix(\"" << sFileName <<
"\"): "
541 integer ir, ic, cnt = 0, nzcnt = 0;
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);
550 if (std::abs(d) > dThreshold) {
558 pedantic_cout(
"got " << cnt <<
" nonzeros (" << nzcnt <<
" actually stored) from file \"" << sFileName <<
"\"" << std::endl);
562 for (
integer ir = 1; ir <= nRows; ir++) {
563 for (
integer ic = 1; ic <= nCols; ic++) {
567 silent_cerr(
"unable to read coefficient(" << ir <<
", " << ic <<
") "
568 "from file \"" << sFileName <<
"\"" << std::endl);
571 if (std::abs(d) > dThreshold) {
577 pedantic_cout(
"got " << nzcnt <<
" nonzeros from file \"" << sFileName <<
"\"" << std::endl);
590 bool bSendAfterPredict =
false;
591 ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
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\" "
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\" "
618 bool bOutputAccelerations(
false);
620 bOutputAccelerations =
true;
633 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): unknown ModalMappingExt type "
640 if (dynamic_cast<ExtFileHandlerEDGE *>(pEFH) != 0) {
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\" "
669 }
else if (dynamic_cast<ExtSocketHandler *>(pEFH) != 0) {
676 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
677 "unknown external force type" << std::endl);
682 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
683 "\"nodes number\" keyword expected "
689 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
690 "invalid nodes number "
694 std::vector<const StructNode *> n(nNodes);
695 for (
int i = 0; i < nNodes; i++) {
700 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
701 "\"modes number\" keyword expected "
709 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
710 "invalid modes number "
718 ASSERT(nCols == 6*nNodes);
723 silent_cerr(
"ModalMappingExt(" << uLabel <<
"): "
724 "semicolon expected at line "
733 bOutputAccelerations,
734 pEFH, pEMF, bSendAfterPredict, iCoupling, bm,
735 bUseReferenceNodeForces, bRotateReferenceNodeForces, fOut));
flag fReadOutput(MBDynParser &HP, const T &t) const
const Vec3 Zero3(0., 0., 0.)
Vec3 Cross(const Vec3 &v) const
bool bUseReferenceNodeForces
virtual bool bToBeOutput(void) const
#define MBDYN_EXCEPT_ARGS
virtual void ResizeReset(integer)
virtual integer GetInt(integer iDefval=0)
virtual void Output(OutputHandler &OH) const
virtual const Mat3x3 & GetRCurr(void) const
integer iGetNumRows(void) const
const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.)
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
virtual bool Prepare(ExtFileHandlerBase *pEFH, unsigned uLabel, bool bRigid, unsigned uModes)=0
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Elem * ReadModalMappingExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
virtual Force::Type GetForceType(void) const
Vec3 MulTV(const Vec3 &v) const
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
#define SAFENEW(pnt, item)
virtual bool IsKeyWord(const char *sKeyWord)
virtual void Put(integer iRow, const Vec3 &v)
void Send(ExtFileHandlerBase *pEFH, ExtFileHandlerBase::SendWhen when)
virtual integer iGetFirstMomentumIndex(void) const =0
virtual void GetConnectedNodes(std::vector< const Node * > &connectedNodes) const
virtual const Vec3 & GetWCurr(void) const
#define ASSERT(expression)
virtual unsigned Recv(ExtFileHandlerBase *pEFH, unsigned uFlags, unsigned &uLabel, Vec3 &f, Vec3 &m, std::vector< doublereal > &fv)=0
Mat3x3 MulTM(const Mat3x3 &m) const
VectorExpression< VectorCrossExpr< VectorLhsExpr, VectorRhsExpr >, 3 > Cross(const VectorExpression< VectorLhsExpr, 3 > &u, const VectorExpression< VectorRhsExpr, 3 > &v)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual const Vec3 & GetXCurr(void) const
const StructNode * pRefNode
bool bRotateReferenceNodeForces
Vec3 MatR2LinParam(const Mat3x3 &m)
static std::stack< cleanup * > c
virtual ~ModalMappingExt(void)
virtual void Put(integer iRow, const Vec3 &v)
ModalMappingExt(unsigned int uL, DataManager *pDM, const StructNode *pRefNode, std::vector< const StructNode * > &n, SpMapMatrixHandler *pH, bool bOutputAccelerations, ExtFileHandlerBase *pEFH, ExtModalForceBase *pEMF, bool bSendAfterPredict, int iCoupling, ExtModalForceBase::BitMask bm, bool bUseReferenceNodeForces, bool bRotateReferenceNodeForces, flag fOut)
virtual bool GetYesNo(bool &bRet)
std::vector< NodeData > Nodes
virtual const Vec3 & GetVCurr(void) const
virtual VectorHandler & MatTVecMul(VectorHandler &out, const VectorHandler &in) const
virtual HighParser::ErrOut GetLineData(void) const
unsigned int GetLabel(void) const
bool Prepare(ExtFileHandlerBase *pEFH)
Node * ReadNode(MBDynParser &HP, Node::Type type) const
virtual VectorHandler & MatVecMul(VectorHandler &out, const VectorHandler &in) const
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
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
virtual void Resize(integer iNewSize)=0
std::ostream & Forces(void) const
bool UseText(int out) const
SpMapMatrixHandler * ReadSparseMappingMatrix(MBDynParser &HP, integer &nRows, integer &nCols)
virtual doublereal GetReal(const doublereal &dDefval=0.0)