#include #include "PartFrame.h" #include "Part.h" #include "EulerConstraint.h" #include "AbsConstraint.h" #include "MarkerFrame.h" #include "EulerParameters.h" #include "EulerParametersDot.h" #include "CREATE.h" #include "RedundantConstraint.h" using namespace MbD; PartFrame::PartFrame() { } PartFrame::PartFrame(const char* str) : CartesianFrame(str) { } void PartFrame::initialize() { aGeu = CREATE::With(); aGeu->setOwner(this); aGabs = std::make_shared>>(); markerFrames = std::make_shared>>(); } void PartFrame::initializeLocally() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->initializeLocally(); }); aGeu->initializeLocally(); aGabsDo([](std::shared_ptr aGab) { aGab->initializeLocally(); }); } void PartFrame::initializeGlobally() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->initializeGlobally(); }); aGeu->initializeGlobally(); aGabsDo([](std::shared_ptr aGab) { aGab->initializeGlobally(); }); } void PartFrame::setqX(FColDsptr x) { qX->copyFrom(x); } FColDsptr PartFrame::getqX() { return qX; } void PartFrame::setqE(FColDsptr x) { qE->copyFrom(x); } FColDsptr PartFrame::getqE() { return qE; } void PartFrame::setqXdot(FColDsptr x) { qXdot = x; } FColDsptr PartFrame::getqXdot() { return qXdot; } void PartFrame::setomeOpO(FColDsptr omeOpO) { qEdot = EulerParametersDot::FromqEOpAndOmegaOpO(qE, omeOpO); } FColDsptr PartFrame::getomeOpO() { return qE; } void MbD::PartFrame::setqXddot(FColDsptr x) { qXddot = x; } FColDsptr MbD::PartFrame::getqXddot() { return qXddot; } void MbD::PartFrame::setqEddot(FColDsptr x) { qEddot = x; } FColDsptr MbD::PartFrame::getqEddot() { return qEddot; } void PartFrame::setPart(Part* x) { part = x; } Part* PartFrame::getPart() { return part; } void PartFrame::addMarkerFrame(std::shared_ptr markerFrame) { markerFrame->setPartFrame(this); markerFrames->push_back(markerFrame); } EndFrmcptr PartFrame::endFrame(std::string name) { auto match = std::find_if(markerFrames->begin(), markerFrames->end(), [&](auto& mkr) {return mkr->getName() == name; }); return (*match)->endFrames->at(0); } void MbD::PartFrame::aGabsDo(const std::function)>& f) { std::for_each(aGabs->begin(), aGabs->end(), f); } void MbD::PartFrame::markerFramesDo(const std::function)>& f) { std::for_each(markerFrames->begin(), markerFrames->end(), f); } void MbD::PartFrame::removeRedundantConstraints(std::shared_ptr> redundantEqnNos) { if (std::find(redundantEqnNos->begin(), redundantEqnNos->end(), aGeu->iG) != redundantEqnNos->end()) { auto redunCon = CREATE::With(); redunCon->constraint = aGeu; aGeu = redunCon; } for (size_t i = 0; i < aGabs->size(); i++) { auto& constraint = aGabs->at(i); if (std::find(redundantEqnNos->begin(), redundantEqnNos->end(), constraint->iG) != redundantEqnNos->end()) { auto redunCon = CREATE::With(); redunCon->constraint = constraint; aGabs->at(i) = redunCon; } } } void MbD::PartFrame::reactivateRedundantConstraints() { if (aGeu->isRedundant()) aGeu = std::dynamic_pointer_cast(aGeu)->constraint; for (size_t i = 0; i < aGabs->size(); i++) { auto& con = aGabs->at(i); if (con->isRedundant()) { aGabs->at(i) = std::static_pointer_cast(con)->constraint; } } } void MbD::PartFrame::constraintsReport() { auto redunCons = std::make_shared>>(); aGabsDo([&](std::shared_ptr con) { if (con->isRedundant()) { redunCons->push_back(con); } }); if (aGeu->isRedundant()) redunCons->push_back(aGeu); if (redunCons->size() > 0) { std::string str = "MbD: " + part->classname() + std::string(" ") + part->getName() + " has the following constraint(s) removed: "; this->logString(str); std::for_each(redunCons->begin(), redunCons->end(), [&](auto& con) { str = "MbD: " + std::string(" ") + std::string(typeid(*con).name()); this->logString(str); }); } } void MbD::PartFrame::prePosIC() { iqX = -1; iqE = -1; Item::prePosIC(); markerFramesDo([](std::shared_ptr markerFrm) { markerFrm->prePosIC(); }); aGeu->prePosIC(); aGabsDo([](std::shared_ptr aGab) { aGab->prePosIC(); }); } void MbD::PartFrame::prePosKine() { iqX = -1; iqE = -1; this->calcPostDynCorrectorIteration(); markerFramesDo([](std::shared_ptr markerFrm) { markerFrm->prePosKine(); }); aGeu->prePosKine(); aGabsDo([](std::shared_ptr aGab) { aGab->prePosKine(); }); } FColDsptr MbD::PartFrame::rOpO() { return qX; } FMatDsptr MbD::PartFrame::aAOp() { return qE->aA; } FMatDsptr MbD::PartFrame::aC() { return qE->aC; } FMatDsptr MbD::PartFrame::aCdot() { return qEdot->aCdot; } FColFMatDsptr MbD::PartFrame::pAOppE() { return qE->pApE; } void MbD::PartFrame::fillEssenConstraints(std::shared_ptr>> essenConstraints) { aGeu->fillEssenConstraints(aGeu, essenConstraints); aGabsDo([&](std::shared_ptr con) { con->fillEssenConstraints(con, essenConstraints); }); } void MbD::PartFrame::fillRedundantConstraints(std::shared_ptr>> redunConstraints) { } void MbD::PartFrame::fillConstraints(std::shared_ptr>> allConstraints) { aGeu->fillConstraints(aGeu, allConstraints); aGabsDo([&](std::shared_ptr con) { con->fillConstraints(con, allConstraints); }); } void MbD::PartFrame::fillqsu(FColDsptr col) { col->atiputFullColumn(iqX, qX); col->atiputFullColumn(iqE, qE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillqsu(col); }); } void MbD::PartFrame::fillqsuWeights(std::shared_ptr> diagMat) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillqsuWeights(diagMat); }); } void MbD::PartFrame::fillqsulam(FColDsptr col) { col->atiputFullColumn(iqX, qX); col->atiputFullColumn(iqE, qE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillqsulam(col); }); aGeu->fillqsulam(col); aGabsDo([&](std::shared_ptr con) { con->fillqsulam(col); }); } void MbD::PartFrame::fillqsudot(FColDsptr col) { col->atiputFullColumn(iqX, qXdot); col->atiputFullColumn(iqE, qEdot); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillqsudot(col); }); } void MbD::PartFrame::fillqsudotWeights(std::shared_ptr> diagMat) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillqsudotWeights(diagMat); }); } void MbD::PartFrame::useEquationNumbers() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->useEquationNumbers(); }); aGeu->useEquationNumbers(); aGabsDo([](std::shared_ptr con) { con->useEquationNumbers(); }); } void MbD::PartFrame::setqsu(FColDsptr col) { qX->equalFullColumnAt(col, iqX); qE->equalFullColumnAt(col, iqE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->setqsu(col); }); aGeu->setqsu(col); aGabsDo([&](std::shared_ptr con) { con->setqsu(col); }); } void MbD::PartFrame::setqsulam(FColDsptr col) { qX->equalFullColumnAt(col, iqX); qE->equalFullColumnAt(col, iqE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->setqsulam(col); }); aGeu->setqsulam(col); aGabsDo([&](std::shared_ptr con) { con->setqsulam(col); }); } void MbD::PartFrame::setqsudotlam(FColDsptr col) { qXdot->equalFullColumnAt(col, iqX); qEdot->equalFullColumnAt(col, iqE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->setqsudotlam(col); }); aGeu->setqsudotlam(col); aGabsDo([&](std::shared_ptr con) { con->setqsudotlam(col); }); } void MbD::PartFrame::postPosICIteration() { Item::postPosICIteration(); markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->postPosICIteration(); }); aGeu->postPosICIteration(); aGabsDo([](std::shared_ptr con) { con->postPosICIteration(); }); } void MbD::PartFrame::fillPosICError(FColDsptr col) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillPosICError(col); }); aGeu->fillPosICError(col); aGabsDo([&](std::shared_ptr con) { con->fillPosICError(col); }); } void MbD::PartFrame::fillPosICJacob(SpMatDsptr mat) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillPosICJacob(mat); }); aGeu->fillPosICJacob(mat); aGabsDo([&](std::shared_ptr con) { con->fillPosICJacob(mat); }); } void MbD::PartFrame::postPosIC() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->postPosIC(); }); aGeu->postPosIC(); aGabsDo([](std::shared_ptr con) { con->postPosIC(); }); } void MbD::PartFrame::outputStates() { std::stringstream ss; ss << "qX = "; qX->printOn(ss); ss << std::endl; ss << "qE = "; qE->printOn(ss); auto str = ss.str(); this->logString(str); aGeu->outputStates(); aGabsDo([](std::shared_ptr con) { con->outputStates(); }); } void MbD::PartFrame::preDyn() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->preDyn(); }); aGeu->preDyn(); aGabsDo([](std::shared_ptr aGab) { aGab->preDyn(); }); } void MbD::PartFrame::storeDynState() { markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->storeDynState(); }); aGeu->storeDynState(); aGabsDo([](std::shared_ptr aGab) { aGab->storeDynState(); }); } void MbD::PartFrame::fillPosKineError(FColDsptr col) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillPosKineError(col); }); aGeu->fillPosKineError(col); aGabsDo([&](std::shared_ptr con) { con->fillPosKineError(col); }); } void MbD::PartFrame::preVelIC() { Item::preVelIC(); markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->preVelIC(); }); aGeu->preVelIC(); aGabsDo([](std::shared_ptr aGab) { aGab->preVelIC(); }); } void MbD::PartFrame::postVelIC() { qEdot->calcAdotBdotCdot(); qEdot->calcpAdotpE(); markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->postVelIC(); }); aGeu->postVelIC(); aGabsDo([](std::shared_ptr aGab) { aGab->postVelIC(); }); } void MbD::PartFrame::fillVelICError(FColDsptr col) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillVelICError(col); }); aGeu->fillVelICError(col); aGabsDo([&](std::shared_ptr con) { con->fillVelICError(col); }); } void MbD::PartFrame::fillVelICJacob(SpMatDsptr mat) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillVelICJacob(mat); }); aGeu->fillVelICJacob(mat); aGabsDo([&](std::shared_ptr con) { con->fillVelICJacob(mat); }); } void MbD::PartFrame::preAccIC() { qXddot = std::make_shared>(3, 0.0); qEddot = std::make_shared>(4, 0.0); Item::preAccIC(); markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->preAccIC(); }); aGeu->preAccIC(); aGabsDo([](std::shared_ptr aGab) { aGab->preAccIC(); }); } void MbD::PartFrame::fillAccICIterError(FColDsptr col) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillAccICIterError(col); }); aGeu->fillAccICIterError(col); aGabsDo([&](std::shared_ptr con) { con->fillAccICIterError(col); }); } void MbD::PartFrame::fillAccICIterJacob(SpMatDsptr mat) { markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->fillAccICIterJacob(mat); }); aGeu->fillAccICIterJacob(mat); aGabsDo([&](std::shared_ptr con) { con->fillAccICIterJacob(mat); }); } void MbD::PartFrame::setqsuddotlam(FColDsptr qsudotlam) { qXddot->equalFullColumnAt(qsudotlam, iqX); qEddot->equalFullColumnAt(qsudotlam, iqE); markerFramesDo([&](std::shared_ptr markerFrame) { markerFrame->setqsuddotlam(qsudotlam); }); aGeu->setqsuddotlam(qsudotlam); aGabsDo([&](std::shared_ptr con) { con->setqsuddotlam(qsudotlam); }); } void PartFrame::asFixed() { for (int i = 0; i < 6; i++) { auto con = CREATE::With(i); con->setOwner(this); aGabs->push_back(con); } } void MbD::PartFrame::postInput() { qXddot = std::make_shared>(3, 0.0); qEddot = std::make_shared>(4, 0.0); Item::postInput(); markerFramesDo([](std::shared_ptr markerFrame) { markerFrame->postInput(); }); aGeu->postInput(); aGabsDo([](std::shared_ptr aGab) { aGab->postInput(); }); } void MbD::PartFrame::calcPostDynCorrectorIteration() { qE->calcABC(); qE->calcpApE(); qEdot->calcAdotBdotCdot(); qEdot->calcpAdotpE(); }