Skip to content

Commit

Permalink
AllowRotation and size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
aiksiongkoh committed Jan 15, 2024
1 parent fe99ad2 commit 2c737d4
Show file tree
Hide file tree
Showing 285 changed files with 1,854 additions and 1,116 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ endif()


set(ONDSELSOLVER_SRC
OndselSolver/AllowZRotation.cpp
OndselSolver/AllowZRotationConstraintIqctJqc.cpp
OndselSolver/ASMTAllowRotation.cpp
OndselSolver/Array.cpp
OndselSolver/FullVector.cpp
OndselSolver/RowTypeMatrix.cpp
Expand Down Expand Up @@ -345,6 +348,9 @@ set(ONDSELSOLVER_SRC
)

set(ONDSELSOLVER_HEADERS
OndselSolver/AllowZRotation.h
OndselSolver/AllowZRotationConstraintIqctJqc.h
OndselSolver/ASMTAllowRotation.h
OndselSolver/Array.h
OndselSolver/FullVector.h
OndselSolver/RowTypeMatrix.h
Expand Down
76 changes: 76 additions & 0 deletions OndselSolver/ASMTAllowRotation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/

#include "ASMTAllowRotation.h"
#include "ASMTAssembly.h"
#include "ASMTJoint.h"
#include "AllowZRotation.h"

using namespace MbD;

std::shared_ptr<ASMTAllowRotation> MbD::ASMTAllowRotation::With()
{
auto asmtAllowRotation = std::make_shared<ASMTAllowRotation>();
return asmtAllowRotation;
}

void MbD::ASMTAllowRotation::parseASMT(std::vector<std::string>& lines)
{
readName(lines);
if (lines[0].find("MarkerI") != std::string::npos) {
readMarkerI(lines);
readMarkerJ(lines);
}
readMotionJoint(lines);
}

void MbD::ASMTAllowRotation::readMotionJoint(std::vector<std::string>& lines)
{
assert(lines[0].find("MotionJoint") != std::string::npos);
lines.erase(lines.begin());
motionJoint = readString(lines[0]);
lines.erase(lines.begin());
}

void MbD::ASMTAllowRotation::initMarkers()
{
if (motionJoint == "") {
assert(markerI != "");
assert(markerJ != "");
}
else {
auto jt = root()->jointAt(motionJoint);
markerI = jt->markerI;
markerJ = jt->markerJ;
}
}

std::shared_ptr<Joint> MbD::ASMTAllowRotation::mbdClassNew()
{
return AllowZRotation::With();
}

void MbD::ASMTAllowRotation::setMotionJoint(std::string motionJoint)
{
}

void MbD::ASMTAllowRotation::storeOnLevel(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "AllowRotation");
storeOnLevelString(os, level + 1, "Name");
storeOnLevelString(os, level + 2, name);
ASMTItemIJ::storeOnLevel(os, level);
storeOnLevelString(os, level + 1, "MotionJoint");
storeOnLevelString(os, level + 2, motionJoint);
}

void MbD::ASMTAllowRotation::storeOnTimeSeries(std::ofstream& os)
{
os << "AllowRotationSeries\t" << fullName("") << std::endl;
ASMTItemIJ::storeOnTimeSeries(os);
}
29 changes: 29 additions & 0 deletions OndselSolver/ASMTAllowRotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/

#pragma once

#include "ASMTMotion.h"

namespace MbD {
class ASMTAllowRotation : public ASMTMotion
{
//
public:
static std::shared_ptr<ASMTAllowRotation> With();
void parseASMT(std::vector<std::string>& lines) override;
void readMotionJoint(std::vector<std::string>& lines);
void initMarkers() override;
std::shared_ptr<Joint> mbdClassNew() override;
void setMotionJoint(std::string motionJoint);
void storeOnLevel(std::ofstream& os, size_t level) override;
void storeOnTimeSeries(std::ofstream& os) override;

std::string motionJoint, rotationZ;
};
}
2 changes: 1 addition & 1 deletion OndselSolver/ASMTAngleJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void MbD::ASMTAngleJoint::createMbD(std::shared_ptr<System> mbdSys, std::shared_
angleJoint->theIzJz = theIzJz;
}

void MbD::ASMTAngleJoint::storeOnLevel(std::ofstream& os, int level)
void MbD::ASMTAngleJoint::storeOnLevel(std::ofstream& os, size_t level)
{
ASMTJoint::storeOnLevel(os, level);
storeOnLevelString(os, level + 1, "theIzJz");
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/ASMTAngleJoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MbD {
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;
void storeOnLevel(std::ofstream& os, size_t level) override;

double theIzJz = 0.0;
};
Expand Down
6 changes: 3 additions & 3 deletions OndselSolver/ASMTAnimationParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ using namespace MbD;

void MbD::ASMTAnimationParameters::parseASMT(std::vector<std::string>& lines)
{
//int nframe, icurrent, istart, iend, framesPerSecond;
//size_t nframe, icurrent, istart, iend, framesPerSecond;
//bool isForward;
int pos = (int)lines[0].find_first_not_of("\t");
auto 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 Expand Up @@ -43,7 +43,7 @@ void MbD::ASMTAnimationParameters::parseASMT(std::vector<std::string>& lines)

}

void MbD::ASMTAnimationParameters::storeOnLevel(std::ofstream& os, int level)
void MbD::ASMTAnimationParameters::storeOnLevel(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "AnimationParameters");
storeOnLevelString(os, level + 1, "nframe");
Expand Down
4 changes: 2 additions & 2 deletions OndselSolver/ASMTAnimationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace MbD {
//
public:
void parseASMT(std::vector<std::string>& lines) override;
void storeOnLevel(std::ofstream& os, int level) override;
void storeOnLevel(std::ofstream& os, size_t level) override;

int nframe = 1000000, icurrent = 1, istart = 1, iend = 1000000, framesPerSecond = 30;
size_t nframe = 1000000, icurrent = 1, istart = 1, iend = 1000000, framesPerSecond = 30;
bool isForward = true;


Expand Down
40 changes: 22 additions & 18 deletions OndselSolver/ASMTAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ASMTSphericalJoint.h"
#include "ASMTFixedJoint.h"
#include "ASMTGeneralMotion.h"
#include "ASMTAllowRotation.h"
#include "ASMTUniversalJoint.h"
#include "ASMTPointInPlaneJoint.h"
#include "ASMTPrincipalMassMarker.h"
Expand Down Expand Up @@ -692,6 +693,9 @@ void MbD::ASMTAssembly::readMotions(std::vector<std::string>& lines)
else if (motionsLines[0] == "\t\t\tGeneralMotion") {
motion = CREATE<ASMTGeneralMotion>::With();
}
else if (motionsLines[0] == "\t\t\tAllowRotation") {
motion = CREATE<ASMTAllowRotation>::With();
}
else {
assert(false);
}
Expand Down Expand Up @@ -809,7 +813,7 @@ void MbD::ASMTAssembly::readJointSeriesMany(std::vector<std::string>& lines)
if (lines.empty()) return;
assert(lines[0].find("JointSeries") != std::string::npos);
auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) {
return s.find("MotionSeries") != std::string::npos;
return s.find("tionSeries") != std::string::npos;
});
std::vector<std::string> jointSeriesLines(lines.begin(), it);
while (!jointSeriesLines.empty()) {
Expand Down Expand Up @@ -885,7 +889,7 @@ void MbD::ASMTAssembly::readJointSeries(std::vector<std::string>& lines)
void MbD::ASMTAssembly::readMotionSeriesMany(std::vector<std::string>& lines)
{
while (!lines.empty()) {
assert(lines[0].find("MotionSeries") != std::string::npos);
assert(lines[0].find("tionSeries") != std::string::npos);
readMotionSeries(lines);
}
}
Expand All @@ -894,7 +898,7 @@ void MbD::ASMTAssembly::readMotionSeries(std::vector<std::string>& lines)
{
if (lines.empty()) return;
std::string str = lines[0];
std::string substr = "MotionSeries";
std::string substr = "tionSeries";
auto pos = str.find(substr);
assert(pos != std::string::npos);
str.erase(0, pos + substr.length());
Expand Down Expand Up @@ -941,9 +945,9 @@ double MbD::ASMTAssembly::calcCharacteristicTime()

double MbD::ASMTAssembly::calcCharacteristicMass()
{
auto n = (int)parts->size();
auto n = parts->size();
double sumOfSquares = 0.0;
for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
auto mass = parts->at(i)->principalMassMarker->mass;
sumOfSquares += mass * mass;
Expand All @@ -964,9 +968,9 @@ double MbD::ASMTAssembly::calcCharacteristicLength()
auto& mkrJ = markerMap->at(connector->markerJ);
lengths->push_back(mkrJ->rpmp()->length());
}
auto n = (int)lengths->size();
auto n = 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));
auto unitLength = std::sqrt(sumOfSquares / std::max(n, size_t(1)));
if (unitLength <= 0) unitLength = 1.0;
return unitLength;
}
Expand Down Expand Up @@ -1062,7 +1066,7 @@ void MbD::ASMTAssembly::outputFile(std::string filename)
// }
}

