|
mbsimelectronics
4.0.0
|
00001 #ifndef _SIMULATION_CLASSES_H 00002 #define _SIMULATION_CLASSES_H 00003 00004 #include "mbsim/dynamic_system_solver.h" 00005 #include "mbsim/object.h" 00006 #include "mbsim/link.h" 00007 #include "mbsim/mbsim_event.h" 00008 #include "modelling_classes.h" 00009 #include <string> 00010 //#include <mbsim/utils/function.h> 00011 00012 namespace MBSimControl { 00013 class Signal; 00014 } 00015 00016 namespace MBSimElectronics { 00017 00018 class Branch; 00019 class Mesh : public MBSim::Object { 00020 protected: 00021 Object* precessor; 00022 std::vector<Branch*> branch; 00023 public: 00024 Mesh(const std::string &name) : MBSim::Object(name), precessor(0) {} 00025 void calcqSize() { qSize = 1;} 00026 void calcuSize(int j) { uSize[j] = (j==0) ? 1 : 0;} 00027 void updateStateDependentVariables(double t) {}; 00028 void updateJacobians(double t, int j=0) {}; 00029 void updateInverseKineticsJacobians(double t) {}; 00030 void init(InitStage stage); 00031 Object* getObjectDependingOn() const {return precessor;} 00032 void setPrecessor(Object* obj) {precessor = obj;} 00033 void addBranch(Branch* branch_) {branch.push_back(branch_);} 00034 int getNumberOfBranches() {return branch.size();} 00035 Branch* getBranch(int i) {return branch[i];} 00036 #ifdef HAVE_OPENMBVCPPINTERFACE 00037 boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); } 00038 #endif 00039 }; 00040 00041 class Branch : public MBSim::Object { 00042 protected: 00043 fmatvec::Mat J[2]; 00044 fmatvec::Vec Q, I; 00045 std::vector<Mesh*> mesh; 00046 std::vector<double> vz; 00047 Terminal *startTerminal, *endTerminal; 00048 std::vector<Branch*> connectedBranch; 00049 int flag; 00050 Object* precessor; 00051 public: 00052 Branch(const std::string &name) : Object(name), Q(1), I(1), flag(0), precessor(0) {} 00053 void calcuSize(int j) { uSize[j] = (j==0) ? 0 : 1;} 00054 void updateStateDependentVariables(double t); 00055 void updateJacobians(double t, int j=0) {}; 00056 void updateInverseKineticsJacobians(double t) {}; 00057 const fmatvec::Mat& getJacobian(int j) const {return J[j];} 00058 fmatvec::Mat& getJacobian(int j) {return J[j];} 00059 const fmatvec::Vec& getCurrent() const {return I;} 00060 fmatvec::Vec& getCurrent() {return I;} 00061 const fmatvec::Vec& getCharge() const {return Q;} 00062 fmatvec::Vec& getCharge() {return Q;} 00063 void setvz(double vz_, Mesh* mesh); 00064 void connect(Mesh *mesh_) {mesh.push_back(mesh_);mesh_->addBranch(this);vz.push_back(0);} 00065 void clearMeshList() {mesh.clear();} 00066 int getNumberOfConnectedMeshes() const {return mesh.size();} 00067 Mesh* getMesh(int i) {return mesh[i];} 00068 void init(InitStage stage); 00069 void setStartTerminal(Terminal* p) {startTerminal = p; p->addConnectedBranch(this);} 00070 void setEndTerminal(Terminal* p) {endTerminal = p; p->addConnectedBranch(this);} 00071 Terminal* getStartTerminal() {return startTerminal;} 00072 Terminal* getEndTerminal() {return endTerminal;} 00073 void addConnectedBranch(Branch* branch); 00074 void buildTreeBranches(Branch* callingBranch, std::vector<Branch*> &treeBranch, unsigned int nmax); 00075 void buildMeshes(Terminal* callingTerminal, Branch* callingBranch, Mesh* currentMesh, bool &foundMesh); 00076 00077 void setFlag(int f) { flag = f; } 00078 int getFlag() const { return flag; } 00079 Object* getObjectDependingOn() const {return precessor;} 00080 void setPrecessor(Object* obj) {precessor = obj;} 00081 void updateh0Fromh1(double t); 00082 void updateW0FromW1(double t); 00083 void updateV0FromV1(double t); 00084 #ifdef HAVE_OPENMBVCPPINTERFACE 00085 boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); } 00086 #endif 00087 }; 00088 00089 class ElectronicLink : public MBSim::Link, public ElectronicComponent { 00090 protected: 00091 fmatvec::Vec gdn, gdd; 00092 public: 00093 ElectronicLink(const std::string &name) : Link(name) {} 00094 virtual Element* getParent() {return parent;} 00095 virtual const Element* getParent() const {return parent;} 00096 virtual void setParent(Element* parent_) {parent = parent_;} 00097 00098 void calcgSize(int j); 00099 void calcgdSize(int j); 00100 void calclaSize(int j); 00101 void updateg(double t); 00102 void updategd(double t); 00103 void updateW(double t, int j=0); 00104 void plot(double t, double dt = 1); 00105 virtual std::string getName() const {return Link::getName();} 00106 virtual void setName(std::string name) {Link::setName(name);} 00107 bool isActive() const {return true;} 00108 bool gActiveChanged() {return true;} 00109 virtual bool isSingleValued() const { return true; } 00110 void init(InitStage stage); 00111 void updatehRef(const fmatvec::Vec &hParent, int j=0); 00112 void updaterRef(const fmatvec::Vec &rParent, int j=0); 00113 virtual double computeVoltage() {return 0;} 00114 00115 /* INHERITED INTERFACE OF LINKINTERFACE */ 00116 virtual void updater(double t) { THROW_MBSIMERROR("(ElectronicLink::updater): Not implemented!"); } 00117 /*****************************************************/ 00118 00119 /* INHERITED INTERFACE OF LINK */ 00120 virtual void updateWRef(const fmatvec::Mat& ref, int j); 00121 virtual void updateVRef(const fmatvec::Mat& ref, int j); 00122 virtual void updatedhdqRef(const fmatvec::Mat& ref, int i=0) {} 00123 virtual void updatedhduRef(const fmatvec::SqrMat& ref, int i=0) {} 00124 virtual void updatedhdtRef(const fmatvec::Vec& ref, int i=0) {} 00125 /*****************************************************/ 00126 }; 00127 00128 class Resistor : public ElectronicLink { 00129 protected: 00130 double R; 00131 public: 00132 Resistor(const std::string &name); 00133 void updateh(double t, int j=0); 00134 void setResistance(double R_) { R = R_;} 00135 double computeVoltage(); 00136 }; 00137 00138 class Capacitor : public ElectronicLink { 00139 protected: 00140 double C; 00141 public: 00142 Capacitor(const std::string &name); 00143 void updateh(double t, int j=0); 00144 void setCapacity(double C_) { C = C_;} 00145 }; 00146 00147 class VoltageSource : public ElectronicLink { 00148 protected: 00149 //MBSim::Function1<fmatvec::Vec,double> *voltageSignal; 00150 MBSimControl::Signal *voltageSignal; 00151 public: 00152 VoltageSource(const std::string &name); 00153 void updateh(double t, int j=0); 00154 void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; } 00155 //void setVoltageSignal(MBSim::Function1<fmatvec::Vec,double> *func) {voltageSignal = func;} 00156 }; 00157 00158 class Diode : public ElectronicLink { 00159 protected: 00160 bool sv; 00161 public: 00162 Diode(const std::string &name); 00163 void setSetValued(bool flag) {sv = flag;} 00164 void updateh(double t, int j=0); 00165 bool isSetValued() const {return sv;} 00166 virtual bool isSingleValued() const {return not sv;} 00167 void checkImpactsForTermination(double dt); 00168 void solveImpactsGaussSeidel(double dt); 00169 }; 00170 00171 class Switch : public ElectronicLink { 00172 protected: 00173 //MBSim::Function1<fmatvec::Vec,double> *voltageSignal; 00174 MBSimControl::Signal *voltageSignal; 00175 double U0; 00176 bool sv; 00177 public: 00178 Switch(const std::string &name); 00179 void setSetValued(bool flag) {sv = flag;} 00180 bool isSetValued() const {return sv;} 00181 virtual bool isSingleValued() const {return not sv;} 00182 void updateh(double t, int j=0); 00183 void updateW(double t, int j=0); 00184 void checkImpactsForTermination(double dt); 00185 void solveImpactsGaussSeidel(double dt); 00186 void setVoltageSignal(MBSimControl::Signal *signal) {voltageSignal = signal; } 00187 //void setVoltageSignal(MBSim::Function1<fmatvec::Vec,double> *func) {voltageSignal = func;} 00188 }; 00189 00190 class ElectronicObject : public MBSim::Object, public ElectronicComponent { 00191 protected: 00192 public: 00193 ElectronicObject(const std::string &name) : Object(name) {} 00194 void init(InitStage stage); 00195 virtual Element* getParent() {return parent;} 00196 virtual const Element* getParent() const {return parent;} 00197 virtual void setParent(Element* parent_) {parent = parent_;} 00198 void plot(double t, double dt = 1); 00199 void updateStateDependentVariables(double t) {}; 00200 void updateJacobians(double t, int j=0) {}; 00201 void updateInverseKineticsJacobians(double t) {}; 00202 virtual std::string getName() const {return Object::getName();} 00203 virtual void setName(std::string name) {Object::setName(name);} 00204 Object* getObjectDependingOn() const {return branch;} 00205 #ifdef HAVE_OPENMBVCPPINTERFACE 00206 boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return boost::shared_ptr<OpenMBV::Group>(); } 00207 #endif 00208 }; 00209 00210 class Inductor : public ElectronicObject { 00211 protected: 00212 double L; 00213 public: 00214 Inductor(const std::string &name); 00215 void updateM(double t, int j=0); 00216 void setInductance(double L_) { L = L_;} 00217 void updateStateDependentVariables(double t); 00218 }; 00219 00220 } 00221 00222 #endif
1.8.0