23 #include "mbsim/object.h"
24 #include "mbsim/utils/function.h"
30 namespace MBSimControl {
34 namespace MBSimHydraulics {
37 class HydlinePressureloss;
41 class HLine :
public MBSim::Object {
43 HLine(
const std::string &name) : MBSim::Object(name), nFrom(NULL), nTo(NULL), nFromRelative(
false), nToRelative(
false), direction(fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(0), Jacobian(0,0), frameOfReference(NULL), saved_frameOfReference(
"") {};
44 virtual std::string getType()
const {
return "HLine"; }
47 virtual void updateStateDependentVariables(
double t) {};
48 virtual void updateJacobians(
double t,
int j=0) {};
49 virtual void updateInverseKineticsJacobians(
double t) {};
50 #ifdef HAVE_OPENMBVCPPINTERFACE
51 virtual OpenMBV::Group* getOpenMBVGrp() {
return 0; }
55 virtual void setFrameOfReference(MBSim::Frame *frame);
56 void setFromNode(
HNode * nFrom_) {nFrom=nFrom_; }
57 void setToNode(
HNode * nTo_) {nTo=nTo_; }
58 void setDirection(fmatvec::Vec dir) {direction=((nrm2(dir)>0)?dir/nrm2(dir):fmatvec::Vec(3, fmatvec::INIT, 0)); }
59 HNode * getFromNode() {
return nFrom; }
60 HNode * getToNode() {
return nTo; }
61 void setOutflowRelative(
bool rel=
true) {nToRelative=rel; }
62 void setInflowRelative(
bool rel=
true) {nFromRelative=rel; }
64 virtual fmatvec::Vec getQIn() = 0;
65 virtual fmatvec::Vec getQOut() = 0;
66 virtual fmatvec::Vec getInflowFactor() = 0;
67 virtual fmatvec::Vec getOutflowFactor() = 0;
68 virtual fmatvec::Mat& getJacobian() {
return Jacobian; }
70 void updateM(
double t,
int j=0) {M[j]=Mlocal; }
72 void init(MBSim::InitStage stage);
73 void initializeUsingXML(TiXmlElement *element);
78 bool nFromRelative, nToRelative;
79 fmatvec::Vec direction;
80 fmatvec::SymMat Mlocal;
81 fmatvec::Mat Jacobian;
82 MBSim::Frame * frameOfReference;
84 std::string saved_frameOfReference;
90 RigidHLine(
const std::string &name) :
HLine(name), pressureLossGravity(0), length(0), Q(fmatvec::Vec(1)) {}
91 virtual std::string getType()
const {
return "RigidHLine"; }
93 void setLength(
double length_) {length=length_; }
94 double getLength()
const {
return length; }
95 void addInflowDependencyOnOutflow(
RigidHLine* line);
96 void addInflowDependencyOnInflow(
RigidHLine* line);
98 virtual fmatvec::Vec getQIn() {
return Q; }
99 virtual fmatvec::Vec getQOut() {
return -Q; }
100 virtual fmatvec::Vec getInflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, -1.); }
101 virtual fmatvec::Vec getOutflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, 1.); }
102 void calcqSize() {qSize=0; }
103 void calcuSize(
int j=0) {uSize[j]=(dependency.size()?0:1); }
104 fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
106 virtual void updateStateDependentVariables(
double t);
107 void updateh(
double t,
int j=0);
108 void updateM(
double t,
int j=0);
110 void initializeUsingXML(TiXmlElement *element);
111 void init(MBSim::InitStage stage);
112 void plot(
double t,
double dt);
115 double pressureLossGravity;
118 std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
119 std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
126 virtual std::string getType()
const {
return "ConstrainedLine"; }
128 void setQFunction(MBSim::Function1<double,double> * QFun_) {QFun=QFun_; }
130 virtual fmatvec::Vec getQIn() {
return Q; }
131 virtual fmatvec::Vec getQOut() {
return -Q; }
132 virtual fmatvec::Vec getInflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, -1.); }
133 virtual fmatvec::Vec getOutflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, 1.); }
134 void calcqSize() {qSize=0; }
135 void calcuSize(
int j) {uSize[j]=0; }
137 virtual void updateStateDependentVariables(
double t);
138 void updateh(
double t,
int j=0) {};
140 void initializeUsingXML(TiXmlElement *element);
141 void init(MBSim::InitStage stage);
144 MBSim::Function1<double,double> * QFun;
151 FluidPump(
const std::string &name) :
HLine(name), QSignal(NULL), QSignalString(
""), Q(1) {}
152 virtual std::string getType()
const {
return "FluidPump"; }
154 void setQSignal(MBSimControl::Signal * QSignal_) {QSignal=QSignal_; }
156 virtual fmatvec::Vec getQIn();
157 virtual fmatvec::Vec getQOut();
158 virtual fmatvec::Vec getInflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, -1.); }
159 virtual fmatvec::Vec getOutflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, 1.); }
160 void calcqSize() {qSize=0; }
161 void calcuSize(
int j) {uSize[j]=0; }
163 void updateh(
double t,
int j=0) {};
165 void initializeUsingXML(TiXmlElement *element);
166 void init(MBSim::InitStage stage);
169 MBSimControl::Signal * QSignal;
170 std::string QSignalString;
177 StatelessOrifice(
const std::string &name) :
HLine(name), inflowSignal(NULL), outflowSignal(NULL), openingSignal(NULL), inflowSignalString(
""), outflowSignalString(
""), openingSignalString(
""), diameter(0), alpha(0.), calcAreaModus(0) {}
178 virtual std::string getType()
const {
return "StatelessOrifice"; }
180 void setInflowSignal(MBSimControl::Signal * inflowSignal_) {inflowSignal=inflowSignal_; }
181 void setOutflowSignal(MBSimControl::Signal * outflowSignal_) {outflowSignal=outflowSignal_; }
182 void setDiameter(
double diameter_) {diameter=diameter_; }
183 void setOpeningSignal(MBSimControl::Signal * openingSignal_) {openingSignal=openingSignal_; }
184 void setAlpha(
double alpha_) {alpha=alpha_; }
185 void setCalcAreaModus(
int calcAreaModus_) {calcAreaModus=calcAreaModus_; }
187 virtual fmatvec::Vec getQIn();
188 virtual fmatvec::Vec getQOut();
189 virtual fmatvec::Vec getInflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, -1.); }
190 virtual fmatvec::Vec getOutflowFactor() {
return fmatvec::Vec(1, fmatvec::INIT, 1.); }
191 void calcqSize() {qSize=0; }
192 void calcuSize(
int j) {uSize[j]=0; }
194 void updateh(
double t,
int j=0) {};
196 void initializeUsingXML(TiXmlElement *element);
197 void init(MBSim::InitStage stage);
198 void plot(
double t,
double dt);
201 MBSimControl::Signal *inflowSignal, *outflowSignal, *openingSignal;
202 std::string inflowSignalString, outflowSignalString, openingSignalString;
203 double diameter, alpha;
205 fmatvec::Vec calculateQ();
207 double pIn, pOut, dp, sign, opening, area, sqrt_dp;