diff --git a/MbDCode/ASMTAssembly.cpp b/MbDCode/ASMTAssembly.cpp index 39418bc..998f559 100644 --- a/MbDCode/ASMTAssembly.cpp +++ b/MbDCode/ASMTAssembly.cpp @@ -19,7 +19,7 @@ #include "ASMTRotationalMotion.h" #include "ASMTTranslationalMotion.h" #include "ASMTMarker.h" -#include "Part.h" +#include "ASMTPart.h" #include "ASMTTranslationalJoint.h" #include "ASMTSphericalJoint.h" #include "ASMTFixedJoint.h" @@ -27,10 +27,151 @@ #include "ASMTUniversalJoint.h" #include "ExternalSystem.h" #include "ASMTPointInPlaneJoint.h" +#include "ASMTPrincipalMassMarker.h" +#include "ASMTForceTorque.h" +#include "ASMTConstantGravity.h" +#include "ASMTSimulationParameters.h" +#include "ASMTAnimationParameters.h" +#include "Part.h" +#include "ASMTRefPoint.h" +#include "ASMTRefCurve.h" +#include "ASMTRefSurface.h" +#include "ASMTTime.h" +#include "SystemSolver.h" +#include "ASMTItemIJ.h" +#include "ASMTKinematicIJ.h" using namespace MbD; -void MbD::ASMTAssembly::runFile(const char* fileName) +void MbD::ASMTAssembly::runSinglePendulum() +{ + auto assembly = CREATE::With(); + std::string str = ""; + assembly->setNotes(str); + str = "Assembly1"; + assembly->setName(str); + auto pos3D = std::make_shared>(ListD{ 0, 0, 0 }); + assembly->setPosition3D(pos3D); + auto rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + assembly->setRotationMatrix(rotMat); + auto vel3D = std::make_shared>(ListD{ 0, 0, 0 }); + assembly->setVelocity3D(vel3D); + auto ome3D = std::make_shared>(ListD{ 0, 0, 0 }); + assembly->setOmega3D(ome3D); + // + auto massMarker = CREATE::With(); + massMarker->setMass(0.0); + massMarker->setDensity(0.0); + auto aJ = std::make_shared>(ListD{ 0, 0, 0 }); + massMarker->setMomentOfInertias(aJ); + pos3D = std::make_shared>(ListD{ 0, 0, 0 }); + massMarker->setPosition3D(pos3D); + rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + massMarker->setRotationMatrix(rotMat); + assembly->setPrincipalMassMarker(massMarker); + // + auto mkr = CREATE::With(); + str = "Marker1"; + mkr->setName(str); + pos3D = std::make_shared>(ListD{ 0, 0, 0 }); + mkr->setPosition3D(pos3D); + rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + massMarker->setRotationMatrix(rotMat); + assembly->addMarker(mkr); + // + auto part = CREATE::With(); + str = "Part1"; + part->setName(str); + pos3D = std::make_shared>(ListD{ -0.1, -0.1, -0.1 }); + part->setPosition3D(pos3D); + rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + part->setRotationMatrix(rotMat); + vel3D = std::make_shared>(ListD{ 0, 0, 0 }); + part->setVelocity3D(vel3D); + ome3D = std::make_shared>(ListD{ 0, 0, 0 }); + part->setOmega3D(ome3D); + assembly->addPart(part); + // + massMarker = CREATE::With(); + massMarker->setMass(0.2); + massMarker->setDensity(10.0); + aJ = std::make_shared>(ListD{ 8.3333333333333e-4, 0.016833333333333, 0.017333333333333 }); + massMarker->setMomentOfInertias(aJ); + pos3D = std::make_shared>(ListD{ 0.5, 0.1, 0.05 }); + massMarker->setPosition3D(pos3D); + rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + massMarker->setRotationMatrix(rotMat); + part->setPrincipalMassMarker(massMarker); + // + mkr = CREATE::With(); + str = "Marker1"; + mkr->setName(str); + pos3D = std::make_shared>(ListD{ 0.1, 0.1, 0.1 }); + mkr->setPosition3D(pos3D); + rotMat = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); + mkr->setRotationMatrix(rotMat); + part->addMarker(mkr); + // + auto joint = CREATE::With(); + str = "Joint1"; + joint->setName(str); + str = "/Assembly1/Marker1"; + joint->setMarkerI(str); + str = "/Assembly1/Part1/Marker1"; + joint->setMarkerJ(str); + assembly->addJoint(joint); + // + auto motion = CREATE::With(); + str = "Motion1"; + motion->setName(str); + str = "/Assembly1/Joint1"; + motion->setMotionJoint(str); + str = "0.0"; + motion->setRotationZ(str); + assembly->addMotion(motion); + // + auto constantGravity = CREATE::With(); + auto gAcceleration = std::make_shared>(ListD{ 0.0, 0.0, 0.0 }); + constantGravity->setg(gAcceleration); + assembly->setConstantGravity(constantGravity); + // + auto simulationParameters = CREATE::With(); + simulationParameters->settstart(0.0); + simulationParameters->settend(0.0); //tstart == tend Initial Conditions only. + simulationParameters->sethmin(1.0e-9); + simulationParameters->sethmax(1.0); + simulationParameters->sethout(0.04); + simulationParameters->seterrorTol(1.0e-6); + assembly->setSimulationParameters(simulationParameters); + // + assembly->runKINEMATIC(); +} + +void MbD::ASMTAssembly::runFile(const char* chars) { std::ifstream stream(fileName); if(stream.fail()) { @@ -53,11 +194,22 @@ void MbD::ASMTAssembly::runFile(const char* fileName) } +void MbD::ASMTAssembly::initialize() +{ + ASMTSpatialContainer::initialize(); + times = std::make_shared>(); +} + ASMTAssembly* MbD::ASMTAssembly::root() { return this; } +void MbD::ASMTAssembly::setNotes(std::string& str) +{ + notes = str; +} + void MbD::ASMTAssembly::parseASMT(std::vector& lines) { readNotes(lines); @@ -96,7 +248,7 @@ void MbD::ASMTAssembly::readParts(std::vector& lines) { assert(lines[0] == "\tParts"); lines.erase(lines.begin()); - parts = std::make_shared>>(); + parts->clear(); auto it = std::find(lines.begin(), lines.end(), "\tKinematicIJs"); std::vector partsLines(lines.begin(), it); while (!partsLines.empty()) { @@ -120,7 +272,7 @@ void MbD::ASMTAssembly::readKinematicIJs(std::vector& lines) { assert(lines[0] == "\tKinematicIJs"); lines.erase(lines.begin()); - kinematicIJs = std::make_shared>>(); + kinematicIJs->clear(); auto it = std::find(lines.begin(), lines.end(), "\tConstraintSets"); std::vector kinematicIJsLines(lines.begin(), it); while (!kinematicIJsLines.empty()) { @@ -148,7 +300,7 @@ void MbD::ASMTAssembly::readJoints(std::vector& lines) { assert(lines[0] == "\t\tJoints"); lines.erase(lines.begin()); - joints = std::make_shared>>(); + joints->clear(); auto it = std::find(lines.begin(), lines.end(), "\t\tMotions"); std::vector jointsLines(lines.begin(), it); std::shared_ptr joint; @@ -190,7 +342,7 @@ void MbD::ASMTAssembly::readMotions(std::vector& lines) { assert(lines[0] == "\t\tMotions"); lines.erase(lines.begin()); - motions = std::make_shared>>(); + motions->clear(); auto it = std::find(lines.begin(), lines.end(), "\t\tGeneralConstraintSets"); std::vector motionsLines(lines.begin(), it); std::shared_ptr motion; @@ -221,7 +373,7 @@ void MbD::ASMTAssembly::readGeneralConstraintSets(std::vector& line { assert(lines[0] == "\t\tGeneralConstraintSets"); lines.erase(lines.begin()); - constraintSets = std::make_shared>>(); + constraintSets->clear(); auto it = std::find(lines.begin(), lines.end(), "\tForceTorques"); std::vector generalConstraintSetsLines(lines.begin(), it); while (!generalConstraintSetsLines.empty()) { @@ -234,7 +386,7 @@ void MbD::ASMTAssembly::readForcesTorques(std::vector& lines) { assert(lines[0] == "\tForceTorques"); //Spelling is not consistent in asmt file. lines.erase(lines.begin()); - forcesTorques = std::make_shared>>(); + forcesTorques->clear(); auto it = std::find(lines.begin(), lines.end(), "\tConstantGravity"); std::vector forcesTorquesLines(lines.begin(), it); while (!forcesTorquesLines.empty()) { @@ -540,7 +692,7 @@ void MbD::ASMTAssembly::createMbD(std::shared_ptr mbdSys, std::shared_pt for (auto& joint : *jointsMotions) { joint->createMbD(mbdSys, mbdUnits); } for (auto& forceTorque : *forcesTorques) { forceTorque->createMbD(mbdSys, mbdUnits); } - auto mbdSysSolver = mbdSys->systemSolver; + auto& mbdSysSolver = mbdSys->systemSolver; mbdSysSolver->errorTolPosKine = simulationParameters->errorTolPosKine; mbdSysSolver->errorTolAccKine = simulationParameters->errorTolAccKine; mbdSysSolver->iterMaxPosKine = simulationParameters->iterMaxPosKine; @@ -585,9 +737,9 @@ void MbD::ASMTAssembly::initprincipalMassMarker() principalMassMarker->mass = 0.0; principalMassMarker->density = 0.0; principalMassMarker->momentOfInertias = std::make_shared>(3, 0); - principalMassMarker->position3D = std::make_shared>(3, 0); - principalMassMarker->rotationMatrix = std::make_shared>(3, 3); - principalMassMarker->rotationMatrix->identity(); + //principalMassMarker->position3D = std::make_shared>(3, 0); + //principalMassMarker->rotationMatrix = std::make_shared>(3, 3); + //principalMassMarker->rotationMatrix->identity(); } std::shared_ptr MbD::ASMTAssembly::spatialContainerAt(std::shared_ptr self, std::string& longname) @@ -662,11 +814,7 @@ std::shared_ptr MbD::ASMTAssembly::geoTime() void MbD::ASMTAssembly::updateFromMbD() { ASMTSpatialContainer::updateFromMbD(); - auto geoTime = asmtTime->getValue(); - auto it = std::find_if(times->begin(), times->end(), [&](double t) { - return Numeric::equaltol(t, geoTime, 1.0e-9); - }); - assert(it != times->end()); + times->push_back(asmtTime->getValue()); for (auto& part : *parts) part->updateFromMbD(); for (auto& joint : *joints) joint->updateFromMbD(); for (auto& motion : *motions) motion->updateFromMbD(); @@ -682,4 +830,44 @@ void MbD::ASMTAssembly::compareResults(AnalysisType type) for (auto& forceTorque : *forcesTorques) forceTorque->compareResults(type); } +void MbD::ASMTAssembly::outputResults(AnalysisType type) +{ + ASMTSpatialContainer::outputResults(type); + for (auto& part : *parts) part->outputResults(type); + for (auto& joint : *joints) joint->outputResults(type); + for (auto& motion : *motions) motion->outputResults(type); + for (auto& forceTorque : *forcesTorques) forceTorque->outputResults(type); +} + +void MbD::ASMTAssembly::addPart(std::shared_ptr part) +{ + parts->push_back(part); + part->owner = this; +} + +void MbD::ASMTAssembly::addJoint(std::shared_ptr joint) +{ + joints->push_back(joint); + joint->owner = this; +} + +void MbD::ASMTAssembly::addMotion(std::shared_ptr motion) +{ + motions->push_back(motion); + motion->owner = this; + motion->initMarkers(); +} + +void MbD::ASMTAssembly::setConstantGravity(std::shared_ptr gravity) +{ + constantGravity = gravity; + gravity->owner = this; +} + +void MbD::ASMTAssembly::setSimulationParameters(std::shared_ptr parameters) +{ + simulationParameters = parameters; + parameters->owner = this; +} + diff --git a/MbDCode/ASMTAssembly.h b/MbDCode/ASMTAssembly.h index 219d4ef..b9a0b32 100644 --- a/MbDCode/ASMTAssembly.h +++ b/MbDCode/ASMTAssembly.h @@ -5,100 +5,111 @@ * * * See LICENSE file for details about copyright. * ***************************************************************************/ - + #pragma once #include #include "ASMTSpatialContainer.h" -#include "ASMTRefPoint.h" -#include "ASMTRefCurve.h" -#include "ASMTRefSurface.h" -#include "ASMTPart.h" -#include "ASMTKinematicIJ.h" -#include "ASMTConstraintSet.h" -#include "ASMTForceTorque.h" -#include "ASMTConstantGravity.h" -#include "ASMTSimulationParameters.h" -#include "ASMTAnimationParameters.h" #include "FullColumn.h" #include "FullMatrix.h" -#include "ASMTJoint.h" -#include "ASMTMotion.h" -#include "Units.h" -#include "ASMTTime.h" -#include "SystemSolver.h" namespace MbD { - class ASMTAssembly : public ASMTSpatialContainer - { - // - public: - static void runFile(const char* fileName); - ASMTAssembly* root() override; - void parseASMT(std::vector& lines) override; - void readNotes(std::vector& lines); - void readParts(std::vector& lines); - void readPart(std::vector& lines); - void readKinematicIJs(std::vector& lines); - void readKinematicIJ(std::vector& lines); - void readConstraintSets(std::vector& lines); - void readJoints(std::vector& lines); - void readMotions(std::vector& lines); - void readGeneralConstraintSets(std::vector& lines); - void readForcesTorques(std::vector& lines); - void readConstantGravity(std::vector& lines); - void readSimulationParameters(std::vector& lines); - void readAnimationParameters(std::vector& lines); - void readTimeSeries(std::vector& lines); - void readTimes(std::vector& lines); - void readAssemblySeries(std::vector& lines); - void readPartSeriesMany(std::vector& lines); - void readPartSeries(std::vector& lines); - void readJointSeriesMany(std::vector& lines); - void readJointSeries(std::vector& lines); - void readMotionSeriesMany(std::vector& lines); - void readMotionSeries(std::vector& lines); + class ASMTRefPoint; + class ASMTRefCurve; + class ASMTRefSurface; + class ASMTPart; + class ASMTKinematicIJ; + class ASMTConstraintSet; + class ASMTForceTorque; + class ASMTConstantGravity; + class ASMTSimulationParameters; + class ASMTAnimationParameters; + class ASMTJoint; + class ASMTMotion; + class Units; + class ASMTTime; + class SystemSolver; + class ASMTItemIJ; - void outputFor(AnalysisType type); - void logString(std::string& str); - void logString(double value); - void preMbDrun(std::shared_ptr mbdSys); - void postMbDrun(); - void calcCharacteristicDimensions(); - double calcCharacteristicTime(); - double calcCharacteristicMass(); - double calcCharacteristicLength(); - std::shared_ptr>> connectorList(); - std::shared_ptr>>markerMap(); - void deleteMbD(); - void createMbD(std::shared_ptr mbdSys, std::shared_ptr mbdUnits) override; - void runKINEMATIC(); - void initprincipalMassMarker(); - std::shared_ptr spatialContainerAt(std::shared_ptr self, std::string& longname); - std::shared_ptr markerAt(std::string& longname); - std::shared_ptr jointAt(std::string& longname); - std::shared_ptr motionAt(std::string& longname); - std::shared_ptr forceTorqueAt(std::string& longname); - FColDsptr vOcmO() override; - FColDsptr omeOpO() override; - std::shared_ptr geoTime(); - void updateFromMbD() override; - void compareResults(AnalysisType type) override; + class ASMTAssembly : public ASMTSpatialContainer + { + // + public: + static void runSinglePendulum(); + static void runFile(const char* chars); + void initialize() override; + ASMTAssembly* root() override; + void setNotes(std::string& str); + void parseASMT(std::vector& lines) override; + void readNotes(std::vector& lines); + void readParts(std::vector& lines); + void readPart(std::vector& lines); + void readKinematicIJs(std::vector& lines); + void readKinematicIJ(std::vector& lines); + void readConstraintSets(std::vector& lines); + void readJoints(std::vector& lines); + void readMotions(std::vector& lines); + void readGeneralConstraintSets(std::vector& lines); + void readForcesTorques(std::vector& lines); + void readConstantGravity(std::vector& lines); + void readSimulationParameters(std::vector& lines); + void readAnimationParameters(std::vector& lines); + void readTimeSeries(std::vector& lines); + void readTimes(std::vector& lines); + void readAssemblySeries(std::vector& lines); + void readPartSeriesMany(std::vector& lines); + void readPartSeries(std::vector& lines); + void readJointSeriesMany(std::vector& lines); + void readJointSeries(std::vector& lines); + void readMotionSeriesMany(std::vector& lines); + void readMotionSeries(std::vector& lines); - std::string notes; - std::shared_ptr>> parts; - std::shared_ptr>> kinematicIJs; - std::shared_ptr>> constraintSets; - std::shared_ptr>> joints; - std::shared_ptr>> motions; - std::shared_ptr>> forcesTorques; - std::shared_ptr constantGravity; - std::shared_ptr simulationParameters; - std::shared_ptr animationParameters; - std::shared_ptr> times; - std::shared_ptr asmtTime = std::make_shared(); - std::shared_ptr mbdUnits; + void outputFor(AnalysisType type); + void logString(std::string& str); + void logString(double value); + void preMbDrun(std::shared_ptr mbdSys); + void postMbDrun(); + void calcCharacteristicDimensions(); + double calcCharacteristicTime(); + double calcCharacteristicMass(); + double calcCharacteristicLength(); + std::shared_ptr>> connectorList(); + std::shared_ptr>>markerMap(); + void deleteMbD(); + void createMbD(std::shared_ptr mbdSys, std::shared_ptr mbdUnits) override; + void runKINEMATIC(); + void initprincipalMassMarker(); + std::shared_ptr spatialContainerAt(std::shared_ptr self, std::string& longname); + std::shared_ptr markerAt(std::string& longname); + std::shared_ptr jointAt(std::string& longname); + std::shared_ptr motionAt(std::string& longname); + std::shared_ptr forceTorqueAt(std::string& longname); + FColDsptr vOcmO() override; + FColDsptr omeOpO() override; + std::shared_ptr geoTime(); + void updateFromMbD() override; + void compareResults(AnalysisType type) override; + void outputResults(AnalysisType type) override; + void addPart(std::shared_ptr part); + void addJoint(std::shared_ptr joint); + void addMotion(std::shared_ptr motion); + void setConstantGravity(std::shared_ptr constantGravity); + void setSimulationParameters(std::shared_ptr simulationParameters); - }; + std::string notes; + std::shared_ptr>> parts = std::make_shared>>(); + std::shared_ptr>> kinematicIJs = std::make_shared>>(); + std::shared_ptr>> constraintSets = std::make_shared>>(); + std::shared_ptr>> joints = std::make_shared>>(); + std::shared_ptr>> motions = std::make_shared>>(); + std::shared_ptr>> forcesTorques = std::make_shared>>(); + std::shared_ptr constantGravity; + std::shared_ptr simulationParameters; + std::shared_ptr animationParameters; + std::shared_ptr> times; + std::shared_ptr asmtTime = std::make_shared(); + std::shared_ptr mbdUnits; + + }; } diff --git a/MbDCode/ASMTConstantGravity.cpp b/MbDCode/ASMTConstantGravity.cpp index 6cc073c..0183bc0 100644 --- a/MbDCode/ASMTConstantGravity.cpp +++ b/MbDCode/ASMTConstantGravity.cpp @@ -28,3 +28,8 @@ void MbD::ASMTConstantGravity::createMbD(std::shared_ptr mbdSys, std::sh mbdGravity->gXYZ = g->times(1.0 / mbdUnits->acceleration); mbdSys->addForceTorque(mbdGravity); } + +void MbD::ASMTConstantGravity::setg(FColDsptr gravity) +{ + g = gravity; +} diff --git a/MbDCode/ASMTConstantGravity.h b/MbDCode/ASMTConstantGravity.h index 2365927..bfd4a16 100644 --- a/MbDCode/ASMTConstantGravity.h +++ b/MbDCode/ASMTConstantGravity.h @@ -21,6 +21,7 @@ namespace MbD { public: void parseASMT(std::vector& lines) override; void createMbD(std::shared_ptr mbdSys, std::shared_ptr mbdUnits) override; + void setg(FColDsptr g); FColDsptr g; }; diff --git a/MbDCode/ASMTConstraintSet.cpp b/MbDCode/ASMTConstraintSet.cpp index 6fde04f..b6db283 100644 --- a/MbDCode/ASMTConstraintSet.cpp +++ b/MbDCode/ASMTConstraintSet.cpp @@ -58,6 +58,7 @@ void MbD::ASMTConstraintSet::updateFromMbD() void MbD::ASMTConstraintSet::compareResults(AnalysisType type) { + if (infxs == nullptr || infxs->empty()) return; auto mbdUnts = mbdUnits(); auto factor = 1.0e-6; auto forceTol = mbdUnts->force * factor; @@ -70,3 +71,7 @@ void MbD::ASMTConstraintSet::compareResults(AnalysisType type) //assert(Numeric::equaltol(tys->at(i), intys->at(i), torqueTol)); //assert(Numeric::equaltol(tzs->at(i), intzs->at(i), torqueTol)); } + +void MbD::ASMTConstraintSet::outputResults(AnalysisType type) +{ +} diff --git a/MbDCode/ASMTConstraintSet.h b/MbDCode/ASMTConstraintSet.h index 9ff6624..88bc167 100644 --- a/MbDCode/ASMTConstraintSet.h +++ b/MbDCode/ASMTConstraintSet.h @@ -21,6 +21,7 @@ namespace MbD { virtual std::shared_ptr mbdClassNew(); void updateFromMbD() override; void compareResults(AnalysisType type) override; + void outputResults(AnalysisType type) override; }; } diff --git a/MbDCode/ASMTForceTorque.cpp b/MbDCode/ASMTForceTorque.cpp index 347c969..0ab7c3a 100644 --- a/MbDCode/ASMTForceTorque.cpp +++ b/MbDCode/ASMTForceTorque.cpp @@ -19,3 +19,8 @@ void MbD::ASMTForceTorque::compareResults(AnalysisType type) { assert(false); } + +void MbD::ASMTForceTorque::outputResults(AnalysisType type) +{ + assert(false); +} diff --git a/MbDCode/ASMTForceTorque.h b/MbDCode/ASMTForceTorque.h index 0f27d8b..6886221 100644 --- a/MbDCode/ASMTForceTorque.h +++ b/MbDCode/ASMTForceTorque.h @@ -17,6 +17,7 @@ namespace MbD { public: void updateFromMbD() override; void compareResults(AnalysisType type) override; + void outputResults(AnalysisType type) override; }; diff --git a/MbDCode/ASMTGeneralMotion.cpp b/MbDCode/ASMTGeneralMotion.cpp index 46a9def..bc76b11 100644 --- a/MbDCode/ASMTGeneralMotion.cpp +++ b/MbDCode/ASMTGeneralMotion.cpp @@ -13,6 +13,8 @@ #include "CREATE.h" #include "Constant.h" #include "EulerAngles.h" +#include "FullMotion.h" +#include "ASMTTime.h" using namespace MbD; diff --git a/MbDCode/ASMTGeneralMotion.h b/MbDCode/ASMTGeneralMotion.h index 5f127f8..20bd578 100644 --- a/MbDCode/ASMTGeneralMotion.h +++ b/MbDCode/ASMTGeneralMotion.h @@ -9,7 +9,6 @@ #pragma once #include "ASMTMotion.h" -#include "FullMotion.h" namespace MbD { class ASMTGeneralMotion : public ASMTMotion diff --git a/MbDCode/ASMTItem.cpp b/MbDCode/ASMTItem.cpp index 70a263f..744ecd9 100644 --- a/MbDCode/ASMTItem.cpp +++ b/MbDCode/ASMTItem.cpp @@ -28,6 +28,11 @@ void MbD::ASMTItem::initialize() { } +void MbD::ASMTItem::setName(std::string& str) +{ + name = str; +} + void MbD::ASMTItem::parseASMT(std::vector& lines) { assert(false); @@ -141,6 +146,11 @@ void MbD::ASMTItem::compareResults(AnalysisType type) assert(false); } +void MbD::ASMTItem::outputResults(AnalysisType type) +{ + assert(false); +} + std::shared_ptr MbD::ASMTItem::mbdUnits() { if (owner) { diff --git a/MbDCode/ASMTItem.h b/MbDCode/ASMTItem.h index 4138617..36a346e 100644 --- a/MbDCode/ASMTItem.h +++ b/MbDCode/ASMTItem.h @@ -22,6 +22,7 @@ namespace MbD { virtual std::shared_ptr part(); virtual void initialize(); + void setName(std::string& str); virtual void parseASMT(std::vector& lines); FRowDsptr readRowOfDoubles(std::string& line); FColDsptr readColumnOfDoubles(std::string& line); @@ -36,6 +37,7 @@ namespace MbD { virtual void createMbD(std::shared_ptr mbdSys, std::shared_ptr mbdUnits); virtual void updateFromMbD(); virtual void compareResults(AnalysisType type); + virtual void outputResults(AnalysisType type); std::shared_ptr mbdUnits(); std::shared_ptr sptrConstant(double value); diff --git a/MbDCode/ASMTItemIJ.cpp b/MbDCode/ASMTItemIJ.cpp index e24ed28..f35a7b0 100644 --- a/MbDCode/ASMTItemIJ.cpp +++ b/MbDCode/ASMTItemIJ.cpp @@ -18,6 +18,16 @@ void MbD::ASMTItemIJ::initialize() tzs = std::make_shared>(); } +void MbD::ASMTItemIJ::setMarkerI(std::string& mkrI) +{ + markerI = mkrI; +} + +void MbD::ASMTItemIJ::setMarkerJ(std::string& mkrJ) +{ + markerJ = mkrJ; +} + void MbD::ASMTItemIJ::readMarkerI(std::vector& lines) { assert(lines[0].find("MarkerI") != std::string::npos); diff --git a/MbDCode/ASMTItemIJ.h b/MbDCode/ASMTItemIJ.h index 335fa3a..76b53bc 100644 --- a/MbDCode/ASMTItemIJ.h +++ b/MbDCode/ASMTItemIJ.h @@ -16,6 +16,8 @@ namespace MbD { // public: void initialize() override; + void setMarkerI(std::string& mkrI); + void setMarkerJ(std::string& mkrJ); void readMarkerI(std::vector& lines); void readMarkerJ(std::vector& lines); void readFXonIs(std::vector& lines); diff --git a/MbDCode/ASMTMarker.cpp b/MbDCode/ASMTMarker.cpp index dc0fe0b..d5f63be 100644 --- a/MbDCode/ASMTMarker.cpp +++ b/MbDCode/ASMTMarker.cpp @@ -12,6 +12,7 @@ #include "Part.h" #include "PartFrame.h" #include "MarkerFrame.h" +#include "ASMTPrincipalMassMarker.h" using namespace MbD; diff --git a/MbDCode/ASMTPart.cpp b/MbDCode/ASMTPart.cpp index 6e24758..28c7c1c 100644 --- a/MbDCode/ASMTPart.cpp +++ b/MbDCode/ASMTPart.cpp @@ -8,6 +8,8 @@ #include "ASMTPart.h" #include "CREATE.h" +#include "ASMTPrincipalMassMarker.h" + using namespace MbD; diff --git a/MbDCode/ASMTPart.h b/MbDCode/ASMTPart.h index 4d3d4f6..6696d95 100644 --- a/MbDCode/ASMTPart.h +++ b/MbDCode/ASMTPart.h @@ -9,13 +9,10 @@ #pragma once #include "ASMTSpatialContainer.h" -#include "ASMTRefPoint.h" -#include "ASMTRefCurve.h" -#include "ASMTRefSurface.h" -#include "ASMTPrincipalMassMarker.h" -#include "PosVelAccData.h" namespace MbD { + class PosVelAccData; + class ASMTPart : public ASMTSpatialContainer { // diff --git a/MbDCode/ASMTPrincipalMassMarker.cpp b/MbDCode/ASMTPrincipalMassMarker.cpp index 8d3e37a..4eeffe4 100644 --- a/MbDCode/ASMTPrincipalMassMarker.cpp +++ b/MbDCode/ASMTPrincipalMassMarker.cpp @@ -51,3 +51,18 @@ void MbD::ASMTPrincipalMassMarker::parseASMT(std::vector& lines) density = readDouble(lines[0]); lines.erase(lines.begin()); } + +void MbD::ASMTPrincipalMassMarker::setMass(double m) +{ + mass = m; +} + +void MbD::ASMTPrincipalMassMarker::setDensity(double rho) +{ + density = rho; +} + +void MbD::ASMTPrincipalMassMarker::setMomentOfInertias(DiagMatDsptr mat) +{ + momentOfInertias = mat; +} diff --git a/MbDCode/ASMTPrincipalMassMarker.h b/MbDCode/ASMTPrincipalMassMarker.h index 770b909..56349f7 100644 --- a/MbDCode/ASMTPrincipalMassMarker.h +++ b/MbDCode/ASMTPrincipalMassMarker.h @@ -8,17 +8,18 @@ #pragma once -#include "ASMTItem.h" +#include "ASMTSpatialItem.h" namespace MbD { - class ASMTPrincipalMassMarker : public ASMTItem + class ASMTPrincipalMassMarker : public ASMTSpatialItem { // public: void parseASMT(std::vector& lines) override; + void setMass(double mass); + void setDensity(double density); + void setMomentOfInertias(DiagMatDsptr momentOfInertias); - FColDsptr position3D; - FMatDsptr rotationMatrix; double mass, density; DiagMatDsptr momentOfInertias; diff --git a/MbDCode/ASMTRefItem.cpp b/MbDCode/ASMTRefItem.cpp index ea78cb2..f0d9d0c 100644 --- a/MbDCode/ASMTRefItem.cpp +++ b/MbDCode/ASMTRefItem.cpp @@ -11,11 +11,17 @@ using namespace MbD; +void MbD::ASMTRefItem::addMarker(std::shared_ptr marker) +{ + markers->push_back(marker); + marker->owner = this; +} + void MbD::ASMTRefItem::readMarkers(std::vector& lines) { assert(lines[0].find("Markers") != std::string::npos); lines.erase(lines.begin()); - markers = std::make_shared>>(); + markers->clear(); auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { return s.find("RefPoint") != std::string::npos; }); diff --git a/MbDCode/ASMTRefItem.h b/MbDCode/ASMTRefItem.h index 16b73f8..42dce37 100644 --- a/MbDCode/ASMTRefItem.h +++ b/MbDCode/ASMTRefItem.h @@ -17,10 +17,11 @@ namespace MbD { { // public: + void addMarker(std::shared_ptr marker); void readMarkers(std::vector& lines); void readMarker(std::vector& lines); - std::shared_ptr>> markers; + std::shared_ptr>> markers = std::make_shared>>(); }; diff --git a/MbDCode/ASMTRotationalMotion.cpp b/MbDCode/ASMTRotationalMotion.cpp index 0fdcb47..45ed977 100644 --- a/MbDCode/ASMTRotationalMotion.cpp +++ b/MbDCode/ASMTRotationalMotion.cpp @@ -12,6 +12,8 @@ #include "BasicUserFunction.h" #include "CREATE.h" #include "Constant.h" +#include "ASMTJoint.h" +#include "ASMTTime.h" using namespace MbD; @@ -64,3 +66,13 @@ std::shared_ptr MbD::ASMTRotationalMotion::mbdClassNew() { return CREATE::With(); } + +void MbD::ASMTRotationalMotion::setMotionJoint(std::string& str) +{ + motionJoint = str; +} + +void MbD::ASMTRotationalMotion::setRotationZ(std::string& rotZ) +{ + rotationZ = rotZ; +} diff --git a/MbDCode/ASMTRotationalMotion.h b/MbDCode/ASMTRotationalMotion.h index d9beea9..3f969c3 100644 --- a/MbDCode/ASMTRotationalMotion.h +++ b/MbDCode/ASMTRotationalMotion.h @@ -22,6 +22,8 @@ namespace MbD { void initMarkers() override; void createMbD(std::shared_ptr mbdSys, std::shared_ptr mbdUnits) override; std::shared_ptr mbdClassNew() override; + void setMotionJoint(std::string& motionJoint); + void setRotationZ(std::string& rotZ); std::string motionJoint, rotationZ; }; diff --git a/MbDCode/ASMTSimulationParameters.cpp b/MbDCode/ASMTSimulationParameters.cpp index e5ec2d7..587a3b1 100644 --- a/MbDCode/ASMTSimulationParameters.cpp +++ b/MbDCode/ASMTSimulationParameters.cpp @@ -42,3 +42,33 @@ void MbD::ASMTSimulationParameters::parseASMT(std::vector& lines) lines.erase(lines.begin()); } + +void MbD::ASMTSimulationParameters::settstart(double t) +{ + tstart = t; +} + +void MbD::ASMTSimulationParameters::settend(double t) +{ + tend = t; +} + +void MbD::ASMTSimulationParameters::sethmin(double h) +{ + hmin = h; +} + +void MbD::ASMTSimulationParameters::sethmax(double h) +{ + hmax = h; +} + +void MbD::ASMTSimulationParameters::sethout(double h) +{ + hout = h; +} + +void MbD::ASMTSimulationParameters::seterrorTol(double tol) +{ + errorTol = tol; +} diff --git a/MbDCode/ASMTSimulationParameters.h b/MbDCode/ASMTSimulationParameters.h index 135c76a..95850b8 100644 --- a/MbDCode/ASMTSimulationParameters.h +++ b/MbDCode/ASMTSimulationParameters.h @@ -16,6 +16,12 @@ namespace MbD { // public: void parseASMT(std::vector& lines) override; + void settstart(double tstart); + void settend(double tend); + void sethmin(double hmin); + void sethmax(double hmax); + void sethout(double hout); + void seterrorTol(double errorTol); double tstart = 0.0, tend = 1.0, hmin = 1.0e-9, hmax = 1.0e9, hout = 0.1, errorTol = 1.0e-6; double errorTolPosKine = 1.0e-6, errorTolAccKine = 1.0e-6, corAbsTol = 1.0e-6, corRelTol = 1.0e-6; diff --git a/MbDCode/ASMTSpatialContainer.cpp b/MbDCode/ASMTSpatialContainer.cpp index 4d8aac2..c23d971 100644 --- a/MbDCode/ASMTSpatialContainer.cpp +++ b/MbDCode/ASMTSpatialContainer.cpp @@ -10,11 +10,20 @@ #include "Units.h" #include "Part.h" #include "System.h" +#include "ASMTRefPoint.h" +#include "ASMTRefCurve.h" +#include "ASMTRefSurface.h" +#include "ASMTPrincipalMassMarker.h" + using namespace MbD; void MbD::ASMTSpatialContainer::initialize() { + refPoints = std::make_shared>>(); + refCurves = std::make_shared>>(); + refSurfaces = std::make_shared>>(); + xs = std::make_shared>(); ys = std::make_shared>(); zs = std::make_shared>(); @@ -35,11 +44,16 @@ void MbD::ASMTSpatialContainer::initialize() alpzs = std::make_shared>(); } +void MbD::ASMTSpatialContainer::setPrincipalMassMarker(std::shared_ptr aJ) +{ + principalMassMarker = aJ; +} + void MbD::ASMTSpatialContainer::readRefPoints(std::vector& lines) { assert(lines[0].find("RefPoints") != std::string::npos); lines.erase(lines.begin()); - refPoints = std::make_shared>>(); + refPoints->clear(); auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { return s.find("RefCurves") != std::string::npos; }); @@ -64,7 +78,7 @@ void MbD::ASMTSpatialContainer::readRefCurves(std::vector& lines) { assert(lines[0].find("RefCurves") != std::string::npos); lines.erase(lines.begin()); - refCurves = std::make_shared>>(); + refCurves->clear(); auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { return s.find("RefSurfaces") != std::string::npos; }); @@ -84,7 +98,7 @@ void MbD::ASMTSpatialContainer::readRefSurfaces(std::vector& lines) { assert(lines[0].find("RefSurfaces") != std::string::npos); lines.erase(lines.begin()); - refSurfaces = std::make_shared>>(); + refSurfaces->clear(); auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { return s.find("Part") != std::string::npos; }); @@ -325,6 +339,7 @@ void MbD::ASMTSpatialContainer::updateFromMbD() void MbD::ASMTSpatialContainer::compareResults(AnalysisType type) { + if (inxs == nullptr || inxs->empty()) return; auto mbdUnts = mbdUnits(); auto factor = 1.0e-6; auto lengthTol = mbdUnts->length * factor; @@ -392,3 +407,25 @@ void MbD::ASMTSpatialContainer::compareResults(AnalysisType type) std::cout << i << " alpzs " << alpzs->at(i) << ", " << inalpzs->at(i) << ", " << alphaTol << std::endl; } } + +void MbD::ASMTSpatialContainer::outputResults(AnalysisType type) +{ + if (inxs != nullptr && !inxs->empty()) return; + auto i = xs->size() - 1; + std::cout << i << " "; + std::cout << xs->at(i) << ", " << ys->at(i) << ", " << zs->at(i) << ", "; + std::cout << bryxs->at(i) << ", " << bryys->at(i) << ", " << bryzs->at(i) << std::endl; +} + +void MbD::ASMTSpatialContainer::addRefPoint(std::shared_ptr refPoint) +{ + refPoints->push_back(refPoint); + refPoint->owner = this; +} + +void MbD::ASMTSpatialContainer::addMarker(std::shared_ptr marker) +{ + auto refPoint = CREATE::With(); + addRefPoint(refPoint); + refPoint->addMarker(marker); +} diff --git a/MbDCode/ASMTSpatialContainer.h b/MbDCode/ASMTSpatialContainer.h index b2f0e1c..b4a0541 100644 --- a/MbDCode/ASMTSpatialContainer.h +++ b/MbDCode/ASMTSpatialContainer.h @@ -9,18 +9,32 @@ #pragma once #include "ASMTSpatialItem.h" -#include "ASMTRefPoint.h" -#include "ASMTRefCurve.h" -#include "ASMTRefSurface.h" -#include "ASMTPrincipalMassMarker.h" -#include "Units.h" +//#include "ASMTRefPoint.h" +//#include "ASMTRefCurve.h" +//#include "ASMTRefSurface.h" +//#include "ASMTPrincipalMassMarker.h" +//#include "Units.h" +//#include "ASMTPart.h" +//#include "ASMTJoint.h" +//#include "ASMTMotion.h" namespace MbD { + class ASMTRefPoint; + class ASMTRefCurve; + class ASMTRefSurface; + class ASMTPrincipalMassMarker; + class Units; + class ASMTPart; + class ASMTJoint; + class ASMTMotion; + class ASMTMarker; + class ASMTSpatialContainer : public ASMTSpatialItem { // public: void initialize() override; + void setPrincipalMassMarker(std::shared_ptr aJ); void readRefPoints(std::vector& lines); void readRefPoint(std::vector& lines); void readRefCurves(std::vector& lines); @@ -53,6 +67,9 @@ namespace MbD { std::shared_ptr part() override; void updateFromMbD() override; void compareResults(AnalysisType type) override; + void outputResults(AnalysisType type) override; + void addRefPoint(std::shared_ptr refPoint); + void addMarker(std::shared_ptr marker); std::shared_ptr>> refPoints; std::shared_ptr>> refCurves; diff --git a/MbDCode/ASMTSpatialItem.cpp b/MbDCode/ASMTSpatialItem.cpp index ac6c25a..6832a6c 100644 --- a/MbDCode/ASMTSpatialItem.cpp +++ b/MbDCode/ASMTSpatialItem.cpp @@ -10,6 +10,26 @@ using namespace MbD; +void MbD::ASMTSpatialItem::setPosition3D(FColDsptr vec) +{ + position3D = vec; +} + +void MbD::ASMTSpatialItem::setRotationMatrix(FMatDsptr mat) +{ + rotationMatrix = mat; +} + +void MbD::ASMTSpatialItem::setVelocity3D(FColDsptr vec) +{ + velocity3D = vec; +} + +void MbD::ASMTSpatialItem::setOmega3D(FColDsptr vec) +{ + omega3D = vec; +} + void MbD::ASMTSpatialItem::readPosition3D(std::vector& lines) { assert(lines[0].find("Position3D") != std::string::npos); diff --git a/MbDCode/ASMTSpatialItem.h b/MbDCode/ASMTSpatialItem.h index 744f241..77abab9 100644 --- a/MbDCode/ASMTSpatialItem.h +++ b/MbDCode/ASMTSpatialItem.h @@ -5,7 +5,7 @@ * * * See LICENSE file for details about copyright. * ***************************************************************************/ - + #pragma once #include "ASMTItem.h" @@ -15,13 +15,23 @@ namespace MbD { { // public: + void setPosition3D(FColDsptr position3D); + void setRotationMatrix(FMatDsptr rotationMatrix); + void setVelocity3D(FColDsptr velocity3D); + void setOmega3D(FColDsptr omega3D); void readPosition3D(std::vector& lines); void readRotationMatrix(std::vector& lines); void readVelocity3D(std::vector& lines); void readOmega3D(std::vector& lines); - FColDsptr position3D, velocity3D, omega3D; - FMatDsptr rotationMatrix; + FColDsptr position3D = std::make_shared>(3); + FColDsptr velocity3D = std::make_shared>(3); + FColDsptr omega3D = std::make_shared>(3); + FMatDsptr rotationMatrix = std::make_shared>(ListListD{ + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }); }; } diff --git a/MbDCode/ASMTTranslationalMotion.cpp b/MbDCode/ASMTTranslationalMotion.cpp index a39d5f0..ababba8 100644 --- a/MbDCode/ASMTTranslationalMotion.cpp +++ b/MbDCode/ASMTTranslationalMotion.cpp @@ -11,6 +11,9 @@ #include "SymbolicParser.h" #include "BasicUserFunction.h" #include "Constant.h" +#include "ASMTJoint.h" +#include "ZTranslation.h" +#include "ASMTTime.h" using namespace MbD; diff --git a/MbDCode/ASMTTranslationalMotion.h b/MbDCode/ASMTTranslationalMotion.h index 6412733..c830e07 100644 --- a/MbDCode/ASMTTranslationalMotion.h +++ b/MbDCode/ASMTTranslationalMotion.h @@ -9,7 +9,6 @@ #pragma once #include "ASMTMotion.h" -#include "ZTranslation.h" namespace MbD { class ASMTTranslationalMotion : public ASMTMotion diff --git a/MbDCode/CADSystem.cpp b/MbDCode/CADSystem.cpp index c7c6d11..6604279 100644 --- a/MbDCode/CADSystem.cpp +++ b/MbDCode/CADSystem.cpp @@ -49,6 +49,141 @@ void CADSystem::logString(double value) { } +void CADSystem::runOndselSinglePendulum() +{ + //Double pendulum with easy input numbers for exact port from Smalltalk + //GEOAssembly calcCharacteristicDimensions must set mbdUnits to unity. + std::cout << "runOndselSinglePendulum" << 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.04; + 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 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 rotMotion1 = CREATE::With("/Assembly1/Motion1"); + rotMotion1->connectsItoJ(assembly1->partFrame->endFrame("/Assembly1/Marker2"), crankPart1->partFrame->endFrame("/Assembly1/Part1/Marker1")); + std::cout << "rotMotion1->name " << rotMotion1->name << std::endl; + rotMotion1->phiBlk = std::make_shared(1.0); + std::cout << "rotMotion1->phiBlk " << *(rotMotion1->phiBlk) << std::endl; + TheSystem->addJoint(rotMotion1); + // + TheSystem->runKINEMATIC(TheSystem); +} + void CADSystem::runOndselDoublePendulum() { //Double pendulum with easy input numbers for exact port from Smalltalk @@ -65,7 +200,7 @@ void CADSystem::runOndselDoublePendulum() systemSolver->iterMaxPosKine = 25; systemSolver->iterMaxAccKine = 25; systemSolver->tstart = 0.0; - systemSolver->tend = 0.0; + systemSolver->tend = 0.04; systemSolver->hmin = 1.0e-9; systemSolver->hmax = 1.0; systemSolver->hout = 0.04; diff --git a/MbDCode/CADSystem.h b/MbDCode/CADSystem.h index f2271d6..39544da 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 runOndselSinglePendulum(); void runOndselDoublePendulum(); void runOndselPiston(); void runPiston(); diff --git a/MbDCode/ExternalSystem.cpp b/MbDCode/ExternalSystem.cpp index d63943c..0c820b1 100644 --- a/MbDCode/ExternalSystem.cpp +++ b/MbDCode/ExternalSystem.cpp @@ -34,6 +34,7 @@ void MbD::ExternalSystem::outputFor(AnalysisType type) else if (asmtAssembly) { asmtAssembly->updateFromMbD(); asmtAssembly->compareResults(type); + asmtAssembly->outputResults(type); } else { assert(false); diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index 4adb2f3..a0489dd 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -26,18 +26,20 @@ void runSpMat(); int main() { + ASMTAssembly::runSinglePendulum(); ASMTAssembly::runFile("piston.asmt"); ASMTAssembly::runFile("00backhoe.asmt"); ASMTAssembly::runFile("circular.asmt"); - //ASMTAssembly::runFile("cirpendu.asmt"); //Under constrained. Testing ICKine. + 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->runOndselSinglePendulum(); cadSystem->runOndselDoublePendulum(); - cadSystem->runOndselPiston(); + //cadSystem->runOndselPiston(); cadSystem->runPiston(); runSpMat(); } diff --git a/MbDCode/SystemSolver.cpp b/MbDCode/SystemSolver.cpp index c5686f2..936e312 100644 --- a/MbDCode/SystemSolver.cpp +++ b/MbDCode/SystemSolver.cpp @@ -153,6 +153,7 @@ void SystemSolver::runBasicCollision() void SystemSolver::runBasicKinematic() { + if (tstart == tend) return; try { basicIntegrator = CREATE::With(); basicIntegrator->setSystem(this); diff --git a/MbDCode/crank_slider.mbd b/MbDCode/crank_slider.mbd new file mode 100644 index 0000000..9b90721 --- /dev/null +++ b/MbDCode/crank_slider.mbd @@ -0,0 +1,176 @@ +# crank_slider.mbd + +#----------------------------------------------------------------------------- +# [Data Block] + +begin: data; + problem: initial value; +end: data; + +#----------------------------------------------------------------------------- +# [ Block] + +begin: initial value; + initial time: 0.; + final time: 5.; + time step: 1.e-2; + max iterations: 10; + tolerance: 1.e-6; +end: initial value; + +#----------------------------------------------------------------------------- +# [Control Data Block] + +begin: control data; + structural nodes: 4; + rigid bodies: 3; + joints: 6; +end: control data; + +#----------------------------------------------------------------------------- +# Design Variables +set: real Mass_Crank = 1.; +set: real Mass_Conrod = 1.; +set: real Mass_Slider = 1.; +set: real Length_Crank = 0.2; +set: real Length_Conrod = 0.4; +set: real Offset_Slider = 0.05; + +#----------------------------------------------------------------------------- +# Reference Labels +set: integer Ref_Conrod = 1; + +# Node Labels +set: integer Node_Ground = 1; +set: integer Node_Crank = 2; +set: integer Node_Conrod = 3; +set: integer Node_Slider = 4; + +# Body Labels +set: integer Body_Crank = 1; +set: integer Body_Conrod = 2; +set: integer Body_Slider = 3; + +# Joint Labels +set: integer JoClamp_Ground = 1; +set: integer JoAxrot_Ground_Crank = 2; +set: integer JoRevh_Crank_Conrod = 3; +set: integer JoInlin_Conrod_Slider = 4; +set: integer JoInlin_Ground_Slider = 5; +set: integer JoPrism_Ground_Slider = 6; + +#----------------------------------------------------------------------------- +# Intermediate Variables +set: real Izz_Crank = Mass_Crank*Length_Crank^2./12.; +set: real Izz_Conrod = Mass_Conrod*Length_Conrod^2./12.; + +#----------------------------------------------------------------------------- +# References +reference: Ref_Conrod, + Length_Crank, 0., 0., # absolute position + euler, 0., 0., asin(Offset_Slider/Length_Conrod), # absolute orientation + null, # absolute velocity + null; # absolute angular velocity + +#----------------------------------------------------------------------------- +# [Nodes Block] + +begin: nodes; + + #----------------------------------------------------------------------------- + # Nodes + structural: Node_Ground, static, + 0., 0., 0., # absolute position + eye, # absolute orientation + null, # absolute velocity + null; # absolute angular velocity + + structural: Node_Crank, dynamic, + Length_Crank/2., 0., 0., # absolute position + eye, # absolute orientation + null, # absolute velocity + null; # absolute angular velocity + + structural: Node_Conrod, dynamic, + reference, Ref_Conrod, Length_Conrod/2., 0., 0., # absolute position + reference, Ref_Conrod, eye, # absolute orientation + null, # absolute velocity + null; # absolute angular velocity + + structural: Node_Slider, dynamic, + reference, Ref_Conrod, Length_Conrod, 0., 0., # absolute position + eye, # absolute orientation + null, # absolute velocity + null; # absolute angular velocity + +end: nodes; + +#----------------------------------------------------------------------------- +# [Elements Block] + +begin: elements; + + #----------------------------------------------------------------------------- + # Bodies + body: Body_Crank, Node_Crank, + Mass_Crank, # mass + null, # relative center of mass + diag, 1., 1., Izz_Crank; # inertia matrix + + body: Body_Conrod, Node_Conrod, + Mass_Conrod, # mass + null, # relative center of mass + diag, 1., 1., Izz_Conrod; # inertia matrix + + body: Body_Slider, Node_Slider, + Mass_Slider, # mass + null, # relative center of mass + eye; # inertia matrix + + #----------------------------------------------------------------------------- + # Joints + joint: JoClamp_Ground, + clamp, + Node_Ground, + null, # absolute position + eye; # absolute orientation + + joint: JoAxrot_Ground_Crank, + axial rotation, + Node_Ground, + null, # relative offset + hinge, eye, # relative orientation + Node_Crank, + -Length_Crank/2., 0., 0., # relative offset + hinge, eye, # relative orientation + ramp, 2.*pi, 0., 1., 0.; # angular velocity + + joint: JoRevh_Crank_Conrod, + revolute hinge, + Node_Crank, + reference, Ref_Conrod, null, # relative offset + hinge, reference, Ref_Conrod, eye, # relative axis orientation + Node_Conrod, + reference, Ref_Conrod, null, # relative offset + hinge, reference, Ref_Conrod, eye; # relative axis orientation + + joint: JoInlin_Conrod_Slider, + in line, + Node_Conrod, + Length_Conrod/2., 0., 0., # relative line position + eye, # relative orientation + Node_Slider; + + joint: JoInlin_Ground_Slider, + in line, + Node_Ground, + 0., Offset_Slider, 0., # relative line position + 1, 0., 0., -1., 3, 1., 0., 0., # relative orientation + Node_Slider; + + joint: JoPrism_Ground_Slider, + prismatic, + Node_Ground, + Node_Slider; + +end: elements; \ No newline at end of file