From c147f2a33dd979916bfb447f00e497d86cf6971f Mon Sep 17 00:00:00 2001 From: Aik-Siong Koh Date: Fri, 12 May 2023 21:50:11 -0600 Subject: [PATCH] EndFrameqct done --- MbDCode/Array.h | 10 ++++ MbDCode/CartesianFrame.cpp | 1 - MbDCode/Constant.cpp | 5 ++ MbDCode/Constant.h | 1 + MbDCode/ConstraintIJ.cpp | 2 +- MbDCode/ConstraintIJ.h | 5 +- MbDCode/DirectionCosineConstraintIJ.cpp | 2 +- MbDCode/DirectionCosineConstraintIJ.h | 2 +- MbDCode/DirectionCosineIecJec.cpp | 2 +- MbDCode/DirectionCosineIecJec.h | 2 +- MbDCode/DirectionCosineIeqcJec.h | 2 +- MbDCode/DirectionCosineIeqcJeqc.h | 2 +- MbDCode/EndFramec.cpp | 1 - MbDCode/EndFramec.h | 6 +- MbDCode/EndFrameqc.cpp | 39 +++++++++---- MbDCode/EndFrameqc.h | 18 +++--- MbDCode/EndFrameqct.cpp | 74 +++++++++++++++++-------- MbDCode/EndFrameqct.h | 21 ++++--- MbDCode/EulerParameters.cpp | 8 +-- MbDCode/EulerParameters.h | 4 +- MbDCode/ExpressionX.cpp | 1 + MbDCode/ExpressionX.h | 10 ++++ MbDCode/FullColumn.h | 7 +-- MbDCode/FullMatrix.h | 22 ++++---- MbDCode/FullRow.h | 3 +- MbDCode/Function.cpp | 1 + MbDCode/Function.h | 10 ++++ MbDCode/FunctionWithManyArgs.cpp | 27 +++++++++ MbDCode/FunctionWithManyArgs.h | 18 ++++++ MbDCode/FunctionX.cpp | 1 + MbDCode/FunctionX.h | 10 ++++ MbDCode/Joint.cpp | 4 +- MbDCode/Joint.h | 12 ++-- MbDCode/KinematicIeJe.cpp | 2 +- MbDCode/KinematicIeJe.h | 5 +- MbDCode/MarkerFrame.cpp | 10 ++-- MbDCode/MarkerFrame.h | 11 ++-- MbDCode/MbDCode.cpp | 7 ++- MbDCode/MbDCode.vcxproj | 13 +++++ MbDCode/MbDCode.vcxproj.filters | 39 +++++++++++++ MbDCode/NewtonRaphson.h | 10 ++++ MbDCode/Part.cpp | 1 + MbDCode/Part.h | 6 +- MbDCode/PartFrame.cpp | 9 ++- MbDCode/PartFrame.h | 7 ++- MbDCode/PrescribedMotion.cpp | 22 +------- MbDCode/PrescribedMotion.h | 17 +++--- MbDCode/Product.cpp | 10 ++++ MbDCode/Product.h | 16 ++++++ MbDCode/RowTypeMatrix.h | 11 ++++ MbDCode/SparseMatrix.h | 7 +-- MbDCode/SparseRow.h | 2 +- MbDCode/Sum.cpp | 10 ++++ MbDCode/Sum.h | 16 ++++++ MbDCode/Symbolic.cpp | 30 ++++++++++ MbDCode/Symbolic.h | 10 ++++ MbDCode/System.cpp | 19 ++++--- MbDCode/System.h | 6 +- MbDCode/SystemSolver.cpp | 2 +- MbDCode/SystemSolver.h | 2 +- MbDCode/Variable.cpp | 5 ++ MbDCode/Variable.h | 1 + MbDCode/Vector.h | 2 - MbDCode/ZRotation.cpp | 9 +-- MbDCode/typedef.h | 30 ++++++++++ 65 files changed, 514 insertions(+), 166 deletions(-) create mode 100644 MbDCode/ExpressionX.cpp create mode 100644 MbDCode/ExpressionX.h create mode 100644 MbDCode/Function.cpp create mode 100644 MbDCode/Function.h create mode 100644 MbDCode/FunctionWithManyArgs.cpp create mode 100644 MbDCode/FunctionWithManyArgs.h create mode 100644 MbDCode/FunctionX.cpp create mode 100644 MbDCode/FunctionX.h create mode 100644 MbDCode/Product.cpp create mode 100644 MbDCode/Product.h create mode 100644 MbDCode/Sum.cpp create mode 100644 MbDCode/Sum.h create mode 100644 MbDCode/typedef.h diff --git a/MbDCode/Array.h b/MbDCode/Array.h index 86dcb35..c0b8ce2 100644 --- a/MbDCode/Array.h +++ b/MbDCode/Array.h @@ -12,6 +12,7 @@ namespace MbD { Array(size_t count, const T& value) : std::vector(count, value) {} Array(std::initializer_list list) : std::vector{ list } {} void copy(std::shared_ptr> x); + void zeroSelf(); }; template inline void Array::copy(std::shared_ptr> x) @@ -20,5 +21,14 @@ namespace MbD { this->at(i) = x->at(i); } } + template <> + inline void Array::zeroSelf() { + for (int i = 0; i < this->size(); i++) { + this->at(i) = 0.0;; + } + } + using ListD = std::initializer_list; + using ListListD = std::initializer_list>; + using ListListPairD = std::initializer_list>>; } diff --git a/MbDCode/CartesianFrame.cpp b/MbDCode/CartesianFrame.cpp index 8b1a632..6199931 100644 --- a/MbDCode/CartesianFrame.cpp +++ b/MbDCode/CartesianFrame.cpp @@ -12,5 +12,4 @@ CartesianFrame::CartesianFrame(const char* str) : Item(str) void CartesianFrame::initialize() { - Item::initialize(); } diff --git a/MbDCode/Constant.cpp b/MbDCode/Constant.cpp index 28a36f7..8f7cbc5 100644 --- a/MbDCode/Constant.cpp +++ b/MbDCode/Constant.cpp @@ -9,3 +9,8 @@ Constant::Constant() Constant::Constant(double val) : Variable(val) { } + +std::shared_ptr MbD::Constant::differentiateWRT(std::shared_ptr var) +{ + return std::make_shared(0.0); +} diff --git a/MbDCode/Constant.h b/MbDCode/Constant.h index b7f98b2..5ac5a89 100644 --- a/MbDCode/Constant.h +++ b/MbDCode/Constant.h @@ -8,6 +8,7 @@ namespace MbD { public: Constant(); Constant(double val); + std::shared_ptr differentiateWRT(std::shared_ptr var) override; }; } diff --git a/MbDCode/ConstraintIJ.cpp b/MbDCode/ConstraintIJ.cpp index f1a8c29..e065d91 100644 --- a/MbDCode/ConstraintIJ.cpp +++ b/MbDCode/ConstraintIJ.cpp @@ -3,7 +3,7 @@ using namespace MbD; -MbD::ConstraintIJ::ConstraintIJ(std::shared_ptr frmi, std::shared_ptr frmj) : frmI(frmi), frmJ(frmj) +MbD::ConstraintIJ::ConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj) : frmI(frmi), frmJ(frmj) { aConstant = 0.0; } diff --git a/MbDCode/ConstraintIJ.h b/MbDCode/ConstraintIJ.h index cdff99a..12ffeff 100644 --- a/MbDCode/ConstraintIJ.h +++ b/MbDCode/ConstraintIJ.h @@ -1,5 +1,6 @@ #pragma once +//#include "typedef.h" #include "Constraint.h" #include "EndFramec.h" @@ -8,9 +9,9 @@ namespace MbD { { //frmI frmJ aConstant public: - ConstraintIJ(std::shared_ptr frmi, std::shared_ptr frmj); + ConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj); - std::shared_ptr frmI, frmJ; + EndFrmcptr frmI, frmJ; double aConstant; }; } diff --git a/MbDCode/DirectionCosineConstraintIJ.cpp b/MbDCode/DirectionCosineConstraintIJ.cpp index 9d3c0dc..bb544bb 100644 --- a/MbDCode/DirectionCosineConstraintIJ.cpp +++ b/MbDCode/DirectionCosineConstraintIJ.cpp @@ -3,7 +3,7 @@ using namespace MbD; -DirectionCosineConstraintIJ::DirectionCosineConstraintIJ(std::shared_ptr frmi, std::shared_ptr frmj, int axisi, int axisj) : +DirectionCosineConstraintIJ::DirectionCosineConstraintIJ(EndFrmcptr frmi, EndFrmcptr frmj, int axisi, int axisj) : ConstraintIJ(frmI, frmJ), axisI(axisi), axisJ(axisj) { aAijIeJe = std::make_shared(frmI, frmJ, axisI, axisJ); diff --git a/MbDCode/DirectionCosineConstraintIJ.h b/MbDCode/DirectionCosineConstraintIJ.h index 7a80d11..0a0f330 100644 --- a/MbDCode/DirectionCosineConstraintIJ.h +++ b/MbDCode/DirectionCosineConstraintIJ.h @@ -9,7 +9,7 @@ namespace MbD { //axisI axisJ aAijIeJe public: // self owns : (MbDDirectionCosineConstraintIJ withFrmI : frmI frmJ : frmJ axisI : 2 axisJ : 1). - DirectionCosineConstraintIJ(std::shared_ptr frmI, std::shared_ptr frmJ, int axisI, int axisJ); + DirectionCosineConstraintIJ(EndFrmcptr frmI, EndFrmcptr frmJ, int axisI, int axisJ); int axisI, axisJ; std::shared_ptr aAijIeJe; diff --git a/MbDCode/DirectionCosineIecJec.cpp b/MbDCode/DirectionCosineIecJec.cpp index 573218d..b84a0c6 100644 --- a/MbDCode/DirectionCosineIecJec.cpp +++ b/MbDCode/DirectionCosineIecJec.cpp @@ -9,7 +9,7 @@ MbD::DirectionCosineIecJec::DirectionCosineIecJec() { } -MbD::DirectionCosineIecJec::DirectionCosineIecJec(std::shared_ptr frmi, std::shared_ptr frmj, int axisi, int axisj) : +MbD::DirectionCosineIecJec::DirectionCosineIecJec(EndFrmcptr frmi, EndFrmcptr frmj, int axisi, int axisj) : KinematicIeJe(frmi, frmj), axisI(axisi), axisJ(axisj) { aAijIeJe = 0.0; diff --git a/MbDCode/DirectionCosineIecJec.h b/MbDCode/DirectionCosineIecJec.h index 5a84bcb..d76a874 100644 --- a/MbDCode/DirectionCosineIecJec.h +++ b/MbDCode/DirectionCosineIecJec.h @@ -11,7 +11,7 @@ namespace MbD { //aAijIeJe axisI axisJ aAjOIe aAjOJe public: DirectionCosineIecJec(); - DirectionCosineIecJec(std::shared_ptr frmI, std::shared_ptr frmJ, int axisI, int axisJ); + DirectionCosineIecJec(EndFrmcptr frmI, EndFrmcptr frmJ, int axisI, int axisJ); int axisI, axisJ; double aAijIeJe; diff --git a/MbDCode/DirectionCosineIeqcJec.h b/MbDCode/DirectionCosineIeqcJec.h index ae14cbc..59f1446 100644 --- a/MbDCode/DirectionCosineIeqcJec.h +++ b/MbDCode/DirectionCosineIeqcJec.h @@ -13,7 +13,7 @@ namespace MbD { FRowDsptr pAijIeJepEI; FMatDsptr ppAijIeJepEIpEI; FMatDsptr pAjOIepEIT; - std::shared_ptr>> ppAjOIepEIpEI; + std::shared_ptr>>> ppAjOIepEIpEI; }; } diff --git a/MbDCode/DirectionCosineIeqcJeqc.h b/MbDCode/DirectionCosineIeqcJeqc.h index c17e021..239a3fa 100644 --- a/MbDCode/DirectionCosineIeqcJeqc.h +++ b/MbDCode/DirectionCosineIeqcJeqc.h @@ -14,7 +14,7 @@ namespace MbD { FMatDsptr ppAijIeJepEIpEJ; FMatDsptr ppAijIeJepEJpEJ; FMatDsptr pAjOJepEJT; - std::shared_ptr>> ppAjOJepEJpEJ; + std::shared_ptr>>> ppAjOJepEJpEJ; }; } diff --git a/MbDCode/EndFramec.cpp b/MbDCode/EndFramec.cpp index dec4843..d583628 100644 --- a/MbDCode/EndFramec.cpp +++ b/MbDCode/EndFramec.cpp @@ -14,7 +14,6 @@ EndFramec::EndFramec(const char* str) : CartesianFrame(str) { void EndFramec::initialize() { - CartesianFrame::initialize(); } void EndFramec::setMarkerFrame(MarkerFrame* markerFrm) diff --git a/MbDCode/EndFramec.h b/MbDCode/EndFramec.h index f384de6..dcbbdcf 100644 --- a/MbDCode/EndFramec.h +++ b/MbDCode/EndFramec.h @@ -1,6 +1,9 @@ #pragma once + +#include + #include "CartesianFrame.h" -#include "MarkerFrame.h" +//#include "MarkerFrame.h" #include "FullColumn.h" #include "FullMatrix.h" @@ -24,5 +27,6 @@ namespace MbD { FColDsptr rOeO = std::make_shared>(3); FMatDsptr aAOe = std::make_shared>(3, 3); }; + using EndFrmcptr = std::shared_ptr; } diff --git a/MbDCode/EndFrameqc.cpp b/MbDCode/EndFrameqc.cpp index 9be88f3..1a82319 100644 --- a/MbDCode/EndFrameqc.cpp +++ b/MbDCode/EndFrameqc.cpp @@ -2,6 +2,8 @@ #include "EndFrameqc.h" #include "EndFrameqct.h" +#include "Variable.h" +#include "MarkerFrame.h" using namespace MbD; @@ -15,26 +17,41 @@ EndFrameqc::EndFrameqc(const char* str) : EndFramec(str) { void EndFrameqc::initialize() { - EndFramec::initialize(); - prOeOpE = std::make_unique>(3, 4); - pprOeOpEpE = std::make_unique>>>(4, 4); - pAOepE = std::make_unique>>>(4); - ppAOepEpE = std::make_unique>>>(4, 4); + prOeOpE = std::make_shared>(3, 4); + pprOeOpEpE = std::make_shared>>>(4, 4); + pAOepE = std::make_shared>>>(4); + ppAOepEpE = std::make_shared>>>(4, 4); } void EndFrameqc::initializeLocally() { + if (endFrameqct) { + endFrameqct->initializeLocally(); + } } void EndFrameqc::initializeGlobally() { + if (endFrameqct) { + endFrameqct->initializeGlobally(); + } + else { + pprOeOpEpE = markerFrame->pprOmOpEpE; + ppAOepEpE = markerFrame->ppAOmpEpE; + } } -void MbD::EndFrameqc::EndFrameqctFrom(std::shared_ptr& frm) +void MbD::EndFrameqc::EndFrameqctFrom(EndFrmcptr& frm) { - std::shared_ptr newFrm; - newFrm = std::make_shared(frm->getName().c_str()); - newFrm->setMarkerFrame(frm->getMarkerFrame()); - //frm.swap(newFrm); - std::swap(*(frm.get()), *(newFrm.get())); + endFrameqct = std::make_shared(); +} + +void MbD::EndFrameqc::setrmemBlks(std::shared_ptr>> xyzBlks) +{ + std::static_pointer_cast(endFrameqct)->rmemBlks = xyzBlks; +} + +void MbD::EndFrameqc::setphiThePsiBlks(std::shared_ptr>> xyzRotBlks) +{ + std::static_pointer_cast(endFrameqct)->phiThePsiBlks = xyzRotBlks; } diff --git a/MbDCode/EndFrameqc.h b/MbDCode/EndFrameqc.h index a2e4680..f962584 100644 --- a/MbDCode/EndFrameqc.h +++ b/MbDCode/EndFrameqc.h @@ -1,10 +1,9 @@ #pragma once + #include "EndFramec.h" -#include "FullColumn.h" -#include "FullMatrix.h" namespace MbD { - class EndFramec; + class Symbolic; class EndFrameqc : public EndFramec { @@ -15,12 +14,15 @@ namespace MbD { void initialize(); void initializeLocally() override; void initializeGlobally() override; - void EndFrameqctFrom(std::shared_ptr& frm) override; + void EndFrameqctFrom(EndFrmcptr& frm) override; + void setrmemBlks(std::shared_ptr>> xyzBlks); + void setphiThePsiBlks(std::shared_ptr>> xyzRotBlks); - FMatDuptr prOeOpE; - std::unique_ptr>>> pprOeOpEpE; - std::unique_ptr>>> pAOepE; - FMatFMatDuptr ppAOepEpE; + FMatDsptr prOeOpE; + std::shared_ptr>>> pprOeOpEpE; + std::shared_ptr>>> pAOepE; + FMatFMatDsptr ppAOepEpE; + std::shared_ptr endFrameqct; }; } diff --git a/MbDCode/EndFrameqct.cpp b/MbDCode/EndFrameqct.cpp index ee0a8b8..889a6d6 100644 --- a/MbDCode/EndFrameqct.cpp +++ b/MbDCode/EndFrameqct.cpp @@ -1,4 +1,5 @@ #include "EndFrameqct.h" +#include "System.h" using namespace MbD; @@ -12,34 +13,63 @@ EndFrameqct::EndFrameqct(const char* str) : EndFrameqc(str) { void EndFrameqct::initialize() { - EndFrameqc::initialize(); - rmem = std::make_unique>(3); - prmempt = std::make_unique>(3); - pprmemptpt = std::make_unique>(3); - aAme = std::make_unique>(3, 3); - pAmept = std::make_unique>(3, 3); - ppAmeptpt = std::make_unique>(3, 3); - pprOeOpEpt = std::make_unique>(3, 4); - pprOeOptpt = std::make_unique>(3); - ppAOepEpt = std::make_unique>>(4); - ppAOeptpt = std::make_unique>(3, 3); + rmem = std::make_shared>(3); + prmempt = std::make_shared>(3); + pprmemptpt = std::make_shared>(3); + aAme = std::make_shared>(3, 3); + pAmept = std::make_shared>(3, 3); + ppAmeptpt = std::make_shared>(3, 3); + pprOeOpEpt = std::make_shared>(3, 4); + pprOeOptpt = std::make_shared>(3); + ppAOepEpt = std::make_shared>>>(4); + ppAOeptpt = std::make_shared>(3, 3); } void EndFrameqct::initializeLocally() { - //rmemBlks == nil - // ifTrue : - //[rmem zeroSelf. - // prmempt zeroSelf. - // pprmemptpt zeroSelf] . - // phiThePsiBlks == nil - // ifTrue : - //[aAme identity. - // pAmept zeroSelf. - // ppAmeptpt zeroSelf] + if (!rmemBlks) { + rmem->zeroSelf(); + prmempt->zeroSelf(); + pprmemptpt->zeroSelf(); + } + if (!phiThePsiBlks) { + aAme->identity(); + pAmept->zeroSelf(); + ppAmeptpt->zeroSelf(); + } } void EndFrameqct::initializeGlobally() { - + if (!rmemBlks) { + initprmemptBlks(); + initpprmemptptBlks(); + } + if (!phiThePsiBlks) { + initpPhiThePsiptBlks(); + initppPhiThePsiptptBlks(); + } +} + +void MbD::EndFrameqct::initprmemptBlks() +{ + auto time = System::getInstance().time; + prmemptBlks = std::make_shared< FullColumn>>(3); + for (int i = 0; i < 3; i++) { + auto disp = rmemBlks->at(i); + auto vel = (disp->differentiateWRT(time))->simplified(); + prmemptBlks->at(i) = vel; + } +} + +void MbD::EndFrameqct::initpprmemptptBlks() +{ +} + +void MbD::EndFrameqct::initpPhiThePsiptBlks() +{ +} + +void MbD::EndFrameqct::initppPhiThePsiptptBlks() +{ } diff --git a/MbDCode/EndFrameqct.h b/MbDCode/EndFrameqct.h index b1c9c30..1fd80a0 100644 --- a/MbDCode/EndFrameqct.h +++ b/MbDCode/EndFrameqct.h @@ -1,8 +1,10 @@ #pragma once #include "EndFrameqc.h" -#include "Variable.h" namespace MbD { + + class Symbolic; + class EndFrameqct : public EndFrameqc { //time rmemBlks prmemptBlks pprmemptptBlks phiThePsiBlks pPhiThePsiptBlks ppPhiThePsiptptBlks @@ -13,14 +15,19 @@ namespace MbD { void initialize(); void initializeLocally() override; void initializeGlobally() override; + void initprmemptBlks(); + void initpprmemptptBlks(); + void initpPhiThePsiptBlks(); + void initppPhiThePsiptptBlks(); double time; - std::shared_ptr>> rmemBlks; - std::shared_ptr>> phiThePsiBlks; - FColDuptr rmem, prmempt, pprmemptpt, pprOeOptpt; - FMatDuptr aAme, pAmept, ppAmeptpt, ppAOeptpt; - FMatDuptr pprOeOpEpt; - std::unique_ptr>> ppAOepEpt; + std::shared_ptr>> rmemBlks, prmemptBlks, pprmemptptBlks; + std::shared_ptr>> phiThePsiBlks, pPhiThePsiptBlks, ppPhiThePsiptptBlks; + FColDsptr rmem, prmempt, pprmemptpt, pprOeOptpt; + FMatDsptr aAme, pAmept, ppAmeptpt, ppAOeptpt; + FMatDsptr pprOeOpEpt; + std::shared_ptr>>> ppAOepEpt; }; + using EndFrmqctptr = std::shared_ptr; } diff --git a/MbDCode/EulerParameters.cpp b/MbDCode/EulerParameters.cpp index 3f628bd..cfac1cf 100644 --- a/MbDCode/EulerParameters.cpp +++ b/MbDCode/EulerParameters.cpp @@ -6,7 +6,7 @@ using namespace MbD; -std::unique_ptr>>> EulerParameters::ppApEpEtimesColumn(FColDsptr col) +std::shared_ptr>>> EulerParameters::ppApEpEtimesColumn(FColDsptr col) { double a2c1 = 2 * col->at(0); double a2c2 = 2 * col->at(1); @@ -24,7 +24,7 @@ std::unique_ptr>>> EulerParameters auto col33 = std::make_shared>(ListD{ m2c1, m2c2, a2c3 }); auto col34 = std::make_shared>(ListD{ m2c2, a2c1, 0 }); auto col44 = std::make_shared>(ListD{ a2c1, a2c2, a2c3 }); - auto answer = std::make_unique>>>(4, 4); + auto answer = std::make_shared>>>(4, 4); auto row1 = answer->at(0); row1->at(0) = col11; row1->at(1) = col12; @@ -48,7 +48,7 @@ std::unique_ptr>>> EulerParameters return answer; } -std::unique_ptr>>> EulerParameters::ppApEpEtimesMatrix(FMatDsptr mat) +std::shared_ptr>>> EulerParameters::ppApEpEtimesMatrix(FMatDsptr mat) { FRowDsptr a2m1 = mat->at(0)->times(2.0); FRowDsptr a2m2 = mat->at(1)->times(2.0); @@ -68,7 +68,7 @@ std::unique_ptr>>> EulerParameters auto mat33 = std::make_shared>(ListFRD{ m2m1, m2m2, a2m3 }); auto mat34 = std::make_shared>(ListFRD{ m2m2, a2m1, zero }); auto mat44 = std::make_shared>(ListFRD{ a2m1, a2m2, a2m3 }); - auto answer = std::make_unique>>>(4, 4); + auto answer = std::make_shared>>>(4, 4); auto row1 = answer->at(0); row1->at(0) = mat11; row1->at(1) = mat12; diff --git a/MbDCode/EulerParameters.h b/MbDCode/EulerParameters.h index d74eb09..30eee56 100644 --- a/MbDCode/EulerParameters.h +++ b/MbDCode/EulerParameters.h @@ -8,8 +8,8 @@ namespace MbD { { //aA aB aC pApE public: - static std::unique_ptr>>> ppApEpEtimesColumn(FColDsptr col); - static std::unique_ptr>>> ppApEpEtimesMatrix(FMatDsptr col); + static std::shared_ptr>>> ppApEpEtimesColumn(FColDsptr col); + static std::shared_ptr>>> ppApEpEtimesMatrix(FMatDsptr col); }; } diff --git a/MbDCode/ExpressionX.cpp b/MbDCode/ExpressionX.cpp new file mode 100644 index 0000000..c2be36f --- /dev/null +++ b/MbDCode/ExpressionX.cpp @@ -0,0 +1 @@ +#include "ExpressionX.h" diff --git a/MbDCode/ExpressionX.h b/MbDCode/ExpressionX.h new file mode 100644 index 0000000..0a7e4d0 --- /dev/null +++ b/MbDCode/ExpressionX.h @@ -0,0 +1,10 @@ +#pragma once + +#include "FunctionX.h" + +namespace MbD { + class ExpressionX : public FunctionX + { + }; +} + diff --git a/MbDCode/FullColumn.h b/MbDCode/FullColumn.h index ce80fa9..bb938b4 100644 --- a/MbDCode/FullColumn.h +++ b/MbDCode/FullColumn.h @@ -25,10 +25,7 @@ namespace MbD { return ss.str(); } }; - - typedef std::shared_ptr> FColDsptr; - typedef std::unique_ptr> FColDuptr; - //typedef std::shared_ptr>>> FColFMatDsptr; - //typedef std::unique_ptr>>> FColFMatDuptr; + using FColDsptr = std::shared_ptr>; + //using FColFMatDsptr = std::shared_ptr>>>; } diff --git a/MbDCode/FullMatrix.h b/MbDCode/FullMatrix.h index 846ffda..51b6627 100644 --- a/MbDCode/FullMatrix.h +++ b/MbDCode/FullMatrix.h @@ -31,16 +31,18 @@ namespace MbD { this->push_back(row); } } + void identity(); }; - - typedef std::initializer_list> ListListD; - typedef std::initializer_list ListFRD; - typedef std::shared_ptr> FMatDsptr; - typedef std::unique_ptr> FMatDuptr; - //typedef std::shared_ptr>>> FMatFColDsptr; - //typedef std::unique_ptr>>> FMatFColDuptr; - typedef std::shared_ptr>>> FMatFMatDsptr; - typedef std::unique_ptr>>> FMatFMatDuptr; - + template <> + inline void FullMatrix::identity() { + this->zeroSelf(); + for (int i = 0; i < this->size(); i++) { + this->at(i)->at(i) = 1.0; + } + } + using FMatDsptr = std::shared_ptr>; + using FMatDsptr = std::shared_ptr>; + //using FMatFColDsptr = std::shared_ptr>>>; + using FMatFMatDsptr = std::shared_ptr>>>; } diff --git a/MbDCode/FullRow.h b/MbDCode/FullRow.h index 9b3a5cf..65979e3 100644 --- a/MbDCode/FullRow.h +++ b/MbDCode/FullRow.h @@ -13,7 +13,6 @@ namespace MbD { std::shared_ptr> negated(); }; - typedef std::shared_ptr> FRowDsptr; template inline std::shared_ptr> FullRow::times(double a) @@ -30,5 +29,7 @@ namespace MbD { { return this->times(-1.0); } + using ListFRD = std::initializer_list>>; + using FRowDsptr = std::shared_ptr>; } diff --git a/MbDCode/Function.cpp b/MbDCode/Function.cpp new file mode 100644 index 0000000..c72491e --- /dev/null +++ b/MbDCode/Function.cpp @@ -0,0 +1 @@ +#include "Function.h" diff --git a/MbDCode/Function.h b/MbDCode/Function.h new file mode 100644 index 0000000..d7f9ff5 --- /dev/null +++ b/MbDCode/Function.h @@ -0,0 +1,10 @@ +#pragma once + +#include "Symbolic.h" + +namespace MbD { + class Function : public Symbolic + { + }; +} + diff --git a/MbDCode/FunctionWithManyArgs.cpp b/MbDCode/FunctionWithManyArgs.cpp new file mode 100644 index 0000000..0b1df70 --- /dev/null +++ b/MbDCode/FunctionWithManyArgs.cpp @@ -0,0 +1,27 @@ +#include "FunctionWithManyArgs.h" +#include "Symbolic.h" + +using namespace MbD; + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term) +{ + terms = std::make_shared>>(); + terms->push_back(term); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term) +{ + terms->push_back(term1); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1) +{ + terms->push_back(term2); +} + +MbD::FunctionWithManyArgs::FunctionWithManyArgs(std::shared_ptr>> _terms) { + terms = std::make_shared>>(); + for (int i = 0; i < _terms->size(); i++) + terms->push_back(_terms->at(i)); +} + diff --git a/MbDCode/FunctionWithManyArgs.h b/MbDCode/FunctionWithManyArgs.h new file mode 100644 index 0000000..0fb6b74 --- /dev/null +++ b/MbDCode/FunctionWithManyArgs.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Function.h" + +namespace MbD { + class FunctionWithManyArgs : public Function + { + //terms + public: + FunctionWithManyArgs(std::shared_ptr term); + FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1); + FunctionWithManyArgs(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2); + FunctionWithManyArgs(std::shared_ptr>> _terms); + + std::shared_ptr>> terms; + }; +} + diff --git a/MbDCode/FunctionX.cpp b/MbDCode/FunctionX.cpp new file mode 100644 index 0000000..d59434a --- /dev/null +++ b/MbDCode/FunctionX.cpp @@ -0,0 +1 @@ +#include "FunctionX.h" diff --git a/MbDCode/FunctionX.h b/MbDCode/FunctionX.h new file mode 100644 index 0000000..239d397 --- /dev/null +++ b/MbDCode/FunctionX.h @@ -0,0 +1,10 @@ +#pragma once + +#include "Function.h" + +namespace MbD { + class FunctionX : public Function + { + }; +} + diff --git a/MbDCode/Joint.cpp b/MbDCode/Joint.cpp index b5dec90..e6ddd9e 100644 --- a/MbDCode/Joint.cpp +++ b/MbDCode/Joint.cpp @@ -14,10 +14,10 @@ Joint::Joint(const char* str) : Item(str) { void Joint::initialize() { - constraints = std::make_unique>>(); + constraints = std::make_shared>>(); } -void Joint::connectsItoJ(std::shared_ptr frmi, std::shared_ptr frmj) +void Joint::connectsItoJ(EndFrmcptr frmi, EndFrmcptr frmj) { frmI = frmi; frmJ = frmj; diff --git a/MbDCode/Joint.h b/MbDCode/Joint.h index e9fc217..f769805 100644 --- a/MbDCode/Joint.h +++ b/MbDCode/Joint.h @@ -2,13 +2,15 @@ #include #include +//#include "typedef.h" #include "Item.h" #include "EndFramec.h" #include "Constraint.h" namespace MbD { - class EndFramec; + //class EndFramec; class Constraint; + //using EndFrmcptr = std::shared_ptr; class Joint : public Item { @@ -17,13 +19,13 @@ namespace MbD { Joint(); Joint(const char* str); void initialize(); - virtual void connectsItoJ(std::shared_ptr frmI, std::shared_ptr frmJ); + virtual void connectsItoJ(EndFrmcptr frmI, EndFrmcptr frmJ); void initializeLocally() override; void initializeGlobally() override; - std::shared_ptr frmI; - std::shared_ptr frmJ; - std::unique_ptr>> constraints; + EndFrmcptr frmI; + EndFrmcptr frmJ; + std::shared_ptr>> constraints; }; } diff --git a/MbDCode/KinematicIeJe.cpp b/MbDCode/KinematicIeJe.cpp index 29f4d15..481ec42 100644 --- a/MbDCode/KinematicIeJe.cpp +++ b/MbDCode/KinematicIeJe.cpp @@ -6,6 +6,6 @@ MbD::KinematicIeJe::KinematicIeJe() { } -MbD::KinematicIeJe::KinematicIeJe(std::shared_ptr frmi, std::shared_ptr frmj) : frmI(frmi), frmJ(frmj) +MbD::KinematicIeJe::KinematicIeJe(EndFrmcptr frmi, EndFrmcptr frmj) : frmI(frmi), frmJ(frmj) { } diff --git a/MbDCode/KinematicIeJe.h b/MbDCode/KinematicIeJe.h index 0449b1b..6964104 100644 --- a/MbDCode/KinematicIeJe.h +++ b/MbDCode/KinematicIeJe.h @@ -1,5 +1,6 @@ #pragma once +//#include "typedef.h" #include "Item.h" #include "EndFramec.h" @@ -9,9 +10,9 @@ namespace MbD { //frmI frmJ public: KinematicIeJe(); - KinematicIeJe(std::shared_ptr frmi, std::shared_ptr frmj); + KinematicIeJe(EndFrmcptr frmi, EndFrmcptr frmj); - std::shared_ptr frmI, frmJ; + EndFrmcptr frmI, frmJ; }; } diff --git a/MbDCode/MarkerFrame.cpp b/MbDCode/MarkerFrame.cpp index 8d103fc..763aa69 100644 --- a/MbDCode/MarkerFrame.cpp +++ b/MbDCode/MarkerFrame.cpp @@ -19,12 +19,9 @@ MarkerFrame::MarkerFrame(const char* str) : CartesianFrame(str) { void MarkerFrame::initialize() { - //prOmOpE: = StMFullMatrix new : 3 by : 4. - //pAOmpE : = StMFullColumn new : 4. - //endFrames : = OrderedCollection new prOmOpE = std::make_shared>(3, 4); - pAOmpE = std::make_unique>>(4); - endFrames = std::make_unique>>(); + pAOmpE = std::make_shared>>>(4); + endFrames = std::make_shared>(); auto endFrm = std::make_shared("EndFrame1"); this->addEndFrame(endFrm); } @@ -47,7 +44,7 @@ void MarkerFrame::setaApm(FMatDsptr x) { aApm->copy(x); } -void MarkerFrame::addEndFrame(std::shared_ptr endFrm) +void MarkerFrame::addEndFrame(EndFrmcptr endFrm) { endFrm->setMarkerFrame(this); endFrames->push_back(endFrm); @@ -62,4 +59,5 @@ void MarkerFrame::initializeLocally() void MarkerFrame::initializeGlobally() { + std::for_each(endFrames->begin(), endFrames->end(), [](const auto& endFrame) { endFrame->initializeGlobally(); }); } diff --git a/MbDCode/MarkerFrame.h b/MbDCode/MarkerFrame.h index 6527d55..af22c4e 100644 --- a/MbDCode/MarkerFrame.h +++ b/MbDCode/MarkerFrame.h @@ -10,6 +10,7 @@ namespace MbD { class PartFrame; class EndFramec; + using EndFrmcptr = std::shared_ptr; class MarkerFrame : public CartesianFrame { @@ -22,7 +23,7 @@ namespace MbD { PartFrame* getPartFrame(); void setrpmp(FColDsptr x); void setaApm(FMatDsptr x); - void addEndFrame(std::shared_ptr x); + void addEndFrame(EndFrmcptr x); void initializeLocally() override; void initializeGlobally() override; @@ -32,10 +33,10 @@ namespace MbD { FColDsptr rOmO = std::make_shared>(3); FMatDsptr aAOm = std::make_shared>(3, 3); FMatDsptr prOmOpE; - std::unique_ptr>> pAOmpE; - std::unique_ptr>>> pprOmOpEpE; - FMatFMatDuptr ppAOmpEpE; - std::unique_ptr>> endFrames; + std::shared_ptr>>> pAOmpE; + std::shared_ptr>>> pprOmOpEpE; + FMatFMatDsptr ppAOmpEpE; + std::shared_ptr> endFrames; }; } diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index d9bff74..eaa6abe 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -6,6 +6,7 @@ #include #include "System.h" +#include "Constant.h" #include "FullColumn.h" #include "FullMatrix.h" #include "Part.h" @@ -14,6 +15,8 @@ #include "RevoluteJoint.h" #include "ZRotation.h" #include "EndFrameqc.h" +#include "EndFrameqct.h" +#include "Product.h" #include "MbDCode.h" using namespace MbD; @@ -21,7 +24,6 @@ using namespace MbD; int main() { std::cout << "Hello World!\n"; - //System& TheSystem = System::getInstance(); System& TheSystem = System::getInstance("TheSystem"); std::cout << "TheSystem.getName() " << TheSystem.getName() << std::endl; auto systemSolver = TheSystem.systemSolver; @@ -195,6 +197,9 @@ int main() auto rotMotion1 = std::make_shared("RotMotion1"); rotMotion1->connectsItoJ(assembly1->partFrame->endFrame("Marker2"), crankPart1->partFrame->endFrame("Marker1")); + auto omega = std::make_shared(6.2831853071796); + auto timeScale = std::make_shared(0.04); + rotMotion1->phiBlk = std::make_shared(omega, timeScale, TheSystem.time); TheSystem.jointsMotions->push_back(rotMotion1); // TheSystem.runKINEMATICS(); diff --git a/MbDCode/MbDCode.vcxproj b/MbDCode/MbDCode.vcxproj index ff40220..e90b03a 100644 --- a/MbDCode/MbDCode.vcxproj +++ b/MbDCode/MbDCode.vcxproj @@ -147,9 +147,13 @@ + + + + @@ -160,6 +164,7 @@ + @@ -167,6 +172,7 @@ + @@ -197,9 +203,13 @@ + + + + @@ -210,6 +220,7 @@ + @@ -217,10 +228,12 @@ + + diff --git a/MbDCode/MbDCode.vcxproj.filters b/MbDCode/MbDCode.vcxproj.filters index a092cda..e0b657c 100644 --- a/MbDCode/MbDCode.vcxproj.filters +++ b/MbDCode/MbDCode.vcxproj.filters @@ -159,6 +159,24 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -305,5 +323,26 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/MbDCode/NewtonRaphson.h b/MbDCode/NewtonRaphson.h index e6b411a..e1402fc 100644 --- a/MbDCode/NewtonRaphson.h +++ b/MbDCode/NewtonRaphson.h @@ -1,8 +1,18 @@ #pragma once + +#include + #include "Solver.h" + +#include "FullColumn.h" + namespace MbD { class NewtonRaphson : public Solver { + //system xold x dx dxNorm dxNorms dxTol y yNorm yNormOld yNorms yNormTol pypx iterNo iterMax nDivergence nBackTracking twoAlp lam + public: + std::shared_ptr> xold, x, dx, dxTol, y; + double dxNorm, yNorm, yNormOld, yNormTol, twoAlp, lam; }; } diff --git a/MbDCode/Part.cpp b/MbDCode/Part.cpp index 6dec654..3c409b4 100644 --- a/MbDCode/Part.cpp +++ b/MbDCode/Part.cpp @@ -54,4 +54,5 @@ void Part::initializeLocally() void Part::initializeGlobally() { + partFrame->initializeGlobally(); } diff --git a/MbDCode/Part.h b/MbDCode/Part.h index bda1563..d02a199 100644 --- a/MbDCode/Part.h +++ b/MbDCode/Part.h @@ -30,14 +30,14 @@ namespace MbD { int ipX; int ipE; double m; - std::unique_ptr> aJ; + std::shared_ptr> aJ; std::shared_ptr partFrame; FColDsptr pX; FColDsptr pXdot; FColDsptr pE; FColDsptr pEdot; - std::unique_ptr> mX; - std::unique_ptr> mE; + std::shared_ptr> mX; + std::shared_ptr> mE; FMatDsptr mEdot; FColDsptr pTpE; FMatDsptr ppTpEpE; diff --git a/MbDCode/PartFrame.cpp b/MbDCode/PartFrame.cpp index 2e607c8..950d2b1 100644 --- a/MbDCode/PartFrame.cpp +++ b/MbDCode/PartFrame.cpp @@ -20,8 +20,8 @@ void PartFrame::initialize() { aGeu = std::make_shared("EulerCon"); aGeu->setOwner(this); - aGabs = std::make_unique>>(); - markerFrames = std::make_unique>>(); + aGabs = std::make_shared>>(); + markerFrames = std::make_shared>>(); } void PartFrame::setqX(FColDsptr x) { qX->copy(x); @@ -48,7 +48,7 @@ void PartFrame::addMarkerFrame(std::shared_ptr markerFrame) markerFrames->push_back(markerFrame); } -std::shared_ptr PartFrame::endFrame(std::string name) +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); @@ -72,4 +72,7 @@ void PartFrame::initializeLocally() void PartFrame::initializeGlobally() { + std::for_each(markerFrames->begin(), markerFrames->end(), [](const auto& markerFrame) { markerFrame->initializeGlobally(); }); + aGeu->initializeGlobally(); + std::for_each(aGabs->begin(), aGabs->end(), [](const auto& aGab) { aGab->initializeGlobally(); }); } diff --git a/MbDCode/PartFrame.h b/MbDCode/PartFrame.h index dc9bbd1..4008c58 100644 --- a/MbDCode/PartFrame.h +++ b/MbDCode/PartFrame.h @@ -14,6 +14,7 @@ namespace MbD { class Part; class MarkerFrame; class EndFramec; + using EndFrmcptr = std::shared_ptr; class PartFrame : public CartesianFrame { @@ -33,7 +34,7 @@ namespace MbD { void setPart(Part* x); Part* getPart(); void addMarkerFrame(std::shared_ptr x); - std::shared_ptr endFrame(std::string name); + EndFrmcptr endFrame(std::string name); Part* part; int iqX, iqE; //Position index of frame variables qX and qE in system list of variables @@ -44,8 +45,8 @@ namespace MbD { FColDsptr qXddot = std::make_shared>(3); FColDsptr qEddot = std::make_shared>(4); std::shared_ptr aGeu; - std::unique_ptr>> aGabs; - std::unique_ptr>> markerFrames; + std::shared_ptr>> aGabs; + std::shared_ptr>> markerFrames; }; } diff --git a/MbDCode/PrescribedMotion.cpp b/MbDCode/PrescribedMotion.cpp index fd11349..c06fb98 100644 --- a/MbDCode/PrescribedMotion.cpp +++ b/MbDCode/PrescribedMotion.cpp @@ -27,28 +27,8 @@ void PrescribedMotion::initialize() psiBlk = std::make_shared(0.0); } -void PrescribedMotion::connectsItoJ(std::shared_ptr frmi, std::shared_ptr frmj) +void PrescribedMotion::connectsItoJ(EndFrmcptr frmi, EndFrmcptr frmj) { Joint::connectsItoJ(frmi, frmj); frmI->EndFrameqctFrom(frmI); } - -//void PrescribedMotion::connectsItoJ(std::shared_ptr frmi, std::shared_ptr frmj) -//{ -// Joint::connectsItoJ(frmi, frmj); -// frmI->EndFrameqctFrom(frmI); -// decltype(frmi) dddd; -// std::cout << "typeid(dddd).name() " << typeid(dddd).name() << std::endl; -// std::cout << "typeid(frmI).name() " << typeid(frmI).name() << std::endl; -// if (typeid(frmI).name() != "EndFrameqct") { -// std::shared_ptr newFrmI; -// newFrmI = std::make_shared(frmI->getName().c_str()); -// decltype(newFrmI) ffff; -// std::cout << "typeid(ffff).name() " << typeid(ffff).name() << std::endl; -// auto gggg = std::make_shared(frmI->getName().c_str()); -// std::cout << "typeid(gggg).name() " << typeid(gggg).name() << std::endl; -// std::cout << "typeid(newFrmI).name() " << typeid(newFrmI).name() << std::endl; -// std::swap(frmI, newFrmI); -// assert(typeid(frmI).name() != "EndFrameqct"); -// } -//} diff --git a/MbDCode/PrescribedMotion.h b/MbDCode/PrescribedMotion.h index 301955d..6236c96 100644 --- a/MbDCode/PrescribedMotion.h +++ b/MbDCode/PrescribedMotion.h @@ -2,6 +2,9 @@ #include "Joint.h" namespace MbD { + + class Symbolic; + class PrescribedMotion : public Joint { //xBlk yBlk zBlk phiBlk theBlk psiBlk @@ -9,14 +12,14 @@ namespace MbD { PrescribedMotion(); PrescribedMotion(const char* str); void initialize(); - void connectsItoJ(std::shared_ptr frmI, std::shared_ptr frmJ) override; + void connectsItoJ(EndFrmcptr frmI, EndFrmcptr frmJ) override; - std::shared_ptr xBlk; - std::shared_ptr yBlk; - std::shared_ptr zBlk; - std::shared_ptr phiBlk; - std::shared_ptr theBlk; - std::shared_ptr psiBlk; + std::shared_ptr xBlk; + std::shared_ptr yBlk; + std::shared_ptr zBlk; + std::shared_ptr phiBlk; + std::shared_ptr theBlk; + std::shared_ptr psiBlk; }; } diff --git a/MbDCode/Product.cpp b/MbDCode/Product.cpp new file mode 100644 index 0000000..149c119 --- /dev/null +++ b/MbDCode/Product.cpp @@ -0,0 +1,10 @@ +#include "Product.h" + +using namespace MbD; + +double MbD::Product::getValue() +{ + double answer = 1.0; + for (int i = 0; i < terms->size(); i++) answer *= terms->at(i)->getValue(); + return answer; +} diff --git a/MbDCode/Product.h b/MbDCode/Product.h new file mode 100644 index 0000000..2b9ca7a --- /dev/null +++ b/MbDCode/Product.h @@ -0,0 +1,16 @@ +#pragma once + +#include "FunctionWithManyArgs.h" + +namespace MbD { + class Product : public FunctionWithManyArgs + { + public: + Product(std::shared_ptr term) : FunctionWithManyArgs(term) {} + Product(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term, term1) {} + Product(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1, term2) {} + Product(std::shared_ptr>> _terms) : FunctionWithManyArgs(_terms) {} + double getValue() override; + }; +} + diff --git a/MbDCode/RowTypeMatrix.h b/MbDCode/RowTypeMatrix.h index c3cf077..39b8598 100644 --- a/MbDCode/RowTypeMatrix.h +++ b/MbDCode/RowTypeMatrix.h @@ -1,6 +1,10 @@ #pragma once + #include "Array.h" +#include "FullRow.h" + namespace MbD { + template class RowTypeMatrix : public Array { @@ -8,6 +12,7 @@ namespace MbD { RowTypeMatrix() {} RowTypeMatrix(std::initializer_list list) : Array{ list } {} void copy(std::shared_ptr> x); + void zeroSelf(); }; template @@ -17,5 +22,11 @@ namespace MbD { this->at(i)->copy(x->at(i)); } } + template <> + inline void RowTypeMatrix< std::shared_ptr>>::zeroSelf() { + for (int i = 0; i < this->size(); i++) { + this->at(i)->zeroSelf(); + } + } } diff --git a/MbDCode/SparseMatrix.h b/MbDCode/SparseMatrix.h index 017a6d9..bffe854 100644 --- a/MbDCode/SparseMatrix.h +++ b/MbDCode/SparseMatrix.h @@ -15,8 +15,5 @@ namespace MbD { } } }; - typedef std::shared_ptr> SpMatDptr; - typedef std::initializer_list>> ListListPairD; -} - - + using SpMatDptr = std::shared_ptr>; +} \ No newline at end of file diff --git a/MbDCode/SparseRow.h b/MbDCode/SparseRow.h index 3d7e0f8..4a632de 100644 --- a/MbDCode/SparseRow.h +++ b/MbDCode/SparseRow.h @@ -13,6 +13,6 @@ namespace MbD { SparseRow(std::initializer_list> list) : SparseVector{ list } {} SparseRow(std::initializer_list> list) : SparseVector{ list } {} }; - typedef std::shared_ptr> SpRowDptr; + using SpRowDptr = std::shared_ptr>; } diff --git a/MbDCode/Sum.cpp b/MbDCode/Sum.cpp new file mode 100644 index 0000000..b39a51f --- /dev/null +++ b/MbDCode/Sum.cpp @@ -0,0 +1,10 @@ +#include "Sum.h" + +using namespace MbD; + +double MbD::Sum::getValue() +{ + double answer = 0.0; + for (int i = 0; i < terms->size(); i++) answer += terms->at(i)->getValue(); + return answer; +} diff --git a/MbDCode/Sum.h b/MbDCode/Sum.h new file mode 100644 index 0000000..3ce07f4 --- /dev/null +++ b/MbDCode/Sum.h @@ -0,0 +1,16 @@ +#pragma once + +#include "FunctionWithManyArgs.h" + +namespace MbD { + class Sum : public FunctionWithManyArgs + { + public: + Sum(std::shared_ptr term) : FunctionWithManyArgs(term) {} + Sum(std::shared_ptr term, std::shared_ptr term1) : FunctionWithManyArgs(term, term1) {} + Sum(std::shared_ptr term, std::shared_ptr term1, std::shared_ptr term2) : FunctionWithManyArgs(term, term1, term2) {} + Sum(std::shared_ptr>> _terms) : FunctionWithManyArgs(_terms) {} + double getValue() override; + }; +} + diff --git a/MbDCode/Symbolic.cpp b/MbDCode/Symbolic.cpp index 50e6dca..fc72fa9 100644 --- a/MbDCode/Symbolic.cpp +++ b/MbDCode/Symbolic.cpp @@ -1,4 +1,9 @@ +#include +#include +#include + #include "Symbolic.h" +#include "Constant.h" using namespace MbD; @@ -10,3 +15,28 @@ Symbolic::Symbolic() void Symbolic::initialize() { } + +std::shared_ptr MbD::Symbolic::differentiateWRT(std::shared_ptr var) +{ + return std::shared_ptr(); +} + +std::shared_ptr MbD::Symbolic::simplified() +{ + //Debug + auto set = nullptr; + //Debug auto set = std::make_shared>(); + auto answer = expandUntil(set); + auto set1 = nullptr; //std::make_shared>(); + return answer->simplifyUntil(set1); +} + +std::shared_ptr MbD::Symbolic::expandUntil(std::shared_ptr> set) +{ + return std::make_shared(0.0); +} + +std::shared_ptr MbD::Symbolic::simplifyUntil(std::shared_ptr> set) +{ + return std::make_shared(0.0); +} diff --git a/MbDCode/Symbolic.h b/MbDCode/Symbolic.h index 981e451..f48b118 100644 --- a/MbDCode/Symbolic.h +++ b/MbDCode/Symbolic.h @@ -1,10 +1,20 @@ #pragma once + +#include +#include + namespace MbD { + class Symbolic { public: Symbolic(); void initialize(); + virtual std::shared_ptr differentiateWRT(std::shared_ptr var); + virtual std::shared_ptr simplified(); + virtual std::shared_ptr expandUntil(std::shared_ptr> set); + virtual std::shared_ptr simplifyUntil(std::shared_ptr> set); + virtual double getValue() = 0; }; } diff --git a/MbDCode/System.cpp b/MbDCode/System.cpp index db9f578..423d2b3 100644 --- a/MbDCode/System.cpp +++ b/MbDCode/System.cpp @@ -5,17 +5,17 @@ using namespace MbD; System::System() { - time = std::make_unique