MBDyn initial commit
This commit is contained in:
13
MbDCode/APIExport.h
Normal file
13
MbDCode/APIExport.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTAnimationParameters : public ASMTItem
|
||||
class EXPORT ASMTAnimationParameters : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -43,6 +43,50 @@
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::ASMTAssembly::runSinglePendulumSuperSimplified()
|
||||
{
|
||||
//In this version we skip declaration of variables that don't need as they use default values.
|
||||
auto assembly = CREATE<ASMTAssembly>::With();
|
||||
|
||||
assembly->setName("Assembly1");
|
||||
|
||||
auto mkr = CREATE<ASMTMarker>::With();
|
||||
mkr->setName("Marker1");
|
||||
assembly->addMarker(mkr);
|
||||
|
||||
auto part = CREATE<ASMTPart>::With();
|
||||
part->setName("Part1");
|
||||
part->setPosition3D(-0.1, -0.1, -0.1);
|
||||
assembly->addPart(part);
|
||||
|
||||
mkr = CREATE<ASMTMarker>::With();
|
||||
mkr->setName("Marker1");
|
||||
mkr->setPosition3D(0.1, 0.1, 0.1);
|
||||
part->addMarker(mkr);
|
||||
|
||||
auto joint = CREATE<ASMTRevoluteJoint>::With();
|
||||
joint->setName("Joint1");
|
||||
joint->setMarkerI("/Assembly1/Marker1");
|
||||
joint->setMarkerJ("/Assembly1/Part1/Marker1");
|
||||
assembly->addJoint(joint);
|
||||
|
||||
auto motion = CREATE<ASMTRotationalMotion>::With();
|
||||
motion->setName("Motion1");
|
||||
motion->setMotionJoint("/Assembly1/Joint1");
|
||||
motion->setRotationZ("0.0");
|
||||
assembly->addMotion(motion);
|
||||
|
||||
auto simulationParameters = CREATE<ASMTSimulationParameters>::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::runSinglePendulumSimplified()
|
||||
{
|
||||
@@ -265,7 +309,7 @@ void MbD::ASMTAssembly::runSinglePendulum()
|
||||
assembly->runKINEMATIC();
|
||||
}
|
||||
|
||||
void MbD::ASMTAssembly::runFile(const char* chars)
|
||||
void MbD::ASMTAssembly::runFile(const char* fileName)
|
||||
{
|
||||
std::ifstream stream(fileName);
|
||||
if(stream.fail()) {
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace MbD {
|
||||
{
|
||||
//
|
||||
public:
|
||||
static void runSinglePendulumSuperSimplified();
|
||||
static void runSinglePendulumSimplified();
|
||||
static void runSinglePendulum();
|
||||
static void runFile(const char* chars);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace MbD {
|
||||
class System;
|
||||
class Units;
|
||||
|
||||
class ASMTConstantGravity : public ASMTItem
|
||||
class EXPORT ASMTConstantGravity : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace MbD {
|
||||
class Joint;
|
||||
|
||||
class ASMTConstraintSet : public ASMTItemIJ
|
||||
class EXPORT ASMTConstraintSet : public ASMTItemIJ
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "CylindricalJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTCylindricalJoint : public ASMTJoint
|
||||
class EXPORT ASMTCylindricalJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTExtrusion : public ASMTItem
|
||||
class EXPORT ASMTExtrusion : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "FixedJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTFixedJoint : public ASMTJoint
|
||||
class EXPORT ASMTFixedJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTItemIJ.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTForceTorque : public ASMTItemIJ
|
||||
class EXPORT ASMTForceTorque : public ASMTItemIJ
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTMotion.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTGeneralMotion : public ASMTMotion
|
||||
class EXPORT ASMTGeneralMotion : public ASMTMotion
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
#include "CREATE.h"
|
||||
#include "APIExport.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTAssembly;
|
||||
class Units;
|
||||
class ASMTSpatialContainer;
|
||||
|
||||
class ASMTItem
|
||||
class EXPORT ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTItemIJ : public ASMTItem
|
||||
class EXPORT ASMTItemIJ : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "ForceTorqueData.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTJoint : public ASMTConstraintSet
|
||||
class EXPORT ASMTJoint : public ASMTConstraintSet
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "FullMatrix.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTMarker : public ASMTSpatialItem
|
||||
class EXPORT ASMTMarker : public ASMTSpatialItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "ForceTorqueData.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTMotion : public ASMTConstraintSet
|
||||
class EXPORT ASMTMotion : public ASMTConstraintSet
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace MbD {
|
||||
class PosVelAccData;
|
||||
|
||||
class ASMTPart : public ASMTSpatialContainer
|
||||
class EXPORT ASMTPart : public ASMTSpatialContainer
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTPointInPlaneJoint : public ASMTJoint
|
||||
class EXPORT ASMTPointInPlaneJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTSpatialItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTPrincipalMassMarker : public ASMTSpatialItem
|
||||
class EXPORT ASMTPrincipalMassMarker : public ASMTSpatialItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTRefItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTRefCurve : public ASMTRefItem
|
||||
class EXPORT ASMTRefCurve : public ASMTRefItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace MbD {
|
||||
|
||||
class ASMTRefItem : public ASMTSpatialItem
|
||||
class EXPORT ASMTRefItem : public ASMTSpatialItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace MbD {
|
||||
class ASMTRefPoint : public ASMTRefItem
|
||||
class EXPORT ASMTRefPoint : public ASMTRefItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTRefItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTRefSurface : public ASMTRefItem
|
||||
class EXPORT ASMTRefSurface : public ASMTRefItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTRevoluteJoint : public ASMTJoint
|
||||
class EXPORT ASMTRevoluteJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "ZRotation.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTRotationalMotion : public ASMTMotion
|
||||
class EXPORT ASMTRotationalMotion : public ASMTMotion
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTSimulationParameters : public ASMTItem
|
||||
class EXPORT ASMTSimulationParameters : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace MbD {
|
||||
class ASMTMotion;
|
||||
class ASMTMarker;
|
||||
|
||||
class ASMTSpatialContainer : public ASMTSpatialItem
|
||||
class EXPORT ASMTSpatialContainer : public ASMTSpatialItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -15,6 +15,13 @@ void MbD::ASMTSpatialItem::setPosition3D(FColDsptr vec)
|
||||
position3D = vec;
|
||||
}
|
||||
|
||||
void MbD::ASMTSpatialItem::setQuarternions(double q0, double q1, double q2, double q3)
|
||||
{
|
||||
auto eulerParameters = CREATE<EulerParameters<double>>::With(ListD{ q1, q2, q3, q0 });
|
||||
eulerParameters->calc();
|
||||
rotationMatrix = eulerParameters->aA;
|
||||
}
|
||||
|
||||
void MbD::ASMTSpatialItem::setRotationMatrix(FMatDsptr mat)
|
||||
{
|
||||
rotationMatrix = mat;
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
#include "ASMTItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTSpatialItem : public ASMTItem
|
||||
class EXPORT ASMTSpatialItem : public ASMTItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
void setPosition3D(FColDsptr position3D);
|
||||
void setQuarternions(double q0, double q1, double q2, double q3);
|
||||
void setRotationMatrix(FMatDsptr rotationMatrix);
|
||||
void setVelocity3D(FColDsptr velocity3D);
|
||||
void setOmega3D(FColDsptr omega3D);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "SphericalJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTSphericalJoint : public ASMTJoint
|
||||
class EXPORT ASMTSphericalJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "TranslationalJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTTranslationalJoint : public ASMTJoint
|
||||
class EXPORT ASMTTranslationalJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTMotion.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTTranslationalMotion : public ASMTMotion
|
||||
class EXPORT ASMTTranslationalMotion : public ASMTMotion
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "ASMTJoint.h"
|
||||
|
||||
namespace MbD {
|
||||
class ASMTUniversalJoint : public ASMTJoint
|
||||
class EXPORT ASMTUniversalJoint : public ASMTJoint
|
||||
{
|
||||
//
|
||||
public:
|
||||
|
||||
26
MbDCode/ArcSine.cpp
Normal file
26
MbDCode/ArcSine.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "ArcSine.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
MbD::ArcSine::ArcSine(Symsptr arg) : FunctionX(arg)
|
||||
{
|
||||
}
|
||||
|
||||
double MbD::ArcSine::getValue()
|
||||
{
|
||||
return std::asin(xx->getValue());
|
||||
}
|
||||
|
||||
std::ostream& MbD::ArcSine::printOn(std::ostream& s) const
|
||||
{
|
||||
s << "arcsin(" << xx << ")";
|
||||
return s;
|
||||
}
|
||||
26
MbDCode/ArcSine.h
Normal file
26
MbDCode/ArcSine.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FunctionX.h"
|
||||
|
||||
namespace MbD {
|
||||
class ArcSine : public FunctionX
|
||||
{
|
||||
//
|
||||
public:
|
||||
ArcSine() = default;
|
||||
ArcSine(Symsptr arg);
|
||||
double getValue() override;
|
||||
|
||||
std::ostream& printOn(std::ostream& s) const override;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include<memory>
|
||||
#include <memory>
|
||||
|
||||
#include "ExternalSystem.h"
|
||||
#include "System.h"
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace MbD {
|
||||
template<typename T>
|
||||
class EulerParameters : public EulerArray<T>
|
||||
{
|
||||
//Quarternion = {q0, q1, q2, q3}
|
||||
//EulerParameters = {qE1, qE2, qE3, qE4} is preferred because Smalltalk uses one-based indexing.
|
||||
// q0 = qE4
|
||||
//Note: It is tempting to use quarternions in C++ because of zero-based indexing.
|
||||
//Note: But that will make it harder to compare computation results with Smalltalk
|
||||
//aA aB aC pApE
|
||||
public:
|
||||
EulerParameters() : EulerArray<T>(4) {}
|
||||
|
||||
3
MbDCode/MBDynBlock.cpp
Normal file
3
MbDCode/MBDynBlock.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "MBDynBlock.h"
|
||||
|
||||
using namespace MbD;
|
||||
18
MbDCode/MBDynBlock.h
Normal file
18
MbDCode/MBDynBlock.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynBlock : public MBDynItem
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
}
|
||||
12
MbDCode/MBDynBody.cpp
Normal file
12
MbDCode/MBDynBody.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "MBDynBody.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynBody::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynBody::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
20
MbDCode/MBDynBody.h
Normal file
20
MbDCode/MBDynBody.h
Normal file
@@ -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 "MBDynElement.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynBody : public MBDynElement
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
};
|
||||
}
|
||||
49
MbDCode/MBDynControlData.cpp
Normal file
49
MbDCode/MBDynControlData.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "MBDynControlData.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynControlData::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynControlData::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
readStructuralNodes(lines);
|
||||
readRigidBodies(lines);
|
||||
readJoints(lines);
|
||||
}
|
||||
|
||||
void MbD::MBDynControlData::readStructuralNodes(std::vector<std::string>& lines)
|
||||
{
|
||||
//structural nodes: 4;
|
||||
std::vector<std::string> tokens{"structural", "nodes:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> structuralNodes;
|
||||
}
|
||||
|
||||
void MbD::MBDynControlData::readRigidBodies(std::vector<std::string>& lines)
|
||||
{
|
||||
//rigid bodies: 3;
|
||||
std::vector<std::string> tokens{"rigid", "bodies:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> rigidBodies;
|
||||
}
|
||||
|
||||
void MbD::MBDynControlData::readJoints(std::vector<std::string>& lines)
|
||||
{
|
||||
//joints: 6;
|
||||
std::vector<std::string> tokens{"joints:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> joints;
|
||||
}
|
||||
24
MbDCode/MBDynControlData.h
Normal file
24
MbDCode/MBDynControlData.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynBlock.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynControlData : public MBDynBlock
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
void readStructuralNodes(std::vector<std::string>& lines);
|
||||
void readRigidBodies(std::vector<std::string>& lines);
|
||||
void readJoints(std::vector<std::string>& lines);
|
||||
|
||||
int structuralNodes, rigidBodies, joints;
|
||||
};
|
||||
}
|
||||
15
MbDCode/MBDynData.cpp
Normal file
15
MbDCode/MBDynData.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "MBDynData.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynData::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynData::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(lines.size() == 3);
|
||||
std::vector<std::string> tokens{"problem:", "initial", "value;"};
|
||||
auto problemit = findLineWith(lines, tokens);
|
||||
assert(problemit != lines.end());
|
||||
}
|
||||
20
MbDCode/MBDynData.h
Normal file
20
MbDCode/MBDynData.h
Normal file
@@ -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 "MBDynBlock.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynData : public MBDynBlock
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
};
|
||||
}
|
||||
7
MbDCode/MBDynElement.cpp
Normal file
7
MbDCode/MBDynElement.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "MBDynElement.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynElement::initialize()
|
||||
{
|
||||
}
|
||||
19
MbDCode/MBDynElement.h
Normal file
19
MbDCode/MBDynElement.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynElement : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
|
||||
};
|
||||
}
|
||||
12
MbDCode/MBDynElements.cpp
Normal file
12
MbDCode/MBDynElements.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "MBDynElements.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynElements::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynElements::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
20
MbDCode/MBDynElements.h
Normal file
20
MbDCode/MBDynElements.h
Normal file
@@ -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 "MBDynBlock.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynElements : public MBDynBlock
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
};
|
||||
}
|
||||
75
MbDCode/MBDynInitialValue.cpp
Normal file
75
MbDCode/MBDynInitialValue.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "MBDynInitialValue.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynInitialValue::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
readInitialTime(lines);
|
||||
readFinalTime(lines);
|
||||
readTimeStep(lines);
|
||||
readMaxIterations(lines);
|
||||
readTolerance(lines);
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::readInitialTime(std::vector<std::string>& lines)
|
||||
{
|
||||
//initial time: 0.;
|
||||
std::vector<std::string> tokens{"initial", "time:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> initialTime;
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::readFinalTime(std::vector<std::string>& lines)
|
||||
{
|
||||
//final time: 5.;
|
||||
std::vector<std::string> tokens{"final", "time:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> finalTime;
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::readTimeStep(std::vector<std::string>& lines)
|
||||
{
|
||||
//time step: 1.e-2;
|
||||
std::vector<std::string> tokens{"time", "step:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> timeStep;
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::readMaxIterations(std::vector<std::string>& lines)
|
||||
{
|
||||
//max iterations: 10;
|
||||
std::vector<std::string> tokens{"max", "iterations:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> maxIterations;
|
||||
}
|
||||
|
||||
void MbD::MBDynInitialValue::readTolerance(std::vector<std::string>& lines)
|
||||
{
|
||||
//tolerance: 1.e-6;
|
||||
std::vector<std::string> tokens{"tolerance:"};
|
||||
auto it = findLineWith(lines, tokens);
|
||||
std::istringstream iss(*it);
|
||||
std::string str;
|
||||
iss >> str;
|
||||
iss >> tolerance;
|
||||
}
|
||||
27
MbDCode/MBDynInitialValue.h
Normal file
27
MbDCode/MBDynInitialValue.h
Normal file
@@ -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 "MBDynBlock.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynInitialValue : public MBDynBlock
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
void readInitialTime(std::vector<std::string>& lines);
|
||||
void readFinalTime(std::vector<std::string>& lines);
|
||||
void readTimeStep(std::vector<std::string>& lines);
|
||||
void readMaxIterations(std::vector<std::string>& lines);
|
||||
void readTolerance(std::vector<std::string>& lines);
|
||||
|
||||
double initialTime, finalTime, timeStep, tolerance;
|
||||
int maxIterations;
|
||||
};
|
||||
}
|
||||
43
MbDCode/MBDynItem.cpp
Normal file
43
MbDCode/MBDynItem.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "MBDynItem.h"
|
||||
#include "MBDynSystem.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
MBDynSystem* MbD::MBDynItem::root()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MbD::MBDynItem::initialize()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void MbD::MBDynItem::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::vector<std::string>::iterator MbD::MBDynItem::findLineWith(std::vector<std::string>& lines, std::vector<std::string>& tokens)
|
||||
{
|
||||
auto it = std::find_if(lines.begin(), lines.end(), [&](const std::string& line) {
|
||||
return lineHasTokens(line, tokens);
|
||||
});
|
||||
return it;
|
||||
}
|
||||
|
||||
bool MbD::MBDynItem::lineHasTokens(const std::string& line, std::vector<std::string>& tokens)
|
||||
{
|
||||
size_t index = 0;
|
||||
for (auto& token : tokens) {
|
||||
index = line.find(token, index);
|
||||
if (index == std::string::npos) return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<MBDynVariables> MbD::MBDynItem::mbdynVariables()
|
||||
{
|
||||
return owner->mbdynVariables();
|
||||
}
|
||||
51
MbDCode/MBDynItem.h
Normal file
51
MbDCode/MBDynItem.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "CREATE.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynSystem;
|
||||
class MBDynVariables;
|
||||
|
||||
class MBDynItem
|
||||
{
|
||||
//
|
||||
public:
|
||||
virtual MBDynSystem* root();
|
||||
|
||||
virtual void initialize();
|
||||
//void setName(std::string str);
|
||||
virtual void parseMBDyn(std::vector<std::string>& lines);
|
||||
std::vector<std::string>::iterator findLineWith(std::vector<std::string>& lines, std::vector<std::string>& tokens);
|
||||
bool lineHasTokens(const std::string& line, std::vector<std::string>& tokens);
|
||||
virtual std::shared_ptr<MBDynVariables> mbdynVariables();
|
||||
//FRowDsptr readRowOfDoubles(std::string& line);
|
||||
//FColDsptr readColumnOfDoubles(std::string& line);
|
||||
//double readDouble(std::string& line);
|
||||
//int readInt(std::string& line);
|
||||
//bool readBool(std::string& line);
|
||||
//std::string readString(std::string& line);
|
||||
//void readName(std::vector<std::string>& lines);
|
||||
//virtual std::string fullName(std::string partialName);
|
||||
//void readDoublesInto(std::string& str, std::string label, FRowDsptr& row);
|
||||
//virtual void deleteMbD();
|
||||
//virtual void createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits);
|
||||
//virtual void updateFromMbD();
|
||||
//virtual void compareResults(AnalysisType type);
|
||||
//virtual void outputResults(AnalysisType type);
|
||||
//std::shared_ptr<Units> mbdUnits();
|
||||
//std::shared_ptr<Constant> sptrConstant(double value);
|
||||
|
||||
std::string name;
|
||||
MBDynItem* owner;
|
||||
std::shared_ptr<Item> mbdObject;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
12
MbDCode/MBDynJoint.cpp
Normal file
12
MbDCode/MBDynJoint.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "MBDynJoint.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynJoint::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynJoint::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
20
MbDCode/MBDynJoint.h
Normal file
20
MbDCode/MBDynJoint.h
Normal file
@@ -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 "MBDynElement.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynJoint : public MBDynElement
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
};
|
||||
}
|
||||
31
MbDCode/MBDynLabels.cpp
Normal file
31
MbDCode/MBDynLabels.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "MBDynLabels.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynLabels::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynLabels::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
labels = std::make_shared<std::map<std::string, int>>();
|
||||
std::string str, label;
|
||||
int intValue;
|
||||
std::vector<std::string> tokens{"set:", "integer"};
|
||||
while (true) {
|
||||
auto it = findLineWith(lines, tokens);
|
||||
if (it != lines.end()) {
|
||||
std::istringstream iss(*it);
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> label;
|
||||
iss >> str;
|
||||
iss >> intValue;
|
||||
labels->insert(std::make_pair(label, intValue));
|
||||
lines.erase(it);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
MbDCode/MBDynLabels.h
Normal file
21
MbDCode/MBDynLabels.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynLabels : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
std::shared_ptr<std::map<std::string, int>> labels;
|
||||
};
|
||||
}
|
||||
12
MbDCode/MBDynNode.cpp
Normal file
12
MbDCode/MBDynNode.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "MBDynNode.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynNode::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynNode::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
20
MbDCode/MBDynNode.h
Normal file
20
MbDCode/MBDynNode.h
Normal file
@@ -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 "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynNode : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
};
|
||||
}
|
||||
28
MbDCode/MBDynNodes.cpp
Normal file
28
MbDCode/MBDynNodes.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "MBDynNodes.h"
|
||||
#include "MBDynNode.h"
|
||||
#include "MBDynStructural.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynNodes::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynNodes::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
nodes = std::make_shared<std::vector<std::shared_ptr<MBDynNode>>>();
|
||||
std::vector<std::string> tokens{ "structural:" };
|
||||
while (true) {
|
||||
auto it = findLineWith(lines, tokens);
|
||||
if (it != lines.end()) {
|
||||
auto structural = CREATE<MBDynStructural>::With();
|
||||
structural->owner = this;
|
||||
structural->parseMBDyn(*it);
|
||||
nodes->push_back(structural);
|
||||
lines.erase(it);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MbDCode/MBDynNodes.h
Normal file
23
MbDCode/MBDynNodes.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynNode;
|
||||
|
||||
class MBDynNodes : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
std::shared_ptr<std::vector<std::shared_ptr<MBDynNode>>> nodes;
|
||||
};
|
||||
}
|
||||
238
MbDCode/MBDynReference.cpp
Normal file
238
MbDCode/MBDynReference.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
#include "MBDynReference.h"
|
||||
#include "MBDynVariables.h"
|
||||
#include "SymbolicParser.h"
|
||||
#include "BasicUserFunction.h"
|
||||
#include "EulerAngles.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynReference::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::parseMBDyn(std::string line)
|
||||
{
|
||||
refString = line;
|
||||
size_t previousPos = 0;
|
||||
auto pos = line.find(":");
|
||||
auto front = line.substr(previousPos, pos - previousPos);
|
||||
assert(front.find("reference") != std::string::npos);
|
||||
auto arguments = std::make_shared<std::vector<std::string>>();
|
||||
std::string argument;
|
||||
while (true) {
|
||||
previousPos = pos;
|
||||
pos = line.find(",", pos + 1);
|
||||
if (pos != std::string::npos) {
|
||||
argument = line.substr(previousPos + 1, pos - previousPos - 1);
|
||||
arguments->push_back(argument);
|
||||
}
|
||||
else {
|
||||
argument = line.substr(previousPos + 1);
|
||||
arguments->push_back(argument);
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::istringstream iss(arguments->at(0));
|
||||
iss >> name;
|
||||
arguments->erase(arguments->begin());
|
||||
|
||||
readPosition(arguments);
|
||||
readOrientation(arguments);
|
||||
readVelocity(arguments);
|
||||
readOmega(arguments);
|
||||
}
|
||||
|
||||
//void MbD::MBDynReference::parseMBDyn(std::string line)
|
||||
//{
|
||||
// refString = line;
|
||||
// std::replace(line.begin(), line.end(), ',', ' ');
|
||||
// std::istringstream iss(line);
|
||||
// std::string str;
|
||||
// iss >> str;
|
||||
// assert(str == "reference:");
|
||||
// iss >> name;
|
||||
// readPosition(iss);
|
||||
// readOrientation(iss);
|
||||
// readVelocity(iss);
|
||||
// readOmega(iss);
|
||||
//}
|
||||
|
||||
void MbD::MBDynReference::readPosition(std::istringstream& iss)
|
||||
{
|
||||
auto dddd = iss.str();
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
rOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
rOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readOrientation(std::istringstream& iss)
|
||||
{
|
||||
std::string str;
|
||||
iss >> str;
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
auto euler = std::make_shared<EulerAngles<Symsptr>>();
|
||||
if (str.find("euler") != std::string::npos) {
|
||||
euler->rotOrder = std::make_shared<FullColumn<int>>(std::initializer_list<int>{ 1, 2, 3 });
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
euler->at(i) = sym;
|
||||
double ddd = sym->getValue();
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
euler->calc();
|
||||
aAOf = euler->aA;
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readVelocity(std::istringstream& iss)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
vOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
auto p = iss.tellg();
|
||||
iss >> str;
|
||||
if (str.find("null") != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
iss.seekg(p);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
vOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readOmega(std::istringstream& iss)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
omeOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
auto p = iss.tellg();
|
||||
iss >> str;
|
||||
if (str.find("null") != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
iss.seekg(p);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
omeOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readPosition(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
rOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
rOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readOrientation(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto str = args->at(0);
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
auto euler = std::make_shared<EulerAngles<Symsptr>>();
|
||||
if (str.find("euler") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
euler->rotOrder = std::make_shared<FullColumn<int>>(std::initializer_list<int>{ 1, 2, 3 });
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
euler->at(i) = sym;
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
euler->calc();
|
||||
aAOf = euler->aA;
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readVelocity(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
vOfO = std::make_shared<FullColumn<double>>(3);
|
||||
auto str = args->at(0);
|
||||
if (str.find("null") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
vOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynReference::readOmega(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
omeOfO = std::make_shared<FullColumn<double>>(3);
|
||||
auto str = args->at(0);
|
||||
if (str.find("null") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
omeOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
MbDCode/MBDynReference.h
Normal file
32
MbDCode/MBDynReference.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
|
||||
class MBDynReference : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::string line);
|
||||
void readPosition(std::istringstream& iss);
|
||||
void readOrientation(std::istringstream& iss);
|
||||
void readVelocity(std::istringstream& iss);
|
||||
void readOmega(std::istringstream& iss);
|
||||
void readPosition(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readOrientation(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readVelocity(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readOmega(std::shared_ptr<std::vector<std::string>>& args);
|
||||
|
||||
std::string refString, name;
|
||||
FColDsptr rOfO, vOfO, omeOfO;
|
||||
FMatDsptr aAOf;
|
||||
};
|
||||
}
|
||||
29
MbDCode/MBDynReferences.cpp
Normal file
29
MbDCode/MBDynReferences.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "MBDynReferences.h"
|
||||
#include "MBDynReference.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynReferences::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynReferences::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
references = std::make_shared<std::map<std::string, std::shared_ptr<MBDynReference>>>();
|
||||
std::string str, refName;
|
||||
double doubleValue;
|
||||
std::vector<std::string> tokens{"reference:"};
|
||||
while (true) {
|
||||
auto it = findLineWith(lines, tokens);
|
||||
if (it != lines.end()) {
|
||||
auto reference = CREATE<MBDynReference>::With();
|
||||
reference->owner = this;
|
||||
reference->parseMBDyn(*it);
|
||||
references->insert(std::make_pair(reference->name, reference));
|
||||
lines.erase(it);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
MbDCode/MBDynReferences.h
Normal file
24
MbDCode/MBDynReferences.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynReference;
|
||||
|
||||
class MBDynReferences : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
std::shared_ptr<std::map<std::string, std::shared_ptr<MBDynReference>>> references;
|
||||
|
||||
};
|
||||
}
|
||||
233
MbDCode/MBDynStructural.cpp
Normal file
233
MbDCode/MBDynStructural.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
#include "MBDynStructural.h"
|
||||
#include "MBDynVariables.h"
|
||||
#include "SymbolicParser.h"
|
||||
#include "BasicUserFunction.h"
|
||||
#include "EulerAngles.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynStructural::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::parseMBDyn(std::string line)
|
||||
{
|
||||
strucString = line;
|
||||
size_t previousPos = 0;
|
||||
auto pos = line.find(":");
|
||||
auto front = line.substr(previousPos, pos - previousPos);
|
||||
assert(front.find("structural") != std::string::npos);
|
||||
auto arguments = std::make_shared<std::vector<std::string>>();
|
||||
std::string argument;
|
||||
while (true) {
|
||||
previousPos = pos;
|
||||
pos = line.find(",", pos + 1);
|
||||
if (pos != std::string::npos) {
|
||||
argument = line.substr(previousPos + 1, pos - previousPos - 1);
|
||||
arguments->push_back(argument);
|
||||
}
|
||||
else {
|
||||
argument = line.substr(previousPos + 1);
|
||||
arguments->push_back(argument);
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::istringstream iss(arguments->at(0));
|
||||
iss >> name;
|
||||
arguments->erase(arguments->begin());
|
||||
iss = std::istringstream(arguments->at(0));
|
||||
iss >> type;
|
||||
arguments->erase(arguments->begin());
|
||||
|
||||
readPosition(arguments);
|
||||
readOrientation(arguments);
|
||||
readVelocity(arguments);
|
||||
readOmega(arguments);
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readPosition(std::istringstream& iss)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
rOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
rOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readOrientation(std::istringstream& iss)
|
||||
{
|
||||
std::string str;
|
||||
iss >> str;
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
auto euler = std::make_shared<EulerAngles<Symsptr>>();
|
||||
if (str.find("eye") != std::string::npos) {
|
||||
aAOf = std::make_shared<FullMatrix<double>>(3, 3);
|
||||
aAOf->identity();
|
||||
return;
|
||||
}
|
||||
else if (str.find("euler") != std::string::npos) {
|
||||
euler->rotOrder = std::make_shared<FullColumn<int>>(std::initializer_list<int>{ 1, 2, 3 });
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
euler->at(i) = sym;
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
euler->calc();
|
||||
aAOf = euler->aA;
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readVelocity(std::istringstream& iss)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
vOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
auto p = iss.tellg();
|
||||
iss >> str;
|
||||
if (str.find("null") != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
iss.seekg(p);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
vOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readOmega(std::istringstream& iss)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
omeOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
auto p = iss.tellg();
|
||||
iss >> str;
|
||||
if (str.find("null") != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
iss.seekg(p);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
iss >> str;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
omeOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readPosition(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
rOfO = std::make_shared<FullColumn<double>>(3);
|
||||
std::string str;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
rOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readOrientation(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto str = args->at(0);
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
auto euler = std::make_shared<EulerAngles<Symsptr>>();
|
||||
if (str.find("euler") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
euler->rotOrder = std::make_shared<FullColumn<int>>(std::initializer_list<int>{ 1, 2, 3 });
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
euler->at(i) = sym;
|
||||
}
|
||||
}
|
||||
else if (str.find("eye") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
euler->rotOrder = std::make_shared<FullColumn<int>>(std::initializer_list<int>{ 1, 2, 3 });
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
euler->calc();
|
||||
aAOf = euler->aA;
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readVelocity(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
vOfO = std::make_shared<FullColumn<double>>(3);
|
||||
auto str = args->at(0);
|
||||
if (str.find("null") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
vOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MbD::MBDynStructural::readOmega(std::shared_ptr<std::vector<std::string>>& args)
|
||||
{
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = mbdynVariables()->variables;
|
||||
omeOfO = std::make_shared<FullColumn<double>>(3);
|
||||
auto str = args->at(0);
|
||||
if (str.find("null") != std::string::npos) {
|
||||
args->erase(args->begin());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
str = args->at(0);
|
||||
args->erase(args->begin());
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
omeOfO->at(i) = sym->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
MbDCode/MBDynStructural.h
Normal file
31
MbDCode/MBDynStructural.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynNode.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynStructural : public MBDynNode
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::string line);
|
||||
void readPosition(std::istringstream& iss);
|
||||
void readOrientation(std::istringstream& iss);
|
||||
void readVelocity(std::istringstream& iss);
|
||||
void readOmega(std::istringstream& iss);
|
||||
void readPosition(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readOrientation(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readVelocity(std::shared_ptr<std::vector<std::string>>& args);
|
||||
void readOmega(std::shared_ptr<std::vector<std::string>>& args);
|
||||
|
||||
std::string strucString, name, type;
|
||||
FColDsptr rOfO, vOfO, omeOfO;
|
||||
FMatDsptr aAOf;
|
||||
};
|
||||
}
|
||||
189
MbDCode/MBDynSystem.cpp
Normal file
189
MbDCode/MBDynSystem.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
#include "MBDynSystem.h"
|
||||
#include "CREATE.h"
|
||||
#include "FullColumn.h"
|
||||
#include "MBDynInitialValue.h"
|
||||
#include "MBDynData.h"
|
||||
#include "MBDynControlData.h"
|
||||
#include "MBDynLabels.h"
|
||||
#include "MBDynVariables.h"
|
||||
#include "MBDynReferences.h"
|
||||
#include "MBDynNodes.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynSystem::runFile(const char* filename)
|
||||
{
|
||||
std::ifstream stream(filename);
|
||||
std::string line;
|
||||
std::vector<std::string> lines;
|
||||
while (std::getline(stream, line)) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
eraseComments(lines);
|
||||
auto statements = collectStatements(lines);
|
||||
|
||||
auto system = CREATE<MBDynSystem>::With();
|
||||
system->setFilename(filename);
|
||||
system->parseMBDyn(statements);
|
||||
system->runKINEMATIC();
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
readDataBlock(lines);
|
||||
readInitialValueBlock(lines);
|
||||
readControlDataBlock(lines);
|
||||
readLabels(lines);
|
||||
readVariables(lines);
|
||||
readReferences(lines);
|
||||
readNodesBlock(lines);
|
||||
readElementsBlock(lines);
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<MBDynVariables> MbD::MBDynSystem::mbdynVariables()
|
||||
{
|
||||
return variables;
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::runKINEMATIC()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::setFilename(std::string str)
|
||||
{
|
||||
filename = str;
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readDataBlock(std::vector<std::string>& lines)
|
||||
{
|
||||
std::vector<std::string> tokens{"begin:", "data;"};
|
||||
auto beginit = findLineWith(lines, tokens);
|
||||
std::vector<std::string> tokens1{"end:", "data;"};
|
||||
auto endit = findLineWith(lines, tokens1);
|
||||
std::vector<std::string> blocklines = { beginit, endit + 1 };
|
||||
dataBlk = CREATE<MBDynData>::With();
|
||||
dataBlk->owner = this;
|
||||
dataBlk->parseMBDyn(blocklines);
|
||||
lines.erase(beginit, endit + 1);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readInitialValueBlock(std::vector<std::string>& lines)
|
||||
{
|
||||
std::vector<std::string> tokens{"begin:", "initial", "value"};
|
||||
auto beginit = findLineWith(lines, tokens);
|
||||
std::vector<std::string> tokens1{"end:", "initial", "value"};
|
||||
auto endit = findLineWith(lines, tokens1);
|
||||
std::vector<std::string> blocklines = { beginit, endit + 1 };
|
||||
initialValueBlk = CREATE<MBDynInitialValue>::With();
|
||||
initialValueBlk->owner = this;
|
||||
initialValueBlk->parseMBDyn(blocklines);
|
||||
lines.erase(beginit, endit + 1);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readControlDataBlock(std::vector<std::string>& lines)
|
||||
{
|
||||
std::vector<std::string> tokens{"begin:", "control", "data"};
|
||||
auto beginit = findLineWith(lines, tokens);
|
||||
std::vector<std::string> tokens1{"end:", "control", "data"};
|
||||
auto endit = findLineWith(lines, tokens1);
|
||||
std::vector<std::string> blocklines = { beginit, endit + 1 };
|
||||
controlDataBlk = CREATE<MBDynControlData>::With();
|
||||
controlDataBlk->owner = this;
|
||||
controlDataBlk->parseMBDyn(blocklines);
|
||||
lines.erase(beginit, endit + 1);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readLabels(std::vector<std::string>& lines)
|
||||
{
|
||||
labels = CREATE<MBDynLabels>::With();
|
||||
labels->owner = this;
|
||||
labels->parseMBDyn(lines);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readVariables(std::vector<std::string>& lines)
|
||||
{
|
||||
variables = CREATE<MBDynVariables>::With();
|
||||
variables->owner = this;
|
||||
variables->parseMBDyn(lines);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readReferences(std::vector<std::string>& lines)
|
||||
{
|
||||
references = CREATE<MBDynReferences>::With();
|
||||
references->owner = this;
|
||||
references->parseMBDyn(lines);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readNodesBlock(std::vector<std::string>& lines)
|
||||
{
|
||||
std::vector<std::string> tokens{ "begin:", "nodes;" };
|
||||
auto beginit = findLineWith(lines, tokens);
|
||||
std::vector<std::string> tokens1{ "end:", "nodes;" };
|
||||
auto endit = findLineWith(lines, tokens1);
|
||||
std::vector<std::string> blocklines = { beginit, endit + 1 };
|
||||
nodesBlk = CREATE<MBDynNodes>::With();
|
||||
nodesBlk->owner = this;
|
||||
nodesBlk->parseMBDyn(blocklines);
|
||||
lines.erase(beginit, endit + 1);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::readElementsBlock(std::vector<std::string>& lines)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::eraseComments(std::vector<std::string>& lines)
|
||||
{
|
||||
for (int i = 0; i < lines.size(); i++)
|
||||
{
|
||||
auto line = lines[i];
|
||||
auto it = line.find('#');
|
||||
if (it != std::string::npos) {
|
||||
lines[i] = line.substr(0, it);
|
||||
}
|
||||
}
|
||||
for (int i = lines.size() - 1; i >= 0; i--) {
|
||||
auto& line = lines[i];
|
||||
auto it = std::find_if(line.begin(), line.end(), [](unsigned char ch) { return !std::isspace(ch); });
|
||||
if (it == line.end()) lines.erase(lines.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> MbD::MBDynSystem::collectStatements(std::vector<std::string>& lines)
|
||||
{
|
||||
auto statements = std::vector<std::string>();
|
||||
while (!lines.empty()) {
|
||||
std::stringstream ss;
|
||||
while (!lines.empty()) {
|
||||
auto line = lines[0];
|
||||
lines.erase(lines.begin());
|
||||
auto i = line.find(';');
|
||||
if (i != std::string::npos) {
|
||||
ss << line.substr(0, i + 1);
|
||||
if (line.size() > i + 1) {
|
||||
auto remainder = line.substr(i + 1);
|
||||
auto it = std::find_if(remainder.begin(), remainder.end(), [](unsigned char ch) { return !std::isspace(ch); });
|
||||
if (it != remainder.end()) lines.insert(lines.begin(), remainder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
ss << line;
|
||||
}
|
||||
}
|
||||
statements.push_back(ss.str());
|
||||
}
|
||||
return statements;
|
||||
}
|
||||
|
||||
void MbD::MBDynSystem::initialize()
|
||||
{
|
||||
}
|
||||
57
MbDCode/MBDynSystem.h
Normal file
57
MbDCode/MBDynSystem.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynData;
|
||||
class MBDynInitialValue;
|
||||
class MBDynControlData;
|
||||
class MBDynNodes;
|
||||
class MBDynElements;
|
||||
class MBDynVariables;
|
||||
class MBDynLabels;
|
||||
class MBDynReferences;
|
||||
|
||||
class MBDynSystem : public MBDynItem
|
||||
{
|
||||
public:
|
||||
static void runFile(const char* chars);
|
||||
static void eraseComments(std::vector<std::string>& lines);
|
||||
static std::vector<std::string> collectStatements(std::vector<std::string>& lines);
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
std::shared_ptr<MBDynVariables> mbdynVariables() override;
|
||||
|
||||
void runKINEMATIC();
|
||||
void setFilename(std::string filename);
|
||||
void readDataBlock(std::vector<std::string>& lines);
|
||||
void readInitialValueBlock(std::vector<std::string>& lines);
|
||||
void readControlDataBlock(std::vector<std::string>& lines);
|
||||
void readLabels(std::vector<std::string>& lines);
|
||||
void readVariables(std::vector<std::string>& lines);
|
||||
void readReferences(std::vector<std::string>& lines);
|
||||
void readNodesBlock(std::vector<std::string>& lines);
|
||||
void readElementsBlock(std::vector<std::string>& lines);
|
||||
|
||||
std::string filename = "";
|
||||
std::shared_ptr<MBDynData> dataBlk;
|
||||
std::shared_ptr<MBDynInitialValue> initialValueBlk;
|
||||
std::shared_ptr<MBDynControlData> controlDataBlk;
|
||||
std::shared_ptr<MBDynNodes> nodesBlk;
|
||||
std::shared_ptr<MBDynElements> elementsBlk;
|
||||
std::shared_ptr<MBDynVariables> variables;
|
||||
std::shared_ptr<MBDynLabels> labels;
|
||||
std::shared_ptr<MBDynReferences> references;
|
||||
|
||||
};
|
||||
}
|
||||
38
MbDCode/MBDynVariables.cpp
Normal file
38
MbDCode/MBDynVariables.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "MBDynVariables.h"
|
||||
#include "SymbolicParser.h"
|
||||
#include "BasicUserFunction.h"
|
||||
|
||||
using namespace MbD;
|
||||
|
||||
void MbD::MBDynVariables::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void MbD::MBDynVariables::parseMBDyn(std::vector<std::string>& lines)
|
||||
{
|
||||
variables = std::make_shared<std::map<std::string, Symsptr>>();
|
||||
std::string str, variable;
|
||||
double doubleValue;
|
||||
std::vector<std::string> tokens{"set:", "real"};
|
||||
while (true) {
|
||||
auto it = findLineWith(lines, tokens);
|
||||
if (it != lines.end()) {
|
||||
std::istringstream iss(*it);
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
iss >> variable;
|
||||
iss >> str;
|
||||
iss >> str;
|
||||
auto parser = CREATE<SymbolicParser>::With();
|
||||
parser->variables = variables;
|
||||
auto userFunc = CREATE<BasicUserFunction>::With(str, 1.0);
|
||||
parser->parseUserFunction(userFunc);
|
||||
auto sym = parser->stack->top();
|
||||
variables->insert(std::make_pair(variable, sym));
|
||||
lines.erase(it);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
MbDCode/MBDynVariables.h
Normal file
21
MbDCode/MBDynVariables.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Ondsel, Inc. *
|
||||
* *
|
||||
* This file is part of OndselSolver. *
|
||||
* *
|
||||
* See LICENSE file for details about copyright. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "MBDynItem.h"
|
||||
|
||||
namespace MbD {
|
||||
class MBDynVariables : public MBDynItem
|
||||
{
|
||||
public:
|
||||
void initialize() override;
|
||||
void parseMBDyn(std::vector<std::string>& lines) override;
|
||||
|
||||
std::shared_ptr<std::map<std::string, Symsptr>> variables;
|
||||
};
|
||||
}
|
||||
@@ -20,26 +20,30 @@
|
||||
#include "CREATE.h"
|
||||
#include "GESpMatParPvPrecise.h"
|
||||
#include "ASMTAssembly.h"
|
||||
#include "MBDynSystem.h"
|
||||
|
||||
using namespace MbD;
|
||||
void runSpMat();
|
||||
|
||||
int main()
|
||||
{
|
||||
ASMTAssembly::runSinglePendulum();
|
||||
//MBDynSystem::runFile("crank_slider.mbd"); //To be completed
|
||||
//ASMTAssembly::runSinglePendulumSuperSimplified(); //Mass is missing
|
||||
ASMTAssembly::runSinglePendulumSimplified();
|
||||
ASMTAssembly::runSinglePendulum();
|
||||
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("circular.asmt"); //Needs checking
|
||||
//ASMTAssembly::runFile("cirpendu.asmt"); //Under constrained. Testing ICKine.
|
||||
//ASMTAssembly::runFile("engine1.asmt"); //Needs checking
|
||||
ASMTAssembly::runFile("fourbar.asmt");
|
||||
ASMTAssembly::runFile("fourbot.asmt");
|
||||
//ASMTAssembly::runFile("fourbot.asmt"); //Very large but works
|
||||
ASMTAssembly::runFile("wobpump.asmt");
|
||||
|
||||
auto cadSystem = std::make_shared<CADSystem>();
|
||||
cadSystem->runOndselSinglePendulum();
|
||||
cadSystem->runOndselDoublePendulum();
|
||||
//cadSystem->runOndselPiston();
|
||||
//cadSystem->runOndselPiston(); //For debugging
|
||||
cadSystem->runPiston();
|
||||
runSpMat();
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@
|
||||
<ClCompile Include="AngleZIeqcJeqc.cpp" />
|
||||
<ClCompile Include="AnyGeneralSpline.cpp" />
|
||||
<ClCompile Include="AnyPosICNewtonRaphson.cpp" />
|
||||
<ClCompile Include="ArcSine.cpp" />
|
||||
<ClCompile Include="ArcTan.cpp" />
|
||||
<ClCompile Include="ArcTan2.cpp" />
|
||||
<ClCompile Include="Array.cpp" />
|
||||
@@ -217,6 +218,23 @@
|
||||
<ClCompile Include="Ln.cpp" />
|
||||
<ClCompile Include="Log10.cpp" />
|
||||
<ClCompile Include="LogN.cpp" />
|
||||
<ClCompile Include="MBDynBlock.cpp" />
|
||||
<ClCompile Include="MBDynBody.cpp" />
|
||||
<ClCompile Include="MBDynControlData.cpp" />
|
||||
<ClCompile Include="MBDynData.cpp" />
|
||||
<ClCompile Include="MBDynElement.cpp" />
|
||||
<ClCompile Include="MBDynElements.cpp" />
|
||||
<ClCompile Include="MBDynInitialValue.cpp" />
|
||||
<ClCompile Include="MBDynItem.cpp" />
|
||||
<ClCompile Include="MBDynJoint.cpp" />
|
||||
<ClCompile Include="MBDynLabels.cpp" />
|
||||
<ClCompile Include="MBDynNode.cpp" />
|
||||
<ClCompile Include="MBDynNodes.cpp" />
|
||||
<ClCompile Include="MBDynReference.cpp" />
|
||||
<ClCompile Include="MBDynReferences.cpp" />
|
||||
<ClCompile Include="MBDynStructural.cpp" />
|
||||
<ClCompile Include="MBDynSystem.cpp" />
|
||||
<ClCompile Include="MBDynVariables.cpp" />
|
||||
<ClCompile Include="Negative.cpp" />
|
||||
<ClCompile Include="PosVelAccData.cpp" />
|
||||
<ClCompile Include="DiagonalMatrix.cpp" />
|
||||
@@ -413,6 +431,7 @@
|
||||
<ClInclude Include="AngleZIeqcJeqc.h" />
|
||||
<ClInclude Include="AnyGeneralSpline.h" />
|
||||
<ClInclude Include="AnyPosICNewtonRaphson.h" />
|
||||
<ClInclude Include="ArcSine.h" />
|
||||
<ClInclude Include="ArcTan.h" />
|
||||
<ClInclude Include="ArcTan2.h" />
|
||||
<ClInclude Include="Array.h" />
|
||||
@@ -485,6 +504,23 @@
|
||||
<ClInclude Include="Ln.h" />
|
||||
<ClInclude Include="Log10.h" />
|
||||
<ClInclude Include="LogN.h" />
|
||||
<ClInclude Include="MBDynBlock.h" />
|
||||
<ClInclude Include="MBDynBody.h" />
|
||||
<ClInclude Include="MBDynControlData.h" />
|
||||
<ClInclude Include="MBDynData.h" />
|
||||
<ClInclude Include="MBDynElement.h" />
|
||||
<ClInclude Include="MBDynElements.h" />
|
||||
<ClInclude Include="MBDynInitialValue.h" />
|
||||
<ClInclude Include="MBDynItem.h" />
|
||||
<ClInclude Include="MBDynJoint.h" />
|
||||
<ClInclude Include="MBDynLabels.h" />
|
||||
<ClInclude Include="MBDynNode.h" />
|
||||
<ClInclude Include="MBDynNodes.h" />
|
||||
<ClInclude Include="MBDynReference.h" />
|
||||
<ClInclude Include="MBDynReferences.h" />
|
||||
<ClInclude Include="MBDynStructural.h" />
|
||||
<ClInclude Include="MBDynSystem.h" />
|
||||
<ClInclude Include="MBDynVariables.h" />
|
||||
<ClInclude Include="Negative.h" />
|
||||
<ClInclude Include="PosVelAccData.h" />
|
||||
<ClInclude Include="DiagonalMatrix.h" />
|
||||
@@ -678,6 +714,7 @@
|
||||
<None Include="circular.asmt" />
|
||||
<None Include="cirpendu.asmt" />
|
||||
<None Include="ClassDiagram.cd" />
|
||||
<None Include="crank_slider.mbd" />
|
||||
<None Include="engine1.asmt" />
|
||||
<None Include="fourbar.asmt" />
|
||||
<None Include="fourbot.asmt" />
|
||||
|
||||
@@ -813,6 +813,60 @@
|
||||
<ClCompile Include="ASMTPointInPlaneJoint.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynItem.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynData.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynNodes.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynSystem.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynBlock.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynInitialValue.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynElements.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynControlData.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynVariables.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynLabels.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynNode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynStructural.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynElement.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynBody.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynJoint.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynReferences.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MBDynReference.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ArcSine.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Array.h">
|
||||
@@ -1619,6 +1673,60 @@
|
||||
<ClInclude Include="ASMTPointInPlaneJoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynItem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynNodes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynBlock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynInitialValue.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynElements.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynControlData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynVariables.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynLabels.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynNode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynStructural.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynElement.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynBody.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynJoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynReferences.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MBDynReference.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ArcSine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="MbDCode.rc">
|
||||
@@ -1637,5 +1745,6 @@
|
||||
<None Include="gyro.asmt" />
|
||||
<None Include="robot.asmt" />
|
||||
<None Include="wobpump.asmt" />
|
||||
<None Include="crank_slider.mbd" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "Negative.h"
|
||||
#include "Reciprocal.h"
|
||||
#include "GeneralSpline.h"
|
||||
#include "ArcSine.h"
|
||||
|
||||
void MbD::SymbolicParser::initialize()
|
||||
{
|
||||
@@ -214,7 +215,7 @@ void MbD::SymbolicParser::xLetter()
|
||||
while (true) {
|
||||
hereChar = source->get();
|
||||
if (hereChar == EOF) break;
|
||||
if (!std::isalnum(hereChar)) break;
|
||||
if (!std::isalnum(hereChar) && hereChar != '_') break;
|
||||
*buffer << hereChar;
|
||||
}
|
||||
tokenType = "word";
|
||||
@@ -338,6 +339,9 @@ bool MbD::SymbolicParser::intrinsic()
|
||||
if (peekForTypevalue("word", "abs")) {
|
||||
symfunc = std::make_shared<Abs>();
|
||||
}
|
||||
else if (peekForTypevalue("word", "asin") || peekForTypevalue("word", "arcsin")) {
|
||||
symfunc = std::make_shared<ArcSine>();
|
||||
}
|
||||
else if (peekForTypevalue("word", "arctan")) {
|
||||
symfunc = std::make_shared<ArcTan>();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void Variable::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void Variable::setName(std::string& str)
|
||||
void Variable::setName(std::string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace MbD {
|
||||
Variable(const char* str);
|
||||
Variable(double val);
|
||||
void initialize() override;
|
||||
void setName(std::string& str);
|
||||
void setName(std::string str);
|
||||
const std::string& getName() const;
|
||||
double getValue() override;
|
||||
std::ostream& printOn(std::ostream& s) const override;
|
||||
|
||||
Reference in New Issue
Block a user