23 #include "mbsim/objects/object.h"
24 #include <mbsim/functions/function.h>
30 namespace MBSimHydraulics {
35 class HydlinePressureloss;
41 HLine(
const std::string &name) :
MBSim::Object(name), nFrom(
nullptr), nTo(
nullptr), nFromRelative(
false), nToRelative(
false), direction(
fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(), QIn(1), QOut(1), Jacobian(), frameOfReference(
nullptr), updQ(
true), saved_frameOfReference(
"") { }
42 void calcSize()
override;
45 void updateh(
int j=0)
override { }
46 void updateJacobians(
int j=0) { }
47 void updateInverseKineticsJacobians() { }
48 std::shared_ptr<OpenMBV::Group> getOpenMBVGrp()
override {
return std::shared_ptr<OpenMBV::Group>(); }
52 void setFromNode(
HNode * nFrom_) {nFrom=nFrom_; }
53 void setToNode(
HNode * nTo_) {nTo=nTo_; }
54 void setDirection(
const fmatvec::Vec& dir) {direction=((nrm2(dir)>0)?dir/nrm2(dir):
fmatvec::Vec(3, fmatvec::INIT, 0)); }
55 HNode * getFromNode() {
return nFrom; }
56 HNode * getToNode() {
return nTo; }
57 void setOutflowRelative(
bool rel=
true) { nToRelative=rel; }
58 void setInflowRelative(
bool rel=
true) { nFromRelative=rel; }
59 virtual fmatvec::VecV getInflowFactor() {
return fmatvec::VecV(1, fmatvec::INIT, -1.); }
60 virtual fmatvec::VecV getOutflowFactor() {
return fmatvec::VecV(1, fmatvec::INIT, 1.); }
62 const fmatvec::VecV& evalQIn() {
if(updQ) updateQ();
return QIn; }
63 const fmatvec::VecV& evalQOut() {
if(updQ) updateQ();
return QOut; }
64 const fmatvec::VecV& getQIn(
bool check=
true)
const { assert((not check) or (not updQ));
return QIn; }
65 const fmatvec::VecV& getQOut(
bool check=
true)
const { assert((not check) or (not updQ));
return QOut; }
66 const fmatvec::MatV& getJacobian()
const {
return Jacobian; }
68 virtual void updateQ() { }
69 void updateM()
override { M=Mlocal; }
71 void init(InitStage stage,
const MBSim::InitConfigSet &config)
override;
72 void initializeUsingXML(xercesc::DOMElement *element)
override;
74 virtual Element* getDependency()
const {
return nullptr; }
76 void resetUpToDate()
override { MBSim::Object::resetUpToDate(); updQ =
true; }
81 bool nFromRelative, nToRelative;
82 fmatvec::VecV direction;
83 fmatvec::SymMatV Mlocal;
84 fmatvec::VecV QIn, QOut;
85 fmatvec::MatV Jacobian;
89 std::string saved_frameOfReference;
95 RigidHLine(
const std::string &name) :
HLine(name), pressureLossGravity(0), length(0), updPLG(
true) { }
97 void setLength(
double length_) {length=length_; }
98 double getLength()
const {
return length; }
99 void addInflowDependencyOnOutflow(
RigidHLine* line);
100 void addInflowDependencyOnInflow(
RigidHLine* line);
102 void calcqSize()
override { qSize=0; }
103 void calcuSize(
int j=0)
override { uSize[j]=getGeneralizedVelocitySize(); }
104 fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
106 void updatePressureLossGravity();
107 double evalPressureLossGravity() {
if(updPLG) updatePressureLossGravity();
return pressureLossGravity; }
109 void updateQ()
override;
110 void updateh(
int j=0)
override;
111 void updateM()
override;
113 void initializeUsingXML(xercesc::DOMElement *element)
override;
114 void init(InitStage stage,
const MBSim::InitConfigSet &config)
override;
115 void plot()
override;
117 void resetUpToDate()
override { HLine::resetUpToDate(); updPLG =
true; }
120 double pressureLossGravity;
122 std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
123 std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
133 QFunction=QFunction_;
134 QFunction->setParent(
this);
135 QFunction->setName(
"Q");
138 void calcqSize()
override { qSize=0; }
139 void calcuSize(
int j)
override { uSize[j]=0; }
141 void updateQ()
override;
143 void initializeUsingXML(xercesc::DOMElement *element)
override;
144 void init(InitStage stage,
const MBSim::InitConfigSet &config)
override;
155 void setQFunction(
MBSim::Function<
double(
double)> * QFunction_) { QFunction=QFunction_; }
157 void calcqSize()
override { qSize=0; }
158 void calcuSize(
int j)
override { uSize[j]=0; }
160 void updateQ()
override;
162 void initializeUsingXML(xercesc::DOMElement *element)
override;
163 void init(InitStage stage,
const MBSim::InitConfigSet &config)
override;
174 void setInflowFunction(
MBSim::Function<
double(
double)> *inflowFunction_) { inflowFunction=inflowFunction_; }
175 void setOutflowFunction(
MBSim::Function<
double(
double)> *outflowFunction_) { outflowFunction=outflowFunction_; }
176 void setOpeningFunction(
MBSim::Function<
double(
double)> *openingFunction_) { openingFunction=openingFunction_; }
177 void setDiameter(
double diameter_) { diameter=diameter_; }
178 void setAlpha(
double alpha_) { alpha=alpha_; }
179 void setCalcAreaModus(
int calcAreaModus_) { calcAreaModus=calcAreaModus_; }
181 void calcqSize()
override { qSize=0; }
182 void calcuSize(
int j)
override { uSize[j]=0; }
184 void updateQ()
override;
186 void initializeUsingXML(xercesc::DOMElement *element)
override;
187 void init(InitStage stage,
const MBSim::InitConfigSet &config)
override;
188 void plot()
override;
192 double diameter{0}, alpha{0.};
193 int calcAreaModus{0};
195 double pIn, pOut, dp, sign, opening, area, sqrt_dp;
Vector< Ref, double > Vec