1 #ifndef _SIMULATION_CLASSES_H
2 #define _SIMULATION_CLASSES_H
4 #include "mbsim/dynamic_system_solver.h"
5 #include "mbsim/object.h"
6 #include "mbsim/link.h"
7 #include "mbsim/mbsim_event.h"
8 #include "modelling_classes.h"
12 namespace MBSimControl {
16 namespace MBSimElectronics {
19 class Mesh :
public MBSim::Object {
22 std::vector<Branch*> branch;
24 Mesh(
const std::string &name) : MBSim::Object(name), precessor(0) {}
25 void calcqSize() { qSize = 1;}
26 void calcuSize(
int j) { uSize[j] = (j==0) ? 1 : 0;}
27 void updateStateDependentVariables(
double t) {};
28 void updateJacobians(
double t,
int j=0) {};
29 void updateInverseKineticsJacobians(
double t) {};
30 void init(MBSim::InitStage stage);
31 Object* getObjectDependingOn()
const {
return precessor;}
32 void setPrecessor(Object* obj) {precessor = obj;}
33 void addBranch(
Branch* branch_) {branch.push_back(branch_);}
34 int getNumberOfBranches() {
return branch.size();}
35 Branch* getBranch(
int i) {
return branch[i];}
36 #ifdef HAVE_OPENMBVCPPINTERFACE
37 OpenMBV::Group* getOpenMBVGrp() {
return 0; }
41 class Branch :
public MBSim::Object {
45 std::vector<Mesh*> mesh;
47 Terminal *startTerminal, *endTerminal;
48 std::vector<Branch*> connectedBranch;
52 Branch(
const std::string &name) : Object(name), Q(1), I(1), flag(0), precessor(0) {}
53 void calcuSize(
int j) { uSize[j] = (j==0) ? 0 : 1;}
54 void updateStateDependentVariables(
double t);
55 void updateJacobians(
double t,
int j=0) {};
56 void updateInverseKineticsJacobians(
double t) {};
57 const fmatvec::Mat& getJacobian(
int j)
const {
return J[j];}
58 fmatvec::Mat& getJacobian(
int j) {
return J[j];}
59 const fmatvec::Vec& getCurrent()
const {
return I;}
60 fmatvec::Vec& getCurrent() {
return I;}
61 const fmatvec::Vec& getCharge()
const {
return Q;}
62 fmatvec::Vec& getCharge() {
return Q;}
63 void setvz(
int vz_,
Mesh* mesh);
64 void connect(
Mesh *mesh_) {mesh.push_back(mesh_);mesh_->addBranch(
this);vz.push_back(0);}
65 void clearMeshList() {mesh.clear();}
66 int getNumberOfConnectedMeshes()
const {
return mesh.size();}
67 Mesh* getMesh(
int i) {
return mesh[i];}
68 void init(MBSim::InitStage stage);
69 void setStartTerminal(
Terminal* p) {startTerminal = p; p->addConnectedBranch(
this);}
70 void setEndTerminal(
Terminal* p) {endTerminal = p; p->addConnectedBranch(
this);}
71 Terminal* getStartTerminal() {
return startTerminal;}
72 Terminal* getEndTerminal() {
return endTerminal;}
73 void addConnectedBranch(
Branch* branch);
74 void buildTreeBranches(
Branch* callingBranch, std::vector<Branch*> &treeBranch,
unsigned int nmax);
75 void buildMeshes(
Terminal* callingTerminal,
Branch* callingBranch,
Mesh* currentMesh,
bool &foundMesh);
77 void setFlag(
int f) { flag = f; }
78 int getFlag()
const {
return flag; }
79 Object* getObjectDependingOn()
const {
return precessor;}
80 void setPrecessor(Object* obj) {precessor = obj;}
81 void updateh0Fromh1(
double t);
82 void updateW0FromW1(
double t);
83 void updateV0FromV1(
double t);
84 #ifdef HAVE_OPENMBVCPPINTERFACE
85 OpenMBV::Group* getOpenMBVGrp() {
return 0; }
91 fmatvec::Vec gdn, gdd;
94 virtual Element* getParent() {
return parent;}
95 virtual const Element* getParent()
const {
return parent;}
96 virtual void setParent(Element* parent_) {parent = parent_;}
98 void calcgSize(
int j);
99 void calcgdSize(
int j);
100 void calclaSize(
int j);
101 void updateg(
double t);
102 void updategd(
double t);
103 void updateW(
double t,
int j=0);
104 void plot(
double t,
double dt = 1);
105 virtual std::string getName()
const {
return Link::getName();}
106 virtual void setName(std::string name) {Link::setName(name);}
107 bool isActive()
const {
return true;}
108 bool gActiveChanged() {
return true;}
109 void init(MBSim::InitStage stage);
110 void updatehRef(
const fmatvec::Vec &hParent,
int j=0);
111 void updaterRef(
const fmatvec::Vec &rParent,
int j=0);
112 virtual double computeVoltage() {
return 0;}
115 virtual void updater(
double t) {
throw MBSim::MBSimError(
"ERROR (ElectronicLink::updater): Not implemented!"); }
119 virtual void updateWRef(
const fmatvec::Mat& ref,
int j);
120 virtual void updateVRef(
const fmatvec::Mat& ref,
int j);
121 virtual void updatedhdqRef(
const fmatvec::Mat& ref,
int i=0) {}
122 virtual void updatedhduRef(
const fmatvec::SqrMat& ref,
int i=0) {}
123 virtual void updatedhdtRef(
const fmatvec::Vec& ref,
int i=0) {}
132 void updateh(
double t,
int j=0);
133 void setResistance(
double R_) { R = R_;}
134 double computeVoltage();
142 void updateh(
double t,
int j=0);
143 void setCapacity(
double C_) { C = C_;}
149 MBSimControl::Signal *voltageSignal;
152 void updateh(
double t,
int j=0);
153 void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; }
161 Diode(
const std::string &name);
162 void setSetValued(
bool flag) {sv = flag;}
163 void updateh(
double t,
int j=0);
164 bool isSetValued()
const {
return sv;}
165 void checkImpactsForTermination(
double dt);
166 void solveImpactsGaussSeidel(
double dt);
172 MBSimControl::Signal *voltageSignal;
176 Switch(
const std::string &name);
177 void setSetValued(
bool flag) {sv = flag;}
178 bool isSetValued()
const {
return sv;}
179 void updateh(
double t,
int j=0);
180 void updateW(
double t,
int j=0);
181 void checkImpactsForTermination(
double dt);
182 void solveImpactsGaussSeidel(
double dt);
183 void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; }
191 void init(MBSim::InitStage stage);
192 virtual Element* getParent() {
return parent;}
193 virtual const Element* getParent()
const {
return parent;}
194 virtual void setParent(Element* parent_) {parent = parent_;}
195 void plot(
double t,
double dt = 1);
196 void updateStateDependentVariables(
double t) {};
197 void updateJacobians(
double t,
int j=0) {};
198 void updateInverseKineticsJacobians(
double t) {};
199 virtual std::string getName()
const {
return Object::getName();}
200 virtual void setName(std::string name) {Object::setName(name);}
201 Object* getObjectDependingOn()
const {
return branch;}
202 #ifdef HAVE_OPENMBVCPPINTERFACE
203 OpenMBV::Group* getOpenMBVGrp() {
return 0; }
212 void updateM(
double t,
int j=0);
213 void setInductance(
double L_) { L = L_;}
214 void updateStateDependentVariables(
double t);