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/objects/object.h"
6 #include "mbsim/links/link.h"
7 #include "mbsim/functions/function.h"
8 #include "mbsim/mbsim_event.h"
9 #include "modelling_classes.h"
10 #include <string>
11 //#include <mbsim/utils/function.h>
12 
13 //namespace MBSimControl {
14 // class Signal;
15 //}
16 
17 namespace MBSimElectronics {
18 
19  class Branch;
20  class Mesh : public MBSim::Object {
21  protected:
22  Object* precessor;
23  std::vector<Branch*> branch;
24  public:
25  Mesh(const std::string &name) : MBSim::Object(name), precessor(0) {}
26  void calcqSize() { qSize = 1;}
27  void calcuSize(int j) { uSize[j] = (j==0) ? 1 : 0;}
28  void init(InitStage stage);
29  void setPrecessor(Object* obj) {precessor = obj;}
30  void addBranch(Branch* branch_) {branch.push_back(branch_);}
31  int getNumberOfBranches() {return branch.size();}
32  Branch* getBranch(int i) {return branch[i];}
33  std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return std::shared_ptr<OpenMBV::Group>(); }
34  };
35 
36  class Branch : public MBSim::Object {
37  protected:
38  fmatvec::Mat J[2];
39  fmatvec::Vec Q, I;
40  std::vector<Mesh*> mesh;
41  std::vector<double> vz;
42  Terminal *startTerminal, *endTerminal;
43  std::vector<Branch*> connectedBranch;
44  int flag;
45  Object* precessor;
46  bool updQ, updI;
47  public:
48  Branch(const std::string &name) : Object(name), Q(1), I(1), flag(0), precessor(0), updQ(true), updI(true) { }
49  void calcuSize(int j) { uSize[j] = (j==0) ? 0 : 1;}
50  void updateCharge();
51  void updateCurrent();
52  const fmatvec::Mat& getJacobian(int j, bool check=true) const { return J[j];}
53  fmatvec::Mat& getJacobian(int j, bool check=true) { return J[j];}
54  const fmatvec::Vec& getCurrent(bool check=true) const { assert((not check) or (not updI)); return I; }
55  fmatvec::Vec& getCurrent(bool check=true) { assert((not check) or (not updI)); return I; }
56  const fmatvec::Vec& evalCurrent() { if(updI) updateCurrent(); return I; }
57  const fmatvec::Vec& getCharge(bool check=true) const { assert((not check) or (not updQ)); return Q; }
58  fmatvec::Vec& getCharge(bool check=true) { assert((not check) or (not updQ)); return Q; }
59  const fmatvec::Vec& evalCharge() { if(updQ) updateCharge(); return Q; }
60  void setvz(double vz_, Mesh* mesh);
61  void connect(Mesh *mesh_) {mesh.push_back(mesh_);mesh_->addBranch(this);vz.push_back(0);}
62  void clearMeshList() {mesh.clear();}
63  int getNumberOfConnectedMeshes() const {return mesh.size();}
64  Mesh* getMesh(int i) {return mesh[i];}
65  void init(InitStage stage);
66  void setStartTerminal(Terminal* p) {startTerminal = p; p->addConnectedBranch(this);}
67  void setEndTerminal(Terminal* p) {endTerminal = p; p->addConnectedBranch(this);}
68  Terminal* getStartTerminal() {return startTerminal;}
69  Terminal* getEndTerminal() {return endTerminal;}
70  void addConnectedBranch(Branch* branch);
71  void buildTreeBranches(Branch* callingBranch, std::vector<Branch*> &treeBranch, unsigned int nmax);
72  void buildMeshes(Terminal* callingTerminal, Branch* callingBranch, Mesh* currentMesh, bool &foundMesh);
73 
74  void setFlag(int f) { flag = f; }
75  int getFlag() const { return flag; }
76  void setPrecessor(Object* obj) {precessor = obj;}
77  void resetUpToDate() { Object::resetUpToDate(); updQ = true; updI = true; }
78  std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return std::shared_ptr<OpenMBV::Group>(); }
79  };
80 
82  protected:
83  fmatvec::Vec gdn, gdd;
84  public:
85  ElectronicLink(const std::string &name) : Link(name) {}
86  virtual Element* getParent() {return parent;}
87  virtual const Element* getParent() const {return parent;}
88  virtual void setParent(Element* parent_) {parent = parent_;}
89 
90  void calcgSize(int j);
91  void calcgdSize(int j);
92  void calclaSize(int j);
93  void updateg();
94  void updategd();
95  void updateW(int j=0);
96  void updateh(int j=0);
97  void plot();
98  virtual std::string getName() const {return Link::getName();}
99  virtual void setName(std::string name) {Link::setName(name);}
100  bool isActive() const {return true;}
101  bool gActiveChanged() {return true;}
102  virtual bool isSingleValued() const { return true; }
103  void init(InitStage stage);
104  void updatehRef(const fmatvec::Vec &hParent, int j=0);
105  void updaterRef(const fmatvec::Vec &rParent, int j=0);
106 
107  /* INHERITED INTERFACE OF LINKINTERFACE */
108  virtual void updater() { THROW_MBSIMERROR("(ElectronicLink::updater): Not implemented!"); }
109  /*****************************************************/
110 
111  /* INHERITED INTERFACE OF LINK */
112  virtual void updateWRef(const fmatvec::Mat& ref, int j);
113  virtual void updateVRef(const fmatvec::Mat& ref, int j);
114  virtual void updatedhdqRef(const fmatvec::Mat& ref, int i=0) {}
115  virtual void updatedhduRef(const fmatvec::SqrMat& ref, int i=0) {}
116  virtual void updatedhdtRef(const fmatvec::Vec& ref, int i=0) {}
117  void resetUpToDate() { Link::resetUpToDate(); updQ = true; updI = true; }
118  /*****************************************************/
119  };
120 
121  class Resistor : public ElectronicLink {
122  protected:
123  double R;
124  public:
125  Resistor(const std::string &name);
126  void setResistance(double R_) { R = R_;}
127  void updateGeneralizedForces();
128  std::string getType() const { return "Resistor"; }
129  };
130 
131  class Capacitor : public ElectronicLink {
132  protected:
133  double C;
134  public:
135  Capacitor(const std::string &name);
136  void setCapacity(double C_) { C = C_;}
137  void updateGeneralizedForces();
138  std::string getType() const { return "Capacitor"; }
139  };
140 
141  class VoltageSource : public ElectronicLink {
142  protected:
144  public:
145  VoltageSource(const std::string &name);
146  ~VoltageSource() { delete voltageSignal; }
147  void setVoltageSignal(MBSim::Function<fmatvec::VecV(double)> *func) {voltageSignal = func;}
148  void updateGeneralizedForces();
149  std::string getType() const { return "VoltageSource"; }
150  };
151 
152  class Diode : public ElectronicLink {
153  protected:
154  bool sv;
155  public:
156  Diode(const std::string &name);
157  void setSetValued(bool flag) {sv = flag;}
158  void updateGeneralizedForces();
159  bool isSetValued() const {return sv;}
160  virtual bool isSingleValued() const {return not sv;}
161  void checkImpactsForTermination();
162  void solveImpactsGaussSeidel();
163  std::string getType() const { return "Diode"; }
164  };
165 
166  class Switch : public ElectronicLink {
167  protected:
169  bool sv;
170  public:
171  Switch(const std::string &name);
172  ~Switch() { delete voltageSignal; }
173  void setSetValued(bool flag) {sv = flag;}
174  bool isSetValued() const {return sv;}
175  virtual bool isSingleValued() const {return not sv;}
176  void updateGeneralizedForces();
177  void checkImpactsForTermination();
178  void solveImpactsGaussSeidel();
179  void setVoltageSignal(MBSim::Function<fmatvec::VecV(double)> *func) {voltageSignal = func;}
180  std::string getType() const { return "Switch"; }
181  };
182 
184  protected:
185  public:
186  ElectronicObject(const std::string &name) : Object(name) {}
187  void init(InitStage stage);
188  virtual Element* getParent() {return parent;}
189  virtual const Element* getParent() const {return parent;}
190  virtual void setParent(Element* parent_) {parent = parent_;}
191  void plot();
192  virtual std::string getName() const {return Object::getName();}
193  virtual void setName(std::string name) {Object::setName(name);}
194  void resetUpToDate() { Object::resetUpToDate(); updQ = true; updI = true; }
195  std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return std::shared_ptr<OpenMBV::Group>(); }
196  };
197 
198  class Inductor : public ElectronicObject {
199  protected:
200  double L;
201  public:
202  Inductor(const std::string &name);
203  void updateM();
204  void setInductance(double L_) { L = L_;}
205  };
206 
207 }
208 
209 #endif
Definition: simulation_classes.h:131
Definition: simulation_classes.h:198
Definition: simulation_classes.h:152
Definition: simulation_classes.h:121
Definition: simulation_classes.h:183
Definition: simulation_classes.h:20
Definition: simulation_classes.h:36
Definition: modelling_classes.h:42
Definition: simulation_classes.h:166
Definition: modelling_classes.h:19
Definition: simulation_classes.h:141

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML