mbsimelectronics 4.0.0 MBSim Electronics Module

modelling_classes.h
1 #ifndef _MODELING_CLASSES_H
2 #define _MODELING_CLASSES_H
3
4 #include "mbsim/element.h"
5 #include "mbsim/modelling_interface.h"
6 #include <string>
7 #include <vector>
8
9 namespace MBSim {
10 class Object;
11 class Link;
12 }
13
14 namespace MBSimElectronics {
15
16 extern const MBSim::PlotFeatureEnum charge, current, voltage;
17
18 class ElectronicComponent;
19 class Branch;
20
21 class Terminal : public MBSim::Element {
22 std::vector<Terminal*> connectedTerminal;
23 std::vector<Branch*> connectedBranch;
24 int flag;
25 ElectronicComponent* parent;
26 public:
27 Terminal(const std::string &name) : Element(name), flag(0), parent(nullptr) {}
28 void addConnectedTerminal(Terminal* terminal);
29 void addConnectedBranch(Branch* branch);
30 void setFlag(int f) { flag = f; }
31 int getFlag() const { return flag; }
32 //void setParent(ElectronicComponent* p) { parent = p; }
33 //ElectronicComponent* getParent() const { return parent; }
34 int getNumberOfConnectedTerminals() const {return connectedTerminal.size();}
35 int getNumberOfConnectedBranches() const {return connectedBranch.size();}
36 Branch* getBranch(int i) {return connectedBranch[i];}
37 std::vector<Branch*> buildBranches(Branch* branch);
38 void findEndOfBranch(Terminal* callingTerminal, Branch* currentBranch);
39 };
40
41 void connectTerminal(Terminal *terminal1, Terminal *terminal2);
42 void connectBranch(Branch *branch1, Branch *branch2);
43
44 class ElectronicComponent : public MBSim::ModellingInterface {
45 protected:
46 std::vector<Terminal*> terminal;
47 Branch* branch{nullptr};
48 double vz{0};
49 double Q{0}, I{0};
50 bool updQ{true}, updI{true};
51 public:
52 ElectronicComponent();
53 ~ElectronicComponent() override;
54 void addTerminal(Terminal *terminal);
55 void addTerminal(const std::string &str);
56 Terminal* getTerminal(const std::string &name, bool check=true);
57 void buildListOfTerminals(std::vector<Terminal*> &terminal);
58 void connect(Branch *branch_,double vz=0);
59 Branch* getBranch() {return branch;}
60 void processModellList(std::vector<ModellingInterface*> &modellList, std::vector<MBSim::Object*> &objectList, std::vector<MBSim::Link*> &linkList) override;
61 double getvz() const { return vz;}
62 virtual void updateCharge();
63 virtual void updateCurrent();
64 double evalCurrent() { if(updI) updateCurrent(); return I; }
65 double evalCharge() { if(updQ) updateCharge(); return Q; }
66 };
67
68 }
69
70 #endif
71
MBSim::Element
MBSim::PlotFeatureEnum
MBSimElectronics::Branch
Definition: simulation_classes.h:36
MBSim::Element::name
std::string name
MBSimElectronics::ElectronicComponent
Definition: modelling_classes.h:44
MBSim::ModellingInterface
MBSimElectronics::Terminal
Definition: modelling_classes.h:21
MBSim::Element::Element
Element(const std::string &name)