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()
override {
qSize = 1;}
27 void calcuSize(
int j)
override {
uSize[j] = (j==0) ? 1 : 0;}
28 void init(
InitStage stage,
const MBSim::InitConfigSet &config)
override;
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];}
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(
nullptr), updQ(
true), updI(
true) { }
49 void calcuSize(
int j)
override {
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,
const MBSim::InitConfigSet &config)
override;
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()
override { Object::resetUpToDate(); updQ =
true; updI =
true; }
86 Element* getParent()
override {
return parent;}
87 const Element* getParent()
const override {
return parent;}
88 void setParent(
Element* parent_)
override {parent = parent_;}
90 void calcSize()
override { ng = 1; ngd = 1; nla = 1; }
92 void calcgSize(
int j)
override;
93 void calcgdSize(
int j)
override;
94 void calclaSize(
int j)
override;
95 void updateg()
override;
96 void updategd()
override;
97 void updateW(
int j=0)
override;
98 void updateh(
int j=0)
override;
100 std::string getName()
const override {
return Link::getName();}
101 void setName(std::string
name)
override {Link::setName(
name);}
102 bool isActive()
const override {
return true;}
103 bool gActiveChanged()
override {
return true;}
104 bool isSingleValued()
const override {
return true; }
105 void init(
InitStage stage,
const MBSim::InitConfigSet &config)
override;
106 void updatehRef(
fmatvec::Vec &hParent,
int j=0)
override;
107 void updaterRef(
fmatvec::Vec &rParent,
int j=0)
override;
110 virtual void updater() { throwError(
"(ElectronicLink::updater): Not implemented!"); }
116 virtual void updatedhdqRef(
fmatvec::Mat& ref,
int i=0) {}
118 virtual void updatedhdtRef(
fmatvec::Vec& ref,
int i=0) {}
119 void resetUpToDate()
override { Link::resetUpToDate(); updQ =
true; updI =
true; }
128 void setResistance(
double R_) { R = R_;}
129 void updateGeneralizedForces()
override;
137 void setCapacity(
double C_) { C = C_;}
138 void updateGeneralizedForces()
override;
147 void setVoltageSignal(
MBSim::Function<fmatvec::VecV(
double)> *func) {voltageSignal = func;}
148 void updateGeneralizedForces()
override;
156 void setSetValued(
bool flag) {sv = flag;}
157 void updateGeneralizedForces()
override;
158 bool isSetValued()
const override {
return sv;}
159 bool isSingleValued()
const override {
return not sv;}
160 void checkImpactsForTermination()
override;
161 void solveImpactsGaussSeidel()
override;
170 ~
Switch()
override {
delete voltageSignal; }
171 void setSetValued(
bool flag) {sv = flag;}
172 bool isSetValued()
const override {
return sv;}
173 bool isSingleValued()
const override {
return not sv;}
174 void updateGeneralizedForces()
override;
175 void checkImpactsForTermination()
override;
176 void solveImpactsGaussSeidel()
override;
177 void setVoltageSignal(
MBSim::Function<fmatvec::VecV(
double)> *func) {voltageSignal = func;}
184 void calcSize()
override { nq = 0; nu = 1; }
185 void init(
InitStage stage,
const MBSim::InitConfigSet &config)
override;
186 Element* getParent()
override {
return parent;}
187 const Element* getParent()
const override {
return parent;}
188 void setParent(
Element* parent_)
override {parent = parent_;}
189 void plot()
override;
190 std::string getName()
const override {
return Object::getName();}
191 void setName(std::string
name)
override {Object::setName(
name);}
192 void resetUpToDate()
override { Object::resetUpToDate(); updQ =
true; updI =
true; }
201 void updateM()
override;
202 void setInductance(
double L_) { L = L_;}
Definition: simulation_classes.h:132
Definition: simulation_classes.h:81
Definition: simulation_classes.h:196
Definition: simulation_classes.h:151
Object(const std::string &name)
Definition: simulation_classes.h:123
Link(const std::string &name)
Definition: simulation_classes.h:180
Definition: simulation_classes.h:20
Definition: simulation_classes.h:36
Definition: modelling_classes.h:44
Definition: simulation_classes.h:164
Definition: modelling_classes.h:21
Definition: simulation_classes.h:141
Element(const std::string &name)