23 #include "mbsim/objects/object.h"
24 #include <mbsim/functions/function.h>
30 namespace MBSimHydraulics {
33 class HydlinePressureloss;
39 HLine(
const std::string &name) :
MBSim::Object(name), nFrom(NULL), nTo(NULL), nFromRelative(
false), nToRelative(
false), direction(
fmatvec::Vec(3, fmatvec::INIT, 0)), Mlocal(), QIn(1), QOut(1), Jacobian(), frameOfReference(NULL), updQ(
true), saved_frameOfReference(
"") { }
40 virtual std::string getType()
const {
return "HLine"; }
43 void updateh(
int j=0) { }
44 void updateJacobians(
int j=0) { }
45 void updateInverseKineticsJacobians() { }
46 virtual std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
50 void setFromNode(
HNode * nFrom_) {nFrom=nFrom_; }
51 void setToNode(
HNode * nTo_) {nTo=nTo_; }
53 HNode * getFromNode() {
return nFrom; }
54 HNode * getToNode() {
return nTo; }
55 void setOutflowRelative(
bool rel=
true) { nToRelative=rel; }
56 void setInflowRelative(
bool rel=
true) { nFromRelative=rel; }
57 virtual fmatvec::VecV getInflowFactor() {
return fmatvec::VecV(1, fmatvec::INIT, -1.); }
58 virtual fmatvec::VecV getOutflowFactor() {
return fmatvec::VecV(1, fmatvec::INIT, 1.); }
60 const fmatvec::VecV& evalQIn() {
if(updQ) updateQ();
return QIn; }
61 const fmatvec::VecV& evalQOut() {
if(updQ) updateQ();
return QOut; }
62 const fmatvec::VecV& getQIn(
bool check=
true)
const { assert((not check) or (not updQ));
return QIn; }
63 const fmatvec::VecV& getQOut(
bool check=
true)
const { assert((not check) or (not updQ));
return QOut; }
64 const fmatvec::MatV& getJacobian()
const {
return Jacobian; }
66 virtual void updateQ() { }
67 void updateM() { M=Mlocal; }
69 void init(InitStage stage);
70 void initializeUsingXML(xercesc::DOMElement *element);
72 virtual Element* getDependency()
const {
return 0; }
74 void resetUpToDate() { MBSim::Object::resetUpToDate(); updQ =
true; }
79 bool nFromRelative, nToRelative;
80 fmatvec::VecV direction;
81 fmatvec::SymMatV Mlocal;
82 fmatvec::VecV QIn, QOut;
83 fmatvec::MatV Jacobian;
87 std::string saved_frameOfReference;
93 RigidHLine(
const std::string &name) :
HLine(name), pressureLossGravity(0), length(0), updPLG(
true) { }
94 virtual std::string getType()
const {
return "RigidHLine"; }
96 void setLength(
double length_) {length=length_; }
97 double getLength()
const {
return length; }
98 void addInflowDependencyOnOutflow(
RigidHLine* line);
99 void addInflowDependencyOnInflow(
RigidHLine* line);
101 void calcqSize() {qSize=0; }
102 void calcuSize(
int j=0) {uSize[j]=(dependency.size()?0:1); }
103 fmatvec::Mat calculateJacobian(std::vector<RigidHLine*> dep_check);
105 void updatePressureLossGravity();
106 double evalPressureLossGravity() {
if(updPLG) updatePressureLossGravity();
return pressureLossGravity; }
109 void updateh(
int j=0);
112 void initializeUsingXML(xercesc::DOMElement *element);
113 void init(InitStage stage);
116 void resetUpToDate() { HLine::resetUpToDate(); updPLG =
true; }
119 double pressureLossGravity;
121 std::vector<RigidHLine*> dependencyOnOutflow, dependencyOnInflow;
122 std::vector<std::string> refDependencyOnOutflowString, refDependencyOnInflowString;
130 virtual std::string getType()
const {
return "ConstrainedLine"; }
133 QFunction=QFunction_;
134 QFunction->setParent(
this);
135 QFunction->setName(
"Q");
138 void calcqSize() { qSize=0; }
139 void calcuSize(
int j) { uSize[j]=0; }
143 void initializeUsingXML(xercesc::DOMElement *element);
144 void init(InitStage stage);
153 FluidPump(
const std::string &name=
"") :
HLine(name), QFunction(NULL) { }
154 virtual std::string getType()
const {
return "FluidPump"; }
156 void setQFunction(
MBSim::Function<
double(
double)> * QFunction_) { QFunction=QFunction_; }
158 void calcqSize() { qSize=0; }
159 void calcuSize(
int j) { uSize[j]=0; }
163 void initializeUsingXML(xercesc::DOMElement *element);
164 void init(InitStage stage);
173 StatelessOrifice(
const std::string &name=
"") :
HLine(name), inflowFunction(NULL), outflowFunction(NULL), openingFunction(NULL), diameter(0), alpha(0.), calcAreaModus(0) {}
174 virtual std::string getType()
const {
return "StatelessOrifice"; }
176 void setInflowFunction(
MBSim::Function<
double(
double)> *inflowFunction_) { inflowFunction=inflowFunction_; }
177 void setOutflowFunction(
MBSim::Function<
double(
double)> *outflowFunction_) { outflowFunction=outflowFunction_; }
178 void setOpeningFunction(
MBSim::Function<
double(
double)> *openingFunction_) { openingFunction=openingFunction_; }
179 void setDiameter(
double diameter_) { diameter=diameter_; }
180 void setAlpha(
double alpha_) { alpha=alpha_; }
181 void setCalcAreaModus(
int calcAreaModus_) { calcAreaModus=calcAreaModus_; }
183 void calcqSize() { qSize=0; }
184 void calcuSize(
int j) { uSize[j]=0; }
188 void initializeUsingXML(xercesc::DOMElement *element);
189 void init(InitStage stage);
194 double diameter, alpha;
197 double pIn, pOut, dp, sign, opening, area, sqrt_dp;
Vector< Ref, double > Vec