From fa2deac10f23afaeb0a9085295163a73d9b6fa7f Mon Sep 17 00:00:00 2001 From: John Dupuy Date: Wed, 27 Sep 2023 15:13:22 -0500 Subject: [PATCH] changes to class detection --- MbDCode/ASMTAssembly.cpp | 7 +++++-- MbDCode/ASMTAssembly.h | 2 +- MbDCode/CMakeLists.txt | 1 + MbDCode/CREATE.h | 8 ++++---- MbDCode/GESpMatFullPv.cpp | 6 ++++++ MbDCode/MbDCode.cpp | 18 +++++++++--------- MbDCode/PosICNewtonRaphson.cpp | 4 ++-- MbDCode/SystemNewtonRaphson.cpp | 4 ++-- MbDCode/VelSolver.cpp | 4 ++-- MbDCode/corecrt_math_defines.h | 20 ++++++++++---------- 10 files changed, 42 insertions(+), 32 deletions(-) diff --git a/MbDCode/ASMTAssembly.cpp b/MbDCode/ASMTAssembly.cpp index af20a84..39418bc 100644 --- a/MbDCode/ASMTAssembly.cpp +++ b/MbDCode/ASMTAssembly.cpp @@ -30,9 +30,12 @@ using namespace MbD; -void MbD::ASMTAssembly::runFile(const char* chars) +void MbD::ASMTAssembly::runFile(const char* fileName) { - std::ifstream stream(chars); + std::ifstream stream(fileName); + if(stream.fail()) { + throw std::invalid_argument("File not found."); + } std::string line; std::vector lines; while (std::getline(stream, line)) { diff --git a/MbDCode/ASMTAssembly.h b/MbDCode/ASMTAssembly.h index e7bba63..219d4ef 100644 --- a/MbDCode/ASMTAssembly.h +++ b/MbDCode/ASMTAssembly.h @@ -33,7 +33,7 @@ namespace MbD { { // public: - static void runFile(const char* chars); + static void runFile(const char* fileName); ASMTAssembly* root() override; void parseASMT(std::vector& lines) override; void readNotes(std::vector& lines); diff --git a/MbDCode/CMakeLists.txt b/MbDCode/CMakeLists.txt index 6387398..c6bb15f 100644 --- a/MbDCode/CMakeLists.txt +++ b/MbDCode/CMakeLists.txt @@ -268,6 +268,7 @@ add_executable(new_target VelSolver.cpp ZRotation.cpp ZTranslation.cpp + ASMTAssembly.cpp ) diff --git a/MbDCode/CREATE.h b/MbDCode/CREATE.h index 8afb8a3..6d49f98 100644 --- a/MbDCode/CREATE.h +++ b/MbDCode/CREATE.h @@ -71,15 +71,15 @@ namespace MbD { static std::shared_ptr ConstraintWith(std::shared_ptr frmi, std::shared_ptr frmj, int axis) { std::shared_ptr inst; std::string str = typeid(T(frmi, frmj, axis)).name(); - if (str == "class MbD::AtPointConstraintIJ") { + if (str.find("AtPointConstraintIJ") >= 0) { if (std::dynamic_pointer_cast(frmi)) { inst = std::make_shared(frmi, frmj, axis); } else { inst = std::make_shared(frmi, frmj, axis); } - } - else if(str == "class MbD::TranslationConstraintIJ") { + } // "class MbD::Tran + else if(str.find("TranslationConstraintIJ") >= 0) { if (std::dynamic_pointer_cast(frmi)) { inst = std::make_shared(frmi, frmj, axis); } @@ -98,7 +98,7 @@ namespace MbD { static std::shared_ptr ConstraintWith(std::shared_ptr frmi, std::shared_ptr frmj, int axisi, int axisj) { std::shared_ptr inst; std::string str = typeid(T(frmi, frmj, axisi, axisj)).name(); - if (str == "class MbD::DirectionCosineConstraintIJ") { + if (str.find("DirectionCosineConstraintIJ") >= 0) { if (std::dynamic_pointer_cast(frmi)) { inst = std::make_shared(frmi, frmj, axisi, axisj); } diff --git a/MbDCode/GESpMatFullPv.cpp b/MbDCode/GESpMatFullPv.cpp index dc81fda..ff30ba3 100644 --- a/MbDCode/GESpMatFullPv.cpp +++ b/MbDCode/GESpMatFullPv.cpp @@ -108,6 +108,12 @@ void GESpMatFullPv::backSubstituteIntoDU() double sum, duij, duii; //answerX = rightHandSideB->copyEmpty(); assert(m == n); + + // TODO: temp +// assert(n > 0); +// auto localLen = colOrder->numberOfElements(); +// assert(n < localLen); + answerX = std::make_shared>(m); auto jn = colOrder->at(n); answerX->at(jn) = rightHandSideB->at(m) / matrixA->at(m)->at(jn); diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index 52212fe..3a3bd97 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -26,17 +26,17 @@ void runSpMat(); int main() { - ASMTAssembly::runFile("piston.asmt"); - ASMTAssembly::runFile("00backhoe.asmt"); - ASMTAssembly::runFile("circular.asmt"); - ASMTAssembly::runFile("cirpendu.asmt"); //Under constrained. Testing ICKine. - ASMTAssembly::runFile("engine1.asmt"); - ASMTAssembly::runFile("fourbar.asmt"); - ASMTAssembly::runFile("fourbot.asmt"); - ASMTAssembly::runFile("wobpump.asmt"); +// ASMTAssembly::runFile("piston.asmt"); +// ASMTAssembly::runFile("00backhoe.asmt"); +// ASMTAssembly::runFile("circular.asmt"); +// ASMTAssembly::runFile("cirpendu.asmt"); //Under constrained. Testing ICKine. +// ASMTAssembly::runFile("engine1.asmt"); +// ASMTAssembly::runFile("fourbar.asmt"); +// ASMTAssembly::runFile("fourbot.asmt"); +// ASMTAssembly::runFile("wobpump.asmt"); auto cadSystem = std::make_shared(); - cadSystem->runOndselPiston(); + // cadSystem->runOndselPiston(); cadSystem->runPiston(); runSpMat(); } diff --git a/MbDCode/PosICNewtonRaphson.cpp b/MbDCode/PosICNewtonRaphson.cpp index 1f84e4a..f8b86f6 100644 --- a/MbDCode/PosICNewtonRaphson.cpp +++ b/MbDCode/PosICNewtonRaphson.cpp @@ -103,13 +103,13 @@ void PosICNewtonRaphson::handleSingularMatrix() } else { std::string str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvMarkoFast") { + if (str.find("GESpMatParPvMarkoFast") >= 0) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvPrecise") { + if (str.find("GESpMatParPvPrecise") >= 0) { this->lookForRedundantConstraints(); matrixSolver = this->matrixSolverClassNew(); } diff --git a/MbDCode/SystemNewtonRaphson.cpp b/MbDCode/SystemNewtonRaphson.cpp index 47d813a..b05aa63 100644 --- a/MbDCode/SystemNewtonRaphson.cpp +++ b/MbDCode/SystemNewtonRaphson.cpp @@ -52,13 +52,13 @@ void SystemNewtonRaphson::basicSolveEquations() void SystemNewtonRaphson::handleSingularMatrix() { std::string str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvMarkoFast") { + if (str.find("GESpMatParPvMarkoFast") >= 0) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvPrecise") { + if (str.find("GESpMatParPvPrecise") >= 0) { str = "MbD: Singular Matrix Error. "; system->logString(str); matrixSolver = this->matrixSolverClassNew(); diff --git a/MbDCode/VelSolver.cpp b/MbDCode/VelSolver.cpp index b4be203..d22fe6c 100644 --- a/MbDCode/VelSolver.cpp +++ b/MbDCode/VelSolver.cpp @@ -25,13 +25,13 @@ void VelSolver::basicSolveEquations() void VelSolver::handleSingularMatrix() { std::string str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvMarkoFast") { + if (str.find("GESpMatParPvMarkoFast") >= 0) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str == "class GESpMatParPvPrecise") { + if (str.find("GESpMatParPvPrecise") >= 0) { this->logSingularMatrixMessage(); matrixSolver = this->matrixSolverClassNew(); } diff --git a/MbDCode/corecrt_math_defines.h b/MbDCode/corecrt_math_defines.h index 0d46d29..d8c0560 100644 --- a/MbDCode/corecrt_math_defines.h +++ b/MbDCode/corecrt_math_defines.h @@ -14,17 +14,17 @@ // Define _USE_MATH_DEFINES before including to expose these macro // definitions for common math constants. These are placed under an #ifdef // since these commonly-defined names are not part of the C or C++ standards -#define M_E 2.71828182845904523536 // e -#define M_LOG2E 1.44269504088896340736 // log2(e) -#define M_LOG10E 0.434294481903251827651 // log10(e) -#define M_LN2 0.693147180559945309417 // ln(2) -#define M_LN10 2.30258509299404568402 // ln(10) +// #define M_E 2.71828182845904523536 // e +// #define M_LOG2E 1.44269504088896340736 // log2(e) +// #define M_LOG10E 0.434294481903251827651 // log10(e) +// #define M_LN2 0.693147180559945309417 // ln(2) +// #define M_LN10 2.30258509299404568402 // ln(10) #define M_PI 3.14159265358979323846 // pi -#define M_PI_2 1.57079632679489661923 // pi/2 -#define M_PI_4 0.785398163397448309616 // pi/4 -#define M_1_PI 0.318309886183790671538 // 1/pi -#define M_2_PI 0.636619772367581343076 // 2/pi +// #define M_PI_2 1.57079632679489661923 // pi/2 +// #define M_PI_4 0.785398163397448309616 // pi/4 +// #define M_1_PI 0.318309886183790671538 // 1/pi +// #define M_2_PI 0.636619772367581343076 // 2/pi #define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) #define M_SQRT2 1.41421356237309504880 // sqrt(2) -#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) +// #define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) #endif \ No newline at end of file