1 #ifndef _SIMULATION_CLASSES_H
2 #define _SIMULATION_CLASSES_H
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"
17 namespace MBSimElectronics {
23 std::vector<Branch*> branch;
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>(); }
40 std::vector<Mesh*> mesh;
41 std::vector<double> vz;
42 Terminal *startTerminal, *endTerminal;
43 std::vector<Branch*> connectedBranch;
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;}
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);
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>(); }
86 virtual Element* getParent() {
return parent;}
87 virtual const Element* getParent()
const {
return parent;}
88 virtual void setParent(Element* parent_) {parent = parent_;}
90 void calcgSize(
int j);
91 void calcgdSize(
int j);
92 void calclaSize(
int j);
95 void updateW(
int j=0);
96 void updateh(
int j=0);
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);
108 virtual void updater() { THROW_MBSIMERROR(
"(ElectronicLink::updater): Not implemented!"); }
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) {}
116 virtual void updatedhdtRef(
const fmatvec::Vec& ref,
int i=0) {}
117 void resetUpToDate() { Link::resetUpToDate(); updQ =
true; updI =
true; }
126 void setResistance(
double R_) { R = R_;}
127 void updateGeneralizedForces();
128 std::string getType()
const {
return "Resistor"; }
136 void setCapacity(
double C_) { C = C_;}
137 void updateGeneralizedForces();
138 std::string getType()
const {
return "Capacitor"; }
147 void setVoltageSignal(
MBSim::Function<fmatvec::VecV(
double)> *func) {voltageSignal = func;}
148 void updateGeneralizedForces();
149 std::string getType()
const {
return "VoltageSource"; }
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"; }
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"; }
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_;}
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>(); }
204 void setInductance(
double L_) { L = L_;}
Definition: simulation_classes.h:131
Definition: simulation_classes.h:81
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