All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
simulation_classes.h
1 #ifndef _SIMULATION_CLASSES_H
2 #define _SIMULATION_CLASSES_H
3 
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"
9 #include <string>
10 //#include <mbsim/utils/function.h>
11 
12 namespace MBSimControl {
13 class Signal;
14 }
15 
16 namespace MBSimElectronics {
17 
18  class Branch;
19  class Mesh : public MBSim::Object {
20  protected:
21  Object* precessor;
22  std::vector<Branch*> branch;
23  public:
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(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  boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); }
38 #endif
39  };
40 
41  class Branch : public MBSim::Object {
42  protected:
43  fmatvec::Mat J[2];
44  fmatvec::Vec Q, I;
45  std::vector<Mesh*> mesh;
46  std::vector<double> vz;
47  Terminal *startTerminal, *endTerminal;
48  std::vector<Branch*> connectedBranch;
49  int flag;
50  Object* precessor;
51  public:
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(double 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(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);
76 
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  boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); }
86 #endif
87  };
88 
90  protected:
91  fmatvec::Vec gdn, gdd;
92  public:
93  ElectronicLink(const std::string &name) : Link(name) {}
94  virtual Element* getParent() {return parent;}
95  virtual const Element* getParent() const {return parent;}
96  virtual void setParent(Element* parent_) {parent = parent_;}
97 
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  virtual bool isSingleValued() const { return true; }
110  void init(InitStage stage);
111  void updatehRef(const fmatvec::Vec &hParent, int j=0);
112  void updaterRef(const fmatvec::Vec &rParent, int j=0);
113  virtual double computeVoltage() {return 0;}
114 
115  /* INHERITED INTERFACE OF LINKINTERFACE */
116  virtual void updater(double t) { THROW_MBSIMERROR("(ElectronicLink::updater): Not implemented!"); }
117  /*****************************************************/
118 
119  /* INHERITED INTERFACE OF LINK */
120  virtual void updateWRef(const fmatvec::Mat& ref, int j);
121  virtual void updateVRef(const fmatvec::Mat& ref, int j);
122  virtual void updatedhdqRef(const fmatvec::Mat& ref, int i=0) {}
123  virtual void updatedhduRef(const fmatvec::SqrMat& ref, int i=0) {}
124  virtual void updatedhdtRef(const fmatvec::Vec& ref, int i=0) {}
125  /*****************************************************/
126  };
127 
128  class Resistor : public ElectronicLink {
129  protected:
130  double R;
131  public:
132  Resistor(const std::string &name);
133  void updateh(double t, int j=0);
134  void setResistance(double R_) { R = R_;}
135  double computeVoltage();
136  };
137 
138  class Capacitor : public ElectronicLink {
139  protected:
140  double C;
141  public:
142  Capacitor(const std::string &name);
143  void updateh(double t, int j=0);
144  void setCapacity(double C_) { C = C_;}
145  };
146 
147  class VoltageSource : public ElectronicLink {
148  protected:
149  //MBSim::Function1<fmatvec::Vec,double> *voltageSignal;
150  MBSimControl::Signal *voltageSignal;
151  public:
152  VoltageSource(const std::string &name);
153  void updateh(double t, int j=0);
154  void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; }
155  //void setVoltageSignal(MBSim::Function1<fmatvec::Vec,double> *func) {voltageSignal = func;}
156  };
157 
158  class Diode : public ElectronicLink {
159  protected:
160  bool sv;
161  public:
162  Diode(const std::string &name);
163  void setSetValued(bool flag) {sv = flag;}
164  void updateh(double t, int j=0);
165  bool isSetValued() const {return sv;}
166  virtual bool isSingleValued() const {return not sv;}
167  void checkImpactsForTermination(double dt);
168  void solveImpactsGaussSeidel(double dt);
169  };
170 
171  class Switch : public ElectronicLink {
172  protected:
173  //MBSim::Function1<fmatvec::Vec,double> *voltageSignal;
174  MBSimControl::Signal *voltageSignal;
175  double U0;
176  bool sv;
177  public:
178  Switch(const std::string &name);
179  void setSetValued(bool flag) {sv = flag;}
180  bool isSetValued() const {return sv;}
181  virtual bool isSingleValued() const {return not sv;}
182  void updateh(double t, int j=0);
183  void updateW(double t, int j=0);
184  void checkImpactsForTermination(double dt);
185  void solveImpactsGaussSeidel(double dt);
186  void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; }
187  //void setVoltageSignal(MBSim::Function1<fmatvec::Vec,double> *func) {voltageSignal = func;}
188  };
189 
191  protected:
192  public:
193  ElectronicObject(const std::string &name) : Object(name) {}
194  void init(InitStage stage);
195  virtual Element* getParent() {return parent;}
196  virtual const Element* getParent() const {return parent;}
197  virtual void setParent(Element* parent_) {parent = parent_;}
198  void plot(double t, double dt = 1);
199  void updateStateDependentVariables(double t) {};
200  void updateJacobians(double t, int j=0) {};
201  void updateInverseKineticsJacobians(double t) {};
202  virtual std::string getName() const {return Object::getName();}
203  virtual void setName(std::string name) {Object::setName(name);}
204  Object* getObjectDependingOn() const {return branch;}
205 #ifdef HAVE_OPENMBVCPPINTERFACE
206  boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); }
207 #endif
208  };
209 
210  class Inductor : public ElectronicObject {
211  protected:
212  double L;
213  public:
214  Inductor(const std::string &name);
215  void updateM(double t, int j=0);
216  void setInductance(double L_) { L = L_;}
217  void updateStateDependentVariables(double t);
218  };
219 
220 }
221 
222 #endif
Definition: simulation_classes.h:138
Definition: simulation_classes.h:210
Definition: simulation_classes.h:158
Definition: simulation_classes.h:128
Definition: simulation_classes.h:190
Definition: simulation_classes.h:19
Definition: simulation_classes.h:41
Definition: modelling_classes.h:42
Definition: simulation_classes.h:171
Definition: modelling_classes.h:19
Definition: simulation_classes.h:147

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML