Skip to content

Commit

Permalink
Merge pull request #36 from Ondsel-Development/MBDynIC2
Browse files Browse the repository at this point in the history
Merging ASMT and MBDyn joints
  • Loading branch information
JohnAD authored Nov 29, 2023
2 parents 810c8d2 + 97f7f6b commit ee1d97e
Show file tree
Hide file tree
Showing 244 changed files with 44,342 additions and 2,618 deletions.
50 changes: 50 additions & 0 deletions OndselSolver/ASMTAngleJoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/
#include <fstream>

#include "ASMTAngleJoint.h"
#include "AngleJoint.h"

using namespace MbD;

std::shared_ptr<Joint> MbD::ASMTAngleJoint::mbdClassNew()
{
return CREATE<AngleJoint>::With();
}

void MbD::ASMTAngleJoint::parseASMT(std::vector<std::string>& lines)
{
ASMTJoint::parseASMT(lines);
readTheIzJz(lines);
}

void MbD::ASMTAngleJoint::readTheIzJz(std::vector<std::string>& lines)
{
if (lines[0].find("theIzJz") == std::string::npos) {
theIzJz = 0.0;
}
else {
lines.erase(lines.begin());
theIzJz = readDouble(lines[0]);
lines.erase(lines.begin());
}
}

void MbD::ASMTAngleJoint::createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits)
{
ASMTJoint::createMbD(mbdSys, mbdUnits);
auto angleJoint = std::static_pointer_cast<AngleJoint>(mbdObject);
angleJoint->theIzJz = theIzJz;
}

void MbD::ASMTAngleJoint::storeOnLevel(std::ofstream& os, int level)
{
ASMTJoint::storeOnLevel(os, level);
storeOnLevelString(os, level + 1, "theIzJz");
storeOnLevelDouble(os, level + 2, theIzJz);
}
27 changes: 27 additions & 0 deletions OndselSolver/ASMTAngleJoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/

#pragma once

#include "ASMTJoint.h"

namespace MbD {
class EXPORT ASMTAngleJoint : public ASMTJoint
{
//
public:
std::shared_ptr<Joint> mbdClassNew() override;
void parseASMT(std::vector<std::string>& lines) override;
void readTheIzJz(std::vector<std::string>& lines);
void createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits) override;
void storeOnLevel(std::ofstream& os, int level) override;

double theIzJz = 0.0;
};
}

