From 4b3d676f30ee697f40104314213a051d1bbbd42d Mon Sep 17 00:00:00 2001 From: John Dupuy Date: Tue, 26 Sep 2023 11:49:32 -0500 Subject: [PATCH 1/4] first stages for making more universal --- .gitignore | 5 +- CMakeLists.txt | 9 + MbDCode/AngleZIecJec.cpp | 2 +- MbDCode/Array.h | 2 +- MbDCode/CMakeLists.txt | 273 ++++++++++++++++++++++++++++++ MbDCode/FullColumn.h | 2 +- MbDCode/FullMatrix.h | 16 +- MbDCode/FullRow.h | 2 +- MbDCode/FullVector.h | 3 +- MbDCode/GearConstraintIJ.h | 2 +- MbDCode/GearConstraintIqcJc.cpp | 2 +- MbDCode/GearConstraintIqcJqc.cpp | 2 +- MbDCode/Item.cpp | 4 +- MbDCode/Numeric.cpp | 2 +- MbDCode/OrbitAnglezIecJec.cpp | 4 +- MbDCode/OrbitAnglezIeqcJec.cpp | 2 +- MbDCode/OrbitAnglezIeqcJec.h | 2 +- MbDCode/OrbitAnglezIeqcJeqc.cpp | 2 +- MbDCode/OrbitAnglezIeqcJeqc.h | 2 +- MbDCode/ScrewConstraintIJ.cpp | 2 +- MbDCode/ScrewConstraintIqcJc.cpp | 2 +- MbDCode/ScrewConstraintIqcJqc.cpp | 2 +- MbDCode/SymbolicParser.cpp | 2 +- MbDCode/corecrt_math_defines.h | 30 ++++ 24 files changed, 346 insertions(+), 30 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 MbDCode/CMakeLists.txt create mode 100644 MbDCode/corecrt_math_defines.h diff --git a/.gitignore b/.gitignore index 774534a..6ead354 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ .vs x64/ -*.bak \ No newline at end of file +*.bak + +cmake-build-debug +.idea diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cec7723 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.10) + +project(MbDCodeLib) + +add_executable(MbDCode MbDCode/MbDCode.cpp) +add_subdirectory(MbDCode) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) diff --git a/MbDCode/AngleZIecJec.cpp b/MbDCode/AngleZIecJec.cpp index 443d225..dbaa8fd 100644 --- a/MbDCode/AngleZIecJec.cpp +++ b/MbDCode/AngleZIecJec.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" #include "AngleZIecJec.h" #include "Numeric.h" diff --git a/MbDCode/Array.h b/MbDCode/Array.h index b654812..db8e407 100644 --- a/MbDCode/Array.h +++ b/MbDCode/Array.h @@ -29,7 +29,7 @@ namespace MbD { Array(std::vector vec) : std::vector(vec) {} Array(int count) : std::vector(count) {} Array(int count, const T& value) : std::vector(count, value) {} - Array(std::vector::iterator begin, std::vector::iterator end) : std::vector(begin, end) {} + Array(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : std::vector(begin, end) {} Array(std::initializer_list list) : std::vector{ list } {} virtual void initialize(); void copyFrom(std::shared_ptr> x); diff --git a/MbDCode/CMakeLists.txt b/MbDCode/CMakeLists.txt new file mode 100644 index 0000000..6387398 --- /dev/null +++ b/MbDCode/CMakeLists.txt @@ -0,0 +1,273 @@ +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +add_executable(new_target + MbDCode.cpp + Abs.cpp + AbsConstraint.cpp + AccICKineNewtonRaphson.cpp + AccICNewtonRaphson.cpp + AccKineNewtonRaphson.cpp + AccNewtonRaphson.cpp + AngleJoint.cpp + AngleZIecJec.cpp + AngleZIeqcJec.cpp + AngleZIeqcJeqc.cpp + AnyGeneralSpline.cpp + AnyPosICNewtonRaphson.cpp + ArcTan.cpp + ArcTan2.cpp + Array.cpp + ASMTAnimationParameters.cpp + ASMTAssembly.cpp + ASMTConstantGravity.cpp + ASMTConstraintSet.cpp + ASMTCylindricalJoint.cpp + ASMTExtrusion.cpp + ASMTFixedJoint.cpp + ASMTForceTorque.cpp + ASMTGeneralMotion.cpp + ASMTItem.cpp + ASMTItemIJ.cpp + ASMTJoint.cpp + ASMTKinematicIJ.cpp + ASMTMarker.cpp + ASMTMotion.cpp + ASMTPart.cpp + ASMTPointInPlaneJoint.cpp + ASMTPrincipalMassMarker.cpp + ASMTRefCurve.cpp + ASMTRefItem.cpp + ASMTRefPoint.cpp + ASMTRefSurface.cpp + ASMTRevoluteJoint.cpp + ASMTRotationalMotion.cpp + ASMTSimulationParameters.cpp + ASMTSpatialContainer.cpp + ASMTSpatialItem.cpp + ASMTSphericalJoint.cpp + ASMTTime.cpp + ASMTTranslationalMotion.cpp + ASMTTranslationalJoint.cpp + ASMTUniversalJoint.cpp + AtPointConstraintIJ.cpp + AtPointConstraintIqcJc.cpp + AtPointConstraintIqcJqc.cpp + AtPointConstraintIqctJqc.cpp + AtPointJoint.cpp + BasicIntegrator.cpp + BasicQuasiIntegrator.cpp + BasicUserFunction.cpp + CADSystem.cpp + CartesianFrame.cpp + CompoundJoint.cpp + Constant.cpp + ConstantGravity.cpp + ConstantVelocityJoint.cpp + Constraint.cpp + ConstraintIJ.cpp + ConstVelConstraintIJ.cpp + ConstVelConstraintIqcJc.cpp + ConstVelConstraintIqcJqc.cpp + Cosine.cpp + CREATE.cpp + CylindricalJoint.cpp + CylSphJoint.cpp + DifferentiatedGeneralSpline.cpp + EndFrameqct2.cpp + EulerAngles.cpp + EulerAnglesDDot.cpp + EulerAnglesDot.cpp + Exponential.cpp + ExternalSystem.cpp + FunctionFromData.cpp + FunctionXcParameter.cpp + FunctionXY.cpp + GeneralSpline.cpp + Ln.cpp + Log10.cpp + LogN.cpp + Negative.cpp + PosVelAccData.cpp + DiagonalMatrix.cpp + DifferenceOperator.cpp + DirectionCosineConstraintIJ.cpp + DirectionCosineConstraintIqcJc.cpp + DirectionCosineConstraintIqcJqc.cpp + DirectionCosineConstraintIqctJqc.cpp + DirectionCosineIecJec.cpp + DirectionCosineIeqcJec.cpp + DirectionCosineIeqcJeqc.cpp + DirectionCosineIeqctJeqc.cpp + DiscontinuityError.cpp + DispCompIecJecIe.cpp + DispCompIecJecKec.cpp + DispCompIecJecKeqc.cpp + DispCompIecJecO.cpp + DispCompIeqcJecIe.cpp + DispCompIeqcJecKeqc.cpp + DispCompIeqcJecO.cpp + DispCompIeqcJeqcIe.cpp + DispCompIeqcJeqcKeqc.cpp + DispCompIeqcJeqcKeqct.cpp + DispCompIeqcJeqcO.cpp + DispCompIeqctJeqcIe.cpp + DispCompIeqctJeqcKeqct.cpp + DispCompIeqctJeqcO.cpp + DistanceConstraintIJ.cpp + DistanceConstraintIqcJc.cpp + DistanceConstraintIqcJqc.cpp + DistanceConstraintIqctJqc.cpp + DistancexyConstraintIJ.cpp + DistancexyConstraintIqcJc.cpp + DistancexyConstraintIqcJqc.cpp + DistIecJec.cpp + DistIeqcJec.cpp + DistIeqcJeqc.cpp + DistIeqctJeqc.cpp + DistxyIecJec.cpp + DistxyIeqcJec.cpp + DistxyIeqcJeqc.cpp + DistxyIeqctJeqc.cpp + EndFramec.cpp + EndFrameqc.cpp + EndFrameqct.cpp + EulerAngleszxz.cpp + EulerAngleszxzDDot.cpp + EulerAngleszxzDot.cpp + EulerArray.cpp + EulerConstraint.cpp + EulerParameters.cpp + EulerParametersDDot.cpp + EulerParametersDot.cpp + ExpressionX.cpp + FixedJoint.cpp + ForceTorqueData.cpp + ForceTorqueItem.cpp + FullColumn.cpp + FullMatrix.cpp + FullMotion.cpp + FullRow.cpp + Function.cpp + FunctionWithManyArgs.cpp + FunctionX.cpp + GearConstraintIJ.cpp + GearConstraintIqcJc.cpp + GearConstraintIqcJqc.cpp + GearJoint.cpp + GEFullMat.cpp + GEFullMatFullPv.cpp + GEFullMatParPv.cpp + GESpMat.cpp + GESpMatFullPv.cpp + GESpMatFullPvPosIC.cpp + GESpMatParPv.cpp + GESpMatParPvMarko.cpp + GESpMatParPvMarkoFast.cpp + GESpMatParPvPrecise.cpp + ICKineIntegrator.cpp + IndependentVariable.cpp + InLineJoint.cpp + InPlaneJoint.cpp + Integrator.cpp + IntegratorInterface.cpp + Item.cpp + Joint.cpp + KineIntegrator.cpp + KinematicIeJe.cpp + LDUFullMatParPv.cpp + LDUSpMat.cpp + LDUSpMatParPv.cpp + LDUSpMatParPvMarko.cpp + LDUSpMatParPvPrecise.cpp + LinearMultiStepMethod.cpp + LineInPlaneJoint.cpp + MarkerFrame.cpp + Math.cpp + MatrixDecomposition.cpp + MatrixGaussElimination.cpp + MatrixLDU.cpp + MatrixSolver.cpp + MaximumIterationError.cpp + NewtonRaphson.cpp + NewtonRaphsonError.cpp + NoRotationJoint.cpp + NotKinematicError.cpp + Numeric.cpp + OrbitAnglezIecJec.cpp + OrbitAnglezIeqcJec.cpp + OrbitAnglezIeqcJeqc.cpp + Orientation.cpp + ParallelAxesJoint.cpp + Part.cpp + PartFrame.cpp + PerpendicularJoint.cpp + PlanarJoint.cpp + PointInLineJoint.cpp + PointInPlaneJoint.cpp + PosICKineNewtonRaphson.cpp + PosICNewtonRaphson.cpp + PosKineNewtonRaphson.cpp + PosNewtonRaphson.cpp + Power.cpp + PrescribedMotion.cpp + Product.cpp + QuasiIntegrator.cpp + RackPinConstraintIJ.cpp + RackPinConstraintIqcJc.cpp + RackPinConstraintIqcJqc.cpp + RackPinJoint.cpp + Reciprocal.cpp + RedundantConstraint.cpp + RevCylJoint.cpp + RevoluteJoint.cpp + RowTypeMatrix.cpp + ScalarNewtonRaphson.cpp + ScrewConstraintIJ.cpp + ScrewConstraintIqcJc.cpp + ScrewConstraintIqcJqc.cpp + ScrewJoint.cpp + SimulationStoppingError.cpp + Sine.cpp + SingularMatrixError.cpp + Solver.cpp + SparseColumn.cpp + SparseMatrix.cpp + SparseRow.cpp + SparseVector.cpp + SphericalJoint.cpp + SphSphJoint.cpp + StableBackwardDifference.cpp + LDUFullMat.cpp + StateData.cpp + Sum.cpp + Symbolic.cpp + SymbolicParser.cpp + SyntaxError.cpp + System.cpp + SystemNewtonRaphson.cpp + SystemSolver.cpp + Time.cpp + TooManyTriesError.cpp + TooSmallStepSizeError.cpp + Translation.cpp + TranslationalJoint.cpp + TranslationConstraintIJ.cpp + TranslationConstraintIqcJc.cpp + TranslationConstraintIqcJqc.cpp + TranslationConstraintIqctJqc.cpp + Units.cpp + UniversalJoint.cpp + UserFunction.cpp + Variable.cpp + FullVector.cpp + VectorNewtonRaphson.cpp + VelICKineSolver.cpp + VelICSolver.cpp + VelKineSolver.cpp + VelSolver.cpp + ZRotation.cpp + ZTranslation.cpp +) + + diff --git a/MbDCode/FullColumn.h b/MbDCode/FullColumn.h index e9dcb36..34b0318 100644 --- a/MbDCode/FullColumn.h +++ b/MbDCode/FullColumn.h @@ -33,7 +33,7 @@ namespace MbD { FullColumn(std::vector vec) : FullVector(vec) {} FullColumn(int count) : FullVector(count) {} FullColumn(int count, const T& value) : FullVector(count, value) {} - FullColumn(std::vector::iterator begin, std::vector::iterator end) : FullVector(begin, end) {} + FullColumn(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : FullVector(begin, end) {} FullColumn(std::initializer_list list) : FullVector{ list } {} FColsptr plusFullColumn(FColsptr fullCol); FColsptr minusFullColumn(FColsptr fullCol); diff --git a/MbDCode/FullMatrix.h b/MbDCode/FullMatrix.h index fd792a7..0b2817e 100644 --- a/MbDCode/FullMatrix.h +++ b/MbDCode/FullMatrix.h @@ -8,7 +8,7 @@ #pragma once -#include +#include "corecrt_math_defines.h" #include #include "RowTypeMatrix.h" @@ -296,6 +296,13 @@ namespace MbD { row2->atiput(2, 0.0); return rotMat; } + template<> + inline void FullMatrix::zeroSelf() + { + for (int i = 0; i < this->size(); i++) { + this->at(i)->zeroSelf(); + } + } template<> inline void FullMatrix::identity() { this->zeroSelf(); @@ -452,13 +459,6 @@ namespace MbD { assert(false); return 0.0; } - template<> - inline void FullMatrix::zeroSelf() - { - for (int i = 0; i < this->size(); i++) { - this->at(i)->zeroSelf(); - } - } template inline void FullMatrix::zeroSelf() { diff --git a/MbDCode/FullRow.h b/MbDCode/FullRow.h index 8ea5619..b4df0bd 100644 --- a/MbDCode/FullRow.h +++ b/MbDCode/FullRow.h @@ -35,7 +35,7 @@ namespace MbD { FullRow(std::vector vec) : FullVector(vec) {} FullRow(int count) : FullVector(count) {} FullRow(int count, const T& value) : FullVector(count, value) {} - FullRow(std::vector::iterator begin, std::vector::iterator end) : FullVector(begin, end) {} + FullRow(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : FullVector(begin, end) {} FullRow(std::initializer_list list) : FullVector{ list } {} FRowsptr times(T a); FRowsptr negated(); diff --git a/MbDCode/FullVector.h b/MbDCode/FullVector.h index c4193d0..1285c7a 100644 --- a/MbDCode/FullVector.h +++ b/MbDCode/FullVector.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include "Array.h" @@ -21,7 +22,7 @@ namespace MbD { FullVector(std::vector vec) : Array(vec) {} FullVector(int count) : Array(count) {} FullVector(int count, const T& value) : Array(count, value) {} - FullVector(std::vector::iterator begin, std::vector::iterator end) : Array(begin, end) {} + FullVector(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : Array(begin, end) {} FullVector(std::initializer_list list) : Array{ list } {} double dot(std::shared_ptr> vec); void atiplusNumber(int i, T value); diff --git a/MbDCode/GearConstraintIJ.h b/MbDCode/GearConstraintIJ.h index 4092d59..7ffd8b7 100644 --- a/MbDCode/GearConstraintIJ.h +++ b/MbDCode/GearConstraintIJ.h @@ -9,7 +9,7 @@ #pragma once #include "ConstraintIJ.h" -#include "OrbitAngleZIecJec.h" +#include "OrbitAnglezIecJec.h" namespace MbD { class GearConstraintIJ : public ConstraintIJ diff --git a/MbDCode/GearConstraintIqcJc.cpp b/MbDCode/GearConstraintIqcJc.cpp index dd01774..cd348ff 100644 --- a/MbDCode/GearConstraintIqcJc.cpp +++ b/MbDCode/GearConstraintIqcJc.cpp @@ -9,7 +9,7 @@ #include "GearConstraintIqcJc.h" #include "EndFrameqc.h" #include "CREATE.h" -#include "OrbitAngleZIeqcJec.h" +#include "OrbitAnglezIeqcJec.h" using namespace MbD; diff --git a/MbDCode/GearConstraintIqcJqc.cpp b/MbDCode/GearConstraintIqcJqc.cpp index 0793ed6..717c815 100644 --- a/MbDCode/GearConstraintIqcJqc.cpp +++ b/MbDCode/GearConstraintIqcJqc.cpp @@ -8,7 +8,7 @@ #include "GearConstraintIqcJqc.h" #include "EndFrameqc.h" -#include "OrbitAngleZIeqcJeqc.h" +#include "OrbitAnglezIeqcJeqc.h" #include "CREATE.h" using namespace MbD; diff --git a/MbDCode/Item.cpp b/MbDCode/Item.cpp index e20f225..820b2e6 100644 --- a/MbDCode/Item.cpp +++ b/MbDCode/Item.cpp @@ -6,9 +6,9 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +//#include #include -#include +//#include #include #include "Item.h" diff --git a/MbDCode/Numeric.cpp b/MbDCode/Numeric.cpp index e78ee3c..b1fc9a2 100644 --- a/MbDCode/Numeric.cpp +++ b/MbDCode/Numeric.cpp @@ -7,7 +7,7 @@ ***************************************************************************/ #include -#include +#include "corecrt_math_defines.h" #include #include "Numeric.h" diff --git a/MbDCode/OrbitAnglezIecJec.cpp b/MbDCode/OrbitAnglezIecJec.cpp index c53166e..3a1ec8b 100644 --- a/MbDCode/OrbitAnglezIecJec.cpp +++ b/MbDCode/OrbitAnglezIecJec.cpp @@ -6,9 +6,9 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" -#include "OrbitAngleZIecJec.h" +#include "OrbitAnglezIecJec.h" #include "Numeric.h" using namespace MbD; diff --git a/MbDCode/OrbitAnglezIeqcJec.cpp b/MbDCode/OrbitAnglezIeqcJec.cpp index 1dd5298..b9bb400 100644 --- a/MbDCode/OrbitAnglezIeqcJec.cpp +++ b/MbDCode/OrbitAnglezIeqcJec.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include "OrbitAngleZIeqcJec.h" +#include "OrbitAnglezIeqcJec.h" #include "CREATE.h" #include "DispCompIeqcJecIe.h" diff --git a/MbDCode/OrbitAnglezIeqcJec.h b/MbDCode/OrbitAnglezIeqcJec.h index 65610f3..2788bad 100644 --- a/MbDCode/OrbitAnglezIeqcJec.h +++ b/MbDCode/OrbitAnglezIeqcJec.h @@ -8,7 +8,7 @@ #pragma once -#include "OrbitAngleZIecJec.h" +#include "OrbitAnglezIecJec.h" namespace MbD { class OrbitAngleZIeqcJec : public OrbitAngleZIecJec diff --git a/MbDCode/OrbitAnglezIeqcJeqc.cpp b/MbDCode/OrbitAnglezIeqcJeqc.cpp index 79709c6..b8e689c 100644 --- a/MbDCode/OrbitAnglezIeqcJeqc.cpp +++ b/MbDCode/OrbitAnglezIeqcJeqc.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include "OrbitAngleZIeqcJeqc.h" +#include "OrbitAnglezIeqcJeqc.h" #include "CREATE.h" #include "DispCompIeqcJeqcIe.h" diff --git a/MbDCode/OrbitAnglezIeqcJeqc.h b/MbDCode/OrbitAnglezIeqcJeqc.h index ec0f843..8455372 100644 --- a/MbDCode/OrbitAnglezIeqcJeqc.h +++ b/MbDCode/OrbitAnglezIeqcJeqc.h @@ -8,7 +8,7 @@ #pragma once -#include "OrbitAngleZIeqcJec.h" +#include "OrbitAnglezIeqcJec.h" namespace MbD { class OrbitAngleZIeqcJeqc : public OrbitAngleZIeqcJec diff --git a/MbDCode/ScrewConstraintIJ.cpp b/MbDCode/ScrewConstraintIJ.cpp index c63e537..cbfd4e7 100644 --- a/MbDCode/ScrewConstraintIJ.cpp +++ b/MbDCode/ScrewConstraintIJ.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" #include "ScrewConstraintIJ.h" diff --git a/MbDCode/ScrewConstraintIqcJc.cpp b/MbDCode/ScrewConstraintIqcJc.cpp index 74cb241..463954f 100644 --- a/MbDCode/ScrewConstraintIqcJc.cpp +++ b/MbDCode/ScrewConstraintIqcJc.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" #include "ScrewConstraintIqcJc.h" #include "EndFrameqc.h" diff --git a/MbDCode/ScrewConstraintIqcJqc.cpp b/MbDCode/ScrewConstraintIqcJqc.cpp index 1ee6649..e02d7fe 100644 --- a/MbDCode/ScrewConstraintIqcJqc.cpp +++ b/MbDCode/ScrewConstraintIqcJqc.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" #include "ScrewConstraintIqcJqc.h" #include "EndFrameqc.h" diff --git a/MbDCode/SymbolicParser.cpp b/MbDCode/SymbolicParser.cpp index ed54b44..ca0c160 100644 --- a/MbDCode/SymbolicParser.cpp +++ b/MbDCode/SymbolicParser.cpp @@ -6,7 +6,7 @@ * See LICENSE file for details about copyright. * ***************************************************************************/ -#include +#include "corecrt_math_defines.h" #include #include diff --git a/MbDCode/corecrt_math_defines.h b/MbDCode/corecrt_math_defines.h new file mode 100644 index 0000000..0d46d29 --- /dev/null +++ b/MbDCode/corecrt_math_defines.h @@ -0,0 +1,30 @@ +// +// corecrt_math_defines.h +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Definitions of useful mathematical constants +// +#pragma once + +#ifndef _MATH_DEFINES_DEFINED +#define _MATH_DEFINES_DEFINED +// Definitions of useful mathematical constants +// +// 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_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_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) +#define M_SQRT2 1.41421356237309504880 // sqrt(2) +#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) +#endif \ No newline at end of file From fa2deac10f23afaeb0a9085295163a73d9b6fa7f Mon Sep 17 00:00:00 2001 From: John Dupuy Date: Wed, 27 Sep 2023 15:13:22 -0500 Subject: [PATCH 2/4] 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 From 1f32157513982903aa9ef33cd6af0079eeb32de1 Mon Sep 17 00:00:00 2001 From: John Dupuy Date: Wed, 27 Sep 2023 16:06:39 -0500 Subject: [PATCH 3/4] merged with latest main --- MbDCode/ASMTSpatialContainer.cpp | 1 - MbDCode/Array.h | 4 +- MbDCode/CADSystem.cpp | 175 +++++++++++++++++++++++++++++++ MbDCode/CADSystem.h | 1 + MbDCode/FullColumn.h | 2 +- MbDCode/FullVector.h | 2 +- MbDCode/GeneralSpline.cpp | 36 +++---- MbDCode/MarkerFrame.cpp | 4 +- MbDCode/MarkerFrame.h | 2 +- MbDCode/MbDCode.cpp | 27 ++--- MbDCode/MbDCode.vcxproj | 6 ++ MbDCode/Part.cpp | 4 + MbDCode/Part.h | 1 + MbDCode/PartFrame.cpp | 5 + MbDCode/PartFrame.h | 1 + 15 files changed, 232 insertions(+), 39 deletions(-) diff --git a/MbDCode/ASMTSpatialContainer.cpp b/MbDCode/ASMTSpatialContainer.cpp index 0d3a382..4d8aac2 100644 --- a/MbDCode/ASMTSpatialContainer.cpp +++ b/MbDCode/ASMTSpatialContainer.cpp @@ -336,7 +336,6 @@ void MbD::ASMTSpatialContainer::compareResults(AnalysisType type) auto i = xs->size() - 1; //Pos if (!Numeric::equaltol(xs->at(i), inxs->at(i), lengthTol)) { - std::cout << i << " xs " << xs->at(i) << ", " << i<< lengthTol << std::endl; std::cout << i << " xs " << xs->at(i) << ", " << inxs->at(i) << ", " << lengthTol << std::endl; } if (!Numeric::equaltol(ys->at(i), inys->at(i), lengthTol)) { diff --git a/MbDCode/Array.h b/MbDCode/Array.h index db8e407..808e366 100644 --- a/MbDCode/Array.h +++ b/MbDCode/Array.h @@ -29,7 +29,7 @@ namespace MbD { Array(std::vector vec) : std::vector(vec) {} Array(int count) : std::vector(count) {} Array(int count, const T& value) : std::vector(count, value) {} - Array(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : std::vector(begin, end) {} + Array(typename std::vector::iterator begin, typename std::vector::iterator end) : std::vector(begin, end) {} Array(std::initializer_list list) : std::vector{ list } {} virtual void initialize(); void copyFrom(std::shared_ptr> x); @@ -180,4 +180,4 @@ namespace MbD { { this->at(i) *= factor; } -} \ No newline at end of file +} diff --git a/MbDCode/CADSystem.cpp b/MbDCode/CADSystem.cpp index 79b1190..c7c6d11 100644 --- a/MbDCode/CADSystem.cpp +++ b/MbDCode/CADSystem.cpp @@ -24,6 +24,7 @@ #include "PartFrame.h" #include "Time.h" #include "StateData.h" +#include "EulerParameters.h" using namespace MbD; @@ -48,6 +49,180 @@ void CADSystem::logString(double value) { } +void CADSystem::runOndselDoublePendulum() +{ + //Double pendulum with easy input numbers for exact port from Smalltalk + //GEOAssembly calcCharacteristicDimensions must set mbdUnits to unity. + std::cout << "runOndselDoublePendulum" << std::endl; + auto& TheSystem = mbdSystem; + TheSystem->clear(); + std::string name = "TheSystem"; + TheSystem->name = name; + std::cout << "TheSystem->name " << TheSystem->name << std::endl; + auto& systemSolver = TheSystem->systemSolver; + systemSolver->errorTolPosKine = 1.0e-6; + systemSolver->errorTolAccKine = 1.0e-6; + systemSolver->iterMaxPosKine = 25; + systemSolver->iterMaxAccKine = 25; + systemSolver->tstart = 0.0; + systemSolver->tend = 0.0; + systemSolver->hmin = 1.0e-9; + systemSolver->hmax = 1.0; + systemSolver->hout = 0.04; + systemSolver->corAbsTol = 1.0e-6; + systemSolver->corRelTol = 1.0e-6; + systemSolver->intAbsTol = 1.0e-6; + systemSolver->intRelTol = 1.0e-6; + systemSolver->iterMaxDyn = 4; + systemSolver->orderMax = 5; + systemSolver->translationLimit = 1.0e10; + systemSolver->rotationLimit = 0.5; + + std::string str; + FColDsptr qX, qE, qXdot, omeOpO, qXddot, alpOpO; + FColDsptr rpmp; + FMatDsptr aAap, aApm; + FRowDsptr fullRow; + // + auto assembly1 = CREATE::With("/Assembly1"); + std::cout << "assembly1->name " << assembly1->name << std::endl; + assembly1->m = 0.0; + assembly1->aJ = std::make_shared>(ListD{ 0, 0, 0 }); + qX = std::make_shared>(ListD{ 0, 0, 0 }); + aAap = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + assembly1->setqX(qX); + assembly1->setaAap(aAap); + qXdot = std::make_shared>(ListD{ 0, 0, 0 }); + omeOpO = std::make_shared>(ListD{ 0, 0, 0 }); + assembly1->setqXdot(qXdot); + assembly1->setomeOpO(omeOpO); + TheSystem->addPart(assembly1); + { + auto& partFrame = assembly1->partFrame; + auto marker2 = CREATE::With("/Assembly1/Marker2"); + rpmp = std::make_shared>(ListD{ 0.0, 0.0, 0.0 }); + marker2->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + marker2->setaApm(aApm); + partFrame->addMarkerFrame(marker2); + // + auto marker1 = CREATE::With("/Assembly1/Marker1"); + rpmp = std::make_shared>(ListD{ 0.0, 3.0, 0.0 }); + marker1->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 0, 1 }, + { 0, -1, 0 } + }); + marker1->setaApm(aApm); + partFrame->addMarkerFrame(marker1); + } + assembly1->asFixed(); + // + auto crankPart1 = CREATE::With("/Assembly1/Part1"); + std::cout << "crankPart1->name " << crankPart1->name << std::endl; + crankPart1->m = 1.0; + crankPart1->aJ = std::make_shared>(ListD{ 1, 1, 1 }); + qX = std::make_shared>(ListD{ 0.4, 0.0, -0.05 }); + aAap = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + crankPart1->setqX(qX); + crankPart1->setaAap(aAap); + qXdot = std::make_shared>(ListD{ 0, 0, 0 }); + omeOpO = std::make_shared>(ListD{ 0, 0, 0 }); + crankPart1->setqXdot(qXdot); + crankPart1->setomeOpO(omeOpO); + TheSystem->addPart(crankPart1); + { + auto& partFrame = crankPart1->partFrame; + auto marker1 = CREATE::With("/Assembly1/Part1/Marker1"); + rpmp = std::make_shared>(ListD{ -0.4, 0.0, 0.05 }); + marker1->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + marker1->setaApm(aApm); + partFrame->addMarkerFrame(marker1); + // + auto marker2 = CREATE::With("/Assembly1/Part1/Marker2"); + rpmp = std::make_shared>(ListD{ 0.4, 0.0, 0.05 }); + marker2->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + marker2->setaApm(aApm); + partFrame->addMarkerFrame(marker2); + } + // + auto conrodPart2 = CREATE::With("/Assembly1/Part2"); + std::cout << "conrodPart2->name " << conrodPart2->name << std::endl; + conrodPart2->m = 1.0; + conrodPart2->aJ = std::make_shared>(ListD{ 1, 1, 1 }); + qX = std::make_shared>(ListD{ 0.15, 0.1, 0.05 }); + qE = std::make_shared>(ListD{ 0.0, 0.0, 1.0, 0.0 }); + auto eulerParameters = CREATE>::With(ListD{ 0.0, 0.0, 1.0, 0.0 }); + eulerParameters->calcABC(); + aAap = eulerParameters->aA; + conrodPart2->setqX(qX); + conrodPart2->setaAap(aAap); + qXdot = std::make_shared>(ListD{ 0, 0, 0 }); + omeOpO = std::make_shared>(ListD{ 0, 0, 0 }); + conrodPart2->setqXdot(qXdot); + conrodPart2->setomeOpO(omeOpO); + TheSystem->addPart(conrodPart2); + { + auto& partFrame = conrodPart2->partFrame; + auto marker1 = CREATE::With("/Assembly1/Part2/Marker1"); + rpmp = std::make_shared>(ListD{ -0.65, 0.0, -0.05 }); + marker1->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + {1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {0.0, 0.0, 1.0} + }); + marker1->setaApm(aApm); + partFrame->addMarkerFrame(marker1); + // + auto marker2 = CREATE::With("/Assembly1/Part2/Marker2"); + rpmp = std::make_shared>(ListD{ 0.65, 0.0, -0.05 }); + marker2->setrpmp(rpmp); + aApm = std::make_shared>(ListListD{ + {1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {0.0, 0.0, 1.0} + }); + marker2->setaApm(aApm); + partFrame->addMarkerFrame(marker2); + } + // + auto revJoint1 = CREATE::With("/Assembly1/Joint1"); + std::cout << "revJoint1->name " << revJoint1->name << std::endl; + revJoint1->connectsItoJ(assembly1->partFrame->endFrame("/Assembly1/Marker2"), crankPart1->partFrame->endFrame("/Assembly1/Part1/Marker1")); + TheSystem->addJoint(revJoint1); + + auto revJoint2 = CREATE::With("/Assembly1/Joint2"); + std::cout << "revJoint2->name " << revJoint2->name << std::endl; + revJoint2->connectsItoJ(crankPart1->partFrame->endFrame("/Assembly1/Part1/Marker2"), conrodPart2->partFrame->endFrame("/Assembly1/Part2/Marker1")); + TheSystem->addJoint(revJoint2); + // + TheSystem->runKINEMATIC(TheSystem); +} + void CADSystem::runOndselPiston() { //Piston with easy input numbers for exact port from Smalltalk diff --git a/MbDCode/CADSystem.h b/MbDCode/CADSystem.h index 9cc0d7c..f2271d6 100644 --- a/MbDCode/CADSystem.h +++ b/MbDCode/CADSystem.h @@ -27,6 +27,7 @@ namespace MbD { void outputFor(AnalysisType type); void logString(std::string& str); void logString(double value); + void runOndselDoublePendulum(); void runOndselPiston(); void runPiston(); void preMbDrun(std::shared_ptr mbdSys); diff --git a/MbDCode/FullColumn.h b/MbDCode/FullColumn.h index 34b0318..b72b006 100644 --- a/MbDCode/FullColumn.h +++ b/MbDCode/FullColumn.h @@ -33,7 +33,7 @@ namespace MbD { FullColumn(std::vector vec) : FullVector(vec) {} FullColumn(int count) : FullVector(count) {} FullColumn(int count, const T& value) : FullVector(count, value) {} - FullColumn(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : FullVector(begin, end) {} + FullColumn(typename std::vector::iterator begin, typename std::vector::iterator end) : FullVector(begin, end) {} FullColumn(std::initializer_list list) : FullVector{ list } {} FColsptr plusFullColumn(FColsptr fullCol); FColsptr minusFullColumn(FColsptr fullCol); diff --git a/MbDCode/FullVector.h b/MbDCode/FullVector.h index 1285c7a..8959c2b 100644 --- a/MbDCode/FullVector.h +++ b/MbDCode/FullVector.h @@ -22,7 +22,7 @@ namespace MbD { FullVector(std::vector vec) : Array(vec) {} FullVector(int count) : Array(count) {} FullVector(int count, const T& value) : Array(count, value) {} - FullVector(typename std::vector::const_iterator begin, typename std::vector::const_iterator end) : Array(begin, end) {} + FullVector(typename std::vector::iterator begin, typename std::vector::iterator end) : Array(begin, end) {} FullVector(std::initializer_list list) : Array{ list } {} double dot(std::shared_ptr> vec); void atiplusNumber(int i, T value); diff --git a/MbDCode/GeneralSpline.cpp b/MbDCode/GeneralSpline.cpp index ba7721b..4f6c054 100644 --- a/MbDCode/GeneralSpline.cpp +++ b/MbDCode/GeneralSpline.cpp @@ -5,7 +5,7 @@ * * * See LICENSE file for details about copyright. * ***************************************************************************/ - + #include #include "GeneralSpline.h" @@ -27,7 +27,7 @@ double MbD::GeneralSpline::getValue() Symsptr MbD::GeneralSpline::differentiateWRTx() { auto self = clonesptr(); - auto arg = std::static_pointer_cast(self)->xx; + auto& arg = std::static_pointer_cast(self)->xx; auto deriv = std::make_shared(arg, self, 1); return deriv; } @@ -35,14 +35,14 @@ Symsptr MbD::GeneralSpline::differentiateWRTx() void MbD::GeneralSpline::arguments(Symsptr args) { auto array = args->getTerms(); - auto arg = array->at(0); + auto& arg = array->at(0); int order = (int)array->at(1)->getValue(); - int n = (array->size() - 2) / 2; + int n = ((int)array->size() - 2) / 2; auto xarray = std::make_shared>(n); auto yarray = std::make_shared>(n); for (int i = 0; i < n; i++) { - size_t ii = 2 * (i + 1); + size_t ii = 2 * ((size_t)i + 1); xarray->at(i) = array->at(ii)->getValue(); yarray->at(i) = array->at(ii + 1)->getValue(); } @@ -63,7 +63,7 @@ void MbD::GeneralSpline::computeDerivatives() { //"See derivation in MbDTheory 9spline.fodt." if (degree == 0) throw std::runtime_error("ToDo: Use ZeroDegreeSpline"); - auto n = xs->size(); + auto n = (int)xs->size(); auto p = degree; auto np = n * p; auto matrix = std::make_shared>(np, np); @@ -72,7 +72,7 @@ void MbD::GeneralSpline::computeDerivatives() auto hmax = 0.0; for (int i = 0; i < n - 1; i++) { - auto h = xs->at(i + 1) - xs->at(i); + auto h = xs->at((size_t)i + 1) - xs->at(i); hmax = std::max(hmax, std::abs(h)); hs->atiput(i, h); } @@ -94,7 +94,7 @@ void MbD::GeneralSpline::computeDerivatives() matrix->atijput(offset + k - j, offset + k, dum); } } - bvector->atiput(offset, ys->at(i + 1) - ys->at(i)); + bvector->atiput(offset, ys->at((size_t)i + 1) - ys->at(i)); } if (isCyclic()) { for (int j = 1; j < p + 1; j++) @@ -127,7 +127,7 @@ void MbD::GeneralSpline::computeDerivatives() } for (int i = 0; i < n; i++) { - auto derivsi = derivs->at(i); + auto& derivsi = derivs->at(i); derivsi->equalArrayAt(derivsVector, (i - 1) * p + 1); for (int j = 0; j < p; j++) { @@ -147,13 +147,13 @@ double MbD::GeneralSpline::derivativeAt(int n, double xxx) //"d2ydx2(x) := d2ydx2i + d3ydx3i*hi + d4ydx4i*hi^2/2! +" if (n > degree) return 0.0; calcIndexAndDeltaFor(xxx); - auto derivsi = derivs->at(index); + auto& derivsi = derivs->at(index); auto sum = 0.0; for (int j = degree; j >= n + 1; j--) { - sum = (sum + derivsi->at(j - 1)) * delta / (j - n); + sum = (sum + derivsi->at((size_t)j - 1)) * delta / (j - n); } - return derivsi->at(n - 1) + sum; + return derivsi->at((size_t)n - 1) + sum; } void MbD::GeneralSpline::calcIndexAndDeltaFor(double xxx) @@ -185,7 +185,7 @@ void MbD::GeneralSpline::calcNonCyclicIndexAndDelta() } else { if (xvalue >= xLast) { - index = xs->size() - 1; + index = (int)xs->size() - 1; delta = xvalue - xLast; } else { @@ -196,8 +196,8 @@ void MbD::GeneralSpline::calcNonCyclicIndexAndDelta() void MbD::GeneralSpline::calcIndexAndDelta() { - if (!(index < xs->size() - 1) || !(xs->at(index) <= xvalue) || !(xvalue < xs->at(index + 1))) { - searchIndexFromto(0, xs->size()); //Using range. + if (!(index < xs->size() - 1) || !(xs->at(index) <= xvalue) || !(xvalue < xs->at((size_t)index + 1))) { + searchIndexFromto(0, (int)xs->size()); //Using range. } delta = xvalue - xs->at(index); } @@ -209,7 +209,7 @@ void MbD::GeneralSpline::searchIndexFromto(int first, int last) index = first; } else { - auto middle = std::floor((first + last) / 2); + auto middle = (int)std::floor((first + last) / 2); if (xvalue < xs->at(middle)) { searchIndexFromto(first, middle); } @@ -229,11 +229,11 @@ double MbD::GeneralSpline::y(double xxx) //"y(x) := yi + dydxi*hi + d2ydx2i*hi^2/2! + d3ydx3i*hi^3/3! +" calcIndexAndDeltaFor(xxx); - auto derivsi = derivs->at(index); + auto& derivsi = derivs->at(index); auto sum = 0.0; for (int j = degree; j >= 1; j--) { - sum = (sum + derivsi->at(j - 1)) * delta / j; + sum = (sum + derivsi->at((size_t)j - 1)) * delta / j; } return ys->at(index) + sum; } diff --git a/MbDCode/MarkerFrame.cpp b/MbDCode/MarkerFrame.cpp index 08eb95e..db8fd07 100644 --- a/MbDCode/MarkerFrame.cpp +++ b/MbDCode/MarkerFrame.cpp @@ -243,9 +243,9 @@ void MarkerFrame::setrpmp(FColDsptr x) rpmp->copyFrom(x); } -void MarkerFrame::setaApm(FMatDsptr x) +void MarkerFrame::setaApm(FMatDsptr mat) { - aApm->copyFrom(x); + aApm->copyFrom(mat); } void MarkerFrame::addEndFrame(EndFrmsptr endFrm) { diff --git a/MbDCode/MarkerFrame.h b/MbDCode/MarkerFrame.h index 8b441fc..9942961 100644 --- a/MbDCode/MarkerFrame.h +++ b/MbDCode/MarkerFrame.h @@ -34,7 +34,7 @@ namespace MbD { void setPartFrame(PartFrame* partFrm); PartFrame* getPartFrame(); void setrpmp(FColDsptr x); - void setaApm(FMatDsptr x); + void setaApm(FMatDsptr mat); void addEndFrame(EndFrmsptr x); void initializeLocally() override; void initializeGlobally() override; diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index 3a3bd97..1564d30 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -26,19 +26,20 @@ 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->runPiston(); - runSpMat(); +// auto cadSystem = std::make_shared(); +// cadSystem->runOndselDoublePendulum(); + ////cadSystem->runOndselPiston(); + //cadSystem->runPiston(); + //runSpMat(); } void runSpMat() { @@ -57,4 +58,4 @@ void runSpMat() { auto matSolver = CREATE::With(); auto answer = matSolver->solvewithsaveOriginal(spMat, fullCol, true); auto aAx = spMat->timesFullColumn(answer); -} \ No newline at end of file +} diff --git a/MbDCode/MbDCode.vcxproj b/MbDCode/MbDCode.vcxproj index aaace72..30fa987 100644 --- a/MbDCode/MbDCode.vcxproj +++ b/MbDCode/MbDCode.vcxproj @@ -76,6 +76,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -90,6 +91,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +106,8 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 + true Console @@ -118,6 +122,8 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 + true Console diff --git a/MbDCode/Part.cpp b/MbDCode/Part.cpp index 1c52f81..6186dbf 100644 --- a/MbDCode/Part.cpp +++ b/MbDCode/Part.cpp @@ -61,6 +61,10 @@ FColDsptr Part::getqX() { return partFrame->getqX(); } +void Part::setaAap(FMatDsptr mat) { + partFrame->setaAap(mat); +} + void Part::setqE(FColDsptr x) { partFrame->setqE(x); } diff --git a/MbDCode/Part.h b/MbDCode/Part.h index 65e2119..399f18f 100644 --- a/MbDCode/Part.h +++ b/MbDCode/Part.h @@ -32,6 +32,7 @@ namespace MbD { void initializeGlobally() override; void setqX(FColDsptr x); FColDsptr getqX(); + void setaAap(FMatDsptr mat); void setqE(FColDsptr x); FColDsptr getqE(); void setqXdot(FColDsptr x); diff --git a/MbDCode/PartFrame.cpp b/MbDCode/PartFrame.cpp index d432566..dafcf89 100644 --- a/MbDCode/PartFrame.cpp +++ b/MbDCode/PartFrame.cpp @@ -64,6 +64,11 @@ void PartFrame::setqE(FColDsptr x) { qE->copyFrom(x); } +void MbD::PartFrame::setaAap(FMatDsptr mat) +{ + qE = mat->asEulerParameters(); +} + FColDsptr PartFrame::getqE() { return qE; } diff --git a/MbDCode/PartFrame.h b/MbDCode/PartFrame.h index aa17c48..24bd58b 100644 --- a/MbDCode/PartFrame.h +++ b/MbDCode/PartFrame.h @@ -42,6 +42,7 @@ namespace MbD { void setqX(FColDsptr x); FColDsptr getqX(); void setqE(FColDsptr x); + void setaAap(FMatDsptr mat); FColDsptr getqE(); void setqXdot(FColDsptr x); FColDsptr getqXdot(); From 0a0a1ad547b7be29c15f69ee5c4261e2ae457430 Mon Sep 17 00:00:00 2001 From: John Dupuy Date: Thu, 28 Sep 2023 13:30:50 -0500 Subject: [PATCH 4/4] fixes str.find bug and cmake files --- CMakeLists.txt | 12 +++++------- MbDCode/CMakeLists.txt | 8 +------- MbDCode/CREATE.h | 6 +++--- MbDCode/MbDCode.cpp | 10 +++++----- MbDCode/PosICNewtonRaphson.cpp | 4 ++-- MbDCode/SystemNewtonRaphson.cpp | 4 ++-- MbDCode/VelSolver.cpp | 4 ++-- 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cec7723..74cf91f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ -cmake_minimum_required(VERSION 3.10) - -project(MbDCodeLib) - -add_executable(MbDCode MbDCode/MbDCode.cpp) -add_subdirectory(MbDCode) - +cmake_minimum_required(VERSION 3.26) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) + +# add_library(some_target main.cpp) +add_executable(ondsel-solver MbDCode/MbDCode.cpp) +add_subdirectory(MbDCode) diff --git a/MbDCode/CMakeLists.txt b/MbDCode/CMakeLists.txt index c6bb15f..85c099a 100644 --- a/MbDCode/CMakeLists.txt +++ b/MbDCode/CMakeLists.txt @@ -1,8 +1,4 @@ -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -add_executable(new_target - MbDCode.cpp +target_sources(ondsel-solver PUBLIC Abs.cpp AbsConstraint.cpp AccICKineNewtonRaphson.cpp @@ -270,5 +266,3 @@ add_executable(new_target ZTranslation.cpp ASMTAssembly.cpp ) - - diff --git a/MbDCode/CREATE.h b/MbDCode/CREATE.h index 6d49f98..67bdf9a 100644 --- a/MbDCode/CREATE.h +++ b/MbDCode/CREATE.h @@ -71,7 +71,7 @@ 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.find("AtPointConstraintIJ") >= 0) { + if (str.find("AtPointConstraintIJ") != std::string::npos) { if (std::dynamic_pointer_cast(frmi)) { inst = std::make_shared(frmi, frmj, axis); } @@ -79,7 +79,7 @@ namespace MbD { inst = std::make_shared(frmi, frmj, axis); } } // "class MbD::Tran - else if(str.find("TranslationConstraintIJ") >= 0) { + else if(str.find("TranslationConstraintIJ") != std::string::npos) { 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.find("DirectionCosineConstraintIJ") >= 0) { + if (str.find("DirectionCosineConstraintIJ") != std::string::npos) { if (std::dynamic_pointer_cast(frmi)) { inst = std::make_shared(frmi, frmj, axisi, axisj); } diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index 1564d30..27d0df2 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -35,11 +35,11 @@ int main() //ASMTAssembly::runFile("fourbot.asmt"); //ASMTAssembly::runFile("wobpump.asmt"); -// auto cadSystem = std::make_shared(); -// cadSystem->runOndselDoublePendulum(); - ////cadSystem->runOndselPiston(); - //cadSystem->runPiston(); - //runSpMat(); + auto cadSystem = std::make_shared(); + cadSystem->runOndselDoublePendulum(); + cadSystem->runOndselPiston(); + cadSystem->runPiston(); + runSpMat(); } void runSpMat() { diff --git a/MbDCode/PosICNewtonRaphson.cpp b/MbDCode/PosICNewtonRaphson.cpp index f8b86f6..b894656 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.find("GESpMatParPvMarkoFast") >= 0) { + if (str.find("GESpMatParPvMarkoFast") != std::string::npos) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str.find("GESpMatParPvPrecise") >= 0) { + if (str.find("GESpMatParPvPrecise") != std::string::npos) { this->lookForRedundantConstraints(); matrixSolver = this->matrixSolverClassNew(); } diff --git a/MbDCode/SystemNewtonRaphson.cpp b/MbDCode/SystemNewtonRaphson.cpp index b05aa63..d569297 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.find("GESpMatParPvMarkoFast") >= 0) { + if (str.find("GESpMatParPvMarkoFast") != std::string::npos) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str.find("GESpMatParPvPrecise") >= 0) { + if (str.find("GESpMatParPvPrecise") != std::string::npos) { str = "MbD: Singular Matrix Error. "; system->logString(str); matrixSolver = this->matrixSolverClassNew(); diff --git a/MbDCode/VelSolver.cpp b/MbDCode/VelSolver.cpp index d22fe6c..e85d4db 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.find("GESpMatParPvMarkoFast") >= 0) { + if (str.find("GESpMatParPvMarkoFast") != std::string::npos) { matrixSolver = CREATE::With(); this->solveEquations(); } else { str = typeid(*matrixSolver).name(); - if (str.find("GESpMatParPvPrecise") >= 0) { + if (str.find("GESpMatParPvPrecise") != std::string::npos) { this->logSingularMatrixMessage(); matrixSolver = this->matrixSolverClassNew(); }