void MbD::ASMTAssembly::storeOnLevel(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevel(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Assembly");
storeOnLevelNotes(os, level + 1);
Expand Down Expand Up @@ -1291,61 +1295,61 @@ std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partPartialNamed(std::string partia
return part;
}

void MbD::ASMTAssembly::storeOnLevelNotes(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelNotes(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Notes");
storeOnLevelString(os, level + 1, notes);
}

void MbD::ASMTAssembly::storeOnLevelParts(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelParts(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Parts");
for (auto& part : *parts) {
part->storeOnLevel(os, level + 1);
}
}

void MbD::ASMTAssembly::storeOnLevelKinematicIJs(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelKinematicIJs(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "KinematicIJs");
for (auto& kinematicIJ : *kinematicIJs) {
kinematicIJ->storeOnLevel(os, level);
}
}

void MbD::ASMTAssembly::storeOnLevelConstraintSets(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelConstraintSets(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "ConstraintSets");
storeOnLevelJoints(os, level + 1);
storeOnLevelMotions(os, level + 1);
storeOnLevelGeneralConstraintSets(os, level + 1);
}

void MbD::ASMTAssembly::storeOnLevelForceTorques(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelForceTorques(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "ForceTorques");
for (auto& forceTorque : *forcesTorques) {
forceTorque->storeOnLevel(os, level + 1);
}
}

void MbD::ASMTAssembly::storeOnLevelJoints(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelJoints(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Joints");
for (auto& joint : *joints) {
joint->storeOnLevel(os, level + 1);
}
}

void MbD::ASMTAssembly::storeOnLevelMotions(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelMotions(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Motions");
for (auto& motion : *motions) {
motion->storeOnLevel(os, level + 1);
}
}

void MbD::ASMTAssembly::storeOnLevelGeneralConstraintSets(std::ofstream& os, int level)
void MbD::ASMTAssembly::storeOnLevelGeneralConstraintSets(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "GeneralConstraintSets");
//for (auto& generalConstraintSet : *generalConstraintSets) {
Expand All @@ -1358,13 +1362,13 @@ void MbD::ASMTAssembly::storeOnTimeSeries(std::ofstream& os)
if (times->empty()) return;
os << "TimeSeries" << std::endl;
os << "Number\tInput\t";
for (int i = 1; i < (int)times->size(); i++)
for (size_t i = 1; i < times->size(); i++)
{
os << i << '\t';
}
os << std::endl;
os << "Time\tInput\t";
for (int i = 1; i < (int)times->size(); i++)
for (size_t i = 1; i < times->size(); i++)
{
os << times->at(i) << '\t';
}
Expand Down
18 changes: 9 additions & 9 deletions OndselSolver/ASMTAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace MbD {
void deleteMbD() override;
void createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits) override;
void outputFile(std::string filename);
void storeOnLevel(std::ofstream& os, int level) override;
void storeOnLevel(std::ofstream& os, size_t level) override;

/* This function performs a one shot solve of the assembly.*/
void solve();
Expand Down Expand Up @@ -109,14 +109,14 @@ namespace MbD {
void setSimulationParameters(std::shared_ptr<ASMTSimulationParameters> simulationParameters);
std::shared_ptr<ASMTPart> partNamed(std::string partName);
std::shared_ptr<ASMTPart> partPartialNamed(std::string partialName);
void storeOnLevelNotes(std::ofstream& os, int level);
void storeOnLevelParts(std::ofstream& os, int level);
void storeOnLevelKinematicIJs(std::ofstream& os, int level);
void storeOnLevelConstraintSets(std::ofstream& os, int level);
void storeOnLevelForceTorques(std::ofstream& os, int level);
void storeOnLevelJoints(std::ofstream& os, int level);
void storeOnLevelMotions(std::ofstream& os, int level);
void storeOnLevelGeneralConstraintSets(std::ofstream& os, int level);
void storeOnLevelNotes(std::ofstream& os, size_t level);
void storeOnLevelParts(std::ofstream& os, size_t level);
void storeOnLevelKinematicIJs(std::ofstream& os, size_t level);
void storeOnLevelConstraintSets(std::ofstream& os, size_t level);
void storeOnLevelForceTorques(std::ofstream& os, size_t level);
void storeOnLevelJoints(std::ofstream& os, size_t level);
void storeOnLevelMotions(std::ofstream& os, size_t level);
void storeOnLevelGeneralConstraintSets(std::ofstream& os, size_t level);
void storeOnTimeSeries(std::ofstream& os) override;
void setFilename(std::string filename);

Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/ASMTCompoundJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MbD::ASMTCompoundJoint::createMbD(std::shared_ptr<System> mbdSys, std::shar
compoundJoint->distanceIJ = distanceIJ;
}

void MbD::ASMTCompoundJoint::storeOnLevel(std::ofstream& os, int level)
void MbD::ASMTCompoundJoint::storeOnLevel(std::ofstream& os, size_t level)
{
ASMTJoint::storeOnLevel(os, level);
storeOnLevelString(os, level + 1, "distanceIJ");
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/ASMTCompoundJoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace MbD {
void parseASMT(std::vector<std::string>& lines) override;
void readDistanceIJ(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;
void storeOnLevel(std::ofstream& os, size_t level) override;

double distanceIJ = 0.0;

Expand Down
Loading

0 comments on commit 2c737d4

Please sign in to comment.