2 changes: 1 addition & 1 deletion OndselSolver/ASMTAnimationParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void MbD::ASMTAnimationParameters::parseASMT(std::vector<std::string>& lines)
{
//int nframe, icurrent, istart, iend, framesPerSecond;
//bool isForward;
size_t pos = lines[0].find_first_not_of("\t");
int pos = lines[0].find_first_not_of("\t");
auto leadingTabs = lines[0].substr(0, pos);
assert(lines[0] == (leadingTabs + "nframe"));
lines.erase(lines.begin());
Expand Down
127 changes: 97 additions & 30 deletions OndselSolver/ASMTAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@
#include "ASMTItemIJ.h"
#include "ASMTKinematicIJ.h"
#include <iomanip>
#include "ASMTAngleJoint.h"
#include "ASMTConstantVelocityJoint.h"
#include "ASMTCylSphJoint.h"
#include "ASMTGearJoint.h"
#include "ASMTPointInLineJoint.h"
#include "ASMTRevCylJoint.h"
#include "ASMTSphSphJoint.h"
#include "ASMTLineInPlaneJoint.h"
#include "ASMTPlanarJoint.h"
#include "ASMTNoRotationJoint.h"
#include "ASMTParallelAxesJoint.h"
#include "ASMTPerpendicularJoint.h"
#include "ASMTRackPinionJoint.h"
#include "ASMTScrewJoint.h"
#include "SimulationStoppingError.h"

using namespace MbD;

Expand Down Expand Up @@ -386,6 +401,7 @@ void MbD::ASMTAssembly::runFile(const char* fileName)
if (lines[0] == "Assembly") {
lines.erase(lines.begin());
auto assembly = CREATE<ASMTAssembly>::With();
assembly->setFilename(fileName);
assembly->parseASMT(lines);
assembly->runKINEMATIC();
}
Expand Down Expand Up @@ -528,24 +544,70 @@ void MbD::ASMTAssembly::readJoints(std::vector<std::string>& lines)
std::vector<std::string> jointsLines(lines.begin(), it);
std::shared_ptr<ASMTJoint> joint;
while (!jointsLines.empty()) {
if (jointsLines[0] == "\t\t\tRevoluteJoint") {
joint = CREATE<ASMTRevoluteJoint>::With();
if (jointsLines[0] == "\t\t\tAngleJoint") {
joint = CREATE<ASMTAngleJoint>::With();
}
else if (jointsLines[0] == "\t\t\tCylindricalJoint") {
joint = CREATE<ASMTCylindricalJoint>::With();
else if (jointsLines[0] == "\t\t\tGearJoint") {
joint = CREATE<ASMTGearJoint>::With();
}
else if (jointsLines[0] == "\t\t\tTranslationalJoint") {
joint = CREATE<ASMTTranslationalJoint>::With();
else if (jointsLines[0] == "\t\t\tNoRotationJoint") {
joint = CREATE<ASMTNoRotationJoint>::With();
}
else if (jointsLines[0] == "\t\t\tSphericalJoint") {
joint = CREATE<ASMTSphericalJoint>::With();
else if (jointsLines[0] == "\t\t\tParallelAxesJoint") {
joint = CREATE<ASMTParallelAxesJoint>::With();
}
else if (jointsLines[0] == "\t\t\tPerpendicularJoint") {
joint = CREATE<ASMTPerpendicularJoint>::With();
}
else if (jointsLines[0] == "\t\t\tRackPinionJoint") {
joint = CREATE<ASMTRackPinionJoint>::With();
}
else if (jointsLines[0] == "\t\t\tScrewJoint") {
joint = CREATE<ASMTScrewJoint>::With();
}
//AtPointJoints
else if (jointsLines[0] == "\t\t\tConstantVelocityJoint") {
joint = CREATE<ASMTConstantVelocityJoint>::With();
}
else if (jointsLines[0] == "\t\t\tFixedJoint") {
joint = CREATE<ASMTFixedJoint>::With();
}
else if (jointsLines[0] == "\t\t\tRevoluteJoint") {
joint = CREATE<ASMTRevoluteJoint>::With();
}
else if (jointsLines[0] == "\t\t\tSphericalJoint") {
joint = CREATE<ASMTSphericalJoint>::With();
}
else if (jointsLines[0] == "\t\t\tUniversalJoint") {
joint = CREATE<ASMTUniversalJoint>::With();
}
//CompoundJoints
else if (jointsLines[0] == "\t\t\tCylSphJoint") {
joint = CREATE<ASMTCylSphJoint>::With();
}
else if (jointsLines[0] == "\t\t\tRevCylJoint") {
joint = CREATE<ASMTRevCylJoint>::With();
}
else if (jointsLines[0] == "\t\t\tSphSphJoint") {
joint = CREATE<ASMTSphSphJoint>::With();
}
//InLineJoints
else if (jointsLines[0] == "\t\t\tCylindricalJoint") {
joint = CREATE<ASMTCylindricalJoint>::With();
}
else if (jointsLines[0] == "\t\t\tPointInLineJoint") {
joint = CREATE<ASMTPointInLineJoint>::With();
}
else if (jointsLines[0] == "\t\t\tTranslationalJoint") {
joint = CREATE<ASMTTranslationalJoint>::With();
}
//InPlaneJoints
else if (jointsLines[0] == "\t\t\tLineInPlaneJoint") {
joint = CREATE<ASMTLineInPlaneJoint>::With();
}
else if (jointsLines[0] == "\t\t\tPlanarJoint") {
joint = CREATE<ASMTPlanarJoint>::With();
}
else if (jointsLines[0] == "\t\t\tPointInPlaneJoint") {
joint = CREATE<ASMTPointInPlaneJoint>::With();
}
Expand Down Expand Up @@ -790,16 +852,6 @@ void MbD::ASMTAssembly::outputFor(AnalysisType type)
assert(false);
}

void MbD::ASMTAssembly::logString(std::string& str)
{
assert(false);
}

void MbD::ASMTAssembly::logString(double value)
{
assert(false);
}

void MbD::ASMTAssembly::preMbDrun(std::shared_ptr<System> mbdSys)
{
calcCharacteristicDimensions();
Expand Down Expand Up @@ -830,7 +882,7 @@ double MbD::ASMTAssembly::calcCharacteristicTime()

double MbD::ASMTAssembly::calcCharacteristicMass()
{
auto n = parts->size();
auto n = (int)parts->size();
double sumOfSquares = 0.0;
for (int i = 0; i < n; i++)
{
Expand All @@ -853,7 +905,7 @@ double MbD::ASMTAssembly::calcCharacteristicLength()
auto& mkrJ = markerMap->at(connector->markerJ);
lengths->push_back(mkrJ->rpmp()->length());
}
auto n = lengths->size();
auto n = (int)lengths->size();
double sumOfSquares = std::accumulate(lengths->begin(), lengths->end(), 0.0, [](double sum, double l) { return sum + l * l; });
auto unitLength = std::sqrt(sumOfSquares / std::max((int)n, 1));
if (unitLength <= 0) unitLength = 1.0;
Expand Down Expand Up @@ -987,7 +1039,12 @@ void MbD::ASMTAssembly::runKINEMATIC()
auto mbdSystem = std::make_shared<System>();
mbdObject = mbdSystem;
mbdSystem->externalSystem->asmtAssembly = this;
mbdSystem->runKINEMATIC(mbdSystem);
try {
mbdSystem->runKINEMATIC(mbdSystem);
}
catch (SimulationStoppingError ex) {

}
}

void MbD::ASMTAssembly::initprincipalMassMarker()
Expand Down Expand Up @@ -1072,8 +1129,9 @@ std::shared_ptr<ASMTTime> MbD::ASMTAssembly::geoTime()
void MbD::ASMTAssembly::updateFromMbD()
{
ASMTSpatialContainer::updateFromMbD();
times->push_back(asmtTime->getValue());
std::cout << "Time = " << asmtTime->getValue() << std::endl;
auto time = asmtTime->getValue();
times->push_back(time);
std::cout << "Time = " << time << std::endl;
for (auto& part : *parts) part->updateFromMbD();
for (auto& joint : *joints) joint->updateFromMbD();
for (auto& motion : *motions) motion->updateFromMbD();
Expand All @@ -1091,11 +1149,11 @@ void MbD::ASMTAssembly::compareResults(AnalysisType 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);
//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<ASMTPart> part)
Expand Down Expand Up @@ -1215,13 +1273,13 @@ void MbD::ASMTAssembly::storeOnTimeSeries(std::ofstream& os)
if (times->empty()) return;
os << "TimeSeries" << std::endl;
os << "Number\tInput\t";
for (size_t i = 1; i < times->size(); i++)
for (int i = 1; i < times->size(); i++)
{
os << i << '\t';
}
os << std::endl;
os << "Time\tInput\t";
for (size_t i = 1; i < times->size(); i++)
for (int i = 1; i < times->size(); i++)
{
os << times->at(i) << '\t';
}
Expand All @@ -1233,4 +1291,13 @@ void MbD::ASMTAssembly::storeOnTimeSeries(std::ofstream& os)
for (auto& motion : *motions) motion->storeOnTimeSeries(os);
}

void MbD::ASMTAssembly::setFilename(std::string str)
{
std::stringstream ss;
ss << "FileName = " << str << std::endl;
auto str2 = ss.str();
logString(str2);
filename = str;
}


4 changes: 2 additions & 2 deletions OndselSolver/ASMTAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ namespace MbD {
void readMotionSeries(std::vector<std::string>& lines);

void outputFor(AnalysisType type);
void logString(std::string& str);
void logString(double value);
void preMbDrun(std::shared_ptr<System> mbdSys);
void postMbDrun();
void calcCharacteristicDimensions();
Expand Down Expand Up @@ -122,7 +120,9 @@ namespace MbD {
void storeOnLevelMotions(std::ofstream& os, int level);
void storeOnLevelGeneralConstraintSets(std::ofstream& os, int level);
void storeOnTimeSeries(std::ofstream& os) override;
void setFilename(std::string filename);

std::string filename = "";
std::string notes = "(Text string: '' runs: (Core.RunArray runs: #() values: #()))";
std::shared_ptr<std::vector<std::shared_ptr<ASMTPart>>> parts = std::make_shared<std::vector<std::shared_ptr<ASMTPart>>>();
std::shared_ptr<std::vector<std::shared_ptr<ASMTKinematicIJ>>> kinematicIJs = std::make_shared<std::vector<std::shared_ptr<ASMTKinematicIJ>>>();
Expand Down
1 change: 1 addition & 0 deletions OndselSolver/ASMTAtPointJoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "ASMTAtPointJoint.h"
20 changes: 20 additions & 0 deletions OndselSolver/ASMTAtPointJoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/

#pragma once

#include "ASMTJoint.h"

namespace MbD {
class EXPORT ASMTAtPointJoint : public ASMTJoint
{
//
public:

};
}
45 changes: 45 additions & 0 deletions OndselSolver/ASMTCompoundJoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/
#include <fstream>

#include "ASMTCompoundJoint.h"
#include "CompoundJoint.h"

using namespace MbD;

void MbD::ASMTCompoundJoint::parseASMT(std::vector<std::string>& lines)
{
ASMTJoint::parseASMT(lines);
readDistanceIJ(lines);
}

void MbD::ASMTCompoundJoint::readDistanceIJ(std::vector<std::string>& lines)
{
if (lines[0].find("distanceIJ") == std::string::npos) {
distanceIJ = 0.0;
}
else {
lines.erase(lines.begin());
distanceIJ = readDouble(lines[0]);
lines.erase(lines.begin());
}
}

void MbD::ASMTCompoundJoint::createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits)
{
ASMTJoint::createMbD(mbdSys, mbdUnits);
auto compoundJoint = std::static_pointer_cast<CompoundJoint>(mbdObject);
compoundJoint->distanceIJ = distanceIJ;
}

void MbD::ASMTCompoundJoint::storeOnLevel(std::ofstream& os, int level)
{
ASMTJoint::storeOnLevel(os, level);
storeOnLevelString(os, level + 1, "distanceIJ");
storeOnLevelDouble(os, level + 2, distanceIJ);
}
Loading

0 comments on commit ee1d97e

Please sign in to comment.