Skip to content

Commit

Permalink
dragging log for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
aiksiongkoh committed Apr 22, 2024
1 parent 041fa1c commit 5e19e4a
Show file tree
Hide file tree
Showing 36 changed files with 15,403 additions and 14,984 deletions.
38 changes: 36 additions & 2 deletions OndselSolver/ASMTAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ void MbD::ASMTAssembly::createMbD(std::shared_ptr<System> mbdSys, std::shared_pt
void MbD::ASMTAssembly::outputFile(std::string filename)
{
std::ofstream os(filename);
os << std::setprecision(static_cast<std::streamsize>(std::numeric_limits<double>::digits10) + 1);
os << std::setprecision(std::numeric_limits<double>::max_digits10);
// try {
os << "OndselSolver" << std::endl;
storeOnLevel(os, 0);
Expand Down Expand Up @@ -1227,6 +1227,13 @@ void MbD::ASMTAssembly::solve()

void MbD::ASMTAssembly::runPreDrag()
{
debug = true; //Comment out in release build.
if (debug) {
outputFile("runPreDrag.asmt");
std::ofstream os("dragging.log");
os << "runPreDrag" << std::endl;
os.close();
}
mbdSystem = std::make_shared<System>();
mbdSystem->externalSystem->asmtAssembly = this;
try {
Expand All @@ -1239,8 +1246,21 @@ void MbD::ASMTAssembly::runPreDrag()

void MbD::ASMTAssembly::runDragStep(std::shared_ptr<std::vector<std::shared_ptr<ASMTPart>>> dragParts) const
{
if (debug) {
std::ofstream os("dragging.log", std::ios_base::app);
os << "runDragStep" << std::endl;
os.close();
}
auto dragMbDParts = std::make_shared<std::vector<std::shared_ptr<Part>>>();
for (auto& dragPart : *dragParts) {
if (debug) {
std::ofstream os("dragging.log", std::ios_base::app);
os << std::setprecision(std::numeric_limits<double>::max_digits10);
dragPart->storeOnLevelName(os, 1);
dragPart->storeOnLevelPositionRaw(os, 1);
dragPart->storeOnLevelRotationMatrixRaw(os, 1);
os.close();
}
auto dragMbDPart = std::static_pointer_cast<Part>(dragPart->mbdObject);
dragMbDParts->push_back(dragMbDPart);
}
Expand All @@ -1249,7 +1269,21 @@ void MbD::ASMTAssembly::runDragStep(std::shared_ptr<std::vector<std::shared_ptr<

void MbD::ASMTAssembly::runPostDrag()
{
runPreDrag();
if (debug) {
//outputFile("runPostDrag.asmt");
std::ofstream os("dragging.log", std::ios_base::app);
os << "runPostDrag" << std::endl;
os.close();
}
debug = false;
mbdSystem = std::make_shared<System>();
mbdSystem->externalSystem->asmtAssembly = this;
try {
mbdSystem->runPreDrag(mbdSystem);
}
catch (SimulationStoppingError ex) {

}
}

void MbD::ASMTAssembly::runKINEMATIC()
Expand Down
2 changes: 2 additions & 0 deletions OndselSolver/ASMTAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ namespace MbD {
std::shared_ptr<Units> mbdUnits = std::make_shared<Units>();
std::shared_ptr<System> mbdSystem;
MBDynSystem* mbdynItem = nullptr;
bool debug = false;

};
}

4 changes: 2 additions & 2 deletions OndselSolver/ASMTItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace MbD {
virtual void storeOnLevelBool(std::ofstream& os, size_t level, bool value);
//template<typename T>
//void storeOnLevelArray(std::ofstream& os, size_t level, std::vector<T> array);
void storeOnLevelArray(std::ofstream& os, size_t level, std::vector<double> array);
void storeOnLevelName(std::ofstream& os, size_t level);
virtual void storeOnLevelArray(std::ofstream& os, size_t level, std::vector<double> array);
virtual void storeOnLevelName(std::ofstream& os, size_t level);
virtual void storeOnTimeSeries(std::ofstream& os);
void logString(std::string& str);
void logString(const char* chars);
Expand Down
1 change: 1 addition & 0 deletions OndselSolver/ASMTPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* *
* See LICENSE file for details about copyright. *
***************************************************************************/
#include <ostream>
#include <fstream>

#include "ASMTPart.h"
Expand Down
15 changes: 15 additions & 0 deletions OndselSolver/ASMTSpatialItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ void MbD::ASMTSpatialItem::storeOnLevelPosition(std::ofstream& os, size_t level)
}
}

void MbD::ASMTSpatialItem::storeOnLevelPositionRaw(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "Position3D");
storeOnLevelArray(os, level + 1, *position3D);
}

void MbD::ASMTSpatialItem::storeOnLevelRotationMatrix(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "RotationMatrix");
Expand All @@ -135,6 +141,15 @@ void MbD::ASMTSpatialItem::storeOnLevelRotationMatrix(std::ofstream& os, size_t

}

void MbD::ASMTSpatialItem::storeOnLevelRotationMatrixRaw(std::ofstream& os, size_t level)
{
storeOnLevelString(os, level, "RotationMatrix");
for (size_t i = 0; i < 3; i++)
{
storeOnLevelArray(os, level + 1, *rotationMatrix->at(i));
}
}

FColDsptr MbD::ASMTSpatialItem::getPosition3D(size_t i)
{
auto vec3 = std::make_shared<FullColumn<double>>(3);
Expand Down
2 changes: 2 additions & 0 deletions OndselSolver/ASMTSpatialItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace MbD {
double v31, double v32, double v33);
void storeOnLevel(std::ofstream& os, size_t level) override;
void storeOnLevelPosition(std::ofstream& os, size_t level);
void storeOnLevelPositionRaw(std::ofstream& os, size_t level);
void storeOnLevelRotationMatrix(std::ofstream& os, size_t level);
void storeOnLevelRotationMatrixRaw(std::ofstream& os, size_t level);
FColDsptr getPosition3D(size_t i);
FMatDsptr getRotationMatrix(size_t i);

Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/MBDynSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void MbD::MBDynSystem::outputFiles()
//auto& asmtJoints = asmtAsm->joints;
//auto& asmtMotions = asmtAsm->motions;
std::ofstream os(movFile);
os << std::setprecision(static_cast<std::streamsize>(std::numeric_limits<double>::digits10) + 1);
os << std::setprecision(std::numeric_limits<double>::max_digits10);
for (size_t i = 1; i < asmtTimes->size(); i++)
{
for (auto& node : *nodes) {
Expand Down
20 changes: 20 additions & 0 deletions OndselSolver/dragging.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
runPreDrag
runDragStep
Name
Part1
Position3D
4.801714581503802e-15 0.099999999999995245 0.19999999999999998
RotationMatrix
1 -4.7573992180162559e-14 0
4.7573992180162559e-14 1 0
0 0 1
runDragStep
Name
Part1
Position3D
0.2633974596215562 0.063397459621556157 0
RotationMatrix
0.86602540378443871 -0.49999999999999994 0
0.49999999999999994 0.86602540378443871 0
0 0 1
runPostDrag
Loading

0 comments on commit 5e19e4a

Please sign in to comment.